Salome HOME
Update copyrights 2014.
[modules/yacs.git] / src / wrappergen / src / parse3.awk
1 # Copyright (C) 2006-2014  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # This awk program contains the type mapping tables - and the treatments
21 # for code generation
22 #
23 BEGIN { 
24 #
25 # file name generation
26   idl_file="code_idl"
27   hxx_file="code_hxx"
28   cxx_file="code_cxx"
29   class_i=class_name"_i"
30   print "\t// generated part" > idl_file
31   printf "    // generated part\n" > hxx_file
32   printf "//\n// generated part\n//\n" > cxx_file
33   print "Functions parsing (for debug)" > "parse_result"
34 #
35 #
36 # type mapping from c++ component to idl
37 #
38   idl_arg_type["int"]="in long"
39   idl_arg_type["double"]="in double"
40   idl_arg_type["float"]="in float"
41   idl_arg_type["long"]="in long"
42   idl_arg_type["short"]="in short"
43   idl_arg_type["unsigned"]="in unsigned long"
44   idl_arg_type["const char*"]="in string"
45   idl_arg_type["const std::string&"]="in string"
46   idl_arg_type["int&"]="out long"
47   idl_arg_type["double&"]="out double"
48   idl_arg_type["float&"]="out float"
49   idl_arg_type["long&"]="out long"
50   idl_arg_type["short&"]="out short"
51   idl_arg_type["unsigned&"]="out unsigned long"
52   idl_arg_type["std::string&"]="out string"
53   idl_arg_type["const MEDMEM::MESH&"]="in SALOME_MED::MESH"
54   idl_arg_type["const MEDMEM::MESH*"]="in SALOME_MED::MESH"
55   idl_arg_type["const MEDMEM::FIELD<double>*"]="in SALOME_MED::FIELDDOUBLE"
56   idl_arg_type["const MEDMEM::FIELD<double>&"]="in SALOME_MED::FIELDDOUBLE"
57   idl_arg_type["MEDMEM::FIELD<double>*&"]="out SALOME_MED::FIELDDOUBLE"
58   idl_arg_type["const std::vector<double>&"]="in SALOME::SenderDouble"
59   idl_arg_type["const std::vector<std::vector<double> >&"]="in SALOME::Matrix"
60   idl_arg_type["std::vector<double>*&"]="out SALOME::SenderDouble"
61   idl_arg_type["const MEDMEM::FIELD<int>*"]="in SALOME_MED::FIELDINT"
62   idl_arg_type["const MEDMEM::FIELD<int>&"]="in SALOME_MED::FIELDINT"
63   idl_arg_type["MEDMEM::FIELD<int>*&"]="out SALOME_MED::FIELDINT"
64   idl_arg_type["const std::vector<int>&"]="in SALOME::SenderInt"
65   idl_arg_type["std::vector<int>*&"]="out SALOME::SenderInt"
66 #
67 #
68 # mapping for returned types
69 #
70   idl_rtn_type["void"]="void"
71   idl_rtn_type["int"]="long"
72   idl_rtn_type["double"]="double"
73   idl_rtn_type["float"]="float"
74   idl_rtn_type["long"]="long"
75   idl_rtn_type["short"]="short"
76   idl_rtn_type["unsigned"]="unsigned long"
77   idl_rtn_type["const char*"]="string"
78   idl_rtn_type["char*"]="string"
79   idl_rtn_type["std::string"]="string"
80   idl_rtn_type["const MEDMEM::MESH&"]="SALOME_MED::MESH"
81   idl_rtn_type["MEDMEM::MESH&"]="SALOME_MED::MESH"
82   idl_rtn_type["MEDMEM::MESH*"]="SALOME_MED::MESH"
83   idl_rtn_type["const MEDMEM::MESH*"]="SALOME_MED::MESH"
84   idl_rtn_type["const MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
85   idl_rtn_type["MEDMEM::FIELD<double>*"]="SALOME_MED::FIELDDOUBLE"
86   idl_rtn_type["MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
87   idl_rtn_type["const MEDMEM::FIELD<double>&"]="SALOME_MED::FIELDDOUBLE"
88   idl_rtn_type["std::vector<double>*"]="SALOME::SenderDouble"
89   idl_rtn_type["std::vector<std::vector<double> >*"]="SALOME::Matrix"
90   idl_rtn_type["const MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
91   idl_rtn_type["MEDMEM::FIELD<int>*"]="SALOME_MED::FIELDINT"
92   idl_rtn_type["MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
93   idl_rtn_type["const MEDMEM::FIELD<int>&"]="SALOME_MED::FIELDINT"
94   idl_rtn_type["std::vector<int>*"]="SALOME::SenderInt"
95 #
96 #
97 # Corba mapping table (for argument's types and returned types)
98 #
99   idl_impl_hxx["in long"]="CORBA::Long"
100   idl_impl_hxx["in double"]="CORBA::Double"
101   idl_impl_hxx["in float"]="CORBA::Float"
102   idl_impl_hxx["in short"]="CORBA::Short"
103   idl_impl_hxx["in unsigned long"]="CORBA::ULong"
104   idl_impl_hxx["in string"]="const char*"
105   idl_impl_hxx["out long"]="CORBA::Long_out"
106   idl_impl_hxx["out double"]="CORBA::Double_out"
107   idl_impl_hxx["out float"]="CORBA::Float_out"
108   idl_impl_hxx["out short"]="CORBA::Short_out"
109   idl_impl_hxx["out unsigned long"]="CORBA::ULong_out"
110   idl_impl_hxx["out string"]="CORBA::String_out"
111   idl_impl_hxx["in SALOME_MED::MESH"]="SALOME_MED::MESH_ptr"
112   idl_impl_hxx["in SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_ptr"
113   idl_impl_hxx["out SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_out"
114   idl_impl_hxx["in SALOME::SenderDouble"]="SALOME::SenderDouble_ptr"
115   idl_impl_hxx["out SALOME::SenderDouble"]="SALOME::SenderDouble_out"
116   idl_impl_hxx["in SALOME::Matrix"]="SALOME::Matrix_ptr"
117   idl_impl_hxx["in SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_ptr"
118   idl_impl_hxx["out SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_out"
119   idl_impl_hxx["in SALOME::SenderInt"]="SALOME::SenderInt_ptr"
120   idl_impl_hxx["out SALOME::SenderInt"]="SALOME::SenderInt_out"
121   idl_impl_hxx["void"]="void"
122   idl_impl_hxx["long"]="CORBA::Long"
123   idl_impl_hxx["double"]="CORBA::Double"
124   idl_impl_hxx["unsigned long"]="CORBA::ULong"
125   idl_impl_hxx["string"]="char*"
126   idl_impl_hxx["SALOME_MED::MESH"]="SALOME_MED::MESH_ptr"
127   idl_impl_hxx["SALOME_MED::FIELDDOUBLE"]="SALOME_MED::FIELDDOUBLE_ptr"
128   idl_impl_hxx["SALOME::SenderDouble"]="SALOME::SenderDouble_ptr"
129   idl_impl_hxx["SALOME::Matrix"]="SALOME::Matrix_ptr"
130   idl_impl_hxx["SALOME_MED::FIELDINT"]="SALOME_MED::FIELDINT_ptr"
131   idl_impl_hxx["SALOME::SenderInt"]="SALOME::SenderInt_ptr"
132 #
133 #
134 # table for c++ code generation : argument's processing
135 #
136   cpp_impl_a["int"]="\tint _%s(%s);\n"
137   cpp_impl_a["double"]="\tdouble _%s(%s);\n"
138   cpp_impl_a["float"]="\tfloat _%s(%s);\n"
139   cpp_impl_a["long"]="\tlong _%s(%s);\n"
140   cpp_impl_a["short"]="\tshort _%s(%s);\n"
141   cpp_impl_a["unsigned"]="\tunsigned _%s(%s);\n"
142   cpp_impl_a["const char*"]="\tconst char* _%s(%s);\n"
143   cpp_impl_a["const std::string&"]="\tconst std::string _%s(%s);\n"
144   cpp_impl_a["int&"]="\tint _%s;\n"
145   cpp_impl_a["double&"]="\tdouble _%s;\n"
146   cpp_impl_a["float&"]="\tfloat _%s;\n"
147   cpp_impl_a["long&"]="\tlong _%s;\n"
148   cpp_impl_a["short&"]="\tshort _%s;\n"
149   cpp_impl_a["unsigned&"]="\tunsigned _%s;\n"
150   cpp_impl_a["std::string&"]="std::string _%s;\n"
151   cpp_impl_a["const MEDMEM::MESH&"]="\tMEDMEM::MESHClient* _%s = new MEDMEM::MESHClient(%s);\n" # MESHClient cannot be created on the stack (private constructor), so we create it on the heap and dereference it later (in treatment 4)
152   cpp_impl_a["const MEDMEM::MESH*"]="\tMEDMEM::MESHClient* _%s = new MEDMEM::MESHClient(%s);\n"
153   cpp_impl_a["MEDMEM::FIELD<double>*&"]="\tMEDMEM::FIELD<double>* _%s;\n"
154   cpp_impl_a["const MEDMEM::FIELD<double>*"]="\tstd::auto_ptr<MEDMEM::FIELD<double> > _%s ( new MEDMEM::FIELDClient<double,MEDMEM::FullInterlace>(%s) );\n"
155   cpp_impl_a["const MEDMEM::FIELD<double>&"]="\tMEDMEM::FIELDClient<double,MEDMEM::FullInterlace> _%s(%s);\n"
156   cpp_impl_a["const std::vector<double>&"]="\tlong _%s_size;\n\tdouble *_%s_value = ReceiverFactory::getValue(%s,_%s_size);\n"\
157              "\tstd::vector<double> _%s(_%s_value,_%s_value+_%s_size);\n\tdelete [] _%s_value;"
158   cpp_impl_a["std::vector<double>*&"]="\tstd::vector<double>* _%s;\n"
159   cpp_impl_a["const std::vector<std::vector<double> >&"]="\tMatrixClient _%s_client;\n\tint _%s_nbRow;\n\tint _%s_nbCol;\n"\
160              "\tdouble* _%s_tab = _%s_client.getValue(%s,_%s_nbCol,_%s_nbRow);\n\tstd::vector<std::vector<double> > _%s(_%s_nbRow);\n"\
161              "\tfor (int i=0; i!=_%s_nbRow; ++i)\n\t{\n\t    _%s.reserve(_%s_nbCol);\n"\
162              "\t    std::copy(_%s_tab+_%s_nbCol*i,_%s_tab+_%s_nbCol*(i+1), _%s[i].begin());\n\t}\n\tdelete [] _%s_tab;\n"
163   cpp_impl_a["MEDMEM::FIELD<int>*&"]="\tMEDMEM::FIELD<int>* _%s;\n"
164   cpp_impl_a["const MEDMEM::FIELD<int>*"]="\tstd::auto_ptr<MEDMEM::FIELD<int> > _%s ( new MEDMEM::FIELDClient<int>(%s) );\n"
165   cpp_impl_a["const MEDMEM::FIELD<int>&"]="\tMEDMEM::FIELDClient<int> _%s(%s);\n"
166   cpp_impl_a["const std::vector<int>&"]="\tlong _%s_size;\n\tint *_%s_value = ReceiverFactory::getValue(%s,_%s_size);\n"\
167              "\tstd::vector<int> _%s(_%s_value,_%s_value+_%s_size);\n\tdelete [] _%s_value;"
168   cpp_impl_a["std::vector<int>*&"]="\tstd::vector<int>* _%s;\n"
169
170 #
171 #
172 # table for c++ code generation : returned value processing
173 #
174   cpp_impl_b["void"]=""
175   cpp_impl_b["int"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
176   cpp_impl_b["double"]="\tCORBA::Double _rtn_ior(_rtn_cpp);\n"
177   cpp_impl_b["float"]="\tCORBA::Float _rtn_ior(_rtn_cpp);\n"
178   cpp_impl_b["long"]="\tCORBA::Long _rtn_ior(_rtn_cpp);\n"
179   cpp_impl_b["short"]="\tCORBA::Short _rtn_ior(_rtn_cpp);\n"
180   cpp_impl_b["unsigned"]="\tCORBA::ULong _rtn_ior(_rtn_cpp);\n"
181   cpp_impl_b["const char*"]="\tchar* _rtn_ior = CORBA::string_dup(_rtn_cpp);\n"
182   cpp_impl_b["char*"]="\tchar* _rtn_ior(_rtn_cpp);\n"
183   cpp_impl_b["std::string"]="\tchar* _rtn_ior=CORBA::string_dup(_rtn_cpp.c_str());\n"
184              "\tstd::copy(_rtn_cpp.begin(),_rtn_cpp.end(),_rtn_ior);\n"    
185   cpp_impl_b["const MEDMEM::MESH&"]=\
186              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(&_rtn_cpp));\n"\
187              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
188   cpp_impl_b["MEDMEM::MESH&"]=\
189              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(&_rtn_cpp);\n"\
190              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
191   cpp_impl_b["MEDMEM::MESH*"]=\
192              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(_rtn_cpp);\n"\
193              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
194   cpp_impl_b["const MEDMEM::MESH*"]=\
195              "\tMEDMEM::MESH_i * _rtn_mesh_i = new MEDMEM::MESH_i(const_cast<MEDMEM::MESH*>(_rtn_cpp));\n"\
196              "\tSALOME_MED::MESH_ptr _rtn_ior = _rtn_mesh_i->_this();\n"
197   cpp_impl_b["const MEDMEM::FIELD<double>*"]=\
198              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(const_cast<MEDMEM::FIELD<double>*>(_rtn_cpp),false);\n"\
199              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
200   cpp_impl_b["MEDMEM::FIELD<double>*"]=\
201              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(_rtn_cpp,true);\n"\
202              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
203   cpp_impl_b["MEDMEM::FIELD<double>&"]=\
204              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(&_rtn_cpp,false);\n"\
205              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
206   cpp_impl_b["const MEDMEM::FIELD<double>&"]=\
207              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * _rtn_field_i = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(const_cast<MEDMEM::FIELD<double>*>(&_rtn_cpp),false);\n"\
208              "\tSALOME_MED::FIELDDOUBLE_ptr _rtn_ior = _rtn_field_i->_this();\n"
209   cpp_impl_b["std::vector<double>*"]=\
210              "\tSALOME::SenderDouble_ptr _rtn_ior = SenderFactory::buildSender(*this,&(*_rtn_cpp)[0],(*_rtn_cpp).size(),true);\n"
211   cpp_impl_b["std::vector<std::vector<double> >*"]=\
212              "\tint _rtn_cpp_i=(*_rtn_cpp).size();\n\tint _rtn_cpp_j=(*_rtn_cpp)[0].size();\n"\
213              "\tdouble* _rtn_tab = new double[_rtn_cpp_i*_rtn_cpp_j];\n"\
214              "\tfor (int i=0; i!=_rtn_cpp_i; ++i)\n\t    std::copy((*_rtn_cpp)[i].begin(),(*_rtn_cpp)[i].end(),_rtn_tab+i*_rtn_cpp_j);\n"\
215              "\tSALOME_Matrix_i* _rtn_matrix_i = new SALOME_Matrix_i(*this,_rtn_tab,_rtn_cpp_j,_rtn_cpp_i,true);\n"\
216              "\tSALOME::Matrix_ptr _rtn_ior = _rtn_matrix_i->_this();\n\tdelete _rtn_cpp;\n"
217   cpp_impl_b["const MEDMEM::FIELD<int>*"]=\
218              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast<MEDMEM::FIELD<int>*>(_rtn_cpp),false);\n"\
219              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
220   cpp_impl_b["MEDMEM::FIELD<int>*"]=\
221              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(_rtn_cpp,true);\n"\
222              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
223   cpp_impl_b["MEDMEM::FIELD<int>&"]=\
224              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(&_rtn_cpp,false);\n"\
225              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
226   cpp_impl_b["const MEDMEM::FIELD<int>&"]=\
227              "\tMEDMEM::FIELDINT_i * _rtn_field_i = new MEDMEM::FIELDINT_i(const_cast<MEDMEM::FIELD<int>*>(&_rtn_cpp),false);\n"\
228              "\tSALOME_MED::FIELDINT_ptr _rtn_ior = _rtn_field_i->_this();\n"
229   cpp_impl_b["std::vector<int>*"]=\
230              "\tSALOME::SenderInt_ptr _rtn_ior = SenderFactory::buildSender(*this,&(*_rtn_cpp)[0],(*_rtn_cpp).size(),true);\n"
231
232 #
233 #
234 # table for c++ code generation : out parameters processing and removeRef for reference counted objects
235 #
236   cpp_impl_c["MEDMEM::FIELD<double>*&"]=\
237              "\tMEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace> * %s_ior = new MEDMEM::FIELDTEMPLATE_I<double,MEDMEM::FullInterlace>(_%s, true);\n"\
238              "\t%s = %s_ior->_this();\n"
239   cpp_impl_c["MEDMEM::FIELD<int>*&"]=\
240              "\tMEDMEM::FIELDINT_i * %s_ior = new MEDMEM::FIELDINT_i(_%s, true);\n"\
241              "\t%s = %s_ior->_this();\n"
242   cpp_impl_c["std::vector<double>*&"]=\
243              "\t%s = SenderFactory::buildSender(*this,&(*_%s)[0],(*_%s).size(),true);\n"
244   cpp_impl_c["std::vector<int>*&"]=\
245              "\t%s = SenderFactory::buildSender(*this,&(*_%s)[0],(*_%s).size(),true);\n"
246   cpp_impl_c["std::string&"]="\t%s = CORBA::string_dup(_%s.c_str());\n"
247   cpp_impl_c["int&"]="\t%s = _%s;\n"
248   cpp_impl_c["double&"]="\t%s = _%s;\n"
249   cpp_impl_c["float&"]="\t%s = _%s;\n"
250   cpp_impl_c["long&"]="\t%s = _%s;\n"
251   cpp_impl_c["short&"]="\t%s = _%s;\n"
252   cpp_impl_c["unsigned&"]="\t%s = _%s;\n"
253   cpp_impl_c["const MEDMEM::MESH&"]="\t_%s->removeReference();\n"
254   cpp_impl_c["const MEDMEM::MESH*"]="\t_%s->removeReference();\n"
255 #
256 #
257 # record sep is ");\n" whith blanks all around, and optional "(" at the beginning
258   RS="[(]?[ \t]*[)][ \t]*;[ \t]*\n?"  
259   FS="[ \t]*[(,][ \t]*"  # field sep is either "(" or "," surrounded by blanks 
260 }
261
262 # --------------------- treatment 1 ----------------------------------
263 #
264 #  extract from fields types, function name, and argument's names
265 #
266 {
267   print "Function : ",$0 >> "parse_result"  # print for debug
268   for (i=1; i<=NF; i++) {
269       print "\t-> ",i," : ",$i >> "parse_result"
270   }
271   ok1=0;ok=1
272   # check if returned type ($1) is one of the accepted types (idl_rtn_type)
273   for (cpptype in idl_rtn_type) {
274     if ( substr($1,1,length(cpptype)) == cpptype ) {
275       # if compatible, store returned type and function name
276       type[1]=cpptype
277       name[1]=substr($1,length(cpptype)+1)
278       sub("^[ \t]*","",name[1]) # get rid of leading blanks
279       ok1=1
280       break
281     }
282   }
283   ok*=ok1
284   # for each argument ($i), check if it is compatible (belongs to idl_arg_type)
285   for (i=2; i<=NF; i++) {
286     ok2=0
287     split($i,tab,"=") # get rid of default value
288     item=tab[1]
289     for (cpptype in idl_arg_type) {
290        if ( substr(item,1,length(cpptype)) == cpptype ) {
291           # if compatible, store argument type and name
292           type[i]=cpptype
293           name[i]=substr(item,length(cpptype)+1)
294           sub("^[ \t]*","",name[i]) # get rid of leading blanks
295           if ( length(name[i]) == 0 ) # automatic name if argument's name wasn't precised
296              name[i]=sprintf("_arg%d",i-1)
297           ok2=1
298           break
299        }
300     }
301     ok*=ok2 # ok=0 if one of the type is not compatible
302   }    
303   if ( ok == 0) # pass to the next function if one of the c++ type is not compatible
304       next
305 }
306 #
307 # --------------------- treatment 2 ----------------------------------
308 #
309 #  generate the Corba interface (idl file)
310 #
311
312   printf "\t%s %s(", idl_rtn_type[type[1]],name[1] >> idl_file  # return type and name of function
313   if ( NF >= 2 ){  # if there is arguments, print them
314     for (i=2; i<=NF-1; i++)
315       printf "%s %s,",idl_arg_type[type[i]],name[i] >> idl_file
316     printf "%s %s", idl_arg_type[type[NF]],name[NF] >> idl_file
317   }
318   printf ");\n" >> idl_file
319 }  
320 #
321 # --------------------- treatment 3 ----------------------------------
322 #
323 #  generate the C++ implementation of component (hxx file)
324 #
325
326   printf "    %s %s(",idl_impl_hxx[idl_rtn_type[type[1]]],name[1] >> hxx_file
327   if ( NF >= 2 ){  # if there is arguments, print them
328       for (i=2; i<=NF-1; i++)
329           printf "%s %s,",idl_impl_hxx[idl_arg_type[type[i]]],name[i] >> hxx_file
330       printf "%s %s", idl_impl_hxx[idl_arg_type[type[NF]]],name[NF] >> hxx_file
331   }
332   printf ");\n" >> hxx_file
333 }
334 #
335 # --------------------- treatment 4 ----------------------------------
336 #
337 #  generate the C++ implementation of component (cxx file)
338 #
339 {
340   # a) generate the function declaration + macro declarations
341   func_name=class_name"_i::"name[1]
342   printf "%s %s(",idl_impl_hxx[idl_rtn_type[type[1]]],func_name >> cxx_file
343   if ( NF >= 2 ){  # if there is arguments, print them
344       for (i=2; i<=NF-1; i++)
345           printf "%s %s,",idl_impl_hxx[idl_arg_type[type[i]]],name[i] >> cxx_file
346       printf "%s %s", idl_impl_hxx[idl_arg_type[type[NF]]],name[NF] >> cxx_file
347   }
348   printf ")\n{\n\tbeginService(\"%s\");\n\tBEGIN_OF(\"%s\");\n",func_name,func_name >> cxx_file
349
350   # b) generate the argument processing part
351   if ( NF >= 2 ){
352       printf "//\tArguments processing\n" >> cxx_file
353       for (i=2; i<=NF; i++)
354           printf cpp_impl_a[type[i]],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],\
355                            name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i],name[i] >> cxx_file
356   }
357
358   # c) generate the call to the c++ component
359   if ( type[1] == "void" ) # if return type is void, the call syntax is different.
360       printf "//\tCall cpp component\n\tcppCompo_->%s(",name[1] >> cxx_file
361   else
362       printf "//\tCall cpp component\n\t%s _rtn_cpp = cppCompo_->%s(",type[1],name[1] >> cxx_file
363   if ( NF >= 2 ){  # if there is arguments, print them
364       for (i=2; i<=NF; i++) {
365           # special treatment for some arguments
366           post=""
367           pre=""
368           if ( cpp_impl_a[type[i]] ~ "auto_ptr" )
369              post=".get()" # for auto_ptr argument, retrieve the raw pointer behind
370           if ( type[i] == "const MEDMEM::MESH&" )
371              pre="*"  # we cannot create MESHClient on the stack (private constructor), so we create it on the heap and dereference it
372           if ( i < NF )
373              post=post"," # separator between arguments
374           printf " %s_%s%s",pre,name[i],post >> cxx_file
375       }
376   }
377
378   # d) generate the post_processing of returned and out parameters
379   printf ");\n//\tPost-processing & return\n" >> cxx_file
380   for (i=2; i<=NF; i++)
381       printf cpp_impl_c[type[i]],name[i],name[i],name[i],name[i] >> cxx_file  # process for out parameters
382   printf cpp_impl_b[type[1]] >> cxx_file  # process for returned value
383   printf "\tendService(\"%s\");\n\tEND_OF(\"%s\");\n",func_name,func_name >> cxx_file
384   if ( type[1] != "void" )
385       printf "\treturn _rtn_ior;\n" >> cxx_file
386   printf "}\n\n" >> cxx_file
387 }
388 #
389 #
390 END {
391 # CNC peut ĂȘtre mis dans le template directement printf "\nprivate:\n    std::auto_ptr<%s> cppImpl_;\n",class_name >> hxx_file
392 }