2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
49 (* for metavariables in general, but here because needed for metatypes *)
50 type inherited
= bool (* true if inherited *)
51 type keep_binding
= Unitary
(* need no info *)
52 | Nonunitary
(* need an env entry *) | Saved
(* need a witness *)
54 type meta_name
= string * string (*Ast_cocci.meta_name*)
57 ConstVol
of const_vol
* typeC
58 | BaseType
of baseType
59 | SignedT
of sign
* typeC
option
61 | FunctionPointer
of typeC
(* only return type *)
62 | Array
of typeC
(* drop size info *)
64 | StructUnionName
of structUnion
* name
66 | MetaType
of meta_name
* keep_binding
* inherited
67 | Unknown
(* for metavariables of type expression *^* *)
72 | MV
of meta_name
* keep_binding
* inherited
74 and tagged_string
= string
76 and baseType
= VoidType
| CharType
| ShortType
| IntType
| DoubleType
77 | FloatType
| LongType
| LongLongType
| BoolType
78 | SizeType
| SSizeType
| PtrDiffType
80 and structUnion
= Struct
| Union
82 and sign
= Signed
| Unsigned
84 and const_vol
= Const
| Volatile
86 (* --------------------------------------------------------------------- *)
90 let rec type2c = function
91 ConstVol
(cv
,ty
) -> (const_vol cv
) ^
(type2c ty
)
92 | BaseType
(ty
) -> baseType ty
93 | SignedT
(sgn
,None
) -> sign sgn
94 | SignedT
(sgn
,Some ty
) -> (sign sgn
) ^
(type2c ty
)
95 | Pointer
(ty
) -> (type2c ty
) ^
"*"
96 | FunctionPointer
(ty
) -> (type2c ty
) ^
"(*)(...)"
97 | Array
(ty
) -> (type2c ty
) ^
"[] "
98 | EnumName
(name
) -> "enum " ^
(print_name name
)
99 | StructUnionName
(kind
,name
) -> (structUnion kind
) ^
(print_name name
)
100 | TypeName
(name
) -> name ^
" "
101 | MetaType
((rule
,name
),keep
,inherited
) -> name ^
" "
103 let print_unitary = function
104 Unitary -> print_string "unitary"
105 | Nonunitary -> print_string "nonunitary"
106 | Saved -> print_string "saved" in
108 print_string "keep:"; print_unitary keep;
109 print_string " inherited:"; print_bool inherited;
112 | Unknown
-> "unknown "
114 and print_name
= function
116 | MV
((_
,name
),_
,_
) -> name ^
" "
117 | Name name
-> name ^
" "
119 and baseType
= function
121 | CharType
-> "char "
122 | ShortType
-> "short "
124 | DoubleType
-> "double "
125 | FloatType
-> "float "
126 | LongType
-> "long "
127 | LongLongType
-> "long long "
128 | BoolType
-> "bool "
129 | SizeType
-> "size_t "
130 | SSizeType
-> "ssize_t "
131 | PtrDiffType
-> "ptrdiff_t "
134 and structUnion
= function
140 | Unsigned
-> "unsigned "
142 and const_vol
= function
144 | Volatile
-> "volatile "
146 let typeC t
= print_string
(type2c t
)
148 (* t1 should be less informative than t1, eg t1 = Pointer(Unknown) and t2 =
150 (* only used in iso *)
151 (* needs to do something for MetaType *)
152 let compatible t1
= function
155 let rec loop = function
157 | (ConstVol
(cv1
,ty1
),ConstVol
(cv2
,ty2
)) when cv1
= cv2
->
159 | (Pointer
(ty1
),Pointer
(ty2
)) -> loop(ty1
,ty2
)
160 | (FunctionPointer
(ty1
),_
) -> false (* not enough info *)
161 | (_
,FunctionPointer
(ty2
)) -> false (* not enough info *)
162 | (Array
(ty1
),Array
(ty2
)) -> loop(ty1
,ty2
)