Release coccinelle-0.1.1
[bpt/coccinelle.git] / parsing_cocci / .#ast0_cocci.ml.1.105
1 (*
2 * Copyright 2005-2008, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
4 * This file is part of Coccinelle.
5 *
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
9 *
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
20 *)
21
22
23 module Ast = Ast_cocci
24
25 (* --------------------------------------------------------------------- *)
26 (* Modified code *)
27
28 type arity = OPT | UNIQUE | NONE
29
30 type token_info =
31 { tline_start : int; tline_end : int;
32 left_offset : int; right_offset : int }
33 let default_token_info =
34 { tline_start = -1; tline_end = -1; left_offset = -1; right_offset = -1 }
35
36 (* MIXED is like CONTEXT, since sometimes MIXED things have to revert to
37 CONTEXT - see insert_plus.ml *)
38 type mcodekind =
39 MINUS of (Ast.anything list list * token_info) ref
40 | PLUS
41 | CONTEXT of (Ast.anything Ast.befaft * token_info * token_info) ref
42 | MIXED of (Ast.anything Ast.befaft * token_info * token_info) ref
43
44 type info = { line_start : int; line_end : int;
45 logical_start : int; logical_end : int;
46 attachable_start : bool; attachable_end : bool;
47 mcode_start : mcodekind list; mcode_end : mcodekind list;
48 column : int; offset : int;
49 (* the following are only for + code *)
50 strings_before : string list; strings_after : string list }
51
52 type 'a mcode = 'a * arity * info * mcodekind * meta_pos ref (* pos, - only *)
53 (* int ref is an index *)
54 and 'a wrap =
55 { node : 'a;
56 info : info;
57 index : int ref;
58 mcodekind : mcodekind ref;
59 exp_ty : Type_cocci.typeC option ref; (* only for expressions *)
60 bef_aft : dots_bef_aft; (* only for statements *)
61 true_if_arg : bool; (* true if "arg_exp", only for exprs *)
62 true_if_test : bool; (* true if "test position", only for exprs *)
63 true_if_test_exp : bool;(* true if "test_exp from iso", only for exprs *)
64 (*nonempty if this represents the use of an iso*)
65 iso_info : (string*anything) list }
66
67 and dots_bef_aft =
68 NoDots | AddingBetweenDots of statement | DroppingBetweenDots of statement
69
70 (* for iso metavariables, true if they can only match nonmodified terms with
71 all metavariables unitary
72 for SP metavariables, true if the metavariable is unitary (valid up to
73 isomorphism phase only)
74 In SP, the only options are impure and context
75 *)
76 and pure = Impure | Pure | Context | PureContext (* pure and only context *)
77
78 (* --------------------------------------------------------------------- *)
79 (* --------------------------------------------------------------------- *)
80 (* Dots *)
81
82 and 'a base_dots =
83 DOTS of 'a list
84 | CIRCLES of 'a list
85 | STARS of 'a list
86
87 and 'a dots = 'a base_dots wrap
88
89 (* --------------------------------------------------------------------- *)
90 (* Identifier *)
91
92 and base_ident =
93 Id of string mcode
94 | MetaId of Ast.meta_name mcode * ident list * pure
95 | MetaFunc of Ast.meta_name mcode * ident list * pure
96 | MetaLocalFunc of Ast.meta_name mcode * ident list * pure
97 | OptIdent of ident
98 | UniqueIdent of ident
99
100 and ident = base_ident wrap
101
102 (* --------------------------------------------------------------------- *)
103 (* Expression *)
104
105 and base_expression =
106 Ident of ident
107 | Constant of Ast.constant mcode
108 | FunCall of expression * string mcode (* ( *) *
109 expression dots * string mcode (* ) *)
110 | Assignment of expression * Ast.assignOp mcode * expression *
111 bool (* true if it can match an initialization *)
112 | CondExpr of expression * string mcode (* ? *) * expression option *
113 string mcode (* : *) * expression
114 | Postfix of expression * Ast.fixOp mcode
115 | Infix of expression * Ast.fixOp mcode
116 | Unary of expression * Ast.unaryOp mcode
117 | Binary of expression * Ast.binaryOp mcode * expression
118 | Nested of expression * Ast.binaryOp mcode * expression
119 | Paren of string mcode (* ( *) * expression *
120 string mcode (* ) *)
121 | ArrayAccess of expression * string mcode (* [ *) * expression *
122 string mcode (* ] *)
123 | RecordAccess of expression * string mcode (* . *) * ident
124 | RecordPtAccess of expression * string mcode (* -> *) * ident
125 | Cast of string mcode (* ( *) * typeC * string mcode (* ) *) *
126 expression
127 | SizeOfExpr of string mcode (* sizeof *) * expression
128 | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) *
129 typeC * string mcode (* ) *)
130 | TypeExp of typeC (* type name used as an expression, only in args *)
131 | MetaErr of Ast.meta_name mcode * expression list * pure
132 | MetaExpr of Ast.meta_name mcode * expression list *
133 Type_cocci.typeC list option * Ast.form * pure
134 | MetaExprList of Ast.meta_name mcode (* only in arg lists *) *
135 listlen * pure
136 | EComma of string mcode (* only in arg lists *)
137 | DisjExpr of string mcode * expression list *
138 string mcode list (* the |s *) * string mcode
139 | NestExpr of string mcode * expression dots * string mcode *
140 expression option * Ast.multi
141 | Edots of string mcode (* ... *) * expression option
142 | Ecircles of string mcode (* ooo *) * expression option
143 | Estars of string mcode (* *** *) * expression option
144 | OptExp of expression
145 | UniqueExp of expression
146
147 and expression = base_expression wrap
148
149 and listlen = Ast.meta_name mcode option
150
151 (* --------------------------------------------------------------------- *)
152 (* Types *)
153
154 and base_typeC =
155 ConstVol of Ast.const_vol mcode * typeC
156 | BaseType of Ast.baseType mcode * Ast.sign mcode option
157 | ImplicitInt of Ast.sign mcode
158 | Pointer of typeC * string mcode (* * *)
159 | FunctionPointer of typeC *
160 string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
161 string mcode (* ( *)*parameter_list*string mcode(* ) *)
162 | FunctionType of typeC option *
163 string mcode (* ( *) * parameter_list *
164 string mcode (* ) *)
165 | Array of typeC * string mcode (* [ *) *
166 expression option * string mcode (* ] *)
167 | StructUnionName of Ast.structUnion mcode * ident option (* name *)
168 | StructUnionDef of typeC (* either StructUnionName or metavar *) *
169 string mcode (* { *) * declaration dots * string mcode (* } *)
170 | TypeName of string mcode
171 | MetaType of Ast.meta_name mcode * pure
172 | DisjType of string mcode * typeC list * (* only after iso *)
173 string mcode list (* the |s *) * string mcode
174 | OptType of typeC
175 | UniqueType of typeC
176
177 and typeC = base_typeC wrap
178
179 (* --------------------------------------------------------------------- *)
180 (* Variable declaration *)
181 (* Even if the Cocci program specifies a list of declarations, they are
182 split out into multiple declarations of a single variable each. *)
183
184 and base_declaration =
185 Init of Ast.storage mcode option * typeC * ident * string mcode (*=*) *
186 initialiser * string mcode (*;*)
187 | UnInit of Ast.storage mcode option * typeC * ident * string mcode (* ; *)
188 | TyDecl of typeC * string mcode (* ; *)
189 | MacroDecl of ident (* name *) * string mcode (* ( *) *
190 expression dots * string mcode (* ) *) * string mcode (* ; *)
191 | Typedef of string mcode (* typedef *) * typeC * typeC * string mcode (*;*)
192 | DisjDecl of string mcode * declaration list *
193 string mcode list (* the |s *) * string mcode
194 (* Ddots is for a structure declaration *)
195 | Ddots of string mcode (* ... *) * declaration option (* whencode *)
196 | OptDecl of declaration
197 | UniqueDecl of declaration
198
199 and declaration = base_declaration wrap
200
201 (* --------------------------------------------------------------------- *)
202 (* Initializers *)
203
204 and base_initialiser =
205 InitExpr of expression
206 | InitList of string mcode (*{*) * initialiser_list * string mcode (*}*)
207 | InitGccDotName of
208 string mcode (*.*) * ident (* name *) * string mcode (*=*) *
209 initialiser (* gccext: *)
210 | InitGccName of ident (* name *) * string mcode (*:*) *
211 initialiser
212 | InitGccIndex of
213 string mcode (*[*) * expression * string mcode (*]*) *
214 string mcode (*=*) * initialiser
215 | InitGccRange of
216 string mcode (*[*) * expression * string mcode (*...*) *
217 expression * string mcode (*]*) * string mcode (*=*) * initialiser
218 | IComma of string mcode (* , *)
219 | Idots of string mcode (* ... *) * initialiser option (* whencode *)
220 | OptIni of initialiser
221 | UniqueIni of initialiser
222
223 and initialiser = base_initialiser wrap
224
225 and initialiser_list = initialiser dots
226
227 (* --------------------------------------------------------------------- *)
228 (* Parameter *)
229
230 and base_parameterTypeDef =
231 VoidParam of typeC
232 | Param of typeC * ident option
233 | MetaParam of Ast.meta_name mcode * pure
234 | MetaParamList of Ast.meta_name mcode * listlen * pure
235 | PComma of string mcode
236 | Pdots of string mcode (* ... *)
237 | Pcircles of string mcode (* ooo *)
238 | OptParam of parameterTypeDef
239 | UniqueParam of parameterTypeDef
240
241 and parameterTypeDef = base_parameterTypeDef wrap
242
243 and parameter_list = parameterTypeDef dots
244
245 (* --------------------------------------------------------------------- *)
246 (* #define Parameters *)
247
248 and base_define_param =
249 DParam of ident
250 | DPComma of string mcode
251 | DPdots of string mcode (* ... *)
252 | DPcircles of string mcode (* ooo *)
253 | OptDParam of define_param
254 | UniqueDParam of define_param
255
256 and define_param = base_define_param wrap
257
258 and base_define_parameters =
259 NoParams
260 | DParams of string mcode(*( *) * define_param dots * string mcode(* )*)
261
262 and define_parameters = base_define_parameters wrap
263
264 (* --------------------------------------------------------------------- *)
265 (* Statement*)
266
267 and base_statement =
268 Decl of (info * mcodekind) (* before the decl *) * declaration
269 | Seq of string mcode (* { *) * statement dots *
270 string mcode (* } *)
271 | ExprStatement of expression * string mcode (*;*)
272 | IfThen of string mcode (* if *) * string mcode (* ( *) *
273 expression * string mcode (* ) *) *
274 statement * (info * mcodekind) (* after info *)
275 | IfThenElse of string mcode (* if *) * string mcode (* ( *) *
276 expression * string mcode (* ) *) *
277 statement * string mcode (* else *) * statement *
278 (info * mcodekind)
279 | While of string mcode (* while *) * string mcode (* ( *) *
280 expression * string mcode (* ) *) *
281 statement * (info * mcodekind) (* after info *)
282 | Do of string mcode (* do *) * statement *
283 string mcode (* while *) * string mcode (* ( *) *
284 expression * string mcode (* ) *) *
285 string mcode (* ; *)
286 | For of string mcode (* for *) * string mcode (* ( *) *
287 expression option * string mcode (*;*) *
288 expression option * string mcode (*;*) *
289 expression option * string mcode (* ) *) * statement *
290 (info * mcodekind) (* after info *)
291 | Iterator of ident (* name *) * string mcode (* ( *) *
292 expression dots * string mcode (* ) *) *
293 statement * (info * mcodekind) (* after info *)
294 | Switch of string mcode (* switch *) * string mcode (* ( *) *
295 expression * string mcode (* ) *) * string mcode (* { *) *
296 case_line dots * string mcode (* } *)
297 | Break of string mcode (* break *) * string mcode (* ; *)
298 | Continue of string mcode (* continue *) * string mcode (* ; *)
299 | Label of ident * string mcode (* : *)
300 | Goto of string mcode (* goto *) * ident * string mcode (* ; *)
301 | Return of string mcode (* return *) * string mcode (* ; *)
302 | ReturnExpr of string mcode (* return *) * expression *
303 string mcode (* ; *)
304 | MetaStmt of Ast.meta_name mcode * pure
305 | MetaStmtList of Ast.meta_name mcode(*only in statement lists*) * pure
306 | Exp of expression (* only in dotted statement lists *)
307 | TopExp of expression (* for macros body *)
308 | Ty of typeC (* only at top level *)
309 | Disj of string mcode * statement dots list *
310 string mcode list (* the |s *) * string mcode
311 | Nest of string mcode * statement dots * string mcode *
312 (statement dots,statement) whencode list * Ast.multi
313 | Dots of string mcode (* ... *) *
314 (statement dots,statement) whencode list
315 | Circles of string mcode (* ooo *) *
316 (statement dots,statement) whencode list
317 | Stars of string mcode (* *** *) *
318 (statement dots,statement) whencode list
319 | FunDecl of (info * mcodekind) (* before the function decl *) *
320 fninfo list * ident (* name *) *
321 string mcode (* ( *) * parameter_list * string mcode (* ) *) *
322 string mcode (* { *) * statement dots *
323 string mcode (* } *)
324 | Include of string mcode (* #include *) * Ast.inc_file mcode (* file *)
325 | Define of string mcode (* #define *) * ident (* name *) *
326 define_parameters (*params*) * statement dots
327 | OptStm of statement
328 | UniqueStm of statement
329
330 and fninfo =
331 FStorage of Ast.storage mcode
332 | FType of typeC
333 | FInline of string mcode
334 | FAttr of string mcode
335
336 and ('a,'b) whencode =
337 WhenNot of 'a
338 | WhenAlways of 'b
339 | WhenModifier of Ast.when_modifier
340
341 and statement = base_statement wrap
342
343 and base_case_line =
344 Default of string mcode (* default *) * string mcode (*:*) * statement dots
345 | Case of string mcode (* case *) * expression * string mcode (*:*) *
346 statement dots
347 | OptCase of case_line
348
349 and case_line = base_case_line wrap
350
351 (* --------------------------------------------------------------------- *)
352 (* Positions *)
353
354 and meta_pos =
355 MetaPos of Ast.meta_name mcode * Ast.meta_name list * Ast.meta_collect
356 | NoMetaPos
357
358 (* --------------------------------------------------------------------- *)
359 (* Top-level code *)
360
361 and base_top_level =
362 DECL of statement
363 | CODE of statement dots
364 | FILEINFO of string mcode (* old file *) * string mcode (* new file *)
365 | ERRORWORDS of expression list
366 | OTHER of statement (* temporary, disappears after top_level.ml *)
367
368 and top_level = base_top_level wrap
369 and rule = top_level list
370
371 and parsed_rule =
372 CocciRule of
373 (rule * Ast.metavar list *
374 (string list * string list * Ast.dependency * string * Ast.exists)) *
375 (rule * Ast.metavar list)
376 | ScriptRule of
377 string * Ast.dependency * (string * Ast.meta_name) list * string
378
379 (* --------------------------------------------------------------------- *)
380
381 and anything =
382 DotsExprTag of expression dots
383 | DotsInitTag of initialiser dots
384 | DotsParamTag of parameterTypeDef dots
385 | DotsStmtTag of statement dots
386 | DotsDeclTag of declaration dots
387 | DotsCaseTag of case_line dots
388 | IdentTag of ident
389 | ExprTag of expression
390 | ArgExprTag of expression (* for isos *)
391 | TestExprTag of expression (* for isos *)
392 | TypeCTag of typeC
393 | ParamTag of parameterTypeDef
394 | InitTag of initialiser
395 | DeclTag of declaration
396 | StmtTag of statement
397 | CaseLineTag of case_line
398 | TopTag of top_level
399 | IsoWhenTag of Ast.when_modifier
400 | MetaPosTag of meta_pos
401
402 let dotsExpr x = DotsExprTag x
403 let dotsParam x = DotsParamTag x
404 let dotsInit x = DotsInitTag x
405 let dotsStmt x = DotsStmtTag x
406 let dotsDecl x = DotsDeclTag x
407 let dotsCase x = DotsCaseTag x
408 let ident x = IdentTag x
409 let expr x = ExprTag x
410 let typeC x = TypeCTag x
411 let param x = ParamTag x
412 let ini x = InitTag x
413 let decl x = DeclTag x
414 let stmt x = StmtTag x
415 let case_line x = CaseLineTag x
416 let top x = TopTag x
417
418 (* --------------------------------------------------------------------- *)
419 (* Avoid cluttering the parser. Calculated in compute_lines.ml. *)
420
421 let default_info _ = (* why is this a function? *)
422 { line_start = -1; line_end = -1;
423 logical_start = -1; logical_end = -1;
424 attachable_start = true; attachable_end = true;
425 mcode_start = []; mcode_end = [];
426 column = -1; offset = -1; strings_before = []; strings_after = [] }
427
428 let default_befaft _ =
429 MIXED(ref (Ast.NOTHING,default_token_info,default_token_info))
430 let context_befaft _ =
431 CONTEXT(ref (Ast.NOTHING,default_token_info,default_token_info))
432
433 let wrap x =
434 { node = x;
435 info = default_info();
436 index = ref (-1);
437 mcodekind = ref (default_befaft());
438 exp_ty = ref None;
439 bef_aft = NoDots;
440 true_if_arg = false;
441 true_if_test = false;
442 true_if_test_exp = false;
443 iso_info = [] }
444 let context_wrap x =
445 { node = x;
446 info = default_info();
447 index = ref (-1);
448 mcodekind = ref (context_befaft());
449 exp_ty = ref None;
450 bef_aft = NoDots;
451 true_if_arg = false;
452 true_if_test = false;
453 true_if_test_exp = false;
454 iso_info = [] }
455 let unwrap x = x.node
456 let unwrap_mcode (x,_,_,_,_) = x
457 let rewrap model x = { model with node = x }
458 let rewrap_mcode (_,arity,info,mcodekind,pos) x = (x,arity,info,mcodekind,pos)
459 let copywrap model x =
460 { model with node = x; index = ref !(model.index);
461 mcodekind = ref !(model.mcodekind); exp_ty = ref !(model.exp_ty)}
462 let get_pos (_,_,_,_,x) = !x
463 let get_pos_ref (_,_,_,_,x) = x
464 let set_pos pos (m,arity,info,mcodekind,_) = (m,arity,info,mcodekind,ref pos)
465 let get_info x = x.info
466 let set_info x info = {x with info = info}
467 let get_line x = x.info.line_start
468 let get_line_end x = x.info.line_end
469 let get_index x = !(x.index)
470 let set_index x i = x.index := i
471 let get_mcodekind x = !(x.mcodekind)
472 let get_mcode_mcodekind (_,_,_,mcodekind,_) = mcodekind
473 let get_mcodekind_ref x = x.mcodekind
474 let set_mcodekind x mk = x.mcodekind := mk
475 let set_type x t = x.exp_ty := t
476 let get_type x = !(x.exp_ty)
477 let get_dots_bef_aft x = x.bef_aft
478 let set_dots_bef_aft x dots_bef_aft = {x with bef_aft = dots_bef_aft}
479 let get_arg_exp x = x.true_if_arg
480 let set_arg_exp x = {x with true_if_arg = true}
481 let get_test_pos x = x.true_if_test
482 let set_test_pos x = {x with true_if_test = true}
483 let get_test_exp x = x.true_if_test_exp
484 let set_test_exp x = {x with true_if_test_exp = true}
485 let get_iso x = x.iso_info
486 let set_iso x i = if !Flag.track_iso_usage then {x with iso_info = i} else x
487 let set_mcode_data data (_,ar,info,mc,pos) = (data,ar,info,mc,pos)
488
489 (* --------------------------------------------------------------------- *)
490
491 (* unique indices, for mcode and tree nodes *)
492 let index_counter = ref 0
493 let fresh_index _ = let cur = !index_counter in index_counter := cur + 1; cur
494
495 (* --------------------------------------------------------------------- *)
496
497 let undots d =
498 match unwrap d with
499 | DOTS e -> e
500 | CIRCLES e -> e
501 | STARS e -> e
502
503 (* --------------------------------------------------------------------- *)
504
505 let rec ast0_type_to_type ty =
506 match unwrap ty with
507 ConstVol(cv,ty) -> Type_cocci.ConstVol(const_vol cv,ast0_type_to_type ty)
508 | BaseType(bty,None) ->
509 Type_cocci.BaseType(baseType bty,None)
510 | BaseType(bty,Some sgn) ->
511 Type_cocci.BaseType(baseType bty,Some (sign sgn))
512 | ImplicitInt(sgn) ->
513 let bty = Type_cocci.IntType in
514 Type_cocci.BaseType(bty,Some (sign sgn))
515 | Pointer(ty,_) -> Type_cocci.Pointer(ast0_type_to_type ty)
516 | FunctionPointer(ty,_,_,_,_,params,_) ->
517 Type_cocci.FunctionPointer(ast0_type_to_type ty)
518 | FunctionType _ -> failwith "not supported"
519 | Array(ety,_,_,_) -> Type_cocci.Array(ast0_type_to_type ety)
520 | StructUnionName(su,Some tag) ->
521 (match unwrap tag with
522 Id(tag) ->
523 Type_cocci.StructUnionName(structUnion su,false,unwrap_mcode tag)
524 | MetaId(tag,_,_) ->
525 (Printf.printf
526 "warning: struct/union with a metavariable name detected.\n";
527 Printf.printf
528 "For type checking assuming the name of the metavariable is the name of the type\n";
529 let (rule,tag) = unwrap_mcode tag in
530 Type_cocci.StructUnionName(structUnion su,true,rule^tag))
531 | _ -> failwith "unexpected struct/union type name")
532 | StructUnionName(su,None) -> failwith "nameless structure - what to do???"
533 | StructUnionDef(ty,_,_,_) -> ast0_type_to_type ty
534 | TypeName(name) -> Type_cocci.TypeName(unwrap_mcode name)
535 | MetaType(name,_) ->
536 Type_cocci.MetaType(unwrap_mcode name,Type_cocci.Unitary,false)
537 | DisjType(_,types,_,_) -> failwith "unexpected DisjType"
538 | OptType(ty) | UniqueType(ty) ->
539 ast0_type_to_type ty
540
541 and baseType t =
542 match unwrap_mcode t with
543 Ast.VoidType -> Type_cocci.VoidType
544 | Ast.CharType -> Type_cocci.CharType
545 | Ast.ShortType -> Type_cocci.ShortType
546 | Ast.IntType -> Type_cocci.IntType
547 | Ast.DoubleType -> Type_cocci.DoubleType
548 | Ast.FloatType -> Type_cocci.FloatType
549 | Ast.LongType -> Type_cocci.LongType
550
551 and structUnion t =
552 match unwrap_mcode t with
553 Ast.Struct -> Type_cocci.Struct
554 | Ast.Union -> Type_cocci.Union
555
556 and sign t =
557 match unwrap_mcode t with
558 Ast.Signed -> Type_cocci.Signed
559 | Ast.Unsigned -> Type_cocci.Unsigned
560
561 and const_vol t =
562 match unwrap_mcode t with
563 Ast.Const -> Type_cocci.Const
564 | Ast.Volatile -> Type_cocci.Volatile
565
566 (* --------------------------------------------------------------------- *)
567 (* this function is a rather minimal attempt. the problem is that information
568 has been lost. but since it is only used for metavariable types in the isos,
569 perhaps it doesn't matter *)
570 let make_mcode x = (x,NONE,default_info(),context_befaft(),ref NoMetaPos)
571 let make_mcode_info x info = (x,NONE,info,context_befaft(),ref NoMetaPos)
572
573 exception TyConv
574
575 let rec reverse_type ty =
576 match ty with
577 Type_cocci.ConstVol(cv,ty) ->
578 ConstVol(reverse_const_vol cv,wrap(reverse_type ty))
579 | Type_cocci.BaseType(bty,None) ->
580 BaseType(reverse_baseType bty,None)
581 | Type_cocci.BaseType(bty,Some sgn) ->
582 BaseType(reverse_baseType bty,Some (reverse_sign sgn))
583 | Type_cocci.Pointer(ty) ->
584 Pointer(wrap(reverse_type ty),make_mcode "*")
585 | Type_cocci.StructUnionName(su,mv,tag) ->
586 if mv
587 then
588 (* not right... *)
589 StructUnionName(reverse_structUnion su,
590 Some(wrap(MetaId(make_mcode ("",tag),[],Impure))))
591 else
592 StructUnionName(reverse_structUnion su,
593 Some (wrap(Id(make_mcode tag))))
594 | Type_cocci.TypeName(name) -> TypeName(make_mcode name)
595 | Type_cocci.MetaType(name,_,_) ->
596 MetaType(make_mcode name,Impure(*not really right*))
597 | _ -> raise TyConv
598
599 and reverse_baseType t =
600 make_mcode
601 (match t with
602 Type_cocci.VoidType -> Ast.VoidType
603 | Type_cocci.CharType -> Ast.CharType
604 | Type_cocci.BoolType -> Ast.IntType
605 | Type_cocci.ShortType -> Ast.ShortType
606 | Type_cocci.IntType -> Ast.IntType
607 | Type_cocci.DoubleType -> Ast.DoubleType
608 | Type_cocci.FloatType -> Ast.FloatType
609 | Type_cocci.LongType -> Ast.LongType)
610
611 and reverse_structUnion t =
612 make_mcode
613 (match t with
614 Type_cocci.Struct -> Ast.Struct
615 | Type_cocci.Union -> Ast.Union)
616
617 and reverse_sign t =
618 make_mcode
619 (match t with
620 Type_cocci.Signed -> Ast.Signed
621 | Type_cocci.Unsigned -> Ast.Unsigned)
622
623 and reverse_const_vol t =
624 make_mcode
625 (match t with
626 Type_cocci.Const -> Ast.Const
627 | Type_cocci.Volatile -> Ast.Volatile)
628
629 (* --------------------------------------------------------------------- *)
630
631 let lub_pure x y =
632 match (x,y) with
633 (Impure,_) | (_,Impure) -> Impure
634 | (Pure,Context) | (Context,Pure) -> Impure
635 | (Pure,_) | (_,Pure) -> Pure
636 | (_,Context) | (Context,_) -> Context
637 | _ -> PureContext
638
639 (* --------------------------------------------------------------------- *)
640
641 let rule_name = ref "" (* for the convenience of the parser *)