cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes
@ 2020-07-03 17:59 Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 01/20] parsing_cocci: ast0_cocci: " Jaskaran Singh
                   ` (19 more replies)
  0 siblings, 20 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

This patch series aims to wrap the existing attribute type on the SmPL
side.  Wrapping attributes is necessary to add support for meta
attributes in SmPL.

Jaskaran Singh (20):
      parsing_cocci: ast0_cocci: Wrap SmPL Attributes
      parsing_cocci: parser: Wrap SmPL Attributes
      parsing_cocci: visitor_ast0: Wrap SmPL Attributes
      parsing_cocci: adjust_pragmas: Wrap SmPL Attributes
      parsing_cocci: arity: Wrap SmPL Attributes
      parsing_cocci: compute_lines: Wrap SmPL Attributes
      parsing_cocci: context_neg: Wrap SmPL Attributes
      parsing_cocci: iso_pattern: Wrap SmPL Attributes
      parsing_cocci: index: Wrap SmPL Attributes
      parsing_cocci: unparse_ast0: Wrap SmPL Attributes
      parsing_cocci: ast0toast: Wrap SmPL Attributes
      parsing_cocci: ast_cocci: Wrap SmPL Attributes
      parsing_cocci: visitor_ast: Wrap SmPL Attributes
      parsing_cocci: get_constants2: Wrap SmPL Attributes
      parsing_cocci: safe_for_multi_decls: Wrap SmPL Attributes
      parsing_cocci: unify_ast: Wrap SmPL Attributes
      parsing_cocci: pretty_print_cocci: Wrap SmPL Attributes
      parsing_c: unparse_cocci: Wrap SmPL Attributes
      engine: cocci_vs_c: Wrap SmPL Attributes
      ocaml: coccilib: Wrap SmPL Attributes

 engine/cocci_vs_c.ml                  |   26 +++---
 ocaml/coccilib.mli                    |   20 ++++-
 parsing_c/unparse_cocci.ml            |   68 ++++++++---------
 parsing_cocci/adjust_pragmas.ml       |   18 +++-
 parsing_cocci/arity.ml                |  134 +++++++++++++++------------------
 parsing_cocci/ast0_cocci.ml           |    5 +
 parsing_cocci/ast0_cocci.mli          |    5 +
 parsing_cocci/ast0toast.ml            |   42 ++++++----
 parsing_cocci/ast_cocci.ml            |   10 ++
 parsing_cocci/ast_cocci.mli           |   10 ++
 parsing_cocci/compute_lines.ml        |   84 ++++++++++++---------
 parsing_cocci/context_neg.ml          |   62 ++++++++++-----
 parsing_cocci/get_constants2.ml       |   12 ++-
 parsing_cocci/index.ml                |   12 ++-
 parsing_cocci/index.mli               |    2 
 parsing_cocci/iso_pattern.ml          |  136 +++++++++++++---------------------
 parsing_cocci/parse_aux.ml            |    6 +
 parsing_cocci/parse_aux.mli           |   14 +++
 parsing_cocci/parser_cocci_menhir.mly |   36 +++++----
 parsing_cocci/pretty_print_cocci.ml   |   68 ++++++++---------
 parsing_cocci/safe_for_multi_decls.ml |   12 ++-
 parsing_cocci/unify_ast.ml            |   42 ++++++----
 parsing_cocci/unparse_ast0.ml         |   68 ++++++++---------
 parsing_cocci/visitor_ast.ml          |   96 +++++++++++++++---------
 parsing_cocci/visitor_ast0.ml         |   54 +++++++++----
 25 files changed, 596 insertions(+), 446 deletions(-)


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

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 01/20] parsing_cocci: ast0_cocci: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 02/20] parsing_cocci: parser: " Jaskaran Singh
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

SmPL attributes need to be wrapped to provide support for meta
attributes. Wrap attributes in AST0 of SmPL.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/ast0_cocci.ml  | 5 ++++-
 parsing_cocci/ast0_cocci.mli | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index 743fab86..bfc0d145 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -460,7 +460,10 @@ and fninfo =
   | FInline of string mcode
   | FAttr of attr
 
-and attr = string mcode
+and base_attr =
+    Attribute of string mcode
+
+and attr = base_attr wrap
 
 and ('a,'b) whencode =
     WhenNot of string mcode (* when *) * string mcode (* != *) * 'a
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 470c837f..20d6e40c 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -445,7 +445,10 @@ and fninfo =
   | FInline of string mcode
   | FAttr of attr
 
-and attr = string mcode
+and base_attr =
+    Attribute of string mcode
+
+and attr = base_attr wrap
 
 and ('a,'b) whencode =
     WhenNot of string mcode (* when *) * string mcode (* != *) * 'a
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 02/20] parsing_cocci: parser: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 01/20] parsing_cocci: ast0_cocci: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-06 20:03   ` Julia Lawall
  2020-07-03 17:59 ` [Cocci] [PATCH 03/20] parsing_cocci: visitor_ast0: " Jaskaran Singh
                   ` (17 subsequent siblings)
  19 siblings, 1 reply; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reciprocate this and wrap
attributes in the SmPL parser.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/parse_aux.ml            |  3 +++
 parsing_cocci/parse_aux.mli           |  7 +++++++
 parsing_cocci/parser_cocci_menhir.mly | 18 ++++++++++--------
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/parsing_cocci/parse_aux.ml b/parsing_cocci/parse_aux.ml
index b5d1afb4..f2036bfc 100644
--- a/parsing_cocci/parse_aux.ml
+++ b/parsing_cocci/parse_aux.ml
@@ -152,6 +152,9 @@ let logic_op ast_op left op right =
 let make_cv cv ty =
   match cv with None -> ty | Some x -> Ast0.wrap (Ast0.ConstVol(x,ty))
 
+let make_attr attr =
+  Ast0.wrap(Ast0.Attribute(id2mcode attr))
+
 let top_dots l = Ast0.wrap l
 
 (* here the offset is that of the first in the sequence of *s, not that of
diff --git a/parsing_cocci/parse_aux.mli b/parsing_cocci/parse_aux.mli
index 91d7cb26..0ecf10b0 100644
--- a/parsing_cocci/parse_aux.mli
+++ b/parsing_cocci/parse_aux.mli
@@ -151,6 +151,13 @@ val logic_op :
   string -> Ast0_cocci.expression -> Ast0_cocci.base_expression Ast0_cocci.wrap
 val make_cv :
   Ast_cocci.const_vol Ast0_cocci.mcode option -> Ast0_cocci.typeC -> Ast0_cocci.typeC
+val make_attr:
+  string *
+  (Data.line_type * int * int * int * int * int *
+   (Ast_cocci.added_string * Ast0_cocci.position_info) list *
+   (Ast_cocci.added_string * Ast0_cocci.position_info) list *
+   Ast0_cocci.anything list * string) ->
+   Ast0_cocci.attr
 val top_dots : 'a -> 'a Ast0_cocci.wrap
 val pointerify :
   Ast0_cocci.typeC ->
diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
index 63cb8b5e..32bcd63c 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -1495,11 +1495,11 @@ fninfo:
 	let _ = List.find (function Ast0.FInline(_) -> true | _ -> false) $2 in
 	raise (Semantic_cocci.Semantic "duplicate inline")
       with Not_found -> (Ast0.FInline(P.clt2mcode "inline" $1))::$2 }
-  | Tattr    fninfo
+  | a=Tattr    fninfo
       { try
 	let _ = List.find (function Ast0.FAttr(_) -> true | _ -> false) $2 in
 	raise (Semantic_cocci.Semantic "multiple attributes")
-      with Not_found -> (Ast0.FAttr(P.id2mcode $1))::$2 }
+      with Not_found -> (Ast0.FAttr(P.make_attr a))::$2 }
 
 fninfo_nt:
     /* empty */ { [] }
@@ -1514,11 +1514,11 @@ fninfo_nt:
 	let _ = List.find (function Ast0.FInline(_) -> true | _ -> false) $2 in
 	raise (Semantic_cocci.Semantic "duplicate inline")
       with Not_found -> (Ast0.FInline(P.clt2mcode "inline" $1))::$2 }
-  | Tattr    fninfo_nt
+  | a=Tattr    fninfo_nt
       { try
 	let _ = List.find (function Ast0.FAttr(_) -> true | _ -> false) $2 in
 	raise (Semantic_cocci.Semantic "duplicate init")
-      with Not_found -> (Ast0.FAttr(P.id2mcode $1))::$2 }
+      with Not_found -> (Ast0.FAttr(P.make_attr a))::$2 }
 
 storage:
          s=Tstatic      { P.clt2mcode Ast.Static s }
@@ -3227,12 +3227,14 @@ script_virt_name_decl:
 
 %inline
 attr_list:
-                        { [] }
- | a=Tattr f=full_attr_list {P.id2mcode a::f}
+                           { [] }
+ | Tattr f=full_attr_list
+    { let a = P.make_attr $1 in a::f }
 
 full_attr_list:
-                        { [] }
- | Tattr full_attr_list {P.id2mcode $1::$2}
+                           { [] }
+ | Tattr f=full_attr_list
+    { let a = P.make_attr $1 in a::f }
 
 anything: /* used for script code */
    TIdentifier { "identifier" }
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 03/20] parsing_cocci: visitor_ast0: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 01/20] parsing_cocci: ast0_cocci: " Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 02/20] parsing_cocci: parser: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 04/20] parsing_cocci: adjust_pragmas: " Jaskaran Singh
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Create a function for attributes
in the SmPL AST0 visitor. This function has not been added to the
visitor API yet.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/visitor_ast0.ml | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index 87b2b3f5..a5902f8c 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -187,7 +187,7 @@ let visitor mode bind option_default
 	| Ast0.Cast(lp,ty,attr,rp,exp) ->
 	    let (lp_n,lp) = string_mcode lp in
 	    let (ty_n,ty) = typeC ty in
-	    let (attr_n,attr) = map_split_bind string_mcode attr in
+	    let (attr_n,attr) = map_split_bind attribute attr in
 	    let (rp_n,rp) = string_mcode rp in
 	    let (exp_n,exp) = expression exp in
             (multibind [lp_n;ty_n;attr_n;rp_n;exp_n],
@@ -611,7 +611,7 @@ let visitor mode bind option_default
 	| Ast0.Init(stg,ty,id,attr,eq,ini,sem) ->
 	    let (stg_n,stg) = get_option storage_mcode stg in
 	    let ((ty_id_n,ty),id) = named_type ty id in
-	    let (attr_n,attr) = map_split_bind string_mcode attr in
+	    let (attr_n,attr) = map_split_bind attribute attr in
 	    let (eq_n,eq) = string_mcode eq in
 	    let (ini_n,ini) = initialiser ini in
 	    let (sem_n,sem) = string_mcode sem in
@@ -620,7 +620,7 @@ let visitor mode bind option_default
 	| Ast0.UnInit(stg,ty,id,attr,sem) ->
 	    let (stg_n,stg) = get_option storage_mcode stg in
 	    let ((ty_id_n,ty),id) = named_type ty id in
-	    let (attr_n,attr) = map_split_bind string_mcode attr in
+	    let (attr_n,attr) = map_split_bind attribute attr in
 	    let (sem_n,sem) = string_mcode sem in
 	    (multibind [stg_n;ty_id_n;attr_n;sem_n],
 	     Ast0.UnInit(stg,ty,id,attr,sem))
@@ -645,7 +645,7 @@ let visitor mode bind option_default
 	    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 (attr_n,attr) = map_split_bind attribute attr in
 	    let (sem_n,sem) = string_mcode sem in
 	    (multibind [stg_n;name_n;lp_n;args_n;rp_n;attr_n;sem_n],
 	     Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem))
@@ -662,7 +662,7 @@ let visitor mode bind option_default
 	     Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem))
 	| Ast0.TyDecl(ty,attr,sem) ->
 	    let (ty_n,ty) = typeC ty in
-	    let (attr_n,attr) = map_split_bind string_mcode attr in
+	    let (attr_n,attr) = map_split_bind attribute attr in
 	    let (sem_n,sem) = string_mcode sem in
             (multibind [ty_n; attr_n; sem_n], Ast0.TyDecl(ty,attr,sem))
 	| Ast0.Typedef(stg,ty,id,sem) ->
