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/cocci@systeme.lip6.fr/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(-) _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Add parameter attributes to AST0 of SmPL. This is a list of attributes in the VoidParam and Param types of AST0. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/ast0_cocci.ml | 4 ++-- parsing_cocci/ast0_cocci.mli | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index a06d99ae..8d30daea 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -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 *) diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index 5c2520be..f66a1fac 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -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 *) -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter 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. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/parser_cocci_menhir.mly | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index db5661bd..fe4ef322 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -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)) } -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to AST0 of SmPL. Visit these attributes in the AST0 visitor. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/visitor_ast0.ml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index d9e340ed..d6feccb7 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -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)) -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in arity.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/arity.ml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index 8ee6d33f..0f64c113 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -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 -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in check_meta.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/check_meta.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index 5a348ba3..0e7e04e5 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -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,_,_) -> -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in compute_lines.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/compute_lines.ml | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index 1361d842..5c739d8b 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -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 -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in context_neg.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/context_neg.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml index dd768a61..98b96ac5 100644 --- a/parsing_cocci/context_neg.ml +++ b/parsing_cocci/context_neg.ml @@ -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 -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in function_prototypes.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/function_prototypes.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/parsing_cocci/function_prototypes.ml b/parsing_cocci/function_prototypes.ml index 71bf1a2a..966369b8 100644 --- a/parsing_cocci/function_prototypes.ml +++ b/parsing_cocci/function_prototypes.ml @@ -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 -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in index.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/index.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml index f7ae48b4..1baeb2bb 100644 --- a/parsing_cocci/index.ml +++ b/parsing_cocci/index.ml @@ -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] -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in iso_pattern.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/iso_pattern.ml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index 9df21fb9..b751f3e8 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -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)) -> -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in type_infer.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/type_infer.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parsing_cocci/type_infer.ml b/parsing_cocci/type_infer.ml index e8aad810..495d7974 100644 --- a/parsing_cocci/type_infer.ml +++ b/parsing_cocci/type_infer.ml @@ -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 -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in unparse_ast0.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/unparse_ast0.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index fdaf6cfa..86b545b9 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -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() -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Print these attributes correctly in unparse_cocci.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_c/unparse_cocci.ml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index 395b3a3c..d3f97bf7 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -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 -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Add parameter attributes to the SmPL AST. This is a list of attributes in the VoidParam and Param types of the SmPL AST. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/ast_cocci.ml | 4 ++-- parsing_cocci/ast_cocci.mli | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index 9b147e5c..919d1dcc 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -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 * diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index c56bba88..4b6e7296 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -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 * -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Visit these attributes in the AST visitor. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/visitor_ast.ml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 8e530114..63eab999 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -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) -> -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in ast0toast.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/ast0toast.ml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index 09c28c06..80d38138 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -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,_) -> -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in disjdistr.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/disjdistr.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index 6724bb25..c868cb1c 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -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 -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Print these attributes correctly in pretty_print_cocci.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/pretty_print_cocci.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index 7628882b..a9eb4a8b 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -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() -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in unify_ast.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_cocci/unify_ast.ml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml index 68cb6613..e2b92c48 100644 --- a/parsing_cocci/unify_ast.ml +++ b/parsing_cocci/unify_ast.ml @@ -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(_,_,_,_)) -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the C and SmPL AST. Match the attributes correctly in cocci_vs_c.ml. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- engine/cocci_vs_c.ml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index 317fa71e..66cb104a 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -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; -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Parameter attributes are added to the SmPL AST. Reflect these changes in coccilib.mli. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- ocaml/coccilib.mli | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli index 0e807c9a..59c58aea 100644 --- a/ocaml/coccilib.mli +++ b/ocaml/coccilib.mli @@ -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 -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Add 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. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- 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 diff --git a/tests/remove_param_attrs.c b/tests/remove_param_attrs.c new file mode 100644 index 00000000..8ec1ffde --- /dev/null +++ b/tests/remove_param_attrs.c @@ -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; +} diff --git a/tests/remove_param_attrs.cocci b/tests/remove_param_attrs.cocci new file mode 100644 index 00000000..43f5a204 --- /dev/null +++ b/tests/remove_param_attrs.cocci @@ -0,0 +1,13 @@ +@@ +type T,U; +attribute name __nocast; +identifier x,y; +@@ + +T x( + ..., + U y +- __nocast + , + ... + ) {...} diff --git a/tests/remove_param_attrs.res b/tests/remove_param_attrs.res new file mode 100644 index 00000000..3705e814 --- /dev/null +++ b/tests/remove_param_attrs.res @@ -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; +} -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Add 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. Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- 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 diff --git a/tests/detect_param_attr.c b/tests/detect_param_attr.c new file mode 100644 index 00000000..160d6af2 --- /dev/null +++ b/tests/detect_param_attr.c @@ -0,0 +1,3 @@ +int func1(int __nocast u, __nocast int z, int q __nocast, int w) { + return 0; +} diff --git a/tests/detect_param_attr.cocci b/tests/detect_param_attr.cocci new file mode 100644 index 00000000..53b8668f --- /dev/null +++ b/tests/detect_param_attr.cocci @@ -0,0 +1,13 @@ +@@ +type T1, T2; +attribute name __nocast; +identifier x, y; +@@ + +T1 x( + ..., +- T2 ++ char + y __nocast, + ... + ) {...} diff --git a/tests/detect_param_attr.res b/tests/detect_param_attr.res new file mode 100644 index 00000000..b3db290e --- /dev/null +++ b/tests/detect_param_attr.res @@ -0,0 +1,3 @@ +int func1(char __nocast u, __nocast char z, char q __nocast, int w) { + return 0; +} -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci