cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Jaskaran Singh <jaskaran.singh@collabora.com>
To: cocci@systeme.lip6.fr
Subject: [Cocci] [PATCH 13/20] parsing_cocci: visitor_ast: Wrap SmPL Attributes
Date: Fri,  3 Jul 2020 23:29:24 +0530	[thread overview]
Message-ID: <20200703175931.1693-14-jaskaran.singh@collabora.com> (raw)
In-Reply-To: <20200703175931.1693-1-jaskaran.singh@collabora.com>

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

  parent reply	other threads:[~2020-07-03 18:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Jaskaran Singh [this message]
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 13/20] parsing_cocci: visitor_ast: " Jaskaran Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200703175931.1693-14-jaskaran.singh@collabora.com \
    --to=jaskaran.singh@collabora.com \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).