An enumerator in the SmPL AST now has the enum_decl type. Add corresponding functions for the combiner, combiner_rebuilder and rebuilder in Visitor_ast.
Signed-off-by: Jaskaran Singh <[email protected]>n --- parsing_cocci/visitor_ast.ml | 72 +++++++++++++++++++++++++++++++---- parsing_cocci/visitor_ast.mli | 8 ++++ 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 3d5de794..df6b5a90 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) -> @@ -498,6 +503,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 @@ -899,6 +923,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 @@ -916,6 +941,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 @@ -935,6 +961,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; @@ -947,6 +974,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 @@ -966,6 +994,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; @@ -977,6 +1006,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; @@ -992,10 +1022,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 @@ -1014,6 +1045,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 @@ -1274,7 +1307,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) -> @@ -1421,6 +1454,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 @@ -1851,6 +1905,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) @@ -1868,6 +1923,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) @@ -1887,6 +1943,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; @@ -1898,6 +1955,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 20ce32b0..0ed17774 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) -> -- 2.21.1 _______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci
