parsing_cocci: Improve attr management in context_neg et al
cover parsing_cocci: Improve attr management in context_neg et al
Introduction of recent patches[1][2][3] for adding additional attributes to the SmPL AST introduced some poor management of attributes in the following files:
parsing_cocci/context_neg.ml
parsing_cocci/arity.ml
parsing_cocci/unify_ast.ml
This patch series is for fixing these issues, by modifying cases wherever necessary.
[1]
[PATCH v3 00/23] cocci: Add parameter attributes to SmPL
https://lore.kernel.org/cocci/[email protected]/T/#t
[2]
[PATCH v3 00/32] cocci: Add cast attributes to C and SmPL ASTs
https://lore.kernel.org/cocci/[email protected]
[3]
[PATCH 00/30] cocci: Add macrodecl attributes to C and SmPL ASTs
https://lore.kernel.org/cocci/[email protected]
Jaskaran Singh (3):
parsing_cocci: arity: Apply mcode2arity on macrodecl/param attrs
parsing_cocci: context_neg: Apply equal_mcode for cast/param attrs
parsing_cocci: unify_ast: Apply unify_mcode to macrodecl attrs
arity.ml | 26 ++++++++++++++++++-------- context_neg.ml | 12 ++++++++---- unify_ast.ml | 3 ++- 3 files changed, 28 insertions(+), 13 deletions(-)
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
PATCH 1/3 parsing_cocci: arity: Apply mcode2arity on macrodecl/param attrs
The following commits introduced some poor management of attributes in arity.ml:
08f1cd9fb83ec400435e0ad8fdf579ec8f9c0f21 b4b8653bd5a9607922e0050fe2fede10d422b218
Apply mcode2arity to macrodecl and parameter attributes.
--- parsing_cocci/arity.ml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
parsing_cocci/arity.ml +18 -8
@@ -601,7 +601,7 @@ and declaration tgt decl = let arity = all_same true tgt (mcode2line lp) ((match stg with None -> [] | Some x -> [mcode2arity x]) @ - (List.map mcode2arity [lp;rp;sem])) in + (List.map mcode2arity ([lp;rp] @ attr @ [sem]))) in let stg = get_option mcode stg in let name = ident false arity name in let lp = mcode lp in
@@ -816,30 +816,40 @@ and make_param = and parameterTypeDef tgt param = let param_same = all_same true tgt in + let make_param_attr param tgt ret = function + [] -> Ast0.rewrap param ret + | x::_ as xs -> + let arity = param_same (mcode2line x) (List.map mcode2arity xs) in + make_param param tgt arity ret in match Ast0.unwrap param with Ast0.VoidParam(ty,attr) -> - Ast0.rewrap param (Ast0.VoidParam(typeC tgt ty,List.map mcode attr)) + let ty = top_typeC tgt true ty in + let attr = List.map mcode attr in + let ret = Ast0.VoidParam(ty,attr) in + make_param_attr param tgt ret 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 + let ret = + match (Ast0.unwrap ty,Ast0.unwrap id) with (Ast0.OptType(ty),Ast0.OptIdent(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,attr)) + | _ -> Ast0.Param(ty,Some id,attr) in + make_param_attr param tgt ret 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 + let ret = + match Ast0.unwrap ty with Ast0.OptType(ty) -> Ast0.OptParam(Ast0.rewrap param (Ast0.Param(ty,None,attr))) - | _ -> Ast0.Param(ty,None,attr)) + | _ -> Ast0.Param(ty,None,attr) in + make_param_attr param tgt ret 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 2/3 parsing_cocci: context_neg: Apply equal_mcode on cast/param attrs
In reply to Jaskaran SinghThe following commits introduced some poor management of attributes in context_neg.ml:
2b7e99a5b86d41e05980c8a9d98eb931e42bb4d8 08f1cd9fb83ec400435e0ad8fdf579ec8f9c0f21
Apply equal_mcode on cast and parameter attributes in context_neg.ml.
--- parsing_cocci/context_neg.ml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
parsing_cocci/context_neg.ml +8 -4
@@ -630,8 +630,10 @@ let rec equal_expression e1 e2 = equal_mcode pt1 pt2 | (Ast0.RecordPtAccess(_,ar1,_),Ast0.RecordPtAccess(_,ar2,_)) -> equal_mcode ar1 ar2 - | (Ast0.Cast(lp1,_,_,rp1,_),Ast0.Cast(lp2,_,_,rp2,_)) -> - equal_mcode lp1 lp2 && equal_mcode rp1 rp2 + | (Ast0.Cast(lp1,_,ar1,rp1,_),Ast0.Cast(lp2,_,ar2,rp2,_)) -> + equal_mcode lp1 lp2 && + List.for_all2 equal_mcode ar1 ar2 && + equal_mcode rp1 rp2 | (Ast0.SizeOfExpr(szf1,_),Ast0.SizeOfExpr(szf2,_)) -> equal_mcode szf1 szf2 | (Ast0.SizeOfType(szf1,lp1,_,rp1),Ast0.SizeOfType(szf2,lp2,_,rp2)) ->
@@ -842,8 +844,10 @@ 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(_,ar1),Ast0.VoidParam(_,ar2)) -> + List.for_all2 equal_mcode ar1 ar2 + | (Ast0.Param(_,_,ar1),Ast0.Param(_,_,ar2)) -> + List.for_all2 equal_mcode ar1 ar2 | (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 3/3 parsing_cocci: unify_ast: Apply unify_mcode on macrodecl attrs
In reply to Jaskaran SinghThe following commit introduced some poor management of attributes in unify_ast.ml:
b4b8653bd5a9607922e0050fe2fede10d422b218
Apply unify_mcode on macrodecl attributes in unify_ast.ml.
--- parsing_cocci/unify_ast.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
parsing_cocci/unify_ast.ml +2 -1
@@ -413,7 +413,8 @@ and unify_declaration d1 d2 = else false | (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 + if bool_unify_option unify_mcode s1 s2 && + List.for_all2 unify_mcode attr1 attr2 then unify_ident n1 n2 && unify_dots unify_expression edots args1 args2
Signature · 6 lines
2.21.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees