[Linux-kernel-mentees] [PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly

Jaskaran Singh jaskaransingh7654321 at gmail.com
Sun Mar 8 08:43:46 UTC 2020


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

Signed-off-by: Jaskaran Singh <jaskaransingh7654321 at 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



More information about the Linux-kernel-mentees mailing list