@@ -832,15 +832,15 @@ let visitor mode bind option_default
 	(match Ast0.unwrap p with
 	  Ast0.VoidParam(ty, attrs) ->
 	    let (ty_n,ty) = typeC ty in
-	    let (attr_n,attr) = map_split_bind string_mcode attrs in
+	    let (attr_n,attr) = map_split_bind attribute 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
-	    let (attr_n,attr) = map_split_bind string_mcode attrs in
+	    let (attr_n,attr) = map_split_bind attribute 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
-	    let (attr_n,attr) = map_split_bind string_mcode attrs in
+	    let (attr_n,attr) = map_split_bind attribute attrs in
 	    (bind ty_n attr_n, Ast0.Param(ty,None,attr))
 	| Ast0.MetaParam(name,constraints,pure) ->
 	    let (n,name) = meta_mcode name in
@@ -1146,7 +1146,16 @@ let visitor mode bind option_default
     | Ast0.FInline(inline) ->
 	let (n,inline) = string_mcode inline in (n,Ast0.FInline(inline))
     | Ast0.FAttr(init) ->
-	let (n,init) = string_mcode init in (n,Ast0.FAttr(init))
+	let (n,init) = attribute init in (n,Ast0.FAttr(init))
+
+  and attribute a =
+    let k a =
+      rewrap a
+        (match Ast0.unwrap a with
+          Ast0.Attribute(attr) ->
+            let (attr_n,attr) = string_mcode attr in
+            (attr_n,Ast0.Attribute(attr))) in
+    k a
 
   (* we only include the when string mcode w because the parameterised
      string_mcodefn function might have side-effects *)
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 04/20] parsing_cocci: adjust_pragmas: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (2 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 03/20] parsing_cocci: visitor_ast0: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 05/20] parsing_cocci: arity: " Jaskaran Singh
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
adjust_pragmas.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/adjust_pragmas.ml | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/adjust_pragmas.ml b/parsing_cocci/adjust_pragmas.ml
index b328ad27..8f24fa71 100644
--- a/parsing_cocci/adjust_pragmas.ml
+++ b/parsing_cocci/adjust_pragmas.ml
@@ -221,6 +221,11 @@ let rec left_ident i =
       call_right left_ident id i (function id -> Ast0.OptIdent(id))
   | Ast0.AsIdent(id,asid) -> failwith "not possible"
 
+let left_attribute attr =
+  match Ast0.unwrap attr with
+    Ast0.Attribute(a) ->
+      call_right left_mcode a attr (function a -> Ast0.Attribute(a))
+
 let left_fundecl name fninfo =
   let fncall_right processor data cont =
     match processor data with
@@ -238,7 +243,7 @@ let left_fundecl name fninfo =
   | (Ast0.FInline inl)::x ->
       fncall_right left_mcode inl (function inl -> (Ast0.FInline inl)::x)
   | (Ast0.FAttr atr)::x ->
-      fncall_right left_mcode atr (function atr -> (Ast0.FAttr atr)::x)
+      fncall_right left_attribute atr (function atr -> (Ast0.FAttr atr)::x)
 
 let rec left_decl decl =
   match Ast0.unwrap decl with
@@ -276,7 +281,7 @@ let rec left_decl decl =
 	    (function inl ->
 	      Ast0.FunProto((Ast0.FInline inl)::x,name,lp1,params,va,rp1,sem))
       | (Ast0.FAttr attr)::x ->
-	  call_right left_mcode attr decl
+	  call_right left_attribute attr decl
 	    (function attr ->
 	      Ast0.FunProto((Ast0.FAttr attr)::x,name,lp1,params,va,rp1,sem)))
   | Ast0.MacroDecl(Some stg,name,lp,args,rp,attr,sem) ->
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 05/20] parsing_cocci: arity: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (3 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 04/20] parsing_cocci: adjust_pragmas: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-06 20:04   ` Julia Lawall
  2020-07-03 17:59 ` [Cocci] [PATCH 06/20] parsing_cocci: compute_lines: " Jaskaran Singh
                   ` (14 subsequent siblings)
  19 siblings, 1 reply; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
arity.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/arity.ml | 67 +++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 36 deletions(-)

diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
index 3bbecedf..524f8994 100644
--- a/parsing_cocci/arity.ml
+++ b/parsing_cocci/arity.ml
@@ -256,10 +256,10 @@ let rec top_expression opt_allowed tgt expr =
       make_exp expr tgt arity (Ast0.RecordPtAccess(exp,ar,field))
   | Ast0.Cast(lp,ty,attr,rp,exp) ->
       let arity =
-        exp_same (mcode2line lp) (List.map mcode2arity ([lp] @ attr @ [rp])) in
+        exp_same (mcode2line lp) (List.map mcode2arity ([lp;rp])) in
       let lp = mcode lp in
       let ty = typeC arity ty in
-      let attr = List.map mcode attr in
+      let attr = List.map attribute attr in
       let rp = mcode rp in
       let exp = expression arity exp in
       make_exp expr tgt arity (Ast0.Cast(lp,ty,attr,rp,exp))
@@ -564,7 +564,7 @@ and declaration tgt decl =
       let stg = get_option mcode stg in
       let ty = typeC arity ty in
       let id = ident false arity id in
-      let attr = List.map mcode attr in
+      let attr = List.map attribute attr in
       let eq = mcode eq in
       let exp = initialiser arity exp in
       let sem = mcode sem in
@@ -577,7 +577,7 @@ and declaration tgt decl =
       let stg = get_option mcode stg in
       let ty = typeC arity ty in
       let id = ident false arity id in
-      let attr = List.map mcode attr in
+      let attr = List.map attribute attr in
       let sem = mcode sem in
       make_decl decl tgt arity (Ast0.UnInit(stg,ty,id,attr,sem))
   | Ast0.FunProto(fi,name,lp1,params,va,rp1,sem) ->
@@ -601,13 +601,13 @@ 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] @ attr @ [sem]))) in
+	   (List.map mcode2arity ([lp;rp;sem]))) in
       let stg = get_option mcode stg in
       let name = ident false arity name in
       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 attr = List.map attribute attr in
       let sem = mcode sem in
       make_decl decl tgt arity (Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem))
   | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
@@ -627,9 +627,9 @@ and declaration tgt decl =
   | Ast0.TyDecl(ty,attr,sem) ->
       let arity =
         all_same true tgt
-          (mcode2line sem) (List.map mcode2arity (attr @ [sem])) in
+          (mcode2line sem) [mcode2arity sem] in
       let ty = typeC arity ty in
-      let attr = List.map mcode attr in
+      let attr = List.map attribute attr in
       let sem = mcode sem in
       make_decl decl tgt arity (Ast0.TyDecl(ty,attr,sem))
   | Ast0.Typedef(stg,ty,id,sem) ->
@@ -816,40 +816,30 @@ 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) ->
-      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.rewrap param (Ast0.VoidParam(typeC tgt ty,List.map attribute 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
-      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) in
-      make_param_attr param tgt ret attr
+      let attr = List.map attribute 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,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,None,attr) ->
       let ty = top_typeC tgt true ty in
-      let attr = List.map mcode attr in
-      let ret =
-	match Ast0.unwrap ty with
-	  Ast0.OptType(ty) ->
+      let attr = List.map attribute attr in
+      Ast0.rewrap param
+        (match Ast0.unwrap ty with
+          Ast0.OptType(ty) ->
 	    Ast0.OptParam(Ast0.rewrap param (Ast0.Param(ty,None,attr)))
-	| _ -> Ast0.Param(ty,None,attr) in
-      make_param_attr param tgt ret 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
@@ -1272,7 +1262,7 @@ and fninfo arity = function
     Ast0.FStorage(stg) -> Ast0.FStorage(mcode stg)
   | Ast0.FType(ty) -> Ast0.FType(typeC arity ty)
   | Ast0.FInline(inline) -> Ast0.FInline(mcode inline)
-  | Ast0.FAttr(attr) -> Ast0.FAttr(mcode attr)
+  | Ast0.FAttr(attr) -> Ast0.FAttr(attribute attr)
 
 and fninfo2arity fninfo =
   List.concat
@@ -1281,9 +1271,14 @@ and fninfo2arity fninfo =
 	   Ast0.FStorage(stg) -> [mcode2arity stg]
 	 | Ast0.FType(ty) -> []
 	 | Ast0.FInline(inline) -> [mcode2arity inline]
-	 | Ast0.FAttr(attr) -> [mcode2arity attr])
+	 | Ast0.FAttr(attr) -> [])
        fninfo)
 
+and attribute attr =
+  match Ast0.unwrap attr with
+    Ast0.Attribute(a) ->
+      Ast0.rewrap attr (Ast0.Attribute(mcode a))
+
 and whencode notfn alwaysfn expression = function
     Ast0.WhenNot (w,e,a) -> Ast0.WhenNot (w,e,notfn a)
   | Ast0.WhenAlways (w,e,a) -> Ast0.WhenAlways (w,e,alwaysfn a)
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 06/20] parsing_cocci: compute_lines: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (4 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 05/20] parsing_cocci: arity: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 07/20] parsing_cocci: context_neg: " Jaskaran Singh
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
compute_lines.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/compute_lines.ml | 42 +++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml
index 4f273307..4420e952 100644
--- a/parsing_cocci/compute_lines.ml
+++ b/parsing_cocci/compute_lines.ml
@@ -428,7 +428,7 @@ let rec expression e =
   | Ast0.Cast(lp,ty,attr,rp,exp) ->
       let lp = normal_mcode lp in
       let exp = expression exp in
-      let attr = List.map normal_mcode attr in
+      let attr = List.map attribute attr in
       let rp = normal_mcode rp in
       mkres e (Ast0.Cast(lp,typeC ty,attr,rp,exp)) (promote_mcode lp) exp
   | Ast0.SizeOfExpr(szf,exp) ->
@@ -672,7 +672,7 @@ and declaration d =
   | Ast0.Init(stg,ty,id,attr,eq,exp,sem) ->
       let ty = typeC ty in
       let id = ident id in
-      let attr = List.map normal_mcode attr in
+      let attr = List.map attribute attr in
       let eq = normal_mcode eq in
       let exp = initialiser exp in
       let sem = normal_mcode sem in
@@ -686,7 +686,7 @@ and declaration d =
   | Ast0.UnInit(stg,ty,id,attr,sem) ->
       let ty = typeC ty in
       let id = ident id in
-      let attr = List.map normal_mcode attr in
+      let attr = List.map attribute attr in
       let sem = normal_mcode sem in
       (match stg with
 	None ->
@@ -715,13 +715,13 @@ and declaration d =
 	| Ast0.FStorage(stg)::_ -> mkres d res (promote_mcode stg) right
 	| 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.FAttr(attr)::_ -> mkres d res attr right)
   | 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 attr = List.map attribute attr in
       let sem = normal_mcode sem in
       (match stg with
 	None ->
@@ -749,7 +749,7 @@ and declaration d =
 	    (promote_mcode x) (promote_mcode sem))
   | Ast0.TyDecl(ty,attr,sem) ->
       let ty = typeC ty in
-      let attr = List.map normal_mcode attr in
+      let attr = List.map attribute attr in
       let sem = normal_mcode sem in
       mkres d (Ast0.TyDecl(ty,attr,sem)) ty (promote_mcode sem)
   | Ast0.Typedef(stg,ty,id,sem) ->
@@ -907,6 +907,13 @@ and initialiser_list prev = dots is_init_dots prev initialiser
 (* for export *)
 and initialiser_dots x = dots is_init_dots None initialiser x
 
+and attribute a =
+  match Ast0.unwrap a with
+    Ast0.Attribute(attr) ->
+      let ln = promote_mcode attr in
+      mkres a (Ast0.Attribute(attr)) ln ln
+
+
 (* --------------------------------------------------------------------- *)
 (* Parameter *)
 
@@ -918,30 +925,30 @@ and is_param_dots p =
 and parameterTypeDef p =
   match Ast0.unwrap p with
     Ast0.VoidParam(ty,attr) ->
-      let attr = List.map normal_mcode attr in
+      let attr = List.map attribute 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))
+          mkres p (Ast0.VoidParam(ty,attr)) ty lattr)
   | Ast0.Param(ty,Some id,attr) ->
       let id = ident id in
       let ty = typeC ty in
-      let attr = List.map normal_mcode attr in
+      let attr = List.map attribute 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))
+          mkres p (Ast0.Param(ty,Some id,attr)) ty lattr)
   | Ast0.Param(ty,None,attr) ->
-      let attr = List.map normal_mcode attr in
+      let attr = List.map attribute 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))
+          mkres p (Ast0.Param(ty,None,attr)) ty lattr)
   | Ast0.MetaParam(name,a,b) ->
       let name = normal_mcode name in
       let ln = promote_mcode name in
@@ -1297,7 +1304,7 @@ let rec statement s =
 	| Ast0.FStorage(stg)::_ -> mkres s res (promote_mcode stg) right
 	| Ast0.FType(ty)::_ -> mkres s res ty right
 	| Ast0.FInline(inline)::_ -> mkres s res (promote_mcode inline) right
-	| Ast0.FAttr(attr)::_ -> mkres s res (promote_mcode attr) right)
+	| Ast0.FAttr(attr)::_ -> mkres s res attr right)
 
     | Ast0.Include(inc,stm) ->
 	let inc = normal_mcode inc in
@@ -1359,11 +1366,10 @@ and leftfninfo fninfo name bef = (* cases on what is leftmost *)
        Ast0.FInline(set_mcode_info inline (Ast0.get_info inlinfo))::rest,
        name)
   | Ast0.FAttr(attr)::rest ->
-      let (leftinfo,attrinfo) =
-	promote_to_statement_start (promote_mcode attr) bef in
-      (leftinfo,
-       Ast0.FAttr(set_mcode_info attr (Ast0.get_info attrinfo))::rest,
-       name)
+      let attr = attribute attr in
+      let (leftinfo,attr) =
+	promote_to_statement_start attr bef in
+      (leftinfo,Ast0.FAttr(attr)::rest,name)
 
 and pragmainfo pi =
   match Ast0.unwrap pi with
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 07/20] parsing_cocci: context_neg: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (5 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 06/20] parsing_cocci: compute_lines: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 08/20] parsing_cocci: iso_pattern: " Jaskaran Singh
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
context_neg.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/context_neg.ml | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml
index 6e992245..6a04f49b 100644
--- a/parsing_cocci/context_neg.ml
+++ b/parsing_cocci/context_neg.ml
@@ -400,6 +400,10 @@ let classify is_minus all_marked table code =
 	  disj_cases e starter expr_list r.VT0.combiner_rec_expression ender
       |	_ -> k e) in
 
+  let attribute a =
+    match Ast0.unwrap a with
+      Ast0.Attribute(attr) -> mcode attr in
+
   (* not clear why we have the next cases, since DisjDecl and
   as it only comes from isos *)
   (* actually, DisjDecl now allowed in source struct decls *)
@@ -423,7 +427,7 @@ let classify is_minus all_marked table code =
 	    (bind (r.VT0.combiner_rec_typeC ty)
 	       (bind (r.VT0.combiner_rec_ident id)
                   (bind
-                     (List.fold_right bind (List.map mcode attr)
+                     (List.fold_right bind (List.map attribute attr)
 			option_default)
 		     (bind (mcode eq)
 			(bind (r.VT0.combiner_rec_initialiser ini)
@@ -433,7 +437,7 @@ let classify is_minus all_marked table code =
 	    (bind (r.VT0.combiner_rec_typeC ty)
 	       (bind (r.VT0.combiner_rec_ident id)
                   (bind
-                     (List.fold_right bind (List.map mcode attr)
+                     (List.fold_right bind (List.map attribute attr)
 			option_default)
 		     (mcode sem))))
       |	_ -> k e) in
@@ -470,7 +474,7 @@ let classify is_minus all_marked table code =
 	  (* needed for the same reason as in the Init and UnInit cases *)
 	  bind (r.VT0.combiner_rec_typeC ty)
            (bind (r.VT0.combiner_rec_ident id)
-              (List.fold_right bind (List.map mcode attr) option_default))
+              (List.fold_right bind (List.map attribute attr) option_default))
       |	_ -> k e) in
 
   let typeC r k e =
@@ -585,6 +589,11 @@ let equal_option e1 e2 =
 let dots fn d1 d2 =
   List.length (Ast0.unwrap d1) = List.length (Ast0.unwrap d2)
 
+let equal_attribute a1 a2 =
+  match (Ast0.unwrap a1, Ast0.unwrap a2) with
+    (Ast0.Attribute(attr1),Ast0.Attribute(attr2)) ->
+      equal_mcode attr1 attr2
+
 let equal_ident i1 i2 =
   match (Ast0.unwrap i1,Ast0.unwrap i2) with
     (Ast0.Id(name1),Ast0.Id(name2)) -> equal_mcode name1 name2
@@ -632,7 +641,7 @@ let rec equal_expression e1 e2 =
       equal_mcode ar1 ar2
   | (Ast0.Cast(lp1,_,ar1,rp1,_),Ast0.Cast(lp2,_,ar2,rp2,_)) ->
       equal_mcode lp1 lp2 &&
-      List.for_all2 equal_mcode ar1 ar2 &&
+      List.for_all2 equal_attribute ar1 ar2 &&
       equal_mcode rp1 rp2
   | (Ast0.SizeOfExpr(szf1,_),Ast0.SizeOfExpr(szf2,_)) ->
       equal_mcode szf1 szf2
@@ -731,7 +740,7 @@ let equal_fninfo x y =
     (Ast0.FStorage(s1),Ast0.FStorage(s2)) -> equal_mcode s1 s2
   | (Ast0.FType(_),Ast0.FType(_)) -> true
   | (Ast0.FInline(i1),Ast0.FInline(i2)) -> equal_mcode i1 i2
-  | (Ast0.FAttr(i1),Ast0.FAttr(i2)) -> equal_mcode i1 i2
+  | (Ast0.FAttr(i1),Ast0.FAttr(i2)) -> equal_attribute i1 i2
   | _ -> false
 
 let equal_declaration d1 d2 =
@@ -740,10 +749,10 @@ let equal_declaration d1 d2 =
       equal_mcode name1 name2
   | (Ast0.Init(stg1,_,_,attr1,eq1,_,sem1),
      Ast0.Init(stg2,_,_,attr2,eq2,_,sem2)) ->
-      equal_option stg1 stg2 && List.for_all2 equal_mcode attr1 attr2 &&
+      equal_option stg1 stg2 && List.for_all2 equal_attribute attr1 attr2 &&
       equal_mcode eq1 eq2 && equal_mcode sem1 sem2
   | (Ast0.UnInit(stg1,_,_,attr1,sem1),Ast0.UnInit(stg2,_,_,attr2,sem2)) ->
-      equal_option stg1 stg2 && List.for_all2 equal_mcode attr1 attr2 &&
+      equal_option stg1 stg2 && List.for_all2 equal_attribute attr1 attr2 &&
       equal_mcode sem1 sem2
   | (Ast0.FunProto(fninfo1,name1,lp1,p1,va1,rp1,sem1),
      Ast0.FunProto(fninfo2,name2,lp2,p2,va2,rp2,sem2)) ->
@@ -758,7 +767,7 @@ let equal_declaration d1 d2 =
        equal_mcode rp1 rp2 && equal_mcode sem1 sem2
   | (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_option stg1 stg2 && List.for_all2 equal_attribute 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)) ->
@@ -766,7 +775,7 @@ let equal_declaration d1 d2 =
        equal_mcode lp1 lp2 && equal_mcode rp1 rp2 && equal_mcode eq1 eq2
 	 && equal_mcode sem1 sem2
   | (Ast0.TyDecl(_,attr1,sem1),Ast0.TyDecl(_,attr2,sem2)) ->
-       List.for_all2 equal_mcode attr1 attr2 && equal_mcode sem1 sem2
+       List.for_all2 equal_attribute attr1 attr2 && equal_mcode sem1 sem2
   | (Ast0.OptDecl(_),Ast0.OptDecl(_)) -> true
   | (Ast0.DisjDecl(starter1,_,mids1,ender1),
      Ast0.DisjDecl(starter2,_,mids2,ender2))
@@ -845,9 +854,9 @@ let equal_initialiser i1 i2 =
 let equal_parameterTypeDef p1 p2 =
   match (Ast0.unwrap p1,Ast0.unwrap p2) with
     (Ast0.VoidParam(_,ar1),Ast0.VoidParam(_,ar2)) ->
-      List.for_all2 equal_mcode ar1 ar2
+      List.for_all2 equal_attribute ar1 ar2
   | (Ast0.Param(_,_,ar1),Ast0.Param(_,_,ar2)) ->
-      List.for_all2 equal_mcode ar1 ar2
+      List.for_all2 equal_attribute ar1 ar2
   | (Ast0.MetaParam(name1,_,_),Ast0.MetaParam(name2,_,_))
   | (Ast0.MetaParamList(name1,_,_,_),Ast0.MetaParamList(name2,_,_,_)) ->
       equal_mcode name1 name2
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 08/20] parsing_cocci: iso_pattern: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (6 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 07/20] parsing_cocci: context_neg: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 09/20] parsing_cocci: index: " Jaskaran Singh
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
iso_pattern.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/iso_pattern.ml | 68 ++++++++++++++----------------------
 1 file changed, 27 insertions(+), 41 deletions(-)

diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 6cd5f1cb..40fd67e8 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -759,14 +759,10 @@ let match_maker checks_needed context_required whencode_allowed =
 		   match_ident fielda fieldb]
 	  | (Ast0.Cast(lp1,tya,attra,rp1,expa),
              Ast0.Cast(lp,tyb,attrb,rp,expb)) ->
-              if (List.length attra = List.length attrb &&
-                  List.fold_left2 (fun p a b -> p && mcode_equal a b) true
-                  attra attrb)
-              then
 	      conjunct_many_bindings
 		[check_mcode lp1 lp; check_mcode rp1 rp;
+                  match_attributes attra attrb;
 		  match_typeC tya tyb; match_expr expa expb]
-              else return false
 	  | (Ast0.SizeOfExpr(szf1,expa),Ast0.SizeOfExpr(szf,expb)) ->
 	      conjunct_bindings (check_mcode szf1 szf) (match_expr expa expb)
 	  | (Ast0.SizeOfType(szf1,lp1,tya,rp1),
@@ -940,27 +936,23 @@ let match_maker checks_needed context_required whencode_allowed =
 	  match (up,Ast0.unwrap d) with
 	    (Ast0.Init(stga,tya,ida,attra,eq1,inia,sc1),
 	     Ast0.Init(stgb,tyb,idb,attrb,eq,inib,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 *)
+	       if bool_match_option mcode_equal stga stgb
 	       then
 		 conjunct_many_bindings
 		   [check_mcode eq1 eq; check_mcode sc1 sc;
 		     match_option check_mcode stga stgb;
 		     match_typeC tya tyb; match_ident ida idb;
+                     match_attributes attra attrb;
 		     match_init inia inib]
 	       else return false
 	  | (Ast0.UnInit(stga,tya,ida,attra,sc1),
 	     Ast0.UnInit(stgb,tyb,idb,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 *)
+	      if bool_match_option mcode_equal stga stgb
 	      then
 		conjunct_many_bindings
 		  [check_mcode sc1 sc; match_option check_mcode stga stgb;
-		    match_typeC tya tyb; match_ident ida idb]
+		    match_typeC tya tyb; match_ident ida idb;
+                    match_attributes attra attrb]
 	      else return false
 	  | (Ast0.FunProto(fninfo1,name1,lp1,params1,va1a,rp1,sem1),
 	     Ast0.FunProto(fninfo,name,lp,params,va1b,rp,sem)) ->
@@ -973,17 +965,15 @@ let match_maker checks_needed context_required whencode_allowed =
                  ]
 	  | (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 *)
+	       if bool_match_option mcode_equal stga stgb
 	       then
 		 conjunct_many_bindings
 		   [match_ident namea nameb;
 		     check_mcode lp1 lp; check_mcode rp1 rp;
 		     check_mcode sc1 sc;
 		     match_dots match_expr is_elist_matcher do_elist_match
-		       argsa argsb]
+                       argsa argsb;
+                     match_attributes attra attrb]
 	       else return false
 	  | (Ast0.MacroDeclInit(stga,namea,lp1,argsa,rp1,eq1,ini1,sc1),
 	     Ast0.MacroDeclInit(stgb,nameb,lp,argsb,rp,eq,ini,sc)) ->
@@ -999,12 +989,10 @@ let match_maker checks_needed context_required whencode_allowed =
 		     match_init ini1 ini]
 	       else return false
 	  | (Ast0.TyDecl(tya,attra,sc1),Ast0.TyDecl(tyb,attrb,sc)) ->
-	      if (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_bindings (check_mcode sc1 sc) (match_typeC tya tyb)
-              else return false
+              conjunct_many_bindings
+                  [check_mcode sc1 sc;
+                    match_typeC tya tyb;
+                    match_attributes attra attrb]
 	  | (Ast0.Typedef(stga,tya,ida,sc1),Ast0.Typedef(stgb,tyb,idb,sc)) ->
 	      conjunct_bindings (check_mcode sc1 sc)
 		(conjunct_bindings (match_typeC tya tyb) (match_typeC ida idb))
@@ -1180,21 +1168,11 @@ let match_maker checks_needed context_required whencode_allowed =
 	then
 	  match (up,Ast0.unwrap p) with
 	    (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
+               conjunct_bindings (match_typeC tya tyb)
+                   (match_attributes attra attrb)
 	  | (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)
+	      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)) ->
@@ -1427,9 +1405,7 @@ let match_maker checks_needed context_required whencode_allowed =
 	  then conjunct_bindings (check_mcode ia ib) (loop (resta,restb))
 	  else return false
       |	(Ast0.FAttr(ia)::resta,Ast0.FAttr(ib)::restb) ->
-	  if mcode_equal ia ib
-	  then conjunct_bindings (check_mcode ia ib) (loop (resta,restb))
-	  else return false
+          conjunct_bindings (match_attributes [ia] [ib]) (loop (resta,restb))
       |	(x::resta,((y::_) as restb)) ->
 	  (match compare x y with
 	    -1 -> return false
@@ -1438,6 +1414,16 @@ let match_maker checks_needed context_required whencode_allowed =
       |	_ -> return false in
     loop (patterninfo,cinfo)
 
+  and match_attribute a1 a2 =
+    match (Ast0.unwrap a1,Ast0.unwrap a2) with
+      (Ast0.Attribute(attr1),Ast0.Attribute(attr2)) ->
+        check_mcode attr1 attr2
+
+  and match_attributes a1 a2 =
+    match_list match_attribute
+     (function _ -> false) (function _ -> failwith "")
+     a1 a2
+
   and match_case_line pattern c =
     if not(checks_needed) || not(context_required) || is_context c
     then
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 09/20] parsing_cocci: index: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (7 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 08/20] parsing_cocci: iso_pattern: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 10/20] parsing_cocci: unparse_ast0: " Jaskaran Singh
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Assign the Attribute variant an
index.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/index.ml  | 6 +++++-
 parsing_cocci/index.mli | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
index 8df048dd..cb3ac7ec 100644
--- a/parsing_cocci/index.ml
+++ b/parsing_cocci/index.ml
@@ -5,7 +5,7 @@
  *)
 
 (* create an index for each constructor *)
-(* current max is 192, also unused: 8-9, 15, 39, 40, 42, 46, 57, 65, 85-86,
+(* current max is 192, also unused: 8-9, 15, 40, 42, 46, 57, 65, 85-86,
  113-115, 140, 162 *)
 
 (* doesn't really work - requires that identical terms with no token
@@ -229,6 +229,10 @@ let string_fragment f =
   | Ast0.Strdots(dots) -> [168]
   | Ast0.MetaFormatList(pct,name,cstr,lenname) -> [169]
 
+let attribute a =
+  match Ast0.unwrap a with
+    Ast0.Attribute(attr) -> [39]
+
 let top_level t =
   match Ast0.unwrap t with
     Ast0.NONDECL(stmt) -> [90]
diff --git a/parsing_cocci/index.mli b/parsing_cocci/index.mli
index 4f86f5ba..e3c10177 100644
--- a/parsing_cocci/index.mli
+++ b/parsing_cocci/index.mli
@@ -28,4 +28,5 @@ val forinfo : Ast0_cocci.forinfo -> int list
 val pragmainfo : Ast0_cocci.pragmainfo -> int list
 val case_line : Ast0_cocci.case_line -> int list
 val string_fragment : Ast0_cocci.string_fragment -> int list
+val attribute : Ast0_cocci.attr -> int list
 val top_level : Ast0_cocci.top_level -> int list
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 10/20] parsing_cocci: unparse_ast0: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (8 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 09/20] parsing_cocci: index: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 11/20] parsing_cocci: ast0toast: " Jaskaran Singh
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
unparse_ast0.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/unparse_ast0.ml | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index 81bbb71a..109f1844 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -223,8 +223,7 @@ let rec expression e =
 	  expression exp; mcode print_string ar; ident field
       | Ast0.Cast(lp,ty,attr,rp,exp) ->
 	  mcode print_string_box lp; typeC ty; close_box();
-	  (if not (attr = []) then print_string " ");
-	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
 	  mcode print_string rp; expression exp
       | Ast0.SizeOfExpr(szf,exp) ->
 	  mcode print_string szf; expression exp
@@ -408,15 +407,13 @@ and declaration d =
       |	Ast0.Init(stg,ty,id,attr,eq,ini,sem) ->
 	  print_option (mcode U.storage) stg;
 	  print_named_type ty id;
-	  (if not (attr = []) then print_string " ");
-	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
 	  print_string " ";
 	  mcode print_string eq; print_string " "; initialiser ini;
 	  mcode print_string sem
       | Ast0.UnInit(stg,ty,id,attr,sem) ->
 	  print_option (mcode U.storage) stg; print_named_type ty id;
-	  (if not (attr = []) then print_string " ");
-	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
 	  mcode print_string sem
       | Ast0.FunProto(fninfo,name,lp1,params,va,rp1,sem) ->
 	  List.iter print_fninfo fninfo;
@@ -429,8 +426,7 @@ and declaration d =
 	  ident name; mcode print_string_box lp;
 	  let _ = dots (function _ -> ()) expression args in
 	  close_box(); mcode print_string rp;
-	  (if not (attr = []) then print_string " ");
-	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
 	  mcode print_string sem
       | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
 	  print_option (mcode U.storage) stg;
@@ -442,8 +438,7 @@ and declaration d =
 	  mcode print_string sem
       | Ast0.TyDecl(ty,attr,sem) ->
           typeC ty;
-          (if not (attr = []) then print_string " ");
-          print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
           mcode print_string sem
       | Ast0.Typedef(stg,ty,id,sem) ->
 	  mcode print_string stg; typeC ty; typeC id;
@@ -557,16 +552,13 @@ and parameterTypeDef p =
       match Ast0.unwrap p with
         Ast0.VoidParam(ty,attr) ->
           typeC ty;
-          (if (attr = []) then print_string " ");
-          print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list 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;
+          print_attribute_list attr;
       | Ast0.Param(ty,None,attr) ->
           typeC ty;
-          (if (attr = []) then print_string " ");
-          print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
       | Ast0.MetaParam(name,_,_) -> mcode print_meta name
       | Ast0.MetaParamList(name,_,_,_) -> mcode print_meta name
       | Ast0.PComma(cm) -> mcode print_string cm; print_space()
@@ -767,7 +759,15 @@ and print_fninfo = function
     Ast0.FStorage(stg) -> mcode U.storage stg
   | Ast0.FType(ty) -> typeC ty
   | Ast0.FInline(inline) -> mcode print_string inline
-  | Ast0.FAttr(attr) -> mcode print_string attr
+  | Ast0.FAttr(attr) -> print_attribute attr
+
+and print_attribute_list attrs =
+  if not (attrs = []) then print_string " ";
+  print_between (fun _ -> print_string " ") print_attribute attrs
+
+and print_attribute a =
+  match Ast0.unwrap a with
+    Ast0.Attribute(attr) -> mcode print_string attr
 
 and whencode notfn alwaysfn = function
     Ast0.WhenNot (_,_,a) ->
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 11/20] parsing_cocci: ast0toast: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (9 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 10/20] parsing_cocci: unparse_ast0: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 12/20] parsing_cocci: ast_cocci: " Jaskaran Singh
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
ast0toast.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/ast0toast.ml | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index cba32af6..f0cad067 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -441,7 +441,7 @@ and expression e =
 	Ast.RecordPtAccess(expression exp,mcode ar,ident field)
     | Ast0.Cast(lp,ty,attr,rp,exp) ->
 	let allminus = check_allminus.VT0.combiner_rec_expression e in
-	let attr = List.map mcode attr in
+	let attr = List.map attribute attr in
 	Ast.Cast(mcode lp,typeC allminus ty,attr,mcode rp,expression exp)
     | Ast0.SizeOfExpr(szf,exp) ->
 	Ast.SizeOfExpr(mcode szf,expression exp)
@@ -637,14 +637,14 @@ and declaration d =
 	let stg = get_option mcode stg in
 	let ty = typeC allminus ty in
 	let id = ident id in
-	let attr = List.map mcode attr in
+	let attr = List.map attribute attr in
 	let eq = mcode eq in
 	let ini = initialiser ini in
 	let sem = mcode sem in
 	Ast.Init(stg,ty,id,attr,eq,ini,sem)
     | Ast0.UnInit(stg,ty,id,attr,sem) ->
 	let allminus = check_allminus.VT0.combiner_rec_declaration d in
-	let attr = List.map mcode attr in
+	let attr = List.map attribute attr in
 	Ast.UnInit(get_option mcode stg,typeC allminus ty,ident id,attr,
 		   mcode sem)
     | Ast0.FunProto(fi,name,lp,params,va,rp,sem) ->
@@ -665,7 +665,7 @@ and declaration d =
 	let lp = mcode lp in
 	let args = dots expression args in
 	let rp = mcode rp in
-	let attr = List.map mcode attr in
+	let attr = List.map attribute attr in
 	let sem = mcode sem in
 	Ast.MacroDecl(stg,name,lp,args,rp,attr,sem)
     | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
@@ -681,7 +681,7 @@ and declaration d =
 	Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem)
     | Ast0.TyDecl(ty,attr,sem) ->
 	let allminus = check_allminus.VT0.combiner_rec_declaration d in
-	let attr = List.map mcode attr in
+	let attr = List.map attribute attr in
 	Ast.TyDecl(typeC allminus ty,attr,mcode sem)
     | Ast0.Typedef(stg,ty,id,sem) ->
 	let allminus = check_allminus.VT0.combiner_rec_declaration d in
@@ -861,10 +861,10 @@ and parameterTypeDef p =
   rewrap p no_isos
     (match Ast0.unwrap p with
       Ast0.VoidParam(ty,attr) ->
-        Ast.VoidParam(typeC false ty,List.map mcode attr)
+        Ast.VoidParam(typeC false ty,List.map attribute 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,List.map mcode attr)
+	Ast.Param(typeC allminus ty,get_option ident id,List.map attribute attr)
     | Ast0.MetaParam(name,cstr,_) ->
 	Ast.MetaParam(mcode name,constraints cstr,unitary,false)
     | Ast0.MetaParamList(name,lenname,cstr,_) ->
@@ -1195,7 +1195,12 @@ and fninfo = function
     Ast0.FStorage(stg) -> Ast.FStorage(mcode stg)
   | Ast0.FType(ty) -> Ast.FType(typeC false ty)
   | Ast0.FInline(inline) -> Ast.FInline(mcode inline)
-  | Ast0.FAttr(attr) -> Ast.FAttr(mcode attr)
+  | Ast0.FAttr(attr) -> Ast.FAttr(attribute attr)
+
+and attribute a =
+  rewrap a no_isos
+    (match Ast0.unwrap a with
+      Ast0.Attribute(attr) -> Ast.Attribute(mcode attr))
 
 and option_to_list = function
     Some x -> [x]
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 12/20] parsing_cocci: ast_cocci: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (10 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 11/20] parsing_cocci: ast0toast: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 13/20] parsing_cocci: visitor_ast: " Jaskaran Singh
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

SmPL attributes need to be wrapped to provide support for meta
attributes. Wrap attributes in the SmPL AST.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/ast_cocci.ml  | 5 ++++-
 parsing_cocci/ast_cocci.mli | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index 403756c4..be6731ab 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -624,7 +624,10 @@ and fninfo =
   | FInline of string mcode
   | FAttr of attr
 
-and attr = string mcode
+and base_attr =
+    Attribute of string mcode
+
+and attr = base_attr wrap
 
 and metaStmtInfo =
     NotSequencible | SequencibleAfterDots of dots_whencode list | Sequencible
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index 873e1d31..6fc961b7 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -604,7 +604,10 @@ and fninfo =
   | FInline of string mcode
   | FAttr of attr
 
-and attr = string mcode
+and base_attr =
+    Attribute of string mcode
+
+and attr = base_attr wrap
 
 and metaStmtInfo =
     NotSequencible | SequencibleAfterDots of dots_whencode list | Sequencible
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 13/20] parsing_cocci: visitor_ast: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (11 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 12/20] parsing_cocci: ast_cocci: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 14/20] parsing_cocci: get_constants2: " Jaskaran Singh
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Create a function for attributes
in the SmPL AST visitor. This function has not been added to the
visitor API yet.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/visitor_ast.ml | 48 +++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 8129bcda..d5819acf 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -201,7 +201,7 @@ let combiner bind option_default
       | Ast.Cast(lp,ty,attr,rp,exp) ->
 	  let llp = string_mcode lp in
 	  let lty = fullType ty in
-	  let lattr = multibind (List.map string_mcode attr) in
+	  let lattr = multibind (List.map attribute attr) in
 	  let lrp = string_mcode rp in
 	  let lexp = expression exp in
           multibind [llp; lty; lattr; lrp; lexp]
@@ -448,7 +448,7 @@ let combiner bind option_default
       |	Ast.Init(stg,ty,id,attr,eq,ini,sem) ->
 	  let lstg = get_option storage_mcode stg in
 	  let lid = named_type ty id in
-	  let lattr = multibind (List.map string_mcode attr) in
+	  let lattr = multibind (List.map attribute attr) in
 	  let leq = string_mcode eq in
 	  let lini = initialiser ini in
 	  let lsem = string_mcode sem in
@@ -456,7 +456,7 @@ let combiner bind option_default
       | Ast.UnInit(stg,ty,id,attr,sem) ->
 	  let lstg = get_option storage_mcode stg in
 	  let lid = named_type ty id in
-	  let lattr = multibind (List.map string_mcode attr) in
+	  let lattr = multibind (List.map attribute attr) in
 	  let lsem = string_mcode sem in
 	  multibind [lstg; lid; lattr; lsem]
       | Ast.FunProto(fi,name,lp1,params,va,rp1,sem) ->
@@ -477,7 +477,7 @@ let combiner bind option_default
 	  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 lattr = multibind (List.map attribute attr) in
 	  let lsem = string_mcode sem in
 	  multibind [lstg; lname; llp; largs; lrp; lattr; lsem]
       | Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
@@ -492,7 +492,7 @@ let combiner bind option_default
 	  multibind [lstg; lname; llp; largs; lrp; leq; lini; lsem]
       | Ast.TyDecl(ty,attr,sem) ->
 	  let lty = fullType ty in
-	  let lattr = multibind (List.map string_mcode attr) in
+	  let lattr = multibind (List.map attribute attr) in
 	  let lsem = string_mcode sem in
 	  multibind [lty; lattr; lsem]
       | Ast.Typedef(stg,ty,id,sem) ->
@@ -626,15 +626,15 @@ let combiner bind option_default
       match Ast.unwrap p with
         Ast.VoidParam(ty,attr) ->
           let lty = fullType ty in
-          let lattr = multibind (List.map string_mcode attr) in
+          let lattr = multibind (List.map attribute 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
+          let lattr = multibind (List.map attribute attr) in
           bind lid lattr
       | Ast.Param(ty,None,attr) ->
           let lty = fullType ty in
-          let lattr = multibind (List.map string_mcode attr) in
+          let lattr = multibind (List.map attribute attr) in
           bind lty lattr
       | Ast.MetaParam(name,_,_,_) -> meta_mcode name
       | Ast.MetaParamList(name,_,_,_,_) -> meta_mcode name
@@ -915,7 +915,14 @@ let combiner bind option_default
       Ast.FStorage(stg) -> storage_mcode stg
     | Ast.FType(ty) -> fullType ty
     | Ast.FInline(inline) -> string_mcode inline
-    | Ast.FAttr(attr) -> string_mcode attr
+    | Ast.FAttr(attr) -> attribute attr
+
+  and attribute a =
+    let k a =
+      match Ast.unwrap a with
+        Ast.Attribute(attr) -> string_mcode attr in
+    k a
+
 
   and whencode notfn alwaysfn = function
       Ast.WhenNot a -> notfn a
@@ -1199,7 +1206,7 @@ let rebuilder
 	| Ast.Cast(lp,ty,attr,rp,exp) ->
 	    let llp = string_mcode lp in
 	    let lty = fullType ty in
-	    let lattr = List.map string_mcode attr in
+	    let lattr = List.map attribute attr in
 	    let lrp = string_mcode rp in
 	    let lexp = expression exp in
 	    Ast.Cast(llp, lty, lattr, lrp, lexp)
@@ -1406,7 +1413,7 @@ let rebuilder
 	    let lstg = get_option storage_mcode stg in
 	    let lty = fullType ty in
 	    let lid = ident id in
-	    let lattr = List.map string_mcode attr in
+	    let lattr = List.map attribute attr in
 	    let leq = string_mcode eq in
 	    let lini = initialiser ini in
 	    let lsem = string_mcode sem in
@@ -1415,7 +1422,7 @@ let rebuilder
 	    let lstg = get_option storage_mcode stg in
 	    let lty = fullType ty in
 	    let lid = ident id in
-	    let lattr = List.map string_mcode attr in
+	    let lattr = List.map attribute attr in
 	    let lsem = string_mcode sem in
 	    Ast.UnInit(lstg, lty, lid, lattr, lsem)
 	| Ast.FunProto(fi,name,lp,params,va,rp,sem) ->
@@ -1436,7 +1443,7 @@ let rebuilder
 	    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 lattr = List.map attribute attr in
 	    let lsem = string_mcode sem in
 	    Ast.MacroDecl(lstg, lname, llp, largs, lrp, lattr, lsem)
 	| Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
@@ -1451,7 +1458,7 @@ let rebuilder
 	    Ast.MacroDeclInit(lstg, lname, llp, largs, lrp, leq, lini, lsem)
 	| Ast.TyDecl(ty,attr,sem) ->
 	    let lty = fullType ty in
-	    let lattr = List.map string_mcode attr in
+	    let lattr = List.map attribute attr in
 	    let lsem = string_mcode sem in
 	    Ast.TyDecl(lty, lattr, lsem)
 	| Ast.Typedef(stg,ty,id,sem) ->
@@ -1598,10 +1605,10 @@ let rebuilder
       Ast.rewrap p
 	(match Ast.unwrap p with
 	  Ast.VoidParam(ty,attr) ->
-            Ast.VoidParam(fullType ty,List.map string_mcode attr)
+            Ast.VoidParam(fullType ty,List.map attribute attr)
 	| Ast.Param(ty,id,attr) ->
             Ast.Param
-              (fullType ty, get_option ident id,List.map string_mcode attr)
+              (fullType ty, get_option ident id,List.map attribute attr)
 	| Ast.MetaParam(name,constraints,keep,inherited) ->
 	    Ast.MetaParam(meta_mcode name,constraints,keep,inherited)
 	| Ast.MetaParamList(name,lenname_inh,constraints,keep,inherited) ->
@@ -1902,7 +1909,14 @@ let rebuilder
       Ast.FStorage(stg) -> Ast.FStorage(storage_mcode stg)
     | Ast.FType(ty) -> Ast.FType(fullType ty)
     | Ast.FInline(inline) -> Ast.FInline(string_mcode inline)
-    | Ast.FAttr(attr) -> Ast.FAttr(string_mcode attr)
+    | Ast.FAttr(attr) -> Ast.FAttr(attribute attr)
+
+  and attribute a =
+    let k a =
+      Ast.rewrap a
+        (match Ast.unwrap a with
+          Ast.Attribute(attr) -> Ast.Attribute(string_mcode attr)) in
+    k a
 
   and whencode notfn alwaysfn = function
       Ast.WhenNot a -> Ast.WhenNot (notfn a)
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 14/20] parsing_cocci: get_constants2: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (12 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 13/20] parsing_cocci: visitor_ast: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 15/20] parsing_cocci: safe_for_multi_decls: " Jaskaran Singh
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
get_constants2.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/get_constants2.ml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml
index 76d6d40b..d1d77f65 100644
--- a/parsing_cocci/get_constants2.ml
+++ b/parsing_cocci/get_constants2.ml
@@ -529,6 +529,10 @@ let do_get_constants constants keywords env (neg_pos,_) =
     | Ast.MetaType(name,_,_,_) -> bind (minherited name) (k ty)
     | _ -> k ty in
 
+  let attribute a =
+    match Ast.unwrap a with
+      Ast.Attribute(attr) -> Ast.unwrap_mcode attr in
+
   let declaration r k d =
     match Ast.unwrap d with
       Ast.MetaDecl(name,_,_,_) ->
@@ -539,7 +543,7 @@ let do_get_constants constants keywords env (neg_pos,_) =
     (* need things with explicit names too *)
     | Ast.Init(_,_,_,attr,_,_,_) | Ast.UnInit(_,_,_,attr,_) ->
 	List.fold_left bind (k d)
-	  (List.map (fun attr -> constants (Ast.unwrap_mcode attr)) attr)
+	  (List.map (fun attr -> constants (attribute attr)) attr)
     | _ -> k d in
 
   let field r k d =
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 15/20] parsing_cocci: safe_for_multi_decls: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (13 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 14/20] parsing_cocci: get_constants2: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 16/20] parsing_cocci: unify_ast: " Jaskaran Singh
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
safe_for_multi_decls.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/safe_for_multi_decls.ml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/safe_for_multi_decls.ml b/parsing_cocci/safe_for_multi_decls.ml
index 8fc49432..70335abb 100644
--- a/parsing_cocci/safe_for_multi_decls.ml
+++ b/parsing_cocci/safe_for_multi_decls.ml
@@ -103,6 +103,10 @@ let contains_modif =
       do_nothing in
   recursor.V.combiner_fullType
 
+let attribute a =
+  match Ast.unwrap a with
+    Ast.Attribute(attr) -> mcode () attr
+
 let decl r k e =
   let e = k e in
   match all_removed_decl e with
@@ -116,7 +120,7 @@ let decl r k e =
 	    match stg with
 	      Some stg -> mcode () stg
 	    | None -> false in
-	  let attr_modif = List.exists (mcode ()) attr in
+	  let attr_modif = List.exists attribute attr in
 	  let ft_modif = contains_modif ty in
 	  let sem_modif = mcode () sem in
 	  if not(stg_modif || attr_modif || ft_modif || sem_modif)
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 16/20] parsing_cocci: unify_ast: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (14 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 15/20] parsing_cocci: safe_for_multi_decls: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 17/20] parsing_cocci: pretty_print_cocci: " Jaskaran Singh
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
unify_ast.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/unify_ast.ml | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml
index 788c8fdc..90cb70ee 100644
--- a/parsing_cocci/unify_ast.ml
+++ b/parsing_cocci/unify_ast.ml
@@ -221,7 +221,7 @@ and unify_expression e1 e2 =
   | (Ast.RecordPtAccess(e1,pt1,fld1),Ast.RecordPtAccess(e2,pt2,fld2)) ->
       unify_expression e1 e2 && unify_ident fld1 fld2
   | (Ast.Cast(lp1,ty1,attr1,rp1,e1),Ast.Cast(lp2,ty2,attr2,rp2,e2)) ->
-      if List.for_all2 unify_mcode attr1 attr2
+      if List.for_all2 unify_attribute attr1 attr2
       then unify_fullType ty1 ty2 && unify_expression e1 e2
       else false
   | (Ast.SizeOfExpr(szf1,e1),Ast.SizeOfExpr(szf2,e2)) ->
@@ -386,7 +386,7 @@ and unify_declaration d1 d2 =
   | (Ast.Init(stg1,ft1,id1,attr1,eq1,i1,s1),
      Ast.Init(stg2,ft2,id2,attr2,eq2,i2,s2)) ->
       if bool_unify_option unify_mcode stg1 stg2 &&
-         List.for_all2 unify_mcode attr1 attr2
+         List.for_all2 unify_attribute attr1 attr2
       then
 	unify_fullType ft1 ft2 &&
 	unify_ident id1 id2 &&
@@ -394,7 +394,7 @@ and unify_declaration d1 d2 =
       else false
   | (Ast.UnInit(stg1,ft1,id1,attr1,s1),Ast.UnInit(stg2,ft2,id2,attr2,s2)) ->
       if bool_unify_option unify_mcode stg1 stg2 &&
-         List.for_all2 unify_mcode attr1 attr2
+         List.for_all2 unify_attribute attr1 attr2
       then unify_fullType ft1 ft2 && unify_ident id1 id2
       else false
   | (Ast.FunProto(fi1,nm1,lp1,params1,va1,rp1,sem1),
@@ -414,7 +414,7 @@ and unify_declaration d1 d2 =
   | (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 &&
-         List.for_all2 unify_mcode attr1 attr2
+         List.for_all2 unify_attribute attr1 attr2
        then
 	 unify_ident n1 n2 &&
 	 unify_dots unify_expression edots args1 args2
@@ -428,7 +428,7 @@ and unify_declaration d1 d2 =
 	 unify_initialiser ini1 ini2
        else false
   | (Ast.TyDecl(ft1,attr1,s1),Ast.TyDecl(ft2,attr2,s2)) ->
-      if List.for_all2 unify_mcode attr1 attr2
+      if List.for_all2 unify_attribute attr1 attr2
       then unify_fullType ft1 ft2
       else false
   | (Ast.Typedef(stg1,ft1,id1,s1),Ast.Typedef(stg2,ft2,id2,s2)) ->
@@ -549,12 +549,12 @@ and unify_designator d1 d2 =
 and unify_parameterTypeDef p1 p2 =
   match (Ast.unwrap p1,Ast.unwrap p2) with
     (Ast.VoidParam(ft1,attr1),Ast.VoidParam(ft2,attr2)) ->
-      if List.for_all2 unify_mcode attr1 attr2
+      if List.for_all2 unify_attribute 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
+      if List.for_all2 unify_attribute attr1 attr2
       then
         unify_fullType ft1 ft2 &&
         unify_option unify_ident i1 i2
@@ -704,7 +704,7 @@ and unify_fninfo patterninfo cinfo =
     | (Ast.FInline(ia)::resta,Ast.FInline(ib)::restb) ->
 	if unify_mcode ia ib then loop (resta,restb) else false
     | (Ast.FAttr(ia)::resta,Ast.FAttr(ib)::restb) ->
-	if unify_mcode ia ib then loop (resta,restb) else false
+	if unify_attribute ia ib then loop (resta,restb) else false
     | (x::resta,((y::_) as restb)) ->
 	(match compare x y with
 	  -1 -> false
@@ -713,6 +713,11 @@ and unify_fninfo patterninfo cinfo =
     | _ -> false in
   loop (patterninfo,cinfo)
 
+and unify_attribute attr1 attr2 =
+  match (Ast.unwrap attr1,Ast.unwrap attr2) with
+    (Ast.Attribute(attr1),Ast.Attribute(attr2)) ->
+      unify_mcode attr1 attr2
+
 and unify_exec_code ec1 ec2 =
   match (Ast.unwrap ec1,Ast.unwrap ec2) with
     (Ast.ExecEval(colon1,id1),Ast.ExecEval(colon2,id2)) ->
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 17/20] parsing_cocci: pretty_print_cocci: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (15 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 16/20] parsing_cocci: unify_ast: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 18/20] parsing_c: unparse_cocci: " Jaskaran Singh
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
pretty_print_cocci.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/pretty_print_cocci.ml | 34 ++++++++++++++---------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml
index aaea3f9d..1ac6d743 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -251,8 +251,7 @@ let rec expression e =
       expression exp; mcode print_string ar; ident field
   | Ast.Cast(lp,ty,attr,rp,exp) ->
       mcode print_string_box lp; fullType ty; close_box();
-      (if not (attr = []) then print_string " ");
-      print_between print_space (mcode print_string) attr;
+      print_attribute_list attr;
       mcode print_string rp; expression exp
   | Ast.SizeOfExpr(sizeof,exp) ->
       mcode print_string sizeof; expression exp
@@ -450,7 +449,15 @@ and print_fninfo = function
     Ast.FStorage(stg) -> mcode storage stg
   | Ast.FType(ty) -> fullType ty
   | Ast.FInline(inline) -> mcode print_string inline; print_string " "
-  | Ast.FAttr(attr) -> mcode print_string attr; print_string " "
+  | Ast.FAttr(attr) -> print_attribute attr; print_string " "
+
+and print_attribute_list attrs =
+  if not (attrs = []) then print_string " ";
+  print_between print_space print_attribute attrs
+
+and print_attribute attr =
+  match Ast.unwrap attr with
+    Ast.Attribute(a) -> mcode print_string a
 
 and typeC ty =
   match Ast.unwrap ty with
@@ -551,15 +558,13 @@ and declaration d =
   | Ast.Init(stg,ty,id,attr,eq,ini,sem) ->
       print_option (mcode storage) stg;
       print_named_type ty (fun _ -> ident id);
-      (if not (attr = []) then print_string " ");
-      print_between print_space (mcode print_string) attr;
+      print_attribute_list attr;
       print_string " "; mcode print_string eq;
       print_string " "; initialiser ini; mcode print_string sem
   | Ast.UnInit(stg,ty,id,attr,sem) ->
       print_option (mcode storage) stg;
       print_named_type ty (fun _ -> ident id);
-      (if not (attr = []) then print_string " ");
-      print_between print_space (mcode print_string) attr;
+      print_attribute_list attr;
       mcode print_string sem
   | Ast.FunProto (fninfo,name,lp1,params,va,rp1,sem) ->
       List.iter print_fninfo fninfo;
@@ -571,8 +576,7 @@ and declaration d =
       print_option (mcode storage) stg; ident name; mcode print_string_box lp;
       dots (function _ -> ()) expression args;
       close_box(); mcode print_string rp;
-      (if not (attr = []) then print_string " ");
-      print_between print_space (mcode print_string) attr;
+      print_attribute_list 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;
@@ -582,8 +586,7 @@ and declaration d =
       print_string " "; initialiser ini; mcode print_string sem
   | Ast.TyDecl(ty,attr,sem) ->
       fullType ty;
-      (if not (attr = []) then print_string " ");
-      print_between print_space (mcode print_string) attr;
+      print_attribute_list attr;
       mcode print_string sem
   | Ast.Typedef(stg,ty,id,sem) ->
       mcode print_string stg; print_string " ";
@@ -699,16 +702,13 @@ and parameterTypeDef p =
   match Ast.unwrap p with
     Ast.VoidParam(ty,attr) ->
       fullType ty;
-      (if not (attr = []) then print_string " ");
-      print_between print_space (mcode print_string) attr
+      print_attribute_list 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
+      print_attribute_list attr
   | Ast.Param(ty,None,attr) ->
       fullType ty;
-      (if not (attr = []) then print_string " ");
-      print_between print_space (mcode print_string) attr
+      print_attribute_list 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.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 18/20] parsing_c: unparse_cocci: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (16 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 17/20] parsing_cocci: pretty_print_cocci: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 19/20] engine: cocci_vs_c: " Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 20/20] ocaml: coccilib: " Jaskaran Singh
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
unparse_cocci.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_c/unparse_cocci.ml | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index f0efc968..6d437971 100644
--- a/parsing_c/unparse_cocci.ml
+++ b/parsing_c/unparse_cocci.ml
@@ -505,8 +505,7 @@ let rec expression e =
       loop exp postfix; mcode print_string ar; ident field
   | Ast.Cast(lp,ty,attr,rp,exp) ->
       mcode print_string_box lp; fullType ty; close_box();
-      (if not (attr = []) then pr_space());
-      print_between pr_space (mcode print_string) attr;
+      print_attribute_list attr;
       mcode print_string rp; loop exp cast
   | Ast.SizeOfExpr(sizeof,exp) ->
       mcode print_string sizeof; loop exp unary
@@ -706,7 +705,15 @@ and print_fninfo = function
     Ast.FStorage(stg) -> mcode storage stg
   | Ast.FType(ty) -> fullType ty
   | Ast.FInline(inline) -> mcode print_string inline; pr_space()
-  | Ast.FAttr(attr) -> mcode print_string attr; pr_space()
+  | Ast.FAttr(attr) -> print_attribute attr; pr_space()
+
+and print_attribute_list attrs =
+  if not (attrs = []) then pr_space();
+  print_between pr_space print_attribute attrs
+
+and print_attribute attr =
+  match Ast.unwrap attr with
+    Ast.Attribute(a) -> mcode print_string a
 
 and typeC ty =
   match Ast.unwrap ty with
@@ -915,16 +922,14 @@ and declaration d =
       print_option (mcode storage) stg;
       print_option (function _ -> pr_space()) stg;
       print_named_type ty (fun _ -> ident id);
-      (if not (attr = []) then pr_space());
-      print_between pr_space (mcode print_string) attr;
+      print_attribute_list attr;
       pr_space(); mcode print_string eq;
       pr_space(); initialiser true ini; mcode print_string sem
   | Ast.UnInit(stg,ty,id,attr,sem) ->
       print_option (mcode storage) stg;
       print_option (function _ -> pr_space()) stg;
       print_named_type ty (fun _ -> ident id);
-      (if not (attr = []) then pr_space());
-      print_between pr_space (mcode print_string) attr;
+      print_attribute_list attr;
       mcode print_string sem
   | Ast.FunProto (fninfo,name,lp1,params,va,rp1,sem) ->
       List.iter print_fninfo fninfo;
@@ -944,8 +949,7 @@ and declaration d =
       ident name; mcode print_string_box lp;
       dots (function _ -> ()) arg_expression args;
       close_box(); mcode print_string rp;
-      (if not (attr = []) then pr_space());
-      print_between pr_space (mcode print_string) attr;
+      print_attribute_list attr;
       mcode print_string sem
   | Ast.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
       print_option (mcode storage) stg;
@@ -957,8 +961,7 @@ and declaration d =
       pr_space(); initialiser true ini; mcode print_string sem
   | Ast.TyDecl(ty,attr,sem) ->
       fullType ty;
-      (if not (attr = []) then pr_space());
-      print_between pr_space (mcode print_string) attr;
+      print_attribute_list attr;
       mcode print_string sem
   | Ast.Typedef(stg,ty,id,sem) ->
       mcode print_string stg; pr_space();
@@ -1100,16 +1103,13 @@ and parameterTypeDef p =
   match Ast.unwrap p with
     Ast.VoidParam(ty,attr) ->
       fullType ty;
-      (if not (attr = []) then pr_space());
-      print_between pr_space (mcode print_string) attr;
+      print_attribute_list 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;
+      print_attribute_list attr;
   | Ast.Param(ty,None,attr) ->
       fullType ty;
-      (if not (attr = []) then pr_space());
-      print_between pr_space (mcode print_string) attr;
+      print_attribute_list attr;
   | Ast.MetaParam(name,_,_,_) ->
       handle_metavar name
 	(function
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 19/20] engine: cocci_vs_c: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (17 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 18/20] parsing_c: unparse_cocci: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  2020-07-03 17:59 ` [Cocci] [PATCH 20/20] ocaml: coccilib: " Jaskaran Singh
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
cocci_vs_c.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 engine/cocci_vs_c.ml | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index 7abc4d53..3199d54d 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -1529,11 +1529,12 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) =
     ((B.Cast (typb, attrsb, eb), typ),ii) ->
 
       let attr_allminus =
-        let mcode_is_not_context = function
-          | (_,_,A.CONTEXT(_,_),_) -> false
+        let attr_is_not_context a =
+          match A.unwrap a with
+          | A.Attribute(_,_,A.CONTEXT(_,_),_) -> false
           | _ -> true in
         check_allminus.Visitor_ast.combiner_fullType typa &&
-        List.for_all mcode_is_not_context attrsa in
+        List.for_all attr_is_not_context attrsa in
 
       let (ib1, ib2) = tuple_of_list2 ii in
       fullType typa typb >>= (fun typa typb ->
@@ -4265,8 +4266,8 @@ and attribute_list allminus attras attrbs =
   | _ -> failwith "only one attribute allowed in SmPL")
 
 and attribute = fun allminus ea eb ->
-  match ea, eb with
-    attra, (B.Attribute attrb, ii)
+  match A.unwrap ea, eb with
+    A.Attribute(attra), (B.Attribute attrb, ii)
       when (A.unwrap_mcode attra) = attrb ->
       let ib1 = tuple_of_list1 ii in
       tokenf attra ib1 >>= (fun attra ib1 ->
@@ -4274,7 +4275,7 @@ and attribute = fun allminus ea eb ->
         then minusize_list [ib1]
         else return ((), [ib1])) >>= (fun _ ib1 ->
 	return (
-	  attra,
+	  A.rewrap ea (A.Attribute(attra)),
           (B.Attribute attrb,ib1)
         )))
   | _ -> fail
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 20/20] ocaml: coccilib: Wrap SmPL Attributes
  2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
                   ` (18 preceding siblings ...)
  2020-07-03 17:59 ` [Cocci] [PATCH 19/20] engine: cocci_vs_c: " Jaskaran Singh
@ 2020-07-03 17:59 ` Jaskaran Singh
  19 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-03 17:59 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
coccilib.mli.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 ocaml/coccilib.mli | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 24b5f1ae..010b8aab 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -2925,7 +2925,10 @@ module Ast_cocci :
       | FType of fullType
       | FInline of string mcode
       | FAttr of attr
-    and attr = string mcode
+    and base_attr =
+      Ast_cocci.base_attr =
+        Attribute of string mcode
+    and attr = base_attr wrap
     and metaStmtInfo =
       Ast_cocci.metaStmtInfo =
         NotSequencible
@@ -3553,7 +3556,10 @@ module Ast0_cocci :
       | FType of typeC
       | FInline of string mcode
       | FAttr of attr
-    and attr = string mcode
+    and base_attr =
+      Ast0_cocci.base_attr =
+        Attribute of string mcode
+    and attr = base_attr wrap
     and ('a, 'b) whencode =
       ('a, 'b) Ast0_cocci.whencode =
         WhenNot of string mcode * string mcode * 'a
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [Cocci] [PATCH 02/20] parsing_cocci: parser: Wrap SmPL Attributes
  2020-07-03 17:59 ` [Cocci] [PATCH 02/20] parsing_cocci: parser: " Jaskaran Singh
@ 2020-07-06 20:03   ` Julia Lawall
  2020-07-07  9:51     ` Jaskaran Singh
  0 siblings, 1 reply; 25+ messages in thread
From: Julia Lawall @ 2020-07-06 20:03 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: cocci



On Fri, 3 Jul 2020, Jaskaran Singh wrote:

> Attributes are wrapped in the SmPL AST. Reciprocate this and wrap
> attributes in the SmPL parser.

This doesn't apply for me.

julia


>
> Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
> ---
>  parsing_cocci/parse_aux.ml            |  3 +++
>  parsing_cocci/parse_aux.mli           |  7 +++++++
>  parsing_cocci/parser_cocci_menhir.mly | 18 ++++++++++--------
>  3 files changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/parsing_cocci/parse_aux.ml b/parsing_cocci/parse_aux.ml
> index b5d1afb4..f2036bfc 100644
> --- a/parsing_cocci/parse_aux.ml
> +++ b/parsing_cocci/parse_aux.ml
> @@ -152,6 +152,9 @@ let logic_op ast_op left op right =
>  let make_cv cv ty =
>    match cv with None -> ty | Some x -> Ast0.wrap (Ast0.ConstVol(x,ty))
>
> +let make_attr attr =
> +  Ast0.wrap(Ast0.Attribute(id2mcode attr))
> +
>  let top_dots l = Ast0.wrap l
>
>  (* here the offset is that of the first in the sequence of *s, not that of
> diff --git a/parsing_cocci/parse_aux.mli b/parsing_cocci/parse_aux.mli
> index 91d7cb26..0ecf10b0 100644
> --- a/parsing_cocci/parse_aux.mli
> +++ b/parsing_cocci/parse_aux.mli
> @@ -151,6 +151,13 @@ val logic_op :
>    string -> Ast0_cocci.expression -> Ast0_cocci.base_expression Ast0_cocci.wrap
>  val make_cv :
>    Ast_cocci.const_vol Ast0_cocci.mcode option -> Ast0_cocci.typeC -> Ast0_cocci.typeC
> +val make_attr:
> +  string *
> +  (Data.line_type * int * int * int * int * int *
> +   (Ast_cocci.added_string * Ast0_cocci.position_info) list *
> +   (Ast_cocci.added_string * Ast0_cocci.position_info) list *
> +   Ast0_cocci.anything list * string) ->
> +   Ast0_cocci.attr
>  val top_dots : 'a -> 'a Ast0_cocci.wrap
>  val pointerify :
>    Ast0_cocci.typeC ->
> diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
> index 63cb8b5e..32bcd63c 100644
> --- a/parsing_cocci/parser_cocci_menhir.mly
> +++ b/parsing_cocci/parser_cocci_menhir.mly
> @@ -1495,11 +1495,11 @@ fninfo:
>  	let _ = List.find (function Ast0.FInline(_) -> true | _ -> false) $2 in
>  	raise (Semantic_cocci.Semantic "duplicate inline")
>        with Not_found -> (Ast0.FInline(P.clt2mcode "inline" $1))::$2 }
> -  | Tattr    fninfo
> +  | a=Tattr    fninfo
>        { try
>  	let _ = List.find (function Ast0.FAttr(_) -> true | _ -> false) $2 in
>  	raise (Semantic_cocci.Semantic "multiple attributes")
> -      with Not_found -> (Ast0.FAttr(P.id2mcode $1))::$2 }
> +      with Not_found -> (Ast0.FAttr(P.make_attr a))::$2 }
>
>  fninfo_nt:
>      /* empty */ { [] }
> @@ -1514,11 +1514,11 @@ fninfo_nt:
>  	let _ = List.find (function Ast0.FInline(_) -> true | _ -> false) $2 in
>  	raise (Semantic_cocci.Semantic "duplicate inline")
>        with Not_found -> (Ast0.FInline(P.clt2mcode "inline" $1))::$2 }
> -  | Tattr    fninfo_nt
> +  | a=Tattr    fninfo_nt
>        { try
>  	let _ = List.find (function Ast0.FAttr(_) -> true | _ -> false) $2 in
>  	raise (Semantic_cocci.Semantic "duplicate init")
> -      with Not_found -> (Ast0.FAttr(P.id2mcode $1))::$2 }
> +      with Not_found -> (Ast0.FAttr(P.make_attr a))::$2 }
>
>  storage:
>           s=Tstatic      { P.clt2mcode Ast.Static s }
> @@ -3227,12 +3227,14 @@ script_virt_name_decl:
>
>  %inline
>  attr_list:
> -                        { [] }
> - | a=Tattr f=full_attr_list {P.id2mcode a::f}
> +                           { [] }
> + | Tattr f=full_attr_list
> +    { let a = P.make_attr $1 in a::f }
>
>  full_attr_list:
> -                        { [] }
> - | Tattr full_attr_list {P.id2mcode $1::$2}
> +                           { [] }
> + | Tattr f=full_attr_list
> +    { let a = P.make_attr $1 in a::f }
>
>  anything: /* used for script code */
>     TIdentifier { "identifier" }
> --
> 2.21.3
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Cocci] [PATCH 05/20] parsing_cocci: arity: Wrap SmPL Attributes
  2020-07-03 17:59 ` [Cocci] [PATCH 05/20] parsing_cocci: arity: " Jaskaran Singh
@ 2020-07-06 20:04   ` Julia Lawall
  0 siblings, 0 replies; 25+ messages in thread
From: Julia Lawall @ 2020-07-06 20:04 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: cocci



On Fri, 3 Jul 2020, Jaskaran Singh wrote:

> Attributes are wrapped in the SmPL AST. Reflect these changes in
> arity.ml.

This gives some space before tab errors.

julia

>
> Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
> ---
>  parsing_cocci/arity.ml | 67 +++++++++++++++++++-----------------------
>  1 file changed, 31 insertions(+), 36 deletions(-)
>
> diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
> index 3bbecedf..524f8994 100644
> --- a/parsing_cocci/arity.ml
> +++ b/parsing_cocci/arity.ml
> @@ -256,10 +256,10 @@ let rec top_expression opt_allowed tgt expr =
>        make_exp expr tgt arity (Ast0.RecordPtAccess(exp,ar,field))
>    | Ast0.Cast(lp,ty,attr,rp,exp) ->
>        let arity =
> -        exp_same (mcode2line lp) (List.map mcode2arity ([lp] @ attr @ [rp])) in
> +        exp_same (mcode2line lp) (List.map mcode2arity ([lp;rp])) in
>        let lp = mcode lp in
>        let ty = typeC arity ty in
> -      let attr = List.map mcode attr in
> +      let attr = List.map attribute attr in
>        let rp = mcode rp in
>        let exp = expression arity exp in
>        make_exp expr tgt arity (Ast0.Cast(lp,ty,attr,rp,exp))
> @@ -564,7 +564,7 @@ and declaration tgt decl =
>        let stg = get_option mcode stg in
>        let ty = typeC arity ty in
>        let id = ident false arity id in
> -      let attr = List.map mcode attr in
> +      let attr = List.map attribute attr in
>        let eq = mcode eq in
>        let exp = initialiser arity exp in
>        let sem = mcode sem in
> @@ -577,7 +577,7 @@ and declaration tgt decl =
>        let stg = get_option mcode stg in
>        let ty = typeC arity ty in
>        let id = ident false arity id in
> -      let attr = List.map mcode attr in
> +      let attr = List.map attribute attr in
>        let sem = mcode sem in
>        make_decl decl tgt arity (Ast0.UnInit(stg,ty,id,attr,sem))
>    | Ast0.FunProto(fi,name,lp1,params,va,rp1,sem) ->
> @@ -601,13 +601,13 @@ 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] @ attr @ [sem]))) in
> +	   (List.map mcode2arity ([lp;rp;sem]))) in
>        let stg = get_option mcode stg in
>        let name = ident false arity name in
>        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 attr = List.map attribute attr in
>        let sem = mcode sem in
>        make_decl decl tgt arity (Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem))
>    | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
> @@ -627,9 +627,9 @@ and declaration tgt decl =
>    | Ast0.TyDecl(ty,attr,sem) ->
>        let arity =
>          all_same true tgt
> -          (mcode2line sem) (List.map mcode2arity (attr @ [sem])) in
> +          (mcode2line sem) [mcode2arity sem] in
>        let ty = typeC arity ty in
> -      let attr = List.map mcode attr in
> +      let attr = List.map attribute attr in
>        let sem = mcode sem in
>        make_decl decl tgt arity (Ast0.TyDecl(ty,attr,sem))
>    | Ast0.Typedef(stg,ty,id,sem) ->
> @@ -816,40 +816,30 @@ 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) ->
> -      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.rewrap param (Ast0.VoidParam(typeC tgt ty,List.map attribute 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
> -      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) in
> -      make_param_attr param tgt ret attr
> +      let attr = List.map attribute 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,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,None,attr) ->
>        let ty = top_typeC tgt true ty in
> -      let attr = List.map mcode attr in
> -      let ret =
> -	match Ast0.unwrap ty with
> -	  Ast0.OptType(ty) ->
> +      let attr = List.map attribute attr in
> +      Ast0.rewrap param
> +        (match Ast0.unwrap ty with
> +          Ast0.OptType(ty) ->
>  	    Ast0.OptParam(Ast0.rewrap param (Ast0.Param(ty,None,attr)))
> -	| _ -> Ast0.Param(ty,None,attr) in
> -      make_param_attr param tgt ret 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
> @@ -1272,7 +1262,7 @@ and fninfo arity = function
>      Ast0.FStorage(stg) -> Ast0.FStorage(mcode stg)
>    | Ast0.FType(ty) -> Ast0.FType(typeC arity ty)
>    | Ast0.FInline(inline) -> Ast0.FInline(mcode inline)
> -  | Ast0.FAttr(attr) -> Ast0.FAttr(mcode attr)
> +  | Ast0.FAttr(attr) -> Ast0.FAttr(attribute attr)
>
>  and fninfo2arity fninfo =
>    List.concat
> @@ -1281,9 +1271,14 @@ and fninfo2arity fninfo =
>  	   Ast0.FStorage(stg) -> [mcode2arity stg]
>  	 | Ast0.FType(ty) -> []
>  	 | Ast0.FInline(inline) -> [mcode2arity inline]
> -	 | Ast0.FAttr(attr) -> [mcode2arity attr])
> +	 | Ast0.FAttr(attr) -> [])
>         fninfo)
>
> +and attribute attr =
> +  match Ast0.unwrap attr with
> +    Ast0.Attribute(a) ->
> +      Ast0.rewrap attr (Ast0.Attribute(mcode a))
> +
>  and whencode notfn alwaysfn expression = function
>      Ast0.WhenNot (w,e,a) -> Ast0.WhenNot (w,e,notfn a)
>    | Ast0.WhenAlways (w,e,a) -> Ast0.WhenAlways (w,e,alwaysfn a)
> --
> 2.21.3
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [Cocci] [PATCH 02/20] parsing_cocci: parser: Wrap SmPL Attributes
  2020-07-06 20:03   ` Julia Lawall
@ 2020-07-07  9:51     ` Jaskaran Singh
  0 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-07  9:51 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Mon, 2020-07-06 at 22:03 +0200, Julia Lawall wrote:
