cocci.inria.fr archive mirror
 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 08/13] parsing_cocci: Add visitor functions for enum_decl in visitor_ast
Date: Sun,  8 Mar 2020 14:13:51 +0530	[thread overview]
Message-ID: <20200308084356.14506-9-jaskaransingh7654321@gmail.com> (raw)
In-Reply-To: <20200308084356.14506-1-jaskaransingh7654321@gmail.com>

An enumerator in the SmPL AST now has the enum_decl type.
Add corresponding functions for the combiner, combiner_rebuilder
and rebuilder in Visitor_ast.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>n
---
 parsing_cocci/visitor_ast.ml  | 72 +++++++++++++++++++++++++++++++----
 parsing_cocci/visitor_ast.mli |  8 ++++
 2 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 3d5de794..df6b5a90 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -27,6 +27,7 @@ type 'a combiner =
      combiner_declaration : Ast.declaration -> 'a;
      combiner_field : Ast.field -> 'a;
      combiner_ann_field : Ast.annotated_field -> 'a;
+     combiner_enumdecl : Ast_cocci.enum_decl -> 'a;
      combiner_initialiser : Ast.initialiser -> 'a;
      combiner_parameter : Ast.parameterTypeDef -> 'a;
      combiner_parameter_list : Ast.parameter_list -> 'a;
@@ -39,6 +40,7 @@ type 'a combiner =
      combiner_statement_dots : Ast.statement Ast.dots -> 'a;
      combiner_anndecl_dots : Ast.annotated_decl Ast.dots -> 'a;
      combiner_annfield_dots : Ast.annotated_field Ast.dots -> 'a;
+     combiner_enumdecl_dots : Ast.enum_decl Ast.dots -> 'a;
      combiner_initialiser_dots : Ast.initialiser Ast.dots -> 'a}
 
 type ('mc,'a) cmcode = 'a combiner -> 'mc Ast_cocci.mcode -> 'a
@@ -50,11 +52,12 @@ let combiner bind option_default
     unary_mcodefn arithop_mcodefn logicalop_mcodefn
     cv_mcodefn sign_mcodefn struct_mcodefn storage_mcodefn
     inc_file_mcodefn
-    expdotsfn paramdotsfn stmtdotsfn anndecldotsfn annfielddotsfn initdotsfn
+    expdotsfn paramdotsfn stmtdotsfn anndecldotsfn annfielddotsfn
+    enumdecldotsfn initdotsfn
     identfn exprfn fragfn fmtfn assignOpfn binaryOpfn ftfn tyfn initfn
     paramfn define_paramfn declfn
-    annotated_declfn fieldfn annotated_fieldfn rulefn stmtfn casefn topfn
-    anyfn =
+    annotated_declfn fieldfn annotated_fieldfn enum_declfn rulefn stmtfn
+    casefn topfn anyfn =
   let multibind l =
     let rec loop = function
 	[] -> option_default
@@ -95,6 +98,8 @@ let combiner bind option_default
     dotsfn anndecldotsfn annotated_decl all_functions d
   and annotated_field_dots d =
     dotsfn annfielddotsfn annotated_field all_functions d
+  and enum_decl_dots d =
+    dotsfn enumdecldotsfn enum_decl all_functions d
   and initialiser_dots d = dotsfn initdotsfn initialiser all_functions d
   and string_fragment_dots d = dotsfn strdotsfn string_fragment all_functions d
   and exec_code_dots d = dotsfn ecdotsfn exec_code all_functions d
@@ -348,7 +353,7 @@ let combiner bind option_default
       | Ast.EnumDef(ty,lb,ids,rb) ->
 	  let lty = fullType ty in
 	  let llb = string_mcode lb in
-	  let lids = expression_dots ids in
+	  let lids = enum_decl_dots ids in
 	  let lrb = string_mcode rb in
 	  multibind [lty; llb; lids; lrb]
       | Ast.StructUnionName(kind,name) ->
@@ -498,6 +503,25 @@ let combiner bind option_default
       | Ast.OptField(decl) -> annotated_field decl in
     annotated_fieldfn all_functions k d
 
+  and enum_decl d =
+    let k d =
+      match Ast.unwrap d with
+	Ast.Enum(name,enum_val) ->
+          let lname = ident name in
+          (match enum_val with
+            None -> lname
+          | Some(eq,eval) ->
+              let leq = string_mcode eq in
+              let leval = expression eval in
+              multibind [lname; leq; leval])
+      | Ast.EnumComma(cm) ->
+        string_mcode cm
+      | Ast.EnumDots(dots,whncode) ->
+        let ldots = string_mcode dots in
+        let lwhncode = get_option enum_decl whncode in
+	bind ldots lwhncode in
+    enum_declfn all_functions k d
+
   and initialiser i =
     let k i =
       match Ast.unwrap i with
@@ -899,6 +923,7 @@ let combiner bind option_default
       | Ast.LogicalOpTag(logop) -> option_default
       | Ast.DeclarationTag(decl) -> declaration decl
       | Ast.FieldTag(decl) -> field decl
+      | Ast.EnumDeclTag(decl) -> enum_decl decl
       | Ast.InitTag(ini) -> initialiser ini
       | Ast.StorageTag(stg) -> option_default
       | Ast.IncFileTag(stg) -> option_default
@@ -916,6 +941,7 @@ let combiner bind option_default
       | Ast.StmtDotsTag(sd) -> statement_dots sd
       | Ast.AnnDeclDotsTag(sd) -> annotated_decl_dots sd
       | Ast.AnnFieldDotsTag(sd) -> annotated_field_dots sd
+      | Ast.EnumDeclDotsTag(sd) -> enum_decl_dots sd
       | Ast.DefParDotsTag(sd) -> define_param_dots sd
       | Ast.TypeCTag(ty) -> typeC ty
       | Ast.ParamTag(param) -> parameterTypeDef param
@@ -935,6 +961,7 @@ let combiner bind option_default
       combiner_declaration = declaration;
       combiner_field = field;
       combiner_ann_field = annotated_field;
+      combiner_enumdecl = enum_decl;
       combiner_initialiser = initialiser;
       combiner_parameter = parameterTypeDef;
       combiner_parameter_list = parameter_dots;
@@ -947,6 +974,7 @@ let combiner bind option_default
       combiner_statement_dots = statement_dots;
       combiner_anndecl_dots = annotated_decl_dots;
       combiner_annfield_dots = annotated_field_dots;
+      combiner_enumdecl_dots = enum_decl_dots;
       combiner_initialiser_dots = initialiser_dots} in
   all_functions
 
@@ -966,6 +994,7 @@ type rebuilder =
       rebuilder_declaration : Ast.declaration inout;
       rebuilder_field : Ast.field inout;
       rebuilder_ann_field : Ast.annotated_field inout;
+      rebuilder_enumdecl : Ast_cocci.enum_decl inout;
       rebuilder_initialiser : Ast.initialiser inout;
       rebuilder_parameter : Ast.parameterTypeDef inout;
       rebuilder_parameter_list : Ast.parameter_list inout;
@@ -977,6 +1006,7 @@ type rebuilder =
       rebuilder_statement_dots : Ast.statement Ast.dots inout;
       rebuilder_anndecl_dots : Ast.annotated_decl Ast.dots inout;
       rebuilder_annfield_dots : Ast.annotated_field Ast.dots inout;
+      rebuilder_enumdecl_dots : Ast.enum_decl Ast.dots inout;
       rebuilder_initialiser_dots : Ast.initialiser Ast.dots inout;
       rebuilder_define_param_dots : Ast.define_param Ast.dots inout;
       rebuilder_define_param : Ast.define_param inout;
@@ -992,10 +1022,11 @@ let rebuilder
     fix_mcode unary_mcode
     arithop_mcode logicalop_mcode cv_mcode sign_mcode struct_mcode
     storage_mcode inc_file_mcode
-    expdotsfn paramdotsfn stmtdotsfn anndecldotsfn annfielddotsfn initdotsfn
+    expdotsfn paramdotsfn stmtdotsfn anndecldotsfn annfielddotsfn
+    enumdecldotsfn initdotsfn
     identfn exprfn fragfn fmtfn assignOpfn binaryOpfn ftfn tyfn initfn
     paramfn define_paramfn declfn annotated_declfn fieldfn annotated_fieldfn
-    rulefn stmtfn casefn topfn anyfn =
+    enum_declfn rulefn stmtfn casefn topfn anyfn =
   let get_option f = function
       Some x -> Some (f x)
     | None -> None in
@@ -1014,6 +1045,8 @@ let rebuilder
     dotsfn anndecldotsfn annotated_decl all_functions d
   and annotated_field_dots d =
     dotsfn annfielddotsfn annotated_field all_functions d
+  and enum_decl_dots d =
+    dotsfn enumdecldotsfn enum_decl all_functions d
   and initialiser_dots d = dotsfn initdotsfn initialiser all_functions d
   and string_fragment_dots d = dotsfn strdotsfn string_fragment all_functions d
   and exec_code_dots d = dotsfn ecdotsfn exec_code all_functions d
@@ -1274,7 +1307,7 @@ let rebuilder
 	| Ast.EnumDef(ty,lb,ids,rb) ->
 	    let lty = fullType ty in
 	    let llb = string_mcode lb in
-	    let lids = expression_dots ids in
+	    let lids = enum_decl_dots ids in
 	    let lrb = string_mcode rb in
 	    Ast.EnumDef (lty, llb, lids, lrb)
 	| Ast.StructUnionName(kind,name) ->
@@ -1421,6 +1454,27 @@ let rebuilder
 	| Ast.OptField(decl) -> Ast.OptField(annotated_field decl)) in
     annotated_fieldfn all_functions k d
 
+  and enum_decl d =
+    let k d =
+      Ast.rewrap d
+        (match Ast.unwrap d with
+         Ast.Enum(name,enum_val) ->
+            let lname = ident name in
+            (match enum_val with
+              None -> Ast.Enum(lname,None)
+            | Some(eq,eval) ->
+                let leq = string_mcode eq in
+                let leval = expression eval in
+                Ast.Enum(lname,Some(leq,leval)))
+        | Ast.EnumComma(cm) ->
+          let lcm = string_mcode cm in
+          Ast.EnumComma(lcm)
+	| Ast.EnumDots(dots,whncode) ->
+	  let ldots = string_mcode dots in
+	  let lwhncode = get_option enum_decl whncode in
+	  Ast.EnumDots(ldots, lwhncode)) in
+    enum_declfn all_functions k d
+
   and initialiser i =
     let k i =
       Ast.rewrap i
@@ -1851,6 +1905,7 @@ let rebuilder
       | Ast.InitTag(decl) -> Ast.InitTag(initialiser decl)
       | Ast.DeclarationTag(decl) -> Ast.DeclarationTag(declaration decl)
       | Ast.FieldTag(decl) -> Ast.FieldTag(field decl)
+      | Ast.EnumDeclTag(decl) -> Ast.EnumDeclTag(enum_decl decl)
       | Ast.StorageTag(stg) as x -> x
       | Ast.IncFileTag(stg) as x -> x
       | Ast.Rule_elemTag(rule) -> Ast.Rule_elemTag(rule_elem rule)
@@ -1868,6 +1923,7 @@ let rebuilder
       | Ast.StmtDotsTag(sd) -> Ast.StmtDotsTag(statement_dots sd)
       | Ast.AnnDeclDotsTag(sd) -> Ast.AnnDeclDotsTag(annotated_decl_dots sd)
       | Ast.AnnFieldDotsTag(sd) -> Ast.AnnFieldDotsTag(annotated_field_dots sd)
+      | Ast.EnumDeclDotsTag(sd) -> Ast.EnumDeclDotsTag(enum_decl_dots sd)
       | Ast.DefParDotsTag(sd) -> Ast.DefParDotsTag(define_param_dots sd)
       | Ast.TypeCTag(ty) -> Ast.TypeCTag(typeC ty)
       | Ast.ParamTag(param) -> Ast.ParamTag(parameterTypeDef param)
@@ -1887,6 +1943,7 @@ let rebuilder
       rebuilder_declaration = declaration;
       rebuilder_field = field;
       rebuilder_ann_field = annotated_field;
+      rebuilder_enumdecl = enum_decl;
       rebuilder_initialiser = initialiser;
       rebuilder_parameter = parameterTypeDef;
       rebuilder_parameter_list = parameter_dots;
@@ -1898,6 +1955,7 @@ let rebuilder
       rebuilder_statement_dots = statement_dots;
       rebuilder_anndecl_dots = annotated_decl_dots;
       rebuilder_annfield_dots = annotated_field_dots;
+      rebuilder_enumdecl_dots = enum_decl_dots;
       rebuilder_initialiser_dots = initialiser_dots;
       rebuilder_define_param_dots = define_param_dots;
       rebuilder_define_param = define_param;
diff --git a/parsing_cocci/visitor_ast.mli b/parsing_cocci/visitor_ast.mli
index 20ce32b0..0ed17774 100644
--- a/parsing_cocci/visitor_ast.mli
+++ b/parsing_cocci/visitor_ast.mli
@@ -16,6 +16,7 @@ type 'a combiner =
      combiner_declaration : Ast_cocci.declaration -> 'a;
      combiner_field : Ast_cocci.field -> 'a;
      combiner_ann_field : Ast_cocci.annotated_field -> 'a;
+     combiner_enumdecl : Ast_cocci.enum_decl -> 'a;
      combiner_initialiser : Ast_cocci.initialiser -> 'a;
      combiner_parameter : Ast_cocci.parameterTypeDef -> 'a;
      combiner_parameter_list : Ast_cocci.parameter_list -> 'a;
@@ -28,6 +29,7 @@ type 'a combiner =
      combiner_statement_dots : Ast_cocci.statement Ast_cocci.dots -> 'a;
      combiner_anndecl_dots : Ast_cocci.annotated_decl Ast_cocci.dots -> 'a;
      combiner_annfield_dots : Ast_cocci.annotated_field Ast_cocci.dots -> 'a;
+     combiner_enumdecl_dots : Ast_cocci.enum_decl Ast_cocci.dots -> 'a;
      combiner_initialiser_dots : Ast_cocci.initialiser Ast_cocci.dots -> 'a}
 
 type ('mc,'a) cmcode = 'a combiner -> 'mc Ast_cocci.mcode -> 'a
@@ -54,6 +56,7 @@ val combiner :
       ((Ast_cocci.statement Ast_cocci.dots,'a) ccode) ->
       ((Ast_cocci.annotated_decl Ast_cocci.dots,'a) ccode) ->
       ((Ast_cocci.annotated_field Ast_cocci.dots,'a) ccode) ->
+      ((Ast_cocci.enum_decl Ast_cocci.dots,'a) ccode) ->
       ((Ast_cocci.initialiser Ast_cocci.dots,'a) ccode) ->
       ((Ast_cocci.ident,'a) ccode) ->
       ((Ast_cocci.expression,'a) ccode) ->
@@ -70,6 +73,7 @@ val combiner :
       ((Ast_cocci.annotated_decl,'a) ccode) ->
       ((Ast_cocci.field,'a) ccode) ->
       ((Ast_cocci.annotated_field,'a) ccode) ->
+      ((Ast_cocci.enum_decl,'a) ccode) ->
       ((Ast_cocci.rule_elem,'a) ccode) ->
       ((Ast_cocci.statement,'a) ccode) ->
       ((Ast_cocci.case_line,'a) ccode) ->
@@ -91,6 +95,7 @@ type rebuilder =
       rebuilder_declaration : Ast_cocci.declaration inout;
       rebuilder_field : Ast_cocci.field inout;
       rebuilder_ann_field : Ast_cocci.annotated_field inout;
+      rebuilder_enumdecl : Ast_cocci.enum_decl inout;
       rebuilder_initialiser : Ast_cocci.initialiser inout;
       rebuilder_parameter : Ast_cocci.parameterTypeDef inout;
       rebuilder_parameter_list : Ast_cocci.parameter_list inout;
@@ -102,6 +107,7 @@ type rebuilder =
       rebuilder_statement_dots : Ast_cocci.statement Ast_cocci.dots inout;
       rebuilder_anndecl_dots : Ast_cocci.annotated_decl Ast_cocci.dots inout;
       rebuilder_annfield_dots : Ast_cocci.annotated_field Ast_cocci.dots inout;
+      rebuilder_enumdecl_dots : Ast_cocci.enum_decl Ast_cocci.dots inout;
       rebuilder_initialiser_dots : Ast_cocci.initialiser Ast_cocci.dots inout;
       rebuilder_define_param_dots: Ast_cocci.define_param Ast_cocci.dots inout;
       rebuilder_define_param : Ast_cocci.define_param inout;
@@ -131,6 +137,7 @@ val rebuilder :
     (Ast_cocci.statement Ast_cocci.dots rcode) ->
     (Ast_cocci.annotated_decl Ast_cocci.dots rcode) ->
     (Ast_cocci.annotated_field Ast_cocci.dots rcode) ->
+    (Ast_cocci.enum_decl Ast_cocci.dots rcode) ->
     (Ast_cocci.initialiser Ast_cocci.dots rcode) ->
     (Ast_cocci.ident rcode) ->
     (Ast_cocci.expression rcode) ->
@@ -147,6 +154,7 @@ val rebuilder :
     (Ast_cocci.annotated_decl rcode) ->
     (Ast_cocci.field rcode) ->
     (Ast_cocci.annotated_field rcode) ->
+    (Ast_cocci.enum_decl rcode) ->
     (Ast_cocci.rule_elem rcode) ->
     (Ast_cocci.statement rcode) ->
     (Ast_cocci.case_line rcode) ->
-- 
2.21.1

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

  parent reply	other threads:[~2020-03-08  8:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 01/13] parsing_cocci: Align " Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 02/13] ocaml: coccilib: Reflect changes in SmPL AST for EnumDef Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 04/13] parsing_cocci: Add EnumDeclTag and EnumDeclDotsTag to SmPL ASTs Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 05/13] ocaml: coccilib: Reflect EnumDeclTag and EnumDeclDotsTag Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 06/13] parsing_cocci: visitor_ast0: Add visitor functions for enum_decl Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in parsing_cocci Jaskaran Singh
2020-03-08  8:43 ` Jaskaran Singh [this message]
2020-03-08  8:43 ` [Cocci] [PATCH 09/13] cocci: Reflect changes in SmPL visitor_ast in codebase Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 10/13] engine: cocci_vs_c: Match enumerators properly as per enum_decl Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 11/13] cocci: pretty print EnumDef as per enum_decl type Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 12/13] tests: Add test case for assigned enumerator Jaskaran Singh
2020-03-08  8:43 ` [Cocci] [PATCH 13/13] tools: spgen: Reflect visitor changes Jaskaran Singh
2020-03-09 14:15 ` [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Julia Lawall
2020-03-09 14:51   ` 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=20200308084356.14506-9-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 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).