cocci: Add macrodecl attributes to C and SmPL ASTs
cover cocci: Add macrodecl attributes to C and SmPL ASTs
This patch series aims to add macrodecl attributes to C and SmPL ASTs, and match them in C source code. This is a continuation of the series "cocci: Improve C parsing of attributes"[1].
Two test cases are included:
- detect_macrodecl_attr: Test case to detect a macrodecl attribute.
- remove_macrodecl_attr: Test case to remove a macrodecl attribute as per the given SmPL.
[1]https://www.mail-archive.com/[email protected]/msg07133.html
Jaskaran Singh (30):
parsing_cocci: ast0_cocci: Add Macrodecl attributes
parsing_cocci: parser: Parse Macrodecl attributes
parsing_cocci: visitor_ast0: Visit Macrodecl attributes
parsing_cocci: unparse_ast0: Reflect Macrodecl attributes
parsing_cocci: index: Reflect Macrodecl attributes
parsing_cocci: iso_pattern: Reflect Macrodecl attributes
parsing_cocci: type_infer: Reflect Macrodecl attributes
parsing_cocci: arity: Reflect Macrodecl attributes
parsing_cocci: check_meta: Reflect Macrodecl attributes
parsing_cocci: compute_lines: Reflect Macrodecl attributes
parsing_cocci: context_neg: Reflect Macrodecl attributes
parsing_cocci: single_statement: Reflect Macrodecl attributes
parsing_cocci: ast_cocci: Reflect Macrodecl attributes
parsing_cocci: visitor_ast: Reflect Macrodecl attributes
parsing_cocci: pretty_print_cocci: Reflect Macrodecl attributes
parsing_cocci: disjdistr: Reflect Macrodecl attributes
parsing_cocci: adjust_pragmas: Reflect Macrodecl attributes
parsing_cocci: unify_ast: Reflect Macrodecl attributes
parsing_cocci: ast0toast: Reflect Macrodecl attributes
parsing_c: ast_c: Add Macrodecl attributes
parsing_c: parser_c: Reflect Macrodecl attributes
parsing_c: visitor_c: Reflect Macrodecl attributes
parsing_c: pretty_print_c: Reflect Macrodecl attributes
parsing_c: unparse_cocci: Reflect Macrodecl attributes
engine: check_exhaustive_pattern: Reflect Macrodecl attributes
engine: cocci_vs_c: Match Macrodecl attributes
ocaml: coccilib: Reflect Macrodecl attributes
tools: spgen: Reflect Macrodecl attributes
tests: Add test case to remove macrodecl attributes
tests: Add test case to detect a macrodecl attribute
engine/check_exhaustive_pattern.ml | 4 ++-- engine/cocci_vs_c.ml | 23 +++++++++++++---------- ocaml/coccilib.mli | 8 +++++--- parsing_c/ast_c.ml | 3 ++- parsing_c/ast_c.mli | 4 +++- parsing_c/parser_c.mly | 23 ++++++++++++++++------- parsing_c/pretty_print_c.ml | 7 ++++--- parsing_c/unparse_cocci.ml | 7 +++++-- parsing_c/visitor_c.ml | 6 ++++-- parsing_cocci/adjust_pragmas.ml | 12 ++++++------ parsing_cocci/arity.ml | 5 +++-- parsing_cocci/ast0_cocci.ml | 3 ++- parsing_cocci/ast0_cocci.mli | 3 ++- parsing_cocci/ast0toast.ml | 5 +++-- parsing_cocci/ast_cocci.ml | 3 ++- parsing_cocci/ast_cocci.mli | 3 ++- parsing_cocci/check_meta.ml | 3 ++- parsing_cocci/compute_lines.ml | 7 ++++--- parsing_cocci/context_neg.ml | 6 +++--- parsing_cocci/disjdistr.ml | 4 ++-- parsing_cocci/index.ml | 2 +- parsing_cocci/iso_pattern.ml | 9 ++++++--- parsing_cocci/parser_cocci_menhir.mly | 8 ++++---- parsing_cocci/pretty_print_cocci.ml | 7 +++++-- parsing_cocci/single_statement.ml | 6 +++--- parsing_cocci/type_infer.ml | 2 +- parsing_cocci/unify_ast.ml | 4 ++-- parsing_cocci/unparse_ast0.ml | 7 +++++-- parsing_cocci/visitor_ast.ml | 10 ++++++---- parsing_cocci/visitor_ast0.ml | 7 ++++--- tests/detect_macrodecl_attr.c | 5 +++++ tests/detect_macrodecl_attr.cocci | 12 ++++++++++++ tests/detect_macrodecl_attr.res | 5 +++++ tests/remove_macrodecl_attr.c | 3 +++ tests/remove_macrodecl_attr.cocci | 8 ++++++++ tests/remove_macrodecl_attr.res | 3 +++ tools/spgen/source/meta_variable.ml | 2 +- tools/spgen/source/position_generator.ml | 4 ++-- 38 files changed, 161 insertions(+), 82 deletions(-)
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 1/30 parsing_cocci: ast0_cocci: Add Macrodecl attributes
Add Macrodecl attributes to AST0 of SmPL. These attributes are for the MacroDecl type of SmPL AST0.
--- parsing_cocci/ast0_cocci.ml | 3 ++- parsing_cocci/ast0_cocci.mli | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
parsing_cocci/ast0_cocci.ml +2 -1
@@ -255,7 +255,8 @@ and base_declaration = | TyDecl of typeC * string mcode (* ; *) | MacroDecl of Ast.storage mcode option * ident (* name *) * string mcode (* ( *) * - expression dots * string mcode (* ) *) * string mcode (* ; *) + expression dots * string mcode (* ) *) * + attr list * string mcode (* ; *) | MacroDeclInit of Ast.storage mcode option * ident (* name *) * string mcode (* ( *) * expression dots * string mcode (* ) *) * string mcode (*=*) *
parsing_cocci/ast0_cocci.mli +2 -1
@@ -243,7 +243,8 @@ and base_declaration = | TyDecl of typeC * string mcode (* ; *) | MacroDecl of Ast_cocci.storage mcode option * ident (* name *) * string mcode (* ( *) * - expression dots * string mcode (* ) *) * string mcode (* ; *) + expression dots * string mcode (* ) *) * + attr list * string mcode (* ; *) | MacroDeclInit of Ast_cocci.storage mcode option * ident (* name *) * string mcode (* ( *) * expression dots * string mcode (* ) *) * string mcode (*=*) *
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 2/30 parsing_cocci: parser: Parse Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL ASTs. Parse these attributes in the SmPL parser and place them in the SmPL AST. The added production only supports attributes before the semicolon.
--- parsing_cocci/parser_cocci_menhir.mly | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
parsing_cocci/parser_cocci_menhir.mly +4 -4
@@ -1710,9 +1710,9 @@ decl_var: [Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e, P.clt2mcode ";" pv))] } | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option c=TCPar - p=TPtVirg + ar=attr_list p=TPtVirg { [Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e, - P.clt2mcode ")" c,P.clt2mcode ";" p))] } + P.clt2mcode ")" c,ar,P.clt2mcode ";" p))] } | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option c=TCPar q=TEq i=initialize p=TPtVirg
@@ -1758,9 +1758,9 @@ one_decl_var: Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e, P.clt2mcode ";" pv)) } | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option c=TCPar - p=TPtVirg + ar=attr_list p=TPtVirg { Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e, - P.clt2mcode ")" c,P.clt2mcode ";" p)) } + P.clt2mcode ")" c,ar,P.clt2mcode ";" p)) } | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option c=TCPar q=TEq i=initialize p=TPtVirg
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 3/30 parsing_cocci: visitor_ast0: Visit Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Visit these attributes the AST0 visitor of SmPL.
--- parsing_cocci/visitor_ast0.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
parsing_cocci/visitor_ast0.ml +4 -3
@@ -637,15 +637,16 @@ let visitor mode bind option_default let (sem_n,sem) = string_mcode sem in (multibind [fi_n;name_n;lp1_n;params_n;va_n;rp1_n;sem_n], Ast0.FunProto(fi,name,lp1,params,va,rp1,sem)) - | Ast0.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) -> let (stg_n,stg) = get_option storage_mcode stg in let (name_n,name) = ident name in let (lp_n,lp) = string_mcode lp in let (args_n,args) = expression_dots args in let (rp_n,rp) = string_mcode rp in + let (attr_n,attr) = map_split_bind string_mcode attr in let (sem_n,sem) = string_mcode sem in - (multibind [stg_n;name_n;lp_n;args_n;rp_n;sem_n], - Ast0.MacroDecl(stg,name,lp,args,rp,sem)) + (multibind [stg_n;name_n;lp_n;args_n;rp_n;attr_n;sem_n], + Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem)) | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> let (stg_n,stg) = get_option storage_mcode stg in let (name_n,name) = ident name in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 4/30 parsing_cocci: unparse_ast0: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in unparse_ast0.ml.
--- parsing_cocci/unparse_ast0.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
parsing_cocci/unparse_ast0.ml +5 -2
@@ -422,11 +422,14 @@ and declaration d = parameter_list params; varargs va; close_box(); mcode print_string rp1; mcode print_string sem - | Ast0.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) -> print_option (mcode U.storage) stg; ident name; mcode print_string_box lp; let _ = dots (function _ -> ()) expression args in - close_box(); mcode print_string rp; mcode print_string sem + close_box(); mcode print_string rp; + (if not (attr = []) then print_string " "); + print_between (fun _ -> print_string " ") (mcode print_string) attr; + mcode print_string sem | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> print_option (mcode U.storage) stg; ident name; mcode print_string_box lp;
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 5/30 parsing_cocci: index: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in index.ml.
--- parsing_cocci/index.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/index.ml +1 -1
@@ -117,7 +117,7 @@ let declaration d = | Ast0.Init(stg,ty,id,attr,eq,exp,sem) -> [54] | Ast0.UnInit(stg,ty,id,attr,sem) -> [55] | Ast0.FunProto(fi,name,lp1,params,va,rp1,sem) -> [132] - | Ast0.MacroDecl(stg,name,lp,args,rp,sem) -> [137] + | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) -> [137] | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> [157] | Ast0.TyDecl(ty,sem) -> [116] | Ast0.Typedef(stg,ty,id,sem) -> [143]
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 6/30 parsing_cocci: iso_pattern: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in iso_pattern.ml.
--- parsing_cocci/iso_pattern.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
parsing_cocci/iso_pattern.ml +6 -3
@@ -965,9 +965,12 @@ let match_maker checks_needed context_required whencode_allowed = params1 params; match_option varargs_equal va1a va1b ] - | (Ast0.MacroDecl(stga,namea,lp1,argsa,rp1,sc1), - Ast0.MacroDecl(stgb,nameb,lp,argsb,rp,sc)) -> - if bool_match_option mcode_equal stga stgb + | (Ast0.MacroDecl(stga,namea,lp1,argsa,rp1,attra,sc1), + Ast0.MacroDecl(stgb,nameb,lp,argsb,rp,attrb,sc)) -> + if bool_match_option mcode_equal stga stgb && + (List.length attra = List.length attrb && + List.fold_left2 (fun p a b -> p && mcode_equal a b) true + attra attrb) (* no metavars *) then conjunct_many_bindings [match_ident namea nameb;
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 7/30 parsing_cocci: type_infer: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in type_infer.ml.
--- parsing_cocci/type_infer.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/type_infer.ml +1 -1
@@ -380,7 +380,7 @@ let rec propagate_types env = | Ast0.UnInit(_,ty,id,_,_) -> List.map (function i -> (i,ty)) (strip id) | Ast0.FunProto(fi,nm,lp,params,va,rp,sem) -> [] - | Ast0.MacroDecl(_,_,_,_,_,_) -> [] + | Ast0.MacroDecl(_,_,_,_,_,_,_) -> [] | Ast0.MacroDeclInit(_,_,_,_,_,_,exp,_) -> let _ = (propagate_types env).VT0.combiner_rec_initialiser exp in []
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 8/30 parsing_cocci: arity: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in arity.ml.
--- parsing_cocci/arity.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/arity.ml +3 -2
@@ -595,7 +595,7 @@ and declaration tgt decl = let rp1 = mcode rp1 in let sem = mcode sem in make_decl decl tgt arity (Ast0.FunProto(fi,name,lp1,params,va,rp1,sem)) - | Ast0.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) -> let arity = all_same true tgt (mcode2line lp) ((match stg with None -> [] | Some x -> [mcode2arity x]) @
@@ -605,8 +605,9 @@ and declaration tgt decl = let lp = mcode lp in let args = dots (expression arity) args in let rp = mcode rp in + let attr = List.map mcode attr in let sem = mcode sem in - make_decl decl tgt arity (Ast0.MacroDecl(stg,name,lp,args,rp,sem)) + make_decl decl tgt arity (Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem)) | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> let arity = all_same true tgt (mcode2line lp)
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 9/30 parsing_cocci: check_meta: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in check_meta.ml.
--- parsing_cocci/check_meta.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
parsing_cocci/check_meta.ml +2 -1
@@ -281,7 +281,8 @@ and declaration context old_metas table minus d = ident FN old_metas table minus name; List.iter (fninfo old_metas table minus) fi; parameter_list old_metas table minus params - | Ast0.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) -> + (* no meta attribute yet *) ident GLOBAL old_metas table minus name; dots (expression ID old_metas table minus) args | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 10/30 parsing_cocci: compute_lines: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in compute_lines.ml.
--- parsing_cocci/compute_lines.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
parsing_cocci/compute_lines.ml +4 -3
@@ -715,19 +715,20 @@ and declaration d = | Ast0.FType(ty)::_ -> mkres d res ty right | Ast0.FInline(inline)::_ -> mkres d res (promote_mcode inline) right | Ast0.FAttr(attr)::_ -> mkres d res (promote_mcode attr) right) - | Ast0.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) -> let name = ident name in let lp = normal_mcode lp in let args = dots is_exp_dots (Some(promote_mcode lp)) expression args in let rp = normal_mcode rp in + let attr = List.map normal_mcode attr in let sem = normal_mcode sem in (match stg with None -> - mkres d (Ast0.MacroDecl(None,name,lp,args,rp,sem)) + mkres d (Ast0.MacroDecl(None,name,lp,args,rp,attr,sem)) name (promote_mcode sem) | Some x -> let stg = Some (normal_mcode x) in - mkres d (Ast0.MacroDecl(stg,name,lp,args,rp,sem)) + mkres d (Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem)) (promote_mcode x) (promote_mcode sem)) | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> let name = ident name in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 11/30 parsing_cocci: context_neg: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in context_neg.ml.
--- parsing_cocci/context_neg.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
parsing_cocci/context_neg.ml +3 -3
@@ -752,9 +752,9 @@ let equal_declaration d1 d2 = List.for_all2 equal_fninfo fninfo1 fninfo2 && equal_mcode lp1 lp2 && equal_varargs va1 va2 && equal_mcode rp1 rp2 && equal_mcode sem1 sem2 - | (Ast0.MacroDecl(stg1,nm1,lp1,_,rp1,sem1), - Ast0.MacroDecl(stg2,nm2,lp2,_,rp2,sem2)) -> - equal_option stg1 stg2 && + | (Ast0.MacroDecl(stg1,nm1,lp1,_,rp1,attr1,sem1), + Ast0.MacroDecl(stg2,nm2,lp2,_,rp2,attr2,sem2)) -> + equal_option stg1 stg2 && List.for_all2 equal_mcode attr1 attr2 && equal_mcode lp1 lp2 && equal_mcode rp1 rp2 && equal_mcode sem1 sem2 | (Ast0.MacroDeclInit(stg1,nm1,lp1,_,rp1,eq1,_,sem1), Ast0.MacroDeclInit(stg2,nm2,lp2,_,rp2,eq2,_,sem2)) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 12/30 parsing_cocci: single_statement: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in single_statement.ml.
--- parsing_cocci/single_statement.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
parsing_cocci/single_statement.ml +3 -3
@@ -200,8 +200,8 @@ and left_declaration d = | Ast0.FunProto(fninfo,name,lp1,params,va,rp1,sem) -> (* should not be nested in anything anyway *) false - | Ast0.MacroDecl(Some stg,name,lp,args,rp,sem) -> modif_before_mcode stg - | Ast0.MacroDecl(None,name,lp,args,rp,sem) -> left_ident name + | Ast0.MacroDecl(Some stg,name,lp,args,rp,attr,sem) -> modif_before_mcode stg + | Ast0.MacroDecl(None,name,lp,args,rp,attr,sem) -> left_ident name | Ast0.MacroDeclInit(Some stg,name,lp,args,rp,eq,ini,sem) -> modif_before_mcode stg | Ast0.MacroDeclInit(None,name,lp,args,rp,eq,ini,sem) -> left_ident name
@@ -219,7 +219,7 @@ and right_declaration d = | Ast0.Init(_,ty,id,eq,ini,attr,sem) -> modif_after_mcode sem | Ast0.UnInit(_,ty,id,attr,sem) -> modif_after_mcode sem | Ast0.FunProto(fninfo,name,lp1,params,va,rp1,sem) -> modif_after_mcode sem - | Ast0.MacroDecl(_,name,lp,args,rp,sem) -> modif_after_mcode sem + | Ast0.MacroDecl(_,name,lp,args,rp,attr,sem) -> modif_after_mcode sem | Ast0.MacroDeclInit(_,name,lp,args,rp,eq,ini,sem) -> modif_after_mcode sem | Ast0.TyDecl(ty,sem) -> modif_after_mcode sem | Ast0.Typedef(stg,ty,id,sem) -> modif_after_mcode sem
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 13/30 parsing_cocci: ast_cocci: Reflect Macrodecl attributes
In reply to Jaskaran SinghAdd macrodecl attributes to the SmPL AST. This is a list of attributes in the Macrodecl type of the SmPL AST.
--- parsing_cocci/ast_cocci.ml | 3 ++- parsing_cocci/ast_cocci.mli | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
parsing_cocci/ast_cocci.ml +2 -1
@@ -399,7 +399,8 @@ and base_declaration = | TyDecl of fullType * string mcode (* ; *) | MacroDecl of storage mcode option * ident (* name *) * string mcode (* ( *) * - expression dots * string mcode (* ) *) * string mcode (* ; *) + expression dots * string mcode (* ) *) * + attr list * string mcode (* ; *) | MacroDeclInit of storage mcode option * ident (* name *) * string mcode (* ( *) * expression dots * string mcode (* ) *) * string mcode (*=*) *
parsing_cocci/ast_cocci.mli +2 -1
@@ -381,7 +381,8 @@ and base_declaration = | TyDecl of fullType * string mcode (* ; *) | MacroDecl of storage mcode option * ident (* name *) * string mcode (* ( *) * - expression dots * string mcode (* ) *) * string mcode (* ; *) + expression dots * string mcode (* ) *) * + attr list * string mcode (* ; *) | MacroDeclInit of storage mcode option * ident (* name *) * string mcode (* ( *) * expression dots * string mcode (* ) *) * string mcode (*=*) *
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 14/30 parsing_cocci: visitor_ast: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Visit these attributes in the SmPL AST visitor.
--- parsing_cocci/visitor_ast.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
parsing_cocci/visitor_ast.ml +6 -4
@@ -470,14 +470,15 @@ let combiner bind option_default let lrp1 = string_mcode rp1 in multibind (lfi @ [lname; llp1; lparams] @ lcomma @ lellipsis @ [lrp1]) - | Ast.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast.MacroDecl(stg,name,lp,args,rp,attr,sem) -> let lstg = get_option storage_mcode stg in let lname = ident name in let llp = string_mcode lp in let largs = expression_dots args in let lrp = string_mcode rp in + let lattr = multibind (List.map string_mcode attr) in let lsem = string_mcode sem in - multibind [lstg; lname; llp; largs; lrp; lsem] + multibind [lstg; lname; llp; largs; lrp; lattr; lsem] | Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> let lstg = get_option storage_mcode stg in let lname = ident name in
@@ -1417,14 +1418,15 @@ let rebuilder let lrp = string_mcode rp in let lsem = string_mcode sem in Ast.FunProto(lfi,lname,llp,lparams,lva,lrp,lsem) - | Ast.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast.MacroDecl(stg,name,lp,args,rp,attr,sem) -> let lstg = get_option storage_mcode stg in let lname = ident name in let llp = string_mcode lp in let largs = expression_dots args in let lrp = string_mcode rp in + let lattr = List.map string_mcode attr in let lsem = string_mcode sem in - Ast.MacroDecl(lstg, lname, llp, largs, lrp, lsem) + Ast.MacroDecl(lstg, lname, llp, largs, lrp, lattr, lsem) | Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> let lstg = get_option storage_mcode stg in let lname = ident name in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 15/30 parsing_cocci: pretty_print_cocci: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in pretty_print_cocci.ml.
--- parsing_cocci/pretty_print_cocci.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
parsing_cocci/pretty_print_cocci.ml +5 -2
@@ -565,10 +565,13 @@ and declaration d = parameter_list params; varargs va; close_box(); mcode print_string rp1; mcode print_string sem - | Ast.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast.MacroDecl(stg,name,lp,args,rp,attr,sem) -> print_option (mcode storage) stg; ident name; mcode print_string_box lp; dots (function _ -> ()) expression args; - close_box(); mcode print_string rp; mcode print_string sem + close_box(); mcode print_string rp; + (if not (attr = []) then print_string " "); + print_between print_space (mcode print_string) attr; + mcode print_string sem | Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> print_option (mcode storage) stg; ident name; mcode print_string_box lp; dots (function _ -> ()) expression args;
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 16/30 parsing_cocci: disjdistr: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in disjdistr.ml.
--- parsing_cocci/disjdistr.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
parsing_cocci/disjdistr.ml +2 -2
@@ -342,10 +342,10 @@ and disjdecl d = disjmult2 (disjmult disjfninfo fninfo) (disjident name) (fun fninfo name -> Ast.rewrap d (Ast.FunProto(fninfo,name,lp1,params,va,rp1,sem))) - | Ast.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast.MacroDecl(stg,name,lp,args,rp,attr,sem) -> disjmult2 (disjident name) (disjdots disjexp args) (fun name args -> - Ast.rewrap d (Ast.MacroDecl(stg,name,lp,args,rp,sem))) + Ast.rewrap d (Ast.MacroDecl(stg,name,lp,args,rp,attr,sem))) | Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> disjmult3 (disjident name) (disjdots disjexp args) (disjini ini) (fun name args ini ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 17/30 parsing_cocci: adjust_pragmas: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in adjust_pragmas.ml.
--- parsing_cocci/adjust_pragmas.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
parsing_cocci/adjust_pragmas.ml +6 -6
@@ -54,9 +54,9 @@ let rec right_decl d = | Ast0.FunProto(fninfo,id,lp1,params,va,rp1,sem) -> call_right right_mcode sem d (function ty -> Ast0.FunProto(fninfo,id,lp1,params,va,rp1,sem)) - | Ast0.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) -> call_right right_mcode sem d - (function sem -> Ast0.MacroDecl(stg,name,lp,args,rp,sem)) + (function sem -> Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem)) | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> call_right right_mcode sem d (function sem -> Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem))
@@ -279,12 +279,12 @@ let rec left_decl decl = call_right left_mcode attr decl (function attr -> Ast0.FunProto((Ast0.FAttr attr)::x,name,lp1,params,va,rp1,sem))) - | Ast0.MacroDecl(Some stg,name,lp,args,rp,sem) -> + | Ast0.MacroDecl(Some stg,name,lp,args,rp,attr,sem) -> call_right left_mcode stg decl - (function stg -> Ast0.MacroDecl(Some stg,name,lp,args,rp,sem)) - | Ast0.MacroDecl(None,name,lp,args,rp,sem) -> + (function stg -> Ast0.MacroDecl(Some stg,name,lp,args,rp,attr,sem)) + | Ast0.MacroDecl(None,name,lp,args,rp,attr,sem) -> call_right left_ident name decl - (function name -> Ast0.MacroDecl(None,name,lp,args,rp,sem)) + (function name -> Ast0.MacroDecl(None,name,lp,args,rp,attr,sem)) | Ast0.MacroDeclInit(Some stg,name,lp,args,rp,eq,ini,sem) -> call_right left_mcode stg decl (function stg ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 18/30 parsing_cocci: unify_ast: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in unify_ast.ml.
--- parsing_cocci/unify_ast.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
parsing_cocci/unify_ast.ml +2 -2
@@ -409,8 +409,8 @@ and unify_declaration d1 d2 = unify_ident nm1 nm2 && unify_dots unify_parameterTypeDef pdots params1 params2 else false - | (Ast.MacroDecl(s1,n1,lp1,args1,rp1,sem1), - Ast.MacroDecl(s2,n2,lp2,args2,rp2,sem2)) -> + | (Ast.MacroDecl(s1,n1,lp1,args1,rp1,attr1,sem1), + Ast.MacroDecl(s2,n2,lp2,args2,rp2,attr2,sem2)) -> if bool_unify_option unify_mcode s1 s2 then unify_ident n1 n2 &&
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 19/30 parsing_cocci: ast0toast: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in ast0toast.ml.
--- parsing_cocci/ast0toast.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/ast0toast.ml +3 -2
@@ -657,15 +657,16 @@ and declaration d = let rp = mcode rp in let sem = mcode sem in Ast.FunProto(fi,name,lp,params,va,rp,sem) - | Ast0.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) -> (* this would seem to need allminus... *) let stg = get_option mcode stg in let name = ident name in let lp = mcode lp in let args = dots expression args in let rp = mcode rp in + let attr = List.map mcode attr in let sem = mcode sem in - Ast.MacroDecl(stg,name,lp,args,rp,sem) + Ast.MacroDecl(stg,name,lp,args,rp,attr,sem) | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> (* this would seem to need allminus... *) let stg = get_option mcode stg in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 20/30 parsing_c: ast_c: Add Macrodecl attributes
In reply to Jaskaran SinghAdd cast attributes to the C AST. This is a list of attributes in the Macrodecl type of the C AST.
--- parsing_c/ast_c.ml | 3 ++- parsing_c/ast_c.mli | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
parsing_c/ast_c.ml +2 -1
@@ -561,7 +561,8 @@ and declaration = (* cppext: *) (* bool is true if there is a ; at the end *) | MacroDecl of - (storagebis * string * argument wrap2 list * bool) wrap (* fakestart *) + (storagebis * string * argument wrap2 list * attribute list * bool) + wrap (* fakestart *) | MacroDeclInit of (storagebis * string * argument wrap2 list * initialiser) wrap (* fakestart *)
parsing_c/ast_c.mli +3 -1
@@ -201,7 +201,9 @@ and exec_code_bis = ExecEval of expression | ExecToken and exec_code = exec_code_bis wrap and declaration = DeclList of onedecl wrap2 list wrap - | MacroDecl of (storagebis * string * argument wrap2 list * bool) wrap + | MacroDecl of + (storagebis * string * argument wrap2 list * attribute list * bool) + wrap | MacroDeclInit of (storagebis * string * argument wrap2 list * initialiser) wrap and onedecl = {
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 21/30 parsing_c: parser_c: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the C AST. Parse these attributes in the C parser and place them in the C AST.
--- parsing_c/parser_c.mly | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
parsing_c/parser_c.mly +16 -7
@@ -1600,10 +1600,11 @@ decl2: match $1 with Some (sto,stoii) -> MacroDecl - ((sto, fst $2, $4, true), (snd $2::$3::$5::$6::fakeInfo()::stoii)) + ((sto, fst $2, $4, [], true), + (snd $2::$3::$5::$6::fakeInfo()::stoii)) | None -> MacroDecl - ((NoSto, fst $2, $4, true), [snd $2;$3;$5;$6;fakeInfo()]) } + ((NoSto, fst $2, $4, [], true), [snd $2;$3;$5;$6;fakeInfo()]) } | storage_const_opt TMacroDecl TOPar argument_list TCPar end_attributes TPtVirg
@@ -1611,10 +1612,12 @@ decl2: match $1 with Some (sto,stoii) -> MacroDecl - ((sto, fst $2, $4, true), (snd $2::$3::$5::$7::fakeInfo()::stoii)) + ((sto, fst $2, $4, $6, true), + (snd $2::$3::$5::$7::fakeInfo()::stoii)) | None -> MacroDecl - ((NoSto, fst $2, $4, true), [snd $2;$3;$5;$7;fakeInfo()]) } + ((NoSto, fst $2, $4, $6, true), + [snd $2;$3;$5;$7;fakeInfo()]) } | storage_const_opt TMacroDecl TOPar argument_list TCPar teq initialize TPtVirg
@@ -2265,7 +2268,9 @@ cpp_other: ($5::iistart::snd sto))) else Declaration - (MacroDecl((NoSto, fst $1, $3, true), [snd $1;$2;$4;$5;fakeInfo()])) + (MacroDecl + ((NoSto, fst $1, $3, Ast_c.noattr, true), + [snd $1;$2;$4;$5;fakeInfo()])) (* old: MacroTop (fst $1, $3, [snd $1;$2;$4;$5]) *) }
@@ -2295,7 +2300,9 @@ cpp_other: ($6::iistart::snd sto))) else Declaration - (MacroDecl((NoSto, fst $1, $3, true), [snd $1;$2;$4;$6;fakeInfo()])) + (MacroDecl + ((NoSto, fst $1, $3, $5, true), + [snd $1;$2;$4;$6;fakeInfo()])) (* old: MacroTop (fst $1, $3, [snd $1;$2;$4;$5]) *) }
@@ -2321,7 +2328,9 @@ cpp_other: /*(* TCParEOL to fix the end-of-stream bug of ocamlyacc *)*/ | identifier TOPar argument_list TCParEOL { Declaration - (MacroDecl ((NoSto, fst $1, $3, false), [snd $1;$2;$4;fakeInfo()])) } + (MacroDecl + ((NoSto, fst $1, $3, Ast_c.noattr, false), + [snd $1;$2;$4;fakeInfo()])) } /*(* ex: EXPORT_NO_SYMBOLS; *)*/ | identifier TPtVirg { EmptyDef [snd $1;$2] }
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 22/30 parsing_c: visitor_c: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the C AST. Visit these attributes in the C AST visitor.
--- parsing_c/visitor_c.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
parsing_c/visitor_c.ml +4 -2
@@ -548,8 +548,9 @@ and vk_decl = fun bigf d -> iif ii; vk_onedecl bigf x ); - | MacroDecl ((_stob, s, args, ptvg),ii) -> + | MacroDecl ((_stob, s, args, attrs, ptvg),ii) -> iif ii; + attrs +> List.iter (vk_attribute bigf); vk_argument_list bigf args | MacroDeclInit ((_stob, s, args, ini),ii) -> iif ii;
@@ -1464,10 +1465,11 @@ and vk_decl_s = fun bigf d -> | DeclList (xs, ii) -> DeclList (List.map (fun (x,ii) -> (vk_onedecl_s bigf x, iif ii)) xs, iif ii) - | MacroDecl ((stob, s, args, ptvg),ii) -> + | MacroDecl ((stob, s, args, attrs, ptvg),ii) -> MacroDecl ((stob, s, args +> List.map (fun (e,ii) -> vk_argument_s bigf e, iif ii), + attrs +> List.map (vk_attribute_s bigf), ptvg), iif ii) | MacroDeclInit ((stob, s, args, ini),ii) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 23/30 parsing_c: pretty_print_c: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the C AST. Print these changes in pretty_print_c.ml.
--- parsing_c/pretty_print_c.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
parsing_c/pretty_print_c.ml +4 -3
@@ -1043,7 +1043,8 @@ and pp_string_format (e,ii) = pr_elem iivirg; - | MacroDecl ((sto, s, es, true), iis::lp::rp::iiend::ifakestart::iisto) -> + | MacroDecl + ((sto, s, es, attrs, true), iis::lp::rp::iiend::ifakestart::iisto) -> pr_elem ifakestart; iisto +> List.iter pr_elem; (* static and const *) pr_elem iis;
@@ -1053,11 +1054,11 @@ and pp_string_format (e,ii) = opt +> List.iter pr_elem; pp_argument e; ); - pr_elem rp; pr_elem iiend; - | MacroDecl ((sto, s, es, false), iis::lp::rp::ifakestart::iisto) -> + | MacroDecl + ((sto, s, es, attrs, false), iis::lp::rp::ifakestart::iisto) -> pr_elem ifakestart; iisto +> List.iter pr_elem; (* static and const *) pr_elem iis;
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 24/30 parsing_c: unparse_cocci: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in unparse_cocci.ml.
--- parsing_c/unparse_cocci.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
parsing_c/unparse_cocci.ml +5 -2
@@ -936,12 +936,15 @@ and declaration d = end; close_box(); mcode print_string rp1; mcode print_string sem - | Ast.MacroDecl(stg,name,lp,args,rp,sem) -> + | Ast.MacroDecl(stg,name,lp,args,rp,attr,sem) -> print_option (mcode storage) stg; print_option (function _ -> pr_space()) stg; ident name; mcode print_string_box lp; dots (function _ -> ()) arg_expression args; - close_box(); mcode print_string rp; mcode print_string sem + close_box(); mcode print_string rp; + (if not (attr = []) then pr_space()); + print_between pr_space (mcode print_string) attr; + mcode print_string sem | Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) -> print_option (mcode storage) stg; print_option (function _ -> pr_space()) stg;
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 25/30 engine: check_exhaustive_pattern: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in check_exhaustive_pattern.ml.
--- engine/check_exhaustive_pattern.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
engine/check_exhaustive_pattern.ml +2 -2
@@ -63,7 +63,7 @@ let dumb_astcocci_decl = function | A.Init (stg, typa, sa, attr, _, expa, _) -> () | A.FunProto _ -> () | A.TyDecl (typa, _) -> () - | A.MacroDecl(stg, fn, _, eas, _, _) -> () + | A.MacroDecl(stg, fn, _, eas, _, _, _) -> () | A.MacroDeclInit(stg, fn, _, eas, _, _, _, _) -> () | A.MetaDecl _ -> () | A.AsDecl _ -> ()
@@ -76,7 +76,7 @@ let dumb_astcocci_initialiser = function (* seems same as the above *) A.Init(stg,ty,id,attr,eq,ini,sem) -> () | A.UnInit(stg,ty,id,attr,sem) -> () | A.FunProto _ -> () - | A.MacroDecl(_, fn, _, eas, _, _) -> () + | A.MacroDecl(_, fn, _, eas, _, _, _) -> () | A.MacroDeclInit(_, fn, _, eas, _, _, _, _) -> () | A.TyDecl(ty,sem) -> () | A.Typedef(d,ty1,ty2,pv) -> ()
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 26/30 engine: cocci_vs_c: Match Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the C and SmPL ASTs. Match these attributes in cocci_vs_c.ml.
--- engine/cocci_vs_c.ml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
engine/cocci_vs_c.ml +13 -10
@@ -2340,8 +2340,8 @@ and (declaration: (A.mcodekind * bool * A.declaration,B.declaration) matcher) = fail end - | A.MacroDecl (stoa,sa,lpa,eas,rpa,enda), - B.MacroDecl ((stob,sb,ebs,true),ii) -> + | A.MacroDecl (stoa,sa,lpa,eas,rpa,attrsa,enda), + B.MacroDecl ((stob,sb,ebs,attrsb,true),ii) -> let (iisb, lpb, rpb, iiendb, iifakestart, iistob) = (match ii with | iisb::lpb::rpb::iiendb::iifakestart::iisto ->
@@ -2352,6 +2352,7 @@ and (declaration: (A.mcodekind * bool * A.declaration,B.declaration) matcher) = stoa ((stob, false), iistob) >>= (fun stoa ((stob, _), iistob) -> X.tokenf_mck mckstart iifakestart >>= (fun mckstart iifakestart -> ident DontKnow sa (sb, iisb) >>= (fun sa (sb, iisb) -> + attribute_list allminus attrsa attrsb >>= (fun attrsa attrsb -> tokenf lpa lpb >>= (fun lpa lpb -> tokenf rpa rpb >>= (fun rpa rpb -> tokenf enda iiendb >>= (fun enda iiendb ->
@@ -2360,13 +2361,13 @@ and (declaration: (A.mcodekind * bool * A.declaration,B.declaration) matcher) = return ( (mckstart, allminus, - (A.MacroDecl (stoa,sa,lpa,eas,rpa,enda)) +> A.rewrap decla), - (B.MacroDecl ((stob,sb,ebs,true), + (A.MacroDecl (stoa,sa,lpa,eas,rpa,attrsa,enda)) +> A.rewrap decla), + (B.MacroDecl ((stob,sb,ebs,attrsb,true), [iisb;lpb;rpb;iiendb;iifakestart] @ iistob)) - )))))))) + ))))))))) - | A.MacroDecl (None,sa,lpa,eas,rpa,enda), - B.MacroDecl ((B.NoSto,sb,ebs,false),ii) -> + | A.MacroDecl (None,sa,lpa,eas,rpa,attrsa,enda), + B.MacroDecl ((B.NoSto,sb,ebs,attrsb,false),ii) -> (* This is for macrodecls with no semicolons, which come from a parsing rule that deals with function prototypes with no return type. That parsing rule would have a conflict if there
@@ -2383,6 +2384,7 @@ and (declaration: (A.mcodekind * bool * A.declaration,B.declaration) matcher) = X.tokenf_mck mckstart iifakestart >>= (fun mckstart iifakestart -> ident DontKnow sa (sb, iisb) >>= (fun sa (sb, iisb) -> + attribute_list allminus attrsa attrsb >>= (fun attrsa attrsb -> tokenf lpa lpb >>= (fun lpa lpb -> tokenf rpa rpb >>= (fun rpa rpb -> arguments (seqstyle eas) (A.unwrap eas) ebs >>=
@@ -2391,10 +2393,11 @@ and (declaration: (A.mcodekind * bool * A.declaration,B.declaration) matcher) = return ( (mckstart, allminus, - (A.MacroDecl (None,sa,lpa,eas,rpa,enda)) +> A.rewrap decla), - (B.MacroDecl ((B.NoSto,sb,ebs,false), + (A.MacroDecl + (None,sa,lpa,eas,rpa,attrsa,enda)) +> A.rewrap decla), + (B.MacroDecl ((B.NoSto,sb,ebs,attrsb,false), [iisb;lpb;rpb;iifakestart])) - )))))) + ))))))) | _ -> fail) | A.MacroDeclInit (stoa,sa,lpa,eas,rpa,weqa,inia,enda),
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 27/30 ocaml: coccilib: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the C and SmPL ASTs. Reflect these changes in coccilib.mli.
--- ocaml/coccilib.mli | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
ocaml/coccilib.mli +5 -3
@@ -288,7 +288,9 @@ module Ast_c : and declaration = Ast_c.declaration = DeclList of onedecl wrap2 list wrap - | MacroDecl of (storagebis * string * argument wrap2 list * bool) wrap + | MacroDecl of + (storagebis * string * argument wrap2 list * attribute list * bool) + wrap | MacroDeclInit of (storagebis * string * argument wrap2 list * initialiser) wrap and onedecl =
@@ -2765,7 +2767,7 @@ module Ast_cocci : (string mcode * string mcode) option * string mcode * string mcode | TyDecl of fullType * string mcode | MacroDecl of storage mcode option * ident * string mcode * - expression dots * string mcode * string mcode + expression dots * string mcode * attr list * string mcode | MacroDeclInit of storage mcode option * ident * string mcode * expression dots * string mcode * string mcode * initialiser * string mcode
@@ -3400,7 +3402,7 @@ module Ast0_cocci : (string mcode * string mcode) option * string mcode * string mcode | TyDecl of typeC * string mcode | MacroDecl of Ast_cocci.storage mcode option * ident * string mcode * - expression dots * string mcode * string mcode + expression dots * string mcode * attr list * string mcode | MacroDeclInit of Ast_cocci.storage mcode option * ident * string mcode * expression dots * string mcode * string mcode * initialiser * string mcode
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 28/30 tools: spgen: Reflect Macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL AST. Reflect these changes in spgen.
--- tools/spgen/source/meta_variable.ml | 2 +- tools/spgen/source/position_generator.ml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/spgen/source/meta_variable.ml +1 -1
@@ -538,7 +538,7 @@ let metavar_combiner rn = meta_mc_format ~mc ~typ:"declaration " ~constr | Ast0.AsDecl(dc1, dc2) -> let dec = c.VT0.combiner_rec_declaration in as_format dc1 dc2 dec dec - | Ast0.MacroDecl(_, id, _, expdots, _, _) -> + | Ast0.MacroDecl(_, id, _, expdots, _, _, _) -> let expids = c.VT0.combiner_rec_expression_dots expdots in MVSet.union (ids ~rn ~typ:"declarer" ~id) expids | Ast0.MacroDeclInit(_, id, _, expdots, _, _, ini, _) ->
tools/spgen/source/position_generator.ml +2 -2
@@ -419,8 +419,8 @@ let rec declaration_pos decl snp | Ast0.Typedef (tm, tc, tc2, sem) -> let constructor ~mc = Ast0.Typedef (mc, tc, tc2, sem) in mcode_wrap ~mc:tm ~constructor snp - | Ast0.MacroDecl (st,id,lp,ed,rp,sem) -> - let constructor ~id = Ast0.MacroDecl (st, id, lp, ed, rp, sem) in + | Ast0.MacroDecl (st,id,lp,ed,rp,attr,sem) -> + let constructor ~id = Ast0.MacroDecl (st, id, lp, ed, rp, attr, sem) in id_wrap ~id ~constructor snp | Ast0.MacroDeclInit (st,id,lp,ed,rp,eq,init,sem) -> let constructor ~id = Ast0.MacroDeclInit (st,id,lp,ed,rp,eq,init,sem) in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 29/30 tests: Add test case to remove macrodecl attributes
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL and C ASTs. Add a test case to remove a macrodecl attribute.
--- tests/remove_macrodecl_attr.c | 3 +++ tests/remove_macrodecl_attr.cocci | 8 ++++++++ tests/remove_macrodecl_attr.res | 3 +++ 3 files changed, 14 insertions(+) create mode 100644 tests/remove_macrodecl_attr.c create mode 100644 tests/remove_macrodecl_attr.cocci create mode 100644 tests/remove_macrodecl_attr.res
tests/remove_macrodecl_attr.c new file +3 -0
@@ -0,0 +1,3 @@ +#define __macro_attr MACROANNOTATION + +DECLARER(a, b) __macro_attr;
tests/remove_macrodecl_attr.cocci new file +8 -0
@@ -0,0 +1,8 @@ +@r0@ +declarer name DECLARER; +attribute name __macro_attr; +@@ + +DECLARER(...) +- __macro_attr +;
tests/remove_macrodecl_attr.res new file +3 -0
@@ -0,0 +1,3 @@ +#define __macro_attr MACROANNOTATION + +DECLARER(a, b);
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 30/30 tests: Add test case to detect a macrodecl attribute
In reply to Jaskaran SinghMacrodecl attributes are added to the SmPL and C ASTs. Add a test case to detect a macrodecl attribute.
--- tests/detect_macrodecl_attr.c | 5 +++++ tests/detect_macrodecl_attr.cocci | 12 ++++++++++++ tests/detect_macrodecl_attr.res | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 tests/detect_macrodecl_attr.c create mode 100644 tests/detect_macrodecl_attr.cocci create mode 100644 tests/detect_macrodecl_attr.res
tests/detect_macrodecl_attr.c new file +5 -0
@@ -0,0 +1,5 @@ +#define __macro_attr MACROANNOTATION + +DECLARER(a, b) __macro_attr; + +DECLARER (a, b);
tests/detect_macrodecl_attr.cocci new file +12 -0
@@ -0,0 +1,12 @@ +@r0@ +declarer name DECLARER; +attribute name __macro_attr; +@@ + +DECLARER( + ..., +- a ++ c + , + ... + ) __macro_attr;
tests/detect_macrodecl_attr.res new file +5 -0
@@ -0,0 +1,5 @@ +#define __macro_attr MACROANNOTATION + +DECLARER(c, b) __macro_attr; + +DECLARER(a, b);
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees