Re: [Cocci] [PATCH 1/3] parsing_cocci: arity: Apply mcode2arity on macrodecl/param attrs

2020-06-12 Thread Markus Elfring
> The following commits introduced some poor management of attributes in
arity.ml:
>   08f1cd9fb83ec400435e0ad8fdf579ec8f9c0f21
>   b4b8653bd5a9607922e0050fe2fede10d422b218

I suggest to specify also subjects for such commit references.


> Apply mcode2arity to macrodecl and parameter attributes.

To which item does the identifier “mcode2arity” refer?

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH 1/3] parsing_cocci: arity: Apply mcode2arity on macrodecl/param attrs

2020-06-11 Thread Jaskaran Singh
The following commits introduced some poor management of attributes in
arity.ml:
08f1cd9fb83ec400435e0ad8fdf579ec8f9c0f21
b4b8653bd5a9607922e0050fe2fede10d422b218
Apply mcode2arity to macrodecl and parameter attributes.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/arity.ml | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
index 6f90616e..3bbecedf 100644
--- a/parsing_cocci/arity.ml
+++ b/parsing_cocci/arity.ml
@@ -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
-- 
2.21.1

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci