(* set in comment_annotater_c.ml *)
comments_tag: comments_around ref;
+ (* annotations on the token (mutable) *)
+ mutable annots_tag: Token_annot.annots
+
(* todo? token_info : sometimes useful to know what token it was *)
}
and il = info list
and typeC = typeCbis wrap (* todo reput wrap3 *)
and typeCbis =
- NoType (* for c++ only *)
+ NoType (* for c++ only, and for K&R C *)
| BaseType of baseType
| Pointer of fullType
and expression = (expressionbis * exp_info ref (* semantic: *)) wrap3
and exp_info = exp_type option * test
and exp_type = fullType (* Type_c.completed_and_simplified *) * local
- and local = LocalVar of parse_info | NotLocalVar (* cocci: *)
+ and local = LocalVar of parse_info | StaticLocalVar of parse_info
+ | NotLocalVar (* cocci: *)
and test = Test | NotTest (* cocci: *)
and expressionbis =
(* gccext: *)
| StatementExpr of compound wrap (* ( ) new scope *)
- | Constructor of fullType * initialiser wrap2 (* , *) list
+ | Constructor of fullType * initialiser
(* for unparser: *)
| ParenExpr of expression
(* for C++: *)
- | New of argument
+ | New of (argument wrap2 (* , *) list) option * argument
| Delete of expression
(* cppext: IfdefExpr TODO *)
and arithOp =
| Plus | Minus | Mul | Div | Mod
| DecLeft | DecRight
- | And | Or | Xor
+ | And | Or | Xor | Max | Min
and logicalOp =
| Inf | Sup | InfEq | SupEq
and exprStatement = expression option
+ and declOrExpr = ForDecl of declaration | ForExp of expression option wrap
+
(* for Switch, need check that all elements in the compound start
* with a case:, otherwise unreachable code.
*)
and iteration =
| While of expression * statement
| DoWhile of statement * expression
- | For of exprStatement wrap * exprStatement wrap * exprStatement wrap *
+ | For of declOrExpr * exprStatement wrap * exprStatement wrap *
statement
(* cppext: *)
| MacroIteration of string * argument wrap2 list * statement
and declaration =
| DeclList of onedecl wrap2 (* , *) list wrap (* ; fakestart sto *)
(* cppext: *)
- | MacroDecl of (string * argument wrap2 list) wrap (* fakestart *)
+ (* bool is true if there is a ; at the end *)
+ | MacroDecl of (string * argument wrap2 list * bool) wrap (* fakestart *)
+ | MacroDeclInit of
+ (string * argument wrap2 list * initialiser) wrap (* fakestart *)
and onedecl =
{ v_namei: (name * v_init) option;
| DefineFunction of definition
| DefineInit of initialiser (* in practice only { } with possible ',' *)
- (* TODO DefineMulti of define_val list *)
+ | DefineMulti of statement list
| DefineText of string wrap
| DefineEmpty
| FinalDef of info (* EOF *)
+ (* c++ *)
+ | Namespace of toplevel list * il
+
(* ------------------------------------------------------------------------- *)
and program = toplevel list
let fakeInfo pi =
{ pinfo = FakeTok ("",no_virt_pos);
cocci_tag = ref emptyAnnot;
+ annots_tag = Token_annot.empty;
comments_tag = ref emptyComments;
}
let equal_posl (l1,c1) (l2,c2) =
(l1 =|= l2) && (c1 =|= c2)
+let compare_posl (l1,c1) (l2,c2) =
+ match l2 - l1 with
+ 0 -> c2 - c1
+ | r -> r
+
let info_to_fixpos ii =
match pinfo_of_info ii with
OriginTok pi -> Ast_cocci.Real pi.Common.charpos
file = "";
str = str_of_info x});
cocci_tag = ref emptyAnnot;
+ annots_tag = Token_annot.empty;
comments_tag = ref emptyComments;
}
file = "";
str = str_of_info x});
cocci_tag = ref emptyAnnot;
+ annots_tag = Token_annot.empty;
comments_tag = ref emptyComments;
}
file = "";
str = str_of_info x});
cocci_tag = ref emptyAnnot;
+ annots_tag = Token_annot.empty;
comments_tag = ref (al_comments !(x.comments_tag));
}
let semi_al_info_cpp x =
{ x with
cocci_tag = ref emptyAnnot;
+ annots_tag = Token_annot.empty;
comments_tag = ref (al_comments !(x.comments_tag));
}
file = "";
str = str_of_info x});
cocci_tag = ref emptyAnnot;
+ annots_tag = Token_annot.empty;
comments_tag = ref (al_comments !(x.comments_tag));
}
let empty_ii = [] in
(e, empty_ii)::unsplit_comma xs
| Right ii::_ ->
- raise Impossible
+ raise (Impossible 59)
s, [iis]
| CppConcatenatedName xs ->
(match xs with
- | [] -> raise Impossible
+ | [] -> raise (Impossible 60)
| ((s,iis),noiiop)::xs ->
s, iis
)
(* bugfix: because of string->name, the ii can be deeper *)
let ii = get_local_ii_of_tybis_inlining_ii_of_name ty in
match ii with
- | ii::_ -> ii.pinfo
- | [] -> failwith "type has no text; need to think again"
+ | ii::_ -> Some ii.pinfo
+ | [] -> None
(* only Label and Goto have name *)
let get_local_ii_of_st_inlining_ii_of_name st =
let name_of_parameter param =
param.p_namei +> Common.map_option (str_of_name)
+
+(* ------------------------------------------------------------------------- *)
+(* Annotations on tokens *)
+(* ------------------------------------------------------------------------- *)
+
+(* to put a given annotation on a token *)
+let put_annot_info info key value =
+ info.annots_tag <- Token_annot.put_annot key value info.annots_tag
+
+(* to check if an annotation has such a token *)
+let get_annot_info info key =
+ Token_annot.get_annot info.annots_tag key
+