> 
> On Fri, 3 Jul 2020, Jaskaran Singh wrote:
> 
> > Attributes are wrapped in the SmPL AST. Reciprocate this and wrap
> > attributes in the SmPL parser.
> 
> This doesn't apply for me.
> 

Ah, I missed the recent changes to the parser. I'll send a v2.

Cheers,
Jaskaran.

> julia
> 
> 
> > Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
> > ---
> >  parsing_cocci/parse_aux.ml            |  3 +++
> >  parsing_cocci/parse_aux.mli           |  7 +++++++
> >  parsing_cocci/parser_cocci_menhir.mly | 18 ++++++++++--------
> >  3 files changed, 20 insertions(+), 8 deletions(-)
> > 
> > diff --git a/parsing_cocci/parse_aux.ml
> > b/parsing_cocci/parse_aux.ml
> > index b5d1afb4..f2036bfc 100644
> > --- a/parsing_cocci/parse_aux.ml
> > +++ b/parsing_cocci/parse_aux.ml
> > @@ -152,6 +152,9 @@ let logic_op ast_op left op right =
> >  let make_cv cv ty =
> >    match cv with None -> ty | Some x -> Ast0.wrap
> > (Ast0.ConstVol(x,ty))
> > 
> > +let make_attr attr =
> > +  Ast0.wrap(Ast0.Attribute(id2mcode attr))
> > +
> >  let top_dots l = Ast0.wrap l
> > 
> >  (* here the offset is that of the first in the sequence of *s, not
> > that of
> > diff --git a/parsing_cocci/parse_aux.mli
> > b/parsing_cocci/parse_aux.mli
> > index 91d7cb26..0ecf10b0 100644
> > --- a/parsing_cocci/parse_aux.mli
> > +++ b/parsing_cocci/parse_aux.mli
> > @@ -151,6 +151,13 @@ val logic_op :
> >    string -> Ast0_cocci.expression -> Ast0_cocci.base_expression
> > Ast0_cocci.wrap
> >  val make_cv :
> >    Ast_cocci.const_vol Ast0_cocci.mcode option -> Ast0_cocci.typeC
> > -> Ast0_cocci.typeC
> > +val make_attr:
> > +  string *
> > +  (Data.line_type * int * int * int * int * int *
> > +   (Ast_cocci.added_string * Ast0_cocci.position_info) list *
> > +   (Ast_cocci.added_string * Ast0_cocci.position_info) list *
> > +   Ast0_cocci.anything list * string) ->
> > +   Ast0_cocci.attr
> >  val top_dots : 'a -> 'a Ast0_cocci.wrap
> >  val pointerify :
> >    Ast0_cocci.typeC ->
> > diff --git a/parsing_cocci/parser_cocci_menhir.mly
> > b/parsing_cocci/parser_cocci_menhir.mly
> > index 63cb8b5e..32bcd63c 100644
> > --- a/parsing_cocci/parser_cocci_menhir.mly
> > +++ b/parsing_cocci/parser_cocci_menhir.mly
> > @@ -1495,11 +1495,11 @@ fninfo:
> >  	let _ = List.find (function Ast0.FInline(_) -> true | _ ->
> > false) $2 in
> >  	raise (Semantic_cocci.Semantic "duplicate inline")
> >        with Not_found -> (Ast0.FInline(P.clt2mcode "inline"
> > $1))::$2 }
> > -  | Tattr    fninfo
> > +  | a=Tattr    fninfo
> >        { try
> >  	let _ = List.find (function Ast0.FAttr(_) -> true | _ -> false)
> > $2 in
> >  	raise (Semantic_cocci.Semantic "multiple attributes")
> > -      with Not_found -> (Ast0.FAttr(P.id2mcode $1))::$2 }
> > +      with Not_found -> (Ast0.FAttr(P.make_attr a))::$2 }
> > 
> >  fninfo_nt:
> >      /* empty */ { [] }
> > @@ -1514,11 +1514,11 @@ fninfo_nt:
> >  	let _ = List.find (function Ast0.FInline(_) -> true | _ ->
> > false) $2 in
> >  	raise (Semantic_cocci.Semantic "duplicate inline")
> >        with Not_found -> (Ast0.FInline(P.clt2mcode "inline"
> > $1))::$2 }
> > -  | Tattr    fninfo_nt
> > +  | a=Tattr    fninfo_nt
> >        { try
> >  	let _ = List.find (function Ast0.FAttr(_) -> true | _ -> false)
> > $2 in
> >  	raise (Semantic_cocci.Semantic "duplicate init")
> > -      with Not_found -> (Ast0.FAttr(P.id2mcode $1))::$2 }
> > +      with Not_found -> (Ast0.FAttr(P.make_attr a))::$2 }
> > 
> >  storage:
> >           s=Tstatic      { P.clt2mcode Ast.Static s }
> > @@ -3227,12 +3227,14 @@ script_virt_name_decl:
> > 
> >  %inline
> >  attr_list:
> > -                        { [] }
> > - | a=Tattr f=full_attr_list {P.id2mcode a::f}
> > +                           { [] }
> > + | Tattr f=full_attr_list
> > +    { let a = P.make_attr $1 in a::f }
> > 
> >  full_attr_list:
> > -                        { [] }
> > - | Tattr full_attr_list {P.id2mcode $1::$2}
> > +                           { [] }
> > + | Tattr f=full_attr_list
> > +    { let a = P.make_attr $1 in a::f }
> > 
> >  anything: /* used for script code */
> >     TIdentifier { "identifier" }
> > --
> > 2.21.3
> > 
> > 

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

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Cocci] [PATCH 10/20] parsing_cocci: unparse_ast0: Wrap SmPL Attributes
  2020-07-08 12:53 [Cocci] [PATCH v2 00/20] parsing_cocci: " Jaskaran Singh
@ 2020-07-08 12:53 ` Jaskaran Singh
  0 siblings, 0 replies; 25+ messages in thread
From: Jaskaran Singh @ 2020-07-08 12:53 UTC (permalink / raw)
  To: cocci

Attributes are wrapped in the SmPL AST. Reflect these changes in
unparse_ast0.ml.

Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
 parsing_cocci/unparse_ast0.ml | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index 81bbb71a..109f1844 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -223,8 +223,7 @@ let rec expression e =
 	  expression exp; mcode print_string ar; ident field
       | Ast0.Cast(lp,ty,attr,rp,exp) ->
 	  mcode print_string_box lp; typeC ty; close_box();
-	  (if not (attr = []) then print_string " ");
-	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
 	  mcode print_string rp; expression exp
       | Ast0.SizeOfExpr(szf,exp) ->
 	  mcode print_string szf; expression exp
@@ -408,15 +407,13 @@ and declaration d =
       |	Ast0.Init(stg,ty,id,attr,eq,ini,sem) ->
 	  print_option (mcode U.storage) stg;
 	  print_named_type ty id;
-	  (if not (attr = []) then print_string " ");
-	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
 	  print_string " ";
 	  mcode print_string eq; print_string " "; initialiser ini;
 	  mcode print_string sem
       | Ast0.UnInit(stg,ty,id,attr,sem) ->
 	  print_option (mcode U.storage) stg; print_named_type ty id;
-	  (if not (attr = []) then print_string " ");
-	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
 	  mcode print_string sem
       | Ast0.FunProto(fninfo,name,lp1,params,va,rp1,sem) ->
 	  List.iter print_fninfo fninfo;
@@ -429,8 +426,7 @@ and declaration d =
 	  ident name; mcode print_string_box lp;
 	  let _ = dots (function _ -> ()) expression args in
 	  close_box(); mcode print_string rp;
-	  (if not (attr = []) then print_string " ");
-	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
 	  mcode print_string sem
       | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
 	  print_option (mcode U.storage) stg;
@@ -442,8 +438,7 @@ and declaration d =
 	  mcode print_string sem
       | Ast0.TyDecl(ty,attr,sem) ->
           typeC ty;
-          (if not (attr = []) then print_string " ");
-          print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
           mcode print_string sem
       | Ast0.Typedef(stg,ty,id,sem) ->
 	  mcode print_string stg; typeC ty; typeC id;
@@ -557,16 +552,13 @@ and parameterTypeDef p =
       match Ast0.unwrap p with
         Ast0.VoidParam(ty,attr) ->
           typeC ty;
-          (if (attr = []) then print_string " ");
-          print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list 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;
+          print_attribute_list attr;
       | Ast0.Param(ty,None,attr) ->
           typeC ty;
-          (if (attr = []) then print_string " ");
-          print_between (fun _ -> print_string " ") (mcode print_string) attr;
+          print_attribute_list attr;
       | Ast0.MetaParam(name,_,_) -> mcode print_meta name
       | Ast0.MetaParamList(name,_,_,_) -> mcode print_meta name
       | Ast0.PComma(cm) -> mcode print_string cm; print_space()
@@ -767,7 +759,15 @@ and print_fninfo = function
     Ast0.FStorage(stg) -> mcode U.storage stg
   | Ast0.FType(ty) -> typeC ty
   | Ast0.FInline(inline) -> mcode print_string inline
-  | Ast0.FAttr(attr) -> mcode print_string attr
+  | Ast0.FAttr(attr) -> print_attribute attr
+
+and print_attribute_list attrs =
+  if not (attrs = []) then print_string " ";
+  print_between (fun _ -> print_string " ") print_attribute attrs
+
+and print_attribute a =
+  match Ast0.unwrap a with
+    Ast0.Attribute(attr) -> mcode print_string attr
 
 and whencode notfn alwaysfn = function
     Ast0.WhenNot (_,_,a) ->
-- 
2.21.3

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

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2020-07-08 12:54 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03 17:59 [Cocci] [PATCH 00/20] parsing_cocci: Wrap SmPL Attributes Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 01/20] parsing_cocci: ast0_cocci: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 02/20] parsing_cocci: parser: " Jaskaran Singh
2020-07-06 20:03   ` Julia Lawall
2020-07-07  9:51     ` Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 03/20] parsing_cocci: visitor_ast0: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 04/20] parsing_cocci: adjust_pragmas: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 05/20] parsing_cocci: arity: " Jaskaran Singh
2020-07-06 20:04   ` Julia Lawall
2020-07-03 17:59 ` [Cocci] [PATCH 06/20] parsing_cocci: compute_lines: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 07/20] parsing_cocci: context_neg: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 08/20] parsing_cocci: iso_pattern: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 09/20] parsing_cocci: index: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 10/20] parsing_cocci: unparse_ast0: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 11/20] parsing_cocci: ast0toast: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 12/20] parsing_cocci: ast_cocci: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 13/20] parsing_cocci: visitor_ast: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 14/20] parsing_cocci: get_constants2: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 15/20] parsing_cocci: safe_for_multi_decls: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 16/20] parsing_cocci: unify_ast: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 17/20] parsing_cocci: pretty_print_cocci: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 18/20] parsing_c: unparse_cocci: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 19/20] engine: cocci_vs_c: " Jaskaran Singh
2020-07-03 17:59 ` [Cocci] [PATCH 20/20] ocaml: coccilib: " Jaskaran Singh
2020-07-08 12:53 [Cocci] [PATCH v2 00/20] parsing_cocci: " Jaskaran Singh
2020-07-08 12:53 ` [Cocci] [PATCH 10/20] parsing_cocci: unparse_ast0: " Jaskaran Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).