diff --git a/cocci.ml b/cocci.ml index 8d72992391cab4d96481b9b37fa9674de47ef706..3f315d4cc988152f298c529243e265d79e357e4b 100644 --- a/cocci.ml +++ b/cocci.ml @@ -596,11 +596,11 @@ let sp_contain_typed_metavar_z toplevel_list_list = Visitor_ast.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing expression donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing in toplevel_list_list +> List.exists diff --git a/engine/asttoctl2.ml b/engine/asttoctl2.ml index 67ec815f1a3753f0260a9c9ba04afc3e81f5fe17..51d574fa4241deea2d960e08d028bbb99a9fd885 100644 --- a/engine/asttoctl2.ml +++ b/engine/asttoctl2.ml @@ -341,9 +341,10 @@ let elim_opt = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing stmtdotsfn donothing donothing donothing donothing - donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing + donothing (* --------------------------------------------------------------------- *) (* after management *) @@ -464,11 +465,12 @@ let contains_modif = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - do_nothing do_nothing do_nothing do_nothing do_nothing + do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing init do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in + do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing + do_nothing in recursor.V.combiner_rule_elem let contains_pos = @@ -495,8 +497,9 @@ let contains_pos = do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing do_nothing - do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in + do_nothing do_nothing do_nothing + do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing + do_nothing in recursor.V.combiner_rule_elem (* code is not a DisjRuleElem *) @@ -592,10 +595,10 @@ let count_nested_braces s = let recursor = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing stmt_count donothing donothing donothing in + donothing donothing donothing donothing donothing donothing donothing + donothing donothing donothing stmt_count donothing donothing donothing in let res = string_of_int (recursor.V.combiner_statement s) in string2var ("p"^res) @@ -2682,10 +2685,10 @@ and drop_minuses stmt_dots = V.rebuilder mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing donothing in + donothing donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing in v.V.rebuilder_statement_dots stmt_dots and find_xx = function diff --git a/engine/asttomember.ml b/engine/asttomember.ml index eb825ec8dc4657af96b3a2e78c16f85fde439d21..a893a833508bf8793fafab11aa0db4156085c2b2 100644 --- a/engine/asttomember.ml +++ b/engine/asttomember.ml @@ -46,8 +46,9 @@ let contains_modif used_after x = do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing do_nothing - do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in + do_nothing do_nothing do_nothing + do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing + do_nothing in recursor.V.combiner_rule_elem x (* contains an inherited metavariable or contains a constant *) @@ -71,10 +72,11 @@ let contains_constant x = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing + do_nothing ident expr do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing in + do_nothing do_nothing in recursor.V.combiner_rule_elem x | _ -> true @@ -133,9 +135,9 @@ let strip x = mcode mcode mcode mcode mcode do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing do_nothing do_nothing do_nothing do_nothing + do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing decl_or_field do_absolutely_nothing decl_or_field do_absolutely_nothing - rule_elem + do_nothing rule_elem do_nothing do_nothing do_nothing do_absolutely_nothing in r.V.rebuilder_rule_elem x @@ -200,9 +202,10 @@ let find_commonalities res : Ast_cocci.rule_elem option = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing expression do_nothing do_nothing do_nothing do_nothing - do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing + expression do_nothing do_nothing do_nothing do_nothing + do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing + do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing in recursor.V.combiner_rule_elem x in match res with diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index e4d68add83c4003b992affaf83f3d3e6a67347ff..245770d73a358c5b059dc3dbcaf76541de4cd440 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -2289,7 +2289,7 @@ and (declaration: (A.mcodekind * bool * A.declaration,B.declaration) matcher) = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing in + donothing donothing donothing donothing in v.Visitor_ast.rebuilder_declaration decla in xs +> List.fold_left (fun acc var -> @@ -3304,14 +3304,14 @@ and (struct_field: (A.annotated_field, B.field) matcher) = and enum_fields = fun eas ebs -> let match_dots ea = match A.unwrap ea with - A.Edots(mcode, optexpr) -> Some (mcode, optexpr) + A.EnumDots(mcode, optexpr) -> Some (mcode, optexpr) | _ -> None in - let build_dots (mcode, optexpr) = A.Edots(mcode, optexpr) in + let build_dots (mcode, optexpr) = A.EnumDots(mcode, optexpr) in let match_comma ea = match A.unwrap ea with - A.EComma ia1 -> Some ia1 + A.EnumComma ia1 -> Some ia1 | _ -> None in - let build_comma ia1 = A.EComma ia1 in + let build_comma ia1 = A.EnumComma ia1 in let match_metalist ea = None in let build_metalist _ (ida,leninfo,cstr,keep,inherited) = failwith "enum: build meta list: not possible" in @@ -3326,29 +3326,21 @@ and enum_fields = fun eas ebs -> and enum_field ida idb = X.all_bound (A.get_inherited ida) >&&> match A.unwrap ida, idb with - A.Ident(id),(nameidb,None) -> - ident_cpp DontKnow id nameidb >>= (fun id nameidb -> - return ((A.Ident id) +> A.rewrap ida, (nameidb,None))) - | A.Ident(id),(nameidb,Some _) -> fail (* should we have an iso? *) - | A.Assignment(ea1,opa,ea2,init),(nameidb,Some(opbi,eb2)) -> - (match A.unwrap ea1 with - A.Ident(id) -> - let assignOp opa0 opbi = - match A.unwrap opa0 with - A.SimpleAssign oa -> - tokenf oa opbi >>= fun oa opbi -> - return - (A.rewrap opa (A.SimpleAssign oa), opbi) - | _ -> failwith "only simple assignment possible here" in - ident_cpp DontKnow id nameidb >>= (fun id nameidb -> - expression ea2 eb2 >>= (fun ea2 eb2 -> - assignOp opa opbi >>= (fun opa opbi ->(* only one kind of assignop *) + A.Enum(nameida,enum_vala),(nameidb,enum_valb) -> + (match enum_vala,enum_valb with + (None, Some _) + | (Some _, None) -> fail + | (None, None) -> + ident_cpp DontKnow nameida nameidb >>= + (fun nameida nameidb -> + return (A.Enum(nameida,None) +> A.rewrap ida, (nameidb,None))) + | (Some (eqa,evala), Some(eqb,evalb)) -> + ident_cpp DontKnow nameida nameidb >>= (fun nameida nameidb -> + tokenf eqa eqb >>= (fun eqa eqb -> + expression evala evalb >>= (fun ea eb -> return ( - (A.Assignment((A.Ident(id)) +> A.rewrap ea1,opa,ea2,init)) +> - A.rewrap ida, - (nameidb,Some(opbi,eb2)))))) - | _ -> failwith "enum: assignment: not possible") - | A.Assignment(ea1,opa,ea2,init),(nameidb,None) -> fail + (A.Enum(nameida,Some(eqa,ea)) +> A.rewrap ida), + (nameidb,Some(eqb,eb))))))) | _ -> failwith ("not possible: "^(Dumper.dump (A.unwrap ida))) (* ------------------------------------------------------------------------- *) diff --git a/engine/transformation_c.ml b/engine/transformation_c.ml index 9f0b0ab27f89500fcb931e8f674566036b90bec5..4de8fe51a6fe44fc0b458ec471f895d234da0d77 100644 --- a/engine/transformation_c.ml +++ b/engine/transformation_c.ml @@ -287,11 +287,11 @@ module XTRANS = struct let fn = Visitor_ast.rebuilder mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing ident expression donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing in + donothing donothing donothing in fn.Visitor_ast.rebuilder_anything anything diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli index 3a5f184aed23f45340987f8fb0e9fae08afdd8c4..d8f7884e5d052fd71651c31e87f645cb1600f67d 100644 --- a/ocaml/coccilib.mli +++ b/ocaml/coccilib.mli @@ -2716,7 +2716,7 @@ module Ast_cocci : | Decimal of string mcode * string mcode * expression * string mcode option * expression option * string mcode | EnumName of string mcode * ident option - | EnumDef of fullType * string mcode * expression dots * string mcode + | EnumDef of fullType * string mcode * enum_decl dots * string mcode | StructUnionName of structUnion mcode * ident option | StructUnionDef of fullType * string mcode * annotated_field dots * string mcode @@ -2793,6 +2793,12 @@ module Ast_cocci : | ConjField of annotated_field list | OptField of annotated_field and annotated_field = base_annotated_field wrap + and base_enum_decl = + Ast_cocci.base_enum_decl = + Enum of ident * (string mcode * expression) option + | EnumComma of string mcode + | EnumDots of string mcode * enum_decl option + and enum_decl = base_enum_decl wrap and base_initialiser = Ast_cocci.base_initialiser = MetaInit of meta_name mcode * constraints * keep_binding * inherited @@ -3054,6 +3060,7 @@ module Ast_cocci : | LogicalOpTag of logicalOp | DeclarationTag of declaration | FieldTag of field + | EnumDeclTag of enum_decl | InitTag of initialiser | StorageTag of storage | IncFileTag of inc_file @@ -3071,6 +3078,7 @@ module Ast_cocci : | StmtDotsTag of statement dots | AnnDeclDotsTag of annotated_decl dots | AnnFieldDotsTag of annotated_field dots + | EnumDeclDotsTag of enum_decl dots | DefParDotsTag of define_param dots | TypeCTag of typeC | ParamTag of parameterTypeDef @@ -3361,7 +3369,7 @@ module Ast0_cocci : | Decimal of string mcode * string mcode * expression * string mcode option * expression option * string mcode | EnumName of string mcode * ident option - | EnumDef of typeC * string mcode * expression dots * string mcode + | EnumDef of typeC * string mcode * enum_decl dots * string mcode | StructUnionName of Ast_cocci.structUnion mcode * ident option | StructUnionDef of typeC * string mcode * field dots * string mcode | TypeOfExpr of string mcode * string mcode * expression * string mcode @@ -3413,6 +3421,13 @@ module Ast0_cocci : | OptField of field and bitfield = string mcode * expression and field = base_field wrap + and base_enum_decl = + Ast0_cocci.base_enum_decl = + Enum of ident * (string mcode * expression) option + | EnumComma of string mcode + | EnumDots of string mcode * + (string mcode * string mcode * enum_decl) option + and enum_decl = base_enum_decl wrap and base_initialiser = Ast0_cocci.base_initialiser = MetaInit of Ast_cocci.meta_name mcode * constraints * pure @@ -3613,6 +3628,7 @@ module Ast0_cocci : | DotsStmtTag of statement dots | DotsDeclTag of declaration dots | DotsFieldTag of field dots + | DotsEnumDeclTag of enum_decl dots | DotsCaseTag of case_line dots | DotsDefParamTag of define_param dots | IdentTag of ident @@ -3626,6 +3642,7 @@ module Ast0_cocci : | InitTag of initialiser | DeclTag of declaration | FieldTag of field + | EnumDeclTag of enum_decl | StmtTag of statement | ForInfoTag of forinfo | CaseLineTag of case_line @@ -3643,6 +3660,7 @@ module Ast0_cocci : val dotsStmt : statement dots -> anything val dotsDecl : declaration dots -> anything val dotsField : field dots -> anything + val dotsEnumDecl : enum_decl dots -> anything val dotsCase : case_line dots -> anything val dotsDefParam : define_param dots -> anything val ident : ident -> anything diff --git a/parsing_c/control_flow_c_build.ml b/parsing_c/control_flow_c_build.ml index b500ed00bab9239817f9e8250a06fcd4a6a3bf76..19254ec9af21b3074a9ad272aa79b1a8961a3134 100644 --- a/parsing_c/control_flow_c_build.ml +++ b/parsing_c/control_flow_c_build.ml @@ -1562,8 +1562,15 @@ let deadcode_detection (g : Control_flow_c.cflow) = | x -> (match Control_flow_c.extract_fullstatement node with | Some st -> - let ii = Ast_c.get_ii_st_take_care st in - raise (Error (DeadCode (Some (pinfo_of_ii ii)))) + let ii = Ast_c.get_ii_st_take_care st in + let loc = + try Some (pinfo_of_ii ii) + with _ -> + begin + Printf.eprintf "dead code problem in: %s\n" (Dumper.dump st); + None + end in + raise (Error (DeadCode loc)) | _ -> pr2 "CFG: orphan nodes, maybe something weird happened" ) ) diff --git a/parsing_c/includes.ml b/parsing_c/includes.ml index 5c742647956a683f477823c79b4f4cc2db172fc7..4dc1e02dcdf60d32ca1dc3e012e769361be4a73a 100644 --- a/parsing_c/includes.ml +++ b/parsing_c/includes.ml @@ -120,10 +120,14 @@ let should_parse parsing_style filename incl = match parsing_style with let resolve filename parsingstyle x = let all_includes = parse_all_includes parsingstyle in let dir = Filename.dirname filename in + let clean s = + if Str.string_match (Str.regexp_string "./") s 0 + then String.sub s 2 (String.length s - 2) + else s in match x with | Ast_c.Local include_path -> let relpath = String.concat "/" include_path in - let f = Filename.concat dir relpath in + let f = Filename.concat dir (clean relpath) in if (Sys.file_exists f) then Some f else if !relax_include_path diff --git a/parsing_c/lexer_c.mll b/parsing_c/lexer_c.mll index d5ef75e5589bb9e63fe26d0a169197c3a5189d59..cf94c24573940838d586d98fc3cc0bd173cf0f5b 100644 --- a/parsing_c/lexer_c.mll +++ b/parsing_c/lexer_c.mll @@ -855,7 +855,20 @@ rule token = parse * now done in parse_c.ml. *) - | None -> TIdent (s, info) + | None -> + (* get information from the semantic patch *) + (* typedef is not done due to tyex.cocci *) + (* attributes not done due to roa; don't know + whether to use MacroAttr or MacroEndAttr *) + (*if List.mem s !Data.type_names + then TypedefIdent (s, info) + else if List.mem s !Data.attr_names + then TMacroAttr (s, info) + else*) if List.mem s !Data.declarer_names + then TMacroDecl (s, info) + else if List.mem s !Data.iterator_names + then TMacroIterator (s, info) + else TIdent (s, info) ) } (* gccext: apparently gcc allows dollar in variable names. found such diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml index 428261f622f1db175f4aac5a8502569c129c2d4d..e33e7cbf2d6357c5800cee0972f39f1e04c5588d 100644 --- a/parsing_c/parse_c.ml +++ b/parsing_c/parse_c.ml @@ -983,12 +983,12 @@ let rec _parse_print_error_heuristic2 saved_typedefs saved_macros Some result end - and handle_include file wrapped_incl k = let incl = Ast_c.unwrap wrapped_incl.Ast_c.i_include in let parsing_style = Includes.get_parsing_style () in if Includes.should_parse parsing_style file incl - then begin match Includes.resolve file parsing_style incl with + then + match Includes.resolve file parsing_style incl with | Some header_filename when Common.lfile_exists header_filename -> (if !Flag_parsing_c.verbose_includes then pr2 ("including "^header_filename)); @@ -996,8 +996,6 @@ and handle_include file wrapped_incl k = match incl with Ast_c.NonLocal _ -> true | _ -> false in ignore (k nonlocal header_filename) | _ -> () - end - and _parse_print_error_heuristic2bis saved_typedefs saved_macros parse_strings file use_header_cache = diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index bfe92e18e02a5d6d1483f06f0074844dfa9d3995..8a551213b2663a69297be4ec996c114ce6148592 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -211,6 +211,13 @@ let fixDeclSpecForParam = function ({storageD = (st,iist)} as r) -> (Semantic ("storage class specified for parameter of function", fake_pi)) +let fixDeclSpecForArg = function ({storageD = (st,iist)} as r) -> + let ((qu,ty) as v,_st) = fixDeclSpecForDecl r in + match st with + | (Sto Register) -> (v, true), iist + | (Sto _) -> (v, false), iist + | NoSto | StoTypedef -> (v, false), iist + let fixDeclSpecForMacro = function ({storageD = (st,iist)} as r) -> let ((qu,ty) as v,_st) = fixDeclSpecForDecl r in match st with @@ -945,13 +952,13 @@ string_format: /*(* to avoid conflicts have to introduce a _not_empty (ne) version *)*/ argument_ne: | assign_expr { Left $1 } - | parameter_decl { Right (ArgType $1) } + | parameter_decl_arg { Right (ArgType $1) } | action_higherordermacro_ne { Right (ArgAction $1) } argument: | assign_expr { Left $1 } - | parameter_decl { Right (ArgType $1) } + | parameter_decl_arg { Right (ArgType $1) } /*(* had conflicts before, but julia fixed them *)*/ | action_higherordermacro { Right (ArgAction $1) } @@ -1465,8 +1472,41 @@ parameter_decl2: } } | decl_spec + { let ((returnType,hasreg), iihasreg) = fixDeclSpecForParam (snd $1) in + { p_namei = None; + p_type = returnType; + p_register = hasreg, iihasreg; + } + } + +parameter_decl_arg: /* more tolerant */ + TKRParam { + let name = RegularName (mk_string_wrap $1) in + LP.add_ident (str_of_name name); + { p_namei = Some name; + p_type = mk_ty NoType []; + p_register = (false, []); + } + } + | decl_spec declaratorp { LP.kr_impossible(); - let ((returnType,hasreg), iihasreg) = fixDeclSpecForParam (snd $1) in + let ((returnType,hasreg),iihasreg) = fixDeclSpecForArg (snd $1) in + let (name, ftyp) = $2 in + { p_namei = Some (name); + p_type = ftyp returnType; + p_register = (hasreg, iihasreg); + } + } + | decl_spec abstract_declaratorp + { LP.kr_impossible(); + let ((returnType,hasreg), iihasreg) = fixDeclSpecForArg (snd $1) in + { p_namei = None; + p_type = $2 returnType; + p_register = hasreg, iihasreg; + } + } + | decl_spec + { let ((returnType,hasreg), iihasreg) = fixDeclSpecForArg (snd $1) in { p_namei = None; p_type = returnType; p_register = hasreg, iihasreg; diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index 10de496e5eaf5b6f50178e0cd1ea6d5e30a5b1d1..4b247275e50a6e40fd9ca758348045060b08c183 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -738,7 +738,7 @@ and typeC ty = | Ast.EnumDef(ty,lb,ids,rb) -> fullType ty; ft_space ty; mcode print_string lb; - dots force_newline expression ids; + dots force_newline enum_decl ids; mcode print_string rb | Ast.StructUnionName(kind,name) -> mcode structUnion kind; print_option_prespace ident name @@ -953,6 +953,24 @@ and annotated_field d = | Ast.OptField(decl) -> raise CantBeInPlus | Ast.Fdots(_,_) -> raise CantBeInPlus +and enum_decl d = + match Ast.unwrap d with + Ast.Enum(name,enum_val) -> + ident name; + pr_space(); + print_option + (function (eq,eval) -> + mcode print_string eq; pr_space(); expression eval) enum_val + | Ast.EnumComma(cm) -> + mcode (print_string_with_hint (SpaceOrNewline (ref " "))) cm + | Ast.EnumDots(dots,whencode) when generating -> + mcode print_string dots; + print_option + (function w -> + print_text " when != "; + enum_decl w) whencode + | Ast.EnumDots(dots,whencode) -> raise CantBeInPlus + (* --------------------------------------------------------------------- *) (* Initialiser *) @@ -1421,6 +1439,7 @@ let pp_any = function | Ast.InitTag(x) -> initialiser false x; false | Ast.DeclarationTag(x) -> declaration x; false | Ast.FieldTag(x) -> field x; false + | Ast.EnumDeclTag(x) -> enum_decl x; false | Ast.StorageTag(x) -> storage x unknown unknown; false | Ast.IncFileTag(x) -> inc_file x unknown unknown; false @@ -1474,6 +1493,7 @@ let pp_any = function | Ast.StmtDotsTag(x) -> dots force_newline (statement "") x; false | Ast.AnnDeclDotsTag(x) -> dots force_newline annotated_decl x; false | Ast.AnnFieldDotsTag(x) -> dots force_newline annotated_field x; false + | Ast.EnumDeclDotsTag(x) -> dots force_newline enum_decl x; false | Ast.DefParDotsTag(x) -> dots (fun _ -> ()) print_define_param x; false | Ast.TypeCTag(x) -> typeC x; false @@ -1506,7 +1526,7 @@ in force_newline(); force_newline() | (Ast.Directive _::_) | (Ast.Rule_elemTag _::_) | (Ast.StatementTag _::_) - | (Ast.FieldTag _::_) | (Ast.InitTag _::_) + | (Ast.FieldTag _::_) | (Ast.EnumDeclTag _::_) | (Ast.InitTag _::_) | (Ast.DeclarationTag _::_) | (Ast.Token ("}",_)::_) -> prnl hd | _ -> () in let newline_after _ = @@ -1517,7 +1537,8 @@ in (if isfn s then force_newline()); force_newline() | (Ast.Directive _::_) | (Ast.StmtDotsTag _::_) - | (Ast.Rule_elemTag _::_) | (Ast.FieldTag _::_) | (Ast.InitTag _::_) + | (Ast.Rule_elemTag _::_) | (Ast.FieldTag _::_) + | (Ast.EnumDeclTag _::_)| (Ast.InitTag _::_) | (Ast.DeclarationTag _::_) | (Ast.Token ("{",_)::_) -> force_newline() | _ -> () in diff --git a/parsing_c/unparse_hrule.ml b/parsing_c/unparse_hrule.ml index 6b766f3cf54925dd09e9a9697c1c4b368e66a160..f2605d82c6cd1160f7ccb49c831e1605507cacef 100644 --- a/parsing_c/unparse_hrule.ml +++ b/parsing_c/unparse_hrule.ml @@ -133,10 +133,10 @@ let get_function_name rule env = (V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing expression donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing donothing donothing donothing donothing donothing).V.combiner_top_level rule in match names with diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index 76db1c818409d13825e867c89881c5de091911a4..97f49132e3496421d09e467d92af148945761acf 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -452,7 +452,7 @@ and top_typeC tgt opt_allowed typ = (List.map mcode2arity [lb;rb]) in let ty = typeC arity ty in let lb = mcode lb in - let ids = dots (expression tgt) decls in + let ids = dots (enum_decl tgt) decls in let rb = mcode rb in make_typeC typ tgt arity (Ast0.EnumDef(ty,lb,ids,rb)) | Ast0.StructUnionName(kind,name) -> @@ -694,6 +694,29 @@ and field tgt decl = | Ast0.OptField(_) -> failwith "unexpected code" +and enum_decl tgt decl = + match Ast0.unwrap decl with + Ast0.Enum(name,enum_val) -> + let name = ident true tgt name in + let enum_val = + get_option + (fun (eq,eval) -> + let arity = all_same true tgt (mcode2line eq) [mcode2arity eq] in + (mcode eq, expression arity eval)) enum_val in + let res = Ast0.Enum(name,enum_val) in + Ast0.rewrap decl res + | Ast0.EnumComma(cm) -> + (*let arity = all_same true tgt (mcode2line cm) [mcode2arity cm] in*) + let cm = mcode cm in + let res = Ast0.EnumComma(cm) in + Ast0.rewrap decl res + | Ast0.EnumDots(dots,whencode) -> + let dots = mcode dots in + let whencode = + get_option (fun (a,e,b) -> (a,e,enum_decl Ast0.NONE b)) whencode in + let res = Ast0.EnumDots(dots,whencode) in + Ast0.rewrap decl res + (* --------------------------------------------------------------------- *) (* Initializer *) diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 7ede511259e341165292b4d5d46b4b11350773b2..168612b322217e135690df80ee7128c5b416298d 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -211,7 +211,7 @@ and base_typeC = string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * ident option (* name *) | EnumDef of typeC (* either StructUnionName or metavar *) * - string mcode (* { *) * expression dots * string mcode (* } *) + string mcode (* { *) * enum_decl dots * string mcode (* } *) | StructUnionName of Ast.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) @@ -289,6 +289,15 @@ and bitfield = string mcode (* : *) * expression and field = base_field wrap +and base_enum_decl = + Enum of ident * (string mcode (* = *) * expression) option + | EnumComma of string mcode (* , *) + | EnumDots of string mcode (* ... *) * (string mcode * string mcode * + enum_decl) option (* whencode *) + +and enum_decl = base_enum_decl wrap + + (* --------------------------------------------------------------------- *) (* Initializers *) @@ -545,6 +554,7 @@ and anything = | DotsStmtTag of statement dots | DotsDeclTag of declaration dots | DotsFieldTag of field dots + | DotsEnumDeclTag of enum_decl dots | DotsCaseTag of case_line dots | DotsDefParamTag of define_param dots | IdentTag of ident @@ -558,6 +568,7 @@ and anything = | InitTag of initialiser | DeclTag of declaration | FieldTag of field + | EnumDeclTag of enum_decl | StmtTag of statement | ForInfoTag of forinfo | CaseLineTag of case_line @@ -577,6 +588,7 @@ let dotsInit x = DotsInitTag x let dotsStmt x = DotsStmtTag x let dotsDecl x = DotsDeclTag x let dotsField x = DotsFieldTag x +let dotsEnumDecl x = DotsEnumDeclTag x let dotsCase x = DotsCaseTag x let dotsDefParam x = DotsDefParamTag x let ident x = IdentTag x @@ -593,6 +605,7 @@ let forinfo x = ForInfoTag x let case_line x = CaseLineTag x let string_fragment x = StringFragmentTag x let top x = TopTag x +let enum_decl x = EnumDeclTag x (* --------------------------------------------------------------------- *) (* Avoid cluttering the parser. Calculated in compute_lines.ml. *) diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index 917682ba2d974203af26507c95a1e272961c282a..d984f23f221f3f96a318cf5e1fee81c118b3713b 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -202,7 +202,7 @@ and base_typeC = string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * ident option (* name *) | EnumDef of typeC (* either StructUnionName or metavar *) * - string mcode (* { *) * expression dots * string mcode (* } *) + string mcode (* { *) * enum_decl dots * string mcode (* } *) | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *) | StructUnionDef of typeC (* either StructUnionName or metavar *) * string mcode (* { *) * field dots * string mcode (* } *) @@ -277,6 +277,14 @@ and bitfield = string mcode (* : *) * expression and field = base_field wrap +and base_enum_decl = + Enum of ident * (string mcode (* = *) * expression) option + | EnumComma of string mcode (* , *) + | EnumDots of string mcode (* ... *) * (string mcode * string mcode * + enum_decl) option (* whencode *) + +and enum_decl = base_enum_decl wrap + (* --------------------------------------------------------------------- *) (* Initializers *) @@ -535,6 +543,7 @@ and anything = | DotsStmtTag of statement dots | DotsDeclTag of declaration dots | DotsFieldTag of field dots + | DotsEnumDeclTag of enum_decl dots | DotsCaseTag of case_line dots | DotsDefParamTag of define_param dots | IdentTag of ident @@ -548,6 +557,7 @@ and anything = | InitTag of initialiser | DeclTag of declaration | FieldTag of field + | EnumDeclTag of enum_decl | StmtTag of statement | ForInfoTag of forinfo | CaseLineTag of case_line @@ -567,6 +577,7 @@ val dotsParam : parameterTypeDef dots -> anything val dotsStmt : statement dots -> anything val dotsDecl : declaration dots -> anything val dotsField : field dots -> anything +val dotsEnumDecl : enum_decl dots -> anything val dotsCase : case_line dots -> anything val dotsDefParam : define_param dots -> anything val ident : ident -> anything @@ -578,6 +589,7 @@ val param : parameterTypeDef -> anything val ini : initialiser -> anything val decl : declaration -> anything val field : field -> anything +val enum_decl : enum_decl -> anything val stmt : statement -> anything val forinfo : forinfo -> anything val case_line : case_line -> anything diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index af688b1420524d4a4554bc915897722d609f9f77..31205d4169d916f09c379d98cdec2e7b28f54575 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -187,9 +187,9 @@ let inline_mcodes = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing + do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing do_nothing do_nothing_end do_nothing_end do_nothing + do_nothing do_nothing do_nothing_end do_nothing_end do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing (* --------------------------------------------------------------------- *) @@ -271,8 +271,10 @@ let check_allminus = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing + donothing donothing ident expression donothing donothing typeC initialiser donothing - declaration field statement donothing case_line donothing donothing + declaration field donothing statement donothing case_line donothing + donothing (* --------------------------------------------------------------------- *) (* --------------------------------------------------------------------- *) @@ -598,7 +600,7 @@ and base_typeC allminus t = | Ast0.EnumName(kind,name) -> Ast.EnumName(mcode kind,get_option ident name) | Ast0.EnumDef(ty,lb,ids,rb) -> - Ast.EnumDef(typeC allminus ty,mcode lb,dots expression ids,mcode rb) + Ast.EnumDef(typeC allminus ty,mcode lb,enum_decl_dots ids,mcode rb) | Ast0.StructUnionName(kind,name) -> Ast.StructUnionName(mcode kind,get_option ident name) | Ast0.StructUnionDef(ty,lb,decls,rb) -> @@ -749,6 +751,24 @@ and annotated_field bef d = and field_dots l = dots (annotated_field None) l +and enum_decl d = + rewrap d (do_isos (Ast0.get_iso d)) + (match Ast0.unwrap d with + Ast0.Enum(name,enum_val) -> + (match enum_val with + None -> Ast.Enum(ident name,None) + | Some(eq,eval) -> + Ast.Enum(ident name,Some(mcode eq,expression eval))) + | Ast0.EnumComma(cm) -> + Ast.EnumComma(mcode cm) + | Ast0.EnumDots(dots,whencode) -> + (* structure definitions only *) + let dots = mcode dots in + let whencode = get_option (fun (_,_,b) -> enum_decl b) whencode in + Ast.EnumDots(dots,whencode)) + +and enum_decl_dots l = dots enum_decl l + (* --------------------------------------------------------------------- *) (* Initialiser *) @@ -1215,6 +1235,7 @@ and anything = function | Ast0.DotsStmtTag(d) -> Ast.StmtDotsTag(statement_dots d) | Ast0.DotsDeclTag(d) -> Ast.AnnDeclDotsTag(declaration_dots d) | Ast0.DotsFieldTag(d) -> Ast.AnnFieldDotsTag(field_dots d) + | Ast0.DotsEnumDeclTag(d) -> Ast.EnumDeclDotsTag(enum_decl_dots d) | Ast0.DotsCaseTag(d) -> failwith "not possible" | Ast0.DotsDefParamTag(d) -> Ast.DefParDotsTag(define_param_dots d) | Ast0.IdentTag(d) -> Ast.IdentTag(ident d) @@ -1228,6 +1249,7 @@ and anything = function | Ast0.InitTag(d) -> Ast.InitTag(initialiser d) | Ast0.DeclTag(d) -> Ast.DeclarationTag(declaration d) | Ast0.FieldTag(d) -> Ast.FieldTag(field d) + | Ast0.EnumDeclTag(d) -> Ast.EnumDeclTag(enum_decl d) | Ast0.StmtTag(d) -> Ast.StatementTag(statement d) | Ast0.ForInfoTag(d) -> Ast.ForInfoTag(forinfo d) | Ast0.CaseLineTag(d) -> Ast.CaseLineTag(case_line d) diff --git a/parsing_cocci/ast0toast.mli b/parsing_cocci/ast0toast.mli index 24f8c52af3aaa6f0c5ad67ee47a0c4ff044b36a1..f4d2bb19da375f6206432ee8b6e3694a4d140db4 100644 --- a/parsing_cocci/ast0toast.mli +++ b/parsing_cocci/ast0toast.mli @@ -28,6 +28,9 @@ val declaration_dots : val field_dots : Ast0_cocci.field Ast0_cocci.dots -> Ast_cocci.annotated_field Ast_cocci.dots +val enum_decl_dots : + Ast0_cocci.enum_decl Ast0_cocci.dots -> + Ast_cocci.enum_decl Ast_cocci.dots val define_param_dots : Ast0_cocci.define_param Ast0_cocci.dots -> Ast_cocci.define_param Ast_cocci.dots @@ -36,6 +39,7 @@ val string_fragment : Ast0_cocci.string_fragment -> Ast_cocci.string_fragment val typeC : bool (*allminus*) -> Ast0_cocci.typeC -> Ast_cocci.fullType val declaration : Ast0_cocci.declaration -> Ast_cocci.declaration val field : Ast0_cocci.field -> Ast_cocci.field +val enum_decl : Ast0_cocci.enum_decl -> Ast_cocci.enum_decl val parameterTypeDef : Ast0_cocci.parameterTypeDef -> Ast_cocci.parameterTypeDef val parameter_list : Ast0_cocci.parameter_list -> Ast_cocci.parameter_list diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index dc438e34d354a8b404de78d24a1eee223815451f..d79a13d654e29930738769f63243caebae2d3bc5 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -351,7 +351,7 @@ and base_typeC = string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * ident option (* name *) | EnumDef of fullType (* either EnumName or metavar *) * - string mcode (* { *) * expression dots * string mcode (* } *) + string mcode (* { *) * enum_decl dots * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) | StructUnionDef of fullType (* either StructUnionName or metavar *) * string mcode (* { *) * annotated_field dots * string mcode (* } *) @@ -444,6 +444,13 @@ and base_annotated_field = and annotated_field = base_annotated_field wrap +and base_enum_decl = + Enum of ident * (string mcode (* = *) * expression) option + | EnumComma of string mcode (* , *) + | EnumDots of string mcode (* ... *) * enum_decl option (* whencode *) + +and enum_decl = base_enum_decl wrap + (* --------------------------------------------------------------------- *) (* Initializers *) @@ -784,6 +791,7 @@ and anything = | LogicalOpTag of logicalOp | DeclarationTag of declaration | FieldTag of field + | EnumDeclTag of enum_decl | InitTag of initialiser | StorageTag of storage | IncFileTag of inc_file @@ -801,6 +809,7 @@ and anything = | StmtDotsTag of statement dots | AnnDeclDotsTag of annotated_decl dots | AnnFieldDotsTag of annotated_field dots + | EnumDeclDotsTag of enum_decl dots | DefParDotsTag of define_param dots | TypeCTag of typeC | ParamTag of parameterTypeDef @@ -926,6 +935,7 @@ and tag2c = function | LogicalOpTag _ -> "LogicalOpTag" | DeclarationTag _ -> "DeclarationTag" | FieldTag _ -> "FieldTag" + | EnumDeclTag _ -> "EnumDeclTag" | InitTag _ -> "InitTag" | StorageTag _ -> "StorageTag" | IncFileTag _ -> "IncFileTag" @@ -943,6 +953,7 @@ and tag2c = function | StmtDotsTag _ -> "StmtDotsTag" | AnnDeclDotsTag _ -> "AnnDeclDotsTag" | AnnFieldDotsTag _ -> "AnnFieldDotsTag" + | EnumDeclDotsTag _ -> "EnumDeclDotsTag" | DefParDotsTag _ -> "DefParDotsTag" | TypeCTag _ -> "TypeCTag" | ParamTag _ -> "ParamTag" diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index 705954aff527f1dc6ccf419472deecea6ca282a2..edd79e9ff1b9ca29ba6ec1d72d1dcf681672f1a3 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -333,7 +333,7 @@ and base_typeC = string mcode (* ) *) (* IBM C only *) | EnumName of string mcode (*enum*) * ident option (* name *) | EnumDef of fullType (* either EnumName or metavar *) * - string mcode (* { *) * expression dots * string mcode (* } *) + string mcode (* { *) * enum_decl dots * string mcode (* } *) | StructUnionName of structUnion mcode * ident option (* name *) | StructUnionDef of fullType (* either StructUnionName or metavar *) * string mcode (* { *) * annotated_field dots * string mcode (* } *) @@ -425,6 +425,14 @@ and base_annotated_field = and annotated_field = base_annotated_field wrap +and base_enum_decl = + Enum of ident * (string mcode (* = *) * expression) option + | EnumComma of string mcode (* , *) + | EnumDots of string mcode (* ... *) * enum_decl option (* whencode *) + +and enum_decl = base_enum_decl wrap + + (* --------------------------------------------------------------------- *) (* Initializers *) @@ -752,6 +760,7 @@ and anything = | LogicalOpTag of logicalOp | DeclarationTag of declaration | FieldTag of field + | EnumDeclTag of enum_decl | InitTag of initialiser | StorageTag of storage | IncFileTag of inc_file @@ -769,6 +778,7 @@ and anything = | StmtDotsTag of statement dots | AnnDeclDotsTag of annotated_decl dots | AnnFieldDotsTag of annotated_field dots + | EnumDeclDotsTag of enum_decl dots | DefParDotsTag of define_param dots | TypeCTag of typeC | ParamTag of parameterTypeDef diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index 02b0fd9ca1ddcd21212205c7d480672d31c779db..fc96bf348b27fd234b5869f3ddc643531a04bce0 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -241,7 +241,7 @@ and typeC old_metas table minus t = | Ast0.EnumName(en,Some id) -> ident GLOBAL old_metas table minus id | Ast0.EnumDef(ty,lb,ids,rb) -> typeC old_metas table minus ty; - dots (expression GLOBAL old_metas table minus) ids + dots (enum_decl GLOBAL old_metas table minus) ids | Ast0.StructUnionName(su,Some id) -> ident GLOBAL old_metas table minus id | Ast0.StructUnionDef(ty,lb,decls,rb) -> typeC old_metas table minus ty; @@ -321,6 +321,15 @@ and field context old_metas table minus d = | Ast0.Fdots(_,Some (_,_,x)) -> field ID old_metas table minus x | Ast0.Fdots(_,None) -> () +and enum_decl context old_metas table minus d = + match Ast0.unwrap d with + Ast0.Enum(name,enum_val) -> + ident context old_metas table minus name; + (match enum_val with + None -> () + | Some(eq,eval) -> expression context old_metas table minus eval) + | Ast0.EnumComma(_) | Ast0.EnumDots(_) -> () + (* --------------------------------------------------------------------- *) (* Initialiser *) @@ -583,7 +592,7 @@ let positions rname table rules = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing in + donothing donothing donothing in List.iter fn.VT0.combiner_rec_top_level rules @@ -651,8 +660,8 @@ let dup_positions rules = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing - donothing donothing expression donothing donothing typeC donothing - donothing declaration field statement + donothing donothing donothing expression donothing donothing typeC + donothing donothing declaration field donothing statement donothing donothing donothing donothing in let res = diff --git a/parsing_cocci/cleanup_rules.ml b/parsing_cocci/cleanup_rules.ml index 08ce96d6443bec35cf21fdd0596c96c366e7ad52..60452bec8eff5096849872f50b741b493e557524 100644 --- a/parsing_cocci/cleanup_rules.ml +++ b/parsing_cocci/cleanup_rules.ml @@ -249,10 +249,11 @@ let do_cleanup = V.rebuilder mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing (* dots *) + donothing donothing donothing donothing donothing + donothing donothing (* dots *) ident expression string_fragment string_format assignOp binaryOp fullType typeC initialiser parameterTypeDef define_param - declaration donothing field ann_field + declaration donothing field ann_field donothing rule_elem statement donothing donothing donothing let cleanup_rules rules d = diff --git a/parsing_cocci/commas_on_lists.ml b/parsing_cocci/commas_on_lists.ml index 3c1facfebe94b03b034b2f0211c244047edc5e93..9ea23ef5808ac376ea8890adf23e0b944b01f5b9 100644 --- a/parsing_cocci/commas_on_lists.ml +++ b/parsing_cocci/commas_on_lists.ml @@ -31,11 +31,11 @@ now. See list_matcher in cocci_vs_c.ml in first try_matches case. *) Ast0.rewrap itemlist (List.rev (Ast0.rewrap e (make_comma comma) :: (e::es))) -let add_exp_comma = +let add_enum_decl_comma = add_comma - (function x -> match Ast0.unwrap x with Ast0.EComma _ -> true | _ -> false) - (function x -> match Ast0.unwrap x with Ast0.Edots _ -> true | _ -> false) - (function x -> Ast0.EComma x) + (function x -> match Ast0.unwrap x with Ast0.EnumComma _ -> true | _ -> false) + (function x -> match Ast0.unwrap x with Ast0.EnumDots _ -> true | _ -> false) + (function x -> Ast0.EnumComma x) and add_init_comma = add_comma @@ -51,7 +51,7 @@ let base_typeC r k t = let t = k t in match Ast0.unwrap t with Ast0.EnumDef(ty,lb,ids,rb) -> - let ids = add_exp_comma ids in + let ids = add_enum_decl_comma ids in Ast0.rewrap t (Ast0.EnumDef(ty,lb,ids,rb)) | _ -> t diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index c9c1872ee37593771ec32baed9e4a3780fecc6d9..cb3e8f0f1c0593e0d72fba2a00edf1a8cefa0204 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -600,7 +600,8 @@ and typeC t = | Ast0.EnumDef(ty,lb,ids,rb) -> let ty = typeC ty in let lb = normal_mcode lb in - let ids = dots is_exp_dots (Some(promote_mcode lb)) expression ids in + let ids = + dots is_enum_decl_dots (Some(promote_mcode lb)) enum_decl ids in let rb = normal_mcode rb in mkres t (Ast0.EnumDef(ty,lb,ids,rb)) ty (promote_mcode rb) | Ast0.StructUnionName(kind,Some name) -> @@ -808,6 +809,28 @@ and field d = let ln = promote_mcode dots in mkres d (Ast0.Fdots(dots,whencode)) ln ln +and is_enum_decl_dots d = + match Ast0.unwrap d with + Ast0.EnumDots(_) -> true + | _ -> false + +and enum_decl d = + match Ast0.unwrap d with + Ast0.Enum(name,enum_val) -> + let name = ident name in + let eval (a, b) = (normal_mcode a, expression b) in + let enum_val = get_option eval enum_val in + mkres d (Ast0.Enum(name,enum_val)) name name + | Ast0.EnumComma(cm) -> + let cm = normal_mcode cm in + let ln = promote_mcode cm in + mkres d (Ast0.EnumComma(cm)) ln ln + | Ast0.EnumDots(dots,whencode) -> + let dots = bad_mcode dots in + let ln = promote_mcode dots in + mkres d (Ast0.EnumDots(dots,whencode)) ln ln + + (* --------------------------------------------------------------------- *) (* Initializer *) diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml index ce5336052614ba36cdb3aeb27586850a1a277c6a..38ef2adb2ebc69baf906885241c7090ec0efd0d6 100644 --- a/parsing_cocci/context_neg.ml +++ b/parsing_cocci/context_neg.ml @@ -27,6 +27,7 @@ let set_mcodekind x mcodekind = | Ast0.DotsStmtTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.DotsDeclTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.DotsFieldTag(d) -> Ast0.set_mcodekind d mcodekind + | Ast0.DotsEnumDeclTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.DotsCaseTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.DotsDefParamTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.IdentTag(d) -> Ast0.set_mcodekind d mcodekind @@ -39,6 +40,7 @@ let set_mcodekind x mcodekind = | Ast0.ParamTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.DeclTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.FieldTag(d) -> Ast0.set_mcodekind d mcodekind + | Ast0.EnumDeclTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.InitTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.StmtTag(d) -> Ast0.set_mcodekind d mcodekind | Ast0.ForInfoTag(d) -> Ast0.set_mcodekind d mcodekind @@ -60,6 +62,7 @@ let set_index x index = | Ast0.DotsStmtTag(d) -> Ast0.set_index d index | Ast0.DotsDeclTag(d) -> Ast0.set_index d index | Ast0.DotsFieldTag(d) -> Ast0.set_index d index + | Ast0.DotsEnumDeclTag(d) -> Ast0.set_index d index | Ast0.DotsCaseTag(d) -> Ast0.set_index d index | Ast0.DotsDefParamTag(d) -> Ast0.set_index d index | Ast0.IdentTag(d) -> Ast0.set_index d index @@ -73,6 +76,7 @@ let set_index x index = | Ast0.InitTag(d) -> Ast0.set_index d index | Ast0.DeclTag(d) -> Ast0.set_index d index | Ast0.FieldTag(d) -> Ast0.set_index d index + | Ast0.EnumDeclTag(d) -> Ast0.set_index d index | Ast0.StmtTag(d) -> Ast0.set_index d index | Ast0.ForInfoTag(d) -> Ast0.set_index d index | Ast0.CaseLineTag(d) -> Ast0.set_index d index @@ -92,6 +96,7 @@ let get_index = function | Ast0.DotsStmtTag(d) -> Index.statement_dots d | Ast0.DotsDeclTag(d) -> Index.declaration_dots d | Ast0.DotsFieldTag(d) -> Index.field_dots d + | Ast0.DotsEnumDeclTag(d) -> Index.enum_decl_dots d | Ast0.DotsCaseTag(d) -> Index.case_line_dots d | Ast0.DotsDefParamTag(d) -> Index.define_param_dots d | Ast0.IdentTag(d) -> Index.ident d @@ -105,6 +110,7 @@ let get_index = function | Ast0.InitTag(d) -> Index.initialiser d | Ast0.DeclTag(d) -> Index.declaration d | Ast0.FieldTag(d) -> Index.field d + | Ast0.EnumDeclTag(d) -> Index.enum_decl d | Ast0.StmtTag(d) -> Index.statement d | Ast0.ForInfoTag(d) -> Index.forinfo d | Ast0.CaseLineTag(d) -> Index.case_line d @@ -174,9 +180,10 @@ let collect_plus_lines top = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing statement donothing donothing donothing donothing in + donothing donothing donothing statement donothing donothing donothing + donothing in fn.VT0.combiner_rec_top_level top (* --------------------------------------------------------------------- *) @@ -446,6 +453,16 @@ let classify is_minus all_marked table code = (bind (Common.default option_default bitfield bf) (mcode sem))) | _ -> k e) in + let enum_decl r k e = + compute_result Ast0.enum_decl e + (match Ast0.unwrap e with + Ast0.Enum(name,Some(eq,eval)) -> + bind (r.VT0.combiner_rec_ident name) + (bind (mcode eq) (r.VT0.combiner_rec_expression eval)) + | Ast0.EnumDots(dots,whencode) -> + k (Ast0.rewrap e (Ast0.EnumDots(dots,None))) + | _ -> k e) in + let param r k e = compute_result Ast0.param e (match Ast0.unwrap e with @@ -526,10 +543,10 @@ let classify is_minus all_marked table code = (do_nothing Ast0.dotsExpr) (do_nothing Ast0.dotsInit) (do_nothing Ast0.dotsParam) (do_nothing Ast0.dotsStmt) (do_nothing Ast0.dotsDecl) (do_nothing Ast0.dotsField) - (do_nothing Ast0.dotsCase) + (do_nothing Ast0.dotsEnumDecl) (do_nothing Ast0.dotsCase) (do_nothing Ast0.dotsDefParam) ident expression (do_nothing Ast0.assignOp) (do_nothing Ast0.binaryOp) - typeC initialiser param declaration field + typeC initialiser param declaration field enum_decl statement (do_nothing Ast0.forinfo) case_line string_fragment (do_top Ast0.top) in combiner.VT0.combiner_rec_top_level code @@ -672,7 +689,9 @@ let equal_typeC t1 t2 = | (Ast0.EnumName(kind1,_),Ast0.EnumName(kind2,_)) -> equal_mcode kind1 kind2 | (Ast0.EnumDef(_,lb1,_,rb1),Ast0.EnumDef(_,lb2,_,rb2)) -> - equal_mcode lb1 lb2 && equal_mcode rb1 rb2 + let tru1 = equal_mcode lb1 lb2 in + let tru2 = equal_mcode rb1 rb2 in + tru1 && tru2 | (Ast0.StructUnionName(kind1,_),Ast0.StructUnionName(kind2,_)) -> equal_mcode kind1 kind2 | (Ast0.StructUnionDef(_,lb1,_,rb1), @@ -767,6 +786,19 @@ let equal_field d1 d2 = equal_mcode ender1 ender2 | _ -> false +let equal_enum_decl d1 d2 = + match (Ast0.unwrap d1,Ast0.unwrap d2) with + (Ast0.Enum(name1,enum_val1),Ast0.Enum(name2,enum_val2)) -> + equal_ident name1 name2 && + (match enum_val1,enum_val2 with + None,None -> true + | Some (eq1,val1),Some(eq2,val2) -> + equal_mcode eq1 eq2 && equal_expression val1 val2 + | _ -> false) + | (Ast0.EnumComma(cm1),Ast0.EnumComma(cm2)) -> equal_mcode cm1 cm2 + | (Ast0.EnumDots(dots1,_),Ast0.EnumDots(dots2,_)) -> equal_mcode dots1 dots2 + | _ -> false + let equal_designator d1 d2 = match (d1,d2) with (Ast0.DesignatorField(dot1,_),Ast0.DesignatorField(dot2,_)) -> @@ -940,6 +972,8 @@ let root_equal e1 e2 = | (Ast0.DotsStmtTag(d1),Ast0.DotsStmtTag(d2)) -> dots equal_statement d1 d2 | (Ast0.DotsDeclTag(d1),Ast0.DotsDeclTag(d2)) -> dots equal_declaration d1 d2 | (Ast0.DotsFieldTag(d1),Ast0.DotsFieldTag(d2)) -> dots equal_field d1 d2 + | (Ast0.DotsEnumDeclTag(d1),Ast0.DotsEnumDeclTag(d2)) -> + dots equal_field d1 d2 | (Ast0.DotsCaseTag(d1),Ast0.DotsCaseTag(d2)) -> dots equal_case_line d1 d2 | (Ast0.DotsDefParamTag(d1),Ast0.DotsDefParamTag(d2)) -> dots equal_define_param d1 d2 @@ -953,6 +987,7 @@ let root_equal e1 e2 = | (Ast0.InitTag(d1),Ast0.InitTag(d2)) -> equal_initialiser d1 d2 | (Ast0.DeclTag(d1),Ast0.DeclTag(d2)) -> equal_declaration d1 d2 | (Ast0.FieldTag(d1),Ast0.FieldTag(d2)) -> equal_field d1 d2 + | (Ast0.EnumDeclTag(d1),Ast0.EnumDeclTag(d2)) -> equal_enum_decl d1 d2 | (Ast0.StmtTag(s1),Ast0.StmtTag(s2)) -> equal_statement s1 s2 | (Ast0.TopTag(t1),Ast0.TopTag(t2)) -> equal_top_level t1 t2 | (Ast0.IsoWhenTag(_),_) | (_,Ast0.IsoWhenTag(_)) @@ -997,7 +1032,7 @@ let contextify_all = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing donothing let contextify_whencode = let bind x y = () in diff --git a/parsing_cocci/data.ml b/parsing_cocci/data.ml index d604fd6364376c216243f7c2df86389e26bf12db..5c9897c6ce6f0dadf194a79ba4f7ffa259b47ca0 100644 --- a/parsing_cocci/data.ml +++ b/parsing_cocci/data.ml @@ -160,3 +160,11 @@ let non_local_script_constraints = let fresh_id_scripts: (Ast_cocci.meta_name * Ast_cocci.seed_script) list ref = ref [] + +(* ---------------------------------------------------------------------- *) +(* Names of some special tokens. Make these acessible to the C parser *) + +let type_names = ref ([]:string list) +let attr_names = ref ([]:string list) +let declarer_names = ref ([]:string list) +let iterator_names = ref ([]:string list) diff --git a/parsing_cocci/data.mli b/parsing_cocci/data.mli index 9fa4e45a223ce6ae989438eef55ff2fc908ac9fa..ed911fddcd4d034cbfd7e9554f0ef98f43985c04 100644 --- a/parsing_cocci/data.mli +++ b/parsing_cocci/data.mli @@ -138,3 +138,11 @@ val non_local_script_constraints: val fresh_id_scripts: (Ast_cocci.meta_name * Ast_cocci.seed_script) list ref (** The list of all fresh id scripts. *) + +(* ---------------------------------------------------------------------- *) +(* Names of some special tokens. Make these acessible to the C parser *) + +val type_names : string list ref +val attr_names : string list ref +val declarer_names : string list ref +val iterator_names : string list ref diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index bcd7547f56173da13cf79fe096a47ad409779276..26ce7dc092c431b749ed60e56102c14d2cc62cf9 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -90,7 +90,7 @@ and disjtypeC bty = (function name -> Ast.rewrap bty (Ast.StructUnionName(su,name))) name | Ast.EnumDef(ty,lb,ids,rb) -> - disjmult2 (disjty ty) (disjdots disjexp ids) + disjmult2 (disjty ty) (disjdots disjenumdecl ids) (function ty -> function ids -> Ast.rewrap bty (Ast.EnumDef(ty,lb,ids,rb))) | Ast.StructUnionDef(ty,lb,decls,rb) -> @@ -130,6 +130,21 @@ and anndisjfield d = let decl = anndisjfield decl in List.map (function decl -> Ast.rewrap d (Ast.OptField(decl))) decl +and disjenumdecl d = + match Ast.unwrap d with + Ast.Enum(name,enum_val) -> + let name = disjident name in + (match enum_val with + None -> + List.map (function name -> Ast.rewrap d (Ast.Enum(name,None))) + name + | Some (eq,eval) -> + disjmult2 name (disjexp eval) + (function name -> function eval -> + Ast.rewrap d (Ast.Enum(name,Some(eq,eval))))) + | Ast.EnumComma(cm) -> [d] + | Ast.EnumDots(dots,whencode) -> [d] + and disjident e = match Ast.unwrap e with Ast.DisjId(id_list) -> List.concat (List.map disjident id_list) @@ -461,8 +476,8 @@ let disj_all = mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing donothing - donothing disj_rule_elem donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing + donothing donothing disj_rule_elem donothing donothing donothing donothing (* ----------------------------------------------------------------------- *) (* collect iso information at the rule_elem level *) @@ -478,9 +493,9 @@ let collect_all_isos = mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing + donothing donothing donothing donothing donothing doanything donothing doanything donothing donothing donothing donothing - doanything + donothing doanything let collect_iso_info = let mcode x = x in @@ -495,9 +510,9 @@ let collect_iso_info = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing - donothing donothing donothing donothing rule_elem donothing donothing + donothing donothing donothing donothing donothing rule_elem donothing donothing donothing donothing (* ----------------------------------------------------------------------- *) diff --git a/parsing_cocci/free_vars.ml b/parsing_cocci/free_vars.ml index 4c34cd08f0cc0bb6bd8cb91813f1836c6d386edb..6ad35dccbfb53d012be5dc4a6521f3b91afc880e 100644 --- a/parsing_cocci/free_vars.ml +++ b/parsing_cocci/free_vars.ml @@ -249,10 +249,10 @@ let collect_refs include_constraints = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing astfvident astfvexpr astfvfrag astfvfmt astfvassignop astfvbinaryop astfvfullType astfvtypeC astfvinit astfvparam astfvdefine_param - astfvdecls donothing astfvfields astafvfields + astfvdecls donothing astfvfields astafvfields donothing astfvrule_elem astfvstatement donothing donothing donothing_a let collect_all_refs = collect_refs true @@ -299,10 +299,10 @@ let collect_pos_positions = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing + donothing donothing donothing donothing cprule_elem cpstmt donothing donothing donothing (* ---------------------------------------------------------------- *) @@ -475,10 +475,11 @@ let collect_saved = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing astfvident astfvexpr astfvfrag astfvfmt astfvassign astfvbinary donothing astfvtypeC astfvinit astfvparam astfvdefine_param astfvdecls donothing - astfvfields donothing astfvrule_elem donothing donothing donothing donothing + astfvfields donothing donothing astfvrule_elem donothing donothing + donothing donothing (* ---------------------------------------------------------------- *) @@ -607,10 +608,10 @@ let collect_in_plus_term = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - mcode mcode donothing donothing + mcode mcode donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing astfvrule_elem + donothing donothing donothing donothing donothing donothing astfvrule_elem astfvstatement donothing donothing donothing let collect_in_plus metavars minirules = @@ -900,11 +901,11 @@ let classify_variables metavar_decls minirules used_after = let fn = V.rebuilder mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing ident expression string_fragment string_format assignop binaryop donothing typeC - init param define_param decl donothing field donothing rule_elem - donothing donothing donothing donothing in + init param define_param decl donothing field donothing donothing + rule_elem donothing donothing donothing donothing in List.map fn.V.rebuilder_top_level minirules @@ -1089,7 +1090,7 @@ let astfvs metavars bound = donothing donothing astfvstatement_dots donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing donothing astfvrule_elem astfvstatement astfvcase_line astfvtoplevel donothing (* @@ -1174,7 +1175,7 @@ let get_neg_pos_list (_,rule) used_after_list = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing in + donothing donothing donothing donothing donothing donothing donothing in match rule with Ast.CocciRule(rule_name,_,minirules,_,_) -> List.map diff --git a/parsing_cocci/function_prototypes.ml b/parsing_cocci/function_prototypes.ml index be5fbd433a408dee57b049eec5c8a1b06d2408fd..70a6ddd30e86e3b7efb676fd1abd6d5f2ace7f61 100644 --- a/parsing_cocci/function_prototypes.ml +++ b/parsing_cocci/function_prototypes.ml @@ -68,7 +68,7 @@ let drop_positions = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing in + donothing donothing donothing in res.VT0.rebuilder_rec_statement let get_all_functions rule = @@ -171,9 +171,10 @@ and strip = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing ident donothing donothing donothing typeC donothing param donothing donothing donothing donothing donothing donothing donothing + donothing and changed_proto = function (mname,mdef,mproto,None) -> true @@ -197,7 +198,7 @@ let collect_ident_strings id = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing in + donothing donothing donothing in v.VT0.combiner_rec_ident id let right_attach_mcode strings (x,ar,info,mc,pos,adj) = diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index b5cfeccc4480e8f61e0a85c4103311d86f0630a5..76d6d40bf071c3ce7987afd01d67d51ecbeff381 100644 --- a/parsing_cocci/get_constants2.ml +++ b/parsing_cocci/get_constants2.ml @@ -638,10 +638,10 @@ let do_get_constants constants keywords env (neg_pos,_) = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing ident expression string_fragment string_format donothing donothing fullType typeC initialiser parameter define_parameter declaration donothing - field ann_field rule_elem statement donothing donothing donothing + field ann_field donothing rule_elem statement donothing donothing donothing (* ------------------------------------------------------------------------ *) @@ -708,8 +708,9 @@ let all_context = mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing + donothing initialiser donothing donothing donothing donothing donothing donothing - rule_elem statement donothing donothing donothing + donothing rule_elem statement donothing donothing donothing (* ------------------------------------------------------------------------ *) diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml index edefb15bd22600c5c170990ec790495bb087f2d9..4876d9536e61e7115448d8bcb935eea7ef7e3a3f 100644 --- a/parsing_cocci/index.ml +++ b/parsing_cocci/index.ml @@ -28,6 +28,7 @@ let parameter_dots x = 3 :: dots x let statement_dots x = 4 :: dots x let declaration_dots x = 5 :: dots x let field_dots x = 8 :: dots x +let enum_decl_dots x = 9 :: dots x let case_line_dots x = 6 :: dots x let define_param_dots x =7 :: dots x @@ -134,6 +135,12 @@ let field d = | Ast0.Fdots(dots,whencode) -> [133] | Ast0.OptField(decl) -> [191] +let enum_decl d = + match Ast0.unwrap d with + | Ast0.Enum(name,enum_val) -> [113] + | Ast0.EnumComma(cm) -> [114] + | Ast0.EnumDots(dots,whencode) -> [115] + let initialiser i = match Ast0.unwrap i with Ast0.MetaInit(nm,_,_) -> [106] (* added after *) diff --git a/parsing_cocci/index.mli b/parsing_cocci/index.mli index 3cf7b8dcdefc22824924da919a681d6b2452ab7b..4f86f5bac33da35496c4e733e5be1460661f4fd3 100644 --- a/parsing_cocci/index.mli +++ b/parsing_cocci/index.mli @@ -10,6 +10,7 @@ val parameter_dots : Ast0_cocci.parameterTypeDef Ast0_cocci.dots -> int list val statement_dots : Ast0_cocci.statement Ast0_cocci.dots -> int list val declaration_dots : Ast0_cocci.declaration Ast0_cocci.dots -> int list val field_dots : Ast0_cocci.field Ast0_cocci.dots -> int list +val enum_decl_dots : Ast0_cocci.enum_decl Ast0_cocci.dots -> int list val case_line_dots : Ast0_cocci.case_line Ast0_cocci.dots -> int list val define_param_dots : Ast0_cocci.define_param Ast0_cocci.dots -> int list val ident : Ast0_cocci.ident -> int list @@ -19,6 +20,7 @@ val binaryOp : Ast0_cocci.binaryOp -> int list val typeC : Ast0_cocci.typeC -> int list val declaration : Ast0_cocci.declaration -> int list val field : Ast0_cocci.field -> int list +val enum_decl : Ast0_cocci.enum_decl -> int list val initialiser : Ast0_cocci.initialiser -> int list val parameterTypeDef : Ast0_cocci.parameterTypeDef -> int list val statement : Ast0_cocci.statement -> int list diff --git a/parsing_cocci/insert_plus.ml b/parsing_cocci/insert_plus.ml index a6b483597b3b138079f257528f5d1361beca5b5d..63635b43e7dd74ac0998cb837fe19fe3444f345c 100644 --- a/parsing_cocci/insert_plus.ml +++ b/parsing_cocci/insert_plus.ml @@ -75,13 +75,13 @@ it *) (donothing Ast0.dotsExpr) (donothing Ast0.dotsInit) (donothing Ast0.dotsParam) (donothing Ast0.dotsStmt) (donothing Ast0.dotsDecl) (donothing Ast0.dotsField) - (donothing Ast0.dotsCase) + (donothing Ast0.dotsEnumDecl) (donothing Ast0.dotsCase) (donothing Ast0.dotsDefParam) (donothing Ast0.ident) expression (donothing Ast0.assignOp) (donothing Ast0.binaryOp) (donothing Ast0.typeC) initialiser (donothing Ast0.param) (donothing Ast0.decl) - (donothing Ast0.field) statement + (donothing Ast0.field) (donothing Ast0.enum_decl) statement (donothing Ast0.forinfo) (donothing Ast0.case_line) (donothing Ast0.string_fragment) topfn in res.VT0.combiner_rec_top_level e @@ -114,6 +114,7 @@ let create_root_token_table minus = | Ast0.DotsStmtTag(d) -> Ast0.get_index d | Ast0.DotsDeclTag(d) -> Ast0.get_index d | Ast0.DotsFieldTag(d) -> Ast0.get_index d + | Ast0.DotsEnumDeclTag(d) -> Ast0.get_index d | Ast0.DotsCaseTag(d) -> Ast0.get_index d | Ast0.DotsDefParamTag(d) -> Ast0.get_index d | Ast0.IdentTag(d) -> Ast0.get_index d @@ -127,6 +128,7 @@ let create_root_token_table minus = | Ast0.InitTag(d) -> Ast0.get_index d | Ast0.DeclTag(d) -> Ast0.get_index d | Ast0.FieldTag(d) -> Ast0.get_index d + | Ast0.EnumDeclTag(d) -> Ast0.get_index d | Ast0.StmtTag(d) -> Ast0.get_index d | Ast0.ForInfoTag(d) -> Ast0.get_index d | Ast0.CaseLineTag(d) -> Ast0.get_index d @@ -243,6 +245,13 @@ bind to that; not good for isomorphisms *) Ast0.DPComma(comma) -> unfavored_mcode comma | _ -> r.VT0.combiner_rec_define_param p) k d in + let enumdots r k d = + dots + (function p -> + match Ast0.unwrap p with + Ast0.EnumComma(comma) -> unfavored_mcode comma + | _ -> r.VT0.combiner_rec_enumdecl p) + k d in let sdots r k d = dots r.VT0.combiner_rec_statement k d in let ddots r k d = dots r.VT0.combiner_rec_declaration k d in @@ -373,9 +382,9 @@ bind to that; not good for isomorphisms *) V0.flat_combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - edots idots pdots sdots ddots fdots cdots dpdots + edots idots pdots sdots ddots fdots enumdots cdots dpdots ident expression do_nothing do_nothing - typeC initialiser param decl field statement forinfo + typeC initialiser param decl field do_nothing statement forinfo case_line do_nothing do_top @@ -402,6 +411,9 @@ let call_collect_minus context_nodes : | Ast0.DotsFieldTag(e) -> (Ast0.get_index e, (collect_minus_join_points e).VT0.combiner_rec_field_dots e) + | Ast0.DotsEnumDeclTag(e) -> + (Ast0.get_index e, + (collect_minus_join_points e).VT0.combiner_rec_enum_decl_dots e) | Ast0.DotsCaseTag(e) -> (Ast0.get_index e, (collect_minus_join_points e).VT0.combiner_rec_case_line_dots e) @@ -437,6 +449,9 @@ let call_collect_minus context_nodes : | Ast0.FieldTag(e) -> (Ast0.get_index e, (collect_minus_join_points e).VT0.combiner_rec_field e) + | Ast0.EnumDeclTag(e) -> + (Ast0.get_index e, + (collect_minus_join_points e).VT0.combiner_rec_enumdecl e) | Ast0.StmtTag(e) -> (Ast0.get_index e, (collect_minus_join_points e).VT0.combiner_rec_statement e) @@ -525,6 +540,7 @@ let mk_arithOp x = Ast.ArithOpTag x let mk_logicalOp x = Ast.LogicalOpTag x let mk_declaration x = Ast.DeclarationTag (Ast0toast.declaration x) let mk_field x = Ast.FieldTag (Ast0toast.field x) +let mk_enum_decl x = Ast.EnumDeclTag (Ast0toast.enum_decl x) let mk_topdeclaration x = Ast.DeclarationTag (Ast0toast.declaration x) let mk_storage x = Ast.StorageTag x let mk_inc_file x = Ast.IncFileTag x @@ -542,6 +558,7 @@ let mk_paramdots x = Ast.ParamDotsTag (Ast0toast.parameter_list x) let mk_stmtdots x = Ast.StmtDotsTag (Ast0toast.statement_dots x) let mk_decldots x = Ast.AnnDeclDotsTag (Ast0toast.declaration_dots x) let mk_fielddots x = Ast.AnnFieldDotsTag (Ast0toast.field_dots x) +let mk_enumdecldots x = Ast.EnumDeclDotsTag (Ast0toast.enum_decl_dots x) let mk_casedots x = failwith "+ case lines not supported" let mk_defpardots x= Ast.DefParDotsTag (Ast0toast.define_param_dots x) let mk_typeC x = Ast.FullTypeTag (Ast0toast.typeC false x) @@ -648,12 +665,13 @@ let collect_plus_nodes root = (mcode mk_storage) (mcode mk_inc_file) (do_nothing mk_exprdots) initdots (do_nothing mk_paramdots) stmt_dots (do_nothing mk_decldots) - (do_nothing mk_fielddots) + (do_nothing mk_fielddots) (do_nothing mk_enumdecldots) (do_nothing mk_casedots) (do_nothing mk_defpardots) (do_nothing mk_ident) (do_nothing mk_expression) (do_nothing mk_assignOp) (do_nothing mk_binaryOp) (do_nothing mk_typeC) (do_nothing mk_init) (do_nothing mk_param) (do_nothing mk_declaration) (do_nothing mk_field) + (do_nothing mk_enum_decl) stmt (do_nothing mk_forinfo) (do_nothing mk_case_line) (do_nothing mk_string_fragment) toplevel @@ -680,6 +698,9 @@ let call_collect_plus context_nodes : | Ast0.DotsFieldTag(e) -> (Ast0.get_index e, (collect_plus_nodes e).VT0.combiner_rec_field_dots e) + | Ast0.DotsEnumDeclTag(e) -> + (Ast0.get_index e, + (collect_plus_nodes e).VT0.combiner_rec_enum_decl_dots e) | Ast0.DotsCaseTag(e) -> (Ast0.get_index e, (collect_plus_nodes e).VT0.combiner_rec_case_line_dots e) @@ -715,6 +736,9 @@ let call_collect_plus context_nodes : | Ast0.FieldTag(e) -> (Ast0.get_index e, (collect_plus_nodes e).VT0.combiner_rec_field e) + | Ast0.EnumDeclTag(e) -> + (Ast0.get_index e, + (collect_plus_nodes e).VT0.combiner_rec_enumdecl e) | Ast0.StmtTag(e) -> (Ast0.get_index e, (collect_plus_nodes e).VT0.combiner_rec_statement e) @@ -1203,8 +1227,9 @@ let reevaluate_contextness = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing stmt donothing + donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing stmt + donothing donothing donothing donothing in res.VT0.combiner_rec_top_level diff --git a/parsing_cocci/iso_compile.ml b/parsing_cocci/iso_compile.ml index 24c825f2b4af58b27e8e4f142aa3d7a2a571aa60..d17e1106dd2aa9122a8b960d10dddf08b6871646 100644 --- a/parsing_cocci/iso_compile.ml +++ b/parsing_cocci/iso_compile.ml @@ -53,9 +53,9 @@ let sequence_tokens = (mcode (function x -> Store (Ast0.unwrap_mcode x))) (mcode (function x -> Inc (Ast0.unwrap_mcode x))) donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing + donothing donothing donothing donothing donothing donothing donothing + donothing donothing donothing (* In general, we will get a list of lists: diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index 49153ef11390f95a92ab76fa04ac38b7b804bd9e..6eaef44fb9cbc5ce081f59c293619118c82d452d 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -45,7 +45,7 @@ let strip_info = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing donothing let anything_equal = function (Ast0.DotsExprTag(d1),Ast0.DotsExprTag(d2)) -> @@ -476,9 +476,9 @@ let match_maker checks_needed context_required whencode_allowed = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing - donothing - ident expression assignOp binaryOp typeC init param decl field stmt - donothing donothing donothing donothing in + donothing donothing + ident expression assignOp binaryOp typeC init param decl field donothing + stmt donothing donothing donothing donothing in let add_pure_list_binding name pure is_pure builder1 builder2 lst = match (checks_needed,pure) with @@ -892,7 +892,7 @@ let match_maker checks_needed context_required whencode_allowed = conjunct_many_bindings [check_mcode lb1 lb; check_mcode rb1 rb; match_typeC tya tyb; - match_dots match_expr no_list do_nolist_match idsa idsb] + match_dots match_enum_decl no_list do_nolist_match idsa idsb] | (Ast0.StructUnionName(kinda,Some namea), Ast0.StructUnionName(kindb,Some nameb)) -> if mcode_equal kinda kindb @@ -1064,6 +1064,35 @@ let match_maker checks_needed context_required whencode_allowed = | _ -> return false else return_false (ContextRequired (Ast0.FieldTag d)) + and match_enum_decl pattern d = + match (Ast0.unwrap pattern,Ast0.unwrap d) with + (Ast0.Enum(namea,enum_vala),Ast0.Enum(nameb,enum_valb)) -> + let match_option_enum_val evala evalb = + match evala, evalb with + Some (eqa,ea), Some (eqb,eb) -> + [check_mcode eqa eqb] @ [match_expr ea eb] + | Some _, None | None, Some _ -> [return false] + | None, None -> [] in + conjunct_many_bindings + ([match_ident namea nameb] + @ match_option_enum_val enum_vala enum_valb) + | (Ast0.EnumComma(comma1),Ast0.EnumComma(comma2)) -> + check_mcode comma1 comma2 + | (Ast0.EnumDots(d1,None),Ast0.EnumDots(d,None)) -> check_mcode d1 d + | (Ast0.EnumDots(dd,None),Ast0.EnumDots(d,Some (wh,ee,wc))) -> + conjunct_bindings (check_mcode dd d) + (* hope that mcode of ddots is unique somehow *) + (let (ddots_whencode_allowed,_,_) = whencode_allowed in + if ddots_whencode_allowed + then add_dot_binding dd + (Ast0.WhenTag (wh,Some ee,Ast0.EnumDeclTag wc)) + else + (Printf.eprintf "warning: not applying iso because of whencode"; + return false)) + | (Ast0.EnumDots(_,Some _),_) -> + failwith "whencode not allowed in a pattern1" + | _ -> return false + and match_init pattern i = match Ast0.unwrap pattern with Ast0.MetaInit(name,_,pure) -> @@ -1499,6 +1528,14 @@ let make_minus = update_mc mcodekind e; Ast0.rewrap e (Ast0.Fdots(mcode d,whencode)) | _ -> donothing r k e in + let enum_decl r k e = + let mcodekind = Ast0.get_mcodekind_ref e in + match Ast0.unwrap e with + Ast0.EnumDots(d,whencode) -> + (*don't recurse because whencode hasn't been processed by context_neg*) + update_mc mcodekind e; Ast0.rewrap e (Ast0.EnumDots(mcode d,whencode)) + | _ -> donothing r k e in + let statement r k e = let mcodekind = Ast0.get_mcodekind_ref e in match Ast0.unwrap e with @@ -1551,9 +1588,10 @@ let make_minus = V0.flat_rebuilder mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - dots dots dots dots dots dots dots dots + dots dots dots dots dots dots dots dots dots donothing expression donothing donothing donothing initialiser donothing - declaration field statement donothing donothing donothing donothing + declaration field enum_decl statement donothing donothing donothing + donothing (* --------------------------------------------------------------------- *) (* rebuild mcode cells in an instantiated alt *) @@ -1644,8 +1682,8 @@ let rebuild_mcode start_line = mcode mcode donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing statement donothing donothing donothing - donothing + donothing donothing donothing donothing donothing statement donothing + donothing donothing donothing (* --------------------------------------------------------------------- *) (* The problem of whencode. If an isomorphism contains dots in multiple @@ -2063,6 +2101,18 @@ let instantiate bindings mv_bindings model = with Not_found -> e) | _ -> e in + let enumdeclfn r k e = + let e = k e in + match Ast0.unwrap e with + Ast0.EnumDots(d,_) -> + (try + (match List.assoc (dot_term d) bindings with + Ast0.WhenTag(wh,Some ee,Ast0.EnumDeclTag(exp)) -> + Ast0.rewrap e (Ast0.EnumDots(d,Some (wh,ee,exp))) + | _ -> failwith "unexpected binding") + with Not_found -> e) + | _ -> e in + let paramfn r k e = let e = k e in match Ast0.unwrap e with @@ -2115,9 +2165,9 @@ let instantiate bindings mv_bindings model = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode (dots elist) donothing (dots plist) (dots slist) donothing donothing - donothing donothing - identfn exprfn donothing donothing tyfn initfn paramfn declfn fieldfn stmtfn - donothing donothing donothing donothing + donothing donothing donothing + identfn exprfn donothing donothing tyfn initfn paramfn declfn fieldfn + enumdeclfn stmtfn donothing donothing donothing donothing (* --------------------------------------------------------------------- *) @@ -2847,7 +2897,7 @@ let rewrap = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing donothing let rec rewrap_anything = function Ast0.DotsExprTag(d) -> @@ -2862,6 +2912,8 @@ let rec rewrap_anything = function Ast0.DotsDeclTag(rewrap.VT0.rebuilder_rec_declaration_dots d) | Ast0.DotsFieldTag(d) -> Ast0.DotsFieldTag(rewrap.VT0.rebuilder_rec_field_dots d) + | Ast0.DotsEnumDeclTag(d) -> + Ast0.DotsEnumDeclTag(rewrap.VT0.rebuilder_rec_enum_decl_dots d) | Ast0.DotsCaseTag(d) -> Ast0.DotsCaseTag(rewrap.VT0.rebuilder_rec_case_line_dots d) | Ast0.DotsDefParamTag(d) -> @@ -2881,6 +2933,8 @@ let rec rewrap_anything = function | Ast0.ParamTag(d) -> Ast0.ParamTag(rewrap.VT0.rebuilder_rec_parameter d) | Ast0.DeclTag(d) -> Ast0.DeclTag(rewrap.VT0.rebuilder_rec_declaration d) | Ast0.FieldTag(d) -> Ast0.FieldTag(rewrap.VT0.rebuilder_rec_field d) + | Ast0.EnumDeclTag(d) -> + Ast0.EnumDeclTag(rewrap.VT0.rebuilder_rec_enumdecl d) | Ast0.StmtTag(d) -> Ast0.StmtTag(rewrap.VT0.rebuilder_rec_statement d) | Ast0.ForInfoTag(d) -> Ast0.ForInfoTag(rewrap.VT0.rebuilder_rec_forinfo d) | Ast0.CaseLineTag(d) -> diff --git a/parsing_cocci/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll index 592c7cb9d35732e46538ed38b9ae93f32e18c0bd..f0025cdd79356eff7b1158b0a1122336670346f8 100644 --- a/parsing_cocci/lexer_cocci.mll +++ b/parsing_cocci/lexer_cocci.mll @@ -347,7 +347,11 @@ let mkassign op lexbuf = TOpAssign (op, (get_current_line_type lexbuf)) let spinit _ = (* per semantic patch *) - Hashtbl.clear Data.non_local_script_constraints + Hashtbl.clear Data.non_local_script_constraints; + D.type_names := []; + D.attr_names := []; + D.iterator_names := []; + D.declarer_names := [] let init _ = (* per file, first .cocci then iso *) line := 1; @@ -367,6 +371,7 @@ let init _ = (* per file, first .cocci then iso *) Hashtbl.clear Data.all_metadecls; Hashtbl.clear metavariables; Hashtbl.clear type_names; + Hashtbl.clear attr_names; Hashtbl.clear rule_names; Hashtbl.clear iterator_names; Hashtbl.clear declarer_names; @@ -523,6 +528,8 @@ let init _ = (* per file, first .cocci then iso *) Data.add_type_name := (function name -> let fn clt = TTypeId(name,clt) in + (if not (List.mem name !D.type_names) + then D.type_names := name :: !D.type_names); Hashtbl.replace type_names name fn); Data.add_attribute := (function name -> @@ -531,14 +538,20 @@ let init _ = (* per file, first .cocci then iso *) ((Data.PLUS | Data.PLUSPLUS),_,_,_,_,_,_,_,_,_) -> TDirective (Ast.Space name, clt) | _ -> Tattr (name, clt) in + (if not (List.mem name !D.attr_names) + then D.attr_names := name :: !D.attr_names); Hashtbl.replace attr_names name fn); Data.add_declarer_name := (function name -> let fn clt = TDeclarerId(name,clt) in + (if not (List.mem name !D.declarer_names) + then D.declarer_names := name :: !D.declarer_names); Hashtbl.replace declarer_names name fn); Data.add_iterator_name := (function name -> let fn clt = TIteratorId(name,clt) in + (if not (List.mem name !D.iterator_names) + then D.iterator_names := name :: !D.iterator_names); Hashtbl.replace iterator_names name fn); Data.add_symbol_meta := (function name -> @@ -555,6 +568,7 @@ let post_init _ = Stdcompat.Hashtbl.reset Data.all_metadecls; Stdcompat.Hashtbl.reset metavariables; Stdcompat.Hashtbl.reset type_names; + Stdcompat.Hashtbl.reset attr_names; Stdcompat.Hashtbl.reset rule_names; Stdcompat.Hashtbl.reset iterator_names; Stdcompat.Hashtbl.reset declarer_names; diff --git a/parsing_cocci/parse_aux.ml b/parsing_cocci/parse_aux.ml index 9f2d607bf18b9ca55ce895f7f14d0427d02209a6..b5d1afb4b7cad4f74588b3a491437f90db4078bb 100644 --- a/parsing_cocci/parse_aux.ml +++ b/parsing_cocci/parse_aux.ml @@ -136,6 +136,11 @@ let mkpdots str dot = "..." -> Ast0.wrap(Ast0.Pdots(clt2mcode str dot)) | _ -> failwith "cannot happen" +let mkenumdots str (dot,whencode) = + match str with + "..." -> Ast0.wrap(Ast0.EnumDots(clt2mcode str dot, whencode)) + | _ -> failwith "cannot happen" + let arith_op ast_op left op right = let op' = Ast0.wrap (Ast0.Arith (clt2mcode ast_op op)) in Ast0.wrap (Ast0.Binary(left, op', right)) diff --git a/parsing_cocci/parse_aux.mli b/parsing_cocci/parse_aux.mli index 63419831c1289d123919e039bc3ce255b7a6cf66..91d7cb263a45618e4872c352b284d6ada8fdd14a 100644 --- a/parsing_cocci/parse_aux.mli +++ b/parsing_cocci/parse_aux.mli @@ -126,6 +126,15 @@ val mkpdots : (Ast_cocci.added_string * Ast0_cocci.position_info) list * (Ast_cocci.added_string * Ast0_cocci.position_info) list * Ast0_cocci.anything list * string -> Ast0_cocci.base_parameterTypeDef Ast0_cocci.wrap +val mkenumdots : + string -> + (Data.line_type * int * int * int * int * int * + (Ast_cocci.added_string * Ast0_cocci.position_info) list * + (Ast_cocci.added_string * Ast0_cocci.position_info) list * Ast0_cocci.anything list * + string) * + (string Ast0_cocci.mcode * string Ast0_cocci.mcode * Ast0_cocci.enum_decl) + option -> + Ast0_cocci.base_enum_decl Ast0_cocci.wrap val arith_op : Ast_cocci.arithOp -> Ast0_cocci.expression -> diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml index a9ed0b45dd2b668a3456406ae9dba14612c30307..7b9ba3c21a00a73d24316456f8bf290bb71b3c46 100644 --- a/parsing_cocci/parse_cocci.ml +++ b/parsing_cocci/parse_cocci.ml @@ -1891,7 +1891,7 @@ let any_modif rule = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing in + donothing donothing donothing in List.exists fn.VT0.combiner_rec_top_level rule let eval_virt virt = @@ -2545,7 +2545,7 @@ let contains_modifs ast = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing in + donothing donothing donothing donothing in List.exists (function Ast.CocciRule(nm,infos,ast,_,_) -> diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index 0a29a24560bd127a8caa300997b861ee4e52eba2..9f497e85467c514c750bb5cc4f68aa89ba476c0c 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -1176,15 +1176,12 @@ struct_decl_list_start: /* very restricted what kinds of expressions can appear in an enum decl */ enum_decl_one: - | disj_ident { Ast0.wrap(Ast0.Ident($1)) } + | disj_ident { Ast0.wrap(Ast0.Enum($1, None)) } | disj_ident TEq enum_val - { let id = Ast0.wrap(Ast0.Ident($1)) in - let (op,clt) = ("=",$2) in - let op' = P.clt2mcode op clt in - let op'' = Ast0.wrap (Ast0.SimpleAssign op') in + { Ast0.wrap - (Ast0.Assignment - (id, op'', Ast0.set_arg_exp $3, false)) } + (Ast0.Enum + ($1, Some(P.clt2mcode "=" $2, $3))) } enum_val: ident { Ast0.wrap(Ast0.Ident($1)) } @@ -1209,7 +1206,7 @@ enum_val: enum_decl_list: nonempty_list_start(enum_decl_one,edots_when(TEllipsis,enum_decl_one)) - { Ast0.wrap($1 P.mkedots (fun c -> Ast0.EComma c)) } + { Ast0.wrap($1 P.mkenumdots (fun c -> Ast0.EnumComma c)) } /*****************************************************************************/ diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index 1415f0296c6ff8bef1ccf97b82b9d716626dabc4..fa4259d154902fdaaab3aff2a1d0e9207e24f062 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -439,7 +439,7 @@ and typeC ty = print_option (function x -> ident x; print_string " ") name | Ast.EnumDef(ty,lb,ids,rb) -> fullType ty; mcode print_string lb; - dots force_newline expression ids; + dots force_newline enum_decl ids; mcode print_string rb | Ast.StructUnionName(kind,name) -> mcode structUnion kind; @@ -586,6 +586,20 @@ and annotated_field arity d = | Ast.ConjField(decls) -> print_disj_list (annotated_field arity) decls "&" | Ast.OptField(decl) -> print_string "?"; annotated_field arity decl +and enum_decl d = + match Ast.unwrap d with + Ast.Enum(name,enum_val) -> + ident name; + (match enum_val with + None -> () + | Some(eq,eval) -> + mcode print_string eq; + expression eval) + | Ast.EnumComma(cm) -> mcode print_string cm + | Ast.EnumDots(dots,Some whencode) -> + mcode print_string dots; print_string " when != "; enum_decl whencode + | Ast.EnumDots(dots,None) -> mcode print_string dots + (* --------------------------------------------------------------------- *) (* Initialiser *) @@ -1091,6 +1105,7 @@ let _ = | Ast.InitTag(x) -> initialiser x | Ast.DeclarationTag(x) -> declaration x | Ast.FieldTag(x) -> field x + | Ast.EnumDeclTag(x) -> enum_decl x | Ast.StorageTag(x) -> storage x | Ast.IncFileTag(x) -> inc_file x | Ast.Rule_elemTag(x) -> rule_elem "" x @@ -1111,6 +1126,7 @@ let _ = | Ast.StmtDotsTag(x) -> dots (function _ -> ()) (statement "") x | Ast.AnnDeclDotsTag(x) -> dots (function _ -> ()) (annotated_decl "") x | Ast.AnnFieldDotsTag(x) -> dots (function _ -> ()) (annotated_field "") x + | Ast.EnumDeclDotsTag(x) -> dots (function _ -> ()) enum_decl x | Ast.DefParDotsTag(x) -> dots (function _ -> ()) print_define_param x | Ast.TypeCTag(x) -> typeC x | Ast.ParamTag(x) -> parameterTypeDef x diff --git a/parsing_cocci/re_constraints.ml b/parsing_cocci/re_constraints.ml index cc2185431521cffd86d9f38826508b0b5960edfb..17011465503ebd68985e008cd786859f0b88d3b9 100644 --- a/parsing_cocci/re_constraints.ml +++ b/parsing_cocci/re_constraints.ml @@ -41,9 +41,9 @@ let disj_free re = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing ident + donothing donothing donothing donothing donothing donothing donothing ident expr donothing donothing donothing donothing ty donothing - donothing donothing donothing decl donothing donothing ann_field + donothing donothing donothing decl donothing donothing ann_field donothing rule_elem statement donothing donothing donothing in try Hashtbl.find disj_free_table re with Not_found -> @@ -90,7 +90,7 @@ let ok_for_all_rule_elems cstr minirules = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - rule_elem donothing donothing donothing donothing in + donothing donothing rule_elem donothing donothing donothing donothing in List.for_all v.V.combiner_top_level minirules let update_for_all_rule_elems cstr minirules = @@ -111,8 +111,8 @@ let update_for_all_rule_elems cstr minirules = mcode mcode donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing - donothing donothing donothing donothing + donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing rule_elem donothing donothing donothing donothing in List.map v.V.rebuilder_top_level minirules diff --git a/parsing_cocci/safe_for_multi_decls.ml b/parsing_cocci/safe_for_multi_decls.ml index 070489c506e13464ff5525aa9722bbb27870bb8f..8fc494325769d4d75d8c62a9e1118b4d960483a7 100644 --- a/parsing_cocci/safe_for_multi_decls.ml +++ b/parsing_cocci/safe_for_multi_decls.ml @@ -43,7 +43,7 @@ let all_removed_recursor = do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing do_nothing + do_nothing do_nothing do_nothing do_nothing let all_removed_decl = all_removed_recursor.V.combiner_declaration @@ -97,9 +97,10 @@ let contains_modif = mcode mcode mcode mcode mcode do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing do_nothing init do_nothing + do_nothing do_nothing do_nothing init do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in + do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing + do_nothing in recursor.V.combiner_fullType let decl r k e = @@ -172,8 +173,8 @@ let process = mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing decl anndecl field annfield - donothing donothing donothing donothing donothing in + donothing donothing donothing donothing decl anndecl field annfield + donothing donothing donothing donothing donothing donothing in List.map fn.V.rebuilder_top_level let safe_for_multi_decls rules = diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index 355fbfd1ad8a348bbb7fee7dee03b8c92089eaf5..d12ca8562c1025e97f943e6eb84d228f11abf163 100644 --- a/parsing_cocci/single_statement.ml +++ b/parsing_cocci/single_statement.ml @@ -459,9 +459,10 @@ and contains_only_minus = V0.flat_combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - dots dots dots dots dots dots dots dots + dots dots dots dots dots dots dots dots dots identifier expression donothing donothing typeC donothing donothing - declaration field statement donothing case_line donothing donothing + declaration field donothing statement donothing case_line donothing + donothing (* needs a special case when there is a Disj or an empty DOTS *) diff --git a/parsing_cocci/stmtlist.ml b/parsing_cocci/stmtlist.ml index 2f01c4043bebedc4cea267874378bac4b2a6c7cd..4e7a0b5af656be7b8af770a1b8d6f90482765910 100644 --- a/parsing_cocci/stmtlist.ml +++ b/parsing_cocci/stmtlist.ml @@ -55,8 +55,8 @@ let stmtlist_rebuilder = donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing statement donothing donothing - donothing + donothing donothing donothing donothing donothing donothing + statement donothing donothing donothing let stmtlist rule = match rule with diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml index 15667fea69b27c66dfd1dd9285184cfa01444caf..e6b400cf885b09a2dbd53f62837da17dea7e2750 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -117,6 +117,11 @@ let dpdots e = Ast.DPdots(_) -> true | _ -> false +let enumdots e = + match Ast.unwrap e with + Ast.EnumDots(_) -> true + | _ -> false + let sdots s = match Ast.unwrap s with Ast.Dots(_,_,_,_) -> true @@ -348,7 +353,7 @@ and unify_typeC t1 t2 = true | (Ast.EnumDef(ty1,lb1,ids1,rb1),Ast.EnumDef(ty2,lb2,ids2,rb2)) -> unify_fullType ty1 ty2 && - unify_dots unify_expression edots ids1 ids2 + unify_dots unify_enum_decl enumdots ids1 ids2 | (Ast.StructUnionName(s1,Some ts1),Ast.StructUnionName(s2,Some ts2)) -> if unify_mcode s1 s2 then unify_ident ts1 ts2 else false | (Ast.StructUnionName(s1,None),Ast.StructUnionName(s2,None)) -> @@ -477,6 +482,19 @@ and unify_annotated_field d1 d2 = | (Ast.OptField(_),_) | (_,Ast.OptField(_)) -> failwith "unsupported decl" +and unify_enum_decl d1 d2 = + match (Ast.unwrap d1,Ast.unwrap d2) with + (Ast.Enum(name1,enum_val1),Ast.Enum(name2,enum_val2)) -> + unify_ident name1 name2 && + unify_option + (function a -> function b -> + let (_,eval1) = a in + let (_,eval2) = b in + unify_expression eval1 eval2) enum_val1 enum_val2 + | (Ast.EnumComma(_),(Ast.EnumComma(_))) -> true + | (Ast.EnumDots(_),(Ast.EnumDots(_))) -> true + | _ -> false + (* --------------------------------------------------------------------- *) (* Initializer *) @@ -701,10 +719,11 @@ and subexp f = let recursor = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing donothing expr + donothing donothing donothing donothing donothing donothing donothing + donothing expr donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing in + donothing donothing donothing donothing donothing in recursor.V.combiner_rule_elem and subtype f = @@ -717,10 +736,10 @@ and subtype f = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing - donothing donothing donothing donothing donothing fullType + donothing donothing donothing donothing donothing donothing fullType donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing in + donothing donothing in recursor.V.combiner_rule_elem let rec unify_statement s1 s2 = diff --git a/parsing_cocci/unitary_ast0.ml b/parsing_cocci/unitary_ast0.ml index a4eed517bdc9fbc3a4db13077eb6dc278073288b..f12bef67b3c975fb8e931209723e58fd65d2cafb 100644 --- a/parsing_cocci/unitary_ast0.ml +++ b/parsing_cocci/unitary_ast0.ml @@ -204,9 +204,10 @@ let get_free checker t = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing - donothing + donothing donothing ident expression donothing donothing typeC donothing parameter - declaration field statement donothing case_line donothing donothing in + declaration field donothing statement donothing case_line donothing + donothing in collect_unitary_nonunitary (List.concat (List.map res.VT0.combiner_rec_top_level t)) diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index cd763d24953746181a11d22148fbecdef5503a74..63b17bc3ac104be0721d1ce6f02610cb15bce98c 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -321,7 +321,7 @@ and typeC t = print_option (function x -> ident x; print_string " ") name | Ast0.EnumDef(ty,lb,ids,rb) -> typeC ty; mcode print_string lb; - dots force_newline expression ids; + dots force_newline enum_decl ids; mcode print_string rb | Ast0.StructUnionName(kind,name) -> mcode U.structUnion kind; @@ -455,6 +455,24 @@ and field d = and field_dots l = dots (function _ -> ()) field l +and enum_decl d = + print_context d + (function _ -> + match Ast0.unwrap d with + Ast0.Enum(name,enum_val) -> + (match enum_val with + None -> ident name + | Some(eq,eval) -> + ident name; mcode print_string eq; expression eval) + | Ast0.EnumComma(cm) -> + mcode print_string cm; force_newline() + | Ast0.EnumDots(dots,Some (_,_,whencode)) -> + mcode print_string dots; print_string " when != "; + enum_decl whencode + | Ast0.EnumDots(dots,None) -> mcode print_string dots) + +and enum_decl_dots l = dots (function _ -> ()) enum_decl l + (* --------------------------------------------------------------------- *) (* Initialiser *) @@ -782,6 +800,7 @@ let rec unparse_anything x = statement_dots d | Ast0.DotsDeclTag(d) -> declaration_dots d | Ast0.DotsFieldTag(d) -> field_dots d + | Ast0.DotsEnumDeclTag(d) -> enum_decl_dots d | Ast0.DotsCaseTag(d) -> case_dots d | Ast0.DotsDefParamTag(d) -> define_param_dots d | Ast0.IdentTag(d) -> ident d @@ -797,6 +816,7 @@ let rec unparse_anything x = | Ast0.InitTag(d) -> initialiser d | Ast0.DeclTag(d) -> declaration d | Ast0.FieldTag(d) -> field d + | Ast0.EnumDeclTag(d) -> enum_decl d | Ast0.StmtTag(d) -> print_string "Stm:"; force_newline(); statement "" d diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 2f3841825c34edc3a8ded1408bc96984a85e12dd..b83c582a5225c59847700214cb98ebf6ba5f33d2 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -27,6 +27,7 @@ type 'a combiner = combiner_declaration : Ast.declaration -> 'a; combiner_field : Ast.field -> 'a; combiner_ann_field : Ast.annotated_field -> 'a; + combiner_enumdecl : Ast_cocci.enum_decl -> 'a; combiner_initialiser : Ast.initialiser -> 'a; combiner_parameter : Ast.parameterTypeDef -> 'a; combiner_parameter_list : Ast.parameter_list -> 'a; @@ -39,6 +40,7 @@ type 'a combiner = combiner_statement_dots : Ast.statement Ast.dots -> 'a; combiner_anndecl_dots : Ast.annotated_decl Ast.dots -> 'a; combiner_annfield_dots : Ast.annotated_field Ast.dots -> 'a; + combiner_enumdecl_dots : Ast.enum_decl Ast.dots -> 'a; combiner_initialiser_dots : Ast.initialiser Ast.dots -> 'a} type ('mc,'a) cmcode = 'a combiner -> 'mc Ast_cocci.mcode -> 'a @@ -50,11 +52,12 @@ let combiner bind option_default unary_mcodefn arithop_mcodefn logicalop_mcodefn cv_mcodefn sign_mcodefn struct_mcodefn storage_mcodefn inc_file_mcodefn - expdotsfn paramdotsfn stmtdotsfn anndecldotsfn annfielddotsfn initdotsfn + expdotsfn paramdotsfn stmtdotsfn anndecldotsfn annfielddotsfn + enumdecldotsfn initdotsfn identfn exprfn fragfn fmtfn assignOpfn binaryOpfn ftfn tyfn initfn paramfn define_paramfn declfn - annotated_declfn fieldfn annotated_fieldfn rulefn stmtfn casefn topfn - anyfn = + annotated_declfn fieldfn annotated_fieldfn enum_declfn rulefn stmtfn + casefn topfn anyfn = let multibind l = let rec loop = function [] -> option_default @@ -95,6 +98,8 @@ let combiner bind option_default dotsfn anndecldotsfn annotated_decl all_functions d and annotated_field_dots d = dotsfn annfielddotsfn annotated_field all_functions d + and enum_decl_dots d = + dotsfn enumdecldotsfn enum_decl all_functions d and initialiser_dots d = dotsfn initdotsfn initialiser all_functions d and string_fragment_dots d = dotsfn strdotsfn string_fragment all_functions d and exec_code_dots d = dotsfn ecdotsfn exec_code all_functions d @@ -348,7 +353,7 @@ let combiner bind option_default | Ast.EnumDef(ty,lb,ids,rb) -> let lty = fullType ty in let llb = string_mcode lb in - let lids = expression_dots ids in + let lids = enum_decl_dots ids in let lrb = string_mcode rb in multibind [lty; llb; lids; lrb] | Ast.StructUnionName(kind,name) -> @@ -499,6 +504,25 @@ let combiner bind option_default | Ast.OptField(decl) -> annotated_field decl in annotated_fieldfn all_functions k d + and enum_decl d = + let k d = + match Ast.unwrap d with + Ast.Enum(name,enum_val) -> + let lname = ident name in + (match enum_val with + None -> lname + | Some(eq,eval) -> + let leq = string_mcode eq in + let leval = expression eval in + multibind [lname; leq; leval]) + | Ast.EnumComma(cm) -> + string_mcode cm + | Ast.EnumDots(dots,whncode) -> + let ldots = string_mcode dots in + let lwhncode = get_option enum_decl whncode in + bind ldots lwhncode in + enum_declfn all_functions k d + and initialiser i = let k i = match Ast.unwrap i with @@ -900,6 +924,7 @@ let combiner bind option_default | Ast.LogicalOpTag(logop) -> option_default | Ast.DeclarationTag(decl) -> declaration decl | Ast.FieldTag(decl) -> field decl + | Ast.EnumDeclTag(decl) -> enum_decl decl | Ast.InitTag(ini) -> initialiser ini | Ast.StorageTag(stg) -> option_default | Ast.IncFileTag(stg) -> option_default @@ -917,6 +942,7 @@ let combiner bind option_default | Ast.StmtDotsTag(sd) -> statement_dots sd | Ast.AnnDeclDotsTag(sd) -> annotated_decl_dots sd | Ast.AnnFieldDotsTag(sd) -> annotated_field_dots sd + | Ast.EnumDeclDotsTag(sd) -> enum_decl_dots sd | Ast.DefParDotsTag(sd) -> define_param_dots sd | Ast.TypeCTag(ty) -> typeC ty | Ast.ParamTag(param) -> parameterTypeDef param @@ -936,6 +962,7 @@ let combiner bind option_default combiner_declaration = declaration; combiner_field = field; combiner_ann_field = annotated_field; + combiner_enumdecl = enum_decl; combiner_initialiser = initialiser; combiner_parameter = parameterTypeDef; combiner_parameter_list = parameter_dots; @@ -948,6 +975,7 @@ let combiner bind option_default combiner_statement_dots = statement_dots; combiner_anndecl_dots = annotated_decl_dots; combiner_annfield_dots = annotated_field_dots; + combiner_enumdecl_dots = enum_decl_dots; combiner_initialiser_dots = initialiser_dots} in all_functions @@ -967,6 +995,7 @@ type rebuilder = rebuilder_declaration : Ast.declaration inout; rebuilder_field : Ast.field inout; rebuilder_ann_field : Ast.annotated_field inout; + rebuilder_enumdecl : Ast_cocci.enum_decl inout; rebuilder_initialiser : Ast.initialiser inout; rebuilder_parameter : Ast.parameterTypeDef inout; rebuilder_parameter_list : Ast.parameter_list inout; @@ -978,6 +1007,7 @@ type rebuilder = rebuilder_statement_dots : Ast.statement Ast.dots inout; rebuilder_anndecl_dots : Ast.annotated_decl Ast.dots inout; rebuilder_annfield_dots : Ast.annotated_field Ast.dots inout; + rebuilder_enumdecl_dots : Ast.enum_decl Ast.dots inout; rebuilder_initialiser_dots : Ast.initialiser Ast.dots inout; rebuilder_define_param_dots : Ast.define_param Ast.dots inout; rebuilder_define_param : Ast.define_param inout; @@ -993,10 +1023,11 @@ let rebuilder fix_mcode unary_mcode arithop_mcode logicalop_mcode cv_mcode sign_mcode struct_mcode storage_mcode inc_file_mcode - expdotsfn paramdotsfn stmtdotsfn anndecldotsfn annfielddotsfn initdotsfn + expdotsfn paramdotsfn stmtdotsfn anndecldotsfn annfielddotsfn + enumdecldotsfn initdotsfn identfn exprfn fragfn fmtfn assignOpfn binaryOpfn ftfn tyfn initfn paramfn define_paramfn declfn annotated_declfn fieldfn annotated_fieldfn - rulefn stmtfn casefn topfn anyfn = + enum_declfn rulefn stmtfn casefn topfn anyfn = let get_option f = function Some x -> Some (f x) | None -> None in @@ -1015,6 +1046,8 @@ let rebuilder dotsfn anndecldotsfn annotated_decl all_functions d and annotated_field_dots d = dotsfn annfielddotsfn annotated_field all_functions d + and enum_decl_dots d = + dotsfn enumdecldotsfn enum_decl all_functions d and initialiser_dots d = dotsfn initdotsfn initialiser all_functions d and string_fragment_dots d = dotsfn strdotsfn string_fragment all_functions d and exec_code_dots d = dotsfn ecdotsfn exec_code all_functions d @@ -1275,7 +1308,7 @@ let rebuilder | Ast.EnumDef(ty,lb,ids,rb) -> let lty = fullType ty in let llb = string_mcode lb in - let lids = expression_dots ids in + let lids = enum_decl_dots ids in let lrb = string_mcode rb in Ast.EnumDef (lty, llb, lids, lrb) | Ast.StructUnionName(kind,name) -> @@ -1423,6 +1456,27 @@ let rebuilder | Ast.OptField(decl) -> Ast.OptField(annotated_field decl)) in annotated_fieldfn all_functions k d + and enum_decl d = + let k d = + Ast.rewrap d + (match Ast.unwrap d with + Ast.Enum(name,enum_val) -> + let lname = ident name in + (match enum_val with + None -> Ast.Enum(lname,None) + | Some(eq,eval) -> + let leq = string_mcode eq in + let leval = expression eval in + Ast.Enum(lname,Some(leq,leval))) + | Ast.EnumComma(cm) -> + let lcm = string_mcode cm in + Ast.EnumComma(lcm) + | Ast.EnumDots(dots,whncode) -> + let ldots = string_mcode dots in + let lwhncode = get_option enum_decl whncode in + Ast.EnumDots(ldots, lwhncode)) in + enum_declfn all_functions k d + and initialiser i = let k i = Ast.rewrap i @@ -1853,6 +1907,7 @@ let rebuilder | Ast.InitTag(decl) -> Ast.InitTag(initialiser decl) | Ast.DeclarationTag(decl) -> Ast.DeclarationTag(declaration decl) | Ast.FieldTag(decl) -> Ast.FieldTag(field decl) + | Ast.EnumDeclTag(decl) -> Ast.EnumDeclTag(enum_decl decl) | Ast.StorageTag(stg) as x -> x | Ast.IncFileTag(stg) as x -> x | Ast.Rule_elemTag(rule) -> Ast.Rule_elemTag(rule_elem rule) @@ -1870,6 +1925,7 @@ let rebuilder | Ast.StmtDotsTag(sd) -> Ast.StmtDotsTag(statement_dots sd) | Ast.AnnDeclDotsTag(sd) -> Ast.AnnDeclDotsTag(annotated_decl_dots sd) | Ast.AnnFieldDotsTag(sd) -> Ast.AnnFieldDotsTag(annotated_field_dots sd) + | Ast.EnumDeclDotsTag(sd) -> Ast.EnumDeclDotsTag(enum_decl_dots sd) | Ast.DefParDotsTag(sd) -> Ast.DefParDotsTag(define_param_dots sd) | Ast.TypeCTag(ty) -> Ast.TypeCTag(typeC ty) | Ast.ParamTag(param) -> Ast.ParamTag(parameterTypeDef param) @@ -1889,6 +1945,7 @@ let rebuilder rebuilder_declaration = declaration; rebuilder_field = field; rebuilder_ann_field = annotated_field; + rebuilder_enumdecl = enum_decl; rebuilder_initialiser = initialiser; rebuilder_parameter = parameterTypeDef; rebuilder_parameter_list = parameter_dots; @@ -1900,6 +1957,7 @@ let rebuilder rebuilder_statement_dots = statement_dots; rebuilder_anndecl_dots = annotated_decl_dots; rebuilder_annfield_dots = annotated_field_dots; + rebuilder_enumdecl_dots = enum_decl_dots; rebuilder_initialiser_dots = initialiser_dots; rebuilder_define_param_dots = define_param_dots; rebuilder_define_param = define_param; diff --git a/parsing_cocci/visitor_ast.mli b/parsing_cocci/visitor_ast.mli index 20ce32b06d919719b8981e18534e430e5c59d050..0ed177749233b3ae7a2cdccdb73a937f2e303043 100644 --- a/parsing_cocci/visitor_ast.mli +++ b/parsing_cocci/visitor_ast.mli @@ -16,6 +16,7 @@ type 'a combiner = combiner_declaration : Ast_cocci.declaration -> 'a; combiner_field : Ast_cocci.field -> 'a; combiner_ann_field : Ast_cocci.annotated_field -> 'a; + combiner_enumdecl : Ast_cocci.enum_decl -> 'a; combiner_initialiser : Ast_cocci.initialiser -> 'a; combiner_parameter : Ast_cocci.parameterTypeDef -> 'a; combiner_parameter_list : Ast_cocci.parameter_list -> 'a; @@ -28,6 +29,7 @@ type 'a combiner = combiner_statement_dots : Ast_cocci.statement Ast_cocci.dots -> 'a; combiner_anndecl_dots : Ast_cocci.annotated_decl Ast_cocci.dots -> 'a; combiner_annfield_dots : Ast_cocci.annotated_field Ast_cocci.dots -> 'a; + combiner_enumdecl_dots : Ast_cocci.enum_decl Ast_cocci.dots -> 'a; combiner_initialiser_dots : Ast_cocci.initialiser Ast_cocci.dots -> 'a} type ('mc,'a) cmcode = 'a combiner -> 'mc Ast_cocci.mcode -> 'a @@ -54,6 +56,7 @@ val combiner : ((Ast_cocci.statement Ast_cocci.dots,'a) ccode) -> ((Ast_cocci.annotated_decl Ast_cocci.dots,'a) ccode) -> ((Ast_cocci.annotated_field Ast_cocci.dots,'a) ccode) -> + ((Ast_cocci.enum_decl Ast_cocci.dots,'a) ccode) -> ((Ast_cocci.initialiser Ast_cocci.dots,'a) ccode) -> ((Ast_cocci.ident,'a) ccode) -> ((Ast_cocci.expression,'a) ccode) -> @@ -70,6 +73,7 @@ val combiner : ((Ast_cocci.annotated_decl,'a) ccode) -> ((Ast_cocci.field,'a) ccode) -> ((Ast_cocci.annotated_field,'a) ccode) -> + ((Ast_cocci.enum_decl,'a) ccode) -> ((Ast_cocci.rule_elem,'a) ccode) -> ((Ast_cocci.statement,'a) ccode) -> ((Ast_cocci.case_line,'a) ccode) -> @@ -91,6 +95,7 @@ type rebuilder = rebuilder_declaration : Ast_cocci.declaration inout; rebuilder_field : Ast_cocci.field inout; rebuilder_ann_field : Ast_cocci.annotated_field inout; + rebuilder_enumdecl : Ast_cocci.enum_decl inout; rebuilder_initialiser : Ast_cocci.initialiser inout; rebuilder_parameter : Ast_cocci.parameterTypeDef inout; rebuilder_parameter_list : Ast_cocci.parameter_list inout; @@ -102,6 +107,7 @@ type rebuilder = rebuilder_statement_dots : Ast_cocci.statement Ast_cocci.dots inout; rebuilder_anndecl_dots : Ast_cocci.annotated_decl Ast_cocci.dots inout; rebuilder_annfield_dots : Ast_cocci.annotated_field Ast_cocci.dots inout; + rebuilder_enumdecl_dots : Ast_cocci.enum_decl Ast_cocci.dots inout; rebuilder_initialiser_dots : Ast_cocci.initialiser Ast_cocci.dots inout; rebuilder_define_param_dots: Ast_cocci.define_param Ast_cocci.dots inout; rebuilder_define_param : Ast_cocci.define_param inout; @@ -131,6 +137,7 @@ val rebuilder : (Ast_cocci.statement Ast_cocci.dots rcode) -> (Ast_cocci.annotated_decl Ast_cocci.dots rcode) -> (Ast_cocci.annotated_field Ast_cocci.dots rcode) -> + (Ast_cocci.enum_decl Ast_cocci.dots rcode) -> (Ast_cocci.initialiser Ast_cocci.dots rcode) -> (Ast_cocci.ident rcode) -> (Ast_cocci.expression rcode) -> @@ -147,6 +154,7 @@ val rebuilder : (Ast_cocci.annotated_decl rcode) -> (Ast_cocci.field rcode) -> (Ast_cocci.annotated_field rcode) -> + (Ast_cocci.enum_decl rcode) -> (Ast_cocci.rule_elem rcode) -> (Ast_cocci.statement rcode) -> (Ast_cocci.case_line rcode) -> diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index b5e027f35291e46fe9fa5b70c39785122a22980a..afe2255d5a7d4eab8e0a54aaa899358968899ca1 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -22,8 +22,9 @@ let visitor mode bind option_default fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode struct_mcode storage_mcode inc_mcode dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn - dotscasefn dotsdefparfn + dotsenumdeclfn dotscasefn dotsdefparfn identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn + enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn = let multibind l = let rec loop = function @@ -63,6 +64,7 @@ let visitor mode bind option_default and statement_dots d = dotsfn dotsstmtfn statement all_functions d and declaration_dots d = dotsfn dotsdeclfn declaration all_functions d and field_dots d = dotsfn dotsfieldfn field all_functions d + and enum_decl_dots d = dotsfn dotsenumdeclfn enum_decl all_functions d and case_line_dots d = dotsfn dotscasefn case_line all_functions d and string_fragment_dots d = dotsfn strdotsfn string_fragment all_functions d and exec_code_dots d = dotsfn ecdotsfn exec_code all_functions d @@ -358,7 +360,7 @@ let visitor mode bind option_default | Ast0.EnumDef(ty,lb,ids,rb) -> let (ty_n,ty) = typeC ty in let (lb_n,lb) = string_mcode lb in - let (ids_n,ids) = expression_dots ids in + let (ids_n,ids) = enum_decl_dots ids in let (rb_n,rb) = string_mcode rb in (multibind [ty_n;lb_n;ids_n;rb_n], Ast0.EnumDef(ty,lb,ids,rb)) | Ast0.StructUnionName(kind,name) -> @@ -625,6 +627,34 @@ let visitor mode bind option_default let (n,decl) = field decl in (n,Ast0.OptField(decl))) in fieldfn all_functions k d + and enum_decl d = + let k d = + rewrap d + (match Ast0.unwrap d with + Ast0.Enum(name,enum_val) -> + let (name_n,name) = ident name in + (match enum_val with + None -> (name_n,Ast0.Enum(name,None)) + | Some(eq,eval) -> + let (eq_n,eq) = string_mcode eq in + let (eval_n,eval) = expression eval in + (multibind [name_n; eq_n; eval_n], + Ast0.Enum(name,Some(eq,eval)))) + | Ast0.EnumComma(cm) -> + let (cm_n,cm) = string_mcode cm in + (cm_n,Ast0.EnumComma(cm)) + | Ast0.EnumDots(dots,whencode) -> + let (dots_n,dots) = string_mcode dots in + let (whencode_n, whencode) = match whencode with + | Some (a,b,c) -> + let (_,a2) = string_mcode a in + let (_,b2) = string_mcode b in + let (c1,c2) = enum_decl c in (c1, Some (a2,b2,c2)) + | None -> (option_default, None) in + (bind dots_n whencode_n, Ast0.EnumDots(dots,whencode))) in + enumdeclfn all_functions k d + + and initialiser i = let k i = rewrap i @@ -1124,6 +1154,9 @@ let visitor mode bind option_default | Ast0.DotsFieldTag(decls) -> let (decls_n,decls) = field_dots decls in (decls_n,Ast0.DotsFieldTag(decls)) + | Ast0.DotsEnumDeclTag(decls) -> + let (decls_n,decls) = enum_decl_dots decls in + (decls_n,Ast0.DotsEnumDeclTag(decls)) | Ast0.DotsCaseTag(cases) -> let (cases_n,cases) = case_line_dots cases in (cases_n,Ast0.DotsCaseTag(cases)) @@ -1163,6 +1196,9 @@ let visitor mode bind option_default | Ast0.FieldTag(decl) -> let (decl_n,decl) = field decl in (decl_n,Ast0.FieldTag(decl)) + | Ast0.EnumDeclTag(decl) -> + let (decl_n,decl) = enum_decl decl in + (decl_n,Ast0.EnumDeclTag(decl)) | Ast0.StmtTag(stmt) -> let (stmt_n,stmt) = statement stmt in (stmt_n,Ast0.StmtTag(stmt)) @@ -1207,6 +1243,7 @@ let visitor mode bind option_default VT0.typeC = typeC; VT0.declaration = declaration; VT0.field = field; + VT0.enum_decl = enum_decl; VT0.initialiser = initialiser; VT0.initialiser_list = initialiser_dots; VT0.parameter = parameterTypeDef; @@ -1221,6 +1258,7 @@ let visitor mode bind option_default VT0.statement_dots = statement_dots; VT0.declaration_dots = declaration_dots; VT0.field_dots = field_dots; + VT0.enum_decl_dots = enum_decl_dots; VT0.case_line_dots = case_line_dots; VT0.define_param_dots = define_param_dots; VT0.anything = anything} in @@ -1247,6 +1285,7 @@ let combiner_functions = VT0.combiner_dotsstmtfn = (fun r k e -> k e); VT0.combiner_dotsdeclfn = (fun r k e -> k e); VT0.combiner_dotsfieldfn = (fun r k e -> k e); + VT0.combiner_dotsenumdeclfn = (fun r k e -> k e); VT0.combiner_dotscasefn = (fun r k e -> k e); VT0.combiner_dotsdefparfn = (fun r k e -> k e); VT0.combiner_identfn = (fun r k e -> k e); @@ -1258,6 +1297,7 @@ let combiner_functions = VT0.combiner_paramfn = (fun r k e -> k e); VT0.combiner_declfn = (fun r k e -> k e); VT0.combiner_fieldfn = (fun r k e -> k e); + VT0.combiner_enumdeclfn = (fun r k e -> k e); VT0.combiner_stmtfn = (fun r k e -> k e); VT0.combiner_forinfofn = (fun r k e -> k e); VT0.combiner_casefn = (fun r k e -> k e); @@ -1281,6 +1321,8 @@ let combiner_dz r = (function e -> let (n,_) = r.VT0.declaration e in n); VT0.combiner_rec_field = (function e -> let (n,_) = r.VT0.field e in n); + VT0.combiner_rec_enumdecl = + (function e -> let (n,_) = r.VT0.enum_decl e in n); VT0.combiner_rec_initialiser = (function e -> let (n,_) = r.VT0.initialiser e in n); VT0.combiner_rec_initialiser_list = @@ -1309,6 +1351,8 @@ let combiner_dz r = (function e -> let (n,_) = r.VT0.declaration_dots e in n); VT0.combiner_rec_field_dots = (function e -> let (n,_) = r.VT0.field_dots e in n); + VT0.combiner_rec_enum_decl_dots = + (function e -> let (n,_) = r.VT0.enum_decl_dots e in n); VT0.combiner_rec_case_line_dots = (function e -> let (n,_) = r.VT0.case_line_dots e in n); VT0.combiner_rec_define_param_dots = @@ -1346,6 +1390,7 @@ let combiner bind option_default functions = (fun r k e -> (functions.VT0.combiner_dotsstmtfn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_dotsdeclfn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_dotsfieldfn (dz r) (xk k) e, e)) + (fun r k e -> (functions.VT0.combiner_dotsenumdeclfn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_dotscasefn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_dotsdefparfn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_identfn (dz r) (xk k) e, e)) @@ -1357,6 +1402,7 @@ let combiner bind option_default functions = (fun r k e -> (functions.VT0.combiner_paramfn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_declfn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_fieldfn (dz r) (xk k) e, e)) + (fun r k e -> (functions.VT0.combiner_enumdeclfn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_stmtfn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_forinfofn (dz r) (xk k) e, e)) (fun r k e -> (functions.VT0.combiner_casefn (dz r) (xk k) e, e)) @@ -1368,8 +1414,9 @@ let flat_combiner bind option_default fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode struct_mcode storage_mcode inc_mcode dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn - dotscasefn dotsdefparfn + dotsenumdeclfn dotscasefn dotsdefparfn identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn + enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn = let dz = combiner_dz in let xk k e = let (n,_) = k e in n in @@ -1394,6 +1441,7 @@ let flat_combiner bind option_default (fun r k e -> (dotsstmtfn (dz r) (xk k) e, e)) (fun r k e -> (dotsdeclfn (dz r) (xk k) e, e)) (fun r k e -> (dotsfieldfn (dz r) (xk k) e, e)) + (fun r k e -> (dotsenumdeclfn (dz r) (xk k) e, e)) (fun r k e -> (dotscasefn (dz r) (xk k) e, e)) (fun r k e -> (dotsdefparfn (dz r) (xk k) e, e)) (fun r k e -> (identfn (dz r) (xk k) e, e)) @@ -1405,6 +1453,7 @@ let flat_combiner bind option_default (fun r k e -> (paramfn (dz r) (xk k) e, e)) (fun r k e -> (declfn (dz r) (xk k) e, e)) (fun r k e -> (fieldfn (dz r) (xk k) e, e)) + (fun r k e -> (enumdeclfn (dz r) (xk k) e, e)) (fun r k e -> (stmtfn (dz r) (xk k) e, e)) (fun r k e -> (forinfofn (dz r) (xk k) e, e)) (fun r k e -> (casefn (dz r) (xk k) e, e)) @@ -1432,6 +1481,7 @@ let rebuilder_functions = VT0.rebuilder_dotsstmtfn = (fun r k e -> k e); VT0.rebuilder_dotsdeclfn = (fun r k e -> k e); VT0.rebuilder_dotsfieldfn = (fun r k e -> k e); + VT0.rebuilder_dotsenumdeclfn = (fun r k e -> k e); VT0.rebuilder_dotscasefn = (fun r k e -> k e); VT0.rebuilder_dotsdefparfn = (fun r k e -> k e); VT0.rebuilder_identfn = (fun r k e -> k e); @@ -1443,6 +1493,7 @@ let rebuilder_functions = VT0.rebuilder_paramfn = (fun r k e -> k e); VT0.rebuilder_declfn = (fun r k e -> k e); VT0.rebuilder_fieldfn = (fun r k e -> k e); + VT0.rebuilder_enumdeclfn = (fun r k e -> k e); VT0.rebuilder_stmtfn = (fun r k e -> k e); VT0.rebuilder_forinfofn = (fun r k e -> k e); VT0.rebuilder_casefn = (fun r k e -> k e); @@ -1466,6 +1517,8 @@ let rebuilder_dz r = (function e -> let (_,e) = r.VT0.declaration e in e); VT0.rebuilder_rec_field = (function e -> let (_,e) = r.VT0.field e in e); + VT0.rebuilder_rec_enumdecl = + (function e -> let (_,e) = r.VT0.enum_decl e in e); VT0.rebuilder_rec_initialiser = (function e -> let (_,e) = r.VT0.initialiser e in e); VT0.rebuilder_rec_initialiser_list = @@ -1492,6 +1545,8 @@ let rebuilder_dz r = (function e -> let (_,e) = r.VT0.declaration_dots e in e); VT0.rebuilder_rec_field_dots = (function e -> let (_,e) = r.VT0.field_dots e in e); + VT0.rebuilder_rec_enum_decl_dots = + (function e -> let (_,e) = r.VT0.enum_decl_dots e in e); VT0.rebuilder_rec_case_line_dots = (function e -> let (_,e) = r.VT0.case_line_dots e in e); VT0.rebuilder_rec_define_param_dots = @@ -1524,6 +1579,7 @@ let rebuilder functions = (fun r k e -> ((),functions.VT0.rebuilder_dotsstmtfn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_dotsdeclfn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_dotsfieldfn (dz r) (xk k) e)) + (fun r k e -> ((),functions.VT0.rebuilder_dotsenumdeclfn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_dotscasefn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_dotsdefparfn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_identfn (dz r) (xk k) e)) @@ -1535,6 +1591,7 @@ let rebuilder functions = (fun r k e -> ((),functions.VT0.rebuilder_paramfn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_declfn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_fieldfn (dz r) (xk k) e)) + (fun r k e -> ((),functions.VT0.rebuilder_enumdeclfn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_stmtfn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_forinfofn (dz r) (xk k) e)) (fun r k e -> ((),functions.VT0.rebuilder_casefn (dz r) (xk k) e)) @@ -1548,8 +1605,9 @@ let flat_rebuilder arithOp_mcode logicalOp_mcode cv_mcode sign_mcode struct_mcode storage_mcode inc_mcode dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn - dotscasefn dotsdefparfn + dotsenumdeclfn dotscasefn dotsdefparfn identfn exprfn assignOpfn arithOpfn tyfn initfn paramfn declfn fieldfn + enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn = let dz = rebuilder_dz in let xk k e = let (_,e) = k e in e in @@ -1575,6 +1633,7 @@ let flat_rebuilder (fun r k e -> ((),dotsstmtfn (dz r) (xk k) e)) (fun r k e -> ((),dotsdeclfn (dz r) (xk k) e)) (fun r k e -> ((),dotsfieldfn (dz r) (xk k) e)) + (fun r k e -> ((),dotsenumdeclfn (dz r) (xk k) e)) (fun r k e -> ((),dotscasefn (dz r) (xk k) e)) (fun r k e -> ((),dotsdefparfn (dz r) (xk k) e)) (fun r k e -> ((),identfn (dz r) (xk k) e)) @@ -1586,6 +1645,7 @@ let flat_rebuilder (fun r k e -> ((),paramfn (dz r) (xk k) e)) (fun r k e -> ((),declfn (dz r) (xk k) e)) (fun r k e -> ((),fieldfn (dz r) (xk k) e)) + (fun r k e -> ((),enumdeclfn (dz r) (xk k) e)) (fun r k e -> ((),stmtfn (dz r) (xk k) e)) (fun r k e -> ((),forinfofn (dz r) (xk k) e)) (fun r k e -> ((),casefn (dz r) (xk k) e)) @@ -1627,6 +1687,7 @@ let combiner_rebuilder_functions = VT0.combiner_rebuilder_dotsstmtfn = (fun r k e -> k e); VT0.combiner_rebuilder_dotsdeclfn = (fun r k e -> k e); VT0.combiner_rebuilder_dotsfieldfn = (fun r k e -> k e); + VT0.combiner_rebuilder_dotsenumdeclfn = (fun r k e -> k e); VT0.combiner_rebuilder_dotscasefn = (fun r k e -> k e); VT0.combiner_rebuilder_dotsdefparfn = (fun r k e -> k e); VT0.combiner_rebuilder_identfn = (fun r k e -> k e); @@ -1638,6 +1699,7 @@ let combiner_rebuilder_functions = VT0.combiner_rebuilder_paramfn = (fun r k e -> k e); VT0.combiner_rebuilder_declfn = (fun r k e -> k e); VT0.combiner_rebuilder_fieldfn = (fun r k e -> k e); + VT0.combiner_rebuilder_enumdeclfn = (fun r k e -> k e); VT0.combiner_rebuilder_stmtfn = (fun r k e -> k e); VT0.combiner_rebuilder_forinfofn = (fun r k e -> k e); VT0.combiner_rebuilder_casefn = (fun r k e -> k e); @@ -1666,6 +1728,7 @@ let combiner_rebuilder bind option_default functions = functions.VT0.combiner_rebuilder_dotsstmtfn functions.VT0.combiner_rebuilder_dotsdeclfn functions.VT0.combiner_rebuilder_dotsfieldfn + functions.VT0.combiner_rebuilder_dotsenumdeclfn functions.VT0.combiner_rebuilder_dotscasefn functions.VT0.combiner_rebuilder_dotsdefparfn functions.VT0.combiner_rebuilder_identfn @@ -1677,6 +1740,7 @@ let combiner_rebuilder bind option_default functions = functions.VT0.combiner_rebuilder_paramfn functions.VT0.combiner_rebuilder_declfn functions.VT0.combiner_rebuilder_fieldfn + functions.VT0.combiner_rebuilder_enumdeclfn functions.VT0.combiner_rebuilder_stmtfn functions.VT0.combiner_rebuilder_forinfofn functions.VT0.combiner_rebuilder_casefn diff --git a/parsing_cocci/visitor_ast0.mli b/parsing_cocci/visitor_ast0.mli index 5784e9e667a0a343990251b0b4a2480e660bc8e1..e801c983ef606cbf0f567ef73655f250a715d1ca 100644 --- a/parsing_cocci/visitor_ast0.mli +++ b/parsing_cocci/visitor_ast0.mli @@ -33,6 +33,7 @@ val flat_combiner : ((Ast0_cocci.statement Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.declaration Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.field Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) -> + ((Ast0_cocci.enum_decl Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.case_line Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.define_param Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.ident,'a) Visitor_ast0_types.ccode) -> @@ -44,6 +45,7 @@ val flat_combiner : ((Ast0_cocci.parameterTypeDef,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.declaration,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.field,'a) Visitor_ast0_types.ccode) -> + ((Ast0_cocci.enum_decl,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.statement,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.forinfo,'a) Visitor_ast0_types.ccode) -> ((Ast0_cocci.case_line,'a) Visitor_ast0_types.ccode) -> @@ -76,6 +78,7 @@ val flat_rebuilder : (Ast0_cocci.statement Ast0_cocci.dots Visitor_ast0_types.rcode) -> (Ast0_cocci.declaration Ast0_cocci.dots Visitor_ast0_types.rcode) -> (Ast0_cocci.field Ast0_cocci.dots Visitor_ast0_types.rcode) -> + (Ast0_cocci.enum_decl Ast0_cocci.dots Visitor_ast0_types.rcode) -> (Ast0_cocci.case_line Ast0_cocci.dots Visitor_ast0_types.rcode) -> (Ast0_cocci.define_param Ast0_cocci.dots Visitor_ast0_types.rcode) -> (Ast0_cocci.ident Visitor_ast0_types.rcode) -> @@ -87,6 +90,7 @@ val flat_rebuilder : (Ast0_cocci.parameterTypeDef Visitor_ast0_types.rcode) -> (Ast0_cocci.declaration Visitor_ast0_types.rcode) -> (Ast0_cocci.field Visitor_ast0_types.rcode) -> + (Ast0_cocci.enum_decl Visitor_ast0_types.rcode) -> (Ast0_cocci.statement Visitor_ast0_types.rcode) -> (Ast0_cocci.forinfo Visitor_ast0_types.rcode) -> (Ast0_cocci.case_line Visitor_ast0_types.rcode) -> diff --git a/parsing_cocci/visitor_ast0_types.ml b/parsing_cocci/visitor_ast0_types.ml index c24a0c0a6ec8b02fbbad84c2cbf8c7cbb672ba0f..7a00c7026fde9e629e3ab4161e1255297168ba67 100644 --- a/parsing_cocci/visitor_ast0_types.ml +++ b/parsing_cocci/visitor_ast0_types.ml @@ -18,6 +18,7 @@ type 'n all_functions = typeC : (Ast0.typeC,'n) inout; declaration : (Ast0.declaration,'n) inout; field : (Ast0.field,'n) inout; + enum_decl : (Ast0.enum_decl,'n) inout; initialiser : (Ast0.initialiser,'n) inout; initialiser_list : (Ast0.initialiser_list,'n) inout; parameter : (Ast0.parameterTypeDef,'n) inout; @@ -32,6 +33,7 @@ type 'n all_functions = statement_dots : (Ast0.statement Ast0.dots,'n) inout; declaration_dots : (Ast0.declaration Ast0.dots,'n) inout; field_dots : (Ast0.field Ast0.dots,'n) inout; + enum_decl_dots : (Ast0.enum_decl Ast0.dots,'n) inout; case_line_dots : (Ast0.case_line Ast0.dots,'n) inout; define_param_dots : (Ast0.define_param Ast0.dots,'n) inout; anything : (Ast0.anything,'n) inout} @@ -50,6 +52,7 @@ type 'n combiner_rec_functions = combiner_rec_typeC : (Ast0.typeC,'n) combiner_inout; combiner_rec_declaration : (Ast0.declaration,'n) combiner_inout; combiner_rec_field : (Ast0.field,'n) combiner_inout; + combiner_rec_enumdecl : (Ast0.enum_decl,'n) combiner_inout; combiner_rec_initialiser : (Ast0.initialiser,'n) combiner_inout; combiner_rec_initialiser_list : (Ast0.initialiser_list,'n) combiner_inout; @@ -69,6 +72,8 @@ type 'n combiner_rec_functions = (Ast0.declaration Ast0.dots,'n) combiner_inout; combiner_rec_field_dots : (Ast0.field Ast0.dots,'n) combiner_inout; + combiner_rec_enum_decl_dots : + (Ast0.enum_decl Ast0.dots,'n) combiner_inout; combiner_rec_case_line_dots : (Ast0.case_line Ast0.dots,'n) combiner_inout; combiner_rec_define_param_dots : @@ -100,6 +105,7 @@ type 'n combiner_functions = combiner_dotsstmtfn : (Ast0.statement Ast0.dots,'n) ccode; combiner_dotsdeclfn : (Ast0.declaration Ast0.dots,'n) ccode; combiner_dotsfieldfn : (Ast0.field Ast0.dots,'n) ccode; + combiner_dotsenumdeclfn : (Ast0.enum_decl Ast0.dots,'n) ccode; combiner_dotscasefn : (Ast0.case_line Ast0.dots,'n) ccode; combiner_dotsdefparfn : (Ast0.define_param Ast0.dots,'n) ccode; combiner_identfn : (Ast0.ident,'n) ccode; @@ -111,6 +117,7 @@ type 'n combiner_functions = combiner_paramfn : (Ast0.parameterTypeDef,'n) ccode; combiner_declfn : (Ast0.declaration,'n) ccode; combiner_fieldfn : (Ast0.field,'n) ccode; + combiner_enumdeclfn : (Ast0.enum_decl,'n) ccode; combiner_stmtfn : (Ast0.statement,'n) ccode; combiner_forinfofn : (Ast0.forinfo,'n) ccode; combiner_casefn : (Ast0.case_line,'n) ccode; @@ -131,6 +138,7 @@ type rebuilder_rec_functions = rebuilder_rec_typeC : Ast0.typeC rebuilder_inout; rebuilder_rec_declaration : Ast0.declaration rebuilder_inout; rebuilder_rec_field : Ast0.field rebuilder_inout; + rebuilder_rec_enumdecl : Ast0.enum_decl rebuilder_inout; rebuilder_rec_initialiser : Ast0.initialiser rebuilder_inout; rebuilder_rec_initialiser_list : Ast0.initialiser_list rebuilder_inout; @@ -149,6 +157,8 @@ type rebuilder_rec_functions = Ast0.declaration Ast0.dots rebuilder_inout; rebuilder_rec_field_dots : Ast0.field Ast0.dots rebuilder_inout; + rebuilder_rec_enum_decl_dots : + Ast0.enum_decl Ast0.dots rebuilder_inout; rebuilder_rec_case_line_dots : Ast0.case_line Ast0.dots rebuilder_inout; rebuilder_rec_define_param_dots : @@ -180,6 +190,7 @@ type rebuilder_functions = rebuilder_dotsstmtfn : Ast0.statement Ast0.dots rcode; rebuilder_dotsdeclfn : Ast0.declaration Ast0.dots rcode; rebuilder_dotsfieldfn : Ast0.field Ast0.dots rcode; + rebuilder_dotsenumdeclfn : Ast0.enum_decl Ast0.dots rcode; rebuilder_dotscasefn : Ast0.case_line Ast0.dots rcode; rebuilder_dotsdefparfn : Ast0.define_param Ast0.dots rcode; rebuilder_identfn : Ast0.ident rcode; @@ -192,6 +203,7 @@ type rebuilder_functions = rebuilder_paramfn : Ast0.parameterTypeDef rcode; rebuilder_declfn : Ast0.declaration rcode; rebuilder_fieldfn : Ast0.field rcode; + rebuilder_enumdeclfn : Ast0.enum_decl rcode; rebuilder_stmtfn : Ast0.statement rcode; rebuilder_forinfofn : Ast0.forinfo rcode; rebuilder_casefn : Ast0.case_line rcode; @@ -227,6 +239,7 @@ type 'n combiner_rebuilder_functions = combiner_rebuilder_dotsstmtfn : (Ast0.statement Ast0.dots,'n) rccode; combiner_rebuilder_dotsdeclfn : (Ast0.declaration Ast0.dots,'n) rccode; combiner_rebuilder_dotsfieldfn : (Ast0.field Ast0.dots,'n) rccode; + combiner_rebuilder_dotsenumdeclfn : (Ast0.enum_decl Ast0.dots,'n) rccode; combiner_rebuilder_dotscasefn : (Ast0.case_line Ast0.dots,'n) rccode; combiner_rebuilder_dotsdefparfn : (Ast0.define_param Ast0.dots,'n) rccode; combiner_rebuilder_identfn : (Ast0.ident,'n) rccode; @@ -238,6 +251,7 @@ type 'n combiner_rebuilder_functions = combiner_rebuilder_paramfn : (Ast0.parameterTypeDef,'n) rccode; combiner_rebuilder_declfn : (Ast0.declaration,'n) rccode; combiner_rebuilder_fieldfn : (Ast0.field,'n) rccode; + combiner_rebuilder_enumdeclfn : (Ast0.enum_decl,'n) rccode; combiner_rebuilder_stmtfn : (Ast0.statement,'n) rccode; combiner_rebuilder_forinfofn : (Ast0.forinfo,'n) rccode; combiner_rebuilder_casefn : (Ast0.case_line,'n) rccode; diff --git a/parsing_cocci/visitor_ast0_types.mli b/parsing_cocci/visitor_ast0_types.mli index 78e3b8041ee84017800f58af33b73cb2b3aa846f..d06baaf79667158691d6ee3118ecc5156c6fa7df 100644 --- a/parsing_cocci/visitor_ast0_types.mli +++ b/parsing_cocci/visitor_ast0_types.mli @@ -8,6 +8,7 @@ type 'n all_functions = { typeC : (Ast0_cocci.typeC, 'n) inout; declaration : (Ast0_cocci.declaration, 'n) inout; field : (Ast0_cocci.field, 'n) inout; + enum_decl : (Ast0_cocci.enum_decl,'n) inout; initialiser : (Ast0_cocci.initialiser, 'n) inout; initialiser_list : (Ast0_cocci.initialiser_list, 'n) inout; parameter : (Ast0_cocci.parameterTypeDef, 'n) inout; @@ -22,6 +23,7 @@ type 'n all_functions = { statement_dots : (Ast0_cocci.statement Ast0_cocci.dots, 'n) inout; declaration_dots : (Ast0_cocci.declaration Ast0_cocci.dots, 'n) inout; field_dots : (Ast0_cocci.field Ast0_cocci.dots, 'n) inout; + enum_decl_dots : (Ast0_cocci.enum_decl Ast0_cocci.dots, 'n) inout; case_line_dots : (Ast0_cocci.case_line Ast0_cocci.dots, 'n) inout; define_param_dots : (Ast0_cocci.define_param Ast0_cocci.dots, 'n) inout; anything : (Ast0_cocci.anything, 'n) inout; @@ -36,6 +38,7 @@ type 'n combiner_rec_functions = { combiner_rec_typeC : (Ast0_cocci.typeC, 'n) combiner_inout; combiner_rec_declaration : (Ast0_cocci.declaration, 'n) combiner_inout; combiner_rec_field : (Ast0_cocci.field, 'n) combiner_inout; + combiner_rec_enumdecl : (Ast0_cocci.enum_decl,'n) combiner_inout; combiner_rec_initialiser : (Ast0_cocci.initialiser, 'n) combiner_inout; combiner_rec_initialiser_list : (Ast0_cocci.initialiser_list, 'n) combiner_inout; combiner_rec_parameter : (Ast0_cocci.parameterTypeDef, 'n) combiner_inout; @@ -52,6 +55,7 @@ type 'n combiner_rec_functions = { combiner_rec_declaration_dots : (Ast0_cocci.declaration Ast0_cocci.dots, 'n) combiner_inout; combiner_rec_field_dots : (Ast0_cocci.field Ast0_cocci.dots, 'n) combiner_inout; + combiner_rec_enum_decl_dots : (Ast0_cocci.enum_decl Ast0_cocci.dots, 'n) combiner_inout; combiner_rec_case_line_dots : (Ast0_cocci.case_line Ast0_cocci.dots, 'n) combiner_inout; combiner_rec_define_param_dots : (Ast0_cocci.define_param Ast0_cocci.dots, 'n) combiner_inout; @@ -81,6 +85,7 @@ type 'n combiner_functions = { combiner_dotsstmtfn : (Ast0_cocci.statement Ast0_cocci.dots, 'n) ccode; combiner_dotsdeclfn : (Ast0_cocci.declaration Ast0_cocci.dots, 'n) ccode; combiner_dotsfieldfn : (Ast0_cocci.field Ast0_cocci.dots, 'n) ccode; + combiner_dotsenumdeclfn : (Ast0_cocci.enum_decl Ast0_cocci.dots, 'n) ccode; combiner_dotscasefn : (Ast0_cocci.case_line Ast0_cocci.dots, 'n) ccode; combiner_dotsdefparfn : (Ast0_cocci.define_param Ast0_cocci.dots, 'n) ccode; combiner_identfn : (Ast0_cocci.ident, 'n) ccode; @@ -92,6 +97,7 @@ type 'n combiner_functions = { combiner_paramfn : (Ast0_cocci.parameterTypeDef, 'n) ccode; combiner_declfn : (Ast0_cocci.declaration, 'n) ccode; combiner_fieldfn : (Ast0_cocci.field, 'n) ccode; + combiner_enumdeclfn : (Ast0_cocci.enum_decl,'n) ccode; combiner_stmtfn : (Ast0_cocci.statement, 'n) ccode; combiner_forinfofn : (Ast0_cocci.forinfo, 'n) ccode; combiner_casefn : (Ast0_cocci.case_line, 'n) ccode; @@ -108,6 +114,7 @@ type rebuilder_rec_functions = { rebuilder_rec_typeC : Ast0_cocci.typeC rebuilder_inout; rebuilder_rec_declaration : Ast0_cocci.declaration rebuilder_inout; rebuilder_rec_field : Ast0_cocci.field rebuilder_inout; + rebuilder_rec_enumdecl : Ast0_cocci.enum_decl rebuilder_inout; rebuilder_rec_initialiser : Ast0_cocci.initialiser rebuilder_inout; rebuilder_rec_initialiser_list : Ast0_cocci.initialiser_list rebuilder_inout; rebuilder_rec_parameter : Ast0_cocci.parameterTypeDef rebuilder_inout; @@ -121,6 +128,7 @@ type rebuilder_rec_functions = { rebuilder_rec_statement_dots : Ast0_cocci.statement Ast0_cocci.dots rebuilder_inout; rebuilder_rec_declaration_dots : Ast0_cocci.declaration Ast0_cocci.dots rebuilder_inout; rebuilder_rec_field_dots : Ast0_cocci.field Ast0_cocci.dots rebuilder_inout; + rebuilder_rec_enum_decl_dots : Ast0_cocci.enum_decl Ast0_cocci.dots rebuilder_inout; rebuilder_rec_case_line_dots : Ast0_cocci.case_line Ast0_cocci.dots rebuilder_inout; rebuilder_rec_define_param_dots : Ast0_cocci.define_param Ast0_cocci.dots rebuilder_inout; @@ -150,6 +158,7 @@ type rebuilder_functions = { rebuilder_dotsstmtfn : Ast0_cocci.statement Ast0_cocci.dots rcode; rebuilder_dotsdeclfn : Ast0_cocci.declaration Ast0_cocci.dots rcode; rebuilder_dotsfieldfn : Ast0_cocci.field Ast0_cocci.dots rcode; + rebuilder_dotsenumdeclfn : Ast0_cocci.enum_decl Ast0_cocci.dots rcode; rebuilder_dotscasefn : Ast0_cocci.case_line Ast0_cocci.dots rcode; rebuilder_dotsdefparfn : Ast0_cocci.define_param Ast0_cocci.dots rcode; rebuilder_identfn : Ast0_cocci.ident rcode; @@ -161,6 +170,7 @@ type rebuilder_functions = { rebuilder_paramfn : Ast0_cocci.parameterTypeDef rcode; rebuilder_declfn : Ast0_cocci.declaration rcode; rebuilder_fieldfn : Ast0_cocci.field rcode; + rebuilder_enumdeclfn : Ast0_cocci.enum_decl rcode; rebuilder_stmtfn : Ast0_cocci.statement rcode; rebuilder_forinfofn : Ast0_cocci.forinfo rcode; rebuilder_casefn : Ast0_cocci.case_line rcode; @@ -192,6 +202,7 @@ type 'n combiner_rebuilder_functions = { combiner_rebuilder_dotsstmtfn : (Ast0_cocci.statement Ast0_cocci.dots, 'n) rccode; combiner_rebuilder_dotsdeclfn : (Ast0_cocci.declaration Ast0_cocci.dots, 'n) rccode; combiner_rebuilder_dotsfieldfn : (Ast0_cocci.field Ast0_cocci.dots, 'n) rccode; + combiner_rebuilder_dotsenumdeclfn : (Ast0_cocci.enum_decl Ast0_cocci.dots, 'n) rccode; combiner_rebuilder_dotscasefn : (Ast0_cocci.case_line Ast0_cocci.dots, 'n) rccode; combiner_rebuilder_dotsdefparfn : (Ast0_cocci.define_param Ast0_cocci.dots, 'n) rccode; combiner_rebuilder_identfn : (Ast0_cocci.ident, 'n) rccode; @@ -203,6 +214,7 @@ type 'n combiner_rebuilder_functions = { combiner_rebuilder_paramfn : (Ast0_cocci.parameterTypeDef, 'n) rccode; combiner_rebuilder_declfn : (Ast0_cocci.declaration, 'n) rccode; combiner_rebuilder_fieldfn : (Ast0_cocci.field, 'n) rccode; + combiner_rebuilder_enumdeclfn : (Ast0_cocci.enum_decl,'n) rccode; combiner_rebuilder_stmtfn : (Ast0_cocci.statement, 'n) rccode; combiner_rebuilder_forinfofn : (Ast0_cocci.forinfo, 'n) rccode; combiner_rebuilder_casefn : (Ast0_cocci.case_line, 'n) rccode; diff --git a/popl/popltoctl.ml b/popl/popltoctl.ml index 978d49d0f54a2c0814583b30cf185de5c83b5caf..933c3faffb97e56ed31be0b15171cd48deeb2750 100644 --- a/popl/popltoctl.ml +++ b/popl/popltoctl.ml @@ -37,7 +37,7 @@ let contains_modif = let recursor = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - mcode + mcode mcode do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing diff --git a/popl09/popltoctl.ml b/popl09/popltoctl.ml index 6b046309e85403d487558b576709135f6ac23bee..1b05a7626362bb4274c797fc27bdc23b80022788 100644 --- a/popl09/popltoctl.ml +++ b/popl09/popltoctl.ml @@ -46,8 +46,9 @@ let contains_modif = do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing - do_nothing do_nothing - do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in + do_nothing do_nothing do_nothing + do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing + do_nothing in recursor.V.combiner_rule_elem let ctl_exists keep_wit v x = diff --git a/tests/enum_assign.c b/tests/enum_assign.c new file mode 100644 index 0000000000000000000000000000000000000000..9c2d16df2babe8c05f862a37a4ba7d27563b654b --- /dev/null +++ b/tests/enum_assign.c @@ -0,0 +1,6 @@ +enum h { + a = 0, + c, + x, + b +}; diff --git a/tests/enum_assign.cocci b/tests/enum_assign.cocci new file mode 100644 index 0000000000000000000000000000000000000000..a1a59ef8f9976f3b895e0b2c31fe49cd7d4fbb24 --- /dev/null +++ b/tests/enum_assign.cocci @@ -0,0 +1,11 @@ +@@ +@@ + +enum h { + ..., +- a = 0, ++ q = 0, + ..., + b, ++ z +}; diff --git a/tests/enum_assign.res b/tests/enum_assign.res new file mode 100644 index 0000000000000000000000000000000000000000..3b204aa0c25136ee091259e241972b08f9d67ef2 --- /dev/null +++ b/tests/enum_assign.res @@ -0,0 +1,7 @@ +enum h { + q = 0, + c, + x, + b, + z +}; diff --git a/tests/rb.c b/tests/rb.c new file mode 100644 index 0000000000000000000000000000000000000000..fd5e5a93923803b5ca52036b69e178e34d85bb8c --- /dev/null +++ b/tests/rb.c @@ -0,0 +1,2 @@ +RB_DECLARE_CALLBACKS_MAX(static, augment_callbacks, struct drbd_interval, +rb, sector_t, end, NODE_END); diff --git a/tests/rb.cocci b/tests/rb.cocci new file mode 100644 index 0000000000000000000000000000000000000000..a9bd6854779b88dac36372effdbaf3a7bb7baff3 --- /dev/null +++ b/tests/rb.cocci @@ -0,0 +1,5 @@ +@@ +declarer name RB_DECLARE_CALLBACKS_MAX; +@@ + +- RB_DECLARE_CALLBACKS_MAX(..., NODE_END); \ No newline at end of file diff --git a/tests/rb.res b/tests/rb.res new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/tests/rb.res @@ -0,0 +1 @@ + diff --git a/tools/spgen/source/detect_patch.ml b/tools/spgen/source/detect_patch.ml index 6cf1c538184224fb11873531fd0822ffc1b1c449..0489afec43947b73696c0d7e6ac447fea23b60c9 100644 --- a/tools/spgen/source/detect_patch.ml +++ b/tools/spgen/source/detect_patch.ml @@ -101,11 +101,13 @@ let patch_combiner = let dotsparamfn = donothing in let dotsdeclfn = donothing in let dotsfieldfn = donothing in + let dotsenumdeclfn = donothing in let dotscasefn = donothing in let dotsdefparfn = donothing in let assignOpfn = donothing in let binaryOpfn = donothing in let initfn = donothing in + let enumdeclfn = donothing in let paramfn = donothing in let forinfofn = donothing in let string_fragmentfn = donothing in @@ -159,9 +161,9 @@ let patch_combiner = fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode struct_mcode storage_mcode inc_mcode dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn - dotscasefn dotsdefparfn + dotsenumdeclfn dotscasefn dotsdefparfn identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn - stmtfn forinfofn casefn string_fragmentfn topfn + enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn (* ------------------------------------------------------------------------- *) diff --git a/tools/spgen/source/meta_variable.ml b/tools/spgen/source/meta_variable.ml index 7adfacad3a58759b75899df21d5b264429dfdea2..a1804a0585d3122fd140171b7c79954828518076 100644 --- a/tools/spgen/source/meta_variable.ml +++ b/tools/spgen/source/meta_variable.ml @@ -390,11 +390,13 @@ let metavar_combiner rn = let dotsstmtfn = donothing in let dotsdeclfn = donothing in let dotsfieldfn = donothing in + let dotsenumdeclfn = donothing in let dotscasefn = donothing in let dotsdefparfn = donothing in let forinfofn = donothing in let casefn = donothing in let topfn = donothing in + let enumdeclfn = donothing in (* --- These are shortened formatting functions that return MVSets --- *) @@ -574,9 +576,9 @@ let metavar_combiner rn = fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode struct_mcode storage_mcode inc_mcode dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn - dotscasefn dotsdefparfn + dotsenumdeclfn dotscasefn dotsdefparfn identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn - stmtfn forinfofn casefn string_fragmentfn topfn + enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn (* ------------------------------------------------------------------------- *) diff --git a/tools/spgen/source/rule_body.ml b/tools/spgen/source/rule_body.ml index 6345c9dfca888e4e4d8a4a4387498b1b0db9e922..163dff9a6f2d3c50607927e7bff7221da072fbf7 100644 --- a/tools/spgen/source/rule_body.ml +++ b/tools/spgen/source/rule_body.ml @@ -219,12 +219,14 @@ let rec gen_combiner ~context_mode = let dotsparamfn = donothing in let dotsdeclfn = donothing in let dotsfieldfn = donothing in + let dotsenumdeclfn = donothing in let dotscasefn = donothing in let dotsdefparfn = donothing in let assignOpfn = donothing in let binaryOpfn = donothing in let tyfn = donothing in let initfn = donothing in + let enumdeclfn = donothing in let paramfn = donothing in let forinfofn = donothing in let casefn = donothing in @@ -349,9 +351,9 @@ let rec gen_combiner ~context_mode = fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode struct_mcode storage_mcode inc_mcode dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn - dotscasefn dotsdefparfn + dotsenumdeclfn dotscasefn dotsdefparfn identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn - stmtfn forinfofn casefn string_fragmentfn topfn + enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn (* ------------------------------------------------------------------------- *)