2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
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.
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.
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/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
23 module Ast
= Ast_cocci
25 (* --------------------------------------------------------------------- *)
28 type arity
= OPT
| UNIQUE
| NONE
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 }
36 (* MIXED is like CONTEXT, since sometimes MIXED things have to revert to
37 CONTEXT - see insert_plus.ml *)
38 type count
= ONE
(* + *) | MANY
(* ++ *)
41 MINUS
of (Ast.anything list list
* token_info
) ref
43 | CONTEXT
of (Ast.anything
Ast.befaft
* token_info
* token_info
) ref
44 | MIXED
of (Ast.anything
Ast.befaft
* token_info
* token_info
) ref
46 type position_info
= { line_start
: int; line_end
: int;
47 logical_start
: int; logical_end
: int;
48 column
: int; offset
: int; }
50 type info
= { pos_info
: position_info
;
51 attachable_start
: bool; attachable_end
: bool;
52 mcode_start
: mcodekind list
; mcode_end
: mcodekind list
;
53 (* the following are only for + code *)
54 strings_before
: (Ast.added_string
* position_info
) list
;
55 strings_after
: (Ast.added_string
* position_info
) list
}
57 (* adjacency index is incremented when we skip over dots or nest delimiters
58 it is used in deciding how much to remove, when two adjacent code tokens are
61 'a
* arity
* info
* mcodekind
* meta_pos
ref (* pos, - only *) *
62 int (* adjacency_index *)
63 (* int ref is an index *)
68 mcodekind
: mcodekind
ref;
69 exp_ty
: Type_cocci.typeC
option ref; (* only for expressions *)
70 bef_aft
: dots_bef_aft
; (* only for statements *)
71 true_if_arg
: bool; (* true if "arg_exp", only for exprs *)
72 true_if_test
: bool; (* true if "test position", only for exprs *)
73 true_if_test_exp
: bool;(* true if "test_exp from iso", only for exprs *)
74 (*nonempty if this represents the use of an iso*)
75 iso_info
: (string*anything
) list
}
78 NoDots
| AddingBetweenDots
of statement
| DroppingBetweenDots
of statement
80 (* for iso metavariables, true if they can only match nonmodified terms with
81 all metavariables unitary
82 for SP metavariables, true if the metavariable is unitary (valid up to
83 isomorphism phase only)
84 In SP, the only options are impure and context
86 and pure
= Impure
| Pure
| Context
| PureContext
(* pure and only context *)
88 (* --------------------------------------------------------------------- *)
89 (* --------------------------------------------------------------------- *)
97 and 'a dots
= 'a base_dots wrap
99 (* --------------------------------------------------------------------- *)
104 | MetaId
of Ast.meta_name mcode
* Ast.idconstraint
* pure
105 | MetaFunc
of Ast.meta_name mcode
* Ast.idconstraint
* pure
106 | MetaLocalFunc
of Ast.meta_name mcode
* Ast.idconstraint
* pure
108 | UniqueIdent
of ident
110 and ident
= base_ident wrap
112 (* --------------------------------------------------------------------- *)
115 and base_expression
=
117 | Constant
of Ast.constant mcode
118 | FunCall
of expression
* string mcode
(* ( *) *
119 expression dots
* string mcode
(* ) *)
120 | Assignment
of expression
* Ast.assignOp mcode
* expression
*
121 bool (* true if it can match an initialization *)
122 | CondExpr
of expression
* string mcode
(* ? *) * expression
option *
123 string mcode
(* : *) * expression
124 | Postfix
of expression
* Ast.fixOp mcode
125 | Infix
of expression
* Ast.fixOp mcode
126 | Unary
of expression
* Ast.unaryOp mcode
127 | Binary
of expression
* Ast.binaryOp mcode
* expression
128 | Nested
of expression
* Ast.binaryOp mcode
* expression
129 | Paren
of string mcode
(* ( *) * expression
*
131 | ArrayAccess
of expression
* string mcode
(* [ *) * expression
*
133 | RecordAccess
of expression
* string mcode
(* . *) * ident
134 | RecordPtAccess
of expression
* string mcode
(* -> *) * ident
135 | Cast
of string mcode
(* ( *) * typeC
* string mcode
(* ) *) *
137 | SizeOfExpr
of string mcode
(* sizeof *) * expression
138 | SizeOfType
of string mcode
(* sizeof *) * string mcode
(* ( *) *
139 typeC
* string mcode
(* ) *)
140 | TypeExp
of typeC
(* type name used as an expression, only in args *)
141 | MetaErr
of Ast.meta_name mcode
* constraints
* pure
142 | MetaExpr
of Ast.meta_name mcode
* constraints
*
143 Type_cocci.typeC list
option * Ast.form
* pure
144 | MetaExprList
of Ast.meta_name mcode
(* only in arg lists *) *
146 | EComma
of string mcode
(* only in arg lists *)
147 | DisjExpr
of string mcode
* expression list
*
148 string mcode list
(* the |s *) * string mcode
149 | NestExpr
of string mcode
* expression dots
* string mcode
*
150 expression
option * Ast.multi
151 | Edots
of string mcode
(* ... *) * expression
option
152 | Ecircles
of string mcode
(* ooo *) * expression
option
153 | Estars
of string mcode
(* *** *) * expression
option
154 | OptExp
of expression
155 | UniqueExp
of expression
157 and expression
= base_expression wrap
161 | NotIdCstrt
of Ast.idconstraint
162 | NotExpCstrt
of expression list
164 and listlen
= Ast.meta_name mcode
option
166 (* --------------------------------------------------------------------- *)
170 ConstVol
of Ast.const_vol mcode
* typeC
171 | BaseType
of Ast.baseType
* string mcode list
172 | Signed
of Ast.sign mcode
* typeC
option
173 | Pointer
of typeC
* string mcode
(* * *)
174 | FunctionPointer
of typeC
*
175 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
176 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
177 | FunctionType
of typeC
option *
178 string mcode
(* ( *) * parameter_list
*
180 | Array
of typeC
* string mcode
(* [ *) *
181 expression
option * string mcode
(* ] *)
182 | EnumName
of string mcode
(*enum*) * ident
(* name *)
183 | StructUnionName
of Ast.structUnion mcode
* ident
option (* name *)
184 | StructUnionDef
of typeC
(* either StructUnionName or metavar *) *
185 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
186 | TypeName
of string mcode
187 | MetaType
of Ast.meta_name mcode
* pure
188 | DisjType
of string mcode
* typeC list
* (* only after iso *)
189 string mcode list
(* the |s *) * string mcode
191 | UniqueType
of typeC
193 and typeC
= base_typeC wrap
195 (* --------------------------------------------------------------------- *)
196 (* Variable declaration *)
197 (* Even if the Cocci program specifies a list of declarations, they are
198 split out into multiple declarations of a single variable each. *)
200 and base_declaration
=
201 Init
of Ast.storage mcode
option * typeC
* ident
* string mcode
(*=*) *
202 initialiser
* string mcode
(*;*)
203 | UnInit
of Ast.storage mcode
option * typeC
* ident
* string mcode
(* ; *)
204 | TyDecl
of typeC
* string mcode
(* ; *)
205 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
206 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
207 | Typedef
of string mcode
(* typedef *) * typeC
* typeC
* string mcode
(*;*)
208 | DisjDecl
of string mcode
* declaration list
*
209 string mcode list
(* the |s *) * string mcode
210 (* Ddots is for a structure declaration *)
211 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
212 | OptDecl
of declaration
213 | UniqueDecl
of declaration
215 and declaration
= base_declaration wrap
217 (* --------------------------------------------------------------------- *)
220 and base_initialiser
=
221 MetaInit
of Ast.meta_name mcode
* pure
222 | InitExpr
of expression
223 | InitList
of string mcode
(*{*) * initialiser_list
* string mcode
(*}*)
225 designator list
(* name *) * string mcode
(*=*) *
226 initialiser
(* gccext: *)
227 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
229 | IComma
of string mcode
(* , *)
230 | Idots
of string mcode
(* ... *) * initialiser
option (* whencode *)
231 | OptIni
of initialiser
232 | UniqueIni
of initialiser
235 DesignatorField
of string mcode
(* . *) * ident
236 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
238 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
239 expression
* string mcode
(* ] *)
241 and initialiser
= base_initialiser wrap
243 and initialiser_list
= initialiser dots
245 (* --------------------------------------------------------------------- *)
248 and base_parameterTypeDef
=
250 | Param
of typeC
* ident
option
251 | MetaParam
of Ast.meta_name mcode
* pure
252 | MetaParamList
of Ast.meta_name mcode
* listlen
* pure
253 | PComma
of string mcode
254 | Pdots
of string mcode
(* ... *)
255 | Pcircles
of string mcode
(* ooo *)
256 | OptParam
of parameterTypeDef
257 | UniqueParam
of parameterTypeDef
259 and parameterTypeDef
= base_parameterTypeDef wrap
261 and parameter_list
= parameterTypeDef dots
263 (* --------------------------------------------------------------------- *)
264 (* #define Parameters *)
266 and base_define_param
=
268 | DPComma
of string mcode
269 | DPdots
of string mcode
(* ... *)
270 | DPcircles
of string mcode
(* ooo *)
271 | OptDParam
of define_param
272 | UniqueDParam
of define_param
274 and define_param
= base_define_param wrap
276 and base_define_parameters
=
278 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
280 and define_parameters
= base_define_parameters wrap
282 (* --------------------------------------------------------------------- *)
286 Decl
of (info
* mcodekind
) (* before the decl *) * declaration
287 | Seq
of string mcode
(* { *) * statement dots
*
289 | ExprStatement
of expression
* string mcode
(*;*)
290 | IfThen
of string mcode
(* if *) * string mcode
(* ( *) *
291 expression
* string mcode
(* ) *) *
292 statement
* (info
* mcodekind
) (* after info *)
293 | IfThenElse
of string mcode
(* if *) * string mcode
(* ( *) *
294 expression
* string mcode
(* ) *) *
295 statement
* string mcode
(* else *) * statement
*
297 | While
of string mcode
(* while *) * string mcode
(* ( *) *
298 expression
* string mcode
(* ) *) *
299 statement
* (info
* mcodekind
) (* after info *)
300 | Do
of string mcode
(* do *) * statement
*
301 string mcode
(* while *) * string mcode
(* ( *) *
302 expression
* string mcode
(* ) *) *
304 | For
of string mcode
(* for *) * string mcode
(* ( *) *
305 expression
option * string mcode
(*;*) *
306 expression
option * string mcode
(*;*) *
307 expression
option * string mcode
(* ) *) * statement
*
308 (info
* mcodekind
) (* after info *)
309 | Iterator
of ident
(* name *) * string mcode
(* ( *) *
310 expression dots
* string mcode
(* ) *) *
311 statement
* (info
* mcodekind
) (* after info *)
312 | Switch
of string mcode
(* switch *) * string mcode
(* ( *) *
313 expression
* string mcode
(* ) *) * string mcode
(* { *) *
314 statement
(*decl*) dots
*
315 case_line dots
* string mcode
(* } *)
316 | Break
of string mcode
(* break *) * string mcode
(* ; *)
317 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
318 | Label
of ident
* string mcode
(* : *)
319 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
320 | Return
of string mcode
(* return *) * string mcode
(* ; *)
321 | ReturnExpr
of string mcode
(* return *) * expression
*
323 | MetaStmt
of Ast.meta_name mcode
* pure
324 | MetaStmtList
of Ast.meta_name mcode
(*only in statement lists*) * pure
325 | Exp
of expression
(* only in dotted statement lists *)
326 | TopExp
of expression
(* for macros body *)
327 | Ty
of typeC
(* only at top level *)
328 | TopInit
of initialiser
(* only at top level *)
329 | Disj
of string mcode
* statement dots list
*
330 string mcode list
(* the |s *) * string mcode
331 | Nest
of string mcode
* statement dots
* string mcode
*
332 (statement dots
,statement
) whencode list
* Ast.multi
333 | Dots
of string mcode
(* ... *) *
334 (statement dots
,statement
) whencode list
335 | Circles
of string mcode
(* ooo *) *
336 (statement dots
,statement
) whencode list
337 | Stars
of string mcode
(* *** *) *
338 (statement dots
,statement
) whencode list
339 | FunDecl
of (info
* mcodekind
) (* before the function decl *) *
340 fninfo list
* ident
(* name *) *
341 string mcode
(* ( *) * parameter_list
* string mcode
(* ) *) *
342 string mcode
(* { *) * statement dots
*
344 | Include
of string mcode
(* #include *) * Ast.inc_file mcode
(* file *)
345 | Define
of string mcode
(* #define *) * ident
(* name *) *
346 define_parameters
(*params*) * statement dots
347 | OptStm
of statement
348 | UniqueStm
of statement
351 FStorage
of Ast.storage mcode
353 | FInline
of string mcode
354 | FAttr
of string mcode
356 and ('a
,'b
) whencode
=
359 | WhenModifier
of Ast.when_modifier
360 | WhenNotTrue
of expression
361 | WhenNotFalse
of expression
363 and statement
= base_statement wrap
366 Default
of string mcode
(* default *) * string mcode
(*:*) * statement dots
367 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*) *
369 | DisjCase
of string mcode
* case_line list
*
370 string mcode list
(* the |s *) * string mcode
371 | OptCase
of case_line
373 and case_line
= base_case_line wrap
375 (* --------------------------------------------------------------------- *)
379 MetaPos
of Ast.meta_name mcode
* Ast.meta_name list
* Ast.meta_collect
382 (* --------------------------------------------------------------------- *)
387 | CODE
of statement dots
388 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
389 | ERRORWORDS
of expression list
390 | OTHER
of statement
(* temporary, disappears after top_level.ml *)
392 and top_level
= base_top_level wrap
393 and rule
= top_level list
397 (rule
* Ast.metavar list
*
398 (string list
* string list
* Ast.dependency
* string * Ast.exists
)) *
399 (rule
* Ast.metavar list
) * Ast.ruletype
401 string * Ast.dependency
* (string * Ast.meta_name
) list
* string
402 | InitialScriptRule
of string * Ast.dependency
* string
403 | FinalScriptRule
of string * Ast.dependency
* string
405 (* --------------------------------------------------------------------- *)
408 DotsExprTag
of expression dots
409 | DotsInitTag
of initialiser dots
410 | DotsParamTag
of parameterTypeDef dots
411 | DotsStmtTag
of statement dots
412 | DotsDeclTag
of declaration dots
413 | DotsCaseTag
of case_line dots
415 | ExprTag
of expression
416 | ArgExprTag
of expression
(* for isos *)
417 | TestExprTag
of expression
(* for isos *)
419 | ParamTag
of parameterTypeDef
420 | InitTag
of initialiser
421 | DeclTag
of declaration
422 | StmtTag
of statement
423 | CaseLineTag
of case_line
424 | TopTag
of top_level
425 | IsoWhenTag
of Ast.when_modifier
426 | IsoWhenTTag
of expression
427 | IsoWhenFTag
of expression
428 | MetaPosTag
of meta_pos
430 let dotsExpr x
= DotsExprTag x
431 let dotsParam x
= DotsParamTag x
432 let dotsInit x
= DotsInitTag x
433 let dotsStmt x
= DotsStmtTag x
434 let dotsDecl x
= DotsDeclTag x
435 let dotsCase x
= DotsCaseTag x
436 let ident x
= IdentTag x
437 let expr x
= ExprTag x
438 let typeC x
= TypeCTag x
439 let param x
= ParamTag x
440 let ini x
= InitTag x
441 let decl x
= DeclTag x
442 let stmt x
= StmtTag x
443 let case_line x
= CaseLineTag x
446 (* --------------------------------------------------------------------- *)
447 (* Avoid cluttering the parser. Calculated in compute_lines.ml. *)
450 { line_start
= -1; line_end
= -1;
451 logical_start
= -1; logical_end
= -1;
452 column
= -1; offset
= -1; }
454 let default_info _
= (* why is this a function? *)
455 { pos_info = pos_info;
456 attachable_start
= true; attachable_end
= true;
457 mcode_start
= []; mcode_end
= [];
458 strings_before
= []; strings_after
= [] }
460 let default_befaft _
=
461 MIXED
(ref (Ast.NOTHING
,default_token_info,default_token_info))
462 let context_befaft _
=
463 CONTEXT
(ref (Ast.NOTHING
,default_token_info,default_token_info))
467 info
= default_info();
469 mcodekind
= ref (default_befaft());
473 true_if_test
= false;
474 true_if_test_exp
= false;
478 info
= default_info();
480 mcodekind
= ref (context_befaft());
484 true_if_test
= false;
485 true_if_test_exp
= false;
487 let unwrap x
= x
.node
488 let unwrap_mcode (x
,_
,_
,_
,_
,_
) = x
489 let rewrap model x
= { model
with node
= x
}
490 let rewrap_mcode (_
,arity
,info
,mcodekind
,pos
,adj
) x
=
491 (x
,arity
,info
,mcodekind
,pos
,adj
)
492 let copywrap model x
=
493 { model
with node
= x
; index
= ref !(model
.index
);
494 mcodekind
= ref !(model
.mcodekind
); exp_ty
= ref !(model
.exp_ty
)}
495 let get_pos (_
,_
,_
,_
,x
,_
) = !x
496 let get_pos_ref (_
,_
,_
,_
,x
,_
) = x
497 let set_pos pos
(m
,arity
,info
,mcodekind
,_
,adj
) =
498 (m
,arity
,info
,mcodekind
,ref pos
,adj
)
499 let get_info x
= x
.info
500 let set_info x info
= {x
with info
= info
}
501 let get_line x
= x
.info
.pos_info.line_start
502 let get_line_end x
= x
.info
.pos_info.line_end
503 let get_index x
= !(x
.index
)
504 let set_index x i
= x
.index
:= i
505 let get_mcodekind x
= !(x
.mcodekind
)
506 let get_mcode_mcodekind (_
,_
,_
,mcodekind
,_
,_
) = mcodekind
507 let get_mcodekind_ref x
= x
.mcodekind
508 let set_mcodekind x mk
= x
.mcodekind
:= mk
509 let set_type x t
= x
.exp_ty
:= t
510 let get_type x
= !(x
.exp_ty
)
511 let get_dots_bef_aft x
= x
.bef_aft
512 let set_dots_bef_aft x dots_bef_aft
= {x
with bef_aft
= dots_bef_aft
}
513 let get_arg_exp x
= x
.true_if_arg
514 let set_arg_exp x
= {x
with true_if_arg
= true}
515 let get_test_pos x
= x
.true_if_test
516 let set_test_pos x
= {x
with true_if_test
= true}
517 let get_test_exp x
= x
.true_if_test_exp
518 let set_test_exp x
= {x
with true_if_test_exp
= true}
519 let get_iso x
= x
.iso_info
520 let set_iso x i
= if !Flag.track_iso_usage
then {x
with iso_info
= i
} else x
521 let set_mcode_data data
(_
,ar
,info
,mc
,pos
,adj
) = (data
,ar
,info
,mc
,pos
,adj
)
523 (* --------------------------------------------------------------------- *)
525 (* unique indices, for mcode and tree nodes *)
526 let index_counter = ref 0
527 let fresh_index _
= let cur = !index_counter in index_counter := cur + 1; cur
529 (* --------------------------------------------------------------------- *)
537 (* --------------------------------------------------------------------- *)
539 let rec ast0_type_to_type ty
=
541 ConstVol
(cv
,ty
) -> Type_cocci.ConstVol
(const_vol cv
,ast0_type_to_type ty
)
542 | BaseType
(bty
,strings
) ->
543 Type_cocci.BaseType
(baseType bty
)
544 | Signed
(sgn
,None
) ->
545 Type_cocci.SignedT
(sign sgn
,None
)
546 | Signed
(sgn
,Some ty
) ->
547 let bty = ast0_type_to_type ty
in
548 Type_cocci.SignedT
(sign sgn
,Some
bty)
549 | Pointer
(ty
,_
) -> Type_cocci.Pointer
(ast0_type_to_type ty
)
550 | FunctionPointer
(ty
,_
,_
,_
,_
,params
,_
) ->
551 Type_cocci.FunctionPointer
(ast0_type_to_type ty
)
552 | FunctionType _
-> failwith
"not supported"
553 | Array
(ety
,_
,_
,_
) -> Type_cocci.Array
(ast0_type_to_type ety
)
554 | EnumName
(su
,tag
) ->
555 (match unwrap tag
with
557 Type_cocci.EnumName
(false,unwrap_mcode tag
)
560 "warning: enum with a metavariable name detected.\n";
562 "For type checking assuming the name of the metavariable is the name of the type\n";
563 let (rule
,tag
) = unwrap_mcode tag
in
564 Type_cocci.EnumName
(true,rule^tag
))
565 | _
-> failwith
"unexpected enum type name")
566 | StructUnionName
(su
,Some tag
) ->
567 (match unwrap tag
with
569 Type_cocci.StructUnionName
(structUnion su
,false,unwrap_mcode tag
)
572 "warning: struct/union with a metavariable name detected.\n";
574 "For type checking assuming the name of the metavariable is the name of the type\n";
575 let (rule
,tag
) = unwrap_mcode tag
in
576 Type_cocci.StructUnionName
(structUnion su
,true,rule^tag
))
577 | _
-> failwith
"unexpected struct/union type name")
578 | StructUnionName
(su
,None
) -> failwith
"nameless structure - what to do???"
579 | StructUnionDef
(ty
,_
,_
,_
) -> ast0_type_to_type ty
580 | TypeName
(name
) -> Type_cocci.TypeName
(unwrap_mcode name
)
581 | MetaType
(name
,_
) ->
582 Type_cocci.MetaType
(unwrap_mcode name
,Type_cocci.Unitary
,false)
583 | DisjType
(_
,types
,_
,_
) ->
585 "disjtype not supported in smpl type inference, assuming unknown";
587 | OptType
(ty
) | UniqueType
(ty
) ->
590 and baseType
= function
591 Ast.VoidType
-> Type_cocci.VoidType
592 | Ast.CharType
-> Type_cocci.CharType
593 | Ast.ShortType
-> Type_cocci.ShortType
594 | Ast.IntType
-> Type_cocci.IntType
595 | Ast.DoubleType
-> Type_cocci.DoubleType
596 | Ast.FloatType
-> Type_cocci.FloatType
597 | Ast.LongType
-> Type_cocci.LongType
598 | Ast.LongLongType
-> Type_cocci.LongLongType
601 match unwrap_mcode t
with
602 Ast.Struct
-> Type_cocci.Struct
603 | Ast.Union
-> Type_cocci.Union
606 match unwrap_mcode t
with
607 Ast.Signed
-> Type_cocci.Signed
608 | Ast.Unsigned
-> Type_cocci.Unsigned
611 match unwrap_mcode t
with
612 Ast.Const
-> Type_cocci.Const
613 | Ast.Volatile
-> Type_cocci.Volatile
615 (* --------------------------------------------------------------------- *)
616 (* this function is a rather minimal attempt. the problem is that information
617 has been lost. but since it is only used for metavariable types in the isos,
618 perhaps it doesn't matter *)
619 and make_mcode x
= (x
,NONE
,default_info(),context_befaft(),ref NoMetaPos
,-1)
620 let make_mcode_info x info
= (x
,NONE
,info
,context_befaft(),ref NoMetaPos
,-1)
624 let rec reverse_type ty
=
626 Type_cocci.ConstVol
(cv
,ty
) ->
627 ConstVol
(reverse_const_vol cv
,context_wrap(reverse_type ty
))
628 | Type_cocci.BaseType
(bty) ->
629 BaseType
(reverse_baseType
bty,[(* not used *)])
630 | Type_cocci.SignedT
(sgn
,None
) -> Signed
(reverse_sign sgn
,None
)
631 | Type_cocci.SignedT
(sgn
,Some
bty) ->
632 Signed
(reverse_sign sgn
,Some
(context_wrap(reverse_type ty
)))
633 | Type_cocci.Pointer
(ty
) ->
634 Pointer
(context_wrap(reverse_type ty
),make_mcode
"*")
635 | Type_cocci.EnumName
(mv
,tag
) ->
642 context_wrap(MetaId
(make_mcode
(rule,tag
),Ast.IdNoConstraint
,
645 EnumName
(make_mcode
"enum",context_wrap(Id
(make_mcode tag
)))
646 | Type_cocci.StructUnionName
(su
,mv
,tag
) ->
652 (reverse_structUnion su
,
653 Some
(context_wrap(MetaId
(make_mcode
(rule,tag
),Ast.IdNoConstraint
,
657 (reverse_structUnion su
,
658 Some
(context_wrap(Id
(make_mcode tag
))))
659 | Type_cocci.TypeName
(name
) -> TypeName
(make_mcode name
)
660 | Type_cocci.MetaType
(name
,_
,_
) ->
661 MetaType
(make_mcode name
,Impure
(*not really right*))
664 and reverse_baseType
= function
665 Type_cocci.VoidType
-> Ast.VoidType
666 | Type_cocci.CharType
-> Ast.CharType
667 | Type_cocci.BoolType
-> Ast.IntType
668 | Type_cocci.ShortType
-> Ast.ShortType
669 | Type_cocci.IntType
-> Ast.IntType
670 | Type_cocci.DoubleType
-> Ast.DoubleType
671 | Type_cocci.FloatType
-> Ast.FloatType
672 | Type_cocci.LongType
-> Ast.LongType
673 | Type_cocci.LongLongType
-> Ast.LongLongType
675 and reverse_structUnion t
=
678 Type_cocci.Struct
-> Ast.Struct
679 | Type_cocci.Union
-> Ast.Union
)
684 Type_cocci.Signed
-> Ast.Signed
685 | Type_cocci.Unsigned
-> Ast.Unsigned
)
687 and reverse_const_vol t
=
690 Type_cocci.Const
-> Ast.Const
691 | Type_cocci.Volatile
-> Ast.Volatile
)
693 (* --------------------------------------------------------------------- *)
697 (Impure
,_
) | (_
,Impure
) -> Impure
698 | (Pure
,Context
) | (Context
,Pure
) -> Impure
699 | (Pure
,_
) | (_
,Pure
) -> Pure
700 | (_
,Context
) | (Context
,_
) -> Context
703 (* --------------------------------------------------------------------- *)
705 let rule_name = ref "" (* for the convenience of the parser *)