Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum
@ 2020-03-08  8:43 Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 01/13] parsing_cocci: Align " Jaskaran Singh
                   ` (13 more replies)
  0 siblings, 14 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The C AST and SmPL AST differs with respect to the enum type.
    
For an enumerator, the C AST is as follows:
    Enum -> list of (name, (info, expression))
    
For the same, the SmPL AST is as follows:
    EnumDef -> list of expression
    
While the SmPL parser does make sure that enumerators are
parsed as per C rules, the OCaml types for an enumerator themselves
mismatch, due to their organization. This causes bugs/mismatches for
cases where enums are in disjunctions.
    
This patch series makes the enumerator type of the SmPL AST
closer to that of the C AST. Various places in the codebase that
handle an enum are also changed to match the new type, and
collateral evolutions caused by changed in the SmPL visitors are
handled as well.

Changes are also made to Cocci_vs_c to correctly match two
enumerators, and in Pretty_print_cocci and Unparse_cocci to
correctly print an enumerator.

[PATCH 01/13] parsing_cocci: Align C AST and SmPL AST for enum
[PATCH 02/13] ocaml: coccilib: Reflect changes in SmPL AST for
[PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly
[PATCH 04/13] parsing_cocci: Add EnumDeclTag and EnumDeclDotsTag to
[PATCH 05/13] ocaml: coccilib: Reflect EnumDeclTag and
[PATCH 06/13] parsing_cocci: visitor_ast0: Add visitor functions for
[PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in
[PATCH 08/13] parsing_cocci: Add visitor functions for enum_decl in
[PATCH 09/13] cocci: Reflect changes in SmPL visitor_ast in codebase
[PATCH 10/13] engine: cocci_vs_c: Match enumerators properly as per
[PATCH 11/13] cocci: pretty print EnumDef as per enum_decl type
[PATCH 12/13] tests: Add test case for assigned enumerator
[PATCH 13/13] tools: spgen: Reflect visitor changes

 cocci.ml                              |    4 -
 engine/asttoctl2.ml                   |   21 +++++---
 engine/asttomember.ml                 |   17 ++++---
 engine/cocci_vs_c.ml                  |   46 ++++++++-----------
 engine/transformation_c.ml            |    4 -
 ocaml/coccilib.mli                    |   22 ++++++++-
 parsing_c/unparse_cocci.ml            |   27 ++++++++++-
 parsing_c/unparse_hrule.ml            |    4 -
 parsing_cocci/arity.ml                |   25 ++++++++++
 parsing_cocci/ast0_cocci.ml           |   15 +++++-
 parsing_cocci/ast0_cocci.mli          |   14 +++++
 parsing_cocci/ast0toast.ml            |   30 +++++++++++-
 parsing_cocci/ast0toast.mli           |    4 +
 parsing_cocci/ast_cocci.ml            |   13 +++++
 parsing_cocci/ast_cocci.mli           |   12 ++++-
 parsing_cocci/check_meta.ml           |   17 +++++--
 parsing_cocci/cleanup_rules.ml        |    5 +-
 parsing_cocci/commas_on_lists.ml      |   10 ++--
 parsing_cocci/compute_lines.ml        |   25 ++++++++++
 parsing_cocci/context_neg.ml          |   47 +++++++++++++++++--
 parsing_cocci/disjdistr.ml            |   29 +++++++++---
 parsing_cocci/free_vars.ml            |   27 +++++------
 parsing_cocci/function_prototypes.ml  |    7 +-
 parsing_cocci/get_constants2.ml       |    7 +-
 parsing_cocci/index.ml                |    7 ++
 parsing_cocci/index.mli               |    2 
 parsing_cocci/insert_plus.ml          |   39 +++++++++++++---
 parsing_cocci/iso_compile.ml          |    4 -
 parsing_cocci/iso_pattern.ml          |   80 ++++++++++++++++++++++++++++------
 parsing_cocci/parse_aux.ml            |    5 ++
 parsing_cocci/parse_aux.mli           |    9 +++
 parsing_cocci/parse_cocci.ml          |    4 -
 parsing_cocci/parser_cocci_menhir.mly |   13 ++---
 parsing_cocci/pretty_print_cocci.ml   |   18 +++++++
 parsing_cocci/re_constraints.ml       |   10 ++--
 parsing_cocci/safe_for_multi_decls.ml |   11 ++--
 parsing_cocci/single_statement.ml     |    5 +-
 parsing_cocci/stmtlist.ml             |    4 -
 parsing_cocci/unify_ast.ml            |   29 ++++++++++--
 parsing_cocci/unitary_ast0.ml         |    5 +-
 parsing_cocci/unparse_ast0.ml         |   22 ++++++++-
 parsing_cocci/visitor_ast.ml          |   72 +++++++++++++++++++++++++++---
 parsing_cocci/visitor_ast.mli         |    8 +++
 parsing_cocci/visitor_ast0.ml         |   72 ++++++++++++++++++++++++++++--
 parsing_cocci/visitor_ast0.mli        |    4 +
 parsing_cocci/visitor_ast0_types.ml   |   14 +++++
 parsing_cocci/visitor_ast0_types.mli  |   12 +++++
 popl/popltoctl.ml                     |    2 
 popl09/popltoctl.ml                   |    5 +-
 tests/enum_assign.c                   |    6 ++
 tests/enum_assign.cocci               |   11 ++++
 tests/enum_assign.res                 |    7 ++
 tools/spgen/source/detect_patch.ml    |    6 +-
 tools/spgen/source/meta_variable.ml   |    6 +-
 tools/spgen/source/rule_body.ml       |    6 +-
 55 files changed, 748 insertions(+), 182 deletions(-)

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

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

* [Cocci] [PATCH 01/13] parsing_cocci: Align C AST and SmPL AST for enum
  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 ` " Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 02/13] ocaml: coccilib: Reflect changes in SmPL AST for EnumDef Jaskaran Singh
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The C AST and SmPL AST differs with respect to the enum type.

For an enumerator, the C AST is as follows:
	Enum -> list of (name, (info, expression))

For the same, the SmPL AST is as follows:
	EnumDef -> list of expression

While the SmPL parser does make sure that enumerators are
parsed as per C rules, the OCaml types for an enumerator themselves
mismatch, due to their organization. This causes bugs/mismatches for
cases where enums are in disjunctions.

Make the enumerator type of the SmPL AST closer to that of
the C AST.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/ast0_cocci.ml  | 11 ++++++++++-
 parsing_cocci/ast0_cocci.mli | 10 +++++++++-
 parsing_cocci/ast_cocci.ml   |  9 ++++++++-
 parsing_cocci/ast_cocci.mli  | 10 +++++++++-
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index 77dc46f0..b3d8b137 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -211,7 +211,7 @@ and base_typeC =
 	               string mcode (* ) *) (* IBM C only *)
   | EnumName        of string mcode (*enum*) * ident option (* name *)
   | EnumDef  of typeC (* either StructUnionName or metavar *) *
-	string mcode (* { *) * expression dots * string mcode (* } *)
+	string mcode (* { *) * enum_decl dots * string mcode (* } *)
   | StructUnionName of Ast.structUnion mcode * ident option (* name *)
   | StructUnionDef  of typeC (* either StructUnionName or metavar *) *
 	string mcode (* { *) * field dots * string mcode (* } *)
@@ -288,6 +288,15 @@ and bitfield = string mcode (* : *) * expression
 
 and field = base_field wrap
 
+and base_enum_decl =
+    Enum of ident * (string mcode (* = *) * expression) option
+  | EnumComma of string mcode (* , *)
+  | EnumDots of string mcode (* ... *) * (string mcode * string mcode *
+                enum_decl) option (* whencode *)
+
+and enum_decl = base_enum_decl wrap
+
+
 (* --------------------------------------------------------------------- *)
 (* Initializers *)
 
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 274c6bc2..732a1345 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -202,7 +202,7 @@ and base_typeC =
 	               string mcode (* ) *) (* IBM C only *)
   | EnumName        of string mcode (*enum*) * ident option (* name *)
   | EnumDef  of typeC (* either StructUnionName or metavar *) *
-	string mcode (* { *) * expression dots * string mcode (* } *)
+	string mcode (* { *) * enum_decl dots * string mcode (* } *)
   | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *)
   | StructUnionDef  of typeC (* either StructUnionName or metavar *) *
 	string mcode (* { *) * field dots * string mcode (* } *)
@@ -276,6 +276,14 @@ and bitfield = string mcode (* : *) * expression
 
 and field = base_field wrap
 
+and base_enum_decl =
+    Enum of ident * (string mcode (* = *) * expression) option
+  | EnumComma of string mcode (* , *)
+  | EnumDots of string mcode (* ... *) * (string mcode * string mcode *
+                enum_decl) option (* whencode *)
+
+and enum_decl = base_enum_decl wrap
+
 (* --------------------------------------------------------------------- *)
 (* Initializers *)
 
diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index ba6ec29e..8fa64dcc 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -351,7 +351,7 @@ and base_typeC =
 	               string mcode (* ) *) (* IBM C only *)
   | EnumName        of string mcode (*enum*) * ident option (* name *)
   | EnumDef  of fullType (* either EnumName or metavar *) *
-	string mcode (* { *) * expression dots * string mcode (* } *)
+	string mcode (* { *) * enum_decl dots * string mcode (* } *)
   | StructUnionName of structUnion mcode * ident option (* name *)
   | StructUnionDef  of fullType (* either StructUnionName or metavar *) *
 	string mcode (* { *) * annotated_field dots * string mcode (* } *)
@@ -443,6 +443,13 @@ and base_annotated_field =
 
 and annotated_field = base_annotated_field wrap
 
+and base_enum_decl =
+    Enum of ident * (string mcode (* = *) * expression) option
+  | EnumComma of string mcode (* , *)
+  | EnumDots of string mcode (* ... *) * enum_decl option (* whencode *)
+
+and enum_decl = base_enum_decl wrap
+
 (* --------------------------------------------------------------------- *)
 (* Initializers *)
 
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index 5f21664b..e921f917 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -333,7 +333,7 @@ and base_typeC =
 	               string mcode (* ) *) (* IBM C only *)
   | EnumName        of string mcode (*enum*) * ident option (* name *)
   | EnumDef  of fullType (* either EnumName or metavar *) *
-	string mcode (* { *) * expression dots * string mcode (* } *)
+	string mcode (* { *) * enum_decl dots * string mcode (* } *)
   | StructUnionName of structUnion mcode * ident option (* name *)
   | StructUnionDef  of fullType (* either StructUnionName or metavar *) *
 	string mcode (* { *) * annotated_field dots * string mcode (* } *)
@@ -424,6 +424,14 @@ and base_annotated_field =
 
 and annotated_field = base_annotated_field wrap
 
+and base_enum_decl =
+    Enum of ident * (string mcode (* = *) * expression) option
+  | EnumComma of string mcode (* , *)
+  | EnumDots of string mcode (* ... *) * enum_decl option (* whencode *)
+
+and enum_decl = base_enum_decl wrap
+
+
 (* --------------------------------------------------------------------- *)
 (* Initializers *)
 
-- 
2.21.1

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

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

* [Cocci] [PATCH 02/13] ocaml: coccilib: Reflect changes in SmPL AST for EnumDef
  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 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly Jaskaran Singh
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The EnumDef constructor is changed in the SmPL AST. Reflect
these changes in coccilib.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 ocaml/coccilib.mli | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 5a913099..9b00e130 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -2713,7 +2713,7 @@ module Ast_cocci :
       | Decimal of string mcode * string mcode * expression *
           string mcode option * expression option * string mcode
       | EnumName of string mcode * ident option
-      | EnumDef of fullType * string mcode * expression dots * string mcode
+      | EnumDef of fullType * string mcode * enum_decl dots * string mcode
       | StructUnionName of structUnion mcode * ident option
       | StructUnionDef of fullType * string mcode * annotated_field dots *
           string mcode
@@ -2789,6 +2789,12 @@ module Ast_cocci :
       | ConjField of annotated_field list
       | OptField  of annotated_field
     and annotated_field = base_annotated_field wrap
+    and base_enum_decl =
+      Ast_cocci.base_enum_decl =
+        Enum of ident * (string mcode * expression) option
+      | EnumComma of string mcode
+      | EnumDots of string mcode * enum_decl option
+    and enum_decl = base_enum_decl wrap
     and base_initialiser =
       Ast_cocci.base_initialiser =
         MetaInit of meta_name mcode * constraints * keep_binding * inherited
@@ -3357,7 +3363,7 @@ module Ast0_cocci :
       | Decimal of string mcode * string mcode * expression *
           string mcode option * expression option * string mcode
       | EnumName of string mcode * ident option
-      | EnumDef of typeC * string mcode * expression dots * string mcode
+      | EnumDef of typeC * string mcode * enum_decl dots * string mcode
       | StructUnionName of Ast_cocci.structUnion mcode * ident option
       | StructUnionDef of typeC * string mcode * field dots * string mcode
       | TypeOfExpr of string mcode * string mcode * expression * string mcode
@@ -3408,6 +3414,13 @@ module Ast0_cocci :
       | OptField of field
     and bitfield = string mcode * expression
     and field = base_field wrap
+    and base_enum_decl =
+      Ast0_cocci.base_enum_decl =
+        Enum of ident * (string mcode * expression) option
+      | EnumComma of string mcode
+      | EnumDots of string mcode *
+                    (string mcode * string mcode * enum_decl) option
+    and enum_decl = base_enum_decl wrap
     and base_initialiser =
       Ast0_cocci.base_initialiser =
         MetaInit of Ast_cocci.meta_name mcode * constraints * pure
-- 
2.21.1

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

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

* [Cocci] [PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly
  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 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 04/13] parsing_cocci: Add EnumDeclTag and EnumDeclDotsTag to SmPL ASTs Jaskaran Singh
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The EnumDef constructor of the SmPL AST has changed. Make
the SmPL parser parse an EnumDef correctly.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/parse_aux.ml            |  5 +++++
 parsing_cocci/parse_aux.mli           |  9 +++++++++
 parsing_cocci/parser_cocci_menhir.mly | 13 +++++--------
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/parsing_cocci/parse_aux.ml b/parsing_cocci/parse_aux.ml
index 9f2d607b..b5d1afb4 100644
--- a/parsing_cocci/parse_aux.ml
+++ b/parsing_cocci/parse_aux.ml
@@ -136,6 +136,11 @@ let mkpdots str dot =
     "..." -> Ast0.wrap(Ast0.Pdots(clt2mcode str dot))
   | _ -> failwith "cannot happen"
 
