cocci: Add parameter attributes to SmPL
v3 cover cocci: Add parameter attributes to SmPL
This patch series aims to add parameter attributes to SmPL, and is a continuation of the series "cocci: Improve C parsing of attributes"[1]. In [1], parameter attributes were added to the C AST of Coccinelle, but not to SmPL.
Two test cases are included:
- detect_param_attr: Test case to detect a parameter attribute.
- remove_param_attr: Test case to remove a parameter attribute as per the given SmPL.
[1]https://www.mail-archive.com/[email protected]/msg07133.html
Changes in v3:
--------------
parsing_cocci: check_meta: Reflect Parameter attributes
- Add comment about the absence of a meta attribute.
parsing_cocci: compute_lines: Reflect Parameter attributes
- Pass the correct last element to mkres.
parsing_cocci: iso_pattern: Reflect Parameter attributes
- Place opening paranthesis to the right of the if.
parsing_cocci: unparse_ast0: Reflect Parameter attributes
- Fix wacky indentation.
parsing_cocci: visitor_ast: Visit Parameter attributes
- Fix wacky indentation.
Changes in v2:
--------------
parsing_cocci: function_prototypes: Reflect Parameter attributes
- Remove unnecessary function name change.
Jaskaran Singh (23):
parsing_cocci: ast0_cocci: Add parameter attributes
parsing_cocci: parser: Parse Parameter attributes
parsing_cocci: visitor_ast0: Visit Parameter attributes
parsing_cocci: arity: Reflect Parameter attributes
parsing_cocci: check_meta: Reflect Parameter attributes
parsing_cocci: compute_lines: Reflect Parameter attributes
parsing_cocci: context_neg: Reflect Parameter attributes
parsing_cocci: function_prototypes: Reflect Parameter attributes
parsing_cocci: index: Reflect Parameter attributes
parsing_cocci: iso_pattern: Reflect Parameter attributes
parsing_cocci: type_infer: Reflect Parameter attributes
parsing_cocci: unparse_ast0: Reflect Parameter attributes
parsing_c: unparse_cocci: Reflect Parameter attributes
parsing_cocci: ast_cocci: Add Parameter attributes
parsing_cocci: visitor_ast: Visit Parameter attributes
parsing_cocci: ast0toast: Reflect Parameter attributes
parsing_cocci: disjdistr: Reflect Parameter attributes
parsing_cocci: pretty_print_cocci: Reflect Parameter attributes
parsing_cocci: unify_ast: Reflect Parameter attributes
engine: cocci_vs_c: Match Parameter attributes
ocaml: coccilib: Reflect Parameter attributes
tests: Add test case for removing parameter attributes
tests: Add test case to detect parameter attributes
engine/cocci_vs_c.ml | 18 +++++++++--------- ocaml/coccilib.mli | 8 ++++---- parsing_c/unparse_cocci.ml | 16 ++++++++++++---- parsing_cocci/arity.ml | 17 ++++++++++------- parsing_cocci/ast0_cocci.ml | 4 ++-- parsing_cocci/ast0_cocci.mli | 4 ++-- parsing_cocci/ast0toast.ml | 7 ++++--- parsing_cocci/ast_cocci.ml | 4 ++-- parsing_cocci/ast_cocci.mli | 4 ++-- parsing_cocci/check_meta.ml | 3 ++- parsing_cocci/compute_lines.ml | 30 ++++++++++++++++++++++++------ parsing_cocci/context_neg.ml | 10 ++++++---- parsing_cocci/disjdistr.ml | 6 +++--- parsing_cocci/function_prototypes.ml | 8 ++++---- parsing_cocci/index.ml | 4 ++-- parsing_cocci/iso_pattern.ml | 20 ++++++++++++++++---- parsing_cocci/parser_cocci_menhir.mly | 7 ++++--- parsing_cocci/pretty_print_cocci.ml | 15 ++++++++++++--- parsing_cocci/type_infer.ml | 2 +- parsing_cocci/unify_ast.ml | 14 ++++++++++---- parsing_cocci/unparse_ast0.ml | 15 ++++++++++++--- parsing_cocci/visitor_ast.ml | 22 +++++++++++++++++----- parsing_cocci/visitor_ast0.ml | 16 ++++++++++------ tests/detect_param_attr.c | 3 +++ tests/detect_param_attr.cocci | 13 +++++++++++++ tests/detect_param_attr.res | 3 +++ tests/remove_param_attrs.c | 11 +++++++++++ tests/remove_param_attrs.cocci | 13 +++++++++++++ tests/remove_param_attrs.res | 11 +++++++++++ 29 files changed, 224 insertions(+), 84 deletions(-)
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 1/23 parsing_cocci: ast0_cocci: Add parameter attributes
Add parameter attributes to AST0 of SmPL. This is a list of attributes in the VoidParam and Param types of AST0.
--- parsing_cocci/ast0_cocci.ml | 4 ++-- parsing_cocci/ast0_cocci.mli | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
parsing_cocci/ast0_cocci.ml +2 -2
@@ -334,8 +334,8 @@ and initialiser_list = initialiser dots (* Parameter *) and base_parameterTypeDef = - VoidParam of typeC - | Param of typeC * ident option + VoidParam of typeC * attr list + | Param of typeC * ident option * attr list | MetaParam of Ast.meta_name mcode * constraints * pure | MetaParamList of Ast.meta_name mcode * listlen * constraints * pure | AsParam of parameterTypeDef * expression (* expr, always metavar *)
parsing_cocci/ast0_cocci.mli +2 -2
@@ -320,8 +320,8 @@ and initialiser_list = initialiser dots (* Parameter *) and base_parameterTypeDef = - VoidParam of typeC - | Param of typeC * ident option + VoidParam of typeC * attr list + | Param of typeC * ident option * attr list | MetaParam of Ast_cocci.meta_name mcode * constraints * pure | MetaParamList of Ast_cocci.meta_name mcode * listlen * constraints * pure | AsParam of parameterTypeDef * expression (* expr, always metavar *)
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 2/23 parsing_cocci: parser: Parse Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Parse these attributes correctly in the SmPL parser. The added production only supports attributes after the type or the type and identifier.
--- parsing_cocci/parser_cocci_menhir.mly | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
parsing_cocci/parser_cocci_menhir.mly +4 -3
@@ -1541,9 +1541,10 @@ storage: | s=Tregister { P.clt2mcode Ast.Register s } | s=Textern { P.clt2mcode Ast.Extern s } -decl: t=ctype d=direct_declarator(disj_ident) - { let (i,fn) = d in Ast0.wrap(Ast0.Param(fn t, Some i)) } - | t=ctype { (*verify in FunDecl*) Ast0.wrap(Ast0.Param(t, None)) } +decl: t=ctype d=direct_declarator(disj_ident) ar=attr_list + { let (i,fn) = d in Ast0.wrap(Ast0.Param(fn t, Some i, ar)) } + | t=ctype ar=attr_list + { (*verify in FunDecl*) Ast0.wrap(Ast0.Param(t, None, ar)) } | TMetaParam { let (nm,cstr,pure,clt) = $1 in Ast0.wrap(Ast0.MetaParam(P.clt2mcode nm clt,cstr,pure)) }
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 3/23 parsing_cocci: visitor_ast0: Visit Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to AST0 of SmPL. Visit these attributes in the AST0 visitor.
--- parsing_cocci/visitor_ast0.ml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
parsing_cocci/visitor_ast0.ml +10 -6
@@ -826,14 +826,18 @@ let visitor mode bind option_default let k p = rewrap p (match Ast0.unwrap p with - Ast0.VoidParam(ty) -> - let (n,ty) = typeC ty in (n,Ast0.VoidParam(ty)) - | Ast0.Param(ty,Some id) -> + Ast0.VoidParam(ty, attrs) -> + let (ty_n,ty) = typeC ty in + let (attr_n,attr) = map_split_bind string_mcode attrs in + (bind ty_n attr_n,Ast0.VoidParam(ty, attrs)) + | Ast0.Param(ty,Some id,attrs) -> let ((ty_id_n,ty),id) = named_type ty id in - (ty_id_n, Ast0.Param(ty,Some id)) - | Ast0.Param(ty,None) -> + let (attr_n,attr) = map_split_bind string_mcode attrs in + (bind ty_id_n attr_n, Ast0.Param(ty,Some id,attr)) + | Ast0.Param(ty,None,attrs) -> let (ty_n,ty) = typeC ty in - (ty_n, Ast0.Param(ty,None)) + let (attr_n,attr) = map_split_bind string_mcode attrs in + (bind ty_n attr_n, Ast0.Param(ty,None,attr)) | Ast0.MetaParam(name,constraints,pure) -> let (n,name) = meta_mcode name in (n,Ast0.MetaParam(name,constraints,pure))
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 4/23 parsing_cocci: arity: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in arity.ml.
--- parsing_cocci/arity.ml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
parsing_cocci/arity.ml +10 -7
@@ -812,26 +812,29 @@ and make_param = and parameterTypeDef tgt param = let param_same = all_same true tgt in match Ast0.unwrap param with - Ast0.VoidParam(ty) -> Ast0.rewrap param (Ast0.VoidParam(typeC tgt ty)) - | Ast0.Param(ty,Some id) -> + Ast0.VoidParam(ty,attr) -> + Ast0.rewrap param (Ast0.VoidParam(typeC tgt ty,List.map mcode attr)) + | Ast0.Param(ty,Some id,attr) -> let ty = top_typeC tgt true ty in let id = ident true tgt id in + let attr = List.map mcode attr in Ast0.rewrap param (match (Ast0.unwrap ty,Ast0.unwrap id) with (Ast0.OptType(ty),Ast0.OptIdent(id)) -> - Ast0.OptParam(Ast0.rewrap param (Ast0.Param(ty,Some id))) + Ast0.OptParam(Ast0.rewrap param (Ast0.Param(ty,Some id,attr))) | (Ast0.OptType(ty),_) -> fail param "arity mismatch in param declaration" | (_,Ast0.OptIdent(id)) -> fail param "arity mismatch in param declaration" - | _ -> Ast0.Param(ty,Some id)) - | Ast0.Param(ty,None) -> + | _ -> Ast0.Param(ty,Some id,attr)) + | Ast0.Param(ty,None,attr) -> let ty = top_typeC tgt true ty in + let attr = List.map mcode attr in Ast0.rewrap param (match Ast0.unwrap ty with Ast0.OptType(ty) -> - Ast0.OptParam(Ast0.rewrap param (Ast0.Param(ty,None))) - | _ -> Ast0.Param(ty,None)) + Ast0.OptParam(Ast0.rewrap param (Ast0.Param(ty,None,attr))) + | _ -> Ast0.Param(ty,None,attr)) | Ast0.MetaParam(name,cstr,pure) -> let arity = param_same (mcode2line name) [mcode2arity name] in let name = mcode 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 v3 5/23 parsing_cocci: check_meta: Reflect Parameter attributes
In reply to Jaskaran SinghParameter 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
@@ -374,7 +374,8 @@ and initialiser_list old_metas table minus = and parameterTypeDef old_metas table minus param = match Ast0.unwrap param with - Ast0.Param(ty,id) -> + Ast0.Param(ty,id,attr) -> + (* No meta attribute yet *) get_opt (ident ID old_metas table minus) id; typeC old_metas table minus ty | Ast0.MetaParam(name,_,_) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 6/23 parsing_cocci: compute_lines: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in compute_lines.ml.
--- parsing_cocci/compute_lines.ml | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
parsing_cocci/compute_lines.ml +24 -6
@@ -914,13 +914,31 @@ and is_param_dots p = and parameterTypeDef p = match Ast0.unwrap p with - Ast0.VoidParam(ty) -> - let ty = typeC ty in mkres p (Ast0.VoidParam(ty)) ty ty - | Ast0.Param(ty,Some id) -> + Ast0.VoidParam(ty,attr) -> + let attr = List.map normal_mcode attr in + let ty = typeC ty in + (match attr with + [] -> mkres p (Ast0.VoidParam(ty,attr)) ty ty + | l -> + let lattr = List.hd (List.rev l) in + mkres p (Ast0.VoidParam(ty,attr)) ty (promote_mcode lattr)) + | Ast0.Param(ty,Some id,attr) -> let id = ident id in - let ty = typeC ty in mkres p (Ast0.Param(ty,Some id)) ty id - | Ast0.Param(ty,None) -> - let ty = typeC ty in mkres p (Ast0.Param(ty,None)) ty ty + let ty = typeC ty in + let attr = List.map normal_mcode attr in + (match attr with + [] -> mkres p (Ast0.Param(ty,Some id,attr)) ty id + | l -> + let lattr = List.hd (List.rev l) in + mkres p (Ast0.Param(ty,Some id,attr)) ty (promote_mcode lattr)) + | Ast0.Param(ty,None,attr) -> + let attr = List.map normal_mcode attr in + let ty = typeC ty in + (match attr with + [] -> mkres p (Ast0.Param(ty,None,attr)) ty ty + | l -> + let lattr = List.hd (List.rev l) in + mkres p (Ast0.Param(ty,None,attr)) ty (promote_mcode lattr)) | Ast0.MetaParam(name,a,b) -> let name = normal_mcode name in let ln = promote_mcode 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 v3 7/23 parsing_cocci: context_neg: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in context_neg.ml.
--- parsing_cocci/context_neg.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
parsing_cocci/context_neg.ml +6 -4
@@ -466,9 +466,11 @@ let classify is_minus all_marked table code = let param r k e = compute_result Ast0.param e (match Ast0.unwrap e with - Ast0.Param(ty,Some id) -> + Ast0.Param(ty,Some id,attr) -> (* needed for the same reason as in the Init and UnInit cases *) - bind (r.VT0.combiner_rec_typeC ty) (r.VT0.combiner_rec_ident id) + bind (r.VT0.combiner_rec_typeC ty) + (bind (r.VT0.combiner_rec_ident id) + (List.fold_right bind (List.map mcode attr) option_default)) | _ -> k e) in let typeC r k e =
@@ -839,8 +841,8 @@ let equal_initialiser i1 i2 = let equal_parameterTypeDef p1 p2 = match (Ast0.unwrap p1,Ast0.unwrap p2) with - (Ast0.VoidParam(_),Ast0.VoidParam(_)) -> true - | (Ast0.Param(_,_),Ast0.Param(_,_)) -> true + (Ast0.VoidParam(_,_),Ast0.VoidParam(_,_)) -> true + | (Ast0.Param(_,_,_),Ast0.Param(_,_,_)) -> true | (Ast0.MetaParam(name1,_,_),Ast0.MetaParam(name2,_,_)) | (Ast0.MetaParamList(name1,_,_,_),Ast0.MetaParamList(name2,_,_,_)) -> equal_mcode name1 name2
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 8/23 parsing_cocci: function_prototypes: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in function_prototypes.ml.
--- parsing_cocci/function_prototypes.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
parsing_cocci/function_prototypes.ml +4 -4
@@ -261,10 +261,10 @@ let rec attach_right strings ty = let rec drop_param_name p = Ast0.rewrap p (match Ast0.unwrap p with - Ast0.Param(p,Some id) -> + Ast0.Param(p,Some id,attr) -> let strings = collect_ident_strings id in let p = attach_right strings p in - Ast0.Param(p,None) + Ast0.Param(p,None,attr) | Ast0.OptParam(p) -> Ast0.OptParam(drop_param_name p) | p -> p)
@@ -297,7 +297,7 @@ let new_iname name index = let rec rename_param old_name all param index = match Ast0.unwrap param with - Ast0.Param(ty,Some id) when all -> + Ast0.Param(ty,Some id,attr) when all -> (match Ast0.unwrap id with Ast0.MetaId (((_,name),arity,info,mcodekind,pos,adj),constraints,seed,pure) ->
@@ -308,7 +308,7 @@ let rec rename_param old_name all param index = ((nm,arity,info,mcodekind,pos,adj),constraints,seed, Ast0.Pure)) in ([Ast.MetaIdDecl(Ast.NONE,nm)], - Ast0.rewrap param (Ast0.Param(ty,Some new_id))) + Ast0.rewrap param (Ast0.Param(ty,Some new_id,attr))) | _ -> ([],param)) | Ast0.Pdots(d) -> let nm = (old_name,new_iname "__P" index) in
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 9/23 parsing_cocci: index: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in index.ml.
--- parsing_cocci/index.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
parsing_cocci/index.ml +2 -2
@@ -157,8 +157,8 @@ let initialiser i = let parameterTypeDef p = match Ast0.unwrap p with - Ast0.VoidParam(ty) -> [59] - | Ast0.Param(ty,id) -> [60] + Ast0.VoidParam(ty,attr) -> [59] + | Ast0.Param(ty,id,attr) -> [60] | Ast0.MetaParam(name,_,_) -> [61] | Ast0.MetaParamList(name,_,_,_) -> [62] | Ast0.PComma(cm) -> [63]
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 10/23 parsing_cocci: iso_pattern: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in iso_pattern.ml.
--- parsing_cocci/iso_pattern.ml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
parsing_cocci/iso_pattern.ml +16 -4
@@ -1165,10 +1165,22 @@ let match_maker checks_needed context_required whencode_allowed = if not(checks_needed) || not(context_required) || is_context p then match (up,Ast0.unwrap p) with - (Ast0.VoidParam(tya),Ast0.VoidParam(tyb)) -> match_typeC tya tyb - | (Ast0.Param(tya,ida),Ast0.Param(tyb,idb)) -> - conjunct_bindings (match_typeC tya tyb) - (match_option match_ident ida idb) + (Ast0.VoidParam(tya,attra),Ast0.VoidParam(tyb,attrb)) -> + if (List.length attra = List.length attrb && + List.fold_left2 (fun p a b -> p && mcode_equal a b) true + attra attrb) + then + match_typeC tya tyb + else return false + | (Ast0.Param(tya,ida,attra),Ast0.Param(tyb,idb,attrb)) -> + if (List.length attra = List.length attrb && + List.fold_left2 (fun p a b -> p && mcode_equal a b) true + attra attrb) + then + conjunct_bindings (match_typeC tya tyb) + (match_option match_ident ida idb) + else + return false | (Ast0.PComma(c1),Ast0.PComma(c)) -> check_mcode c1 c | (Ast0.Pdots(d1),Ast0.Pdots(d)) -> check_mcode d1 d | (Ast0.OptParam(parama),Ast0.OptParam(paramb)) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 11/23 parsing_cocci: type_infer: Reflect Parameter attributes
In reply to Jaskaran SinghParameter 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
@@ -420,7 +420,7 @@ let rec propagate_types env = Ast0.FunDecl(_,fninfo,name,lp,params,va,rp,lbrace,body,rbrace,_) -> let rec get_binding p = match Ast0.unwrap p with - Ast0.Param(ty,Some id) -> + Ast0.Param(ty,Some id,attr) -> List.map (function i -> (i,ty)) (strip id) | Ast0.OptParam(param) -> get_binding param | Ast0.AsParam(param,e) -> get_binding param
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 12/23 parsing_cocci: unparse_ast0: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in unparse_ast0.ml.
--- parsing_cocci/unparse_ast0.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
parsing_cocci/unparse_ast0.ml +12 -3
@@ -546,9 +546,18 @@ and parameterTypeDef p = print_context p (function _ -> match Ast0.unwrap p with - Ast0.VoidParam(ty) -> typeC ty - | Ast0.Param(ty,Some id) -> print_named_type ty id - | Ast0.Param(ty,None) -> typeC ty + Ast0.VoidParam(ty,attr) -> + typeC ty; + (if (attr = []) then print_string " "); + print_between (fun _ -> print_string " ") (mcode print_string) attr; + | Ast0.Param(ty,Some id,attr) -> + print_named_type ty id; + (if (attr = []) then print_string " "); + print_between (fun _ -> print_string " ") (mcode print_string) attr; + | Ast0.Param(ty,None,attr) -> + typeC ty; + (if (attr = []) then print_string " "); + print_between (fun _ -> print_string " ") (mcode print_string) attr; | Ast0.MetaParam(name,_,_) -> mcode print_meta name | Ast0.MetaParamList(name,_,_,_) -> mcode print_meta name | Ast0.PComma(cm) -> mcode print_string cm; print_space()
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 13/23 parsing_c: unparse_cocci: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Print these attributes correctly in unparse_cocci.ml.
--- parsing_c/unparse_cocci.ml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
parsing_c/unparse_cocci.ml +12 -4
@@ -1089,10 +1089,18 @@ and designator = function and parameterTypeDef p = match Ast.unwrap p with - Ast.VoidParam(ty) -> fullType ty - | Ast.Param(ty,Some id) -> print_named_type ty (fun _ -> ident id) - | Ast.Param(ty,None) -> fullType ty - + Ast.VoidParam(ty,attr) -> + fullType ty; + (if not (attr = []) then pr_space()); + print_between pr_space (mcode print_string) attr; + | Ast.Param(ty,Some id,attr) -> + print_named_type ty (fun _ -> ident id); + (if not (attr = []) then pr_space()); + print_between pr_space (mcode print_string) attr; + | Ast.Param(ty,None,attr) -> + fullType ty; + (if not (attr = []) then pr_space()); + print_between pr_space (mcode print_string) attr; | Ast.MetaParam(name,_,_,_) -> handle_metavar name (function
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 14/23 parsing_cocci: ast_cocci: Add Parameter attributes
In reply to Jaskaran SinghAdd parameter attributes to the SmPL AST. This is a list of attributes in the VoidParam and Param types of the SmPL AST.
--- parsing_cocci/ast_cocci.ml | 4 ++-- parsing_cocci/ast_cocci.mli | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
parsing_cocci/ast_cocci.ml +2 -2
@@ -487,8 +487,8 @@ and initialiser = base_initialiser wrap (* Parameter *) and base_parameterTypeDef = - VoidParam of fullType - | Param of fullType * ident option + VoidParam of fullType * attr list + | Param of fullType * ident option * attr list | MetaParam of meta_name mcode * constraints * keep_binding * inherited | MetaParamList of meta_name mcode * listlen * constraints * keep_binding *
parsing_cocci/ast_cocci.mli +2 -2
@@ -468,8 +468,8 @@ and initialiser = base_initialiser wrap (* Parameter *) and base_parameterTypeDef = - VoidParam of fullType - | Param of fullType * ident option + VoidParam of fullType * attr list + | Param of fullType * ident option * attr list | MetaParam of meta_name mcode * constraints * keep_binding * inherited | MetaParamList of meta_name mcode * listlen * constraints * keep_binding *
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 15/23 parsing_cocci: visitor_ast: Visit Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Visit these attributes in the AST visitor.
--- parsing_cocci/visitor_ast.ml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
parsing_cocci/visitor_ast.ml +17 -5
@@ -621,9 +621,18 @@ let combiner bind option_default and parameterTypeDef p = let k p = match Ast.unwrap p with - Ast.VoidParam(ty) -> fullType ty - | Ast.Param(ty,Some id) -> named_type ty id - | Ast.Param(ty,None) -> fullType ty + Ast.VoidParam(ty,attr) -> + let lty = fullType ty in + let lattr = multibind (List.map string_mcode attr) in + bind lty lattr + | Ast.Param(ty,Some id,attr) -> + let lid = named_type ty id in + let lattr = multibind (List.map string_mcode attr) in + bind lid lattr + | Ast.Param(ty,None,attr) -> + let lty = fullType ty in + let lattr = multibind (List.map string_mcode attr) in + bind lty lattr | Ast.MetaParam(name,_,_,_) -> meta_mcode name | Ast.MetaParamList(name,_,_,_,_) -> meta_mcode name | Ast.AsParam(p,asexp) ->
@@ -1582,8 +1591,11 @@ let rebuilder let k p = Ast.rewrap p (match Ast.unwrap p with - Ast.VoidParam(ty) -> Ast.VoidParam(fullType ty) - | Ast.Param(ty,id) -> Ast.Param(fullType ty, get_option ident id) + Ast.VoidParam(ty,attr) -> + Ast.VoidParam(fullType ty,List.map string_mcode attr) + | Ast.Param(ty,id,attr) -> + Ast.Param + (fullType ty, get_option ident id,List.map string_mcode attr) | Ast.MetaParam(name,constraints,keep,inherited) -> Ast.MetaParam(meta_mcode name,constraints,keep,inherited) | Ast.MetaParamList(name,lenname_inh,constraints,keep,inherited) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 16/23 parsing_cocci: ast0toast: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in ast0toast.ml.
--- parsing_cocci/ast0toast.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
parsing_cocci/ast0toast.ml +4 -3
@@ -857,10 +857,11 @@ and designator = function and parameterTypeDef p = rewrap p no_isos (match Ast0.unwrap p with - Ast0.VoidParam(ty) -> Ast.VoidParam(typeC false ty) - | Ast0.Param(ty,id) -> + Ast0.VoidParam(ty,attr) -> + Ast.VoidParam(typeC false ty,List.map mcode attr) + | Ast0.Param(ty,id,attr) -> let allminus = check_allminus.VT0.combiner_rec_parameter p in - Ast.Param(typeC allminus ty,get_option ident id) + Ast.Param(typeC allminus ty,get_option ident id,List.map mcode attr) | Ast0.MetaParam(name,cstr,_) -> Ast.MetaParam(mcode name,constraints cstr,unitary,false) | Ast0.MetaParamList(name,lenname,cstr,_) ->
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 17/23 parsing_cocci: disjdistr: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in disjdistr.ml.
--- parsing_cocci/disjdistr.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
parsing_cocci/disjdistr.ml +3 -3
@@ -259,10 +259,10 @@ and disjexp e = and disjparam p = match Ast.unwrap p with - Ast.VoidParam(ty) -> [p] (* void is the only possible value *) - | Ast.Param(ty,id) -> + Ast.VoidParam(ty,attr) -> [p] (* void is the only possible value *) + | Ast.Param(ty,id,attr) -> disjmult2 (disjty ty) (disjoption disjident id) - (fun ty id -> Ast.rewrap p (Ast.Param(ty,id))) + (fun ty id -> Ast.rewrap p (Ast.Param(ty,id,attr))) | Ast.AsParam(pm,asexp) -> (* as exp doesn't contain disj *) let pm = disjparam pm in List.map (function pm -> Ast.rewrap p (Ast.AsParam(pm,asexp))) pm
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 18/23 parsing_cocci: pretty_print_cocci: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Print these attributes correctly in pretty_print_cocci.ml.
--- parsing_cocci/pretty_print_cocci.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
parsing_cocci/pretty_print_cocci.ml +12 -3
@@ -688,9 +688,18 @@ and designator = function and parameterTypeDef p = match Ast.unwrap p with - Ast.VoidParam(ty) -> fullType ty - | Ast.Param(ty,Some id) -> print_named_type ty (fun _ -> ident id); - | Ast.Param(ty,None) -> fullType ty + Ast.VoidParam(ty,attr) -> + fullType ty; + (if not (attr = []) then print_string " "); + print_between print_space (mcode print_string) attr + | Ast.Param(ty,Some id,attr) -> + print_named_type ty (fun _ -> ident id); + (if not (attr = []) then print_string " "); + print_between print_space (mcode print_string) attr + | Ast.Param(ty,None,attr) -> + fullType ty; + (if not (attr = []) then print_string " "); + print_between print_space (mcode print_string) attr | Ast.MetaParam(name,_,_,_) -> mcode print_meta name | Ast.MetaParamList(name,_,_,_,_) -> mcode print_meta name | Ast.PComma(cm) -> mcode print_string cm; print_space()
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 19/23 parsing_cocci: unify_ast: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in unify_ast.ml.
--- parsing_cocci/unify_ast.ml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
parsing_cocci/unify_ast.ml +10 -4
@@ -542,11 +542,17 @@ and unify_designator d1 d2 = and unify_parameterTypeDef p1 p2 = match (Ast.unwrap p1,Ast.unwrap p2) with - (Ast.VoidParam(ft1),Ast.VoidParam(ft2)) -> unify_fullType ft1 ft2 - | (Ast.Param(ft1,i1),Ast.Param(ft2,i2)) -> - unify_fullType ft1 ft2 && - unify_option unify_ident i1 i2 + (Ast.VoidParam(ft1,attr1),Ast.VoidParam(ft2,attr2)) -> + if List.for_all2 unify_mcode attr1 attr2 + then unify_fullType ft1 ft2 + else false + | (Ast.Param(ft1,i1,attr1),Ast.Param(ft2,i2,attr2)) -> + if List.for_all2 unify_mcode attr1 attr2 + then + unify_fullType ft1 ft2 && + unify_option unify_ident i1 i2 + else false | (Ast.MetaParam(_,_,_,_),_) | (Ast.MetaParamList(_,_,_,_,_),_) | (_,Ast.MetaParam(_,_,_,_))
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 20/23 engine: cocci_vs_c: Match Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the C and SmPL AST. Match the attributes correctly in cocci_vs_c.ml.
--- engine/cocci_vs_c.ml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
engine/cocci_vs_c.ml +9 -9
@@ -2112,14 +2112,14 @@ and parameters_bis eas ebs = let special_cases ea eas ebs = (* a case where one smpl parameter matches a list of C parameters *) match A.unwrap ea,ebs with - A.VoidParam ta, ys -> + A.VoidParam (ta, attrsa), ys -> Some (match eas, ebs with | [], [Left eb] -> let {B.p_register=(hasreg,iihasreg); p_namei = idbopt; p_type=tb; - p_attr=attrs; } = eb in + p_attr=attrsb; } = eb in let attr_allminus = check_allminus.Visitor_ast.combiner_parameter ea in
@@ -2128,10 +2128,10 @@ and parameters_bis eas ebs = match tb with | (qub, (B.BaseType B.Void,_)) -> fullType ta tb >>= (fun ta tb -> - attribute_list attr_allminus [] attrs >>= + attribute_list attr_allminus attrsa attrsb >>= (fun attrsa attrsb -> return ( - [(A.VoidParam ta) +> A.rewrap ea], + [(A.VoidParam (ta, attrsa)) +> A.rewrap ea], [Left {B.p_register=(hasreg, iihasreg); p_namei = idbopt; p_type = tb;
@@ -2171,23 +2171,23 @@ and parameter = fun parama paramb -> return (A.MetaParam(ida,constraints,keep,inherited)+> A.rewrap parama,eb))) - | A.Param (typa, idaopt), eb -> + | A.Param (typa, idaopt, attrsa), eb -> let {B.p_register = (hasreg,iihasreg); p_namei = nameidbopt; p_type = typb; - p_attr = attrs;} = paramb in + p_attr = attrsb;} = paramb in let attr_allminus = check_allminus.Visitor_ast.combiner_parameter parama in fullType typa typb >>= (fun typa typb -> - attribute_list attr_allminus [] attrs >>= (fun attrsa attrsb -> + attribute_list attr_allminus attrsa attrsb >>= (fun attrsa attrsb -> match idaopt, nameidbopt with | Some ida, Some nameidb -> (* todo: if minus on ida, should also minus the iihasreg ? *) ident_cpp DontKnow ida nameidb >>= (fun ida nameidb -> return ( - A.Param (typa, Some ida)+> A.rewrap parama, + A.Param (typa, Some ida, attrsa)+> A.rewrap parama, {B.p_register = (hasreg, iihasreg); p_namei = Some (nameidb); p_type = typb;
@@ -2196,7 +2196,7 @@ and parameter = fun parama paramb -> | None, None -> return ( - A.Param (typa, None)+> A.rewrap parama, + A.Param (typa, None, attrsa)+> A.rewrap parama, {B.p_register=(hasreg,iihasreg); p_namei = None; p_type = typb;
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 21/23 ocaml: coccilib: Reflect Parameter attributes
In reply to Jaskaran SinghParameter attributes are added to the SmPL AST. Reflect these changes in coccilib.mli.
--- ocaml/coccilib.mli | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
ocaml/coccilib.mli +4 -4
@@ -2825,8 +2825,8 @@ module Ast_cocci : and initialiser = base_initialiser wrap and base_parameterTypeDef = Ast_cocci.base_parameterTypeDef = - VoidParam of fullType - | Param of fullType * ident option + VoidParam of fullType * attr list + | Param of fullType * ident option * attr list | MetaParam of meta_name mcode * constraints * keep_binding * inherited | MetaParamList of meta_name mcode * listlen * constraints * keep_binding * inherited
@@ -3455,8 +3455,8 @@ module Ast0_cocci : and initialiser_list = initialiser dots and base_parameterTypeDef = Ast0_cocci.base_parameterTypeDef = - VoidParam of typeC - | Param of typeC * ident option + VoidParam of typeC * attr list + | Param of typeC * ident option * attr list | MetaParam of Ast_cocci.meta_name mcode * constraints * pure | MetaParamList of Ast_cocci.meta_name mcode * listlen * constraints * pure
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 22/23 tests: Add test case for removing parameter attributes
In reply to Jaskaran SinghAdd a test case for removing Parameter attributes. The test case checks correct removal of the attribute when it is:
- before the parameter type.
- after the parameter type and before the parameter identifier.
- after the parameter identifier.
--- tests/remove_param_attrs.c | 11 +++++++++++ tests/remove_param_attrs.cocci | 13 +++++++++++++ tests/remove_param_attrs.res | 11 +++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tests/remove_param_attrs.c create mode 100644 tests/remove_param_attrs.cocci create mode 100644 tests/remove_param_attrs.res
tests/remove_param_attrs.c new file +11 -0
@@ -0,0 +1,11 @@ +int func1 (int x,__nocast int y) { +return 0 ; +} + +int func2 (int x,int __nocast y) { +return 0 ; +} + +int func3 (int x,int y__nocast ) { +return 0 ; +}
tests/remove_param_attrs.cocci new file +13 -0
@@ -0,0 +1,13 @@ +@@ +type T,U; +attribute name __nocast; +identifier x,y; +@@ + +T x( + ..., + U y +- __nocast + , + ... + ) {...}
tests/remove_param_attrs.res new file +11 -0
@@ -0,0 +1,11 @@ +int func1(int x, int y) { + return 0; +} + +int func2(int x, int y) { + return 0; +} + +int func3(int x, int y) { + return 0; +}
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH v3 23/23 tests: Add test case to detect parameter attributes
In reply to Jaskaran SinghAdd a test case to detect parameter attributes in C. The test case changes the type of the parameter if it has the attribute. The cases covered are for when the attribute is:
- before the parameter type.
- after the parameter type and before the parameter identifier.
- after the parameter identifier.
--- tests/detect_param_attr.c | 3 +++ tests/detect_param_attr.cocci | 13 +++++++++++++ tests/detect_param_attr.res | 3 +++ 3 files changed, 19 insertions(+) create mode 100644 tests/detect_param_attr.c create mode 100644 tests/detect_param_attr.cocci create mode 100644 tests/detect_param_attr.res
tests/detect_param_attr.c new file +3 -0
@@ -0,0 +1,3 @@ +int func1 (int __nocast u,__nocast int z,int q__nocast ,int w) { +return 0 ; +}
tests/detect_param_attr.cocci new file +13 -0
@@ -0,0 +1,13 @@ +@@ +type T1, T2; +attribute name __nocast; +identifier x, y; +@@ + +T1 x( + ..., +- T2 ++ char + y __nocast, + ... + ) {...}
tests/detect_param_attr.res new file +3 -0
@@ -0,0 +1,3 @@ +int func1(char __nocast u, __nocast char z, char q __nocast, int w) { + return 0; +}
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees