Salome HOME
bdc401e2c029f68e8f2d68e3e8058e89b9d43404
[modules/yacs.git] / src / wrappergen / src / parse30.awk
1 # Copyright (C) 2006-2022  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 checks the arguments and return value compatibility
21 #
22 BEGIN { 
23
24 #
25 #
26 # allowed types for arguments
27 #
28   arg_type["int"]= 1;
29   arg_type["double"]= 1;
30   arg_type["float"]= 1;
31   arg_type["long"]= 1;
32   arg_type["short"]= 1;
33   arg_type["unsigned"]= 1;
34   arg_type["const char*"]= 1;
35   arg_type["const std::string&"]= 1;
36   arg_type["int&"]= 1;
37   arg_type["double&"]= 1;
38   arg_type["float&"]= 1;
39   arg_type["long&"]= 1;
40   arg_type["short&"]= 1;
41   arg_type["unsigned&"]= 1;
42   arg_type["std::string&"]= 1;
43   arg_type["const MEDMEM::MESH&"]= 1;
44   arg_type["const MEDMEM::MESH*"]= 1;
45   arg_type["const MEDMEM::FIELD<double>*"]= 1;
46   arg_type["const MEDMEM::FIELD<double>&"]= 1;
47   arg_type["MEDMEM::FIELD<double>*&"]= 1;
48   arg_type["const std::vector<double>&"]= 1;
49   arg_type["const std::vector<std::vector<double> >&"]= 1;
50   arg_type["std::vector<double>&"]= 1;
51   arg_type["std::vector<double>*&"]= 1;
52   arg_type["const MEDMEM::FIELD<int>*"]= 1;
53   arg_type["const MEDMEM::FIELD<int>&"]= 1;
54   arg_type["MEDMEM::FIELD<int>*&"]= 1;
55   arg_type["const std::vector<int>&"]= 1;
56   arg_type["std::vector<int>*&"]= 1;
57   arg_type["std::vector<int>&"]= 1;
58 #
59 #
60 # allowed types for return values
61 #
62   rtn_type["void"]= 1;
63   rtn_type["int"]= 1;
64   rtn_type["double"]= 1;
65   rtn_type["float"]= 1;
66   rtn_type["long"]= 1;
67   rtn_type["short"]= 1;
68   rtn_type["unsigned"]= 1;
69   rtn_type["const char*"]= 1;
70   rtn_type["char*"]= 1;
71   rtn_type["std::string"]= 1;
72   rtn_type["const MEDMEM::MESH&"]= 1;
73   rtn_type["MEDMEM::MESH&"]= 1;
74   rtn_type["MEDMEM::MESH*"]= 1;
75   rtn_type["const MEDMEM::MESH*"]= 1;
76   rtn_type["const MEDMEM::FIELD<double>*"]= 1;
77   rtn_type["MEDMEM::FIELD<double>*"]= 1;
78   rtn_type["MEDMEM::FIELD<double>&"]= 1;
79   rtn_type["const MEDMEM::FIELD<double>&"]= 1;
80   rtn_type["std::vector<double>*"]= 1;
81   rtn_type["std::vector<double>"]= 1;
82   rtn_type["std::vector<std::vector<double> >*"]= 1;
83   rtn_type["const MEDMEM::FIELD<int>*"]= 1;
84   rtn_type["MEDMEM::FIELD<int>*"]= 1;
85   rtn_type["MEDMEM::FIELD<int>&"]= 1;
86   rtn_type["const MEDMEM::FIELD<int>&"]= 1;
87   rtn_type["std::vector<int>*"]= 1;
88 #
89 #
90 # record sep is ");\n" whith blanks all around, and optional "(" at the beginning
91   RS="[(]?[ \t]*[)][ \t]*;[ \t]*\n?"  
92   FS="[ \t]*[(,][ \t]*"  # field sep is either "(" or "," surrounded by blanks 
93 }
94
95 # --------------------- treatment 1 ----------------------------------
96 #
97 #  extract from fields types, function name, and argument's names
98 #
99 {
100
101   print "Function : ",$0 >> "parse_result"  # print for debug
102   for (i=1; i<=NF; i++) {
103       print "\t-> ",i," : ",$i >> "parse_result"
104   }
105   ok1=0;ok=1
106   # check if returned type ($1) is one of the accepted types (rtn_type)
107   for (cpptype in rtn_type) {
108     if ( substr($1,1,length(cpptype)) == cpptype ) {
109       # if compatible, store returned type and function name
110       type[1]=cpptype
111       name[1]=substr($1,length(cpptype)+1)
112       sub("^[ \t]*","",name[1]) # get rid of leading blanks
113       ok1=1
114       break
115     }
116   }
117   ok*=ok1
118   # for each argument ($i), check if it is compatible (belongs to arg_type)
119   for (i=2; i<=NF; i++) {
120     ok2=0
121     split($i,tab,"=") # get rid of default value
122     item=tab[1]
123     for (cpptype in arg_type) {
124        if ( substr(item,1,length(cpptype)) == cpptype ) {
125           # if compatible, store argument type and name
126           type[i]=cpptype
127           name[i]=substr(item,length(cpptype)+1)
128           sub("^[ \t]*","",name[i]) # get rid of leading blanks
129           if ( length(name[i]) == 0 ) # automatic name if argument's name wasn't precised
130              name[i]=sprintf("_arg%d",i-1)
131           ok2=1
132           break
133        }
134     }
135     ok*=ok2 # ok=0 if one of the type is not compatible
136   }
137
138   # print compatibility 
139   if ( $0 !~ class_name ) { # constructor are not considered, but we don't print it
140       if ( ok == 0){ # if one of the c++ type is not compatible
141           printf "     [KO]     :  %s",$0
142       }
143       else
144           printf "     [OK]     :  %s",$0
145         
146       if ( $0 !~ /\(/  ) {
147           printf "(" # if there is no argument, parenthesis was suppressed, so we add it for printing
148       }
149       printf ");\n"
150   }    
151   if ( ok == 0) # pass to the next function if one of the c++ type is not compatible
152       next
153 }
154 #
155 #
156 END {
157 }