+let mkenumdots str (dot,whencode) =
+  match str with
+    "..." -> Ast0.wrap(Ast0.EnumDots(clt2mcode str dot, whencode))
+  | _ -> failwith "cannot happen"
+
 let arith_op ast_op left op right =
   let op' = Ast0.wrap (Ast0.Arith (clt2mcode ast_op op)) in  
   Ast0.wrap (Ast0.Binary(left, op', right))
diff --git a/parsing_cocci/parse_aux.mli b/parsing_cocci/parse_aux.mli
index 63419831..91d7cb26 100644
--- a/parsing_cocci/parse_aux.mli
+++ b/parsing_cocci/parse_aux.mli
@@ -126,6 +126,15 @@ val mkpdots :
   (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.base_parameterTypeDef Ast0_cocci.wrap
+val mkenumdots :
+  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) *
+  (string Ast0_cocci.mcode * string Ast0_cocci.mcode * Ast0_cocci.enum_decl)
+  option ->
+  Ast0_cocci.base_enum_decl Ast0_cocci.wrap
 val arith_op :
   Ast_cocci.arithOp ->
   Ast0_cocci.expression ->
diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
index 9e6c8a08..ff535729 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -1160,15 +1160,12 @@ struct_decl_list_start:
 /* very restricted what kinds of expressions can appear in an enum decl */
 
 enum_decl_one:
-    | disj_ident    { Ast0.wrap(Ast0.Ident($1)) }
+    | disj_ident    { Ast0.wrap(Ast0.Enum($1, None)) }
     | disj_ident TEq enum_val
-	{ let id = Ast0.wrap(Ast0.Ident($1)) in
-        let (op,clt) = ("=",$2) in
-        let op' = P.clt2mcode op clt in
-        let op'' = Ast0.wrap (Ast0.SimpleAssign op') in
+	{
 	Ast0.wrap
-	  (Ast0.Assignment
-	     (id, op'', Ast0.set_arg_exp $3, false)) }
+	  (Ast0.Enum
+	     ($1, Some(P.clt2mcode "=" $2, $3))) }
 
 enum_val:
    ident    { Ast0.wrap(Ast0.Ident($1)) }
@@ -1193,7 +1190,7 @@ enum_val:
 
 enum_decl_list:
    nonempty_list_start(enum_decl_one,edots_when(TEllipsis,enum_decl_one))
-     { Ast0.wrap($1 P.mkedots (fun c -> Ast0.EComma c)) }
+     { Ast0.wrap($1 P.mkenumdots (fun c -> Ast0.EnumComma c)) }
 
 /*****************************************************************************/
 
-- 
2.21.1

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

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

* [Cocci] [PATCH 04/13] parsing_cocci: Add EnumDeclTag and EnumDeclDotsTag to SmPL ASTs
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (2 preceding siblings ...)
  2020-03-08  8:43 ` [Cocci] [PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly Jaskaran Singh
@ 2020-03-08  8:43 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 05/13] ocaml: coccilib: Reflect EnumDeclTag and EnumDeclDotsTag Jaskaran Singh
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

These constructors are needed by the visitor and various other
functions in the codebase. Maintain consistency and add these
constructs w/r/t changes in the SmPL AST.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/ast0_cocci.ml  | 4 ++++
 parsing_cocci/ast0_cocci.mli | 4 ++++
 parsing_cocci/ast_cocci.ml   | 4 ++++
 parsing_cocci/ast_cocci.mli  | 2 ++
 4 files changed, 14 insertions(+)

diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index b3d8b137..70486e4c 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -553,6 +553,7 @@ and anything =
   | DotsStmtTag of statement dots
   | DotsDeclTag of declaration dots
   | DotsFieldTag of field dots
+  | DotsEnumDeclTag of enum_decl dots
   | DotsCaseTag of case_line dots
   | DotsDefParamTag of define_param dots
   | IdentTag of ident
@@ -566,6 +567,7 @@ and anything =
   | InitTag of initialiser
   | DeclTag of declaration
   | FieldTag of field
+  | EnumDeclTag of enum_decl
   | StmtTag of statement
   | ForInfoTag of forinfo
   | CaseLineTag of case_line
@@ -585,6 +587,7 @@ let dotsInit x = DotsInitTag x
 let dotsStmt x = DotsStmtTag x
 let dotsDecl x = DotsDeclTag x
 let dotsField x = DotsFieldTag x
+let dotsEnumDecl x = DotsEnumDeclTag x
 let dotsCase x = DotsCaseTag x
 let dotsDefParam x = DotsDefParamTag x
 let ident x = IdentTag x
@@ -601,6 +604,7 @@ let forinfo x = ForInfoTag x
 let case_line x = CaseLineTag x
 let string_fragment x = StringFragmentTag x
 let top x = TopTag x
+let enum_decl x = EnumDeclTag x
 
 (* --------------------------------------------------------------------- *)
 (* Avoid cluttering the parser.  Calculated in compute_lines.ml. *)
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 732a1345..7b2a87c4 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -542,6 +542,7 @@ and anything =
   | DotsStmtTag of statement dots
   | DotsDeclTag of declaration dots
   | DotsFieldTag of field dots
+  | DotsEnumDeclTag of enum_decl dots
   | DotsCaseTag of case_line dots
   | DotsDefParamTag of define_param dots
   | IdentTag of ident
@@ -555,6 +556,7 @@ and anything =
   | InitTag of initialiser
   | DeclTag of declaration
   | FieldTag of field
+  | EnumDeclTag of enum_decl
   | StmtTag of statement
   | ForInfoTag of forinfo
   | CaseLineTag of case_line
@@ -574,6 +576,7 @@ val dotsParam : parameterTypeDef dots -> anything
 val dotsStmt : statement dots -> anything
 val dotsDecl : declaration dots -> anything
 val dotsField : field dots -> anything
+val dotsEnumDecl : enum_decl dots -> anything
 val dotsCase : case_line dots -> anything
 val dotsDefParam : define_param dots -> anything
 val ident : ident -> anything
@@ -585,6 +588,7 @@ val param : parameterTypeDef -> anything
 val ini : initialiser -> anything
 val decl : declaration -> anything
 val field : field -> anything
+val enum_decl : enum_decl -> anything
 val stmt : statement -> anything
 val forinfo : forinfo -> anything
 val case_line : case_line -> anything
diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index 8fa64dcc..27942992 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -790,6 +790,7 @@ and anything =
   | LogicalOpTag        of logicalOp
   | DeclarationTag      of declaration
   | FieldTag            of field
+  | EnumDeclTag         of enum_decl
   | InitTag             of initialiser
   | StorageTag          of storage
   | IncFileTag          of inc_file
@@ -807,6 +808,7 @@ and anything =
   | StmtDotsTag         of statement dots
   | AnnDeclDotsTag      of annotated_decl dots
   | AnnFieldDotsTag     of annotated_field dots
+  | EnumDeclDotsTag     of enum_decl dots
   | DefParDotsTag       of define_param dots
   | TypeCTag            of typeC
   | ParamTag            of parameterTypeDef
@@ -932,6 +934,7 @@ and tag2c = function
   | LogicalOpTag _ -> "LogicalOpTag"
   | DeclarationTag _ -> "DeclarationTag"
   | FieldTag _ -> "FieldTag"
+  | EnumDeclTag _ -> "EnumDeclTag"
   | InitTag _      -> "InitTag"
   | StorageTag _   -> "StorageTag"
   | IncFileTag _   -> "IncFileTag"
@@ -949,6 +952,7 @@ and tag2c = function
   | StmtDotsTag _ -> "StmtDotsTag"
   | AnnDeclDotsTag _ -> "AnnDeclDotsTag"
   | AnnFieldDotsTag _ -> "AnnFieldDotsTag"
+  | EnumDeclDotsTag _ -> "EnumDeclDotsTag"
   | DefParDotsTag _ -> "DefParDotsTag"
   | TypeCTag _ -> "TypeCTag"
   | ParamTag _ -> "ParamTag"
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index e921f917..8316a427 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -759,6 +759,7 @@ and anything =
   | LogicalOpTag        of logicalOp
   | DeclarationTag      of declaration
   | FieldTag            of field
+  | EnumDeclTag         of enum_decl
   | InitTag             of initialiser
   | StorageTag          of storage
   | IncFileTag          of inc_file
@@ -776,6 +777,7 @@ and anything =
   | StmtDotsTag         of statement dots
   | AnnDeclDotsTag      of annotated_decl dots
   | AnnFieldDotsTag     of annotated_field dots
+  | EnumDeclDotsTag     of enum_decl dots
   | DefParDotsTag       of define_param dots
   | TypeCTag            of typeC
   | ParamTag            of parameterTypeDef
-- 
2.21.1

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

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

* [Cocci] [PATCH 05/13] ocaml: coccilib: Reflect EnumDeclTag and EnumDeclDotsTag
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (3 preceding siblings ...)
  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 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 06/13] parsing_cocci: visitor_ast0: Add visitor functions for enum_decl Jaskaran Singh
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The SmPL AST now has these constructors. Reflect these changes in
coccilib.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 ocaml/coccilib.mli | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 9b00e130..d01d2a93 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -3056,6 +3056,7 @@ module Ast_cocci :
       | LogicalOpTag of logicalOp
       | DeclarationTag of declaration
       | FieldTag of field
+      | EnumDeclTag of enum_decl
       | InitTag of initialiser
       | StorageTag of storage
       | IncFileTag of inc_file
@@ -3073,6 +3074,7 @@ module Ast_cocci :
       | StmtDotsTag of statement dots
       | AnnDeclDotsTag of annotated_decl dots
       | AnnFieldDotsTag of annotated_field dots
+      | EnumDeclDotsTag of enum_decl dots
       | DefParDotsTag of define_param dots
       | TypeCTag of typeC
       | ParamTag of parameterTypeDef
@@ -3621,6 +3623,7 @@ module Ast0_cocci :
       | DotsStmtTag of statement dots
       | DotsDeclTag of declaration dots
       | DotsFieldTag of field dots
+      | DotsEnumDeclTag of enum_decl dots
       | DotsCaseTag of case_line dots
       | DotsDefParamTag of define_param dots
       | IdentTag of ident
@@ -3634,6 +3637,7 @@ module Ast0_cocci :
       | InitTag of initialiser
       | DeclTag of declaration
       | FieldTag of field
+      | EnumDeclTag of enum_decl
       | StmtTag of statement
       | ForInfoTag of forinfo
       | CaseLineTag of case_line
@@ -3651,6 +3655,7 @@ module Ast0_cocci :
     val dotsStmt : statement dots -> anything
     val dotsDecl : declaration dots -> anything
     val dotsField : field dots -> anything
+    val dotsEnumDecl : enum_decl dots -> anything
     val dotsCase : case_line dots -> anything
     val dotsDefParam : define_param dots -> anything
     val ident : ident -> anything
-- 
2.21.1

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

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

* [Cocci] [PATCH 06/13] parsing_cocci: visitor_ast0: Add visitor functions for enum_decl
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (4 preceding siblings ...)
  2020-03-08  8:43 ` [Cocci] [PATCH 05/13] ocaml: coccilib: Reflect EnumDeclTag and EnumDeclDotsTag Jaskaran Singh
@ 2020-03-08  8:43 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in parsing_cocci Jaskaran Singh
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

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

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/visitor_ast0.ml        | 72 ++++++++++++++++++++++++++--
 parsing_cocci/visitor_ast0.mli       |  4 ++
 parsing_cocci/visitor_ast0_types.ml  | 14 ++++++
 parsing_cocci/visitor_ast0_types.mli | 12 +++++
 4 files changed, 98 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index c282e1f8..e4ac82bc 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -22,8 +22,9 @@ let visitor mode bind option_default
     fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode
     struct_mcode storage_mcode inc_mcode
     dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
-    dotscasefn dotsdefparfn
+    dotsenumdeclfn dotscasefn dotsdefparfn
     identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
+    enumdeclfn
     stmtfn forinfofn casefn string_fragmentfn topfn =
   let multibind l =
     let rec loop = function
@@ -63,6 +64,7 @@ let visitor mode bind option_default
   and statement_dots d = dotsfn dotsstmtfn statement all_functions d
   and declaration_dots d = dotsfn dotsdeclfn declaration all_functions d
   and field_dots d = dotsfn dotsfieldfn field all_functions d
+  and enum_decl_dots d = dotsfn dotsenumdeclfn enum_decl all_functions d
   and case_line_dots d = dotsfn dotscasefn case_line 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
@@ -358,7 +360,7 @@ let visitor mode bind option_default
 	| Ast0.EnumDef(ty,lb,ids,rb) ->
 	    let (ty_n,ty) = typeC ty in
 	    let (lb_n,lb) = string_mcode lb in
-	    let (ids_n,ids) = expression_dots ids in
+	    let (ids_n,ids) = enum_decl_dots ids in
 	    let (rb_n,rb) = string_mcode rb in
 	    (multibind [ty_n;lb_n;ids_n;rb_n], Ast0.EnumDef(ty,lb,ids,rb))
 	| Ast0.StructUnionName(kind,name) ->
@@ -622,6 +624,34 @@ let visitor mode bind option_default
 	    let (n,decl) = field decl in (n,Ast0.OptField(decl))) in
     fieldfn all_functions k d
 
+  and enum_decl d =
+    let k d =
+      rewrap d
+	(match Ast0.unwrap d with
+	  Ast0.Enum(name,enum_val) ->
+	    let (name_n,name) = ident name in
+            (match enum_val with
+              None -> (name_n,Ast0.Enum(name,None))
+            | Some(eq,eval) ->
+                let (eq_n,eq) = string_mcode eq in
+                let (eval_n,eval) = expression eval in
+                (multibind [name_n; eq_n; eval_n],
+                 Ast0.Enum(name,Some(eq,eval))))
+	| Ast0.EnumComma(cm) ->
+	    let (cm_n,cm) = string_mcode cm in
+	    (cm_n,Ast0.EnumComma(cm))
+	| Ast0.EnumDots(dots,whencode) ->
+	    let (dots_n,dots) = string_mcode dots in
+	    let (whencode_n, whencode) = match whencode with
+              | Some (a,b,c) ->
+                  let (_,a2) = string_mcode a in
+                  let (_,b2) = string_mcode b in
+                  let (c1,c2) = enum_decl c in (c1, Some (a2,b2,c2))
+              | None -> (option_default, None) in
+	    (bind dots_n whencode_n, Ast0.EnumDots(dots,whencode))) in
+    enumdeclfn all_functions k d
+
+
   and initialiser i =
     let k i =
       rewrap i
@@ -1121,6 +1151,9 @@ let visitor mode bind option_default
       | Ast0.DotsFieldTag(decls) ->
 	  let (decls_n,decls) = field_dots decls in
 	  (decls_n,Ast0.DotsFieldTag(decls))
+      | Ast0.DotsEnumDeclTag(decls) ->
+	  let (decls_n,decls) = enum_decl_dots decls in
+	  (decls_n,Ast0.DotsEnumDeclTag(decls))
       | Ast0.DotsCaseTag(cases) ->
 	  let (cases_n,cases) = case_line_dots cases in
 	  (cases_n,Ast0.DotsCaseTag(cases))
@@ -1160,6 +1193,9 @@ let visitor mode bind option_default
       | Ast0.FieldTag(decl) ->
 	  let (decl_n,decl) = field decl in
 	  (decl_n,Ast0.FieldTag(decl))
+      | Ast0.EnumDeclTag(decl) ->
+	  let (decl_n,decl) = enum_decl decl in
+	  (decl_n,Ast0.EnumDeclTag(decl))
       | Ast0.StmtTag(stmt) ->
 	  let (stmt_n,stmt) = statement stmt in
 	  (stmt_n,Ast0.StmtTag(stmt))
@@ -1204,6 +1240,7 @@ let visitor mode bind option_default
       VT0.typeC = typeC;
       VT0.declaration = declaration;
       VT0.field = field;
+      VT0.enum_decl = enum_decl;
       VT0.initialiser = initialiser;
       VT0.initialiser_list = initialiser_dots;
       VT0.parameter = parameterTypeDef;
@@ -1218,6 +1255,7 @@ let visitor mode bind option_default
       VT0.statement_dots = statement_dots;
       VT0.declaration_dots = declaration_dots;
       VT0.field_dots = field_dots;
+      VT0.enum_decl_dots = enum_decl_dots;
       VT0.case_line_dots = case_line_dots;
       VT0.define_param_dots = define_param_dots;
       VT0.anything = anything} in
@@ -1244,6 +1282,7 @@ let combiner_functions =
    VT0.combiner_dotsstmtfn = (fun r k e -> k e);
    VT0.combiner_dotsdeclfn = (fun r k e -> k e);
    VT0.combiner_dotsfieldfn = (fun r k e -> k e);
+   VT0.combiner_dotsenumdeclfn = (fun r k e -> k e);
    VT0.combiner_dotscasefn = (fun r k e -> k e);
    VT0.combiner_dotsdefparfn = (fun r k e -> k e);
    VT0.combiner_identfn = (fun r k e -> k e);
@@ -1255,6 +1294,7 @@ let combiner_functions =
    VT0.combiner_paramfn = (fun r k e -> k e);
    VT0.combiner_declfn = (fun r k e -> k e);
    VT0.combiner_fieldfn = (fun r k e -> k e);
+   VT0.combiner_enumdeclfn = (fun r k e -> k e);
    VT0.combiner_stmtfn = (fun r k e -> k e);
    VT0.combiner_forinfofn = (fun r k e -> k e);
    VT0.combiner_casefn = (fun r k e -> k e);
@@ -1278,6 +1318,8 @@ let combiner_dz r =
       (function e -> let (n,_) = r.VT0.declaration e in n);
       VT0.combiner_rec_field =
       (function e -> let (n,_) = r.VT0.field e in n);
+      VT0.combiner_rec_enumdecl =
+      (function e -> let (n,_) = r.VT0.enum_decl e in n);
       VT0.combiner_rec_initialiser =
       (function e -> let (n,_) = r.VT0.initialiser e in n);
       VT0.combiner_rec_initialiser_list =
@@ -1306,6 +1348,8 @@ let combiner_dz r =
       (function e -> let (n,_) = r.VT0.declaration_dots e in n);
       VT0.combiner_rec_field_dots =
       (function e -> let (n,_) = r.VT0.field_dots e in n);
+      VT0.combiner_rec_enum_decl_dots =
+      (function e -> let (n,_) = r.VT0.enum_decl_dots e in n);
       VT0.combiner_rec_case_line_dots =
       (function e -> let (n,_) = r.VT0.case_line_dots e in n);
       VT0.combiner_rec_define_param_dots =
@@ -1343,6 +1387,7 @@ let combiner bind option_default functions =
     (fun r k e -> (functions.VT0.combiner_dotsstmtfn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_dotsdeclfn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_dotsfieldfn (dz r) (xk k) e, e))
+    (fun r k e -> (functions.VT0.combiner_dotsenumdeclfn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_dotscasefn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_dotsdefparfn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_identfn (dz r) (xk k) e, e))
@@ -1354,6 +1399,7 @@ let combiner bind option_default functions =
     (fun r k e -> (functions.VT0.combiner_paramfn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_declfn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_fieldfn (dz r) (xk k) e, e))
+    (fun r k e -> (functions.VT0.combiner_enumdeclfn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_stmtfn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_forinfofn (dz r) (xk k) e, e))
     (fun r k e -> (functions.VT0.combiner_casefn (dz r) (xk k) e, e))
@@ -1365,8 +1411,9 @@ let flat_combiner bind option_default
     fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode
     struct_mcode storage_mcode inc_mcode
     dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
-    dotscasefn dotsdefparfn
+    dotsenumdeclfn dotscasefn dotsdefparfn
     identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
+    enumdeclfn
     stmtfn forinfofn casefn string_fragmentfn topfn =
   let dz = combiner_dz in
   let xk k e = let (n,_) = k e in n in
@@ -1391,6 +1438,7 @@ let flat_combiner bind option_default
     (fun r k e -> (dotsstmtfn (dz r) (xk k) e, e))
     (fun r k e -> (dotsdeclfn (dz r) (xk k) e, e))
     (fun r k e -> (dotsfieldfn (dz r) (xk k) e, e))
+    (fun r k e -> (dotsenumdeclfn (dz r) (xk k) e, e))
     (fun r k e -> (dotscasefn (dz r) (xk k) e, e))
     (fun r k e -> (dotsdefparfn (dz r) (xk k) e, e))
     (fun r k e -> (identfn (dz r) (xk k) e, e))
@@ -1402,6 +1450,7 @@ let flat_combiner bind option_default
     (fun r k e -> (paramfn (dz r) (xk k) e, e))
     (fun r k e -> (declfn (dz r) (xk k) e, e))
     (fun r k e -> (fieldfn (dz r) (xk k) e, e))
+    (fun r k e -> (enumdeclfn (dz r) (xk k) e, e))
     (fun r k e -> (stmtfn (dz r) (xk k) e, e))
     (fun r k e -> (forinfofn (dz r) (xk k) e, e))
     (fun r k e -> (casefn (dz r) (xk k) e, e))
@@ -1429,6 +1478,7 @@ let rebuilder_functions =
    VT0.rebuilder_dotsstmtfn = (fun r k e -> k e);
    VT0.rebuilder_dotsdeclfn = (fun r k e -> k e);
    VT0.rebuilder_dotsfieldfn = (fun r k e -> k e);
+   VT0.rebuilder_dotsenumdeclfn = (fun r k e -> k e);
    VT0.rebuilder_dotscasefn = (fun r k e -> k e);
    VT0.rebuilder_dotsdefparfn = (fun r k e -> k e);
    VT0.rebuilder_identfn = (fun r k e -> k e);
@@ -1440,6 +1490,7 @@ let rebuilder_functions =
    VT0.rebuilder_paramfn = (fun r k e -> k e);
    VT0.rebuilder_declfn = (fun r k e -> k e);
    VT0.rebuilder_fieldfn = (fun r k e -> k e);
+   VT0.rebuilder_enumdeclfn = (fun r k e -> k e);
    VT0.rebuilder_stmtfn = (fun r k e -> k e);
    VT0.rebuilder_forinfofn = (fun r k e -> k e);
    VT0.rebuilder_casefn = (fun r k e -> k e);
@@ -1463,6 +1514,8 @@ let rebuilder_dz r =
       (function e -> let (_,e) = r.VT0.declaration e in e);
       VT0.rebuilder_rec_field =
       (function e -> let (_,e) = r.VT0.field e in e);
+      VT0.rebuilder_rec_enumdecl =
+      (function e -> let (_,e) = r.VT0.enum_decl e in e);
       VT0.rebuilder_rec_initialiser =
       (function e -> let (_,e) = r.VT0.initialiser e in e);
       VT0.rebuilder_rec_initialiser_list =
@@ -1489,6 +1542,8 @@ let rebuilder_dz r =
       (function e -> let (_,e) = r.VT0.declaration_dots e in e);
       VT0.rebuilder_rec_field_dots =
       (function e -> let (_,e) = r.VT0.field_dots e in e);
+      VT0.rebuilder_rec_enum_decl_dots =
+      (function e -> let (_,e) = r.VT0.enum_decl_dots e in e);
       VT0.rebuilder_rec_case_line_dots =
       (function e -> let (_,e) = r.VT0.case_line_dots e in e);
       VT0.rebuilder_rec_define_param_dots =
@@ -1521,6 +1576,7 @@ let rebuilder functions =
     (fun r k e -> ((),functions.VT0.rebuilder_dotsstmtfn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_dotsdeclfn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_dotsfieldfn (dz r) (xk k) e))
+    (fun r k e -> ((),functions.VT0.rebuilder_dotsenumdeclfn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_dotscasefn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_dotsdefparfn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_identfn (dz r) (xk k) e))
@@ -1532,6 +1588,7 @@ let rebuilder functions =
     (fun r k e -> ((),functions.VT0.rebuilder_paramfn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_declfn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_fieldfn (dz r) (xk k) e))
+    (fun r k e -> ((),functions.VT0.rebuilder_enumdeclfn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_stmtfn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_forinfofn (dz r) (xk k) e))
     (fun r k e -> ((),functions.VT0.rebuilder_casefn (dz r) (xk k) e))
@@ -1545,8 +1602,9 @@ let flat_rebuilder
     arithOp_mcode logicalOp_mcode cv_mcode sign_mcode struct_mcode
     storage_mcode inc_mcode
     dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
-    dotscasefn dotsdefparfn
+    dotsenumdeclfn dotscasefn dotsdefparfn
     identfn exprfn assignOpfn arithOpfn tyfn initfn paramfn declfn fieldfn
+    enumdeclfn
     stmtfn forinfofn casefn string_fragmentfn topfn =
   let dz = rebuilder_dz in
   let xk k e = let (_,e) = k e in e in
@@ -1572,6 +1630,7 @@ let flat_rebuilder
     (fun r k e -> ((),dotsstmtfn (dz r) (xk k) e))
     (fun r k e -> ((),dotsdeclfn (dz r) (xk k) e))
     (fun r k e -> ((),dotsfieldfn (dz r) (xk k) e))
+    (fun r k e -> ((),dotsenumdeclfn (dz r) (xk k) e))
     (fun r k e -> ((),dotscasefn (dz r) (xk k) e))
     (fun r k e -> ((),dotsdefparfn (dz r) (xk k) e))
     (fun r k e -> ((),identfn (dz r) (xk k) e))
@@ -1583,6 +1642,7 @@ let flat_rebuilder
     (fun r k e -> ((),paramfn (dz r) (xk k) e))
     (fun r k e -> ((),declfn (dz r) (xk k) e))
     (fun r k e -> ((),fieldfn (dz r) (xk k) e))
+    (fun r k e -> ((),enumdeclfn (dz r) (xk k) e))
     (fun r k e -> ((),stmtfn (dz r) (xk k) e))
     (fun r k e -> ((),forinfofn (dz r) (xk k) e))
     (fun r k e -> ((),casefn (dz r) (xk k) e))
@@ -1624,6 +1684,7 @@ let combiner_rebuilder_functions =
    VT0.combiner_rebuilder_dotsstmtfn = (fun r k e -> k e);
    VT0.combiner_rebuilder_dotsdeclfn = (fun r k e -> k e);
    VT0.combiner_rebuilder_dotsfieldfn = (fun r k e -> k e);
+   VT0.combiner_rebuilder_dotsenumdeclfn = (fun r k e -> k e);
    VT0.combiner_rebuilder_dotscasefn = (fun r k e -> k e);
    VT0.combiner_rebuilder_dotsdefparfn = (fun r k e -> k e);
    VT0.combiner_rebuilder_identfn = (fun r k e -> k e);
@@ -1635,6 +1696,7 @@ let combiner_rebuilder_functions =
    VT0.combiner_rebuilder_paramfn = (fun r k e -> k e);
    VT0.combiner_rebuilder_declfn = (fun r k e -> k e);
    VT0.combiner_rebuilder_fieldfn = (fun r k e -> k e);
+   VT0.combiner_rebuilder_enumdeclfn = (fun r k e -> k e);
    VT0.combiner_rebuilder_stmtfn = (fun r k e -> k e);
    VT0.combiner_rebuilder_forinfofn = (fun r k e -> k e);
    VT0.combiner_rebuilder_casefn = (fun r k e -> k e);
@@ -1663,6 +1725,7 @@ let combiner_rebuilder bind option_default functions =
     functions.VT0.combiner_rebuilder_dotsstmtfn
     functions.VT0.combiner_rebuilder_dotsdeclfn
     functions.VT0.combiner_rebuilder_dotsfieldfn
+    functions.VT0.combiner_rebuilder_dotsenumdeclfn
     functions.VT0.combiner_rebuilder_dotscasefn
     functions.VT0.combiner_rebuilder_dotsdefparfn
     functions.VT0.combiner_rebuilder_identfn
@@ -1674,6 +1737,7 @@ let combiner_rebuilder bind option_default functions =
     functions.VT0.combiner_rebuilder_paramfn
     functions.VT0.combiner_rebuilder_declfn
     functions.VT0.combiner_rebuilder_fieldfn
+    functions.VT0.combiner_rebuilder_enumdeclfn
     functions.VT0.combiner_rebuilder_stmtfn
     functions.VT0.combiner_rebuilder_forinfofn
     functions.VT0.combiner_rebuilder_casefn
diff --git a/parsing_cocci/visitor_ast0.mli b/parsing_cocci/visitor_ast0.mli
index 5784e9e6..e801c983 100644
--- a/parsing_cocci/visitor_ast0.mli
+++ b/parsing_cocci/visitor_ast0.mli
@@ -33,6 +33,7 @@ val flat_combiner :
     ((Ast0_cocci.statement Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.declaration Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.field Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) ->
+    ((Ast0_cocci.enum_decl Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.case_line Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.define_param Ast0_cocci.dots,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.ident,'a) Visitor_ast0_types.ccode) ->
@@ -44,6 +45,7 @@ val flat_combiner :
     ((Ast0_cocci.parameterTypeDef,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.declaration,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.field,'a) Visitor_ast0_types.ccode) ->
+    ((Ast0_cocci.enum_decl,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.statement,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.forinfo,'a) Visitor_ast0_types.ccode) ->
     ((Ast0_cocci.case_line,'a) Visitor_ast0_types.ccode) ->
@@ -76,6 +78,7 @@ val flat_rebuilder :
     (Ast0_cocci.statement Ast0_cocci.dots Visitor_ast0_types.rcode) ->
     (Ast0_cocci.declaration Ast0_cocci.dots Visitor_ast0_types.rcode) ->
     (Ast0_cocci.field Ast0_cocci.dots Visitor_ast0_types.rcode) ->
+    (Ast0_cocci.enum_decl Ast0_cocci.dots Visitor_ast0_types.rcode) ->
     (Ast0_cocci.case_line Ast0_cocci.dots Visitor_ast0_types.rcode) ->
     (Ast0_cocci.define_param Ast0_cocci.dots Visitor_ast0_types.rcode) ->
     (Ast0_cocci.ident Visitor_ast0_types.rcode) ->
@@ -87,6 +90,7 @@ val flat_rebuilder :
     (Ast0_cocci.parameterTypeDef Visitor_ast0_types.rcode) ->
     (Ast0_cocci.declaration Visitor_ast0_types.rcode) ->
     (Ast0_cocci.field Visitor_ast0_types.rcode) ->
+    (Ast0_cocci.enum_decl Visitor_ast0_types.rcode) ->
     (Ast0_cocci.statement Visitor_ast0_types.rcode) ->
     (Ast0_cocci.forinfo Visitor_ast0_types.rcode) ->
     (Ast0_cocci.case_line Visitor_ast0_types.rcode) ->
diff --git a/parsing_cocci/visitor_ast0_types.ml b/parsing_cocci/visitor_ast0_types.ml
index c24a0c0a..7a00c702 100644
--- a/parsing_cocci/visitor_ast0_types.ml
+++ b/parsing_cocci/visitor_ast0_types.ml
@@ -18,6 +18,7 @@ type 'n all_functions =
       typeC : (Ast0.typeC,'n) inout;
       declaration : (Ast0.declaration,'n) inout;
       field : (Ast0.field,'n) inout;
+      enum_decl : (Ast0.enum_decl,'n) inout;
       initialiser : (Ast0.initialiser,'n) inout;
       initialiser_list : (Ast0.initialiser_list,'n) inout;
       parameter : (Ast0.parameterTypeDef,'n) inout;
@@ -32,6 +33,7 @@ type 'n all_functions =
       statement_dots : (Ast0.statement Ast0.dots,'n) inout;
       declaration_dots : (Ast0.declaration Ast0.dots,'n) inout;
       field_dots : (Ast0.field Ast0.dots,'n) inout;
+      enum_decl_dots : (Ast0.enum_decl Ast0.dots,'n) inout;
       case_line_dots : (Ast0.case_line Ast0.dots,'n) inout;
       define_param_dots : (Ast0.define_param Ast0.dots,'n) inout;
       anything : (Ast0.anything,'n) inout}
@@ -50,6 +52,7 @@ type 'n combiner_rec_functions =
       combiner_rec_typeC : (Ast0.typeC,'n) combiner_inout;
       combiner_rec_declaration : (Ast0.declaration,'n) combiner_inout;
       combiner_rec_field : (Ast0.field,'n) combiner_inout;
+      combiner_rec_enumdecl : (Ast0.enum_decl,'n) combiner_inout;
       combiner_rec_initialiser : (Ast0.initialiser,'n) combiner_inout;
       combiner_rec_initialiser_list :
 	(Ast0.initialiser_list,'n) combiner_inout;
@@ -69,6 +72,8 @@ type 'n combiner_rec_functions =
 	(Ast0.declaration Ast0.dots,'n) combiner_inout;
       combiner_rec_field_dots :
 	(Ast0.field Ast0.dots,'n) combiner_inout;
+      combiner_rec_enum_decl_dots :
+	(Ast0.enum_decl Ast0.dots,'n) combiner_inout;
       combiner_rec_case_line_dots :
 	(Ast0.case_line Ast0.dots,'n) combiner_inout;
       combiner_rec_define_param_dots :
@@ -100,6 +105,7 @@ type 'n combiner_functions =
    combiner_dotsstmtfn : (Ast0.statement Ast0.dots,'n) ccode;
    combiner_dotsdeclfn : (Ast0.declaration Ast0.dots,'n) ccode;
    combiner_dotsfieldfn : (Ast0.field Ast0.dots,'n) ccode;
+   combiner_dotsenumdeclfn : (Ast0.enum_decl Ast0.dots,'n) ccode;
    combiner_dotscasefn : (Ast0.case_line Ast0.dots,'n) ccode;
    combiner_dotsdefparfn : (Ast0.define_param Ast0.dots,'n) ccode;
    combiner_identfn : (Ast0.ident,'n) ccode;
@@ -111,6 +117,7 @@ type 'n combiner_functions =
    combiner_paramfn : (Ast0.parameterTypeDef,'n) ccode;
    combiner_declfn : (Ast0.declaration,'n) ccode;
    combiner_fieldfn : (Ast0.field,'n) ccode;
+   combiner_enumdeclfn : (Ast0.enum_decl,'n) ccode;
    combiner_stmtfn : (Ast0.statement,'n) ccode;
    combiner_forinfofn : (Ast0.forinfo,'n) ccode;
    combiner_casefn : (Ast0.case_line,'n) ccode;
@@ -131,6 +138,7 @@ type rebuilder_rec_functions =
       rebuilder_rec_typeC : Ast0.typeC rebuilder_inout;
       rebuilder_rec_declaration : Ast0.declaration rebuilder_inout;
       rebuilder_rec_field : Ast0.field rebuilder_inout;
+      rebuilder_rec_enumdecl : Ast0.enum_decl rebuilder_inout;
       rebuilder_rec_initialiser : Ast0.initialiser rebuilder_inout;
       rebuilder_rec_initialiser_list :
 	Ast0.initialiser_list rebuilder_inout;
@@ -149,6 +157,8 @@ type rebuilder_rec_functions =
 	Ast0.declaration Ast0.dots rebuilder_inout;
       rebuilder_rec_field_dots :
 	Ast0.field Ast0.dots rebuilder_inout;
+      rebuilder_rec_enum_decl_dots :
+	Ast0.enum_decl Ast0.dots rebuilder_inout;
       rebuilder_rec_case_line_dots :
 	Ast0.case_line Ast0.dots rebuilder_inout;
       rebuilder_rec_define_param_dots :
@@ -180,6 +190,7 @@ type rebuilder_functions =
    rebuilder_dotsstmtfn : Ast0.statement Ast0.dots rcode;
    rebuilder_dotsdeclfn : Ast0.declaration Ast0.dots rcode;
    rebuilder_dotsfieldfn : Ast0.field Ast0.dots rcode;
+   rebuilder_dotsenumdeclfn : Ast0.enum_decl Ast0.dots rcode;
    rebuilder_dotscasefn : Ast0.case_line Ast0.dots rcode;
    rebuilder_dotsdefparfn : Ast0.define_param Ast0.dots rcode;
    rebuilder_identfn : Ast0.ident rcode;
@@ -192,6 +203,7 @@ type rebuilder_functions =
    rebuilder_paramfn : Ast0.parameterTypeDef rcode;
    rebuilder_declfn : Ast0.declaration rcode;
    rebuilder_fieldfn : Ast0.field rcode;
+   rebuilder_enumdeclfn : Ast0.enum_decl rcode;
    rebuilder_stmtfn : Ast0.statement rcode;
    rebuilder_forinfofn : Ast0.forinfo rcode;
    rebuilder_casefn : Ast0.case_line rcode;
@@ -227,6 +239,7 @@ type 'n combiner_rebuilder_functions =
    combiner_rebuilder_dotsstmtfn : (Ast0.statement Ast0.dots,'n) rccode;
    combiner_rebuilder_dotsdeclfn : (Ast0.declaration Ast0.dots,'n) rccode;
    combiner_rebuilder_dotsfieldfn : (Ast0.field Ast0.dots,'n) rccode;
+   combiner_rebuilder_dotsenumdeclfn : (Ast0.enum_decl Ast0.dots,'n) rccode;
    combiner_rebuilder_dotscasefn : (Ast0.case_line Ast0.dots,'n) rccode;
    combiner_rebuilder_dotsdefparfn : (Ast0.define_param Ast0.dots,'n) rccode;
    combiner_rebuilder_identfn : (Ast0.ident,'n) rccode;
@@ -238,6 +251,7 @@ type 'n combiner_rebuilder_functions =
    combiner_rebuilder_paramfn : (Ast0.parameterTypeDef,'n) rccode;
    combiner_rebuilder_declfn : (Ast0.declaration,'n) rccode;
    combiner_rebuilder_fieldfn : (Ast0.field,'n) rccode;
+   combiner_rebuilder_enumdeclfn : (Ast0.enum_decl,'n) rccode;
    combiner_rebuilder_stmtfn : (Ast0.statement,'n) rccode;
    combiner_rebuilder_forinfofn : (Ast0.forinfo,'n) rccode;
    combiner_rebuilder_casefn : (Ast0.case_line,'n) rccode;
diff --git a/parsing_cocci/visitor_ast0_types.mli b/parsing_cocci/visitor_ast0_types.mli
index 78e3b804..d06baaf7 100644
--- a/parsing_cocci/visitor_ast0_types.mli
+++ b/parsing_cocci/visitor_ast0_types.mli
@@ -8,6 +8,7 @@ type 'n all_functions = {
   typeC : (Ast0_cocci.typeC, 'n) inout;
   declaration : (Ast0_cocci.declaration, 'n) inout;
   field : (Ast0_cocci.field, 'n) inout;
+  enum_decl : (Ast0_cocci.enum_decl,'n) inout;
   initialiser : (Ast0_cocci.initialiser, 'n) inout;
   initialiser_list : (Ast0_cocci.initialiser_list, 'n) inout;
   parameter : (Ast0_cocci.parameterTypeDef, 'n) inout;
@@ -22,6 +23,7 @@ type 'n all_functions = {
   statement_dots : (Ast0_cocci.statement Ast0_cocci.dots, 'n) inout;
   declaration_dots : (Ast0_cocci.declaration Ast0_cocci.dots, 'n) inout;
   field_dots : (Ast0_cocci.field Ast0_cocci.dots, 'n) inout;
+  enum_decl_dots : (Ast0_cocci.enum_decl Ast0_cocci.dots, 'n) inout;
   case_line_dots : (Ast0_cocci.case_line Ast0_cocci.dots, 'n) inout;
   define_param_dots : (Ast0_cocci.define_param Ast0_cocci.dots, 'n) inout;
   anything : (Ast0_cocci.anything, 'n) inout;
@@ -36,6 +38,7 @@ type 'n combiner_rec_functions = {
   combiner_rec_typeC : (Ast0_cocci.typeC, 'n) combiner_inout;
   combiner_rec_declaration : (Ast0_cocci.declaration, 'n) combiner_inout;
   combiner_rec_field : (Ast0_cocci.field, 'n) combiner_inout;
+  combiner_rec_enumdecl : (Ast0_cocci.enum_decl,'n) combiner_inout;
   combiner_rec_initialiser : (Ast0_cocci.initialiser, 'n) combiner_inout;
   combiner_rec_initialiser_list : (Ast0_cocci.initialiser_list, 'n) combiner_inout;
   combiner_rec_parameter : (Ast0_cocci.parameterTypeDef, 'n) combiner_inout;
@@ -52,6 +55,7 @@ type 'n combiner_rec_functions = {
   combiner_rec_declaration_dots :
     (Ast0_cocci.declaration Ast0_cocci.dots, 'n) combiner_inout;
   combiner_rec_field_dots : (Ast0_cocci.field Ast0_cocci.dots, 'n) combiner_inout;
+  combiner_rec_enum_decl_dots : (Ast0_cocci.enum_decl Ast0_cocci.dots, 'n) combiner_inout;
   combiner_rec_case_line_dots : (Ast0_cocci.case_line Ast0_cocci.dots, 'n) combiner_inout;
   combiner_rec_define_param_dots :
     (Ast0_cocci.define_param Ast0_cocci.dots, 'n) combiner_inout;
@@ -81,6 +85,7 @@ type 'n combiner_functions = {
   combiner_dotsstmtfn : (Ast0_cocci.statement Ast0_cocci.dots, 'n) ccode;
   combiner_dotsdeclfn : (Ast0_cocci.declaration Ast0_cocci.dots, 'n) ccode;
   combiner_dotsfieldfn : (Ast0_cocci.field Ast0_cocci.dots, 'n) ccode;
+  combiner_dotsenumdeclfn : (Ast0_cocci.enum_decl Ast0_cocci.dots, 'n) ccode;
   combiner_dotscasefn : (Ast0_cocci.case_line Ast0_cocci.dots, 'n) ccode;
   combiner_dotsdefparfn : (Ast0_cocci.define_param Ast0_cocci.dots, 'n) ccode;
   combiner_identfn : (Ast0_cocci.ident, 'n) ccode;
@@ -92,6 +97,7 @@ type 'n combiner_functions = {
   combiner_paramfn : (Ast0_cocci.parameterTypeDef, 'n) ccode;
   combiner_declfn : (Ast0_cocci.declaration, 'n) ccode;
   combiner_fieldfn : (Ast0_cocci.field, 'n) ccode;
+  combiner_enumdeclfn : (Ast0_cocci.enum_decl,'n) ccode;
   combiner_stmtfn : (Ast0_cocci.statement, 'n) ccode;
   combiner_forinfofn : (Ast0_cocci.forinfo, 'n) ccode;
   combiner_casefn : (Ast0_cocci.case_line, 'n) ccode;
@@ -108,6 +114,7 @@ type rebuilder_rec_functions = {
   rebuilder_rec_typeC : Ast0_cocci.typeC rebuilder_inout;
   rebuilder_rec_declaration : Ast0_cocci.declaration rebuilder_inout;
   rebuilder_rec_field : Ast0_cocci.field rebuilder_inout;
+  rebuilder_rec_enumdecl : Ast0_cocci.enum_decl rebuilder_inout;
   rebuilder_rec_initialiser : Ast0_cocci.initialiser rebuilder_inout;
   rebuilder_rec_initialiser_list : Ast0_cocci.initialiser_list rebuilder_inout;
   rebuilder_rec_parameter : Ast0_cocci.parameterTypeDef rebuilder_inout;
@@ -121,6 +128,7 @@ type rebuilder_rec_functions = {
   rebuilder_rec_statement_dots : Ast0_cocci.statement Ast0_cocci.dots rebuilder_inout;
   rebuilder_rec_declaration_dots : Ast0_cocci.declaration Ast0_cocci.dots rebuilder_inout;
   rebuilder_rec_field_dots : Ast0_cocci.field Ast0_cocci.dots rebuilder_inout;
+  rebuilder_rec_enum_decl_dots : Ast0_cocci.enum_decl Ast0_cocci.dots rebuilder_inout;
   rebuilder_rec_case_line_dots : Ast0_cocci.case_line Ast0_cocci.dots rebuilder_inout;
   rebuilder_rec_define_param_dots :
     Ast0_cocci.define_param Ast0_cocci.dots rebuilder_inout;
@@ -150,6 +158,7 @@ type rebuilder_functions = {
   rebuilder_dotsstmtfn : Ast0_cocci.statement Ast0_cocci.dots rcode;
   rebuilder_dotsdeclfn : Ast0_cocci.declaration Ast0_cocci.dots rcode;
   rebuilder_dotsfieldfn : Ast0_cocci.field Ast0_cocci.dots rcode;
+  rebuilder_dotsenumdeclfn : Ast0_cocci.enum_decl Ast0_cocci.dots rcode;
   rebuilder_dotscasefn : Ast0_cocci.case_line Ast0_cocci.dots rcode;
   rebuilder_dotsdefparfn : Ast0_cocci.define_param Ast0_cocci.dots rcode;
   rebuilder_identfn : Ast0_cocci.ident rcode;
@@ -161,6 +170,7 @@ type rebuilder_functions = {
   rebuilder_paramfn : Ast0_cocci.parameterTypeDef rcode;
   rebuilder_declfn : Ast0_cocci.declaration rcode;
   rebuilder_fieldfn : Ast0_cocci.field rcode;
+  rebuilder_enumdeclfn : Ast0_cocci.enum_decl rcode;
   rebuilder_stmtfn : Ast0_cocci.statement rcode;
   rebuilder_forinfofn : Ast0_cocci.forinfo rcode;
   rebuilder_casefn : Ast0_cocci.case_line rcode;
@@ -192,6 +202,7 @@ type 'n combiner_rebuilder_functions = {
   combiner_rebuilder_dotsstmtfn : (Ast0_cocci.statement Ast0_cocci.dots, 'n) rccode;
   combiner_rebuilder_dotsdeclfn : (Ast0_cocci.declaration Ast0_cocci.dots, 'n) rccode;
   combiner_rebuilder_dotsfieldfn : (Ast0_cocci.field Ast0_cocci.dots, 'n) rccode;
+  combiner_rebuilder_dotsenumdeclfn : (Ast0_cocci.enum_decl Ast0_cocci.dots, 'n) rccode;
   combiner_rebuilder_dotscasefn : (Ast0_cocci.case_line Ast0_cocci.dots, 'n) rccode;
   combiner_rebuilder_dotsdefparfn : (Ast0_cocci.define_param Ast0_cocci.dots, 'n) rccode;
   combiner_rebuilder_identfn : (Ast0_cocci.ident, 'n) rccode;
@@ -203,6 +214,7 @@ type 'n combiner_rebuilder_functions = {
   combiner_rebuilder_paramfn : (Ast0_cocci.parameterTypeDef, 'n) rccode;
   combiner_rebuilder_declfn : (Ast0_cocci.declaration, 'n) rccode;
   combiner_rebuilder_fieldfn : (Ast0_cocci.field, 'n) rccode;
+  combiner_rebuilder_enumdeclfn : (Ast0_cocci.enum_decl,'n) rccode;
   combiner_rebuilder_stmtfn : (Ast0_cocci.statement, 'n) rccode;
   combiner_rebuilder_forinfofn : (Ast0_cocci.forinfo, 'n) rccode;
   combiner_rebuilder_casefn : (Ast0_cocci.case_line, 'n) rccode;
-- 
2.21.1

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

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

* [Cocci] [PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in parsing_cocci
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (5 preceding siblings ...)
  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 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 08/13] parsing_cocci: Add visitor functions for enum_decl in visitor_ast Jaskaran Singh
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The SmPL AST0 visitor has functions for handling enumerators
separately. Handle these collateral evolutions in parsing_cocci
by creating visitor functions for enum and enumdots in various places,
as well as adding the additional arguments needed in the visitor
combiners and rebuilders.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/ast0toast.ml           | 30 +++++++++--
 parsing_cocci/ast0toast.mli          |  4 ++
 parsing_cocci/check_meta.ml          | 17 ++++--
 parsing_cocci/commas_on_lists.ml     | 10 ++--
 parsing_cocci/compute_lines.ml       | 25 ++++++++-
 parsing_cocci/context_neg.ml         | 47 +++++++++++++---
 parsing_cocci/function_prototypes.ml |  7 +--
 parsing_cocci/index.ml               |  7 +++
 parsing_cocci/index.mli              |  2 +
 parsing_cocci/insert_plus.ml         | 39 +++++++++++---
 parsing_cocci/iso_compile.ml         |  4 +-
 parsing_cocci/iso_pattern.ml         | 80 +++++++++++++++++++++++-----
 parsing_cocci/parse_cocci.ml         |  2 +-
 parsing_cocci/unitary_ast0.ml        |  5 +-
 parsing_cocci/unparse_ast0.ml        | 22 +++++++-
 15 files changed, 252 insertions(+), 49 deletions(-)

diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index f1bbde0b..cd46b0b8 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -187,9 +187,9 @@ let inline_mcodes =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode
     do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-    do_nothing
+    do_nothing do_nothing
     do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-    do_nothing do_nothing do_nothing_end do_nothing_end do_nothing
+    do_nothing do_nothing do_nothing_end do_nothing_end do_nothing do_nothing
     do_nothing do_nothing do_nothing do_nothing
 
 (* --------------------------------------------------------------------- *)
@@ -271,8 +271,10 @@ let check_allminus =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode mcode mcode
     donothing donothing donothing donothing donothing donothing donothing
+    donothing
     donothing ident expression donothing donothing typeC initialiser donothing
-    declaration field statement donothing case_line donothing donothing
+    declaration field donothing statement donothing case_line donothing
+    donothing
 
 (* --------------------------------------------------------------------- *)
 (* --------------------------------------------------------------------- *)
@@ -598,7 +600,7 @@ and base_typeC allminus t =
   | Ast0.EnumName(kind,name) ->
       Ast.EnumName(mcode kind,get_option ident name)
   | Ast0.EnumDef(ty,lb,ids,rb) ->
-      Ast.EnumDef(typeC allminus ty,mcode lb,dots expression ids,mcode rb)
+      Ast.EnumDef(typeC allminus ty,mcode lb,enum_decl_dots ids,mcode rb)
   | Ast0.StructUnionName(kind,name) ->
       Ast.StructUnionName(mcode kind,get_option ident name)
   | Ast0.StructUnionDef(ty,lb,decls,rb) ->
@@ -748,6 +750,24 @@ and annotated_field bef d =
 
 and field_dots l = dots (annotated_field None) l
 
+and enum_decl d =
+  rewrap d (do_isos (Ast0.get_iso d))
+    (match Ast0.unwrap d with
+      Ast0.Enum(name,enum_val) ->
+        (match enum_val with
+          None -> Ast.Enum(ident name,None)
+        | Some(eq,eval) ->
+            Ast.Enum(ident name,Some(mcode eq,expression eval)))
+    | Ast0.EnumComma(cm) ->
+	Ast.EnumComma(mcode cm)
+    | Ast0.EnumDots(dots,whencode) ->
+	(* structure definitions only *)
+	let dots = mcode dots in
+	let whencode = get_option (fun (_,_,b) -> enum_decl b) whencode in
+	Ast.EnumDots(dots,whencode))
+
+and enum_decl_dots l = dots enum_decl l
+
 (* --------------------------------------------------------------------- *)
 (* Initialiser *)
 
@@ -1214,6 +1234,7 @@ and anything = function
   | Ast0.DotsStmtTag(d) -> Ast.StmtDotsTag(statement_dots d)
   | Ast0.DotsDeclTag(d) -> Ast.AnnDeclDotsTag(declaration_dots d)
   | Ast0.DotsFieldTag(d) -> Ast.AnnFieldDotsTag(field_dots d)
+  | Ast0.DotsEnumDeclTag(d) -> Ast.EnumDeclDotsTag(enum_decl_dots d)
   | Ast0.DotsCaseTag(d) -> failwith "not possible"
   | Ast0.DotsDefParamTag(d) -> Ast.DefParDotsTag(define_param_dots d)
   | Ast0.IdentTag(d) -> Ast.IdentTag(ident d)
@@ -1227,6 +1248,7 @@ and anything = function
   | Ast0.InitTag(d) -> Ast.InitTag(initialiser d)
   | Ast0.DeclTag(d) -> Ast.DeclarationTag(declaration d)
   | Ast0.FieldTag(d) -> Ast.FieldTag(field d)
+  | Ast0.EnumDeclTag(d) -> Ast.EnumDeclTag(enum_decl d)
   | Ast0.StmtTag(d) -> Ast.StatementTag(statement d)
   | Ast0.ForInfoTag(d) -> Ast.ForInfoTag(forinfo d)
   | Ast0.CaseLineTag(d) -> Ast.CaseLineTag(case_line d)
diff --git a/parsing_cocci/ast0toast.mli b/parsing_cocci/ast0toast.mli
index 24f8c52a..f4d2bb19 100644
--- a/parsing_cocci/ast0toast.mli
+++ b/parsing_cocci/ast0toast.mli
@@ -28,6 +28,9 @@ val declaration_dots :
 val field_dots :
     Ast0_cocci.field Ast0_cocci.dots ->
       Ast_cocci.annotated_field Ast_cocci.dots
+val enum_decl_dots :
+    Ast0_cocci.enum_decl Ast0_cocci.dots ->
+      Ast_cocci.enum_decl Ast_cocci.dots
 val define_param_dots :
     Ast0_cocci.define_param Ast0_cocci.dots ->
       Ast_cocci.define_param Ast_cocci.dots
@@ -36,6 +39,7 @@ val string_fragment : Ast0_cocci.string_fragment -> Ast_cocci.string_fragment
 val typeC : bool (*allminus*) -> Ast0_cocci.typeC -> Ast_cocci.fullType
 val declaration : Ast0_cocci.declaration -> Ast_cocci.declaration
 val field : Ast0_cocci.field -> Ast_cocci.field
+val enum_decl : Ast0_cocci.enum_decl -> Ast_cocci.enum_decl
 val parameterTypeDef :
     Ast0_cocci.parameterTypeDef -> Ast_cocci.parameterTypeDef
 val parameter_list : Ast0_cocci.parameter_list -> Ast_cocci.parameter_list
diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml
index 02b0fd9c..fc96bf34 100644
--- a/parsing_cocci/check_meta.ml
+++ b/parsing_cocci/check_meta.ml
@@ -241,7 +241,7 @@ and typeC old_metas table minus t =
   | Ast0.EnumName(en,Some id) -> ident GLOBAL old_metas table minus id
   | Ast0.EnumDef(ty,lb,ids,rb) ->
       typeC old_metas table minus ty;
-      dots (expression GLOBAL old_metas table minus) ids
+      dots (enum_decl GLOBAL old_metas table minus) ids
   | Ast0.StructUnionName(su,Some id) -> ident GLOBAL old_metas table minus id
   | Ast0.StructUnionDef(ty,lb,decls,rb) ->
       typeC old_metas table minus ty;
@@ -321,6 +321,15 @@ and field context old_metas table minus d =
   | Ast0.Fdots(_,Some (_,_,x)) -> field ID old_metas table minus x
   | Ast0.Fdots(_,None) -> ()
 
+and enum_decl context old_metas table minus d =
+  match Ast0.unwrap d with
+    Ast0.Enum(name,enum_val) ->
+      ident context old_metas table minus name;
+      (match enum_val with
+        None -> ()
+      | Some(eq,eval) -> expression context old_metas table minus eval)
+  | Ast0.EnumComma(_) | Ast0.EnumDots(_) -> ()
+
 (* --------------------------------------------------------------------- *)
 (* Initialiser *)
 
@@ -583,7 +592,7 @@ let positions rname table rules =
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing in
+      donothing donothing donothing in
 
   List.iter fn.VT0.combiner_rec_top_level rules
 
@@ -651,8 +660,8 @@ let dup_positions rules =
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode mcode mcode
       donothing donothing donothing donothing donothing donothing donothing
-      donothing donothing expression donothing donothing typeC donothing
-      donothing declaration field statement
+      donothing donothing donothing expression donothing donothing typeC
+      donothing donothing declaration field donothing statement
       donothing donothing donothing donothing in
 
   let res =
diff --git a/parsing_cocci/commas_on_lists.ml b/parsing_cocci/commas_on_lists.ml
index 3c1facfe..9ea23ef5 100644
--- a/parsing_cocci/commas_on_lists.ml
+++ b/parsing_cocci/commas_on_lists.ml
@@ -31,11 +31,11 @@ now. See list_matcher in cocci_vs_c.ml in first try_matches case. *)
 	Ast0.rewrap itemlist
           (List.rev (Ast0.rewrap e (make_comma comma) :: (e::es)))
 
-let add_exp_comma =
+let add_enum_decl_comma =
   add_comma
-    (function x -> match Ast0.unwrap x with Ast0.EComma _ -> true | _ -> false)
-    (function x -> match Ast0.unwrap x with Ast0.Edots _  -> true | _ -> false)
-    (function x -> Ast0.EComma x)
+    (function x -> match Ast0.unwrap x with Ast0.EnumComma _ -> true | _ -> false)
+    (function x -> match Ast0.unwrap x with Ast0.EnumDots _  -> true | _ -> false)
+    (function x -> Ast0.EnumComma x)
 
 and add_init_comma =
   add_comma
@@ -51,7 +51,7 @@ let base_typeC r k t =
   let t = k t in
   match Ast0.unwrap t with
     Ast0.EnumDef(ty,lb,ids,rb) ->
-      let ids = add_exp_comma ids in
+      let ids = add_enum_decl_comma ids in
       Ast0.rewrap t (Ast0.EnumDef(ty,lb,ids,rb))
   | _ -> t
 
diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml
index f4b6f4d8..d7ca651c 100644
--- a/parsing_cocci/compute_lines.ml
+++ b/parsing_cocci/compute_lines.ml
@@ -600,7 +600,8 @@ and typeC t =
   | Ast0.EnumDef(ty,lb,ids,rb) ->
       let ty = typeC ty in
       let lb = normal_mcode lb in
-      let ids = dots is_exp_dots (Some(promote_mcode lb)) expression ids in
+      let ids =
+        dots is_enum_decl_dots (Some(promote_mcode lb)) enum_decl ids in
       let rb = normal_mcode rb in
       mkres t (Ast0.EnumDef(ty,lb,ids,rb)) ty (promote_mcode rb)
   | Ast0.StructUnionName(kind,Some name) ->
@@ -804,6 +805,28 @@ and field d =
       let ln = promote_mcode dots in
       mkres d (Ast0.Fdots(dots,whencode)) ln ln
 
+and is_enum_decl_dots d =
+  match Ast0.unwrap d with
+    Ast0.EnumDots(_) -> true
+  | _ -> false
+
+and enum_decl d =
+  match Ast0.unwrap d with
+     Ast0.Enum(name,enum_val) ->
+      let name = ident name in
+      let eval (a, b) = (normal_mcode a, expression b) in
+      let enum_val = get_option eval enum_val in
+      mkres d (Ast0.Enum(name,enum_val)) name name
+  | Ast0.EnumComma(cm) ->
+      let cm = normal_mcode cm in
+      let ln = promote_mcode cm in
+      mkres d (Ast0.EnumComma(cm)) ln ln
+  | Ast0.EnumDots(dots,whencode) ->
+      let dots = bad_mcode dots in
+      let ln = promote_mcode dots in
+      mkres d (Ast0.EnumDots(dots,whencode)) ln ln
+
+
 (* --------------------------------------------------------------------- *)
 (* Initializer *)
 
diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml
index 7bbf743d..85214b5b 100644
--- a/parsing_cocci/context_neg.ml
+++ b/parsing_cocci/context_neg.ml
@@ -27,6 +27,7 @@ let set_mcodekind x mcodekind =
   | Ast0.DotsStmtTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.DotsDeclTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.DotsFieldTag(d) -> Ast0.set_mcodekind d mcodekind
+  | Ast0.DotsEnumDeclTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.DotsCaseTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.DotsDefParamTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.IdentTag(d) -> Ast0.set_mcodekind d mcodekind
@@ -39,6 +40,7 @@ let set_mcodekind x mcodekind =
   | Ast0.ParamTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.DeclTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.FieldTag(d) -> Ast0.set_mcodekind d mcodekind
+  | Ast0.EnumDeclTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.InitTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.StmtTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.ForInfoTag(d) -> Ast0.set_mcodekind d mcodekind
@@ -60,6 +62,7 @@ let set_index x index =
   | Ast0.DotsStmtTag(d) -> Ast0.set_index d index
   | Ast0.DotsDeclTag(d) -> Ast0.set_index d index
   | Ast0.DotsFieldTag(d) -> Ast0.set_index d index
+  | Ast0.DotsEnumDeclTag(d) -> Ast0.set_index d index
   | Ast0.DotsCaseTag(d) -> Ast0.set_index d index
   | Ast0.DotsDefParamTag(d) -> Ast0.set_index d index
   | Ast0.IdentTag(d) -> Ast0.set_index d index
@@ -73,6 +76,7 @@ let set_index x index =
   | Ast0.InitTag(d) -> Ast0.set_index d index
   | Ast0.DeclTag(d) -> Ast0.set_index d index
   | Ast0.FieldTag(d) -> Ast0.set_index d index
+  | Ast0.EnumDeclTag(d) -> Ast0.set_index d index
   | Ast0.StmtTag(d) -> Ast0.set_index d index
   | Ast0.ForInfoTag(d) -> Ast0.set_index d index
   | Ast0.CaseLineTag(d) -> Ast0.set_index d index
@@ -92,6 +96,7 @@ let get_index = function
   | Ast0.DotsStmtTag(d) -> Index.statement_dots d
   | Ast0.DotsDeclTag(d) -> Index.declaration_dots d
   | Ast0.DotsFieldTag(d) -> Index.field_dots d
+  | Ast0.DotsEnumDeclTag(d) -> Index.enum_decl_dots d
   | Ast0.DotsCaseTag(d) -> Index.case_line_dots d
   | Ast0.DotsDefParamTag(d) -> Index.define_param_dots d
   | Ast0.IdentTag(d) -> Index.ident d
@@ -105,6 +110,7 @@ let get_index = function
   | Ast0.InitTag(d) -> Index.initialiser d
   | Ast0.DeclTag(d) -> Index.declaration d
   | Ast0.FieldTag(d) -> Index.field d
+  | Ast0.EnumDeclTag(d) -> Index.enum_decl d
   | Ast0.StmtTag(d) -> Index.statement d
   | Ast0.ForInfoTag(d) -> Index.forinfo d
   | Ast0.CaseLineTag(d) -> Index.case_line d
@@ -174,9 +180,10 @@ let collect_plus_lines top =
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode
       donothing donothing donothing donothing donothing donothing donothing
-      donothing
+      donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing donothing statement donothing donothing donothing donothing in
+      donothing donothing donothing statement donothing donothing donothing
+      donothing in
   fn.VT0.combiner_rec_top_level top
 
 (* --------------------------------------------------------------------- *)
@@ -446,6 +453,16 @@ let classify is_minus all_marked table code =
 	       (bind (Common.default option_default bitfield bf) (mcode sem)))
       |	_ -> k e) in
 
+  let enum_decl r k e =
+    compute_result Ast0.enum_decl e
+      (match Ast0.unwrap e with
+	Ast0.Enum(name,Some(eq,eval)) ->
+          bind (r.VT0.combiner_rec_ident name)
+            (bind (mcode eq) (r.VT0.combiner_rec_expression eval))
+      | Ast0.EnumDots(dots,whencode) ->
+	  k (Ast0.rewrap e (Ast0.EnumDots(dots,None)))
+      | _ -> k e) in
+
   let param r k e =
     compute_result Ast0.param e
       (match Ast0.unwrap e with
@@ -526,10 +543,10 @@ let classify is_minus all_marked table code =
       (do_nothing Ast0.dotsExpr) (do_nothing Ast0.dotsInit)
       (do_nothing Ast0.dotsParam) (do_nothing Ast0.dotsStmt)
       (do_nothing Ast0.dotsDecl) (do_nothing Ast0.dotsField)
-      (do_nothing Ast0.dotsCase)
+      (do_nothing Ast0.dotsEnumDecl) (do_nothing Ast0.dotsCase)
       (do_nothing Ast0.dotsDefParam)
       ident expression (do_nothing Ast0.assignOp) (do_nothing Ast0.binaryOp)
-      typeC initialiser param declaration field
+      typeC initialiser param declaration field enum_decl
       statement (do_nothing Ast0.forinfo) case_line string_fragment
       (do_top Ast0.top) in
   combiner.VT0.combiner_rec_top_level code
@@ -672,7 +689,9 @@ let equal_typeC t1 t2 =
   | (Ast0.EnumName(kind1,_),Ast0.EnumName(kind2,_)) ->
       equal_mcode kind1 kind2
   | (Ast0.EnumDef(_,lb1,_,rb1),Ast0.EnumDef(_,lb2,_,rb2)) ->
-       equal_mcode lb1 lb2 && equal_mcode rb1 rb2
+       let tru1 = equal_mcode lb1 lb2 in
+       let tru2 = equal_mcode rb1 rb2 in
+       tru1 && tru2
   | (Ast0.StructUnionName(kind1,_),Ast0.StructUnionName(kind2,_)) ->
       equal_mcode kind1 kind2
   | (Ast0.StructUnionDef(_,lb1,_,rb1),
@@ -766,6 +785,19 @@ let equal_field d1 d2 =
        equal_mcode ender1 ender2
   | _ -> false
 
+let equal_enum_decl d1 d2 =
+  match (Ast0.unwrap d1,Ast0.unwrap d2) with
+    (Ast0.Enum(name1,enum_val1),Ast0.Enum(name2,enum_val2)) ->
+      equal_ident name1 name2 &&
+      (match enum_val1,enum_val2 with
+        None,None -> true
+      | Some (eq1,val1),Some(eq2,val2) ->
+         equal_mcode eq1 eq2 && equal_expression val1 val2
+      | _ -> false)
+  | (Ast0.EnumComma(cm1),Ast0.EnumComma(cm2)) -> equal_mcode cm1 cm2
+  | (Ast0.EnumDots(dots1,_),Ast0.EnumDots(dots2,_)) -> equal_mcode dots1 dots2
+  | _ -> false
+
 let equal_designator d1 d2 =
   match (d1,d2) with
     (Ast0.DesignatorField(dot1,_),Ast0.DesignatorField(dot2,_)) ->
@@ -939,6 +971,8 @@ let root_equal e1 e2 =
   | (Ast0.DotsStmtTag(d1),Ast0.DotsStmtTag(d2)) -> dots equal_statement d1 d2
   | (Ast0.DotsDeclTag(d1),Ast0.DotsDeclTag(d2)) -> dots equal_declaration d1 d2
   | (Ast0.DotsFieldTag(d1),Ast0.DotsFieldTag(d2)) -> dots equal_field d1 d2
+  | (Ast0.DotsEnumDeclTag(d1),Ast0.DotsEnumDeclTag(d2)) ->
+      dots equal_field d1 d2
   | (Ast0.DotsCaseTag(d1),Ast0.DotsCaseTag(d2)) -> dots equal_case_line d1 d2
   | (Ast0.DotsDefParamTag(d1),Ast0.DotsDefParamTag(d2)) ->
       dots equal_define_param d1 d2
@@ -952,6 +986,7 @@ let root_equal e1 e2 =
   | (Ast0.InitTag(d1),Ast0.InitTag(d2)) -> equal_initialiser d1 d2
   | (Ast0.DeclTag(d1),Ast0.DeclTag(d2)) -> equal_declaration d1 d2
   | (Ast0.FieldTag(d1),Ast0.FieldTag(d2)) -> equal_field d1 d2
+  | (Ast0.EnumDeclTag(d1),Ast0.EnumDeclTag(d2)) -> equal_enum_decl d1 d2
   | (Ast0.StmtTag(s1),Ast0.StmtTag(s2)) -> equal_statement s1 s2
   | (Ast0.TopTag(t1),Ast0.TopTag(t2)) -> equal_top_level t1 t2
   | (Ast0.IsoWhenTag(_),_) | (_,Ast0.IsoWhenTag(_))
@@ -996,7 +1031,7 @@ let contextify_all =
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing
+    donothing donothing donothing
 
 let contextify_whencode =
   let bind x y = () in
diff --git a/parsing_cocci/function_prototypes.ml b/parsing_cocci/function_prototypes.ml
index 2e6eea43..6eeb72af 100644
--- a/parsing_cocci/function_prototypes.ml
+++ b/parsing_cocci/function_prototypes.ml
@@ -68,7 +68,7 @@ let drop_positions =
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing in
+    donothing donothing donothing in
   res.VT0.rebuilder_rec_statement
 
 let get_all_functions rule =
@@ -171,9 +171,10 @@ and strip =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode
     donothing donothing donothing donothing donothing donothing donothing
-    donothing
+    donothing donothing
     ident donothing donothing donothing typeC donothing param
     donothing donothing donothing donothing donothing donothing donothing
+    donothing
 
 and changed_proto = function
     (mname,mdef,mproto,None) -> true
@@ -197,7 +198,7 @@ let collect_ident_strings id =
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing in
+      donothing donothing donothing in
       v.VT0.combiner_rec_ident id
 
 let right_attach_mcode strings (x,ar,info,mc,pos,adj) =
diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
index a1103503..f2cbe3d0 100644
--- a/parsing_cocci/index.ml
+++ b/parsing_cocci/index.ml
@@ -28,6 +28,7 @@ let parameter_dots x =   3 :: dots x
 let statement_dots x =   4 :: dots x
 let declaration_dots x = 5 :: dots x
 let field_dots x = 8 :: dots x
+let enum_decl_dots x = 9 :: dots x
 let case_line_dots x =   6 :: dots x
 let define_param_dots x =7 :: dots x
 
@@ -133,6 +134,12 @@ let field d =
   | Ast0.Fdots(dots,whencode) -> [133]
   | Ast0.OptField(decl) -> [191]
 
+let enum_decl d =
+  match Ast0.unwrap d with
+  | Ast0.Enum(name,enum_val) -> [113]
+  | Ast0.EnumComma(cm) -> [114]
+  | Ast0.EnumDots(dots,whencode) -> [115]
+
 let initialiser i =
   match Ast0.unwrap i with
     Ast0.MetaInit(nm,_,_) -> [106] (* added after *)
diff --git a/parsing_cocci/index.mli b/parsing_cocci/index.mli
index 3cf7b8dc..4f86f5ba 100644
--- a/parsing_cocci/index.mli
+++ b/parsing_cocci/index.mli
@@ -10,6 +10,7 @@ val parameter_dots : Ast0_cocci.parameterTypeDef Ast0_cocci.dots -> int list
 val statement_dots : Ast0_cocci.statement Ast0_cocci.dots -> int list
 val declaration_dots : Ast0_cocci.declaration Ast0_cocci.dots -> int list
 val field_dots : Ast0_cocci.field Ast0_cocci.dots -> int list
+val enum_decl_dots : Ast0_cocci.enum_decl Ast0_cocci.dots -> int list
 val case_line_dots : Ast0_cocci.case_line Ast0_cocci.dots -> int list
 val define_param_dots : Ast0_cocci.define_param Ast0_cocci.dots -> int list
 val ident : Ast0_cocci.ident -> int list
@@ -19,6 +20,7 @@ val binaryOp : Ast0_cocci.binaryOp -> int list
 val typeC : Ast0_cocci.typeC -> int list
 val declaration : Ast0_cocci.declaration -> int list
 val field : Ast0_cocci.field -> int list
+val enum_decl : Ast0_cocci.enum_decl -> int list
 val initialiser : Ast0_cocci.initialiser -> int list
 val parameterTypeDef : Ast0_cocci.parameterTypeDef -> int list
 val statement : Ast0_cocci.statement -> int list
diff --git a/parsing_cocci/insert_plus.ml b/parsing_cocci/insert_plus.ml
index b7b50f10..bdc10ae6 100644
--- a/parsing_cocci/insert_plus.ml
+++ b/parsing_cocci/insert_plus.ml
@@ -75,13 +75,13 @@ it *)
       (donothing Ast0.dotsExpr) (donothing Ast0.dotsInit)
       (donothing Ast0.dotsParam) (donothing Ast0.dotsStmt)
       (donothing Ast0.dotsDecl) (donothing Ast0.dotsField)
-      (donothing Ast0.dotsCase)
+      (donothing Ast0.dotsEnumDecl) (donothing Ast0.dotsCase)
       (donothing Ast0.dotsDefParam)
       (donothing Ast0.ident) expression  (donothing Ast0.assignOp)
       (donothing Ast0.binaryOp)
       (donothing Ast0.typeC) initialiser
       (donothing Ast0.param) (donothing Ast0.decl)
-      (donothing Ast0.field) statement
+      (donothing Ast0.field) (donothing Ast0.enum_decl) statement
       (donothing Ast0.forinfo) (donothing Ast0.case_line)
       (donothing Ast0.string_fragment) topfn in
   res.VT0.combiner_rec_top_level e
@@ -114,6 +114,7 @@ let create_root_token_table minus =
 	  | Ast0.DotsStmtTag(d) -> Ast0.get_index d
 	  | Ast0.DotsDeclTag(d) -> Ast0.get_index d
 	  | Ast0.DotsFieldTag(d) -> Ast0.get_index d
+	  | Ast0.DotsEnumDeclTag(d) -> Ast0.get_index d
 	  | Ast0.DotsCaseTag(d) -> Ast0.get_index d
 	  | Ast0.DotsDefParamTag(d) -> Ast0.get_index d
 	  | Ast0.IdentTag(d) -> Ast0.get_index d
@@ -127,6 +128,7 @@ let create_root_token_table minus =
 	  | Ast0.InitTag(d) -> Ast0.get_index d
 	  | Ast0.DeclTag(d) -> Ast0.get_index d
 	  | Ast0.FieldTag(d) -> Ast0.get_index d
+	  | Ast0.EnumDeclTag(d) -> Ast0.get_index d
 	  | Ast0.StmtTag(d) -> Ast0.get_index d
 	  | Ast0.ForInfoTag(d) -> Ast0.get_index d
 	  | Ast0.CaseLineTag(d) -> Ast0.get_index d
@@ -215,6 +217,13 @@ bind to that; not good for isomorphisms *)
 	  Ast0.DPComma(comma) -> unfavored_mcode comma
 	| _ -> r.VT0.combiner_rec_define_param p)
   k d in
+  let enumdots r k d =
+    dots
+      (function p ->
+	match Ast0.unwrap p with
+	  Ast0.EnumComma(comma) -> unfavored_mcode comma
+	| _ -> r.VT0.combiner_rec_enumdecl p)
+  k d in
 
   let sdots r k d = dots r.VT0.combiner_rec_statement k d in
   let ddots r k d = dots r.VT0.combiner_rec_declaration k d in
@@ -345,9 +354,9 @@ bind to that; not good for isomorphisms *)
   V0.flat_combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode
-    edots idots pdots sdots ddots fdots cdots dpdots
+    edots idots pdots sdots ddots fdots enumdots cdots dpdots
     ident expression do_nothing do_nothing
-    typeC initialiser param decl field statement forinfo
+    typeC initialiser param decl field do_nothing statement forinfo
     case_line do_nothing do_top
 
 
@@ -374,6 +383,9 @@ let call_collect_minus context_nodes :
       | Ast0.DotsFieldTag(e) ->
 	  (Ast0.get_index e,
 	   (collect_minus_join_points e).VT0.combiner_rec_field_dots e)
+      | Ast0.DotsEnumDeclTag(e) ->
+	  (Ast0.get_index e,
+	   (collect_minus_join_points e).VT0.combiner_rec_enum_decl_dots e)
       | Ast0.DotsCaseTag(e) ->
 	  (Ast0.get_index e,
 	   (collect_minus_join_points e).VT0.combiner_rec_case_line_dots e)
@@ -409,6 +421,9 @@ let call_collect_minus context_nodes :
       | Ast0.FieldTag(e) ->
 	  (Ast0.get_index e,
 	   (collect_minus_join_points e).VT0.combiner_rec_field e)
+      | Ast0.EnumDeclTag(e) ->
+	  (Ast0.get_index e,
+	   (collect_minus_join_points e).VT0.combiner_rec_enumdecl e)
       | Ast0.StmtTag(e) ->
 	  (Ast0.get_index e,
 	   (collect_minus_join_points e).VT0.combiner_rec_statement e)
@@ -497,6 +512,7 @@ let mk_arithOp x          = Ast.ArithOpTag x
 let mk_logicalOp x        = Ast.LogicalOpTag x
 let mk_declaration x      = Ast.DeclarationTag (Ast0toast.declaration x)
 let mk_field x            = Ast.FieldTag (Ast0toast.field x)
+let mk_enum_decl x        = Ast.EnumDeclTag (Ast0toast.enum_decl x)
 let mk_topdeclaration x   = Ast.DeclarationTag (Ast0toast.declaration x)
 let mk_storage x          = Ast.StorageTag x
 let mk_inc_file x         = Ast.IncFileTag x
@@ -514,6 +530,7 @@ let mk_paramdots x = Ast.ParamDotsTag (Ast0toast.parameter_list x)
 let mk_stmtdots x  = Ast.StmtDotsTag (Ast0toast.statement_dots x)
 let mk_decldots x  = Ast.AnnDeclDotsTag (Ast0toast.declaration_dots x)
 let mk_fielddots x  = Ast.AnnFieldDotsTag (Ast0toast.field_dots x)
+let mk_enumdecldots x  = Ast.EnumDeclDotsTag (Ast0toast.enum_decl_dots x)
 let mk_casedots x  = failwith "+ case lines not supported"
 let mk_defpardots x= Ast.DefParDotsTag (Ast0toast.define_param_dots x)
 let mk_typeC x     = Ast.FullTypeTag (Ast0toast.typeC false x)
@@ -620,12 +637,13 @@ let collect_plus_nodes root =
     (mcode mk_storage) (mcode mk_inc_file)
     (do_nothing mk_exprdots) initdots
     (do_nothing mk_paramdots) stmt_dots (do_nothing mk_decldots)
-    (do_nothing mk_fielddots)
+    (do_nothing mk_fielddots) (do_nothing mk_enumdecldots)
     (do_nothing mk_casedots) (do_nothing mk_defpardots)
     (do_nothing mk_ident) (do_nothing mk_expression)
     (do_nothing mk_assignOp) (do_nothing mk_binaryOp)
     (do_nothing mk_typeC) (do_nothing mk_init) (do_nothing mk_param)
     (do_nothing mk_declaration) (do_nothing mk_field)
+    (do_nothing mk_enum_decl)
     stmt (do_nothing mk_forinfo) (do_nothing mk_case_line)
     (do_nothing mk_string_fragment) toplevel
 
@@ -652,6 +670,9 @@ let call_collect_plus context_nodes :
       | Ast0.DotsFieldTag(e) ->
 	  (Ast0.get_index e,
 	   (collect_plus_nodes e).VT0.combiner_rec_field_dots e)
+      | Ast0.DotsEnumDeclTag(e) ->
+	  (Ast0.get_index e,
+	   (collect_plus_nodes e).VT0.combiner_rec_enum_decl_dots e)
       | Ast0.DotsCaseTag(e) ->
 	  (Ast0.get_index e,
 	   (collect_plus_nodes e).VT0.combiner_rec_case_line_dots e)
@@ -687,6 +708,9 @@ let call_collect_plus context_nodes :
       | Ast0.FieldTag(e) ->
 	  (Ast0.get_index e,
 	   (collect_plus_nodes e).VT0.combiner_rec_field e)
+      | Ast0.EnumDeclTag(e) ->
+	  (Ast0.get_index e,
+	   (collect_plus_nodes e).VT0.combiner_rec_enumdecl e)
       | Ast0.StmtTag(e) ->
 	  (Ast0.get_index e,
 	   (collect_plus_nodes e).VT0.combiner_rec_statement e)
@@ -1175,8 +1199,9 @@ let reevaluate_contextness =
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode
       donothing donothing donothing donothing donothing donothing donothing
-      donothing donothing donothing donothing donothing
-      donothing donothing donothing donothing donothing stmt donothing
+      donothing donothing donothing donothing donothing donothing
+      donothing donothing donothing donothing donothing donothing stmt
+      donothing
       donothing donothing
       donothing in
   res.VT0.combiner_rec_top_level
diff --git a/parsing_cocci/iso_compile.ml b/parsing_cocci/iso_compile.ml
index 24c825f2..d17e1106 100644
--- a/parsing_cocci/iso_compile.ml
+++ b/parsing_cocci/iso_compile.ml
@@ -53,9 +53,9 @@ let sequence_tokens =
     (mcode (function x -> Store (Ast0.unwrap_mcode x)))
     (mcode (function x -> Inc (Ast0.unwrap_mcode x)))
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing
+    donothing donothing donothing donothing donothing donothing donothing
+    donothing donothing donothing
 
 (* In general, we will get a list of lists:
 
diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 5ceb2bdb..ca1b2810 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -45,7 +45,7 @@ let strip_info =
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing
+    donothing donothing donothing
 
 let anything_equal = function
     (Ast0.DotsExprTag(d1),Ast0.DotsExprTag(d2)) ->
@@ -476,9 +476,9 @@ let match_maker checks_needed context_required whencode_allowed =
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode
       donothing donothing donothing donothing donothing donothing donothing
-      donothing
-      ident expression assignOp binaryOp typeC init param decl field stmt
-      donothing donothing donothing donothing in
+      donothing donothing
+      ident expression assignOp binaryOp typeC init param decl field donothing
+      stmt donothing donothing donothing donothing in
 
   let add_pure_list_binding name pure is_pure builder1 builder2 lst =
     match (checks_needed,pure) with
@@ -892,7 +892,7 @@ let match_maker checks_needed context_required whencode_allowed =
 	       conjunct_many_bindings
 		 [check_mcode lb1 lb; check_mcode rb1 rb;
 		   match_typeC tya tyb;
-		   match_dots match_expr no_list do_nolist_match idsa idsb]
+		   match_dots match_enum_decl no_list do_nolist_match idsa idsb]
 	  | (Ast0.StructUnionName(kinda,Some namea),
 	     Ast0.StructUnionName(kindb,Some nameb)) ->
 	       if mcode_equal kinda kindb
@@ -1062,6 +1062,35 @@ let match_maker checks_needed context_required whencode_allowed =
 	  | _ -> return false
 	else return_false (ContextRequired (Ast0.FieldTag d))
 
+  and match_enum_decl pattern d =
+    match (Ast0.unwrap pattern,Ast0.unwrap d) with
+      (Ast0.Enum(namea,enum_vala),Ast0.Enum(nameb,enum_valb)) ->
+        let match_option_enum_val evala evalb =
+          match evala, evalb with
+            Some (eqa,ea), Some (eqb,eb) ->
+              [check_mcode eqa eqb] @ [match_expr ea eb]
+          | Some _, None | None, Some _ -> [return false]
+          | None, None -> [] in
+        conjunct_many_bindings
+          ([match_ident namea nameb]
+           @ match_option_enum_val enum_vala enum_valb)
+    | (Ast0.EnumComma(comma1),Ast0.EnumComma(comma2)) ->
+        check_mcode comma1 comma2
+    | (Ast0.EnumDots(d1,None),Ast0.EnumDots(d,None)) -> check_mcode d1 d
+    | (Ast0.EnumDots(dd,None),Ast0.EnumDots(d,Some (wh,ee,wc))) ->
+      conjunct_bindings (check_mcode dd d)
+	(* hope that mcode of ddots is unique somehow *)
+	(let (ddots_whencode_allowed,_,_) = whencode_allowed in
+	if ddots_whencode_allowed
+	then add_dot_binding dd
+	  (Ast0.WhenTag (wh,Some ee,Ast0.EnumDeclTag wc))
+	else
+	  (Printf.eprintf "warning: not applying iso because of whencode";
+	   return false))
+    | (Ast0.EnumDots(_,Some _),_) ->
+	failwith "whencode not allowed in a pattern1"
+    | _ -> return false
+
   and match_init pattern i =
     match Ast0.unwrap pattern with
       Ast0.MetaInit(name,_,pure) ->
@@ -1497,6 +1526,14 @@ let make_minus =
 	update_mc mcodekind e; Ast0.rewrap e (Ast0.Fdots(mcode d,whencode))
     | _ -> donothing r k e in
 
+  let enum_decl r k e =
+    let mcodekind = Ast0.get_mcodekind_ref e in
+    match Ast0.unwrap e with
+      Ast0.EnumDots(d,whencode) ->
+       (*don't recurse because whencode hasn't been processed by context_neg*)
+	update_mc mcodekind e; Ast0.rewrap e (Ast0.EnumDots(mcode d,whencode))
+    | _ -> donothing r k e in
+
   let statement r k e =
     let mcodekind = Ast0.get_mcodekind_ref e in
     match Ast0.unwrap e with
@@ -1549,9 +1586,10 @@ let make_minus =
   V0.flat_rebuilder
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode
-    dots dots dots dots dots dots dots dots
+    dots dots dots dots dots dots dots dots dots
     donothing expression donothing donothing donothing initialiser donothing
-    declaration field statement donothing donothing donothing donothing
+    declaration field enum_decl statement donothing donothing donothing
+    donothing
 
 (* --------------------------------------------------------------------- *)
 (* rebuild mcode cells in an instantiated alt *)
@@ -1642,8 +1680,8 @@ let rebuild_mcode start_line =
     mcode mcode
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing donothing statement donothing donothing donothing
-    donothing
+    donothing donothing donothing donothing donothing statement donothing
+    donothing donothing donothing
 
 (* --------------------------------------------------------------------- *)
 (* The problem of whencode.  If an isomorphism contains dots in multiple
@@ -2059,6 +2097,18 @@ let instantiate bindings mv_bindings model =
 	with Not_found -> e)
     | _ -> e in
 
+  let enumdeclfn r k e =
+    let e = k e in
+    match Ast0.unwrap e with
+      Ast0.EnumDots(d,_) ->
+	(try
+	  (match List.assoc (dot_term d) bindings with
+	    Ast0.WhenTag(wh,Some ee,Ast0.EnumDeclTag(exp)) ->
+              Ast0.rewrap e (Ast0.EnumDots(d,Some (wh,ee,exp)))
+	  | _ -> failwith "unexpected binding")
+	with Not_found -> e)
+    | _ -> e in
+
   let paramfn r k e =
     let e = k e in
     match Ast0.unwrap e with
@@ -2111,9 +2161,9 @@ let instantiate bindings mv_bindings model =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode
     (dots elist) donothing (dots plist) (dots slist) donothing donothing
-    donothing donothing
-    identfn exprfn donothing donothing tyfn initfn paramfn declfn fieldfn stmtfn
-    donothing donothing donothing donothing
+    donothing donothing donothing
+    identfn exprfn donothing donothing tyfn initfn paramfn declfn fieldfn
+    enumdeclfn stmtfn donothing donothing donothing donothing
 
 (* --------------------------------------------------------------------- *)
 
@@ -2843,7 +2893,7 @@ let rewrap =
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing
+    donothing donothing donothing
 
 let rec rewrap_anything = function
     Ast0.DotsExprTag(d) ->
@@ -2858,6 +2908,8 @@ let rec rewrap_anything = function
       Ast0.DotsDeclTag(rewrap.VT0.rebuilder_rec_declaration_dots d)
   | Ast0.DotsFieldTag(d) ->
       Ast0.DotsFieldTag(rewrap.VT0.rebuilder_rec_field_dots d)
+  | Ast0.DotsEnumDeclTag(d) ->
+      Ast0.DotsEnumDeclTag(rewrap.VT0.rebuilder_rec_enum_decl_dots d)
   | Ast0.DotsCaseTag(d) ->
       Ast0.DotsCaseTag(rewrap.VT0.rebuilder_rec_case_line_dots d)
   | Ast0.DotsDefParamTag(d) ->
@@ -2877,6 +2929,8 @@ let rec rewrap_anything = function
   | Ast0.ParamTag(d) -> Ast0.ParamTag(rewrap.VT0.rebuilder_rec_parameter d)
   | Ast0.DeclTag(d) -> Ast0.DeclTag(rewrap.VT0.rebuilder_rec_declaration d)
   | Ast0.FieldTag(d) -> Ast0.FieldTag(rewrap.VT0.rebuilder_rec_field d)
+  | Ast0.EnumDeclTag(d) ->
+      Ast0.EnumDeclTag(rewrap.VT0.rebuilder_rec_enumdecl d)
   | Ast0.StmtTag(d) -> Ast0.StmtTag(rewrap.VT0.rebuilder_rec_statement d)
   | Ast0.ForInfoTag(d) -> Ast0.ForInfoTag(rewrap.VT0.rebuilder_rec_forinfo d)
   | Ast0.CaseLineTag(d) ->
diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml
index 679d213a..886882cc 100644
--- a/parsing_cocci/parse_cocci.ml
+++ b/parsing_cocci/parse_cocci.ml
@@ -1887,7 +1887,7 @@ let any_modif rule =
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing in
+      donothing donothing donothing in
   List.exists fn.VT0.combiner_rec_top_level rule
 
 let eval_virt virt =
diff --git a/parsing_cocci/unitary_ast0.ml b/parsing_cocci/unitary_ast0.ml
index a4eed517..f12bef67 100644
--- a/parsing_cocci/unitary_ast0.ml
+++ b/parsing_cocci/unitary_ast0.ml
@@ -204,9 +204,10 @@ let get_free checker t =
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode mcode mcode
       donothing donothing donothing donothing donothing donothing donothing
-      donothing
+      donothing donothing
       ident expression donothing donothing typeC donothing parameter
-      declaration field statement donothing case_line donothing donothing in
+      declaration field donothing statement donothing case_line donothing
+      donothing in
 
   collect_unitary_nonunitary
     (List.concat (List.map res.VT0.combiner_rec_top_level t))
diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index 5d450e0e..bfd98ddb 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -321,7 +321,7 @@ and typeC t =
 	  print_option (function x -> ident x; print_string " ") name
       | Ast0.EnumDef(ty,lb,ids,rb) ->
 	  typeC ty; mcode print_string lb;
-	  dots force_newline expression ids;
+	  dots force_newline enum_decl ids;
 	  mcode print_string rb
       | Ast0.StructUnionName(kind,name) ->
 	  mcode U.structUnion kind;
@@ -454,6 +454,24 @@ and field d =
 
 and field_dots l = dots (function _ -> ()) field l
 
+and enum_decl d =
+  print_context d
+    (function _ ->
+      match Ast0.unwrap d with
+	Ast0.Enum(name,enum_val) ->
+          (match enum_val with
+            None -> ident name
+          | Some(eq,eval) ->
+              ident name; mcode print_string eq; expression eval)
+      | Ast0.EnumComma(cm) ->
+          mcode print_string cm; force_newline()
+      | Ast0.EnumDots(dots,Some (_,_,whencode)) ->
+	  mcode print_string dots; print_string "   when != ";
+	  enum_decl whencode
+      | Ast0.EnumDots(dots,None) -> mcode print_string dots)
+
+and enum_decl_dots l = dots (function _ -> ()) enum_decl l
+
 (* --------------------------------------------------------------------- *)
 (* Initialiser *)
 
@@ -781,6 +799,7 @@ let rec unparse_anything x =
       statement_dots d
   | Ast0.DotsDeclTag(d) -> declaration_dots d
   | Ast0.DotsFieldTag(d) -> field_dots d
+  | Ast0.DotsEnumDeclTag(d) -> enum_decl_dots d
   | Ast0.DotsCaseTag(d) -> case_dots d
   | Ast0.DotsDefParamTag(d) -> define_param_dots d
   | Ast0.IdentTag(d)    -> ident d
@@ -796,6 +815,7 @@ let rec unparse_anything x =
   | Ast0.InitTag(d)  -> initialiser d
   | Ast0.DeclTag(d)  -> declaration d
   | Ast0.FieldTag(d)  -> field d
+  | Ast0.EnumDeclTag(d)  -> enum_decl d
   | Ast0.StmtTag(d)  ->
       print_string "Stm:"; force_newline();
       statement "" d
-- 
2.21.1

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

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

* [Cocci] [PATCH 08/13] parsing_cocci: Add visitor functions for enum_decl in visitor_ast
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (6 preceding siblings ...)
  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
  2020-03-08  8:43 ` [Cocci] [PATCH 09/13] cocci: Reflect changes in SmPL visitor_ast in codebase Jaskaran Singh
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

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

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

* [Cocci] [PATCH 09/13] cocci: Reflect changes in SmPL visitor_ast in codebase
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (7 preceding siblings ...)
  2020-03-08  8:43 ` [Cocci] [PATCH 08/13] parsing_cocci: Add visitor functions for enum_decl in visitor_ast Jaskaran Singh
@ 2020-03-08  8:43 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 10/13] engine: cocci_vs_c: Match enumerators properly as per enum_decl Jaskaran Singh
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The SmPL AST visitor has functions for handling enumerators
separately. Handle these collateral evolutions in the codebase
by creating visitor functions for enum and enumdots in various places,
as well as adding the additional arguments needed in the visitor
combiners and rebuilders.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 cocci.ml                              |  4 ++--
 engine/asttoctl2.ml                   | 21 ++++++++++---------
 engine/asttomember.ml                 | 17 +++++++++-------
 engine/cocci_vs_c.ml                  |  2 +-
 engine/transformation_c.ml            |  4 ++--
 parsing_c/unparse_hrule.ml            |  4 ++--
 parsing_cocci/arity.ml                | 25 ++++++++++++++++++++++-
 parsing_cocci/cleanup_rules.ml        |  5 +++--
 parsing_cocci/disjdistr.ml            | 29 ++++++++++++++++++++-------
 parsing_cocci/free_vars.ml            | 27 +++++++++++++------------
 parsing_cocci/get_constants2.ml       |  7 ++++---
 parsing_cocci/parse_cocci.ml          |  2 +-
 parsing_cocci/re_constraints.ml       | 10 ++++-----
 parsing_cocci/safe_for_multi_decls.ml | 11 +++++-----
 parsing_cocci/single_statement.ml     |  5 +++--
 parsing_cocci/stmtlist.ml             |  4 ++--
 parsing_cocci/unify_ast.ml            | 29 ++++++++++++++++++++++-----
 popl/popltoctl.ml                     |  2 +-
 popl09/popltoctl.ml                   |  5 +++--
 19 files changed, 141 insertions(+), 72 deletions(-)

diff --git a/cocci.ml b/cocci.ml
index 8d729923..3f315d4c 100644
--- a/cocci.ml
+++ b/cocci.ml
@@ -596,11 +596,11 @@ let sp_contain_typed_metavar_z toplevel_list_list =
     Visitor_ast.combiner bind option_default
       mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode mcode mcode mcode
-      donothing donothing donothing donothing donothing donothing
+      donothing donothing donothing donothing donothing donothing donothing
       donothing expression donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing
-      donothing
+      donothing donothing
   in
   toplevel_list_list +>
     List.exists
diff --git a/engine/asttoctl2.ml b/engine/asttoctl2.ml
index 67ec815f..51d574fa 100644
--- a/engine/asttoctl2.ml
+++ b/engine/asttoctl2.ml
@@ -341,9 +341,10 @@ let elim_opt =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode mcode mcode mcode
     donothing donothing stmtdotsfn donothing donothing donothing donothing
-    donothing donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
+    donothing
 
 (* --------------------------------------------------------------------- *)
 (* after management *)
@@ -464,11 +465,12 @@ let contains_modif =
     V.combiner bind option_default
       mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode mcode mcode mcode
-      do_nothing do_nothing do_nothing do_nothing do_nothing
+      do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing init do_nothing do_nothing
       do_nothing do_nothing do_nothing
-      do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in
+      do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
+      do_nothing in
   recursor.V.combiner_rule_elem
 
 let contains_pos =
@@ -495,8 +497,9 @@ let contains_pos =
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-      do_nothing do_nothing
-      do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in
+      do_nothing do_nothing do_nothing
+      do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
+      do_nothing in
   recursor.V.combiner_rule_elem
 
 (* code is not a DisjRuleElem *)
@@ -592,10 +595,10 @@ let count_nested_braces s =
   let recursor = V.combiner bind option_default
       mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode mcode mcode mcode
-      donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing donothing stmt_count donothing donothing donothing in
+      donothing donothing donothing donothing donothing donothing donothing
+      donothing donothing donothing stmt_count donothing donothing donothing in
   let res = string_of_int (recursor.V.combiner_statement s) in
   string2var ("p"^res)
 
@@ -2682,10 +2685,10 @@ and drop_minuses stmt_dots =
     V.rebuilder
       mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode mcode mcode mcode
-      donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing donothing donothing donothing donothing donothing in
+      donothing donothing donothing donothing donothing donothing donothing
+      donothing donothing donothing donothing donothing donothing donothing in
   v.V.rebuilder_statement_dots stmt_dots
 
 and find_xx = function
diff --git a/engine/asttomember.ml b/engine/asttomember.ml
index eb825ec8..a893a833 100644
--- a/engine/asttomember.ml
+++ b/engine/asttomember.ml
@@ -46,8 +46,9 @@ let contains_modif used_after x =
 	do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
 	do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
 	do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-	do_nothing do_nothing
-	do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in
+	do_nothing do_nothing do_nothing
+	do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
+	do_nothing in
     recursor.V.combiner_rule_elem x
 
 (* contains an inherited metavariable or contains a constant *)
@@ -71,10 +72,11 @@ let contains_constant x =
 	  mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 	  mcode mcode mcode
 	  do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
+	  do_nothing
 	  ident expr do_nothing do_nothing do_nothing do_nothing do_nothing
 	  do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
 	  do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-	  do_nothing in
+	  do_nothing do_nothing in
       recursor.V.combiner_rule_elem x
   | _ -> true
 
@@ -133,9 +135,9 @@ let strip x =
       mcode mcode mcode mcode mcode
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-      do_nothing do_nothing do_nothing do_nothing do_nothing
+      do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       decl_or_field do_absolutely_nothing decl_or_field do_absolutely_nothing
-      rule_elem
+      do_nothing rule_elem
       do_nothing do_nothing do_nothing do_absolutely_nothing in
   r.V.rebuilder_rule_elem x
 
@@ -200,9 +202,10 @@ let find_commonalities res : Ast_cocci.rule_elem option =
 	mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 	mcode mcode mcode
 	do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-	do_nothing expression do_nothing do_nothing do_nothing do_nothing
-	do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
 	do_nothing do_nothing
+	expression do_nothing do_nothing do_nothing do_nothing
+	do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
+	do_nothing do_nothing do_nothing
 	do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing in
     recursor.V.combiner_rule_elem x in
   match res with
diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index a4a0e53b..5d123164 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -2289,7 +2289,7 @@ and (declaration: (A.mcodekind * bool * A.declaration,B.declaration) matcher) =
 		donothing donothing donothing donothing donothing donothing
 		donothing donothing donothing donothing donothing donothing
 		donothing donothing donothing donothing donothing donothing
-	        donothing donothing in
+	        donothing donothing donothing donothing in
 	    v.Visitor_ast.rebuilder_declaration decla in
 
 	  xs +> List.fold_left (fun acc var ->
diff --git a/engine/transformation_c.ml b/engine/transformation_c.ml
index 9f0b0ab2..4de8fe51 100644
--- a/engine/transformation_c.ml
+++ b/engine/transformation_c.ml
@@ -287,11 +287,11 @@ module XTRANS = struct
     let fn = Visitor_ast.rebuilder
 	mcode mcode mcode mcode mcode mcode mcode mcode mcode
 	mcode mcode mcode mcode mcode
-	donothing donothing donothing donothing donothing donothing
+	donothing donothing donothing donothing donothing donothing donothing
 	ident expression donothing donothing donothing donothing
 	donothing donothing donothing donothing donothing donothing
 	donothing donothing donothing donothing donothing donothing
-	donothing donothing in
+	donothing donothing donothing in
 
   fn.Visitor_ast.rebuilder_anything anything
 
diff --git a/parsing_c/unparse_hrule.ml b/parsing_c/unparse_hrule.ml
index 6b766f3c..f2605d82 100644
--- a/parsing_c/unparse_hrule.ml
+++ b/parsing_c/unparse_hrule.ml
@@ -133,10 +133,10 @@ let get_function_name rule env =
     (V.combiner bind option_default
       mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode mcode mcode mcode
-      donothing donothing donothing donothing donothing donothing
+      donothing donothing donothing donothing donothing donothing donothing
       donothing expression donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing
+      donothing donothing
       donothing donothing donothing donothing donothing).V.combiner_top_level
       rule in
   match names with
diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
index f29b86eb..b932c3fa 100644
--- a/parsing_cocci/arity.ml
+++ b/parsing_cocci/arity.ml
@@ -452,7 +452,7 @@ and top_typeC tgt opt_allowed typ =
 	  (List.map mcode2arity [lb;rb]) in
       let ty = typeC arity ty in
       let lb = mcode lb in
-      let ids = dots (expression tgt) decls in
+      let ids = dots (enum_decl tgt) decls in
       let rb = mcode rb in
       make_typeC typ tgt arity (Ast0.EnumDef(ty,lb,ids,rb))
   | Ast0.StructUnionName(kind,name) ->
@@ -689,6 +689,29 @@ and field tgt decl =
   | Ast0.OptField(_) ->
       failwith "unexpected code"
 
+and enum_decl tgt decl =
+  match Ast0.unwrap decl with
+    Ast0.Enum(name,enum_val) ->
+      let name = ident true tgt name in
+      let enum_val =
+        get_option
+          (fun (eq,eval) ->
+             let arity = all_same true tgt (mcode2line eq) [mcode2arity eq] in
+             (mcode eq, expression arity eval)) enum_val in
+      let res = Ast0.Enum(name,enum_val) in
+      Ast0.rewrap decl res
+  | Ast0.EnumComma(cm) ->
+      (*let arity = all_same true tgt (mcode2line cm) [mcode2arity cm] in*)
+      let cm = mcode cm in
+      let res = Ast0.EnumComma(cm) in
+      Ast0.rewrap decl res
+  | Ast0.EnumDots(dots,whencode) ->
+      let dots = mcode dots in
+      let whencode =
+        get_option (fun (a,e,b) -> (a,e,enum_decl Ast0.NONE b)) whencode in
+      let res = Ast0.EnumDots(dots,whencode) in
+      Ast0.rewrap decl res
+
 (* --------------------------------------------------------------------- *)
 (* Initializer *)
 
diff --git a/parsing_cocci/cleanup_rules.ml b/parsing_cocci/cleanup_rules.ml
index 08ce96d6..60452bec 100644
--- a/parsing_cocci/cleanup_rules.ml
+++ b/parsing_cocci/cleanup_rules.ml
@@ -249,10 +249,11 @@ let do_cleanup =
   V.rebuilder
     mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode mcode mcode mcode
-    donothing donothing donothing donothing donothing donothing (* dots *)
+    donothing donothing donothing donothing donothing
+    donothing donothing (* dots *)
     ident expression string_fragment string_format assignOp
     binaryOp fullType typeC initialiser parameterTypeDef define_param
-    declaration donothing field ann_field
+    declaration donothing field ann_field donothing
     rule_elem statement donothing donothing donothing
 
 let cleanup_rules rules d =
diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml
index 668a8810..87b5c7a3 100644
--- a/parsing_cocci/disjdistr.ml
+++ b/parsing_cocci/disjdistr.ml
@@ -90,7 +90,7 @@ and disjtypeC bty =
 	(function name -> Ast.rewrap bty (Ast.StructUnionName(su,name)))
 	name
   | Ast.EnumDef(ty,lb,ids,rb) ->
-      disjmult2 (disjty ty) (disjdots disjexp ids)
+      disjmult2 (disjty ty) (disjdots disjenumdecl ids)
 	(function ty -> function ids ->
 	  Ast.rewrap bty (Ast.EnumDef(ty,lb,ids,rb)))
   | Ast.StructUnionDef(ty,lb,decls,rb) ->
@@ -130,6 +130,21 @@ and anndisjfield d =
       let decl = anndisjfield decl in
       List.map (function decl -> Ast.rewrap d (Ast.OptField(decl))) decl
 
+and disjenumdecl d =
+  match Ast.unwrap d with
+    Ast.Enum(name,enum_val) ->
+      let name = disjident name in
+      (match enum_val with
+        None ->
+          List.map (function name -> Ast.rewrap d (Ast.Enum(name,None)))
+            name
+      | Some (eq,eval) ->
+          disjmult2 name (disjexp eval)
+          (function name -> function eval ->
+	    Ast.rewrap d (Ast.Enum(name,Some(eq,eval)))))
+  | Ast.EnumComma(cm) -> [d]
+  | Ast.EnumDots(dots,whencode) -> [d]
+
 and disjident e =
   match Ast.unwrap e with
     Ast.DisjId(id_list) -> List.concat (List.map disjident id_list)
@@ -461,8 +476,8 @@ let disj_all =
     mcode mcode mcode mcode mcode
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing donothing donothing donothing donothing
-    donothing disj_rule_elem donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing donothing donothing
+    donothing donothing disj_rule_elem donothing donothing donothing donothing
 
 (* ----------------------------------------------------------------------- *)
 (* collect iso information at the rule_elem level *)
@@ -478,9 +493,9 @@ let collect_all_isos =
     mcode mcode mcode mcode mcode
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing
     doanything donothing doanything donothing donothing donothing donothing
-    doanything
+    donothing doanything
 
 let collect_iso_info =
   let mcode x = x in
@@ -495,9 +510,9 @@ let collect_iso_info =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode mcode mcode mcode
     donothing donothing donothing donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing
-    donothing donothing donothing donothing donothing
-    donothing donothing donothing donothing rule_elem donothing donothing
+    donothing donothing donothing donothing donothing rule_elem donothing donothing
     donothing donothing
 
 (* ----------------------------------------------------------------------- *)
diff --git a/parsing_cocci/free_vars.ml b/parsing_cocci/free_vars.ml
index 4c34cd08..6ad35dcc 100644
--- a/parsing_cocci/free_vars.ml
+++ b/parsing_cocci/free_vars.ml
@@ -249,10 +249,10 @@ let collect_refs include_constraints =
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode mcode mcode
-    donothing donothing donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing donothing donothing
     astfvident astfvexpr astfvfrag astfvfmt astfvassignop astfvbinaryop
     astfvfullType astfvtypeC astfvinit astfvparam astfvdefine_param
-    astfvdecls donothing astfvfields astafvfields
+    astfvdecls donothing astfvfields astafvfields donothing
     astfvrule_elem astfvstatement donothing donothing donothing_a
 
 let collect_all_refs = collect_refs true
@@ -299,10 +299,10 @@ let collect_pos_positions =
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode mcode mcode mcode
-    donothing donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing
-    donothing donothing donothing
+    donothing donothing donothing donothing
     cprule_elem cpstmt donothing donothing donothing
 
 (* ---------------------------------------------------------------- *)
@@ -475,10 +475,11 @@ let collect_saved =
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode
-    donothing donothing donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing donothing donothing
     astfvident astfvexpr astfvfrag astfvfmt astfvassign astfvbinary donothing
     astfvtypeC astfvinit astfvparam astfvdefine_param astfvdecls donothing
-    astfvfields donothing astfvrule_elem donothing donothing donothing donothing
+    astfvfields donothing donothing astfvrule_elem donothing donothing
+    donothing donothing
 
 (* ---------------------------------------------------------------- *)
 
@@ -607,10 +608,10 @@ let collect_in_plus_term =
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
-    mcode mcode donothing donothing
+    mcode mcode donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing donothing donothing donothing astfvrule_elem
+    donothing donothing donothing donothing donothing donothing astfvrule_elem
     astfvstatement donothing donothing donothing
 
 let collect_in_plus metavars minirules =
@@ -900,11 +901,11 @@ let classify_variables metavar_decls minirules used_after =
   let fn = V.rebuilder
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode
-      donothing donothing donothing donothing donothing donothing
+      donothing donothing donothing donothing donothing donothing donothing
       ident expression string_fragment string_format assignop binaryop
       donothing typeC
-      init param define_param decl donothing field donothing rule_elem
-      donothing donothing donothing donothing in
+      init param define_param decl donothing field donothing donothing
+      rule_elem donothing donothing donothing donothing in
 
   List.map fn.V.rebuilder_top_level minirules
 
@@ -1089,7 +1090,7 @@ let astfvs metavars bound =
     donothing donothing astfvstatement_dots donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing
+    donothing donothing donothing
     astfvrule_elem astfvstatement astfvcase_line astfvtoplevel donothing
 
 (*
@@ -1174,7 +1175,7 @@ let get_neg_pos_list (_,rule) used_after_list =
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing donothing donothing donothing in
+    donothing donothing donothing donothing donothing donothing donothing in
   match rule with
     Ast.CocciRule(rule_name,_,minirules,_,_) ->
       List.map
diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml
index b5cfeccc..76d6d40b 100644
--- a/parsing_cocci/get_constants2.ml
+++ b/parsing_cocci/get_constants2.ml
@@ -638,10 +638,10 @@ let do_get_constants constants keywords env (neg_pos,_) =
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode mcode mcode mcode
-    donothing donothing donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing donothing donothing
     ident expression string_fragment string_format donothing donothing
     fullType typeC initialiser parameter define_parameter declaration donothing
-    field ann_field rule_elem statement donothing donothing donothing
+    field ann_field donothing rule_elem statement donothing donothing donothing
 
 (* ------------------------------------------------------------------------ *)
 
@@ -708,8 +708,9 @@ let all_context =
     mcode mcode mcode mcode mcode
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
+    donothing
     initialiser donothing donothing donothing donothing donothing donothing
-    rule_elem statement donothing donothing donothing
+    donothing rule_elem statement donothing donothing donothing
 
 (* ------------------------------------------------------------------------ *)
 
diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml
index 886882cc..da2c1288 100644
--- a/parsing_cocci/parse_cocci.ml
+++ b/parsing_cocci/parse_cocci.ml
@@ -2541,7 +2541,7 @@ let contains_modifs ast =
       donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing
-      donothing donothing in
+      donothing donothing donothing donothing in
   List.exists
     (function
 	Ast.CocciRule(nm,infos,ast,_,_) ->
diff --git a/parsing_cocci/re_constraints.ml b/parsing_cocci/re_constraints.ml
index cc218543..17011465 100644
--- a/parsing_cocci/re_constraints.ml
+++ b/parsing_cocci/re_constraints.ml
@@ -41,9 +41,9 @@ let disj_free re =
     V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode
-    donothing donothing donothing donothing donothing donothing ident
+    donothing donothing donothing donothing donothing donothing donothing ident
     expr donothing donothing donothing donothing ty donothing
-    donothing donothing donothing decl donothing donothing ann_field
+    donothing donothing donothing decl donothing donothing ann_field donothing
     rule_elem statement donothing donothing donothing in
   try Hashtbl.find disj_free_table re
   with Not_found ->
@@ -90,7 +90,7 @@ let ok_for_all_rule_elems cstr minirules =
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      rule_elem donothing donothing donothing donothing in
+      donothing donothing rule_elem donothing donothing donothing donothing in
   List.for_all v.V.combiner_top_level minirules
 
 let update_for_all_rule_elems cstr minirules =
@@ -111,8 +111,8 @@ let update_for_all_rule_elems cstr minirules =
       mcode mcode
       donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing
-      donothing donothing donothing donothing
-      donothing donothing donothing donothing
+      donothing donothing donothing donothing donothing
+      donothing donothing donothing donothing donothing
       donothing rule_elem donothing donothing donothing donothing in
   List.map v.V.rebuilder_top_level minirules
 
diff --git a/parsing_cocci/safe_for_multi_decls.ml b/parsing_cocci/safe_for_multi_decls.ml
index 070489c5..8fc49432 100644
--- a/parsing_cocci/safe_for_multi_decls.ml
+++ b/parsing_cocci/safe_for_multi_decls.ml
@@ -43,7 +43,7 @@ let all_removed_recursor =
     do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
     do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
     do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-    do_nothing do_nothing
+    do_nothing do_nothing do_nothing do_nothing
 
 let all_removed_decl =
   all_removed_recursor.V.combiner_declaration
@@ -97,9 +97,10 @@ let contains_modif =
       mcode mcode mcode mcode mcode
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-      do_nothing do_nothing init do_nothing
+      do_nothing do_nothing do_nothing init do_nothing
       do_nothing do_nothing do_nothing do_nothing
-      do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in
+      do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
+      do_nothing in
   recursor.V.combiner_fullType
 
 let decl r k e =
@@ -172,8 +173,8 @@ let process =
       mcode mcode mcode mcode mcode
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing donothing donothing decl anndecl field annfield
-      donothing donothing donothing donothing donothing in
+      donothing donothing donothing donothing decl anndecl field annfield
+      donothing donothing donothing donothing donothing donothing in
   List.map fn.V.rebuilder_top_level
 
 let safe_for_multi_decls rules =
diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml
index 46408b73..e9cda647 100644
--- a/parsing_cocci/single_statement.ml
+++ b/parsing_cocci/single_statement.ml
@@ -458,9 +458,10 @@ and contains_only_minus =
   V0.flat_combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     mcode mcode mcode
-    dots dots dots dots dots dots dots dots
+    dots dots dots dots dots dots dots dots dots
     identifier expression donothing donothing typeC donothing donothing
-    declaration field statement donothing case_line donothing donothing
+    declaration field donothing statement donothing case_line donothing
+    donothing
 
 
 (* needs a special case when there is a Disj or an empty DOTS *)
diff --git a/parsing_cocci/stmtlist.ml b/parsing_cocci/stmtlist.ml
index 2f01c404..4e7a0b5a 100644
--- a/parsing_cocci/stmtlist.ml
+++ b/parsing_cocci/stmtlist.ml
@@ -55,8 +55,8 @@ let stmtlist_rebuilder =
     donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing
-    donothing donothing donothing donothing statement donothing donothing
-    donothing
+    donothing donothing donothing donothing donothing donothing
+    statement donothing donothing donothing
 
 let stmtlist rule =
   match rule with
diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml
index d4ad3030..64887550 100644
--- a/parsing_cocci/unify_ast.ml
+++ b/parsing_cocci/unify_ast.ml
@@ -117,6 +117,11 @@ let dpdots e =
     Ast.DPdots(_) -> true
   | _ -> false
 
+let enumdots e =
+  match Ast.unwrap e with
+    Ast.EnumDots(_) -> true
+  | _ -> false
+
 let sdots s =
   match Ast.unwrap s with
     Ast.Dots(_,_,_,_) -> true
@@ -348,7 +353,7 @@ and unify_typeC t1 t2 =
       true
   | (Ast.EnumDef(ty1,lb1,ids1,rb1),Ast.EnumDef(ty2,lb2,ids2,rb2)) ->
       unify_fullType ty1 ty2 &&
-      unify_dots unify_expression edots ids1 ids2
+      unify_dots unify_enum_decl enumdots ids1 ids2
   | (Ast.StructUnionName(s1,Some ts1),Ast.StructUnionName(s2,Some ts2)) ->
       if unify_mcode s1 s2 then unify_ident ts1 ts2 else false
   | (Ast.StructUnionName(s1,None),Ast.StructUnionName(s2,None)) ->
@@ -476,6 +481,19 @@ and unify_annotated_field d1 d2 =
   | (Ast.OptField(_),_)
   | (_,Ast.OptField(_)) -> failwith "unsupported decl"
 
+and unify_enum_decl d1 d2 =
+  match (Ast.unwrap d1,Ast.unwrap d2) with
+    (Ast.Enum(name1,enum_val1),Ast.Enum(name2,enum_val2)) ->
+       unify_ident name1 name2 &&
+       unify_option
+         (function a -> function b ->
+            let (_,eval1) = a in
+            let (_,eval2) = b in
+            unify_expression eval1 eval2) enum_val1 enum_val2
+  | (Ast.EnumComma(_),(Ast.EnumComma(_))) -> true
+  | (Ast.EnumDots(_),(Ast.EnumDots(_))) -> true
+  | _ -> false
+
 (* --------------------------------------------------------------------- *)
 (* Initializer *)
 
@@ -700,10 +718,11 @@ and subexp f =
   let recursor = V.combiner bind option_default
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode
-      donothing donothing donothing donothing donothing donothing donothing expr
+      donothing donothing donothing donothing donothing donothing donothing
+      donothing expr
       donothing donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing donothing
-      donothing donothing donothing donothing in
+      donothing donothing donothing donothing donothing in
   recursor.V.combiner_rule_elem
 
 and subtype f =
@@ -716,10 +735,10 @@ and subtype f =
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       mcode mcode
       donothing donothing donothing donothing donothing donothing donothing
-      donothing donothing donothing donothing donothing fullType
+      donothing donothing donothing donothing donothing donothing fullType
       donothing donothing donothing donothing donothing donothing
       donothing donothing donothing donothing donothing donothing
-      donothing in
+      donothing donothing in
   recursor.V.combiner_rule_elem
 
 let rec unify_statement s1 s2 =
diff --git a/popl/popltoctl.ml b/popl/popltoctl.ml
index 978d49d0..933c3faf 100644
--- a/popl/popltoctl.ml
+++ b/popl/popltoctl.ml
@@ -37,7 +37,7 @@ let contains_modif =
   let recursor =
     V.combiner bind option_default
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
-      mcode
+      mcode mcode
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing
diff --git a/popl09/popltoctl.ml b/popl09/popltoctl.ml
index 6b046309..1b05a762 100644
--- a/popl09/popltoctl.ml
+++ b/popl09/popltoctl.ml
@@ -46,8 +46,9 @@ let contains_modif =
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
       do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-      do_nothing do_nothing
-      do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in
+      do_nothing do_nothing do_nothing
+      do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
+      do_nothing in
   recursor.V.combiner_rule_elem
 
 let ctl_exists keep_wit v x =
-- 
2.21.1

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

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

* [Cocci] [PATCH 10/13] engine: cocci_vs_c: Match enumerators properly as per enum_decl
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (8 preceding siblings ...)
  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 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 11/13] cocci: pretty print EnumDef as per enum_decl type Jaskaran Singh
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The SmPL AST has a separate enum_decl type for an enumerator.
Make corresponding changes in Cocci_vs_c to correctly match
enumerators.

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

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index 5d123164..1a9b3671 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -3304,14 +3304,14 @@ and (struct_field: (A.annotated_field, B.field) matcher) =
 and enum_fields = fun eas ebs ->
   let match_dots ea =
     match A.unwrap ea with
-      A.Edots(mcode, optexpr) -> Some (mcode, optexpr)
+      A.EnumDots(mcode, optexpr) -> Some (mcode, optexpr)
     | _ -> None in
-  let build_dots (mcode, optexpr) = A.Edots(mcode, optexpr) in
+  let build_dots (mcode, optexpr) = A.EnumDots(mcode, optexpr) in
   let match_comma ea =
     match A.unwrap ea with
-      A.EComma ia1 -> Some ia1
+      A.EnumComma ia1 -> Some ia1
     | _ -> None in
-  let build_comma ia1 = A.EComma ia1 in
+  let build_comma ia1 = A.EnumComma ia1 in
   let match_metalist ea = None in
   let build_metalist _ (ida,leninfo,cstr,keep,inherited) =
     failwith "enum: build meta list: not possible" in
@@ -3326,29 +3326,21 @@ and enum_fields = fun eas ebs ->
 and enum_field ida idb =
   X.all_bound (A.get_inherited ida) >&&>
   match A.unwrap ida, idb with
-    A.Ident(id),(nameidb,None) ->
-      ident_cpp DontKnow id nameidb >>= (fun id nameidb ->
-        return ((A.Ident id) +> A.rewrap ida, (nameidb,None)))
-  | A.Ident(id),(nameidb,Some _) -> fail (* should we have an iso? *)
-  | A.Assignment(ea1,opa,ea2,init),(nameidb,Some(opbi,eb2)) ->
-      (match A.unwrap ea1 with
-	A.Ident(id) ->
-	  let assignOp opa0 opbi =
-	    match A.unwrap opa0 with
-              A.SimpleAssign oa ->
-		tokenf oa opbi >>= fun oa opbi ->
-		  return
-                    (A.rewrap opa (A.SimpleAssign oa), opbi)
-            | _ -> failwith "only simple assignment possible here" in
-	  ident_cpp DontKnow id nameidb >>= (fun id nameidb ->
-	  expression ea2 eb2 >>= (fun ea2 eb2 ->
-          assignOp opa opbi >>= (fun opa opbi ->(* only one kind of assignop *)
+    A.Enum(nameida,enum_vala),(nameidb,enum_valb) ->
+      (match enum_vala,enum_valb with
+        (None, Some _)
+      | (Some _, None) -> fail
+      | (None, None) ->
+         ident_cpp DontKnow nameida nameidb >>=
+         (fun nameida nameidb ->
+           return (A.Enum(nameida,None) +> A.rewrap ida, (nameidb,None)))
+      | (Some (eqa,evala), Some(eqb,evalb)) ->
+	  ident_cpp DontKnow nameida nameidb >>= (fun nameida nameidb ->
+          tokenf eqa eqb >>= (fun eqa eqb ->
+	  expression evala evalb >>= (fun ea eb ->
 	    return (
-	    (A.Assignment((A.Ident(id)) +> A.rewrap ea1,opa,ea2,init)) +>
-	    A.rewrap ida,
-	    (nameidb,Some(opbi,eb2))))))
-      |	_ -> failwith "enum: assignment: not possible")
-  | A.Assignment(ea1,opa,ea2,init),(nameidb,None) -> fail
+	    (A.Enum(nameida,Some(eqa,ea)) +> A.rewrap ida),
+	    (nameidb,Some(eqb,eb)))))))
   | _ -> failwith ("not possible: "^(Dumper.dump (A.unwrap ida)))
 
 (* ------------------------------------------------------------------------- *)
-- 
2.21.1

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

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

* [Cocci] [PATCH 11/13] cocci: pretty print EnumDef as per enum_decl type
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (9 preceding siblings ...)
  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 ` Jaskaran Singh
  2020-03-08  8:43 ` [Cocci] [PATCH 12/13] tests: Add test case for assigned enumerator Jaskaran Singh
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The SmPL AST has a separate enum_decl for a enumerator. Make
corresponding changes in Unparse_cocci and Pretty_print_cocci
to correctly pretty print enumerators.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_c/unparse_cocci.ml          | 27 ++++++++++++++++++++++++---
 parsing_cocci/pretty_print_cocci.ml | 18 +++++++++++++++++-
 2 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index 30e755e9..8dff2b81 100644
--- a/parsing_c/unparse_cocci.ml
+++ b/parsing_c/unparse_cocci.ml
@@ -738,7 +738,7 @@ and typeC ty =
   | Ast.EnumDef(ty,lb,ids,rb) ->
       fullType ty; ft_space ty;
       mcode print_string lb;
-      dots force_newline expression ids;
+      dots force_newline enum_decl ids;
       mcode print_string rb
   | Ast.StructUnionName(kind,name) ->
       mcode structUnion kind; print_option_prespace ident name
@@ -952,6 +952,24 @@ and annotated_field d =
   | Ast.OptField(decl) -> raise CantBeInPlus
   | Ast.Fdots(_,_) -> raise CantBeInPlus
 
+and enum_decl d =
+  match Ast.unwrap d with
+    Ast.Enum(name,enum_val) ->
+      ident name;
+      pr_space();
+      print_option
+        (function (eq,eval) ->
+          mcode print_string eq; pr_space(); expression eval) enum_val
+  | Ast.EnumComma(cm) ->
+      mcode (print_string_with_hint (SpaceOrNewline (ref " "))) cm
+  | Ast.EnumDots(dots,whencode) when generating ->
+      mcode print_string dots;
+      print_option
+      (function w ->
+        print_text "   when != ";
+        enum_decl w) whencode
+  | Ast.EnumDots(dots,whencode) -> raise CantBeInPlus
+
 (* --------------------------------------------------------------------- *)
 (* Initialiser *)
 
@@ -1420,6 +1438,7 @@ let pp_any = function
   | Ast.InitTag(x) -> initialiser false x; false
   | Ast.DeclarationTag(x) -> declaration x; false
   | Ast.FieldTag(x) -> field x; false
+  | Ast.EnumDeclTag(x) -> enum_decl x; false
 
   | Ast.StorageTag(x) -> storage x unknown unknown; false
   | Ast.IncFileTag(x) -> inc_file x unknown unknown; false
@@ -1473,6 +1492,7 @@ let pp_any = function
   | Ast.StmtDotsTag(x) -> dots force_newline (statement "") x; false
   | Ast.AnnDeclDotsTag(x) -> dots force_newline annotated_decl x; false
   | Ast.AnnFieldDotsTag(x) -> dots force_newline annotated_field x; false
+  | Ast.EnumDeclDotsTag(x) -> dots force_newline enum_decl x; false
   | Ast.DefParDotsTag(x) -> dots (fun _ -> ()) print_define_param x; false
 
   | Ast.TypeCTag(x) -> typeC x; false
@@ -1505,7 +1525,7 @@ in
 	      force_newline(); force_newline()
 	  | (Ast.Directive _::_)
 	  | (Ast.Rule_elemTag _::_) | (Ast.StatementTag _::_)
-	  | (Ast.FieldTag _::_) | (Ast.InitTag _::_)
+	  | (Ast.FieldTag _::_) | (Ast.EnumDeclTag _::_) | (Ast.InitTag _::_)
 	  | (Ast.DeclarationTag _::_) | (Ast.Token ("}",_)::_) -> prnl hd
 	  | _ -> () in
       let newline_after _ =
@@ -1516,7 +1536,8 @@ in
 	      (if isfn s then force_newline());
 	      force_newline()
 	  | (Ast.Directive _::_) | (Ast.StmtDotsTag _::_)
-	  | (Ast.Rule_elemTag _::_) | (Ast.FieldTag _::_) | (Ast.InitTag _::_)
+	  | (Ast.Rule_elemTag _::_) | (Ast.FieldTag _::_)
+	  | (Ast.EnumDeclTag _::_)| (Ast.InitTag _::_)
 	  | (Ast.DeclarationTag _::_) | (Ast.Token ("{",_)::_) ->
 	      force_newline()
 	  | _ -> () in
diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml
index 6338e464..f6b2894f 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -439,7 +439,7 @@ and typeC ty =
       print_option (function x -> ident x; print_string " ") name
   | Ast.EnumDef(ty,lb,ids,rb) ->
       fullType ty; mcode print_string lb;
-      dots force_newline expression ids;
+      dots force_newline enum_decl ids;
       mcode print_string rb
   | Ast.StructUnionName(kind,name) ->
       mcode structUnion kind;
@@ -585,6 +585,20 @@ and annotated_field arity d =
   | Ast.ConjField(decls) -> print_disj_list (annotated_field arity) decls "&"
   | Ast.OptField(decl) -> print_string "?"; annotated_field arity decl
 
+and enum_decl d =
+  match Ast.unwrap d with
+    Ast.Enum(name,enum_val) ->
+      ident name;
+      (match enum_val with
+        None -> ()
+      | Some(eq,eval) ->
+          mcode print_string eq;
+          expression eval)
+  | Ast.EnumComma(cm) -> mcode print_string cm
+  | Ast.EnumDots(dots,Some whencode) ->
+      mcode print_string dots; print_string "   when != "; enum_decl whencode
+  | Ast.EnumDots(dots,None) -> mcode print_string dots
+
 (* --------------------------------------------------------------------- *)
 (* Initialiser *)
 
@@ -1090,6 +1104,7 @@ let _ =
     | Ast.InitTag(x) -> initialiser x
     | Ast.DeclarationTag(x) -> declaration x
     | Ast.FieldTag(x) -> field x
+    | Ast.EnumDeclTag(x) -> enum_decl x
     | Ast.StorageTag(x) -> storage x
     | Ast.IncFileTag(x) -> inc_file x
     | Ast.Rule_elemTag(x) -> rule_elem "" x
@@ -1110,6 +1125,7 @@ let _ =
     | Ast.StmtDotsTag(x) -> dots (function _ -> ()) (statement "") x
     | Ast.AnnDeclDotsTag(x) -> dots (function _ -> ()) (annotated_decl "") x
     | Ast.AnnFieldDotsTag(x) -> dots (function _ -> ()) (annotated_field "") x
+    | Ast.EnumDeclDotsTag(x) -> dots (function _ -> ()) enum_decl x
     | Ast.DefParDotsTag(x) -> dots (function _ -> ()) print_define_param x
     | Ast.TypeCTag(x) -> typeC x
     | Ast.ParamTag(x) -> parameterTypeDef x
-- 
2.21.1

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

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

* [Cocci] [PATCH 12/13] tests: Add test case for assigned enumerator
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (10 preceding siblings ...)
  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 ` 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
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

Add a test case to verify correct pretty printing of
enumerators that are assigned. The test case should cover
minused assigned enumerators, plussed assigned enumerators
and correct matching of an enum with an assigned enumerator.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 tests/enum_assign.c     |  6 ++++++
 tests/enum_assign.cocci | 11 +++++++++++
 tests/enum_assign.res   |  7 +++++++
 3 files changed, 24 insertions(+)
 create mode 100644 tests/enum_assign.c
 create mode 100644 tests/enum_assign.cocci
 create mode 100644 tests/enum_assign.res

diff --git a/tests/enum_assign.c b/tests/enum_assign.c
new file mode 100644
index 00000000..9c2d16df
--- /dev/null
+++ b/tests/enum_assign.c
@@ -0,0 +1,6 @@
+enum h {
+	a = 0,
+	c,
+	x,
+	b
+};
diff --git a/tests/enum_assign.cocci b/tests/enum_assign.cocci
new file mode 100644
index 00000000..a1a59ef8
--- /dev/null
+++ b/tests/enum_assign.cocci
@@ -0,0 +1,11 @@
+@@
+@@
+
+enum h {
+  ...,
+- a = 0,
++ q = 0,
+  ...,
+  b,
++ z
+};
diff --git a/tests/enum_assign.res b/tests/enum_assign.res
new file mode 100644
index 00000000..3b204aa0
--- /dev/null
+++ b/tests/enum_assign.res
@@ -0,0 +1,7 @@
+enum h {
+	q = 0,
+	c,
+	x,
+	b,
+	z
+};
-- 
2.21.1

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

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

* [Cocci] [PATCH 13/13] tools: spgen: Reflect visitor changes
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (11 preceding siblings ...)
  2020-03-08  8:43 ` [Cocci] [PATCH 12/13] tests: Add test case for assigned enumerator Jaskaran Singh
@ 2020-03-08  8:43 ` Jaskaran Singh
  2020-03-09 14:15 ` [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Julia Lawall
  13 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-08  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

Visitor_ast0 has changes with respect to enums. Reflect these
changes in spgen by adding additional arguments in the combiners
and rebuilders.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 tools/spgen/source/detect_patch.ml  | 6 ++++--
 tools/spgen/source/meta_variable.ml | 6 ++++--
 tools/spgen/source/rule_body.ml     | 6 ++++--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/tools/spgen/source/detect_patch.ml b/tools/spgen/source/detect_patch.ml
index 6cf1c538..0489afec 100644
--- a/tools/spgen/source/detect_patch.ml
+++ b/tools/spgen/source/detect_patch.ml
@@ -101,11 +101,13 @@ let patch_combiner =
   let dotsparamfn = donothing in
   let dotsdeclfn = donothing in
   let dotsfieldfn = donothing in
+  let dotsenumdeclfn = donothing in
   let dotscasefn = donothing in
   let dotsdefparfn = donothing in
   let assignOpfn = donothing in
   let binaryOpfn = donothing in
   let initfn = donothing in
+  let enumdeclfn = donothing in
   let paramfn = donothing in
   let forinfofn = donothing in
   let string_fragmentfn = donothing in
@@ -159,9 +161,9 @@ let patch_combiner =
     fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode
     struct_mcode storage_mcode inc_mcode
     dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
-    dotscasefn dotsdefparfn
+    dotsenumdeclfn dotscasefn dotsdefparfn
     identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
-    stmtfn forinfofn casefn string_fragmentfn topfn
+    enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn
 
 
 (* ------------------------------------------------------------------------- *)
diff --git a/tools/spgen/source/meta_variable.ml b/tools/spgen/source/meta_variable.ml
index 7adfacad..a1804a05 100644
--- a/tools/spgen/source/meta_variable.ml
+++ b/tools/spgen/source/meta_variable.ml
@@ -390,11 +390,13 @@ let metavar_combiner rn =
   let dotsstmtfn = donothing in
   let dotsdeclfn = donothing in
   let dotsfieldfn = donothing in
+  let dotsenumdeclfn = donothing in
   let dotscasefn = donothing in
   let dotsdefparfn = donothing in
   let forinfofn = donothing in
   let casefn = donothing in
   let topfn = donothing in
+  let enumdeclfn = donothing in
 
   (* --- These are shortened formatting functions that return MVSets --- *)
 
@@ -574,9 +576,9 @@ let metavar_combiner rn =
     fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode
     struct_mcode storage_mcode inc_mcode
     dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
-    dotscasefn dotsdefparfn
+    dotsenumdeclfn dotscasefn dotsdefparfn
     identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
-    stmtfn forinfofn casefn string_fragmentfn topfn
+    enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn
 
 
 (* ------------------------------------------------------------------------- *)
diff --git a/tools/spgen/source/rule_body.ml b/tools/spgen/source/rule_body.ml
index 6345c9df..163dff9a 100644
--- a/tools/spgen/source/rule_body.ml
+++ b/tools/spgen/source/rule_body.ml
@@ -219,12 +219,14 @@ let rec gen_combiner ~context_mode =
   let dotsparamfn = donothing in
   let dotsdeclfn = donothing in
   let dotsfieldfn = donothing in
+  let dotsenumdeclfn = donothing in
   let dotscasefn = donothing in
   let dotsdefparfn = donothing in
   let assignOpfn = donothing in
   let binaryOpfn = donothing in
   let tyfn = donothing in
   let initfn = donothing in
+  let enumdeclfn = donothing in
   let paramfn = donothing in
   let forinfofn = donothing in
   let casefn = donothing in
@@ -349,9 +351,9 @@ let rec gen_combiner ~context_mode =
     fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode
     struct_mcode storage_mcode inc_mcode
     dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
-    dotscasefn dotsdefparfn
+    dotsenumdeclfn dotscasefn dotsdefparfn
     identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
-    stmtfn forinfofn casefn string_fragmentfn topfn
+    enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn
 
 
 (* ------------------------------------------------------------------------- *)
-- 
2.21.1

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

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

* Re: [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum
  2020-03-08  8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
                   ` (12 preceding siblings ...)
  2020-03-08  8:43 ` [Cocci] [PATCH 13/13] tools: spgen: Reflect visitor changes Jaskaran Singh
@ 2020-03-09 14:15 ` Julia Lawall
  2020-03-09 14:51   ` Jaskaran Singh
  13 siblings, 1 reply; 17+ messages in thread
From: Julia Lawall @ 2020-03-09 14:15 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Sun, 8 Mar 2020, Jaskaran Singh wrote:

> The C AST and SmPL AST differs with respect to the enum type.
>
> For an enumerator, the C AST is as follows:
>     Enum -> list of (name, (info, expression))
>
> For the same, the SmPL AST is as follows:
>     EnumDef -> list of expression
>
> While the SmPL parser does make sure that enumerators are
> parsed as per C rules, the OCaml types for an enumerator themselves
> mismatch, due to their organization. This causes bugs/mismatches for
> cases where enums are in disjunctions.
>
> This patch series makes the enumerator type of the SmPL AST
> closer to that of the C AST. Various places in the codebase that
> handle an enum are also changed to match the new type, and
> collateral evolutions caused by changed in the SmPL visitors are
> handled as well.
>
> Changes are also made to Cocci_vs_c to correctly match two
> enumerators, and in Pretty_print_cocci and Unparse_cocci to
> correctly print an enumerator.

I have applied all of the changes.  In the end, I squashed all of the
commits together, to only commit something that compiles, but I
appreciated having the changes broken up into more understandable units.

thanks,
julia


>
> [PATCH 01/13] parsing_cocci: Align C AST and SmPL AST for enum
> [PATCH 02/13] ocaml: coccilib: Reflect changes in SmPL AST for
> [PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly
> [PATCH 04/13] parsing_cocci: Add EnumDeclTag and EnumDeclDotsTag to
> [PATCH 05/13] ocaml: coccilib: Reflect EnumDeclTag and
> [PATCH 06/13] parsing_cocci: visitor_ast0: Add visitor functions for
> [PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in
> [PATCH 08/13] parsing_cocci: Add visitor functions for enum_decl in
> [PATCH 09/13] cocci: Reflect changes in SmPL visitor_ast in codebase
> [PATCH 10/13] engine: cocci_vs_c: Match enumerators properly as per
> [PATCH 11/13] cocci: pretty print EnumDef as per enum_decl type
> [PATCH 12/13] tests: Add test case for assigned enumerator
> [PATCH 13/13] tools: spgen: Reflect visitor changes
>
>  cocci.ml                              |    4 -
>  engine/asttoctl2.ml                   |   21 +++++---
>  engine/asttomember.ml                 |   17 ++++---
>  engine/cocci_vs_c.ml                  |   46 ++++++++-----------
>  engine/transformation_c.ml            |    4 -
>  ocaml/coccilib.mli                    |   22 ++++++++-
>  parsing_c/unparse_cocci.ml            |   27 ++++++++++-
>  parsing_c/unparse_hrule.ml            |    4 -
>  parsing_cocci/arity.ml                |   25 ++++++++++
>  parsing_cocci/ast0_cocci.ml           |   15 +++++-
>  parsing_cocci/ast0_cocci.mli          |   14 +++++
>  parsing_cocci/ast0toast.ml            |   30 +++++++++++-
>  parsing_cocci/ast0toast.mli           |    4 +
>  parsing_cocci/ast_cocci.ml            |   13 +++++
>  parsing_cocci/ast_cocci.mli           |   12 ++++-
>  parsing_cocci/check_meta.ml           |   17 +++++--
>  parsing_cocci/cleanup_rules.ml        |    5 +-
>  parsing_cocci/commas_on_lists.ml      |   10 ++--
>  parsing_cocci/compute_lines.ml        |   25 ++++++++++
>  parsing_cocci/context_neg.ml          |   47 +++++++++++++++++--
>  parsing_cocci/disjdistr.ml            |   29 +++++++++---
>  parsing_cocci/free_vars.ml            |   27 +++++------
>  parsing_cocci/function_prototypes.ml  |    7 +-
>  parsing_cocci/get_constants2.ml       |    7 +-
>  parsing_cocci/index.ml                |    7 ++
>  parsing_cocci/index.mli               |    2
>  parsing_cocci/insert_plus.ml          |   39 +++++++++++++---
>  parsing_cocci/iso_compile.ml          |    4 -
>  parsing_cocci/iso_pattern.ml          |   80 ++++++++++++++++++++++++++++------
>  parsing_cocci/parse_aux.ml            |    5 ++
>  parsing_cocci/parse_aux.mli           |    9 +++
>  parsing_cocci/parse_cocci.ml          |    4 -
>  parsing_cocci/parser_cocci_menhir.mly |   13 ++---
>  parsing_cocci/pretty_print_cocci.ml   |   18 +++++++
>  parsing_cocci/re_constraints.ml       |   10 ++--
>  parsing_cocci/safe_for_multi_decls.ml |   11 ++--
>  parsing_cocci/single_statement.ml     |    5 +-
>  parsing_cocci/stmtlist.ml             |    4 -
>  parsing_cocci/unify_ast.ml            |   29 ++++++++++--
>  parsing_cocci/unitary_ast0.ml         |    5 +-
>  parsing_cocci/unparse_ast0.ml         |   22 ++++++++-
>  parsing_cocci/visitor_ast.ml          |   72 +++++++++++++++++++++++++++---
>  parsing_cocci/visitor_ast.mli         |    8 +++
>  parsing_cocci/visitor_ast0.ml         |   72 ++++++++++++++++++++++++++++--
>  parsing_cocci/visitor_ast0.mli        |    4 +
>  parsing_cocci/visitor_ast0_types.ml   |   14 +++++
>  parsing_cocci/visitor_ast0_types.mli  |   12 +++++
>  popl/popltoctl.ml                     |    2
>  popl09/popltoctl.ml                   |    5 +-
>  tests/enum_assign.c                   |    6 ++
>  tests/enum_assign.cocci               |   11 ++++
>  tests/enum_assign.res                 |    7 ++
>  tools/spgen/source/detect_patch.ml    |    6 +-
>  tools/spgen/source/meta_variable.ml   |    6 +-
>  tools/spgen/source/rule_body.ml       |    6 +-
>  55 files changed, 748 insertions(+), 182 deletions(-)
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum
  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
  0 siblings, 0 replies; 17+ messages in thread
From: Jaskaran Singh @ 2020-03-09 14:51 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel-mentees, cocci

On Mon, 2020-03-09 at 15:15 +0100, Julia Lawall wrote:
> 
> On Sun, 8 Mar 2020, Jaskaran Singh wrote:
> 
> > The C AST and SmPL AST differs with respect to the enum type.
> > 
> > For an enumerator, the C AST is as follows:
> >     Enum -> list of (name, (info, expression))
> > 
> > For the same, the SmPL AST is as follows:
> >     EnumDef -> list of expression
> > 
> > While the SmPL parser does make sure that enumerators are
> > parsed as per C rules, the OCaml types for an enumerator themselves
> > mismatch, due to their organization. This causes bugs/mismatches
> > for
> > cases where enums are in disjunctions.
> > 
> > This patch series makes the enumerator type of the SmPL AST
> > closer to that of the C AST. Various places in the codebase that
> > handle an enum are also changed to match the new type, and
> > collateral evolutions caused by changed in the SmPL visitors are
> > handled as well.
> > 
> > Changes are also made to Cocci_vs_c to correctly match two
> > enumerators, and in Pretty_print_cocci and Unparse_cocci to
> > correctly print an enumerator.
> 
> I have applied all of the changes.  In the end, I squashed all of the
> commits together, to only commit something that compiles, but I
> appreciated having the changes broken up into more understandable
> units.
> 

Sorry about that. Will be more careful about these big changes next
time, and thanks for applying.

Cheers,
Jaskaran.

> thanks,
> julia
> 
> 
> > [PATCH 01/13] parsing_cocci: Align C AST and SmPL AST for enum
> > [PATCH 02/13] ocaml: coccilib: Reflect changes in SmPL AST for
> > [PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly
> > [PATCH 04/13] parsing_cocci: Add EnumDeclTag and EnumDeclDotsTag to
> > [PATCH 05/13] ocaml: coccilib: Reflect EnumDeclTag and
> > [PATCH 06/13] parsing_cocci: visitor_ast0: Add visitor functions
> > for
> > [PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in
> > [PATCH 08/13] parsing_cocci: Add visitor functions for enum_decl in
> > [PATCH 09/13] cocci: Reflect changes in SmPL visitor_ast in
> > codebase
> > [PATCH 10/13] engine: cocci_vs_c: Match enumerators properly as per
> > [PATCH 11/13] cocci: pretty print EnumDef as per enum_decl type
> > [PATCH 12/13] tests: Add test case for assigned enumerator
> > [PATCH 13/13] tools: spgen: Reflect visitor changes
> > 
> >  cocci.ml                              |    4 -
> >  engine/asttoctl2.ml                   |   21 +++++---
> >  engine/asttomember.ml                 |   17 ++++---
> >  engine/cocci_vs_c.ml                  |   46 ++++++++-----------
> >  engine/transformation_c.ml            |    4 -
> >  ocaml/coccilib.mli                    |   22 ++++++++-
> >  parsing_c/unparse_cocci.ml            |   27 ++++++++++-
> >  parsing_c/unparse_hrule.ml            |    4 -
> >  parsing_cocci/arity.ml                |   25 ++++++++++
> >  parsing_cocci/ast0_cocci.ml           |   15 +++++-
> >  parsing_cocci/ast0_cocci.mli          |   14 +++++
> >  parsing_cocci/ast0toast.ml            |   30 +++++++++++-
> >  parsing_cocci/ast0toast.mli           |    4 +
> >  parsing_cocci/ast_cocci.ml            |   13 +++++
> >  parsing_cocci/ast_cocci.mli           |   12 ++++-
> >  parsing_cocci/check_meta.ml           |   17 +++++--
> >  parsing_cocci/cleanup_rules.ml        |    5 +-
> >  parsing_cocci/commas_on_lists.ml      |   10 ++--
> >  parsing_cocci/compute_lines.ml        |   25 ++++++++++
> >  parsing_cocci/context_neg.ml          |   47 +++++++++++++++++--
> >  parsing_cocci/disjdistr.ml            |   29 +++++++++---
> >  parsing_cocci/free_vars.ml            |   27 +++++------
> >  parsing_cocci/function_prototypes.ml  |    7 +-
> >  parsing_cocci/get_constants2.ml       |    7 +-
> >  parsing_cocci/index.ml                |    7 ++
> >  parsing_cocci/index.mli               |    2
> >  parsing_cocci/insert_plus.ml          |   39 +++++++++++++---
> >  parsing_cocci/iso_compile.ml          |    4 -
> >  parsing_cocci/iso_pattern.ml          |   80
> > ++++++++++++++++++++++++++++------
> >  parsing_cocci/parse_aux.ml            |    5 ++
> >  parsing_cocci/parse_aux.mli           |    9 +++
> >  parsing_cocci/parse_cocci.ml          |    4 -
> >  parsing_cocci/parser_cocci_menhir.mly |   13 ++---
> >  parsing_cocci/pretty_print_cocci.ml   |   18 +++++++
> >  parsing_cocci/re_constraints.ml       |   10 ++--
> >  parsing_cocci/safe_for_multi_decls.ml |   11 ++--
> >  parsing_cocci/single_statement.ml     |    5 +-
> >  parsing_cocci/stmtlist.ml             |    4 -
> >  parsing_cocci/unify_ast.ml            |   29 ++++++++++--
> >  parsing_cocci/unitary_ast0.ml         |    5 +-
> >  parsing_cocci/unparse_ast0.ml         |   22 ++++++++-
> >  parsing_cocci/visitor_ast.ml          |   72
> > +++++++++++++++++++++++++++---
> >  parsing_cocci/visitor_ast.mli         |    8 +++
> >  parsing_cocci/visitor_ast0.ml         |   72
> > ++++++++++++++++++++++++++++--
> >  parsing_cocci/visitor_ast0.mli        |    4 +
> >  parsing_cocci/visitor_ast0_types.ml   |   14 +++++
> >  parsing_cocci/visitor_ast0_types.mli  |   12 +++++
> >  popl/popltoctl.ml                     |    2
> >  popl09/popltoctl.ml                   |    5 +-
> >  tests/enum_assign.c                   |    6 ++
> >  tests/enum_assign.cocci               |   11 ++++
> >  tests/enum_assign.res                 |    7 ++
> >  tools/spgen/source/detect_patch.ml    |    6 +-
> >  tools/spgen/source/meta_variable.ml   |    6 +-
> >  tools/spgen/source/rule_body.ml       |    6 +-
> >  55 files changed, 748 insertions(+), 182 deletions(-)
> > 
> > 

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

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

* Re: [Cocci] [PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in parsing_cocci
@ 2020-03-09 12:33 Markus Elfring
  0 siblings, 0 replies; 17+ messages in thread
From: Markus Elfring @ 2020-03-09 12:33 UTC (permalink / raw)
  To: Jaskaran Singh, cocci; +Cc: linux-kernel-mentees

> The SmPL AST0 visitor has functions for handling enumerators
> separately. Handle these collateral evolutions in parsing_cocci

I got the impression that an other change description would be easier to understand.

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

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

end of thread, back to index

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [Cocci] [PATCH 08/13] parsing_cocci: Add visitor functions for enum_decl in visitor_ast Jaskaran Singh
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
2020-03-09 12:33 [Cocci] [PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in parsing_cocci Markus Elfring

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git