All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaskaran Singh <jaskaransingh7654321@gmail.com>
To: cocci@systeme.lip6.fr
Cc: linux-kernel-mentees@lists.linuxfoundation.org
Subject: [Cocci] [PATCH v2 17/25] engine: cocci_vs_c: Add allminus argument to attribute_list
Date: Thu, 28 May 2020 17:54:19 +0530	[thread overview]
Message-ID: <20200528122428.4212-18-jaskaransingh7654321@gmail.com> (raw)
In-Reply-To: <20200528122428.4212-1-jaskaransingh7654321@gmail.com>

The allminus argument is used to denote when attributes should be
removed. This is with respect to the given SmPL program.

Add the allminus argument to attribute_list, and pass it correctly in
places where attribute_list is used.

This also makes sure that the test case unstruct does not break when
attributes are identified correctly by the C parser.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 engine/cocci_vs_c.ml | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index e383aef8..413ea220 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -2563,7 +2563,7 @@ and onedecl = fun allminus decla (declb, iiptvirgb, iistob) ->
        ident_cpp DontKnow ida nameidb >>= (fun ida nameidb ->
        tokenf ptvirga iiptvirgb >>= (fun ptvirga iiptvirgb ->
        fullType typa typb >>= (fun typa typb ->
-       attribute_list attrsa endattrs >>= (fun attrsa endattrs ->
+       attribute_list allminus attrsa endattrs >>= (fun attrsa endattrs ->
        storage_optional_allminus allminus stoa (stob, iistob) >>=
         (fun stoa (stob, iistob) ->
          return (
@@ -2592,7 +2592,7 @@ and onedecl = fun allminus decla (declb, iiptvirgb, iistob) ->
        tokenf ptvirga iiptvirgb >>= (fun ptvirga iiptvirgb ->
        tokenf eqa iieqb >>= (fun eqa iieqb ->
        fullType typa typb >>= (fun typa typb ->
-       attribute_list attrsa endattrs >>= (fun attrsa endattrs ->
+       attribute_list allminus attrsa endattrs >>= (fun attrsa endattrs ->
        storage_optional_allminus allminus stoa (stob, iistob) >>=
        (fun stoa (stob, iistob) ->
        initialiser inia inib >>= (fun inia inib ->
@@ -2651,7 +2651,7 @@ and onedecl = fun allminus decla (declb, iiptvirgb, iistob) ->
           inla (stob, iistob) >>= (fun inla (stob, iistob) ->
         storage_optional_allminus allminus
           stoa (stob, iistob) >>= (fun stoa (stob, iistob) ->
-        attribute_list attras attrs >>= (fun attras attrs ->
+        attribute_list allminus attras attrs >>= (fun attras attrs ->
         fullType_optional_allminus allminus tya tyb >>= (fun tya tyb ->
 	let fninfoa = put_fninfo stoa tya inla attras in
         parameters (seqstyle paramsa) (A.unwrap paramsa) paramsb >>=
@@ -4194,29 +4194,41 @@ and attribute_list attras attrbs =
 
 (* The cheap hackish version.  No wrapping requires... *)
 
-and attribute_list attras attrbs =
+and attribute_list allminus attras attrbs =
   X.optional_attributes_flag (fun optional_attributes ->
   match attras,attrbs with
     [], _ when optional_attributes || attrbs = [] ->
-      return ([], attrbs)
+      if allminus
+      then
+        let rec loop = function
+            [] -> return ([],[])
+          | ib::ibs ->
+              X.distrf_attr minusizer ib >>= (fun _ ib ->
+                  loop ibs >>= (fun l ibs ->
+                    return([],ib::ibs))) in
+        loop attrbs
+      else return ([], attrbs)
   | [], _ -> fail
   | [attra], [attrb] ->
-    attribute attra attrb >>= (fun attra attrb ->
+    attribute allminus attra attrb >>= (fun attra attrb ->
       return ([attra], [attrb])
     )
   | [attra], attrb -> fail
   | _ -> failwith "only one attribute allowed in SmPL")
 
-and attribute = fun ea eb ->
+and attribute = fun allminus ea eb ->
   match ea, eb with
     attra, (B.Attribute attrb, ii)
       when (A.unwrap_mcode attra) = attrb ->
       let ib1 = tuple_of_list1 ii in
       tokenf attra ib1 >>= (fun attra ib1 ->
+       (if allminus
+        then minusize_list [ib1]
+        else return ((), [ib1])) >>= (fun _ ib1 ->
 	return (
 	  attra,
-	  (B.Attribute attrb, [ib1])
-        ))
+          (B.Attribute attrb,ib1)
+        )))
   | _ -> fail
 
 (*---------------------------------------------------------------------------*)
@@ -4927,7 +4939,7 @@ let rec (rule_elem_node: (A.rule_elem, F.node) matcher) =
             inla (stob, iistob) >>= (fun inla (stob, iistob) ->
           storage_optional_allminus allminus
             stoa (stob, iistob) >>= (fun stoa (stob, iistob) ->
-          attribute_list attras attrs >>= (fun attras attrs ->
+          attribute_list allminus attras attrs >>= (fun attras attrs ->
               (
                 if isvaargs
                 then
-- 
2.21.1

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

WARNING: multiple messages have this Message-ID (diff)
From: Jaskaran Singh <jaskaransingh7654321@gmail.com>
To: cocci@systeme.lip6.fr
Cc: julia.lawall@inria.fr, jaskaransingh7654321@gmail.com,
	linux-kernel-mentees@lists.linuxfoundation.org
Subject: [Linux-kernel-mentees] [PATCH v2 17/25] engine: cocci_vs_c: Add allminus argument to attribute_list
Date: Thu, 28 May 2020 17:54:19 +0530	[thread overview]
Message-ID: <20200528122428.4212-18-jaskaransingh7654321@gmail.com> (raw)
In-Reply-To: <20200528122428.4212-1-jaskaransingh7654321@gmail.com>

The allminus argument is used to denote when attributes should be
removed. This is with respect to the given SmPL program.

Add the allminus argument to attribute_list, and pass it correctly in
places where attribute_list is used.

This also makes sure that the test case unstruct does not break when
attributes are identified correctly by the C parser.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 engine/cocci_vs_c.ml | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index e383aef8..413ea220 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -2563,7 +2563,7 @@ and onedecl = fun allminus decla (declb, iiptvirgb, iistob) ->
        ident_cpp DontKnow ida nameidb >>= (fun ida nameidb ->
        tokenf ptvirga iiptvirgb >>= (fun ptvirga iiptvirgb ->
        fullType typa typb >>= (fun typa typb ->
-       attribute_list attrsa endattrs >>= (fun attrsa endattrs ->
+       attribute_list allminus attrsa endattrs >>= (fun attrsa endattrs ->
        storage_optional_allminus allminus stoa (stob, iistob) >>=
         (fun stoa (stob, iistob) ->
          return (
@@ -2592,7 +2592,7 @@ and onedecl = fun allminus decla (declb, iiptvirgb, iistob) ->
        tokenf ptvirga iiptvirgb >>= (fun ptvirga iiptvirgb ->
        tokenf eqa iieqb >>= (fun eqa iieqb ->
        fullType typa typb >>= (fun typa typb ->
-       attribute_list attrsa endattrs >>= (fun attrsa endattrs ->
+       attribute_list allminus attrsa endattrs >>= (fun attrsa endattrs ->
        storage_optional_allminus allminus stoa (stob, iistob) >>=
        (fun stoa (stob, iistob) ->
        initialiser inia inib >>= (fun inia inib ->
@@ -2651,7 +2651,7 @@ and onedecl = fun allminus decla (declb, iiptvirgb, iistob) ->
           inla (stob, iistob) >>= (fun inla (stob, iistob) ->
         storage_optional_allminus allminus
           stoa (stob, iistob) >>= (fun stoa (stob, iistob) ->
-        attribute_list attras attrs >>= (fun attras attrs ->
+        attribute_list allminus attras attrs >>= (fun attras attrs ->
         fullType_optional_allminus allminus tya tyb >>= (fun tya tyb ->
 	let fninfoa = put_fninfo stoa tya inla attras in
         parameters (seqstyle paramsa) (A.unwrap paramsa) paramsb >>=
@@ -4194,29 +4194,41 @@ and attribute_list attras attrbs =
 
 (* The cheap hackish version.  No wrapping requires... *)
 
-and attribute_list attras attrbs =
+and attribute_list allminus attras attrbs =
   X.optional_attributes_flag (fun optional_attributes ->
   match attras,attrbs with
     [], _ when optional_attributes || attrbs = [] ->
-      return ([], attrbs)
+      if allminus
+      then
+        let rec loop = function
+            [] -> return ([],[])
+          | ib::ibs ->
+              X.distrf_attr minusizer ib >>= (fun _ ib ->
+                  loop ibs >>= (fun l ibs ->
+                    return([],ib::ibs))) in
+        loop attrbs
+      else return ([], attrbs)
   | [], _ -> fail
   | [attra], [attrb] ->
-    attribute attra attrb >>= (fun attra attrb ->
+    attribute allminus attra attrb >>= (fun attra attrb ->
       return ([attra], [attrb])
     )
   | [attra], attrb -> fail
   | _ -> failwith "only one attribute allowed in SmPL")
 
-and attribute = fun ea eb ->
+and attribute = fun allminus ea eb ->
   match ea, eb with
     attra, (B.Attribute attrb, ii)
       when (A.unwrap_mcode attra) = attrb ->
       let ib1 = tuple_of_list1 ii in
       tokenf attra ib1 >>= (fun attra ib1 ->
+       (if allminus
+        then minusize_list [ib1]
+        else return ((), [ib1])) >>= (fun _ ib1 ->
 	return (
 	  attra,
-	  (B.Attribute attrb, [ib1])
-        ))
+          (B.Attribute attrb,ib1)
+        )))
   | _ -> fail
 
 (*---------------------------------------------------------------------------*)
@@ -4927,7 +4939,7 @@ let rec (rule_elem_node: (A.rule_elem, F.node) matcher) =
             inla (stob, iistob) >>= (fun inla (stob, iistob) ->
           storage_optional_allminus allminus
             stoa (stob, iistob) >>= (fun stoa (stob, iistob) ->
-          attribute_list attras attrs >>= (fun attras attrs ->
+          attribute_list allminus attras attrs >>= (fun attras attrs ->
               (
                 if isvaargs
                 then
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  parent reply	other threads:[~2020-05-28 12:25 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28 12:24 [Cocci] [PATCH v2 00/25] cocci: Improve C parsing of attributes Jaskaran Singh
2020-05-28 12:24 ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 01/25] parsing_c: parse_c: Ignore TMacroAttr and TMacroEndAttr in passed tokens Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 02/25] parsing_c: parsing_hacks: Label end attributes correctly Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 03/25] parsing_c: parsing_hacks: Commentize attributes before qualif/type Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 04/25] parsing_c: parser: Add rule for multiple end attributes Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 05/25] parsing_c: parser: Add expression statement attributes Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 06/25] parsing_c: parser: Add attribute production in spec_qualif_list Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 07/25] parsing_c: parser: Add init_declarator_attrs rule Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 08/25] parsing_c: parser: Add field declaration end attributes production Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 09/25] parsing_c: parser: Handle struct/union/enum end attributes Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 10/25] parsing_c: parser: Add MacroDecl end attributes production Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 11/25] parsing_c: parser: cpp_other " Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 12/25] parsing_c: cpp_token_c: Introduce MACROANNOTATION hint Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 13/25] cocci: standard.h: Annotate attributes with MACROANNOTATION Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 14/25] parsing_c: visitor_c: Add vk_attribute and vk_attribute_s Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 15/25] parsing_c: lib_parsing_c: Add ii_of_attr Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 16/25] engine: Add distrf_attr to PARAM functor Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` Jaskaran Singh [this message]
2020-05-28 12:24   ` [Linux-kernel-mentees] [PATCH v2 17/25] engine: cocci_vs_c: Add allminus argument to attribute_list Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 18/25] parsing_c: parser: Make abstract_declarator pass attributes Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 19/25] cocci: Add parameter attributes to C AST Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 20/25] parsing_c: parser: Place parameter attributes in " Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 21/25] parsing_c: visitor_c: Visit parameter attributes Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 22/25] parsing_c: unparse_hrule: Add parameter attributes in record Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 23/25] parsing_c: type_c: Add parameter attributes to record Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 24/25] engine: cocci_vs_c: "Match" parameter attributes Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 12:24 ` [Cocci] [PATCH v2 25/25] engine: c_vs_c: Match " Jaskaran Singh
2020-05-28 12:24   ` [Linux-kernel-mentees] " Jaskaran Singh
2020-05-28 13:29 ` [Cocci] [PATCH v3 20/25] parsing_c: parser: Place parameter attributes in C AST Jaskaran Singh
2020-05-28 13:29   ` [Linux-kernel-mentees] " 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=20200528122428.4212-18-jaskaransingh7654321@gmail.com \
    --to=jaskaransingh7654321@gmail.com \
    --cc=cocci@systeme.lip6.fr \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.