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