Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs
@ 2020-03-16 10:02 Jaskaran Singh
  2020-03-16 10:02 ` [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token Jaskaran Singh
                   ` (25 more replies)
  0 siblings, 26 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:02 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The aim of this patch series is to add the types ParenType
and FunctionType to the SmPL AST. These types are present in
the C AST but not in the SmPL AST.

Preliminarily, a hack to resolve a reduce/reduce conflict
with the funproto rule in the SmPL parser is implemented.

Upon this, rules similar to that of the C parser's direct
declarator and abstract direct declarator rules are implemented,
and used wherever suitable.  These rules produce ParenType and
FunctionType, similar to the C parser.

Cases for these types are added to various places in the codebase.

The FunctionPointer type is removed from the SmPL AST, since
all the productions that produce FunctionPointers in the SmPL
parser are replaced by those that produce ParenType. Any functions,
constructs or cases of FunctionPointer are also removed from the
codebase.

A test case to match an array of function pointers is included to
demonstrate matching improvements.

[PATCH 01/26] parsing_cocci: Add Function Prototype token
[PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to
[PATCH 03/26] parsing_cocci: parser: Add
[PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for
[PATCH 05/26] parsing_cocci: visitor_ast0: Add cases for
[PATCH 06/26] parsing_cocci: arity: Add cases for
[PATCH 07/26] parsing_cocci: index: Add cases for
[PATCH 08/26] parsing_cocci: context_neg: Add cases for
[PATCH 09/26] parsing_cocci: unparse_ast0: Add cases for
[PATCH 10/26] parsing_cocci: single_statement: Add cases for
[PATCH 11/26] parsing_cocci: function_prototypes: Add cases for
[PATCH 12/26] parsing_cocci: check_meta: Add cases for
[PATCH 13/26] parsing_cocci: iso_pattern: Add cases for
[PATCH 14/26] parsing_cocci: adjust_pragmas: Add cases for
[PATCH 15/26] parsing_cocci: compute_lines: Add cases for
[PATCH 16/26] parsing_cocci: ast0toast: Add cases for
[PATCH 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType
[PATCH 18/26] parsing_cocci: unify_ast: Add cases for
[PATCH 19/26] parsing_cocci: disjdistr: Add cases for
[PATCH 20/26] parsing_cocci: ast_cocci: Add cases for
[PATCH 21/26] parsing_cocci: pretty_print_cocci: Print
[PATCH 22/26] parsing_c: unparse_cocci: Print ParenType/FunctionType
[PATCH 23/26] engine: Match A.ParenType and A.FunctionType
[PATCH 24/26] tools: spgen: Add cases for ParenType/FunctionType
[PATCH 25/26] cocci: Remove Ast_cocci.FunctionPointer
[PATCH 26/26] tests: Add test case for array of function pointers

 engine/check_exhaustive_pattern.ml       |    3 
 engine/cocci_vs_c.ml                     |   82 +++-------
 ocaml/coccilib.mli                       |   10 -
 parsing_c/unparse_cocci.ml               |   74 +++++++--
 parsing_cocci/adjust_pragmas.ml          |    7 
 parsing_cocci/arity.ml                   |   25 ++-
 parsing_cocci/ast0_cocci.ml              |    7 
 parsing_cocci/ast0_cocci.mli             |    6 
 parsing_cocci/ast0toast.ml               |   11 -
 parsing_cocci/ast_cocci.ml               |   21 +-
 parsing_cocci/ast_cocci.mli              |    6 
 parsing_cocci/check_meta.ml              |    8 -
 parsing_cocci/compute_lines.ml           |   21 +-
 parsing_cocci/context_neg.ml             |    4 
 parsing_cocci/disjdistr.ml               |   16 +-
 parsing_cocci/function_prototypes.ml     |    7 
 parsing_cocci/get_constants.ml           |    2 
 parsing_cocci/index.ml                   |    3 
 parsing_cocci/iso_pattern.ml             |   17 --
 parsing_cocci/parse_cocci.ml             |   72 +++++++--
 parsing_cocci/parser_cocci_menhir.mly    |  248 +++++++++++++++----------------
 parsing_cocci/pretty_print_cocci.ml      |   71 +++++++-
 parsing_cocci/single_statement.ml        |    3 
 parsing_cocci/type_cocci.mli             |    3 
 parsing_cocci/type_infer.ml              |   25 +--
 parsing_cocci/unify_ast.ml               |   16 +-
 parsing_cocci/unparse_ast0.ml            |   56 +++++--
 parsing_cocci/visitor_ast.ml             |  101 +++++++++---
 parsing_cocci/visitor_ast0.ml            |  214 ++++++++++++++++++++------
 tests/funptr_array.c                     |    1 
 tests/funptr_array.cocci                 |    9 +
 tests/funptr_array.res                   |    1 
 tools/spgen/source/meta_variable.ml      |    1 
 tools/spgen/source/position_generator.ml |    9 -
 34 files changed, 754 insertions(+), 406 deletions(-)

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

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

* [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
@ 2020-03-16 10:02 ` Jaskaran Singh
  2020-03-18 17:25   ` Julia Lawall
  2020-03-16 10:02 ` [Cocci] [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs Jaskaran Singh
                   ` (24 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:02 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

To add the types ParenType and FunctionType to the SmPL AST, a
reduce/reduce conflict with the funproto rule of the SmPL parser
must be resolved. This requires explicitly identifying a function
prototype by use of a token (TFunProto).

While the correct method of identifying a function prototype would be to
check if an identifier is preceded by a return type, it is challenging
to implement. This is because implementing an OCaml function, to
correctly determine a C type in SmPL, without the aid of Yacc, would
have to handle a number of cases (disjunctions, typeof expressions,
etc.).

Thus, a slightly hacky approach is taken to determine a function
prototype with not the best certainty but what works for most cases
in SmPL. If the identifier is preceded by any token that does not
seem to be part of a type, then it is not identified as a function
prototype. Else, it is.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/parse_cocci.ml          | 72 +++++++++++++++++++++++----
 parsing_cocci/parser_cocci_menhir.mly |  9 ++--
 2 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml
index 679d213a..4b2cb7e4 100644
--- a/parsing_cocci/parse_cocci.ml
+++ b/parsing_cocci/parse_cocci.ml
@@ -295,6 +295,7 @@ let token2c (tok,_) add_clt =
   | PC.TLineEnd(clt) -> "line end"
   | PC.TInvalid -> "invalid"
   | PC.TFunDecl(clt) -> "fundecl"
+  | PC.TFunProto(clt) -> "funproto"
 
   | PC.TIso -> "<=>"
   | PC.TRightIso -> "=>"
@@ -480,7 +481,7 @@ let get_clt (tok,_) =
 
   | PC.TOPar0(_,clt) | PC.TMid0(_,clt) | PC.TAnd0(_,clt) | PC.TCPar0(_,clt)
   | PC.TOEllipsis(clt) | PC.TCEllipsis(clt)
-  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt)
+  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) | PC.TFunProto(clt)
   | PC.TFunDecl(clt) | PC.TDirective(_,clt) | PC.TAttr_(clt)
   | PC.TLineEnd(clt) -> clt
   | PC.TVAEllipsis(clt) -> clt
@@ -718,6 +719,7 @@ let update_clt (tok,x) clt =
 
   | PC.TLineEnd(_) -> (PC.TLineEnd(clt),x)
   | PC.TFunDecl(_) -> (PC.TFunDecl(clt),x)
+  | PC.TFunProto(_) -> (PC.TFunProto(clt),x)
   | PC.TTildeExclEq(_) -> (PC.TTildeExclEq(clt),x)
   | PC.TDirective(a,_) -> (PC.TDirective(a,clt),x)
   | PC.TAttr_(_) -> (PC.TAttr_(clt),x)
@@ -925,7 +927,7 @@ let split_token ((tok,_) as t) =
   | PC.TInitialize | PC.TFinalize -> ([t],[t])
   | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt) -> split t clt
 
-  | PC.TFunDecl(clt)
+  | PC.TFunDecl(clt) | PC.TFunProto(clt)
   | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
   | PC.TAny(clt) | PC.TStrict(clt) | PC.TLineEnd(clt)
   | PC.TEllipsis(clt)
@@ -1006,7 +1008,8 @@ let find_function_names l =
     | _ -> false in
   let rec split acc = function
       [] | [_] -> raise Irrelevant
-    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest ->
+    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest
+    | ((PC.TCPar(_),_) as t1) :: ((PC.TPtVirg(_),_) as t2) :: rest ->
 	(List.rev (t1::acc),(t2::rest))
     | x::xs -> split (x::acc) xs in
   let rec balanced_name level = function
@@ -1037,7 +1040,48 @@ let find_function_names l =
     | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_ ->
 	raise Irrelevant
     | t::rest -> balanced_args level rest in
-  let rec loop = function
+  let rec is_permissible_proto = function
+      [] -> false
+    | (PC.TCPar0(_),_)::
+      ((PC.TMid0(_),_) | (PC.TAnd0(_),_))::
+      (PC.TOPar0(_),_)::_ -> false
+    | (PC.TOPar0(_),_)::rest
+    | (PC.TCPar0(_),_)::rest -> is_permissible_proto rest
+    | x::rest when is_mid x ->
+        let rec loop = function
+          [] -> false
+        | (PC.TOPar0(_),_)::xs -> is_permissible_proto xs
+        | x::xs -> loop xs in
+        loop rest
+    | _::((PC.TEq(_),_) | (PC.TNotEq(_),_))::(PC.TWhen(_),_)::_
+    | _::(PC.TWhen(_),_)::_
+    | (PC.TComma(_),_)::_
+    | (PC.TDirective(_),_)::_
+    | (PC.TElse(_),_)::_
+    | (PC.TReturn(_),_)::_
+    | (PC.TMetaStm(_),_)::_
+    | (PC.TMetaExp(_),_)::_
+    | (PC.TMetaId(_),_)::_
+    | (PC.TMetaLocalIdExp(_),_)::_
+    | (PC.TEq(_),_)::_
+    | (PC.TEllipsis(_),_)::_
+    | (PC.TOEllipsis(_),_)::_
+    | (PC.TCEllipsis(_),_)::_
+    | (PC.TPOEllipsis(_),_)::_
+    | (PC.TPCEllipsis(_),_)::_
+    | (PC.TPtVirg(_),_)::_
+    | (PC.TOBrace(_),_)::_
+    | (PC.TCBrace(_),_)::_
+    | (PC.TOPar(_),_)::_
+    | (PC.TCPar(_),_)::_
+    | (PC.TIdent(_),_)::_ -> false
+    | _ -> true in
+  let decl_or_proto clt info bef aft =
+    match aft with
+      (PC.TOBrace(_),_)::_ -> (((PC.TFunDecl(clt),info) :: bef), aft)
+    | (PC.TPtVirg(_),_)::_ -> (((PC.TFunProto(clt),info) :: bef), aft)
+    | _ -> raise Irrelevant in
+  let rec loop acc = function
       [] -> []
     | t :: rest ->
 	if is_par t || is_mid t || is_ident t
@@ -1046,26 +1090,30 @@ let find_function_names l =
 	    try
 	      let (bef,aft) = split [] (t::rest) in
 	      let rest = balanced_name 0 bef in
+              (match aft with
+                (PC.TPtVirg(_),_)::_
+                 when not(is_permissible_proto acc) -> raise Irrelevant
+              | _ ->
 	      (match rest with
 		(PC.TOPar(_),_)::_ ->
 		  (match balanced_args 0 rest with
 		    [] ->
 		      let (_,info) as h = List.hd bef in
 		      let clt = get_clt h in
-		      (((PC.TFunDecl(clt),info) :: bef), aft)
+                      decl_or_proto clt info bef aft
 		  | (PC.TAttr_(_),_)::rest ->
 		      (match balanced_args 0 rest with
 			[] ->
 			  let (_,info) as h = List.hd bef in
 			  let clt = get_clt h in
-			  (((PC.TFunDecl(clt),info) :: bef), aft)
+                          decl_or_proto clt info bef aft
 		      | _ -> raise Irrelevant)
 		  | _ -> raise Irrelevant)
-	      | _ -> raise Irrelevant)
+	      | _ -> raise Irrelevant))
 	    with Irrelevant -> ([t],rest) in
-	  t @ (loop rest)
-	else t :: (loop rest) in
-  loop l
+          t @ (loop (t @ acc) rest)
+        else t :: (loop (t :: acc) rest) in
+  loop [] l
 
 (* ----------------------------------------------------------------------- *)
 (* an attribute is an identifier that precedes another identifier and
@@ -1168,6 +1216,8 @@ let detect_types in_meta_decls l =
 	delim::newid::id::(loop false infn (ident::type_names) rest)
     | ((PC.TFunDecl(_),_) as fn)::rest ->
 	fn::(loop false 1 type_names rest)
+    | ((PC.TFunProto(_),_) as fn)::rest ->
+	fn::(loop false 1 type_names rest)
     | ((PC.TOPar(_),_) as lp)::rest when infn > 0 ->
 	lp::(loop false (infn + 1) type_names rest)
     | ((PC.TCPar(_),_) as rp)::rest when infn > 0 ->
@@ -1252,7 +1302,7 @@ let token2line (tok,_) =
   | PC.TMetaDParamList(_,_,_,_,clt) | PC.TMetaFunc(_,_,_,clt)
   | PC.TMetaLocalFunc(_,_,_,clt) | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt)
 
-  | PC.TFunDecl(clt)
+  | PC.TFunDecl(clt) | PC.TFunProto(clt)
   | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
   | PC.TAny(clt) | PC.TStrict(clt) | PC.TEllipsis(clt)
 
diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
index 9e6c8a08..26958f63 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -239,7 +239,8 @@ let inline_id aft = function
 
 %token <Data.clt> TVAEllipsis
 %token <Data.clt> TIf TElse TWhile TFor TDo TSwitch TCase TDefault TReturn
-%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof TFunDecl Tdecimal Texec
+%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof TFunDecl TFunProto
+%token <Data.clt> Tdecimal Texec
 %token <string * Data.clt> TIdent TTypeId TDeclarerId TIteratorId TSymId
 %token <Ast_cocci.added_string * Data.clt> TDirective
 %token <Data.clt> TAttr_
@@ -1439,7 +1440,8 @@ reverse_separated_nonempty_llist(separator, X):
 
 funproto:
   s=ioption(storage) i=ioption(Tinline) t=ctype
-  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
+  TFunProto id=fn_ident
+  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
       { let s = match s with None -> [] | Some s -> [Ast0.FStorage s] in
         let i =
 	  match i with
@@ -1453,7 +1455,8 @@ funproto:
 	      P.clt2mcode "(" lp, args, vararg, P.clt2mcode ")" rp,
 	      P.clt2mcode ";" pt)) }
 | i=Tinline s=storage t=ctype
-  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
+  TFunProto id=fn_ident
+  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
       { let s = [Ast0.FStorage s] in
         let i = [Ast0.FInline (P.clt2mcode "inline" i)] in
 	let t = [Ast0.FType t] in
-- 
2.21.1

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

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

* [Cocci] [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
  2020-03-16 10:02 ` [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token Jaskaran Singh
@ 2020-03-16 10:02 ` Jaskaran Singh
  2020-03-18 17:27   ` Julia Lawall
  2020-03-16 10:02 ` [Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules Jaskaran Singh
                   ` (23 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:02 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are types present in the C AST that
are not present in the SmPL AST. In the pursuit of aligning
both the C and SmPL ASTs, add these types to the SmPL ASTs.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 ocaml/coccilib.mli           | 6 ++++++
 parsing_cocci/ast0_cocci.ml  | 3 +++
 parsing_cocci/ast0_cocci.mli | 3 +++
 parsing_cocci/ast_cocci.ml   | 3 +++
 parsing_cocci/ast_cocci.mli  | 3 +++
 5 files changed, 18 insertions(+)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 5a913099..e5409a97 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -2709,6 +2709,9 @@ module Ast_cocci :
       | Pointer of fullType * string mcode
       | FunctionPointer of fullType * string mcode * string mcode *
           string mcode * string mcode * parameter_list * string mcode
+      | ParenType of string mcode (* ( *) * fullType * string mcode (* ) *)
+      | FunctionType of fullType *
+          string mcode (* ( *) * parameter_list * string mcode (* ) *)
       | Array of fullType * string mcode * expression option * string mcode
       | Decimal of string mcode * string mcode * expression *
           string mcode option * expression option * string mcode
@@ -3353,6 +3356,9 @@ module Ast0_cocci :
       | Pointer of typeC * string mcode
       | FunctionPointer of typeC * string mcode * string mcode *
           string mcode * string mcode * parameter_list * string mcode
+      | ParenType of string mcode * typeC * string mcode
+      | FunctionType of typeC *
+          string mcode * parameter_list * string mcode
       | Array of typeC * string mcode * expression option * string mcode
       | Decimal of string mcode * string mcode * expression *
           string mcode option * expression option * string mcode
diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index 77dc46f0..0acbeaa4 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -203,6 +203,9 @@ and base_typeC =
   | FunctionPointer of typeC *
 	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
                   string mcode (* ( *)*parameter_list*string mcode(* ) *)
+  | ParenType       of string mcode (* ( *) * typeC * string mcode (* ) *)
+  | FunctionType    of typeC *
+                  string mcode (* ( *) * parameter_list * string mcode (* ) *)
   | Array           of typeC * string mcode (* [ *) *
 	               expression option * string mcode (* ] *)
   | Decimal         of string mcode (* decimal *) * string mcode (* ( *) *
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 274c6bc2..33bd12b2 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -194,6 +194,9 @@ and base_typeC =
   | FunctionPointer of typeC *
 	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
                   string mcode (* ( *)*parameter_list*string mcode(* ) *)
+  | ParenType       of string mcode (* ( *) * typeC * string mcode (* ) *)
+  | FunctionType    of typeC *
+                  string mcode (* ( *) * parameter_list * string mcode (* ) *)
   | Array           of typeC * string mcode (* [ *) *
 	               expression option * string mcode (* ] *)
   | Decimal         of string mcode (* decimal *) * string mcode (* ( *) *
diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index ba6ec29e..f8e6dee6 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -343,6 +343,9 @@ and base_typeC =
   | FunctionPointer of fullType *
 	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
                   string mcode (* ( *)*parameter_list*string mcode(* ) *)
+  | ParenType       of string mcode (* ( *) * fullType * string mcode (* ) *)
+  | FunctionType    of fullType *
+                  string mcode (* ( *) * parameter_list * string mcode (* ) *)
   | Array           of fullType * string mcode (* [ *) *
 	               expression option * string mcode (* ] *)
   | Decimal         of string mcode (* decimal *) * string mcode (* ( *) *
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index 5f21664b..7fb54e4d 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -325,6 +325,9 @@ and base_typeC =
   | FunctionPointer of fullType *
 	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
                   string mcode (* ( *)*parameter_list*string mcode(* ) *)
+  | ParenType       of string mcode (* ( *) * fullType * string mcode (* ) *)
+  | FunctionType    of fullType *
+                  string mcode (* ( *) * parameter_list * string mcode (* ) *)
   | Array           of fullType * string mcode (* [ *) *
 	               expression option * string mcode (* ] *)
   | Decimal         of string mcode (* decimal *) * string mcode (* ( *) *
-- 
2.21.1

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

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

* [Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
  2020-03-16 10:02 ` [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token Jaskaran Singh
  2020-03-16 10:02 ` [Cocci] [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs Jaskaran Singh
@ 2020-03-16 10:02 ` Jaskaran Singh
  2020-03-18 17:31   ` Julia Lawall
  2020-03-16 10:02 ` [Cocci] [PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType Jaskaran Singh
                   ` (22 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:02 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The direct_declarator rule and the direct_abstract_d rule are
present in the C parser. Add similar rules to the SmPL parser so that
declarators are parsed as they are in the C parser.

For the type ParenType, direct_declarator and direct_abstract_d only
allow the following productions:

	( * id  [ .* ] ) ( params )

i.e. a function pointer or an array of function pointers. The compromise
is flexibility in the range of productions, mainly because collateral
evolutions needed by having a flexible rule are very large and
distasteful.

Replace usage of the older d_ident rule in the SmPL parser with the
above mentioned rules. All usages of d_ident, however, have not been
removed due to reduce/reduce conflicts.

Remove rules/productions that parse function pointers with usage of
direct_declarator and direct_abstract_d.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/parser_cocci_menhir.mly | 239 +++++++++++++-------------
 1 file changed, 116 insertions(+), 123 deletions(-)

diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
index 26958f63..fade830f 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -1116,33 +1116,17 @@ struct_decl_one:
 	{ let (mids,code) = t in
 	Ast0.wrap
 	  (Ast0.ConjField(P.id2mcode lp,code,mids, P.id2mcode rp)) }
-    | t=ctype d=d_ident_option bf=struct_bitfield? pv=TPtVirg
+    | t=ctype d=direct_decl_option(disj_ident) bf=struct_bitfield? pv=TPtVirg
 	 { let (id,fn) = d in
 	 Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) }
-    | t=ctype lp1=TOPar st=TMul d=d_ident_option rp1=TCPar
-	lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
-	bf=struct_bitfield? pv=TPtVirg
-        { let (id,fn) = d in
-        let t =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
-		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
-        Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) }
-     | cv=ioption(const_vol) i=pure_ident_or_symbol d=d_ident_option
+    | cv=ioption(const_vol) i=pure_ident_or_symbol
+      d=direct_decl_option(disj_ident)
 	 bf=struct_bitfield?
 	 pv=TPtVirg
 	 { let (id,fn) = d in
 	 let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in
 	 Ast0.wrap(Ast0.Field(fn idtype,id,bf,P.clt2mcode ";" pv)) }
 
-d_ident_option:
-	 { None, (fun x -> x) }
-     | d=d_ident {
-       let (id, fn) = d in
-       (Some id, fn)
-    }
-
 struct_bitfield:
    c=TDotDot e=expr { (P.clt2mcode ":" c, e) }
 
@@ -1529,17 +1513,9 @@ storage:
        | s=Tregister    { P.clt2mcode Ast.Register s }
        | s=Textern      { P.clt2mcode Ast.Extern s }
 
-decl: t=ctype i=disj_ident a=list(array_dec)
-	{ let t = P.arrayify t a in Ast0.wrap(Ast0.Param(t, Some i)) }
+decl: t=ctype d=direct_declarator(disj_ident)
+	{ let (i,fn) = d in Ast0.wrap(Ast0.Param(fn t, Some i)) }
     | t=ctype { (*verify in FunDecl*) Ast0.wrap(Ast0.Param(t, None)) }
-    | t=ctype lp=TOPar s=TMul i=disj_ident rp=TCPar
-	lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar
-        { let fnptr =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")" rp,
-		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
-	Ast0.wrap(Ast0.Param(fnptr, Some i)) }
     | TMetaParam
 	{ let (nm,cstr,pure,clt) = $1 in
 	Ast0.wrap(Ast0.MetaParam(P.clt2mcode nm clt,cstr,pure)) }
@@ -1547,14 +1523,6 @@ decl: t=ctype i=disj_ident a=list(array_dec)
 
 name_opt_decl:
       decl  { $1 }
-    | t=ctype lp=TOPar s=TMul rp=TCPar
-	lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar
-        { let fnptr =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")" rp,
-		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
-	Ast0.wrap(Ast0.Param(fnptr, None)) }
 
 const_vol:
       Tconst       { P.clt2mcode Ast.Const $1 }
@@ -1684,13 +1652,15 @@ decl_var:
     t=ctype pv=TPtVirg
       { [Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv))] }
   | TMetaDecl { [P.meta_decl $1] }
-  | s=ioption(storage) t=ctype d=comma_list(d_ident) pv=TPtVirg
+  | s=ioption(storage) t=ctype
+      d=comma_list(direct_declarator(disj_ident)) pv=TPtVirg
       { List.map
 	  (function (id,fn) ->
 	    Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv)))
 	  d }
   | f=funproto { [f] }
-  | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq e=initialize
+  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
+    a=attr_list q=TEq e=initialize
       pv=TPtVirg
       {let (id,fn) = d in
       [Ast0.wrap
@@ -1711,18 +1681,6 @@ decl_var:
       let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in
       [Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
 			   P.clt2mcode ";" pv))] }
-  /* function pointer type */
-  | s=ioption(storage)
-    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
-    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
-    pv=TPtVirg
-      { let (id,fn) = d in
-        let t =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
-		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
-        [Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv))] }
   | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option c=TCPar
       p=TPtVirg
       { [Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e,
@@ -1735,56 +1693,25 @@ decl_var:
 	       (s,d,P.clt2mcode "(" o,e,
 		P.clt2mcode ")" c,P.clt2mcode "=" q,i,
 		P.clt2mcode ";" p))] }
-  | s=ioption(storage)
-    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
-    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
-    q=TEq e=initialize pv=TPtVirg
-      { let (id,fn) = d in
-        let t =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
-		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
-      [Ast0.wrap
-	  (Ast0.Init(s,fn t,id,[],P.clt2mcode "=" q,e,P.clt2mcode ";" pv))]}
-  | s=Ttypedef t=typedef_ctype id=comma_list(typedef_ident) pv=TPtVirg
+  | s=Ttypedef t=typedef_ctype
+      d=comma_list(direct_declarator(typedef_ident)) pv=TPtVirg
       { let s = P.clt2mcode "typedef" s in
         List.map
-	  (function id ->
-	    Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv)))
-	  id }
-  | s=Ttypedef t=typedef_ctype id=typedef_ident
-      l=TOCro i=eexpr r=TCCro pv=TPtVirg
-      { let s = P.clt2mcode "typedef" s in
-        let t = P.arrayify t [(l,Some i,r)] in
-	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))] }
-  | s=Ttypedef t=typedef_ctype id=typedef_ident
-      l=TOCro i=eexpr r=TCCro
-      l2=TOCro i2=eexpr r2=TCCro pv=TPtVirg
-      { let s = P.clt2mcode "typedef" s in
-        let t = P.arrayify t [(l,Some i,r)] in
-        let t = P.arrayify t [(l2,Some i2,r2)] in
-	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))] }
-  | s=Ttypedef
-    t=typedef_ctype lp1=TOPar st=TMul id=typedef_ident rp1=TCPar
-    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar pv=TPtVirg
-      { let s = P.clt2mcode "typedef" s in
-        let t =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
-		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
-	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))]}
+	  (function (id,fn) ->
+	    Ast0.wrap(Ast0.Typedef(s,fn t,id,P.clt2mcode ";" pv)))
+	  d }
 
 one_decl_var:
     t=ctype pv=TPtVirg
       { Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv)) }
   | TMetaDecl { P.meta_decl $1 }
-  | s=ioption(storage) t=ctype d=d_ident a=attr_list pv=TPtVirg
+  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
+      a=attr_list pv=TPtVirg
       { let (id,fn) = d in
         Ast0.wrap(Ast0.UnInit(s,fn t,id,a,P.clt2mcode ";" pv)) }
   | f=funproto { f }
-  | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq e=initialize
+  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
+      a=attr_list q=TEq e=initialize
       pv=TPtVirg
       { let (id,fn) = d in
       Ast0.wrap
@@ -1802,18 +1729,6 @@ one_decl_var:
       let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in
       Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
 			   P.clt2mcode ";" pv)) }
-  /* function pointer type */
-  | s=ioption(storage)
-    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
-    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
-    pv=TPtVirg
-      { let (id,fn) = d in
-        let t =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
-		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
-        Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv)) }
   | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option c=TCPar
       p=TPtVirg
       { Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e,
@@ -1826,19 +1741,103 @@ one_decl_var:
                (s,d,P.clt2mcode "(" o,e,
                 P.clt2mcode ")" c,P.clt2mcode "=" q,i,
                 P.clt2mcode ";" p)) }
-  | s=ioption(storage)
-    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
-    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar a=attr_list
-    q=TEq e=initialize pv=TPtVirg
-      { let (id,fn) = d in
-        let t =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
-		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
-      Ast0.wrap(Ast0.Init(s,fn t,id,a,P.clt2mcode "=" q,e,P.clt2mcode ";" pv))}
 
 
+direct_declarator(ident_type):
+    ident_type
+      { ($1, function x -> x) }
+  | o=TOPar m=list(TMul) d=direct_declarator(ident_type) c=TCPar
+      { let (id,fn) = d in
+        (id,
+         function t ->
+          let ty =  fn (P.pointerify t m) in
+          let _ =
+           match Ast0.unwrap ty with
+            Ast0.Pointer(ty1,_) ->
+             (match Ast0.unwrap ty1 with
+               Ast0.FunctionType(ty2,_,_,_) -> ()
+             | _ ->
+              raise (Semantic_cocci.Semantic "expected function pointer"))
+           | Ast0.Array(ty1,_,_,_) ->
+              (match Ast0.unwrap ty1 with
+                Ast0.Pointer(ty2,_) ->(
+                 match Ast0.unwrap ty2 with
+                  Ast0.FunctionType(ty3,_,_,_) -> ()
+                 | _ ->
+                  raise (Semantic_cocci.Semantic "expected function pointer"))
+             | _ ->
+              raise (Semantic_cocci.Semantic "expected function pointer"))
+           | _ ->
+            raise (Semantic_cocci.Semantic "expected function pointer") in
+          Ast0.wrap
+            (Ast0.ParenType
+               (P.clt2mcode "(" o,
+                ty,
+                P.clt2mcode ")" c))) }
+  | d=direct_declarator(ident_type) a=array_dec
+      { let (id,fn) = d in
+        (id, function t -> let r = P.arrayify t [a] in fn r) }
+  | d=direct_declarator(ident_type)
+      o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
+      { let (id,fn) = d in
+        (id, function t ->
+              let r =
+               Ast0.wrap
+                (Ast0.FunctionType
+                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c)) in fn r) }
+
+
+direct_abstract_d:
+    o=TOPar m=list(TMul) d=direct_abstract_d c=TCPar
+      { function t ->
+          let ty = d (P.pointerify t m) in
+          let _ =
+           match Ast0.unwrap ty with
+            Ast0.Pointer(ty1,_) ->
+             (match Ast0.unwrap ty1 with
+               Ast0.FunctionType(ty2,_,_,_) ->()
+             | _ ->
+              raise (Semantic_cocci.Semantic "expected function pointer"))
+           | Ast0.Array(ty1,_,_,_) ->
+              (match Ast0.unwrap ty1 with
+                Ast0.Pointer(ty2,_) ->(
+                 match Ast0.unwrap ty2 with
+                  Ast0.FunctionType(ty3,_,_,_) -> ()
+                 | _ ->
+                  raise (Semantic_cocci.Semantic "expected function pointer"))
+             | _ ->
+              raise (Semantic_cocci.Semantic "expected function pointer"))
+           | _ ->
+            raise (Semantic_cocci.Semantic "expected function pointer") in
+          Ast0.wrap
+            (Ast0.ParenType
+               (P.clt2mcode "(" o,
+                ty,
+                P.clt2mcode ")" c))
+      }
+  | a=array_dec
+      { function t -> P.arrayify t [a] }
+  | d=direct_abstract_d a=array_dec
+      { function t -> let r = P.arrayify t [a] in d r }
+  | o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
+      { function t ->
+               Ast0.wrap
+                (Ast0.FunctionType
+                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c)) }
+  | d=direct_abstract_d o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
+      { function t ->
+              let r =
+               Ast0.wrap
+                (Ast0.FunctionType
+                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c)) in d r }
+
+
+direct_decl_option(ident_type):
+      { (None, function x -> x) }
+  | d=direct_declarator(ident_type)
+      { let (id,fn) = d in
+        (Some id, fn) }
+
 d_ident:
     disj_ident list(array_dec)
       { ($1, function t -> P.arrayify t $2) }
@@ -2151,16 +2150,10 @@ cast_expr(r,pe):
     unary_expr(r,pe)                      { $1 }
   | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe)
       { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t,
+                             P.clt2mcode ")" rp, e)) }
+  | lp=TOPar t=ctype d=direct_abstract_d rp=TCPar e=cast_expr(r,pe)
+      { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t,
 			     P.clt2mcode ")" rp, e)) }
-  | lp=TOPar t=ctype lp1=TOPar s=TMul rp1=TCPar
-      lp2=TOPar d=decl_list(name_opt_decl) rp2=TCPar rp=TCPar
-      e=cast_expr(r,pe)
-      { let fnptr =
-	  Ast0.wrap
-	    (Ast0.FunctionPointer
-	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" s,P.clt2mcode ")" rp1,
-		P.clt2mcode "(" lp2,d,P.clt2mcode ")" rp2)) in
-      Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, fnptr, P.clt2mcode ")" rp, e)) }
 
 unary_expr(r,pe):
     postfix_expr(r,pe)                   { $1 }
-- 
2.21.1

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

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

* [Cocci] [PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (2 preceding siblings ...)
  2020-03-16 10:02 ` [Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules Jaskaran Singh
@ 2020-03-16 10:02 ` Jaskaran Singh
  2020-03-18 17:42   ` Julia Lawall
  2020-03-16 10:02 ` [Cocci] [PATCH 05/26] " Jaskaran Singh
                   ` (21 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:02 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The order of the terms in ParenType require implementing a special
case for ParenType. This case handles only the following:

	<type> ( * id [ .* ] ) ( params )

i.e., a function pointer or an array of function pointers, and will fail
for any other cases. This is similar to the function used to print
ParenType in Pretty_print_c.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/visitor_ast0.ml | 163 ++++++++++++++++++++++++++++++++++
 1 file changed, 163 insertions(+)

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index c282e1f8..c56cd7a7 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -339,6 +339,12 @@ let visitor mode bind option_default
 	| Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
 	    let (t,id) =
               function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2) in t
+        | Ast0.ParenType(lp,ty,rp) ->
+	    let (t,id) =
+              parentype_type (lp,ty,None,rp) in t
+        | Ast0.FunctionType(ty,lp,params,rp) ->
+	    let (t,id) =
+              functiontype_type (ty,None,lp,params,rp) in t
 	| Ast0.Array(ty,lb,size,rb) ->
             let (t,id) = array_type (ty,None,lb,size,rb) in t
 	| Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) ->
@@ -435,6 +441,76 @@ let visitor mode bind option_default
     ((multibind ([ty_n] @ idl @ [lb_n;size_n;rb_n]),
      Ast0.Array(ty,lb,size,rb)), idu)
 
+  and parentype_type (lp,ty,(id : Ast0.ident option),rp) =
+    match Ast0.unwrap ty with
+      Ast0.Pointer(ty1,star) ->
+        (match Ast0.unwrap ty1 with
+          Ast0.FunctionType(ty2,lp2,params,rp2) ->
+            let (ty_n,typ) = typeC ty2 in
+            let (lp_n,lp) = string_mcode lp in
+            let (star_n,star) = string_mcode star in
+            let (idl,idu) = (match id with
+              | Some a -> let (b,c) = ident a in ([b],Some c)
+              | None -> ([],None)) in
+            let (rp_n,rp) = string_mcode rp in
+            let (lp2_n,lp2) = string_mcode lp2 in
+            let (params_n,params) = parameter_dots params in
+            let (rp2_n,rp2) = string_mcode rp2 in
+            ((multibind ([ty_n;lp_n;star_n] @ idl @
+              [rp_n;lp2_n;params_n;rp2_n]),
+               Ast0.ParenType
+                 (lp,
+                  Ast0.rewrap ty1 (Ast0.Pointer
+                   (Ast0.rewrap ty2 (Ast0.FunctionType
+                     (typ,lp2,params,rp2)),star)),rp)), idu)
+	| _ -> failwith "ParenType Visitor_ast0")
+    | Ast0.Array(ty1,lb1,size1,rb1) ->
+        (match Ast0.unwrap ty1 with
+          Ast0.Pointer(ty2,star) ->
+            (match Ast0.unwrap ty2 with
+              Ast0.FunctionType(ty3,lp3,params,rp3) ->
+                let (ty_n,typ) = typeC ty3 in
+                let (lp_n,lp) = string_mcode lp in
+                let (star_n,star) = string_mcode star in
+                let (idl,idu) = (match id with
+                  | Some a -> let (b,c) = ident a in ([b],Some c)
+                  | None -> ([],None)) in
+                let (lb1_n,lb1) = string_mcode lb1 in
+                let (size_n,size1) = get_option expression size1 in
+                let (rb1_n,rb1) = string_mcode rb1 in
+                let (rp_n,rp) = string_mcode rp in
+                let (lp3_n,lp3) = string_mcode lp3 in
+                let (params_n,params) = parameter_dots params in
+                let (rp3_n,rp3) = string_mcode rp3 in
+                ((multibind ([ty_n;lp_n;star_n] @ idl @
+                  [lb1_n;size_n;rb1_n;rp_n;lp3_n;params_n;rp3_n]),
+                   Ast0.ParenType
+                     (lp,
+                      Ast0.rewrap ty1
+                       (Ast0.Array
+                         (Ast0.rewrap ty2
+                           (Ast0.Pointer
+                             (Ast0.rewrap ty3
+                               (Ast0.FunctionType(typ,lp3,params,rp3)),
+                              star)),
+                        lb1,size1,rb1)),
+                   rp)),
+                 idu)
+    	    | _ -> failwith "ParenType Visitor_ast0")
+        | _ -> failwith "ParenType Visitor_ast0")
+    | _ -> failwith "ParenType Visitor_ast0"
+
+  and functiontype_type (ty,(id : Ast0.ident option),lp,params,rp) =
+    let (ty_n,ty) = typeC ty in
+    let (idl,idu) = (match id with
+      | Some a -> let (b,c) = ident a in ([b],Some c)
+      | None -> ([],None)) in
+    let (lp_n,lp) = string_mcode lp in
+    let (params_n,params) = parameter_dots params in
+    let (rp_n,rp) = string_mcode rp in
+    ((multibind ([ty_n] @ idl @ [lp_n; params_n; rp_n]),
+     Ast0.FunctionType(ty,lp,params,rp)), idu)
+
   and named_type ty id =
     match Ast0.unwrap ty with
       Ast0.FunctionPointer(rty,lp1,star,rp1,lp2,params,rp2) ->
@@ -446,6 +522,14 @@ let visitor mode bind option_default
 	let (tyres, idn) = array_type (rty,Some id,lb,size,rb) in
         let idn = match idn with Some i -> i | None -> failwith "Impossible" in
 	(rewrap ty tyres, idn)
+    | Ast0.ParenType(lp,rty,rp) ->
+	let (tyres, idn) = parentype_type (lp,rty,Some id,rp) in
+        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
+	(rewrap ty tyres, idn)
+    | Ast0.FunctionType(rty,lp,params,rp) ->
+	let (tyres, idn) = functiontype_type (rty,Some id,lp,params,rp) in
+        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
+	(rewrap ty tyres, idn)
     | _ -> let (ty_n,ty) = typeC ty in
            let (id_n,id) = ident id in
              ((bind ty_n id_n, ty), id)
@@ -479,6 +563,77 @@ let visitor mode bind option_default
     ((multibind ([ty_n] @ idl @ [lb_n;size_n;rb_n]),
      Ast0.Array(ty,lb,size,rb)), idu)
 
+  (* returns ((bind value,original value),id) since id may have been updated*)
+  and parentype_typedef (lp,ty,id,rp) =
+    match Ast0.unwrap ty with
+      Ast0.Pointer(ty1,star) ->
+        (match Ast0.unwrap ty1 with
+          Ast0.FunctionType(ty2,lp2,params,rp2) ->
+            let (ty_n,typ) = typeC ty2 in
+            let (lp_n,lp) = string_mcode lp in
+            let (star_n,star) = string_mcode star in
+            let (idl,idu) = (match id with
+              | Some a -> let (b,c) = typeC a in ([b],Some c)
+              | None -> ([],None)) in
+            let (rp_n,rp) = string_mcode rp in
+            let (lp2_n,lp2) = string_mcode lp2 in
+            let (params_n,params) = parameter_dots params in
+            let (rp2_n,rp2) = string_mcode rp2 in
+            ((multibind ([ty_n;lp_n;star_n] @ idl @
+              [rp_n;lp2_n;params_n;rp2_n]),
+               Ast0.ParenType
+                 (lp,
+                  Ast0.rewrap ty1 (Ast0.Pointer
+                   (Ast0.rewrap ty2 (Ast0.FunctionType
+                     (typ,lp2,params,rp2)),star)),rp)), idu)
+	| _ -> failwith "ParenType Visitor_ast0")
+    | Ast0.Array(ty1,lb1,size1,rb1) ->
+        (match Ast0.unwrap ty with
+          Ast0.Pointer(ty2,star) ->
+            (match Ast0.unwrap ty1 with
+              Ast0.FunctionType(ty3,lp3,params,rp3) ->
+                let (ty_n,typ) = typeC ty3 in
+                let (lp_n,lp) = string_mcode lp in
+                let (star_n,star) = string_mcode star in
+                let (idl,idu) = (match id with
+                  | Some a -> let (b,c) = typeC a in ([b],Some c)
+                  | None -> ([],None)) in
+                let (lb1_n,lb1) = string_mcode lb1 in
+                let (size_n,size1) = get_option expression size1 in
+                let (rb1_n,rb1) = string_mcode rb1 in
+                let (rp_n,rp) = string_mcode rp in
+                let (lp3_n,lp3) = string_mcode lp3 in
+                let (params_n,params) = parameter_dots params in
+                let (rp3_n,rp3) = string_mcode rp3 in
+                ((multibind ([ty_n;lp_n;star_n] @ idl @
+                  [lb1_n;size_n;rb1_n;rp_n;lp3_n;params_n;rp3_n]),
+                   Ast0.ParenType
+                     (lp,
+                      Ast0.rewrap ty1
+                       (Ast0.Array
+                         (Ast0.rewrap ty2 
+                           (Ast0.Pointer
+                             (Ast0.rewrap ty3
+                               (Ast0.FunctionType(typ,lp3,params,rp3)),
+                              star)),
+                        lb1,size1,rb1)),
+                   rp)),
+                 idu)
+    	    | _ -> failwith "ParenType Visitor_ast0")
+        | _ -> failwith "ParenType Visitor_ast0")
+    | _ -> failwith "ParenType Visitor_ast0"
+
+  and functiontype_typedef (ty,id,lp,params,rp) =
+    let (ty_n,ty) = typeC ty in
+    let (idl,idu) = (match id with
+      | Some a -> let (b,c) = typeC a in ([b],Some c)
+      | None -> ([],None)) in
+    let (lp_n,lp) = string_mcode lp in
+    let (params_n,params) = parameter_dots params in
+    let (rp_n,rp) = string_mcode rp in
+    ((multibind ([ty_n] @ idl @ [lp_n; params_n; rp_n]),
+     Ast0.FunctionType(ty,lp,params,rp)), idu)
+
   and named_type_typedef ty id =
     match Ast0.unwrap ty with
       Ast0.FunctionPointer(rty,lp1,star,rp1,lp2,params,rp2) ->
@@ -490,6 +645,14 @@ let visitor mode bind option_default
 	let (tyres, idn) = array_type_typedef (rty,Some id,lb,size,rb) in
         let idn = match idn with Some i -> i | None -> failwith "Impossible" in
 	(rewrap ty tyres, idn)
+    | Ast0.ParenType(lp,rty,rp) ->
+	let (tyres, idn) = parentype_typedef (lp,rty,Some id,rp) in
+        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
+	(rewrap ty tyres, idn)
+    | Ast0.FunctionType(rty,lp,params,rp) ->
+	let (tyres, idn) = functiontype_typedef (rty,Some id,lp,params,rp) in
+        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
+	(rewrap ty tyres, idn)
     | _ -> let (ty_n,ty) = typeC ty in
            let (id_n,id) = typeC id in
              ((bind ty_n id_n, ty), id)
-- 
2.21.1

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

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

* [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (3 preceding siblings ...)
  2020-03-16 10:02 ` [Cocci] [PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType Jaskaran Singh
@ 2020-03-16 10:02 ` " Jaskaran Singh
  2020-03-17  5:59   ` [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast: " Jaskaran Singh
  2020-03-17  8:43   ` [Cocci] [PATCH v2 " Jaskaran Singh
  2020-03-16 10:02 ` [Cocci] [PATCH 06/26] parsing_cocci: arity: " Jaskaran Singh
                   ` (20 subsequent siblings)
  25 siblings, 2 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:02 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The order of the terms in ParenType require implementing a special
case for ParenType. This case handles only the following:

	<type> ( * id [ .* ] ) ( params )

i.e., a function pointer or an array of function pointers, and will fail
for any other cases. This is similar to the function used to print
ParenType in Pretty_print_c.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/visitor_ast.ml | 75 ++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 3d5de794..99af7652 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -318,6 +318,61 @@ let combiner bind option_default
     let lrb = string_mcode rb in
     multibind ([lty] @ lid @ [lb; lsize; lrb])
 
+  and parentype_type (lp, ty, (id : Ast.ident option), rp) =
+    match Ast.unwrap ty with
+     Ast.Type(_,_,fty1) ->
+      (match Ast.unwrap fty1 with
+         Ast.Pointer(ty1,star) ->
+          (match Ast.unwrap ty1 with
+             Ast.Type(_,_,fty2) ->
+              (match Ast.unwrap fty2 with
+                Ast.FunctionType(ty2,lp2,params,rp2) ->
+                  let typ = fullType ty2 in
+                  let lp = string_mcode lp in
+                  let star = string_mcode star in
+                  let idl = match id with
+                    | Some idd -> [ident idd]
+                    | None -> [] in
+                  let rp = string_mcode rp in
+                  let lp2 = string_mcode lp2 in
+                  let params = parameter_dots params in
+                  let rp2 = string_mcode rp2 in
+                  multibind
+                    ([typ;lp;star] @ idl @ [rp;lp2;params;rp2])
+                | _ -> failwith "ParenType Visitor_ast")
+           | _ -> failwith "ParenType Visitor_ast")
+       | Ast.Array(ty1,lb1,size1,rb1) ->
+          (match Ast.unwrap ty1 with
+            Ast.Type(_,_,fty2) ->
+             (match Ast.unwrap fty2 with
+               Ast.Pointer(ty2,star) ->
+                (match Ast.unwrap ty2 with
+                  Ast.Type(_,_,fty3) ->
+                   (match Ast.unwrap fty3 with
+                     Ast.FunctionType(ty3,lp3,params,rp3) ->
+                     let typ = fullType ty3 in
+                     let lp = string_mcode lp in
+                     let star = string_mcode star in
+                     let idl = match id with
+                       | Some idd -> [ident idd]
+                       | None -> [] in
+                     let lb1 = string_mcode lb1 in
+                     let size1 = get_option expression size1 in
+                     let rb1 = string_mcode rb1 in
+                     let rp = string_mcode rp in
+                     let lp3 = string_mcode lp3 in
+                     let params = parameter_dots params in
+                     let rp3 = string_mcode rp3 in
+                     multibind
+                       ([typ;lp;star] @ idl @
+                        [lb1;size1;rb1;rp;lp3;params;rp3])
+   	           | _ -> failwith "ParenType Visitor_ast")
+                | _ -> failwith "ParenType Visitor_ast")
+             | _ -> failwith "ParenType Visitor_ast")
+          | _ -> failwith "ParenType Visitor_ast")
+       | _ -> failwith "ParenType Visitor_ast")
+    | _ -> failwith "ParenType Visitor_ast"
+
   and typeC ty =
     let k ty =
       match Ast.unwrap ty with
@@ -332,6 +387,14 @@ let combiner bind option_default
 	  bind lty lstar
       | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
 	  function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2)
+      | Ast.ParenType(lp,ty,rp) ->
+          parentype_type (lp,ty,None,rp)
+      | Ast.FunctionType(ty,lp,params,rp) ->
+          let lty = fullType ty in
+          let llp = string_mcode lp in
+          let lparams = parameter_dots params in
+          let lrp = string_mcode rp in
+          multibind [lty; llp; lparams; lrp]
       | Ast.Array(ty,lb,size,rb) -> array_type (ty,None,lb,size,rb)
       | Ast.Decimal(dec,lp,length,comma,precision_opt,rp) ->
 	  let ldec = string_mcode dec in
@@ -384,6 +447,7 @@ let combiner bind option_default
 	  Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
 	    function_pointer (ty, lp1, star, Some id, rp1, lp2, params, rp2)
 	| Ast.Array(ty,lb,size,rb) -> array_type (ty, Some id, lb, size, rb)
+        | Ast.ParenType(lp,ty,rp) -> parentype_type (lp, ty, Some id, rp)
 	| _ -> let lty = fullType ty in
 	       let lid = ident id in
 	       bind lty lid)
@@ -1253,6 +1317,17 @@ let rebuilder
 	    let lparams = parameter_dots params in
 	    let lrp2 = string_mcode rp2 in
 	    Ast.FunctionPointer(lty, llp1, lstar, lrp1, llp2, lparams, lrp2)
+        | Ast.ParenType(lp,ty,rp) ->
+            let llp = string_mcode lp in
+            let lty = fullType ty in
+            let lrp = string_mcode rp in
+            Ast.ParenType(llp,lty,lrp)
+        | Ast.FunctionType(ty,lp,params,rp) ->
+            let lty = fullType ty in
+            let llp = string_mcode lp in
+            let lparams = parameter_dots params in
+            let lrp = string_mcode rp in
+            Ast.FunctionType(lty,llp,lparams,lrp)
 	| Ast.Array(ty,lb,size,rb) ->
 	    let lty = fullType ty in
 	    let llb = string_mcode lb in
-- 
2.21.1

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

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

* [Cocci] [PATCH 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (4 preceding siblings ...)
  2020-03-16 10:02 ` [Cocci] [PATCH 05/26] " Jaskaran Singh
@ 2020-03-16 10:02 ` " Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 07/26] parsing_cocci: index: " Jaskaran Singh
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:02 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are added to the SmPL ASTs. Add
cases for these types in arity.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/arity.ml | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
index f29b86eb..3b408554 100644
--- a/parsing_cocci/arity.ml
+++ b/parsing_cocci/arity.ml
@@ -419,6 +419,23 @@ and top_typeC tgt opt_allowed typ =
       let params = parameter_list tgt params in
       make_typeC typ tgt arity
 	(Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))
+  | Ast0.ParenType(lp,ty,rp) ->
+      let arity =
+        all_same opt_allowed tgt (mcode2line lp)
+        [mcode2arity lp; mcode2arity rp] in
+      let lp = mcode lp in
+      let ty = typeC arity ty in
+      let rp = mcode rp in
+      make_typeC typ tgt arity (Ast0.ParenType(lp,ty,rp))
+  | Ast0.FunctionType(ty,lp,params,rp) ->
+      let arity =
+        all_same opt_allowed tgt (mcode2line lp)
+        [mcode2arity lp; mcode2arity rp] in
+      let ty = typeC arity ty in
+      let lp = mcode lp in
+      let params = parameter_list tgt params in
+      let rp = mcode rp in
+      make_typeC typ tgt arity (Ast0.FunctionType(ty,lp,params,rp))
   | Ast0.Array(ty,lb,size,rb) ->
       let arity =
 	all_same opt_allowed tgt (mcode2line lb)
-- 
2.21.1

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

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

* [Cocci] [PATCH 07/26] parsing_cocci: index: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (5 preceding siblings ...)
  2020-03-16 10:02 ` [Cocci] [PATCH 06/26] parsing_cocci: arity: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-18 18:35   ` Julia Lawall
  2020-03-16 10:03 ` [Cocci] [PATCH 08/26] parsing_cocci: context_neg: " Jaskaran Singh
                   ` (18 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in index.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/index.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
index a1103503..5c91f620 100644
--- a/parsing_cocci/index.ml
+++ b/parsing_cocci/index.ml
@@ -93,6 +93,8 @@ let typeC t =
   | Ast0.Signed(sign,ty) -> [129]
   | Ast0.Pointer(ty,star) -> [49]
   | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> [131]
+  | Ast0.ParenType(lp,ty,rp) -> [138]
+  | Ast0.FunctionType(ty,lp,params,rp) -> [139]
   | Ast0.Array(ty,lb,size,rb) -> [50]
   | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> [160]
   | Ast0.EnumName(kind,name) -> [146]
-- 
2.21.1

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

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

* [Cocci] [PATCH 08/26] parsing_cocci: context_neg: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (6 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 07/26] parsing_cocci: index: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 09/26] parsing_cocci: unparse_ast0: " Jaskaran Singh
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in context_neg.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/context_neg.ml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml
index 7bbf743d..b3a52daf 100644
--- a/parsing_cocci/context_neg.ml
+++ b/parsing_cocci/context_neg.ml
@@ -663,6 +663,10 @@ let equal_typeC t1 t2 =
       equal_mcode sign1 sign2
   | (Ast0.Pointer(_,star1),Ast0.Pointer(_,star2)) ->
       equal_mcode star1 star2
+  | (Ast0.ParenType(lp1,_,rp1),Ast0.ParenType(lp2,_,rp2)) ->
+      equal_mcode lp1 lp2 && equal_mcode rp1 rp2
+  | (Ast0.FunctionType(_,lp1,_,rp1),Ast0.FunctionType(_,lp2,_,rp2)) ->
+      equal_mcode lp1 lp2 && equal_mcode rp1 rp2
   | (Ast0.Array(_,lb1,_,rb1),Ast0.Array(_,lb2,_,rb2)) ->
       equal_mcode lb1 lb2 && equal_mcode rb1 rb2
   | (Ast0.Decimal(dec1,lp1,_,comma1,_,rp1),
-- 
2.21.1

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

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

* [Cocci] [PATCH 09/26] parsing_cocci: unparse_ast0: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (7 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 08/26] parsing_cocci: context_neg: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-18 18:36   ` Julia Lawall
  2020-03-16 10:03 ` [Cocci] [PATCH 10/26] parsing_cocci: single_statement: " Jaskaran Singh
                   ` (16 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType/FunctionType are now types in the SmPL ASTs. Add
cases for these types in unparse_ast0.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/unparse_ast0.ml | 43 +++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index 5d450e0e..f8684dd2 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -292,6 +292,40 @@ and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn =
   mcode print_string rp1; mcode print_string lp2;
   parameter_list params; mcode print_string rp2
 
+and print_parentype (lp,ty,rp) fn =
+ match Ast0.unwrap ty with
+   Ast0.Pointer(ty1,star) ->
+     (match Ast0.unwrap ty1 with
+       Ast0.FunctionType(ty2,lp2,params,rp2) ->
+         typeC ty2;
+         mcode print_string lp;
+         mcode print_string star;
+         fn();
+         mcode print_string rp;
+         mcode print_string lp2;
+         parameter_list params;
+         mcode print_string rp2;
+       | _ -> failwith "ParenType Unparse_ast0")
+ | Ast0.Array(ty1,lb1,size1,rb1) ->
+     (match Ast0.unwrap ty1 with
+       Ast0.Pointer(ty2,star) ->
+         (match Ast0.unwrap ty2 with
+           Ast0.FunctionType(ty3,lp3,params,rp3) ->
+             typeC ty3;
+             mcode print_string lp;
+             mcode print_string star;
+             fn();
+             mcode print_string lb1;
+             print_option expression size1;
+             mcode print_string rb1;
+             mcode print_string rp;
+             mcode print_string lp3;
+             parameter_list params;
+             mcode print_string rp3;
+ 	| _ -> failwith "ParenType Unparse_ast0")
+     | _ -> failwith "ParenType Unparse_ast0")
+ | _ -> failwith "ParenType Unparse_ast0"
+
 and typeC t =
   print_context t
     (function _ ->
@@ -306,6 +340,13 @@ and typeC t =
       | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
 	  print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
 	    (function _ -> ())
+      | Ast0.ParenType(lp,ty,rp) ->
+          print_parentype (lp,ty,rp) (function _ -> ())
+      | Ast0.FunctionType(ty,lp,params,rp) ->
+          typeC ty;
+          mcode print_string lp;
+          parameter_list params;
+          mcode print_string rp
       | Ast0.Array(ty,lb,size,rb) ->
 	  typeC ty; mcode print_string lb; print_option expression size;
 	  mcode print_string rb
@@ -367,6 +408,8 @@ and print_named_type ty id =
 		mcode print_string rb)
 	| _ -> typeC ty; ident id; k () in
       loop ty (function _ -> ())
+  | Ast0.ParenType(lp,ty,rp) ->
+      print_parentype (lp,ty,rp) (function _ -> ident id)
   | _ -> typeC ty; ident id
 
 and declaration d =
-- 
2.21.1

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

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

* [Cocci] [PATCH 10/26] parsing_cocci: single_statement: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (8 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 09/26] parsing_cocci: unparse_ast0: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-18 18:37   ` Julia Lawall
  2020-03-16 10:03 ` [Cocci] [PATCH 11/26] parsing_cocci: function_prototypes: " Jaskaran Singh
                   ` (15 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType/FunctionType are now types in the SmPL ASTs. Add
cases for these types in single_statement.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/single_statement.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml
index 46408b73..48d77b5a 100644
--- a/parsing_cocci/single_statement.ml
+++ b/parsing_cocci/single_statement.ml
@@ -166,6 +166,8 @@ and left_typeC t =
   | Ast0.Signed(sgn,ty) -> modif_before_mcode sgn
   | Ast0.Pointer(ty,star) -> left_typeC ty
   | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> left_typeC ty
+  | Ast0.ParenType(lp,ty,rp) -> left_typeC ty
+  | Ast0.FunctionType(ty,lp,params,rp) -> left_typeC ty
   | Ast0.Array(ty,lb,size,rb) -> left_typeC ty
   | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) ->
       modif_before_mcode dec
-- 
2.21.1

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

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

* [Cocci] [PATCH 11/26] parsing_cocci: function_prototypes: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (9 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 10/26] parsing_cocci: single_statement: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 12/26] parsing_cocci: check_meta: " Jaskaran Singh
                   ` (14 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in function_prototypes.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/function_prototypes.ml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/parsing_cocci/function_prototypes.ml b/parsing_cocci/function_prototypes.ml
index 2e6eea43..fd36f31b 100644
--- a/parsing_cocci/function_prototypes.ml
+++ b/parsing_cocci/function_prototypes.ml
@@ -229,6 +229,10 @@ let rec attach_right strings ty =
     | Ast0.FunctionPointer(ty,lp,star,rp,lp1,ps,rp1) ->
 	Ast0.FunctionPointer(ty,lp,star,rp,lp1,ps,
 			     right_attach_mcode strings rp1)
+    | Ast0.ParenType(lp,ty,rp) ->
+	Ast0.ParenType(lp,ty,right_attach_mcode strings rp)
+    | Ast0.FunctionType(ty,lp,ps,rp) ->
+	Ast0.FunctionType(ty,lp,ps,right_attach_mcode strings rp)
     | Ast0.Array(ty,lb,e,rb) ->
 	Ast0.Array(ty,lb,e,right_attach_mcode strings rb)
     | Ast0.Decimal(dec,lp,e1,comma,e2,rp) ->
-- 
2.21.1

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

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

* [Cocci] [PATCH 12/26] parsing_cocci: check_meta: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (10 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 11/26] parsing_cocci: function_prototypes: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 13/26] parsing_cocci: iso_pattern: " Jaskaran Singh
                   ` (13 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in check_meta.ml.

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

diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml
index 02b0fd9c..7b10bd53 100644
--- a/parsing_cocci/check_meta.ml
+++ b/parsing_cocci/check_meta.ml
@@ -224,6 +224,11 @@ and typeC old_metas table minus t =
   | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
       typeC old_metas table minus ty;
       parameter_list old_metas table minus params
+  | Ast0.ParenType(lp,ty,rp) ->
+      typeC old_metas table minus ty
+  | Ast0.FunctionType(ty,lp,params,rp) ->
+      typeC old_metas table minus ty;
+      parameter_list old_metas table minus params
   | Ast0.Array(ty,lb,size,rb) ->
       typeC old_metas table minus ty;
       get_opt (expression ID old_metas table minus) size
-- 
2.21.1

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

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

* [Cocci] [PATCH 13/26] parsing_cocci: iso_pattern: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (11 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 12/26] parsing_cocci: check_meta: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 14/26] parsing_cocci: adjust_pragmas: " Jaskaran Singh
                   ` (12 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in iso_pattern.ml.

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

diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 5ceb2bdb..6d51b072 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -1818,6 +1818,11 @@ let instantiate bindings mv_bindings model =
                           Ast0.rewrap ty (
                             Ast0.FunctionPointer(
                               renamer ty', s0, s1, s2, s3, p, s4))
+                      | Ast0.ParenType(s0, ty', s1) ->
+                          Ast0.rewrap ty (Ast0.ParenType(s0, renamer ty', s1))
+                      | Ast0.FunctionType(ty', s0, s1, s2) ->
+                          Ast0.rewrap ty (
+                            Ast0.FunctionType(renamer ty', s0, s1, s2))
                       | Ast0.Array(ty', s0, e, s1) ->
                           Ast0.rewrap ty (Ast0.Array(renamer ty', s0, e, s1))
                       | Ast0.Signed(s, ty') ->
-- 
2.21.1

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

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

* [Cocci] [PATCH 14/26] parsing_cocci: adjust_pragmas: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (12 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 13/26] parsing_cocci: iso_pattern: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-18 18:42   ` Julia Lawall
  2020-03-16 10:03 ` [Cocci] [PATCH 15/26] parsing_cocci: compute_lines: " Jaskaran Singh
                   ` (11 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in adjust_pragmas.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/adjust_pragmas.ml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/parsing_cocci/adjust_pragmas.ml b/parsing_cocci/adjust_pragmas.ml
index 73b5ff5f..537150e7 100644
--- a/parsing_cocci/adjust_pragmas.ml
+++ b/parsing_cocci/adjust_pragmas.ml
@@ -171,6 +171,10 @@ let rec left_ty t =
   | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
       call_right left_ty ty t
 	(function ty -> Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))
+  | Ast0.ParenType(lp,ty,rp) ->
+      call_right left_ty ty t (function ty -> Ast0.ParenType(lp,ty,rp))
+  | Ast0.FunctionType(ty,lp,params,rp) ->
+      call_right left_ty ty t (function ty -> Ast0.FunctionType(ty,lp,params,rp))
   | Ast0.Array(ty,lb,size,rb) ->
       call_right left_ty ty t (function ty -> Ast0.Array(ty,lb,size,rb))
   | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) ->
-- 
2.21.1

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

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

* [Cocci] [PATCH 15/26] parsing_cocci: compute_lines: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (13 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 14/26] parsing_cocci: adjust_pragmas: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-18 18:43   ` Julia Lawall
  2020-03-16 10:03 ` [Cocci] [PATCH 16/26] parsing_cocci: ast0toast: " Jaskaran Singh
                   ` (10 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in compute_lines.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/compute_lines.ml | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml
index f4b6f4d8..8231a0e7 100644
--- a/parsing_cocci/compute_lines.ml
+++ b/parsing_cocci/compute_lines.ml
@@ -574,6 +574,17 @@ and typeC t =
       let rp2 = normal_mcode rp2 in
       mkres t (Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))
 	ty (promote_mcode rp2)
+  | Ast0.ParenType(lp,ty,rp) ->
+      let lp = normal_mcode lp in
+      let rp = normal_mcode rp in
+      let ty = typeC ty in
+      mkres t (Ast0.ParenType(lp,ty,rp)) ty (promote_mcode rp)
+  | Ast0.FunctionType(ty,lp,params,rp) ->
+      let ty = typeC ty in
+      let lp = normal_mcode lp in
+      let params = parameter_list (Some(promote_mcode lp)) params in
+      let rp = normal_mcode rp in
+      mkres t (Ast0.FunctionType(ty,lp,params,rp)) ty (promote_mcode rp)
   | Ast0.Array(ty,lb,size,rb) ->
       let ty = typeC ty in
       let lb = normal_mcode lb in
-- 
2.21.1

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

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

* [Cocci] [PATCH 16/26] parsing_cocci: ast0toast: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (14 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 15/26] parsing_cocci: compute_lines: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types Jaskaran Singh
                   ` (9 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in ast0toast.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/ast0toast.ml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index f1bbde0b..dc7b30f7 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -562,6 +562,7 @@ and typeC allminus t =
 	| types -> Ast.DisjType(List.map (rewrap t no_isos) types))
     | Ast0.BaseType(_) | Ast0.Signed(_,_) | Ast0.Pointer(_,_)
     | Ast0.FunctionPointer(_,_,_,_,_,_,_)
+    | Ast0.ParenType(_,_,_) | Ast0.FunctionType(_,_,_,_)
     | Ast0.Array(_,_,_,_) | Ast0.Decimal(_,_,_,_,_,_)
     | Ast0.EnumName(_,_) | Ast0.StructUnionName(_,_)
     | Ast0.StructUnionDef(_,_,_,_) | Ast0.EnumDef(_,_,_,_)
@@ -588,6 +589,11 @@ and base_typeC allminus t =
       Ast.FunctionPointer
 	(typeC allminus ty,mcode lp1,mcode star,mcode rp1,
 	 mcode lp2,parameter_list params,mcode rp2)
+  | Ast0.ParenType(lp,ty,rp) ->
+      Ast.ParenType(mcode lp,typeC allminus ty,mcode rp)
+  | Ast0.FunctionType(ty,lp,params,rp) ->
+      Ast.FunctionType
+        (typeC allminus ty,mcode lp,parameter_list params,mcode rp)
   | Ast0.Array(ty,lb,size,rb) ->
       Ast.Array(typeC allminus ty,mcode lb,get_option expression size,
 		mcode rb)
-- 
2.21.1

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

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

* [Cocci] [PATCH 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (15 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 16/26] parsing_cocci: ast0toast: " Jaskaran Singh
@ 2020-03-16 10:03 ` Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType Jaskaran Singh
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in type_cocci.ml.

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

diff --git a/parsing_cocci/type_cocci.mli b/parsing_cocci/type_cocci.mli
index c1ccb58f..6f24adf7 100644
--- a/parsing_cocci/type_cocci.mli
+++ b/parsing_cocci/type_cocci.mli
@@ -16,6 +16,8 @@ type typeC =
   | SignedT         of sign * typeC option
   | Pointer         of typeC
   | FunctionPointer of typeC (* only return type *)
+  | ParenType       of typeC (* only return type *)
+  | FunctionType    of typeC (* only return type *)
   | Array           of typeC (* drop size info *)
   | Decimal         of name * name
   | EnumName        of name
-- 
2.21.1

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

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

* [Cocci] [PATCH 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (16 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types Jaskaran Singh
@ 2020-03-16 10:03 ` Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 19/26] parsing_cocci: disjdistr: " Jaskaran Singh
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in unify_ast.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/unify_ast.ml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml
index d4ad3030..de86b1d3 100644
--- a/parsing_cocci/unify_ast.ml
+++ b/parsing_cocci/unify_ast.ml
@@ -336,6 +336,14 @@ and unify_typeC t1 t2 =
 	 unify_fullType tya tyb &&
 	 unify_dots unify_parameterTypeDef pdots paramsa paramsb
        else false
+  | (Ast.ParenType(lpa,tya,rpa),Ast.ParenType(lpb,tyb,rpb)) ->
+      unify_fullType tya tyb && unify_mcode lpa lpb && unify_mcode rpa rpb
+  | (Ast.FunctionType(tya,lpa,paramsa,rpa),
+     Ast.FunctionType(tyb,lpb,paramsb,rpb)) ->
+      unify_fullType tya tyb &&
+      unify_mcode lpa lpb &&
+      unify_dots unify_parameterTypeDef pdots paramsa paramsb &&
+      unify_mcode rpa rpb
   | (Ast.Array(ty1,lb1,e1,rb1),Ast.Array(ty2,lb2,e2,rb2)) ->
       unify_fullType ty1 ty2 && unify_option unify_expression e1 e2
   | (Ast.Decimal(dec1,lp1,len1,comma1,prec_opt1,rp1),
-- 
2.21.1

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

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

* [Cocci] [PATCH 19/26] parsing_cocci: disjdistr: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (17 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 20/26] parsing_cocci: ast_cocci: " Jaskaran Singh
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in disjdistr.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/disjdistr.ml | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml
index 668a8810..91d7f1b8 100644
--- a/parsing_cocci/disjdistr.ml
+++ b/parsing_cocci/disjdistr.ml
@@ -73,6 +73,16 @@ and disjtypeC bty =
 	(function ty ->
 	  Ast.rewrap bty (Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2)))
 	ty
+  | Ast.ParenType(lp,ty,rp) ->
+      let ty = disjty ty in
+      List.map
+        (function ty ->
+          Ast.rewrap bty (Ast.ParenType(lp,ty,rp))) ty
+  | Ast.FunctionType(ty,lp,params,rp) ->
+      let ty = disjty ty in
+      List.map
+        (function ty ->
+          Ast.rewrap bty (Ast.FunctionType(ty,lp,params,rp))) ty
   | Ast.Array(ty,lb,size,rb) ->
       disjmult2 (disjty ty) (disjoption disjexp size)
 	(function ty -> function size ->
-- 
2.21.1

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

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

* [Cocci] [PATCH 20/26] parsing_cocci: ast_cocci: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (18 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 19/26] parsing_cocci: disjdistr: " Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType Jaskaran Singh
                   ` (5 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in ast_cocci.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/ast_cocci.ml | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index f8e6dee6..4fea9794 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -1110,6 +1110,10 @@ let rec string_of_typeC ty =
       string_of_fullType ty' ^ "*"
   | FunctionPointer (ty', _, _, _, _, _, _) ->
       string_of_fullType ty' ^ "(*)()"
+  | ParenType (_ , ty', _) ->
+      "(" ^ string_of_fullType ty' ^ ")"
+  | FunctionType (ty' , _, _, _) ->
+      string_of_fullType ty' ^ "()"
   | Array (ty', _, _, _) ->
       string_of_fullType ty' ^ "[]"
   | Decimal(_, _, e0, _, e1, _) ->
@@ -1191,6 +1195,10 @@ and typeC_map tr ty =
   | Pointer (ty', s) -> rewrap ty (Pointer (fullType_map tr ty', s))
   | FunctionPointer (ty, s0, s1, s2, s3, s4, s5) ->
       rewrap ty (FunctionPointer (fullType_map tr ty, s0, s1, s2, s3, s4, s5))
+  | ParenType (s0, ty', s1) ->
+      rewrap ty (ParenType (s0, fullType_map tr ty', s1))
+  | FunctionType (ty', s0, s1, s2) ->
+      rewrap ty (FunctionType (fullType_map tr ty', s0, s1, s2))
   | Array (ty', s0, s1, s2) ->
       rewrap ty (Array (fullType_map tr ty', s0, s1, s2))
   | EnumName (s0, ident) ->
@@ -1250,6 +1258,8 @@ and typeC_fold tr ty v =
   | SignedT (_, Some ty') -> typeC_fold tr ty' v
   | Pointer (ty', _)
   | FunctionPointer (ty', _, _, _, _, _, _)
+  | ParenType (_, ty', _)
+  | FunctionType (ty', _, _, _)
   | Array (ty', _, _, _)
   | EnumDef (ty', _, _, _)
   | StructUnionDef (ty', _, _, _) -> fullType_fold tr ty' v
-- 
2.21.1

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

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

* [Cocci] [PATCH 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (19 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 20/26] parsing_cocci: ast_cocci: " Jaskaran Singh
@ 2020-03-16 10:03 ` Jaskaran Singh
  2020-03-18 18:45   ` Julia Lawall
  2020-03-16 10:03 ` [Cocci] [PATCH 22/26] parsing_c: unparse_cocci: " Jaskaran Singh
                   ` (4 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The order of the terms in ParenType require implementing a special
case for ParenType. This case handles only the following:

        <type> ( * id [ .* ] ) ( params )

i.e., a function pointer or an array of function pointers, and will fail
for any other cases. This is similar to the function used to print
ParenType in Pretty_print_c.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/pretty_print_cocci.ml | 57 +++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml
index 6338e464..ef60106c 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -403,6 +403,54 @@ and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn =
   mcode print_string rp1; mcode print_string lp1;
   parameter_list params; mcode print_string rp2
 
+and print_parentype (lp,ty,rp) fn =
+  match Ast.unwrap ty with
+   Ast.Type(_,_,fty1) ->
+    (match Ast.unwrap fty1 with
+      Ast.Pointer(ty1,star) ->
+       (match Ast.unwrap ty1 with
+         Ast.Type(_,_,fty2) ->
+          (match Ast.unwrap fty2 with
+            Ast.FunctionType(ty2,lp2,params,rp2) ->
+             fullType ty2;
+             print_space();
+             mcode print_string lp;
+             mcode print_string star;
+             fn();
+             mcode print_string rp;
+             mcode print_string lp2;
+             parameter_list params;
+             mcode print_string rp2
+         | _ -> failwith "ParenType Pretty_print_cocci")
+       | _ -> failwith "ParenType Pretty_print_cocci")
+    | Ast.Array(ty1,lb1,size1,rb1) ->
+       (match Ast.unwrap ty1 with
+         Ast.Type(_,_,fty2) ->
+          (match Ast.unwrap fty2 with
+            Ast.Pointer(ty2,star) ->
+             (match Ast.unwrap ty2 with
+               Ast.Type(_,_,fty3) ->
+                (match Ast.unwrap fty3 with
+                  Ast.FunctionType(ty3,lp3,params,rp3) ->
+                  fullType ty3;
+                  print_space();
+                  mcode print_string lp;
+                  mcode print_string star;
+                  fn();
+                  mcode print_string lb1;
+                  print_option expression size1;
+                  mcode print_string rb1;
+                  mcode print_string rp;
+                  mcode print_string lp3;
+                  parameter_list params;
+                  mcode print_string rp3
+                | _ -> failwith "ParenType Pretty_print_cocci")
+             | _ -> failwith "ParenType Pretty_print_cocci")
+          | _ -> failwith "ParenType Pretty_print_cocci")
+       | _ -> failwith "ParenType Pretty_print_cocci")
+    | _ -> failwith "ParenType Pretty_print_cocci")
+  | _ -> failwith "ParenType Pretty_print_cocci"
+
 and varargs = function
   | None -> ()
   | Some (comma, ellipsis) ->
@@ -424,6 +472,13 @@ and typeC ty =
   | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
       print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
 	(function _ -> ())
+  | Ast.ParenType(lp,ty,rp) ->
+      print_parentype (lp,ty,rp) (function _ -> ())
+  | Ast.FunctionType(ty,lp,params,rp) ->
+      fullType ty;
+      mcode print_string lp;
+      parameter_list params;
+      mcode print_string rp
   | Ast.Array(ty,lb,size,rb) ->
       fullType ty; mcode print_string lb; print_option expression size;
       mcode print_string rb
@@ -498,6 +553,8 @@ and print_named_type ty id =
 		| _ -> failwith "complex array types not supported")
 	    | _ -> typeC ty; id(); k () in
 	  loop ty1 (function _ -> ())
+      | Ast.ParenType(lp,ty,rp) ->
+          print_parentype (lp,ty,rp) (function _ -> id())
       | _ -> fullType ty; id())
   | _ -> fullType ty; id()
 
-- 
2.21.1

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

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

* [Cocci] [PATCH 22/26] parsing_c: unparse_cocci: Print ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (20 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType Jaskaran Singh
@ 2020-03-16 10:03 ` " Jaskaran Singh
  2020-03-18 18:47   ` Julia Lawall
  2020-03-16 10:03 ` [Cocci] [PATCH 23/26] engine: Match A.ParenType and A.FunctionType Jaskaran Singh
                   ` (3 subsequent siblings)
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The order of the terms in ParenType require implementing a special
case for ParenType. This case handles only the following:

        <type> ( * id [ .* ] ) ( params )

i.e., a function pointer or an array of function pointers, and will fail
for any other cases. This is similar to the function used to print
ParenType in Pretty_print_c.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_c/unparse_cocci.ml | 60 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index 30e755e9..9dd84821 100644
--- a/parsing_c/unparse_cocci.ml
+++ b/parsing_c/unparse_cocci.ml
@@ -722,6 +722,13 @@ and typeC ty =
   | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
       print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
 	(function _ -> ())
+  | Ast.ParenType(lp,ty,rp) ->
+      print_parentype (lp,ty,rp) (function _ -> ())
+  | Ast.FunctionType(ty,lp,params,rp) ->
+      fullType ty;
+      mcode print_string lp;
+      parameter_list params;
+      mcode print_string rp
   | Ast.Array(ty,lb,size,rb) ->
       fullType ty; mcode print_string lb; print_option expression size;
       mcode print_string rb
@@ -786,6 +793,57 @@ and storage = function
   | Ast.Register -> print_string "register"
   | Ast.Extern -> print_string "extern"
 
+(* --------------------------------------------------------------------- *)
+(* ParenType *)
+
+and print_parentype (lp,ty,rp) fn =
+  match Ast.unwrap ty with
+   Ast.Type(_,_,fty1) ->
+    (match Ast.unwrap fty1 with
+      Ast.Pointer(ty1,star) ->
+       (match Ast.unwrap ty1 with
+         Ast.Type(_,_,fty2) ->
+          (match Ast.unwrap fty2 with
+            Ast.FunctionType(ty2,lp2,params,rp2) ->
+             fullType ty2;
+             pr_space();
+             mcode print_string lp;
+             mcode print_string star;
+             fn();
+             mcode print_string rp;
+             mcode print_string lp2;
+             parameter_list params;
+             mcode print_string rp2
+         | _ -> failwith "ParenType Unparse_cocci")
+       | _ -> failwith "ParenType Unparse_cocci")
+    | Ast.Array(ty1,lb1,size1,rb1) ->
+       (match Ast.unwrap ty1 with
+         Ast.Type(_,_,fty2) ->
+          (match Ast.unwrap fty2 with
+            Ast.Pointer(ty2,star) ->
+             (match Ast.unwrap ty2 with
+               Ast.Type(_,_,fty3) ->
+                (match Ast.unwrap fty3 with
+                  Ast.FunctionType(ty3,lp3,params,rp3) ->
+                  fullType ty3;
+                  pr_space();
+                  mcode print_string lp;
+                  mcode print_string star;
+                  fn();
+                  mcode print_string lb1;
+                  print_option expression size1;
+                  mcode print_string rb1;
+                  mcode print_string rp;
+                  mcode print_string lp3;
+                  parameter_list params;
+                  mcode print_string rp3
+                | _ -> failwith "ParenType Unparse_cocci")
+             | _ -> failwith "ParenType Unparse_cocci")
+          | _ -> failwith "ParenType Unparse_cocci")
+       | _ -> failwith "ParenType Unparse_cocci")
+    | _ -> failwith "ParenType Unparse_cocci")
+  | _ -> failwith "ParenType Unparse_cocci"
+
 (* --------------------------------------------------------------------- *)
 (* Variable declaration *)
 
@@ -818,6 +876,8 @@ and print_named_type ty id =
 		pretty_print_c.Pretty_print_c.type_with_ident ty
 		  (function _ -> id())
             | _ -> error name ty "type value expected")
+      | Ast.ParenType(lp,ty,rp) ->
+          print_parentype (lp,ty,rp) (function _ -> id())
     (*| should have a case here for pointer to array or function type
         that would put ( * ) around the variable.  This makes one wonder
         why we really need a special case for function pointer *)
-- 
2.21.1

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

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

* [Cocci] [PATCH 23/26] engine: Match A.ParenType and A.FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (21 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 22/26] parsing_c: unparse_cocci: " Jaskaran Singh
@ 2020-03-16 10:03 ` Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 24/26] tools: spgen: Add cases for ParenType/FunctionType Jaskaran Singh
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are added to the SmPL AST as types.
Match these types correctly.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 engine/check_exhaustive_pattern.ml |  2 ++
 engine/cocci_vs_c.ml               | 27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/engine/check_exhaustive_pattern.ml b/engine/check_exhaustive_pattern.ml
index 5a047f73..872c060c 100644
--- a/engine/check_exhaustive_pattern.ml
+++ b/engine/check_exhaustive_pattern.ml
@@ -149,6 +149,8 @@ let dumb_astcocci_type = function
  | A.SignedT (signa,tya) -> ()
  | A.Pointer (typa, _) -> ()
  | A.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> ()
+ | A.ParenType(lp,ty,rp) -> ()
+ | A.FunctionType(ty,lp,params,rp) -> ()
  | A.Array (typa, _, eaopt, _) -> ()
  | A.Decimal(_, _, _, _, _, _) -> ()
  | A.EnumName(en, ena) -> ()
diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index a4a0e53b..3e0eb50e 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -3785,6 +3785,29 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) =
         | _ -> fail
         )
 
+    | A.ParenType (lpa, typa, rpa), (B.ParenType typb, ii) ->
+        let (lpb, rpb) = tuple_of_list2 ii in
+        fullType typa typb >>= (fun typa typb ->
+        tokenf lpa lpb >>= (fun lpa lpb ->
+        tokenf rpa rpb >>= (fun rpa rpb ->
+          return (
+            (A.ParenType (lpa, typa, rpa)) +> A.rewrap ta,
+            (B.ParenType (typb), [lpb;rpb])
+          ))))
+
+    | A.FunctionType (typa, lpa, paramsa, rpa),
+        (B.FunctionType (typb, (paramsb, (isvaargs, iidotsb))), ii) ->
+        let (lpb, rpb) = tuple_of_list2 ii in
+        fullType typa typb >>= (fun typa typb ->
+        tokenf lpa lpb >>= (fun lpa lpb ->
+        tokenf rpa rpb >>= (fun rpa rpb ->
+        parameters (seqstyle paramsa) (A.unwrap paramsa) paramsb >>=
+        (fun paramsaunwrap paramsb ->
+          let paramsa = A.rewrap paramsa paramsaunwrap in
+          return (
+            (A.FunctionType (typa, lpa, paramsa, rpa)) +> A.rewrap ta,
+            (B.FunctionType (typb, (paramsb, (isvaargs, iidotsb))), [lpb;rpb])
+          )))))
 
 
     (* todo: handle the iso on optional size specification ? *)
@@ -4361,6 +4384,10 @@ and compatible_typeC a (b,local) =
     | A.FunctionPointer (a, _, _, _, _, _, _), _ ->
 	failwith
 	  "TODO: function pointer type doesn't store enough information to determine compatibility"
+    | A.ParenType (_, a, _), (qub, (B.ParenType b, ii)) ->
+	compatible_type a (b, local)
+    | A.FunctionType (a, _, _, _), (qub, (B.FunctionType (b,_), ii)) ->
+	compatible_type a (b, local)
     | A.Array (a, _, _, _), (qub, (B.Array (eopt, b),ii)) ->
       (* no size info for cocci *)
 	compatible_type a (b, local)
-- 
2.21.1

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

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

* [Cocci] [PATCH 24/26] tools: spgen: Add cases for ParenType/FunctionType
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (22 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 23/26] engine: Match A.ParenType and A.FunctionType Jaskaran Singh
@ 2020-03-16 10:03 ` Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 25/26] cocci: Remove Ast_cocci.FunctionPointer Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 26/26] tests: Add test case for array of function pointers Jaskaran Singh
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now added to the SmPL ASTs. Add
cases for these types in position_generator.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 tools/spgen/source/position_generator.ml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/spgen/source/position_generator.ml b/tools/spgen/source/position_generator.ml
index 31d6cb5e..2fa630fb 100644
--- a/tools/spgen/source/position_generator.ml
+++ b/tools/spgen/source/position_generator.ml
@@ -195,6 +195,12 @@ let rec type_pos t snp
   | Ast0.FunctionPointer(t,lp,star,rp,lp2,params,rp2) ->
       let constructor ~mc = Ast0.FunctionPointer(t,lp,star,rp,lp2,params,mc) in
       mcode_wrap ~mc:rp2 ~constructor snp
+  | Ast0.ParenType(lp,t,rp) ->
+      let constructor ~mc = Ast0.ParenType(lp,t,rp) in
+      mcode_wrap ~mc:rp ~constructor snp
+  | Ast0.FunctionType(t,lp,params,rp) ->
+      let constructor ~mc = Ast0.FunctionType(t,lp,params,rp) in
+      mcode_wrap ~mc:rp ~constructor snp
   | Ast0.Array(t,lb,expr,rb) ->
       let constructor ~mc = Ast0.Array(t,lb,expr,mc) in
       mcode_wrap ~mc:rb ~constructor snp
-- 
2.21.1

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

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

* [Cocci] [PATCH 25/26] cocci: Remove Ast_cocci.FunctionPointer
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (23 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 24/26] tools: spgen: Add cases for ParenType/FunctionType Jaskaran Singh
@ 2020-03-16 10:03 ` Jaskaran Singh
  2020-03-16 10:03 ` [Cocci] [PATCH 26/26] tests: Add test case for array of function pointers Jaskaran Singh
  25 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

ParenType and FunctionType are now in the SmPL AST, and these
types have replaced all productions related to the FunctionPointer
type in the SmPL parser.

Remove FunctionPointer from the SmPL ASTs, its cases and any functions
or constructs related to it from the codebase.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 engine/check_exhaustive_pattern.ml       |  1 -
 engine/cocci_vs_c.ml                     | 55 ------------------------
 ocaml/coccilib.mli                       |  4 --
 parsing_c/unparse_cocci.ml               | 14 +-----
 parsing_cocci/adjust_pragmas.ml          |  3 --
 parsing_cocci/arity.ml                   |  8 ----
 parsing_cocci/ast0_cocci.ml              |  4 --
 parsing_cocci/ast0_cocci.mli             |  3 --
 parsing_cocci/ast0toast.ml               |  5 ---
 parsing_cocci/ast_cocci.ml               |  8 ----
 parsing_cocci/ast_cocci.mli              |  3 --
 parsing_cocci/check_meta.ml              |  3 --
 parsing_cocci/compute_lines.ml           | 10 -----
 parsing_cocci/disjdistr.ml               |  6 ---
 parsing_cocci/function_prototypes.ml     |  3 --
 parsing_cocci/get_constants.ml           |  2 +-
 parsing_cocci/index.ml                   |  1 -
 parsing_cocci/iso_pattern.ml             | 12 ------
 parsing_cocci/pretty_print_cocci.ml      | 14 +-----
 parsing_cocci/single_statement.ml        |  1 -
 parsing_cocci/type_cocci.mli             |  1 -
 parsing_cocci/type_infer.ml              | 25 +++++------
 parsing_cocci/unify_ast.ml               |  8 ----
 parsing_cocci/unparse_ast0.ml            | 13 +-----
 parsing_cocci/visitor_ast.ml             | 26 -----------
 parsing_cocci/visitor_ast0.ml            | 51 +---------------------
 tools/spgen/source/meta_variable.ml      |  1 -
 tools/spgen/source/position_generator.ml |  3 --
 28 files changed, 19 insertions(+), 269 deletions(-)

diff --git a/engine/check_exhaustive_pattern.ml b/engine/check_exhaustive_pattern.ml
index 872c060c..fe0b2c78 100644
--- a/engine/check_exhaustive_pattern.ml
+++ b/engine/check_exhaustive_pattern.ml
@@ -148,7 +148,6 @@ let dumb_astcocci_type = function
  | A.BaseType (basea,strings) -> ()
  | A.SignedT (signa,tya) -> ()
  | A.Pointer (typa, _) -> ()
- | A.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> ()
  | A.ParenType(lp,ty,rp) -> ()
  | A.FunctionType(ty,lp,params,rp) -> ()
  | A.Array (typa, _, eaopt, _) -> ()
diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index 3e0eb50e..87b0ce70 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -3733,58 +3733,6 @@ and (typeC: (A.typeC, Ast_c.typeC) matcher) =
             (B.Pointer typb, [ibmult])
           )))
 
-    | A.FunctionPointer(tya,lp1a,stara,rp1a,lp2a,paramsa,rp2a),
-        (B.ParenType t1, ii) ->
-        let (lp1b, rp1b) = tuple_of_list2 ii in
-        let (qu1b, t1b) = t1 in
-        (match t1b with
-        | B.Pointer t2, ii ->
-            let (starb) = tuple_of_list1 ii in
-            let (qu2b, t2b) = t2 in
-            (match t2b with
-            | B.FunctionType (tyb, (paramsb, (isvaargs, iidotsb))), ii ->
-                let (lp2b, rp2b) = tuple_of_list2 ii in
-
-                if isvaargs
-                then
-		  pr2_once
-		    ("Not handling well variable length arguments func. "^
-		     "You have been warned");
-
-                fullType tya tyb >>= (fun tya tyb ->
-                tokenf lp1a lp1b >>= (fun lp1a lp1b ->
-                tokenf rp1a rp1b >>= (fun rp1a rp1b ->
-                tokenf lp2a lp2b >>= (fun lp2a lp2b ->
-                tokenf rp2a rp2b >>= (fun rp2a rp2b ->
-                tokenf stara starb >>= (fun stara starb ->
-                parameters (seqstyle paramsa) (A.unwrap paramsa) paramsb >>=
-                (fun paramsaunwrap paramsb ->
-                  let paramsa = A.rewrap paramsa paramsaunwrap in
-
-                  let t2 =
-                    (qu2b,
-                    (B.FunctionType (tyb, (paramsb, (isvaargs, iidotsb))),
-                    [lp2b;rp2b]))
-                  in
-                  let t1 =
-                    (qu1b,
-                    (B.Pointer t2, [starb]))
-                  in
-
-                  return (
-                    (A.FunctionPointer(tya,lp1a,stara,rp1a,lp2a,paramsa,rp2a))
-                    +> A.rewrap ta,
-                    (B.ParenType t1, [lp1b;rp1b])
-                  )
-                )))))))
-
-
-
-            | _ -> fail
-            )
-        | _ -> fail
-        )
-
     | A.ParenType (lpa, typa, rpa), (B.ParenType typb, ii) ->
         let (lpb, rpb) = tuple_of_list2 ii in
         fullType typa typb >>= (fun typa typb ->
@@ -4381,9 +4329,6 @@ and compatible_typeC a (b,local) =
 
     | A.Pointer (a, _), (qub, (B.Pointer b, ii)) ->
 	compatible_type a (b, local)
-    | A.FunctionPointer (a, _, _, _, _, _, _), _ ->
-	failwith
-	  "TODO: function pointer type doesn't store enough information to determine compatibility"
     | A.ParenType (_, a, _), (qub, (B.ParenType b, ii)) ->
 	compatible_type a (b, local)
     | A.FunctionType (a, _, _, _), (qub, (B.FunctionType (b,_), ii)) ->
diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index e5409a97..c54607d5 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -2707,8 +2707,6 @@ module Ast_cocci :
         BaseType of baseType * string mcode list
       | SignedT of sign mcode * typeC option
       | Pointer of fullType * string mcode
-      | FunctionPointer of fullType * string mcode * string mcode *
-          string mcode * string mcode * parameter_list * string mcode
       | ParenType of string mcode (* ( *) * fullType * string mcode (* ) *)
       | FunctionType of fullType *
           string mcode (* ( *) * parameter_list * string mcode (* ) *)
@@ -3354,8 +3352,6 @@ module Ast0_cocci :
       | BaseType of Ast_cocci.baseType * string mcode list
       | Signed of Ast_cocci.sign mcode * typeC option
       | Pointer of typeC * string mcode
-      | FunctionPointer of typeC * string mcode * string mcode *
-          string mcode * string mcode * parameter_list * string mcode
       | ParenType of string mcode * typeC * string mcode
       | FunctionType of typeC *
           string mcode * parameter_list * string mcode
diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index 9dd84821..6949f9b2 100644
--- a/parsing_c/unparse_cocci.ml
+++ b/parsing_c/unparse_cocci.ml
@@ -700,12 +700,6 @@ and fullType ft =
   | Ast.DisjType _ | Ast.ConjType _ -> raise CantBeInPlus
   | Ast.OptType(_) -> raise CantBeInPlus
 
-and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn =
-  fullType ty; pr_space();
-  mcode print_string lp1; mcode print_string star; fn();
-  mcode print_string rp1; mcode print_string lp1;
-  parameter_list params; mcode print_string rp2
-
 and print_fninfo = function
     Ast.FStorage(stg) -> mcode storage stg
   | Ast.FType(ty) -> fullType ty
@@ -719,9 +713,6 @@ and typeC ty =
   | Ast.SignedT(sgn,ty) -> mcode sign sgn; print_option_prespace typeC ty
   | Ast.Pointer(ty,star) ->
       fullType ty; ft_space ty; mcode print_string star; eatspace()
-  | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
-	(function _ -> ())
   | Ast.ParenType(lp,ty,rp) ->
       print_parentype (lp,ty,rp) (function _ -> ())
   | Ast.FunctionType(ty,lp,params,rp) ->
@@ -851,10 +842,7 @@ and print_named_type ty id =
   match Ast.unwrap ty with
     Ast.Type(_,None,ty1) ->
       (match Ast.unwrap ty1 with
-	Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-	  print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
-	    (function _ -> id())
-      | Ast.Array(_,_,_,_) ->
+        Ast.Array(_,_,_,_) ->
 	  let rec loop ty k =
 	    match Ast.unwrap ty with
 	      Ast.Array(ty,lb,size,rb) ->
diff --git a/parsing_cocci/adjust_pragmas.ml b/parsing_cocci/adjust_pragmas.ml
index 537150e7..a7f681f0 100644
--- a/parsing_cocci/adjust_pragmas.ml
+++ b/parsing_cocci/adjust_pragmas.ml
@@ -168,9 +168,6 @@ let rec left_ty t =
       call_right left_mcode sign t (function sign -> Ast0.Signed(sign,ty))
   | Ast0.Pointer(ty,star) ->
       call_right left_ty ty t (function ty -> Ast0.Pointer(ty,star))
-  | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      call_right left_ty ty t
-	(function ty -> Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))
   | Ast0.ParenType(lp,ty,rp) ->
       call_right left_ty ty t (function ty -> Ast0.ParenType(lp,ty,rp))
   | Ast0.FunctionType(ty,lp,params,rp) ->
diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
index 3b408554..e1515873 100644
--- a/parsing_cocci/arity.ml
+++ b/parsing_cocci/arity.ml
@@ -411,14 +411,6 @@ and top_typeC tgt opt_allowed typ =
       let ty = typeC arity ty in
       let star = mcode star in
       make_typeC typ tgt arity (Ast0.Pointer(ty,star))
-  | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      let arity =
-	all_same opt_allowed tgt (mcode2line lp1)
-	  (List.map mcode2arity [lp1;star;rp1;lp2;rp2]) in
-      let ty = typeC arity ty in
-      let params = parameter_list tgt params in
-      make_typeC typ tgt arity
-	(Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))
   | Ast0.ParenType(lp,ty,rp) ->
       let arity =
         all_same opt_allowed tgt (mcode2line lp)
diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index 0acbeaa4..1b4087c3 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -200,9 +200,6 @@ and base_typeC =
   | BaseType        of Ast.baseType * string mcode list
   | Signed          of Ast.sign mcode * typeC option
   | Pointer         of typeC * string mcode (* * *)
-  | FunctionPointer of typeC *
-	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
-                  string mcode (* ( *)*parameter_list*string mcode(* ) *)
   | ParenType       of string mcode (* ( *) * typeC * string mcode (* ) *)
   | FunctionType    of typeC *
                   string mcode (* ( *) * parameter_list * string mcode (* ) *)
@@ -737,7 +734,6 @@ let rec meta_names_of_typeC ty =
     ConstVol (_, ty)
   | Signed (_, Some ty)
   | Pointer (ty, _)
-  | FunctionPointer (ty, _, _, _, _, _, _)
   | Array (ty, _, _, _) -> meta_names_of_typeC ty
   | EnumName (_, Some ident)
   | StructUnionName(_, Some ident) -> meta_names_of_ident ident
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 33bd12b2..c1bc561b 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -191,9 +191,6 @@ and base_typeC =
   | BaseType        of Ast_cocci.baseType * string mcode list
   | Signed          of Ast_cocci.sign mcode * typeC option
   | Pointer         of typeC * string mcode (* * *)
-  | FunctionPointer of typeC *
-	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
-                  string mcode (* ( *)*parameter_list*string mcode(* ) *)
   | ParenType       of string mcode (* ( *) * typeC * string mcode (* ) *)
   | FunctionType    of typeC *
                   string mcode (* ( *) * parameter_list * string mcode (* ) *)
diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index dc7b30f7..375b2292 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -561,7 +561,6 @@ and typeC allminus t =
 	  [ty] -> ty
 	| types -> Ast.DisjType(List.map (rewrap t no_isos) types))
     | Ast0.BaseType(_) | Ast0.Signed(_,_) | Ast0.Pointer(_,_)
-    | Ast0.FunctionPointer(_,_,_,_,_,_,_)
     | Ast0.ParenType(_,_,_) | Ast0.FunctionType(_,_,_,_)
     | Ast0.Array(_,_,_,_) | Ast0.Decimal(_,_,_,_,_,_)
     | Ast0.EnumName(_,_) | Ast0.StructUnionName(_,_)
@@ -585,10 +584,6 @@ and base_typeC allminus t =
 	(mcode sgn,
 	 get_option (function x -> rewrap_iso x (base_typeC allminus x)) ty)
   | Ast0.Pointer(ty,star) -> Ast.Pointer(typeC allminus ty,mcode star)
-  | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      Ast.FunctionPointer
-	(typeC allminus ty,mcode lp1,mcode star,mcode rp1,
-	 mcode lp2,parameter_list params,mcode rp2)
   | Ast0.ParenType(lp,ty,rp) ->
       Ast.ParenType(mcode lp,typeC allminus ty,mcode rp)
   | Ast0.FunctionType(ty,lp,params,rp) ->
diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index 4fea9794..b1639ba6 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -340,9 +340,6 @@ and base_typeC =
     BaseType        of baseType * string mcode list (* Yoann style *)
   | SignedT         of sign mcode * typeC option
   | Pointer         of fullType * string mcode (* * *)
-  | FunctionPointer of fullType *
-	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
-                  string mcode (* ( *)*parameter_list*string mcode(* ) *)
   | ParenType       of string mcode (* ( *) * fullType * string mcode (* ) *)
   | FunctionType    of fullType *
                   string mcode (* ( *) * parameter_list * string mcode (* ) *)
@@ -1108,8 +1105,6 @@ let rec string_of_typeC ty =
       ssign ^ " " ^ Common.default "" string_of_typeC ty'
   | Pointer (ty', _) ->
       string_of_fullType ty' ^ "*"
-  | FunctionPointer (ty', _, _, _, _, _, _) ->
-      string_of_fullType ty' ^ "(*)()"
   | ParenType (_ , ty', _) ->
       "(" ^ string_of_fullType ty' ^ ")"
   | FunctionType (ty' , _, _, _) ->
@@ -1193,8 +1188,6 @@ and typeC_map tr ty =
         | Some f -> rewrap ty (f ty' s)
       end
   | Pointer (ty', s) -> rewrap ty (Pointer (fullType_map tr ty', s))
-  | FunctionPointer (ty, s0, s1, s2, s3, s4, s5) ->
-      rewrap ty (FunctionPointer (fullType_map tr ty, s0, s1, s2, s3, s4, s5))
   | ParenType (s0, ty', s1) ->
       rewrap ty (ParenType (s0, fullType_map tr ty', s1))
   | FunctionType (ty', s0, s1, s2) ->
@@ -1257,7 +1250,6 @@ and typeC_fold tr ty v =
   | SignedT (_, None) -> v
   | SignedT (_, Some ty') -> typeC_fold tr ty' v
   | Pointer (ty', _)
-  | FunctionPointer (ty', _, _, _, _, _, _)
   | ParenType (_, ty', _)
   | FunctionType (ty', _, _, _)
   | Array (ty', _, _, _)
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index 7fb54e4d..6bc1d652 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -322,9 +322,6 @@ and base_typeC =
     BaseType        of baseType * string mcode list (* Yoann style *)
   | SignedT         of sign mcode * typeC option
   | Pointer         of fullType * string mcode (* * *)
-  | FunctionPointer of fullType *
-	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
-                  string mcode (* ( *)*parameter_list*string mcode(* ) *)
   | ParenType       of string mcode (* ( *) * fullType * string mcode (* ) *)
   | FunctionType    of fullType *
                   string mcode (* ( *) * parameter_list * string mcode (* ) *)
diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml
index 7b10bd53..fc6766ae 100644
--- a/parsing_cocci/check_meta.ml
+++ b/parsing_cocci/check_meta.ml
@@ -221,9 +221,6 @@ and typeC old_metas table minus t =
   | Ast0.Signed(sgn,ty) ->
       get_opt (typeC old_metas table minus) ty
   | Ast0.Pointer(ty,star) -> typeC old_metas table minus ty
-  | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      typeC old_metas table minus ty;
-      parameter_list old_metas table minus params
   | Ast0.ParenType(lp,ty,rp) ->
       typeC old_metas table minus ty
   | Ast0.FunctionType(ty,lp,params,rp) ->
diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml
index 8231a0e7..fb093299 100644
--- a/parsing_cocci/compute_lines.ml
+++ b/parsing_cocci/compute_lines.ml
@@ -564,16 +564,6 @@ and typeC t =
       let ty = typeC ty in
       let star = normal_mcode star in
       mkres t (Ast0.Pointer(ty,star)) ty (promote_mcode star)
-  | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      let ty = typeC ty in
-      let lp1 = normal_mcode lp1 in
-      let star = normal_mcode star in
-      let rp1 = normal_mcode rp1 in
-      let lp2 = normal_mcode lp2 in
-      let params = parameter_list (Some(promote_mcode lp2)) params in
-      let rp2 = normal_mcode rp2 in
-      mkres t (Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))
-	ty (promote_mcode rp2)
   | Ast0.ParenType(lp,ty,rp) ->
       let lp = normal_mcode lp in
       let rp = normal_mcode rp in
diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml
index 91d7f1b8..ff49057c 100644
--- a/parsing_cocci/disjdistr.ml
+++ b/parsing_cocci/disjdistr.ml
@@ -67,12 +67,6 @@ and disjtypeC bty =
   | Ast.Pointer(ty,star) ->
       let ty = disjty ty in
       List.map (function ty -> Ast.rewrap bty (Ast.Pointer(ty,star))) ty
-  | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      let ty = disjty ty in
-      List.map
-	(function ty ->
-	  Ast.rewrap bty (Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2)))
-	ty
   | Ast.ParenType(lp,ty,rp) ->
       let ty = disjty ty in
       List.map
diff --git a/parsing_cocci/function_prototypes.ml b/parsing_cocci/function_prototypes.ml
index fd36f31b..b31178d2 100644
--- a/parsing_cocci/function_prototypes.ml
+++ b/parsing_cocci/function_prototypes.ml
@@ -226,9 +226,6 @@ let rec attach_right strings ty =
     | Ast0.Signed(sgn,Some ty) ->
 	Ast0.Signed(sgn,Some (attach_right strings ty))
     | Ast0.Pointer(ty,star) -> Ast0.Pointer(ty,right_attach_mcode strings star)
-    | Ast0.FunctionPointer(ty,lp,star,rp,lp1,ps,rp1) ->
-	Ast0.FunctionPointer(ty,lp,star,rp,lp1,ps,
-			     right_attach_mcode strings rp1)
     | Ast0.ParenType(lp,ty,rp) ->
 	Ast0.ParenType(lp,ty,right_attach_mcode strings rp)
     | Ast0.FunctionType(ty,lp,ps,rp) ->
diff --git a/parsing_cocci/get_constants.ml b/parsing_cocci/get_constants.ml
index 65c72641..a23f2e4f 100644
--- a/parsing_cocci/get_constants.ml
+++ b/parsing_cocci/get_constants.ml
@@ -181,7 +181,7 @@ let check_inherited nm =
     | _ -> k i in
 
   let rec type_collect res = function
-      TC.ConstVol(_,ty) | TC.Pointer(ty) | TC.FunctionPointer(ty)
+      TC.ConstVol(_,ty) | TC.Pointer(ty)
     | TC.Array(ty) -> type_collect res ty
     | TC.MetaType(tyname,_,_) ->
 	inherited tyname
diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
index 5c91f620..9143203b 100644
--- a/parsing_cocci/index.ml
+++ b/parsing_cocci/index.ml
@@ -92,7 +92,6 @@ let typeC t =
   | Ast0.BaseType(ty,strings) -> [48]
   | Ast0.Signed(sign,ty) -> [129]
   | Ast0.Pointer(ty,star) -> [49]
-  | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> [131]
   | Ast0.ParenType(lp,ty,rp) -> [138]
   | Ast0.FunctionType(ty,lp,params,rp) -> [139]
   | Ast0.Array(ty,lb,size,rb) -> [50]
diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 6d51b072..71640044 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -863,14 +863,6 @@ let match_maker checks_needed context_required whencode_allowed =
 	      else return false
 	  | (Ast0.Pointer(tya,star1),Ast0.Pointer(tyb,star)) ->
 	      conjunct_bindings (check_mcode star1 star) (match_typeC tya tyb)
-	  | (Ast0.FunctionPointer(tya,lp1a,stara,rp1a,lp2a,paramsa,rp2a),
-	     Ast0.FunctionPointer(tyb,lp1b,starb,rp1b,lp2b,paramsb,rp2b)) ->
-	       conjunct_many_bindings
-		 [check_mcode stara starb; check_mcode lp1a lp1b;
-		   check_mcode rp1a rp1b; check_mcode lp2a lp2b;
-		   check_mcode rp2a rp2b; match_typeC tya tyb;
-		   match_dots match_param is_plist_matcher
-		     do_plist_match paramsa paramsb]
 	  | (Ast0.Array(tya,lb1,sizea,rb1),Ast0.Array(tyb,lb,sizeb,rb)) ->
 	      conjunct_many_bindings
 		[check_mcode lb1 lb; check_mcode rb1 rb;
@@ -1814,10 +1806,6 @@ let instantiate bindings mv_bindings model =
                           Ast0.rewrap ty (Ast0.ConstVol(cv,renamer ty'))
                       | Ast0.Pointer(ty', s) ->
                           Ast0.rewrap ty (Ast0.Pointer(renamer ty', s))
-                      | Ast0.FunctionPointer(ty', s0, s1, s2, s3, p, s4) ->
-                          Ast0.rewrap ty (
-                            Ast0.FunctionPointer(
-                              renamer ty', s0, s1, s2, s3, p, s4))
                       | Ast0.ParenType(s0, ty', s1) ->
                           Ast0.rewrap ty (Ast0.ParenType(s0, renamer ty', s1))
                       | Ast0.FunctionType(ty', s0, s1, s2) ->
diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml
index ef60106c..213994fc 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -397,12 +397,6 @@ and fullType ft =
   | Ast.ConjType(decls) -> print_disj_list fullType decls "&"
   | Ast.OptType(ty) -> print_string "?"; fullType ty
 
-and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn =
-  fullType ty; print_string " ";
-  mcode print_string lp1; mcode print_string star; fn();
-  mcode print_string rp1; mcode print_string lp1;
-  parameter_list params; mcode print_string rp2
-
 and print_parentype (lp,ty,rp) fn =
   match Ast.unwrap ty with
    Ast.Type(_,_,fty1) ->
@@ -469,9 +463,6 @@ and typeC ty =
       List.iter (function s -> mcode print_string s; print_string " ") strings
   | Ast.SignedT(sgn,ty) -> mcode sign sgn; print_option typeC ty
   | Ast.Pointer(ty,star) -> fullType ty; mcode print_string star
-  | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
-	(function _ -> ())
   | Ast.ParenType(lp,ty,rp) ->
       print_parentype (lp,ty,rp) (function _ -> ())
   | Ast.FunctionType(ty,lp,params,rp) ->
@@ -532,10 +523,7 @@ and print_named_type ty id =
   match Ast.unwrap ty with
     Ast.Type(_,None,ty1) ->
       (match Ast.unwrap ty1 with
-	Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-	  print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
-	    (function _ -> id())
-      | Ast.Array(ty,lb,size,rb) ->
+        Ast.Array(ty,lb,size,rb) ->
 	  let rec loop ty k =
 	    match Ast.unwrap ty with
 	      Ast.Array(ty,lb,size,rb) ->
diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml
index 48d77b5a..c1266980 100644
--- a/parsing_cocci/single_statement.ml
+++ b/parsing_cocci/single_statement.ml
@@ -165,7 +165,6 @@ and left_typeC t =
   | Ast0.BaseType(ty,strings) -> modif_before_mcode (List.hd strings)
   | Ast0.Signed(sgn,ty) -> modif_before_mcode sgn
   | Ast0.Pointer(ty,star) -> left_typeC ty
-  | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> left_typeC ty
   | Ast0.ParenType(lp,ty,rp) -> left_typeC ty
   | Ast0.FunctionType(ty,lp,params,rp) -> left_typeC ty
   | Ast0.Array(ty,lb,size,rb) -> left_typeC ty
diff --git a/parsing_cocci/type_cocci.mli b/parsing_cocci/type_cocci.mli
index 6f24adf7..5b0734d2 100644
--- a/parsing_cocci/type_cocci.mli
+++ b/parsing_cocci/type_cocci.mli
@@ -15,7 +15,6 @@ type typeC =
   | BaseType        of baseType
   | SignedT         of sign * typeC option
   | Pointer         of typeC
-  | FunctionPointer of typeC (* only return type *)
   | ParenType       of typeC (* only return type *)
   | FunctionType    of typeC (* only return type *)
   | Array           of typeC (* drop size info *)
diff --git a/parsing_cocci/type_infer.ml b/parsing_cocci/type_infer.ml
index b4c0b55e..345bc129 100644
--- a/parsing_cocci/type_infer.ml
+++ b/parsing_cocci/type_infer.ml
@@ -161,18 +161,19 @@ let rec propagate_types env =
               Ast0.rewrap e (
                 Ast0.Array(Ast0.rewrap e char_type, dummy, None, dummy)))
 	| Ast0.FunCall(fn,lp,args,rp) ->
-	    (match Common.map_option Ast0.unwrap (Ast0.get_type fn) with
-		 Some (Ast0.FunctionPointer(ty, _, _, _, _, _, _)) -> Some ty
-	       |  _ ->
-		    (match Ast0.unwrap fn with
-			 Ast0.Ident(id) ->
-			   (match Ast0.unwrap id with
-				Ast0.Id(id) ->
-				  if List.mem (Ast0.unwrap_mcode id) bool_functions
-				  then Some(Ast0.rewrap e bool_type)
-				  else None
-			      | _ -> None)
-		       |	_ -> None))
+            let fna = Common.map_option Ast0.unwrap (Ast0.get_type fn) in
+            (match fna with
+                 Some _ ->
+                 (match Ast0.unwrap fn with
+                    Ast0.Ident(id) ->
+                      (match Ast0.unwrap id with
+                         Ast0.Id(id) ->
+                           if List.mem (Ast0.unwrap_mcode id) bool_functions
+                           then Some(Ast0.rewrap e bool_type)
+                           else None
+                       | _ -> None)
+                  | _ -> None)
+            | _ -> None)
 	| Ast0.Assignment(exp1,op,exp2,_) ->
 	    let ty = lub_type (Ast0.get_type exp1) (Ast0.get_type exp2) in
 	      Ast0.set_type exp1 ty; Ast0.set_type exp2 ty; ty
diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml
index de86b1d3..47a4dfe6 100644
--- a/parsing_cocci/unify_ast.ml
+++ b/parsing_cocci/unify_ast.ml
@@ -328,14 +328,6 @@ and unify_typeC t1 t2 =
       then unify_option unify_typeC ty1 ty2
       else false
   | (Ast.Pointer(ty1,s1),Ast.Pointer(ty2,s2)) -> unify_fullType ty1 ty2
-  | (Ast.FunctionPointer(tya,lp1a,stara,rp1a,lp2a,paramsa,rp2a),
-     Ast.FunctionPointer(tyb,lp1b,starb,rp1b,lp2b,paramsb,rp2b)) ->
-       if List.for_all2 unify_mcode
-	   [lp1a;stara;rp1a;lp2a;rp2a] [lp1b;starb;rp1b;lp2b;rp2b]
-       then
-	 unify_fullType tya tyb &&
-	 unify_dots unify_parameterTypeDef pdots paramsa paramsb
-       else false
   | (Ast.ParenType(lpa,tya,rpa),Ast.ParenType(lpb,tyb,rpb)) ->
       unify_fullType tya tyb && unify_mcode lpa lpb && unify_mcode rpa rpb
   | (Ast.FunctionType(tya,lpa,paramsa,rpa),
diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index f8684dd2..7e108232 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -287,11 +287,6 @@ and string_format e =
 (* --------------------------------------------------------------------- *)
 (* Types *)
 
-and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn =
-  typeC ty; mcode print_string lp1; mcode print_string star; fn();
-  mcode print_string rp1; mcode print_string lp2;
-  parameter_list params; mcode print_string rp2
-
 and print_parentype (lp,ty,rp) fn =
  match Ast0.unwrap ty with
    Ast0.Pointer(ty1,star) ->
@@ -337,9 +332,6 @@ and typeC t =
 	    strings
       |	Ast0.Signed(sgn,ty) -> mcode U.sign sgn; print_option typeC ty
       | Ast0.Pointer(ty,star) -> typeC ty; mcode print_string star
-      | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-	  print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
-	    (function _ -> ())
       | Ast0.ParenType(lp,ty,rp) ->
           print_parentype (lp,ty,rp) (function _ -> ())
       | Ast0.FunctionType(ty,lp,params,rp) ->
@@ -393,10 +385,7 @@ and typeC t =
 
 and print_named_type ty id =
   match Ast0.unwrap ty with
-    Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-      print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
-	(function _ -> print_string " "; ident id)
-  | Ast0.Array(ty,lb,size,rb) ->
+    Ast0.Array(ty,lb,size,rb) ->
       let rec loop ty k =
 	match Ast0.unwrap ty with
 	  Ast0.Array(ty,lb,size,rb) ->
diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 99af7652..a6bd59a3 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -297,19 +297,6 @@ let combiner bind option_default
       | Ast.OptType(ty) -> fullType ty in
     ftfn all_functions k ft
 
-  and function_pointer
-	(ty, lp1, star, (id : Ast.ident option), rp1, lp2, params, rp2) =
-    (* have to put the treatment of the identifier into the right position *)
-    let lty = fullType ty in
-    let llp1 = string_mcode lp1 in
-    let lstar = string_mcode star in
-    let lid = match id with Some idd -> [ident idd] | None -> [] in
-    let lrp1 = string_mcode rp1 in
-    let llp2 = string_mcode lp2 in
-    let lparams = parameter_dots params in
-    let lrp2 = string_mcode rp2 in
-    multibind ([lty; llp1; lstar] @ lid @ [lrp1; llp2; lparams; lrp2])
-
   and array_type (ty,(id : Ast.ident option),lb,size,rb) =
     let lty = fullType ty in
     let lid = match id with Some idd -> [ident idd] | None -> [] in
@@ -385,8 +372,6 @@ let combiner bind option_default
 	  let lty = fullType ty in
 	  let lstar = string_mcode star in
 	  bind lty lstar
-      | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-	  function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2)
       | Ast.ParenType(lp,ty,rp) ->
           parentype_type (lp,ty,None,rp)
       | Ast.FunctionType(ty,lp,params,rp) ->
@@ -444,8 +429,6 @@ let combiner bind option_default
     match Ast.unwrap ty with
       Ast.Type(_,None,ty1) ->
 	(match Ast.unwrap ty1 with
-	  Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-	    function_pointer (ty, lp1, star, Some id, rp1, lp2, params, rp2)
 	| Ast.Array(ty,lb,size,rb) -> array_type (ty, Some id, lb, size, rb)
         | Ast.ParenType(lp,ty,rp) -> parentype_type (lp, ty, Some id, rp)
 	| _ -> let lty = fullType ty in
@@ -1308,15 +1291,6 @@ let rebuilder
 	    let lty = fullType ty in
 	    let lstar = string_mcode star in
 	    Ast.Pointer (lty, lstar)
-	| Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-	    let lty = fullType ty in
-	    let llp1 = string_mcode lp1 in
-	    let lstar = string_mcode star in
-	    let lrp1 = string_mcode rp1 in
-	    let llp2 = string_mcode lp2 in
-	    let lparams = parameter_dots params in
-	    let lrp2 = string_mcode rp2 in
-	    Ast.FunctionPointer(lty, llp1, lstar, lrp1, llp2, lparams, lrp2)
         | Ast.ParenType(lp,ty,rp) ->
             let llp = string_mcode lp in
             let lty = fullType ty in
diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index c56cd7a7..4b0dcdd4 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -336,9 +336,6 @@ let visitor mode bind option_default
 	    let (ty_n,ty) = typeC ty in
 	    let (star_n,star) = string_mcode star in
 	    (bind ty_n star_n, Ast0.Pointer(ty,star))
-	| Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
-	    let (t,id) =
-              function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2) in t
         | Ast0.ParenType(lp,ty,rp) ->
 	    let (t,id) =
               parentype_type (lp,ty,None,rp) in t
@@ -412,23 +409,6 @@ let visitor mode bind option_default
 	    (bind ty_n asty_n, Ast0.AsType(ty,asty))) in
     tyfn all_functions k t
 
-  (* returns ((bind value,original value),id) since id may have been updated*)
-  and function_pointer
-      (ty,lp1,star,(id : Ast0.ident option),rp1,lp2,params,rp2) =
-    let (ty_n,ty) = typeC ty in
-    let (lp1_n,lp1) = string_mcode lp1 in
-    let (star_n,star) = string_mcode star in
-    let (idl,idu) = (match id with
-      | Some a -> let (b,c) = ident a in ([b],Some c)
-      | None -> ([],None)) in
-    let (rp1_n,rp1) = string_mcode rp1 in
-    let (lp2_n,lp2) = string_mcode lp2 in
-    let (params_n,params) = parameter_dots params in
-    let (rp2_n,rp2) = string_mcode rp2 in
-    (* have to put the treatment of the identifier into the right position *)
-    ((multibind ([ty_n;lp1_n;star_n] @ idl @ [rp1_n;lp2_n;params_n;rp2_n]),
-     Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2)), idu)
-
   (* returns ((bind value,original value),id) since id may have been updated*)
   and array_type (ty,(id : Ast0.ident option),lb,size,rb) =
     let (ty_n,ty) = typeC ty in
@@ -513,12 +493,7 @@ let visitor mode bind option_default
 
   and named_type ty id =
     match Ast0.unwrap ty with
-      Ast0.FunctionPointer(rty,lp1,star,rp1,lp2,params,rp2) ->
-	let (tyres, idn) =
-          function_pointer (rty,lp1,star,Some id,rp1,lp2,params,rp2) in
-        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
-	(rewrap ty tyres, idn)
-    | Ast0.Array(rty,lb,size,rb) ->
+      Ast0.Array(rty,lb,size,rb) ->
 	let (tyres, idn) = array_type (rty,Some id,lb,size,rb) in
         let idn = match idn with Some i -> i | None -> failwith "Impossible" in
 	(rewrap ty tyres, idn)
@@ -534,23 +509,6 @@ let visitor mode bind option_default
            let (id_n,id) = ident id in
              ((bind ty_n id_n, ty), id)
 
-  (* returns ((bind value,original value),id) since id may have been updated*)
-  (* the next three functions are needed due to a lack of polymorphism :( *)
-  and function_pointer_typedef (ty,lp1,star,id,rp1,lp2,params,rp2) =
-    let (ty_n,ty) = typeC ty in
-    let (lp1_n,lp1) = string_mcode lp1 in
-    let (star_n,star) = string_mcode star in
-    let (idl,idu) = (match id with
-      | Some a -> let (b,c) = typeC a in ([b],Some c)
-      | None -> ([],None)) in
-    let (rp1_n,rp1) = string_mcode rp1 in
-    let (lp2_n,lp2) = string_mcode lp2 in
-    let (params_n,params) = parameter_dots params in
-    let (rp2_n,rp2) = string_mcode rp2 in
-    (* have to put the treatment of the identifier into the right position *)
-    ((multibind ([ty_n;lp1_n;star_n] @ idl @ [rp1_n;lp2_n;params_n;rp2_n]),
-     Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2)), idu)
-
   (* returns ((bind value,original value),id) since id may have been updated*)
   and array_type_typedef (ty,id,lb,size,rb) =
     let (ty_n,ty) = typeC ty in
@@ -636,12 +594,7 @@ let visitor mode bind option_default
 
   and named_type_typedef ty id =
     match Ast0.unwrap ty with
-      Ast0.FunctionPointer(rty,lp1,star,rp1,lp2,params,rp2) ->
-	let (tyres, idn) =
-          function_pointer_typedef (rty,lp1,star,Some id,rp1,lp2,params,rp2) in
-        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
-	(rewrap ty tyres, idn)
-    | Ast0.Array(rty,lb,size,rb) ->
+      Ast0.Array(rty,lb,size,rb) ->
 	let (tyres, idn) = array_type_typedef (rty,Some id,lb,size,rb) in
         let idn = match idn with Some i -> i | None -> failwith "Impossible" in
 	(rewrap ty tyres, idn)
diff --git a/tools/spgen/source/meta_variable.ml b/tools/spgen/source/meta_variable.ml
index 7adfacad..6a3c2089 100644
--- a/tools/spgen/source/meta_variable.ml
+++ b/tools/spgen/source/meta_variable.ml
@@ -273,7 +273,6 @@ let types ~rn = function
         | Ast.StructUnionName(_, Some n) -> get_meta_id acc n
         | Ast.SignedT (_, Some t) -> get_meta_type acc t
         | Ast.Pointer (t, _)
-        | Ast.FunctionPointer (t, _, _, _, _, _, _)
         | Ast.Array (t, _, _, _) -> get_meta_type_full acc t
 	| Ast.TypeOfExpr(_,_,exp,_) -> acc (* not sure *)
 	| Ast.TypeOfType(_,_,ty,_) -> get_meta_type_full acc ty
diff --git a/tools/spgen/source/position_generator.ml b/tools/spgen/source/position_generator.ml
index 2fa630fb..602e768e 100644
--- a/tools/spgen/source/position_generator.ml
+++ b/tools/spgen/source/position_generator.ml
@@ -192,9 +192,6 @@ let rec type_pos t snp
   | Ast0.Pointer(t,star) ->
       let constructor ~mc = Ast0.Pointer(t,mc) in
       mcode_wrap ~mc:star ~constructor snp
-  | Ast0.FunctionPointer(t,lp,star,rp,lp2,params,rp2) ->
-      let constructor ~mc = Ast0.FunctionPointer(t,lp,star,rp,lp2,params,mc) in
-      mcode_wrap ~mc:rp2 ~constructor snp
   | Ast0.ParenType(lp,t,rp) ->
       let constructor ~mc = Ast0.ParenType(lp,t,rp) in
       mcode_wrap ~mc:rp ~constructor snp
-- 
2.21.1

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

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

* [Cocci] [PATCH 26/26] tests: Add test case for array of function pointers
  2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (24 preceding siblings ...)
  2020-03-16 10:03 ` [Cocci] [PATCH 25/26] cocci: Remove Ast_cocci.FunctionPointer Jaskaran Singh
@ 2020-03-16 10:03 ` Jaskaran Singh
  2020-03-18 18:48   ` Julia Lawall
  25 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-16 10:03 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

Add a test case to match against an array of function pointers.
This would previously not work due to differences in the C
and SmPL ASTs.

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

diff --git a/tests/funptr_array.c b/tests/funptr_array.c
new file mode 100644
index 00000000..dac29ac6
--- /dev/null
+++ b/tests/funptr_array.c
@@ -0,0 +1 @@
+int (*x[2])(int x);
diff --git a/tests/funptr_array.cocci b/tests/funptr_array.cocci
new file mode 100644
index 00000000..8027bcf4
--- /dev/null
+++ b/tests/funptr_array.cocci
@@ -0,0 +1,9 @@
+@@
+type T;
+identifier x;
+@@
+
+T (*x[2])(
+- int
++ char
+  x);
diff --git a/tests/funptr_array.res b/tests/funptr_array.res
new file mode 100644
index 00000000..72e1a14a
--- /dev/null
+++ b/tests/funptr_array.res
@@ -0,0 +1 @@
+int (*x[2])(char x);
-- 
2.21.1

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

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

* [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast: Add cases for ParenType/FunctionType
  2020-03-16 10:02 ` [Cocci] [PATCH 05/26] " Jaskaran Singh
@ 2020-03-17  5:59   ` " Jaskaran Singh
  2020-03-17  7:16     ` Julia Lawall
  2020-03-17  8:43   ` [Cocci] [PATCH v2 " Jaskaran Singh
  1 sibling, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-17  5:59 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The order of the terms in ParenType require implementing a special
case for ParenType. This case handles only the following:

	<type> ( * id [ .* ] ) ( params )

i.e., a function pointer or an array of function pointers, and will fail
for any other cases. This is similar to the function used to print
ParenType in Pretty_print_c.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_cocci/visitor_ast.ml | 75 ++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 3d5de794..99af7652 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -318,6 +318,61 @@ let combiner bind option_default
     let lrb = string_mcode rb in
     multibind ([lty] @ lid @ [lb; lsize; lrb])
 
+  and parentype_type (lp, ty, (id : Ast.ident option), rp) =
+    match Ast.unwrap ty with
+     Ast.Type(_,_,fty1) ->
+      (match Ast.unwrap fty1 with
+         Ast.Pointer(ty1,star) ->
+          (match Ast.unwrap ty1 with
+             Ast.Type(_,_,fty2) ->
+              (match Ast.unwrap fty2 with
+                Ast.FunctionType(ty2,lp2,params,rp2) ->
+                  let typ = fullType ty2 in
+                  let lp = string_mcode lp in
+                  let star = string_mcode star in
+                  let idl = match id with
+                    | Some idd -> [ident idd]
+                    | None -> [] in
+                  let rp = string_mcode rp in
+                  let lp2 = string_mcode lp2 in
+                  let params = parameter_dots params in
+                  let rp2 = string_mcode rp2 in
+                  multibind
+                    ([typ;lp;star] @ idl @ [rp;lp2;params;rp2])
+                | _ -> failwith "ParenType Visitor_ast")
+           | _ -> failwith "ParenType Visitor_ast")
+       | Ast.Array(ty1,lb1,size1,rb1) ->
+          (match Ast.unwrap ty1 with
+            Ast.Type(_,_,fty2) ->
+             (match Ast.unwrap fty2 with
+               Ast.Pointer(ty2,star) ->
+                (match Ast.unwrap ty2 with
+                  Ast.Type(_,_,fty3) ->
+                   (match Ast.unwrap fty3 with
+                     Ast.FunctionType(ty3,lp3,params,rp3) ->
+                     let typ = fullType ty3 in
+                     let lp = string_mcode lp in
+                     let star = string_mcode star in
+                     let idl = match id with
+                       | Some idd -> [ident idd]
+                       | None -> [] in
+                     let lb1 = string_mcode lb1 in
+                     let size1 = get_option expression size1 in
+                     let rb1 = string_mcode rb1 in
+                     let rp = string_mcode rp in
+                     let lp3 = string_mcode lp3 in
+                     let params = parameter_dots params in
+                     let rp3 = string_mcode rp3 in
+                     multibind
+                       ([typ;lp;star] @ idl @
+                        [lb1;size1;rb1;rp;lp3;params;rp3])
+   	           | _ -> failwith "ParenType Visitor_ast")
+                | _ -> failwith "ParenType Visitor_ast")
+             | _ -> failwith "ParenType Visitor_ast")
+          | _ -> failwith "ParenType Visitor_ast")
+       | _ -> failwith "ParenType Visitor_ast")
+    | _ -> failwith "ParenType Visitor_ast"
+
   and typeC ty =
     let k ty =
       match Ast.unwrap ty with
@@ -332,6 +387,14 @@ let combiner bind option_default
 	  bind lty lstar
       | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
 	  function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2)
+      | Ast.ParenType(lp,ty,rp) ->
+          parentype_type (lp,ty,None,rp)
+      | Ast.FunctionType(ty,lp,params,rp) ->
+          let lty = fullType ty in
+          let llp = string_mcode lp in
+          let lparams = parameter_dots params in
+          let lrp = string_mcode rp in
+          multibind [lty; llp; lparams; lrp]
       | Ast.Array(ty,lb,size,rb) -> array_type (ty,None,lb,size,rb)
       | Ast.Decimal(dec,lp,length,comma,precision_opt,rp) ->
 	  let ldec = string_mcode dec in
@@ -384,6 +447,7 @@ let combiner bind option_default
 	  Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
 	    function_pointer (ty, lp1, star, Some id, rp1, lp2, params, rp2)
 	| Ast.Array(ty,lb,size,rb) -> array_type (ty, Some id, lb, size, rb)
+        | Ast.ParenType(lp,ty,rp) -> parentype_type (lp, ty, Some id, rp)
 	| _ -> let lty = fullType ty in
 	       let lid = ident id in
 	       bind lty lid)
@@ -1253,6 +1317,17 @@ let rebuilder
 	    let lparams = parameter_dots params in
 	    let lrp2 = string_mcode rp2 in
 	    Ast.FunctionPointer(lty, llp1, lstar, lrp1, llp2, lparams, lrp2)
+        | Ast.ParenType(lp,ty,rp) ->
+            let llp = string_mcode lp in
+            let lty = fullType ty in
+            let lrp = string_mcode rp in
+            Ast.ParenType(llp,lty,lrp)
+        | Ast.FunctionType(ty,lp,params,rp) ->
+            let lty = fullType ty in
+            let llp = string_mcode lp in
+            let lparams = parameter_dots params in
+            let lrp = string_mcode rp in
+            Ast.FunctionType(lty,llp,lparams,lrp)
 	| Ast.Array(ty,lb,size,rb) ->
 	    let lty = fullType ty in
 	    let llb = string_mcode lb in
-- 
2.21.1

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

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

* Re: [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast: Add cases for ParenType/FunctionType
  2020-03-17  5:59   ` [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast: " Jaskaran Singh
@ 2020-03-17  7:16     ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-17  7:16 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Tue, 17 Mar 2020, Jaskaran Singh wrote:

> The order of the terms in ParenType require implementing a special
> case for ParenType. This case handles only the following:
>
> 	<type> ( * id [ .* ] ) ( params )
>
> i.e., a function pointer or an array of function pointers, and will fail
> for any other cases. This is similar to the function used to print
> ParenType in Pretty_print_c.

Did you change this?  It should be v2, and then the reason for the change
should be described under the ---

julia

>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/visitor_ast.ml | 75 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 75 insertions(+)
>
> diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
> index 3d5de794..99af7652 100644
> --- a/parsing_cocci/visitor_ast.ml
> +++ b/parsing_cocci/visitor_ast.ml
> @@ -318,6 +318,61 @@ let combiner bind option_default
>      let lrb = string_mcode rb in
>      multibind ([lty] @ lid @ [lb; lsize; lrb])
>
> +  and parentype_type (lp, ty, (id : Ast.ident option), rp) =
> +    match Ast.unwrap ty with
> +     Ast.Type(_,_,fty1) ->
> +      (match Ast.unwrap fty1 with
> +         Ast.Pointer(ty1,star) ->
> +          (match Ast.unwrap ty1 with
> +             Ast.Type(_,_,fty2) ->
> +              (match Ast.unwrap fty2 with
> +                Ast.FunctionType(ty2,lp2,params,rp2) ->
> +                  let typ = fullType ty2 in
> +                  let lp = string_mcode lp in
> +                  let star = string_mcode star in
> +                  let idl = match id with
> +                    | Some idd -> [ident idd]
> +                    | None -> [] in
> +                  let rp = string_mcode rp in
> +                  let lp2 = string_mcode lp2 in
> +                  let params = parameter_dots params in
> +                  let rp2 = string_mcode rp2 in
> +                  multibind
> +                    ([typ;lp;star] @ idl @ [rp;lp2;params;rp2])
> +                | _ -> failwith "ParenType Visitor_ast")
> +           | _ -> failwith "ParenType Visitor_ast")
> +       | Ast.Array(ty1,lb1,size1,rb1) ->
> +          (match Ast.unwrap ty1 with
> +            Ast.Type(_,_,fty2) ->
> +             (match Ast.unwrap fty2 with
> +               Ast.Pointer(ty2,star) ->
> +                (match Ast.unwrap ty2 with
> +                  Ast.Type(_,_,fty3) ->
> +                   (match Ast.unwrap fty3 with
> +                     Ast.FunctionType(ty3,lp3,params,rp3) ->
> +                     let typ = fullType ty3 in
> +                     let lp = string_mcode lp in
> +                     let star = string_mcode star in
> +                     let idl = match id with
> +                       | Some idd -> [ident idd]
> +                       | None -> [] in
> +                     let lb1 = string_mcode lb1 in
> +                     let size1 = get_option expression size1 in
> +                     let rb1 = string_mcode rb1 in
> +                     let rp = string_mcode rp in
> +                     let lp3 = string_mcode lp3 in
> +                     let params = parameter_dots params in
> +                     let rp3 = string_mcode rp3 in
> +                     multibind
> +                       ([typ;lp;star] @ idl @
> +                        [lb1;size1;rb1;rp;lp3;params;rp3])
> +   	           | _ -> failwith "ParenType Visitor_ast")
> +                | _ -> failwith "ParenType Visitor_ast")
> +             | _ -> failwith "ParenType Visitor_ast")
> +          | _ -> failwith "ParenType Visitor_ast")
> +       | _ -> failwith "ParenType Visitor_ast")
> +    | _ -> failwith "ParenType Visitor_ast"
> +
>    and typeC ty =
>      let k ty =
>        match Ast.unwrap ty with
> @@ -332,6 +387,14 @@ let combiner bind option_default
>  	  bind lty lstar
>        | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>  	  function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2)
> +      | Ast.ParenType(lp,ty,rp) ->
> +          parentype_type (lp,ty,None,rp)
> +      | Ast.FunctionType(ty,lp,params,rp) ->
> +          let lty = fullType ty in
> +          let llp = string_mcode lp in
> +          let lparams = parameter_dots params in
> +          let lrp = string_mcode rp in
> +          multibind [lty; llp; lparams; lrp]
>        | Ast.Array(ty,lb,size,rb) -> array_type (ty,None,lb,size,rb)
>        | Ast.Decimal(dec,lp,length,comma,precision_opt,rp) ->
>  	  let ldec = string_mcode dec in
> @@ -384,6 +447,7 @@ let combiner bind option_default
>  	  Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>  	    function_pointer (ty, lp1, star, Some id, rp1, lp2, params, rp2)
>  	| Ast.Array(ty,lb,size,rb) -> array_type (ty, Some id, lb, size, rb)
> +        | Ast.ParenType(lp,ty,rp) -> parentype_type (lp, ty, Some id, rp)
>  	| _ -> let lty = fullType ty in
>  	       let lid = ident id in
>  	       bind lty lid)
> @@ -1253,6 +1317,17 @@ let rebuilder
>  	    let lparams = parameter_dots params in
>  	    let lrp2 = string_mcode rp2 in
>  	    Ast.FunctionPointer(lty, llp1, lstar, lrp1, llp2, lparams, lrp2)
> +        | Ast.ParenType(lp,ty,rp) ->
> +            let llp = string_mcode lp in
> +            let lty = fullType ty in
> +            let lrp = string_mcode rp in
> +            Ast.ParenType(llp,lty,lrp)
> +        | Ast.FunctionType(ty,lp,params,rp) ->
> +            let lty = fullType ty in
> +            let llp = string_mcode lp in
> +            let lparams = parameter_dots params in
> +            let lrp = string_mcode rp in
> +            Ast.FunctionType(lty,llp,lparams,lrp)
>  	| Ast.Array(ty,lb,size,rb) ->
>  	    let lty = fullType ty in
>  	    let llb = string_mcode lb in
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* [Cocci] [PATCH v2 05/26] parsing_cocci: visitor_ast: Add cases for ParenType/FunctionType
  2020-03-16 10:02 ` [Cocci] [PATCH 05/26] " Jaskaran Singh
  2020-03-17  5:59   ` [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast: " Jaskaran Singh
@ 2020-03-17  8:43   ` " Jaskaran Singh
  2020-03-18 17:45     ` Julia Lawall
  1 sibling, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-17  8:43 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

The order of the terms in ParenType require implementing a special
case for ParenType. This case handles only the following:

	<type> ( * id [ .* ] ) ( params )

i.e., a function pointer or an array of function pointers, and will fail
for any other cases. This is similar to the function used to print
ParenType in Pretty_print_c.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
Changes in v2:
-------------
- Change the "visitor_ast0" in patch subject to "visitor_ast"

 parsing_cocci/visitor_ast.ml | 75 ++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 3d5de794..99af7652 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -318,6 +318,61 @@ let combiner bind option_default
     let lrb = string_mcode rb in
     multibind ([lty] @ lid @ [lb; lsize; lrb])
 
+  and parentype_type (lp, ty, (id : Ast.ident option), rp) =
+    match Ast.unwrap ty with
+     Ast.Type(_,_,fty1) ->
+      (match Ast.unwrap fty1 with
+         Ast.Pointer(ty1,star) ->
+          (match Ast.unwrap ty1 with
+             Ast.Type(_,_,fty2) ->
+              (match Ast.unwrap fty2 with
+                Ast.FunctionType(ty2,lp2,params,rp2) ->
+                  let typ = fullType ty2 in
+                  let lp = string_mcode lp in
+                  let star = string_mcode star in
+                  let idl = match id with
+                    | Some idd -> [ident idd]
+                    | None -> [] in
+                  let rp = string_mcode rp in
+                  let lp2 = string_mcode lp2 in
+                  let params = parameter_dots params in
+                  let rp2 = string_mcode rp2 in
+                  multibind
+                    ([typ;lp;star] @ idl @ [rp;lp2;params;rp2])
+                | _ -> failwith "ParenType Visitor_ast")
+           | _ -> failwith "ParenType Visitor_ast")
+       | Ast.Array(ty1,lb1,size1,rb1) ->
+          (match Ast.unwrap ty1 with
+            Ast.Type(_,_,fty2) ->
+             (match Ast.unwrap fty2 with
+               Ast.Pointer(ty2,star) ->
+                (match Ast.unwrap ty2 with
+                  Ast.Type(_,_,fty3) ->
+                   (match Ast.unwrap fty3 with
+                     Ast.FunctionType(ty3,lp3,params,rp3) ->
+                     let typ = fullType ty3 in
+                     let lp = string_mcode lp in
+                     let star = string_mcode star in
+                     let idl = match id with
+                       | Some idd -> [ident idd]
+                       | None -> [] in
+                     let lb1 = string_mcode lb1 in
+                     let size1 = get_option expression size1 in
+                     let rb1 = string_mcode rb1 in
+                     let rp = string_mcode rp in
+                     let lp3 = string_mcode lp3 in
+                     let params = parameter_dots params in
+                     let rp3 = string_mcode rp3 in
+                     multibind
+                       ([typ;lp;star] @ idl @
+                        [lb1;size1;rb1;rp;lp3;params;rp3])
+   	           | _ -> failwith "ParenType Visitor_ast")
+                | _ -> failwith "ParenType Visitor_ast")
+             | _ -> failwith "ParenType Visitor_ast")
+          | _ -> failwith "ParenType Visitor_ast")
+       | _ -> failwith "ParenType Visitor_ast")
+    | _ -> failwith "ParenType Visitor_ast"
+
   and typeC ty =
     let k ty =
       match Ast.unwrap ty with
@@ -332,6 +387,14 @@ let combiner bind option_default
 	  bind lty lstar
       | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
 	  function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2)
+      | Ast.ParenType(lp,ty,rp) ->
+          parentype_type (lp,ty,None,rp)
+      | Ast.FunctionType(ty,lp,params,rp) ->
+          let lty = fullType ty in
+          let llp = string_mcode lp in
+          let lparams = parameter_dots params in
+          let lrp = string_mcode rp in
+          multibind [lty; llp; lparams; lrp]
       | Ast.Array(ty,lb,size,rb) -> array_type (ty,None,lb,size,rb)
       | Ast.Decimal(dec,lp,length,comma,precision_opt,rp) ->
 	  let ldec = string_mcode dec in
@@ -384,6 +447,7 @@ let combiner bind option_default
 	  Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
 	    function_pointer (ty, lp1, star, Some id, rp1, lp2, params, rp2)
 	| Ast.Array(ty,lb,size,rb) -> array_type (ty, Some id, lb, size, rb)
+        | Ast.ParenType(lp,ty,rp) -> parentype_type (lp, ty, Some id, rp)
 	| _ -> let lty = fullType ty in
 	       let lid = ident id in
 	       bind lty lid)
@@ -1253,6 +1317,17 @@ let rebuilder
 	    let lparams = parameter_dots params in
 	    let lrp2 = string_mcode rp2 in
 	    Ast.FunctionPointer(lty, llp1, lstar, lrp1, llp2, lparams, lrp2)
+        | Ast.ParenType(lp,ty,rp) ->
+            let llp = string_mcode lp in
+            let lty = fullType ty in
+            let lrp = string_mcode rp in
+            Ast.ParenType(llp,lty,lrp)
+        | Ast.FunctionType(ty,lp,params,rp) ->
+            let lty = fullType ty in
+            let llp = string_mcode lp in
+            let lparams = parameter_dots params in
+            let lrp = string_mcode rp in
+            Ast.FunctionType(lty,llp,lparams,lrp)
 	| Ast.Array(ty,lb,size,rb) ->
 	    let lty = fullType ty in
 	    let llb = string_mcode lb in
-- 
2.21.1

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

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

* Re: [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
  2020-03-16 10:02 ` [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token Jaskaran Singh
@ 2020-03-18 17:25   ` Julia Lawall
  2020-03-19 13:58     ` Jaskaran Singh
  0 siblings, 1 reply; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 17:25 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> To add the types ParenType and FunctionType to the SmPL AST, a
> reduce/reduce conflict with the funproto rule of the SmPL parser
> must be resolved. This requires explicitly identifying a function
> prototype by use of a token (TFunProto).
>
> While the correct method of identifying a function prototype would be to
> check if an identifier is preceded by a return type, it is challenging
> to implement. This is because implementing an OCaml function, to
> correctly determine a C type in SmPL, without the aid of Yacc, would
> have to handle a number of cases (disjunctions, typeof expressions,
> etc.).
>
> Thus, a slightly hacky approach is taken to determine a function
> prototype with not the best certainty but what works for most cases
> in SmPL. If the identifier is preceded by any token that does not
> seem to be part of a type, then it is not identified as a function
> prototype. Else, it is.

This sacrifices the test case tests/p1p2.cocci:

@@
typedef Error;
type T;
identifier FN;
parameter P1;
@@
 T
+__attribute__((nonnull(1)))
 FN(P1, Error **errp);

@@
typedef Error;
type T;
identifier FN;
parameter P1;
parameter P2;
@@
 T
+__attribute__((nonnull(2)))
 FN(P1, P2, Error **errp);

Normally, the only way that you can have a ) before a function call is
when there is a cast.  But hopefully in that case there would not be two
)) before the function call.  Can that get around the problem?

julia




>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/parse_cocci.ml          | 72 +++++++++++++++++++++++----
>  parsing_cocci/parser_cocci_menhir.mly |  9 ++--
>  2 files changed, 67 insertions(+), 14 deletions(-)
>
> diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml
> index 679d213a..4b2cb7e4 100644
> --- a/parsing_cocci/parse_cocci.ml
> +++ b/parsing_cocci/parse_cocci.ml
> @@ -295,6 +295,7 @@ let token2c (tok,_) add_clt =
>    | PC.TLineEnd(clt) -> "line end"
>    | PC.TInvalid -> "invalid"
>    | PC.TFunDecl(clt) -> "fundecl"
> +  | PC.TFunProto(clt) -> "funproto"
>
>    | PC.TIso -> "<=>"
>    | PC.TRightIso -> "=>"
> @@ -480,7 +481,7 @@ let get_clt (tok,_) =
>
>    | PC.TOPar0(_,clt) | PC.TMid0(_,clt) | PC.TAnd0(_,clt) | PC.TCPar0(_,clt)
>    | PC.TOEllipsis(clt) | PC.TCEllipsis(clt)
> -  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt)
> +  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) | PC.TFunProto(clt)
>    | PC.TFunDecl(clt) | PC.TDirective(_,clt) | PC.TAttr_(clt)
>    | PC.TLineEnd(clt) -> clt
>    | PC.TVAEllipsis(clt) -> clt
> @@ -718,6 +719,7 @@ let update_clt (tok,x) clt =
>
>    | PC.TLineEnd(_) -> (PC.TLineEnd(clt),x)
>    | PC.TFunDecl(_) -> (PC.TFunDecl(clt),x)
> +  | PC.TFunProto(_) -> (PC.TFunProto(clt),x)
>    | PC.TTildeExclEq(_) -> (PC.TTildeExclEq(clt),x)
>    | PC.TDirective(a,_) -> (PC.TDirective(a,clt),x)
>    | PC.TAttr_(_) -> (PC.TAttr_(clt),x)
> @@ -925,7 +927,7 @@ let split_token ((tok,_) as t) =
>    | PC.TInitialize | PC.TFinalize -> ([t],[t])
>    | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt) -> split t clt
>
> -  | PC.TFunDecl(clt)
> +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
>    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
>    | PC.TAny(clt) | PC.TStrict(clt) | PC.TLineEnd(clt)
>    | PC.TEllipsis(clt)
> @@ -1006,7 +1008,8 @@ let find_function_names l =
>      | _ -> false in
>    let rec split acc = function
>        [] | [_] -> raise Irrelevant
> -    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest ->
> +    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest
> +    | ((PC.TCPar(_),_) as t1) :: ((PC.TPtVirg(_),_) as t2) :: rest ->
>  	(List.rev (t1::acc),(t2::rest))
>      | x::xs -> split (x::acc) xs in
>    let rec balanced_name level = function
> @@ -1037,7 +1040,48 @@ let find_function_names l =
>      | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_ ->
>  	raise Irrelevant
>      | t::rest -> balanced_args level rest in
> -  let rec loop = function
> +  let rec is_permissible_proto = function
> +      [] -> false
> +    | (PC.TCPar0(_),_)::
> +      ((PC.TMid0(_),_) | (PC.TAnd0(_),_))::
> +      (PC.TOPar0(_),_)::_ -> false
> +    | (PC.TOPar0(_),_)::rest
> +    | (PC.TCPar0(_),_)::rest -> is_permissible_proto rest
> +    | x::rest when is_mid x ->
> +        let rec loop = function
> +          [] -> false
> +        | (PC.TOPar0(_),_)::xs -> is_permissible_proto xs
> +        | x::xs -> loop xs in
> +        loop rest
> +    | _::((PC.TEq(_),_) | (PC.TNotEq(_),_))::(PC.TWhen(_),_)::_
> +    | _::(PC.TWhen(_),_)::_
> +    | (PC.TComma(_),_)::_
> +    | (PC.TDirective(_),_)::_
> +    | (PC.TElse(_),_)::_
> +    | (PC.TReturn(_),_)::_
> +    | (PC.TMetaStm(_),_)::_
> +    | (PC.TMetaExp(_),_)::_
> +    | (PC.TMetaId(_),_)::_
> +    | (PC.TMetaLocalIdExp(_),_)::_
> +    | (PC.TEq(_),_)::_
> +    | (PC.TEllipsis(_),_)::_
> +    | (PC.TOEllipsis(_),_)::_
> +    | (PC.TCEllipsis(_),_)::_
> +    | (PC.TPOEllipsis(_),_)::_
> +    | (PC.TPCEllipsis(_),_)::_
> +    | (PC.TPtVirg(_),_)::_
> +    | (PC.TOBrace(_),_)::_
> +    | (PC.TCBrace(_),_)::_
> +    | (PC.TOPar(_),_)::_
> +    | (PC.TCPar(_),_)::_
> +    | (PC.TIdent(_),_)::_ -> false
> +    | _ -> true in
> +  let decl_or_proto clt info bef aft =
> +    match aft with
> +      (PC.TOBrace(_),_)::_ -> (((PC.TFunDecl(clt),info) :: bef), aft)
> +    | (PC.TPtVirg(_),_)::_ -> (((PC.TFunProto(clt),info) :: bef), aft)
> +    | _ -> raise Irrelevant in
> +  let rec loop acc = function
>        [] -> []
>      | t :: rest ->
>  	if is_par t || is_mid t || is_ident t
> @@ -1046,26 +1090,30 @@ let find_function_names l =
>  	    try
>  	      let (bef,aft) = split [] (t::rest) in
>  	      let rest = balanced_name 0 bef in
> +              (match aft with
> +                (PC.TPtVirg(_),_)::_
> +                 when not(is_permissible_proto acc) -> raise Irrelevant
> +              | _ ->
>  	      (match rest with
>  		(PC.TOPar(_),_)::_ ->
>  		  (match balanced_args 0 rest with
>  		    [] ->
>  		      let (_,info) as h = List.hd bef in
>  		      let clt = get_clt h in
> -		      (((PC.TFunDecl(clt),info) :: bef), aft)
> +                      decl_or_proto clt info bef aft
>  		  | (PC.TAttr_(_),_)::rest ->
>  		      (match balanced_args 0 rest with
>  			[] ->
>  			  let (_,info) as h = List.hd bef in
>  			  let clt = get_clt h in
> -			  (((PC.TFunDecl(clt),info) :: bef), aft)
> +                          decl_or_proto clt info bef aft
>  		      | _ -> raise Irrelevant)
>  		  | _ -> raise Irrelevant)
> -	      | _ -> raise Irrelevant)
> +	      | _ -> raise Irrelevant))
>  	    with Irrelevant -> ([t],rest) in
> -	  t @ (loop rest)
> -	else t :: (loop rest) in
> -  loop l
> +          t @ (loop (t @ acc) rest)
> +        else t :: (loop (t :: acc) rest) in
> +  loop [] l
>
>  (* ----------------------------------------------------------------------- *)
>  (* an attribute is an identifier that precedes another identifier and
> @@ -1168,6 +1216,8 @@ let detect_types in_meta_decls l =
>  	delim::newid::id::(loop false infn (ident::type_names) rest)
>      | ((PC.TFunDecl(_),_) as fn)::rest ->
>  	fn::(loop false 1 type_names rest)
> +    | ((PC.TFunProto(_),_) as fn)::rest ->
> +	fn::(loop false 1 type_names rest)
>      | ((PC.TOPar(_),_) as lp)::rest when infn > 0 ->
>  	lp::(loop false (infn + 1) type_names rest)
>      | ((PC.TCPar(_),_) as rp)::rest when infn > 0 ->
> @@ -1252,7 +1302,7 @@ let token2line (tok,_) =
>    | PC.TMetaDParamList(_,_,_,_,clt) | PC.TMetaFunc(_,_,_,clt)
>    | PC.TMetaLocalFunc(_,_,_,clt) | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt)
>
> -  | PC.TFunDecl(clt)
> +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
>    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
>    | PC.TAny(clt) | PC.TStrict(clt) | PC.TEllipsis(clt)
>
> diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
> index 9e6c8a08..26958f63 100644
> --- a/parsing_cocci/parser_cocci_menhir.mly
> +++ b/parsing_cocci/parser_cocci_menhir.mly
> @@ -239,7 +239,8 @@ let inline_id aft = function
>
>  %token <Data.clt> TVAEllipsis
>  %token <Data.clt> TIf TElse TWhile TFor TDo TSwitch TCase TDefault TReturn
> -%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof TFunDecl Tdecimal Texec
> +%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof TFunDecl TFunProto
> +%token <Data.clt> Tdecimal Texec
>  %token <string * Data.clt> TIdent TTypeId TDeclarerId TIteratorId TSymId
>  %token <Ast_cocci.added_string * Data.clt> TDirective
>  %token <Data.clt> TAttr_
> @@ -1439,7 +1440,8 @@ reverse_separated_nonempty_llist(separator, X):
>
>  funproto:
>    s=ioption(storage) i=ioption(Tinline) t=ctype
> -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> +  TFunProto id=fn_ident
> +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
>        { let s = match s with None -> [] | Some s -> [Ast0.FStorage s] in
>          let i =
>  	  match i with
> @@ -1453,7 +1455,8 @@ funproto:
>  	      P.clt2mcode "(" lp, args, vararg, P.clt2mcode ")" rp,
>  	      P.clt2mcode ";" pt)) }
>  | i=Tinline s=storage t=ctype
> -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> +  TFunProto id=fn_ident
> +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
>        { let s = [Ast0.FStorage s] in
>          let i = [Ast0.FInline (P.clt2mcode "inline" i)] in
>  	let t = [Ast0.FType t] in
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs
  2020-03-16 10:02 ` [Cocci] [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs Jaskaran Singh
@ 2020-03-18 17:27   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 17:27 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> ParenType and FunctionType are types present in the C AST that
> are not present in the SmPL AST. In the pursuit of aligning
> both the C and SmPL ASTs, add these types to the SmPL ASTs.

It would be nice to extend the log message to give an example of how these
constructors would be used.

julia

>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  ocaml/coccilib.mli           | 6 ++++++
>  parsing_cocci/ast0_cocci.ml  | 3 +++
>  parsing_cocci/ast0_cocci.mli | 3 +++
>  parsing_cocci/ast_cocci.ml   | 3 +++
>  parsing_cocci/ast_cocci.mli  | 3 +++
>  5 files changed, 18 insertions(+)
>
> diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
> index 5a913099..e5409a97 100644
> --- a/ocaml/coccilib.mli
> +++ b/ocaml/coccilib.mli
> @@ -2709,6 +2709,9 @@ module Ast_cocci :
>        | Pointer of fullType * string mcode
>        | FunctionPointer of fullType * string mcode * string mcode *
>            string mcode * string mcode * parameter_list * string mcode
> +      | ParenType of string mcode (* ( *) * fullType * string mcode (* ) *)
> +      | FunctionType of fullType *
> +          string mcode (* ( *) * parameter_list * string mcode (* ) *)
>        | Array of fullType * string mcode * expression option * string mcode
>        | Decimal of string mcode * string mcode * expression *
>            string mcode option * expression option * string mcode
> @@ -3353,6 +3356,9 @@ module Ast0_cocci :
>        | Pointer of typeC * string mcode
>        | FunctionPointer of typeC * string mcode * string mcode *
>            string mcode * string mcode * parameter_list * string mcode
> +      | ParenType of string mcode * typeC * string mcode
> +      | FunctionType of typeC *
> +          string mcode * parameter_list * string mcode
>        | Array of typeC * string mcode * expression option * string mcode
>        | Decimal of string mcode * string mcode * expression *
>            string mcode option * expression option * string mcode
> diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
> index 77dc46f0..0acbeaa4 100644
> --- a/parsing_cocci/ast0_cocci.ml
> +++ b/parsing_cocci/ast0_cocci.ml
> @@ -203,6 +203,9 @@ and base_typeC =
>    | FunctionPointer of typeC *
>  	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
>                    string mcode (* ( *)*parameter_list*string mcode(* ) *)
> +  | ParenType       of string mcode (* ( *) * typeC * string mcode (* ) *)
> +  | FunctionType    of typeC *
> +                  string mcode (* ( *) * parameter_list * string mcode (* ) *)
>    | Array           of typeC * string mcode (* [ *) *
>  	               expression option * string mcode (* ] *)
>    | Decimal         of string mcode (* decimal *) * string mcode (* ( *) *
> diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
> index 274c6bc2..33bd12b2 100644
> --- a/parsing_cocci/ast0_cocci.mli
> +++ b/parsing_cocci/ast0_cocci.mli
> @@ -194,6 +194,9 @@ and base_typeC =
>    | FunctionPointer of typeC *
>  	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
>                    string mcode (* ( *)*parameter_list*string mcode(* ) *)
> +  | ParenType       of string mcode (* ( *) * typeC * string mcode (* ) *)
> +  | FunctionType    of typeC *
> +                  string mcode (* ( *) * parameter_list * string mcode (* ) *)
>    | Array           of typeC * string mcode (* [ *) *
>  	               expression option * string mcode (* ] *)
>    | Decimal         of string mcode (* decimal *) * string mcode (* ( *) *
> diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
> index ba6ec29e..f8e6dee6 100644
> --- a/parsing_cocci/ast_cocci.ml
> +++ b/parsing_cocci/ast_cocci.ml
> @@ -343,6 +343,9 @@ and base_typeC =
>    | FunctionPointer of fullType *
>  	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
>                    string mcode (* ( *)*parameter_list*string mcode(* ) *)
> +  | ParenType       of string mcode (* ( *) * fullType * string mcode (* ) *)
> +  | FunctionType    of fullType *
> +                  string mcode (* ( *) * parameter_list * string mcode (* ) *)
>    | Array           of fullType * string mcode (* [ *) *
>  	               expression option * string mcode (* ] *)
>    | Decimal         of string mcode (* decimal *) * string mcode (* ( *) *
> diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
> index 5f21664b..7fb54e4d 100644
> --- a/parsing_cocci/ast_cocci.mli
> +++ b/parsing_cocci/ast_cocci.mli
> @@ -325,6 +325,9 @@ and base_typeC =
>    | FunctionPointer of fullType *
>  	          string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
>                    string mcode (* ( *)*parameter_list*string mcode(* ) *)
> +  | ParenType       of string mcode (* ( *) * fullType * string mcode (* ) *)
> +  | FunctionType    of fullType *
> +                  string mcode (* ( *) * parameter_list * string mcode (* ) *)
>    | Array           of fullType * string mcode (* [ *) *
>  	               expression option * string mcode (* ] *)
>    | Decimal         of string mcode (* decimal *) * string mcode (* ( *) *
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules
  2020-03-16 10:02 ` [Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules Jaskaran Singh
@ 2020-03-18 17:31   ` Julia Lawall
  2020-03-19  5:11     ` Jaskaran Singh
  0 siblings, 1 reply; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 17:31 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> The direct_declarator rule and the direct_abstract_d rule are
> present in the C parser. Add similar rules to the SmPL parser so that
> declarators are parsed as they are in the C parser.
>
> For the type ParenType, direct_declarator and direct_abstract_d only
> allow the following productions:
>
> 	( * id  [ .* ] ) ( params )
>
> i.e. a function pointer or an array of function pointers. The compromise
> is flexibility in the range of productions, mainly because collateral
> evolutions needed by having a flexible rule are very large and
> distasteful.

It is not clear what is meant by flexible.  Can you give an example of
what will not be supported?

julia

> Replace usage of the older d_ident rule in the SmPL parser with the
> above mentioned rules. All usages of d_ident, however, have not been
> removed due to reduce/reduce conflicts.
>
> Remove rules/productions that parse function pointers with usage of
> direct_declarator and direct_abstract_d.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/parser_cocci_menhir.mly | 239 +++++++++++++-------------
>  1 file changed, 116 insertions(+), 123 deletions(-)
>
> diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
> index 26958f63..fade830f 100644
> --- a/parsing_cocci/parser_cocci_menhir.mly
> +++ b/parsing_cocci/parser_cocci_menhir.mly
> @@ -1116,33 +1116,17 @@ struct_decl_one:
>  	{ let (mids,code) = t in
>  	Ast0.wrap
>  	  (Ast0.ConjField(P.id2mcode lp,code,mids, P.id2mcode rp)) }
> -    | t=ctype d=d_ident_option bf=struct_bitfield? pv=TPtVirg
> +    | t=ctype d=direct_decl_option(disj_ident) bf=struct_bitfield? pv=TPtVirg
>  	 { let (id,fn) = d in
>  	 Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) }
> -    | t=ctype lp1=TOPar st=TMul d=d_ident_option rp1=TCPar
> -	lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> -	bf=struct_bitfield? pv=TPtVirg
> -        { let (id,fn) = d in
> -        let t =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
> -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> -        Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) }
> -     | cv=ioption(const_vol) i=pure_ident_or_symbol d=d_ident_option
> +    | cv=ioption(const_vol) i=pure_ident_or_symbol
> +      d=direct_decl_option(disj_ident)
>  	 bf=struct_bitfield?
>  	 pv=TPtVirg
>  	 { let (id,fn) = d in
>  	 let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in
>  	 Ast0.wrap(Ast0.Field(fn idtype,id,bf,P.clt2mcode ";" pv)) }
>
> -d_ident_option:
> -	 { None, (fun x -> x) }
> -     | d=d_ident {
> -       let (id, fn) = d in
> -       (Some id, fn)
> -    }
> -
>  struct_bitfield:
>     c=TDotDot e=expr { (P.clt2mcode ":" c, e) }
>
> @@ -1529,17 +1513,9 @@ storage:
>         | s=Tregister    { P.clt2mcode Ast.Register s }
>         | s=Textern      { P.clt2mcode Ast.Extern s }
>
> -decl: t=ctype i=disj_ident a=list(array_dec)
> -	{ let t = P.arrayify t a in Ast0.wrap(Ast0.Param(t, Some i)) }
> +decl: t=ctype d=direct_declarator(disj_ident)
> +	{ let (i,fn) = d in Ast0.wrap(Ast0.Param(fn t, Some i)) }
>      | t=ctype { (*verify in FunDecl*) Ast0.wrap(Ast0.Param(t, None)) }
> -    | t=ctype lp=TOPar s=TMul i=disj_ident rp=TCPar
> -	lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar
> -        { let fnptr =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")" rp,
> -		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
> -	Ast0.wrap(Ast0.Param(fnptr, Some i)) }
>      | TMetaParam
>  	{ let (nm,cstr,pure,clt) = $1 in
>  	Ast0.wrap(Ast0.MetaParam(P.clt2mcode nm clt,cstr,pure)) }
> @@ -1547,14 +1523,6 @@ decl: t=ctype i=disj_ident a=list(array_dec)
>
>  name_opt_decl:
>        decl  { $1 }
> -    | t=ctype lp=TOPar s=TMul rp=TCPar
> -	lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar
> -        { let fnptr =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")" rp,
> -		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
> -	Ast0.wrap(Ast0.Param(fnptr, None)) }
>
>  const_vol:
>        Tconst       { P.clt2mcode Ast.Const $1 }
> @@ -1684,13 +1652,15 @@ decl_var:
>      t=ctype pv=TPtVirg
>        { [Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv))] }
>    | TMetaDecl { [P.meta_decl $1] }
> -  | s=ioption(storage) t=ctype d=comma_list(d_ident) pv=TPtVirg
> +  | s=ioption(storage) t=ctype
> +      d=comma_list(direct_declarator(disj_ident)) pv=TPtVirg
>        { List.map
>  	  (function (id,fn) ->
>  	    Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv)))
>  	  d }
>    | f=funproto { [f] }
> -  | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq e=initialize
> +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> +    a=attr_list q=TEq e=initialize
>        pv=TPtVirg
>        {let (id,fn) = d in
>        [Ast0.wrap
> @@ -1711,18 +1681,6 @@ decl_var:
>        let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in
>        [Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
>  			   P.clt2mcode ";" pv))] }
> -  /* function pointer type */
> -  | s=ioption(storage)
> -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> -    pv=TPtVirg
> -      { let (id,fn) = d in
> -        let t =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
> -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> -        [Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv))] }
>    | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option c=TCPar
>        p=TPtVirg
>        { [Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e,
> @@ -1735,56 +1693,25 @@ decl_var:
>  	       (s,d,P.clt2mcode "(" o,e,
>  		P.clt2mcode ")" c,P.clt2mcode "=" q,i,
>  		P.clt2mcode ";" p))] }
> -  | s=ioption(storage)
> -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> -    q=TEq e=initialize pv=TPtVirg
> -      { let (id,fn) = d in
> -        let t =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
> -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> -      [Ast0.wrap
> -	  (Ast0.Init(s,fn t,id,[],P.clt2mcode "=" q,e,P.clt2mcode ";" pv))]}
> -  | s=Ttypedef t=typedef_ctype id=comma_list(typedef_ident) pv=TPtVirg
> +  | s=Ttypedef t=typedef_ctype
> +      d=comma_list(direct_declarator(typedef_ident)) pv=TPtVirg
>        { let s = P.clt2mcode "typedef" s in
>          List.map
> -	  (function id ->
> -	    Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv)))
> -	  id }
> -  | s=Ttypedef t=typedef_ctype id=typedef_ident
> -      l=TOCro i=eexpr r=TCCro pv=TPtVirg
> -      { let s = P.clt2mcode "typedef" s in
> -        let t = P.arrayify t [(l,Some i,r)] in
> -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))] }
> -  | s=Ttypedef t=typedef_ctype id=typedef_ident
> -      l=TOCro i=eexpr r=TCCro
> -      l2=TOCro i2=eexpr r2=TCCro pv=TPtVirg
> -      { let s = P.clt2mcode "typedef" s in
> -        let t = P.arrayify t [(l,Some i,r)] in
> -        let t = P.arrayify t [(l2,Some i2,r2)] in
> -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))] }
> -  | s=Ttypedef
> -    t=typedef_ctype lp1=TOPar st=TMul id=typedef_ident rp1=TCPar
> -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar pv=TPtVirg
> -      { let s = P.clt2mcode "typedef" s in
> -        let t =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
> -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))]}
> +	  (function (id,fn) ->
> +	    Ast0.wrap(Ast0.Typedef(s,fn t,id,P.clt2mcode ";" pv)))
> +	  d }
>
>  one_decl_var:
>      t=ctype pv=TPtVirg
>        { Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv)) }
>    | TMetaDecl { P.meta_decl $1 }
> -  | s=ioption(storage) t=ctype d=d_ident a=attr_list pv=TPtVirg
> +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> +      a=attr_list pv=TPtVirg
>        { let (id,fn) = d in
>          Ast0.wrap(Ast0.UnInit(s,fn t,id,a,P.clt2mcode ";" pv)) }
>    | f=funproto { f }
> -  | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq e=initialize
> +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> +      a=attr_list q=TEq e=initialize
>        pv=TPtVirg
>        { let (id,fn) = d in
>        Ast0.wrap
> @@ -1802,18 +1729,6 @@ one_decl_var:
>        let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode i))) in
>        Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
>  			   P.clt2mcode ";" pv)) }
> -  /* function pointer type */
> -  | s=ioption(storage)
> -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> -    pv=TPtVirg
> -      { let (id,fn) = d in
> -        let t =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
> -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> -        Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv)) }
>    | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option c=TCPar
>        p=TPtVirg
>        { Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e,
> @@ -1826,19 +1741,103 @@ one_decl_var:
>                 (s,d,P.clt2mcode "(" o,e,
>                  P.clt2mcode ")" c,P.clt2mcode "=" q,i,
>                  P.clt2mcode ";" p)) }
> -  | s=ioption(storage)
> -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar a=attr_list
> -    q=TEq e=initialize pv=TPtVirg
> -      { let (id,fn) = d in
> -        let t =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode ")" rp1,
> -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> -      Ast0.wrap(Ast0.Init(s,fn t,id,a,P.clt2mcode "=" q,e,P.clt2mcode ";" pv))}
>
>
> +direct_declarator(ident_type):
> +    ident_type
> +      { ($1, function x -> x) }
> +  | o=TOPar m=list(TMul) d=direct_declarator(ident_type) c=TCPar
> +      { let (id,fn) = d in
> +        (id,
> +         function t ->
> +          let ty =  fn (P.pointerify t m) in
> +          let _ =
> +           match Ast0.unwrap ty with
> +            Ast0.Pointer(ty1,_) ->
> +             (match Ast0.unwrap ty1 with
> +               Ast0.FunctionType(ty2,_,_,_) -> ()
> +             | _ ->
> +              raise (Semantic_cocci.Semantic "expected function pointer"))
> +           | Ast0.Array(ty1,_,_,_) ->
> +              (match Ast0.unwrap ty1 with
> +                Ast0.Pointer(ty2,_) ->(
> +                 match Ast0.unwrap ty2 with
> +                  Ast0.FunctionType(ty3,_,_,_) -> ()
> +                 | _ ->
> +                  raise (Semantic_cocci.Semantic "expected function pointer"))
> +             | _ ->
> +              raise (Semantic_cocci.Semantic "expected function pointer"))
> +           | _ ->
> +            raise (Semantic_cocci.Semantic "expected function pointer") in
> +          Ast0.wrap
> +            (Ast0.ParenType
> +               (P.clt2mcode "(" o,
> +                ty,
> +                P.clt2mcode ")" c))) }
> +  | d=direct_declarator(ident_type) a=array_dec
> +      { let (id,fn) = d in
> +        (id, function t -> let r = P.arrayify t [a] in fn r) }
> +  | d=direct_declarator(ident_type)
> +      o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
> +      { let (id,fn) = d in
> +        (id, function t ->
> +              let r =
> +               Ast0.wrap
> +                (Ast0.FunctionType
> +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c)) in fn r) }
> +
> +
> +direct_abstract_d:
> +    o=TOPar m=list(TMul) d=direct_abstract_d c=TCPar
> +      { function t ->
> +          let ty = d (P.pointerify t m) in
> +          let _ =
> +           match Ast0.unwrap ty with
> +            Ast0.Pointer(ty1,_) ->
> +             (match Ast0.unwrap ty1 with
> +               Ast0.FunctionType(ty2,_,_,_) ->()
> +             | _ ->
> +              raise (Semantic_cocci.Semantic "expected function pointer"))
> +           | Ast0.Array(ty1,_,_,_) ->
> +              (match Ast0.unwrap ty1 with
> +                Ast0.Pointer(ty2,_) ->(
> +                 match Ast0.unwrap ty2 with
> +                  Ast0.FunctionType(ty3,_,_,_) -> ()
> +                 | _ ->
> +                  raise (Semantic_cocci.Semantic "expected function pointer"))
> +             | _ ->
> +              raise (Semantic_cocci.Semantic "expected function pointer"))
> +           | _ ->
> +            raise (Semantic_cocci.Semantic "expected function pointer") in
> +          Ast0.wrap
> +            (Ast0.ParenType
> +               (P.clt2mcode "(" o,
> +                ty,
> +                P.clt2mcode ")" c))
> +      }
> +  | a=array_dec
> +      { function t -> P.arrayify t [a] }
> +  | d=direct_abstract_d a=array_dec
> +      { function t -> let r = P.arrayify t [a] in d r }
> +  | o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
> +      { function t ->
> +               Ast0.wrap
> +                (Ast0.FunctionType
> +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c)) }
> +  | d=direct_abstract_d o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
> +      { function t ->
> +              let r =
> +               Ast0.wrap
> +                (Ast0.FunctionType
> +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c)) in d r }
> +
> +
> +direct_decl_option(ident_type):
> +      { (None, function x -> x) }
> +  | d=direct_declarator(ident_type)
> +      { let (id,fn) = d in
> +        (Some id, fn) }
> +
>  d_ident:
>      disj_ident list(array_dec)
>        { ($1, function t -> P.arrayify t $2) }
> @@ -2151,16 +2150,10 @@ cast_expr(r,pe):
>      unary_expr(r,pe)                      { $1 }
>    | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe)
>        { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t,
> +                             P.clt2mcode ")" rp, e)) }
> +  | lp=TOPar t=ctype d=direct_abstract_d rp=TCPar e=cast_expr(r,pe)
> +      { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t,
>  			     P.clt2mcode ")" rp, e)) }
> -  | lp=TOPar t=ctype lp1=TOPar s=TMul rp1=TCPar
> -      lp2=TOPar d=decl_list(name_opt_decl) rp2=TCPar rp=TCPar
> -      e=cast_expr(r,pe)
> -      { let fnptr =
> -	  Ast0.wrap
> -	    (Ast0.FunctionPointer
> -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" s,P.clt2mcode ")" rp1,
> -		P.clt2mcode "(" lp2,d,P.clt2mcode ")" rp2)) in
> -      Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, fnptr, P.clt2mcode ")" rp, e)) }
>
>  unary_expr(r,pe):
>      postfix_expr(r,pe)                   { $1 }
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType
  2020-03-16 10:02 ` [Cocci] [PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType Jaskaran Singh
@ 2020-03-18 17:42   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 17:42 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> The order of the terms in ParenType require implementing a special
> case for ParenType. This case handles only the following:
>
> 	<type> ( * id [ .* ] ) ( params )
>
> i.e., a function pointer or an array of function pointers, and will fail
> for any other cases. This is similar to the function used to print
> ParenType in Pretty_print_c.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/visitor_ast0.ml | 163 ++++++++++++++++++++++++++++++++++
>  1 file changed, 163 insertions(+)
>
> diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
> index c282e1f8..c56cd7a7 100644
> --- a/parsing_cocci/visitor_ast0.ml
> +++ b/parsing_cocci/visitor_ast0.ml
> @@ -339,6 +339,12 @@ let visitor mode bind option_default
>  	| Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>  	    let (t,id) =
>                function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2) in t
> +        | Ast0.ParenType(lp,ty,rp) ->
> +	    let (t,id) =
> +              parentype_type (lp,ty,None,rp) in t
> +        | Ast0.FunctionType(ty,lp,params,rp) ->
> +	    let (t,id) =
> +              functiontype_type (ty,None,lp,params,rp) in t
>  	| Ast0.Array(ty,lb,size,rb) ->
>              let (t,id) = array_type (ty,None,lb,size,rb) in t
>  	| Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) ->
> @@ -435,6 +441,76 @@ let visitor mode bind option_default
>      ((multibind ([ty_n] @ idl @ [lb_n;size_n;rb_n]),
>       Ast0.Array(ty,lb,size,rb)), idu)
>
> +  and parentype_type (lp,ty,(id : Ast0.ident option),rp) =
> +    match Ast0.unwrap ty with
> +      Ast0.Pointer(ty1,star) ->
> +        (match Ast0.unwrap ty1 with
> +          Ast0.FunctionType(ty2,lp2,params,rp2) ->
> +            let (ty_n,typ) = typeC ty2 in
> +            let (lp_n,lp) = string_mcode lp in
> +            let (star_n,star) = string_mcode star in
> +            let (idl,idu) = (match id with

I would prefer the match on a line by itself.  It doesn't need parentheses
around it.  (Even though I see that some other code has done it the way
you do it here).

> +              | Some a -> let (b,c) = ident a in ([b],Some c)
> +              | None -> ([],None)) in
> +            let (rp_n,rp) = string_mcode rp in
> +            let (lp2_n,lp2) = string_mcode lp2 in
> +            let (params_n,params) = parameter_dots params in
> +            let (rp2_n,rp2) = string_mcode rp2 in
> +            ((multibind ([ty_n;lp_n;star_n] @ idl @
> +              [rp_n;lp2_n;params_n;rp2_n]),
> +               Ast0.ParenType
> +                 (lp,
> +                  Ast0.rewrap ty1 (Ast0.Pointer
> +                   (Ast0.rewrap ty2 (Ast0.FunctionType
> +                     (typ,lp2,params,rp2)),star)),rp)), idu)
> +	| _ -> failwith "ParenType Visitor_ast0")
> +    | Ast0.Array(ty1,lb1,size1,rb1) ->
> +        (match Ast0.unwrap ty1 with
> +          Ast0.Pointer(ty2,star) ->
> +            (match Ast0.unwrap ty2 with
> +              Ast0.FunctionType(ty3,lp3,params,rp3) ->
> +                let (ty_n,typ) = typeC ty3 in
> +                let (lp_n,lp) = string_mcode lp in
> +                let (star_n,star) = string_mcode star in
> +                let (idl,idu) = (match id with
> +                  | Some a -> let (b,c) = ident a in ([b],Some c)
> +                  | None -> ([],None)) in
> +                let (lb1_n,lb1) = string_mcode lb1 in
> +                let (size_n,size1) = get_option expression size1 in
> +                let (rb1_n,rb1) = string_mcode rb1 in
> +                let (rp_n,rp) = string_mcode rp in
> +                let (lp3_n,lp3) = string_mcode lp3 in
> +                let (params_n,params) = parameter_dots params in
> +                let (rp3_n,rp3) = string_mcode rp3 in
> +                ((multibind ([ty_n;lp_n;star_n] @ idl @
> +                  [lb1_n;size_n;rb1_n;rp_n;lp3_n;params_n;rp3_n]),
> +                   Ast0.ParenType
> +                     (lp,
> +                      Ast0.rewrap ty1
> +                       (Ast0.Array
> +                         (Ast0.rewrap ty2
> +                           (Ast0.Pointer
> +                             (Ast0.rewrap ty3
> +                               (Ast0.FunctionType(typ,lp3,params,rp3)),
> +                              star)),
> +                        lb1,size1,rb1)),
> +                   rp)),
> +                 idu)
> +    	    | _ -> failwith "ParenType Visitor_ast0")
> +        | _ -> failwith "ParenType Visitor_ast0")
> +    | _ -> failwith "ParenType Visitor_ast0"

Can some code be shared between the above two cases?

> +  and functiontype_type (ty,(id : Ast0.ident option),lp,params,rp) =
> +    let (ty_n,ty) = typeC ty in
> +    let (idl,idu) = (match id with
> +      | Some a -> let (b,c) = ident a in ([b],Some c)
> +      | None -> ([],None)) in
> +    let (lp_n,lp) = string_mcode lp in
> +    let (params_n,params) = parameter_dots params in
> +    let (rp_n,rp) = string_mcode rp in
> +    ((multibind ([ty_n] @ idl @ [lp_n; params_n; rp_n]),
> +     Ast0.FunctionType(ty,lp,params,rp)), idu)
> +
>    and named_type ty id =
>      match Ast0.unwrap ty with
>        Ast0.FunctionPointer(rty,lp1,star,rp1,lp2,params,rp2) ->
> @@ -446,6 +522,14 @@ let visitor mode bind option_default
>  	let (tyres, idn) = array_type (rty,Some id,lb,size,rb) in
>          let idn = match idn with Some i -> i | None -> failwith "Impossible" in
>  	(rewrap ty tyres, idn)
> +    | Ast0.ParenType(lp,rty,rp) ->
> +	let (tyres, idn) = parentype_type (lp,rty,Some id,rp) in
> +        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
> +	(rewrap ty tyres, idn)
> +    | Ast0.FunctionType(rty,lp,params,rp) ->
> +	let (tyres, idn) = functiontype_type (rty,Some id,lp,params,rp) in
> +        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
> +	(rewrap ty tyres, idn)

The second let is using spaces instead of a tab in each case.  The code
above has the same problem.  No need to modify the code above, but the new
code could use the tabs.

>      | _ -> let (ty_n,ty) = typeC ty in
>             let (id_n,id) = ident id in
>               ((bind ty_n id_n, ty), id)
> @@ -479,6 +563,77 @@ let visitor mode bind option_default
>      ((multibind ([ty_n] @ idl @ [lb_n;size_n;rb_n]),
>       Ast0.Array(ty,lb,size,rb)), idu)
>
> +  (* returns ((bind value,original value),id) since id may have been updated*)
> +  and parentype_typedef (lp,ty,id,rp) =
> +    match Ast0.unwrap ty with
> +      Ast0.Pointer(ty1,star) ->
> +        (match Ast0.unwrap ty1 with
> +          Ast0.FunctionType(ty2,lp2,params,rp2) ->
> +            let (ty_n,typ) = typeC ty2 in
> +            let (lp_n,lp) = string_mcode lp in
> +            let (star_n,star) = string_mcode star in
> +            let (idl,idu) = (match id with
> +              | Some a -> let (b,c) = typeC a in ([b],Some c)
> +              | None -> ([],None)) in
> +            let (rp_n,rp) = string_mcode rp in
> +            let (lp2_n,lp2) = string_mcode lp2 in
> +            let (params_n,params) = parameter_dots params in
> +            let (rp2_n,rp2) = string_mcode rp2 in
> +            ((multibind ([ty_n;lp_n;star_n] @ idl @
> +              [rp_n;lp2_n;params_n;rp2_n]),
> +               Ast0.ParenType
> +                 (lp,
> +                  Ast0.rewrap ty1 (Ast0.Pointer
> +                   (Ast0.rewrap ty2 (Ast0.FunctionType
> +                     (typ,lp2,params,rp2)),star)),rp)), idu)
> +	| _ -> failwith "ParenType Visitor_ast0")
> +    | Ast0.Array(ty1,lb1,size1,rb1) ->
> +        (match Ast0.unwrap ty with
> +          Ast0.Pointer(ty2,star) ->
> +            (match Ast0.unwrap ty1 with
> +              Ast0.FunctionType(ty3,lp3,params,rp3) ->
> +                let (ty_n,typ) = typeC ty3 in
> +                let (lp_n,lp) = string_mcode lp in
> +                let (star_n,star) = string_mcode star in
> +                let (idl,idu) = (match id with
> +                  | Some a -> let (b,c) = typeC a in ([b],Some c)
> +                  | None -> ([],None)) in
> +                let (lb1_n,lb1) = string_mcode lb1 in
> +                let (size_n,size1) = get_option expression size1 in
> +                let (rb1_n,rb1) = string_mcode rb1 in
> +                let (rp_n,rp) = string_mcode rp in
> +                let (lp3_n,lp3) = string_mcode lp3 in
> +                let (params_n,params) = parameter_dots params in
> +                let (rp3_n,rp3) = string_mcode rp3 in
> +                ((multibind ([ty_n;lp_n;star_n] @ idl @
> +                  [lb1_n;size_n;rb1_n;rp_n;lp3_n;params_n;rp3_n]),
> +                   Ast0.ParenType
> +                     (lp,
> +                      Ast0.rewrap ty1
> +                       (Ast0.Array
> +                         (Ast0.rewrap ty2
> +                           (Ast0.Pointer
> +                             (Ast0.rewrap ty3
> +                               (Ast0.FunctionType(typ,lp3,params,rp3)),
> +                              star)),
> +                        lb1,size1,rb1)),
> +                   rp)),
> +                 idu)
> +    	    | _ -> failwith "ParenType Visitor_ast0")
> +        | _ -> failwith "ParenType Visitor_ast0")
> +    | _ -> failwith "ParenType Visitor_ast0"

Again, can some code be shared?

julia


> +
> +  and functiontype_typedef (ty,id,lp,params,rp) =
> +    let (ty_n,ty) = typeC ty in
> +    let (idl,idu) = (match id with
> +      | Some a -> let (b,c) = typeC a in ([b],Some c)
> +      | None -> ([],None)) in
> +    let (lp_n,lp) = string_mcode lp in
> +    let (params_n,params) = parameter_dots params in
> +    let (rp_n,rp) = string_mcode rp in
> +    ((multibind ([ty_n] @ idl @ [lp_n; params_n; rp_n]),
> +     Ast0.FunctionType(ty,lp,params,rp)), idu)
> +
>    and named_type_typedef ty id =
>      match Ast0.unwrap ty with
>        Ast0.FunctionPointer(rty,lp1,star,rp1,lp2,params,rp2) ->
> @@ -490,6 +645,14 @@ let visitor mode bind option_default
>  	let (tyres, idn) = array_type_typedef (rty,Some id,lb,size,rb) in
>          let idn = match idn with Some i -> i | None -> failwith "Impossible" in
>  	(rewrap ty tyres, idn)
> +    | Ast0.ParenType(lp,rty,rp) ->
> +	let (tyres, idn) = parentype_typedef (lp,rty,Some id,rp) in
> +        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
> +	(rewrap ty tyres, idn)
> +    | Ast0.FunctionType(rty,lp,params,rp) ->
> +	let (tyres, idn) = functiontype_typedef (rty,Some id,lp,params,rp) in
> +        let idn = match idn with Some i -> i | None -> failwith "Impossible" in
> +	(rewrap ty tyres, idn)
>      | _ -> let (ty_n,ty) = typeC ty in
>             let (id_n,id) = typeC id in
>               ((bind ty_n id_n, ty), id)
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH v2 05/26] parsing_cocci: visitor_ast: Add cases for ParenType/FunctionType
  2020-03-17  8:43   ` [Cocci] [PATCH v2 " Jaskaran Singh
@ 2020-03-18 17:45     ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 17:45 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Tue, 17 Mar 2020, Jaskaran Singh wrote:

> The order of the terms in ParenType require implementing a special
> case for ParenType. This case handles only the following:
>
> 	<type> ( * id [ .* ] ) ( params )
>
> i.e., a function pointer or an array of function pointers, and will fail
> for any other cases. This is similar to the function used to print
> ParenType in Pretty_print_c.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
> Changes in v2:
> -------------
> - Change the "visitor_ast0" in patch subject to "visitor_ast"
>
>  parsing_cocci/visitor_ast.ml | 75 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 75 insertions(+)
>
> diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
> index 3d5de794..99af7652 100644
> --- a/parsing_cocci/visitor_ast.ml
> +++ b/parsing_cocci/visitor_ast.ml
> @@ -318,6 +318,61 @@ let combiner bind option_default
>      let lrb = string_mcode rb in
>      multibind ([lty] @ lid @ [lb; lsize; lrb])
>
> +  and parentype_type (lp, ty, (id : Ast.ident option), rp) =
> +    match Ast.unwrap ty with
> +     Ast.Type(_,_,fty1) ->
> +      (match Ast.unwrap fty1 with
> +         Ast.Pointer(ty1,star) ->
> +          (match Ast.unwrap ty1 with
> +             Ast.Type(_,_,fty2) ->
> +              (match Ast.unwrap fty2 with
> +                Ast.FunctionType(ty2,lp2,params,rp2) ->
> +                  let typ = fullType ty2 in
> +                  let lp = string_mcode lp in
> +                  let star = string_mcode star in
> +                  let idl = match id with
> +                    | Some idd -> [ident idd]
> +                    | None -> [] in
> +                  let rp = string_mcode rp in
> +                  let lp2 = string_mcode lp2 in
> +                  let params = parameter_dots params in
> +                  let rp2 = string_mcode rp2 in
> +                  multibind
> +                    ([typ;lp;star] @ idl @ [rp;lp2;params;rp2])
> +                | _ -> failwith "ParenType Visitor_ast")
> +           | _ -> failwith "ParenType Visitor_ast")
> +       | Ast.Array(ty1,lb1,size1,rb1) ->
> +          (match Ast.unwrap ty1 with
> +            Ast.Type(_,_,fty2) ->
> +             (match Ast.unwrap fty2 with
> +               Ast.Pointer(ty2,star) ->
> +                (match Ast.unwrap ty2 with
> +                  Ast.Type(_,_,fty3) ->
> +                   (match Ast.unwrap fty3 with
> +                     Ast.FunctionType(ty3,lp3,params,rp3) ->
> +                     let typ = fullType ty3 in
> +                     let lp = string_mcode lp in
> +                     let star = string_mcode star in
> +                     let idl = match id with
> +                       | Some idd -> [ident idd]
> +                       | None -> [] in
> +                     let lb1 = string_mcode lb1 in
> +                     let size1 = get_option expression size1 in
> +                     let rb1 = string_mcode rb1 in
> +                     let rp = string_mcode rp in
> +                     let lp3 = string_mcode lp3 in
> +                     let params = parameter_dots params in
> +                     let rp3 = string_mcode rp3 in
> +                     multibind
> +                       ([typ;lp;star] @ idl @
> +                        [lb1;size1;rb1;rp;lp3;params;rp3])
> +   	           | _ -> failwith "ParenType Visitor_ast")
> +                | _ -> failwith "ParenType Visitor_ast")
> +             | _ -> failwith "ParenType Visitor_ast")
> +          | _ -> failwith "ParenType Visitor_ast")
> +       | _ -> failwith "ParenType Visitor_ast")
> +    | _ -> failwith "ParenType Visitor_ast"

Same comments as in the ast0 case: the match can go on a line below and I
wonder if some of the code can be shared.

julia


> +
>    and typeC ty =
>      let k ty =
>        match Ast.unwrap ty with
> @@ -332,6 +387,14 @@ let combiner bind option_default
>  	  bind lty lstar
>        | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>  	  function_pointer (ty,lp1,star,None,rp1,lp2,params,rp2)
> +      | Ast.ParenType(lp,ty,rp) ->
> +          parentype_type (lp,ty,None,rp)
> +      | Ast.FunctionType(ty,lp,params,rp) ->
> +          let lty = fullType ty in
> +          let llp = string_mcode lp in
> +          let lparams = parameter_dots params in
> +          let lrp = string_mcode rp in
> +          multibind [lty; llp; lparams; lrp]
>        | Ast.Array(ty,lb,size,rb) -> array_type (ty,None,lb,size,rb)
>        | Ast.Decimal(dec,lp,length,comma,precision_opt,rp) ->
>  	  let ldec = string_mcode dec in
> @@ -384,6 +447,7 @@ let combiner bind option_default
>  	  Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>  	    function_pointer (ty, lp1, star, Some id, rp1, lp2, params, rp2)
>  	| Ast.Array(ty,lb,size,rb) -> array_type (ty, Some id, lb, size, rb)
> +        | Ast.ParenType(lp,ty,rp) -> parentype_type (lp, ty, Some id, rp)
>  	| _ -> let lty = fullType ty in
>  	       let lid = ident id in
>  	       bind lty lid)
> @@ -1253,6 +1317,17 @@ let rebuilder
>  	    let lparams = parameter_dots params in
>  	    let lrp2 = string_mcode rp2 in
>  	    Ast.FunctionPointer(lty, llp1, lstar, lrp1, llp2, lparams, lrp2)
> +        | Ast.ParenType(lp,ty,rp) ->
> +            let llp = string_mcode lp in
> +            let lty = fullType ty in
> +            let lrp = string_mcode rp in
> +            Ast.ParenType(llp,lty,lrp)
> +        | Ast.FunctionType(ty,lp,params,rp) ->
> +            let lty = fullType ty in
> +            let llp = string_mcode lp in
> +            let lparams = parameter_dots params in
> +            let lrp = string_mcode rp in
> +            Ast.FunctionType(lty,llp,lparams,lrp)
>  	| Ast.Array(ty,lb,size,rb) ->
>  	    let lty = fullType ty in
>  	    let llb = string_mcode lb in
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 07/26] parsing_cocci: index: Add cases for ParenType/FunctionType
  2020-03-16 10:03 ` [Cocci] [PATCH 07/26] parsing_cocci: index: " Jaskaran Singh
@ 2020-03-18 18:35   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 18:35 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci

On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> ParenType and FunctionType are now added to the SmPL ASTs. Add
> cases for these types in index.ml.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/index.ml | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
> index a1103503..5c91f620 100644
> --- a/parsing_cocci/index.ml
> +++ b/parsing_cocci/index.ml
> @@ -93,6 +93,8 @@ let typeC t =
>    | Ast0.Signed(sign,ty) -> [129]
>    | Ast0.Pointer(ty,star) -> [49]
>    | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> [131]
> +  | Ast0.ParenType(lp,ty,rp) -> [138]
> +  | Ast0.FunctionType(ty,lp,params,rp) -> [139]

You should indicate at the top of the file that these numbers aren't
available any more.

julia

>    | Ast0.Array(ty,lb,size,rb) -> [50]
>    | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) -> [160]
>    | Ast0.EnumName(kind,name) -> [146]
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 09/26] parsing_cocci: unparse_ast0: Add cases for ParenType/FunctionType
  2020-03-16 10:03 ` [Cocci] [PATCH 09/26] parsing_cocci: unparse_ast0: " Jaskaran Singh
@ 2020-03-18 18:36   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 18:36 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> ParenType/FunctionType are now types in the SmPL ASTs. Add
> cases for these types in unparse_ast0.ml.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/unparse_ast0.ml | 43 +++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
>
> diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
> index 5d450e0e..f8684dd2 100644
> --- a/parsing_cocci/unparse_ast0.ml
> +++ b/parsing_cocci/unparse_ast0.ml
> @@ -292,6 +292,40 @@ and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn =
>    mcode print_string rp1; mcode print_string lp2;
>    parameter_list params; mcode print_string rp2
>
> +and print_parentype (lp,ty,rp) fn =
> + match Ast0.unwrap ty with
> +   Ast0.Pointer(ty1,star) ->
> +     (match Ast0.unwrap ty1 with
> +       Ast0.FunctionType(ty2,lp2,params,rp2) ->
> +         typeC ty2;
> +         mcode print_string lp;
> +         mcode print_string star;
> +         fn();
> +         mcode print_string rp;
> +         mcode print_string lp2;
> +         parameter_list params;
> +         mcode print_string rp2;
> +       | _ -> failwith "ParenType Unparse_ast0")
> + | Ast0.Array(ty1,lb1,size1,rb1) ->
> +     (match Ast0.unwrap ty1 with
> +       Ast0.Pointer(ty2,star) ->
> +         (match Ast0.unwrap ty2 with
> +           Ast0.FunctionType(ty3,lp3,params,rp3) ->
> +             typeC ty3;
> +             mcode print_string lp;
> +             mcode print_string star;
> +             fn();
> +             mcode print_string lb1;
> +             print_option expression size1;
> +             mcode print_string rb1;
> +             mcode print_string rp;
> +             mcode print_string lp3;
> +             parameter_list params;
> +             mcode print_string rp3;

It should be possible to share some code here.

julia

> + 	| _ -> failwith "ParenType Unparse_ast0")
> +     | _ -> failwith "ParenType Unparse_ast0")
> + | _ -> failwith "ParenType Unparse_ast0"
> +
>  and typeC t =
>    print_context t
>      (function _ ->
> @@ -306,6 +340,13 @@ and typeC t =
>        | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>  	  print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
>  	    (function _ -> ())
> +      | Ast0.ParenType(lp,ty,rp) ->
> +          print_parentype (lp,ty,rp) (function _ -> ())
> +      | Ast0.FunctionType(ty,lp,params,rp) ->
> +          typeC ty;
> +          mcode print_string lp;
> +          parameter_list params;
> +          mcode print_string rp
>        | Ast0.Array(ty,lb,size,rb) ->
>  	  typeC ty; mcode print_string lb; print_option expression size;
>  	  mcode print_string rb
> @@ -367,6 +408,8 @@ and print_named_type ty id =
>  		mcode print_string rb)
>  	| _ -> typeC ty; ident id; k () in
>        loop ty (function _ -> ())
> +  | Ast0.ParenType(lp,ty,rp) ->
> +      print_parentype (lp,ty,rp) (function _ -> ident id)
>    | _ -> typeC ty; ident id
>
>  and declaration d =
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 10/26] parsing_cocci: single_statement: Add cases for ParenType/FunctionType
  2020-03-16 10:03 ` [Cocci] [PATCH 10/26] parsing_cocci: single_statement: " Jaskaran Singh
@ 2020-03-18 18:37   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 18:37 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> ParenType/FunctionType are now types in the SmPL ASTs. Add
> cases for these types in single_statement.ml.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/single_statement.ml | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml
> index 46408b73..48d77b5a 100644
> --- a/parsing_cocci/single_statement.ml
> +++ b/parsing_cocci/single_statement.ml
> @@ -166,6 +166,8 @@ and left_typeC t =
>    | Ast0.Signed(sgn,ty) -> modif_before_mcode sgn
>    | Ast0.Pointer(ty,star) -> left_typeC ty
>    | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> left_typeC ty
> +  | Ast0.ParenType(lp,ty,rp) -> left_typeC ty

This doesn't look correct.  ty is not the leftmost thing.

julia

> +  | Ast0.FunctionType(ty,lp,params,rp) -> left_typeC ty
>    | Ast0.Array(ty,lb,size,rb) -> left_typeC ty
>    | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) ->
>        modif_before_mcode dec
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 14/26] parsing_cocci: adjust_pragmas: Add cases for ParenType/FunctionType
  2020-03-16 10:03 ` [Cocci] [PATCH 14/26] parsing_cocci: adjust_pragmas: " Jaskaran Singh
@ 2020-03-18 18:42   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 18:42 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> ParenType and FunctionType are now added to the SmPL ASTs. Add
> cases for these types in adjust_pragmas.ml.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/adjust_pragmas.ml | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/parsing_cocci/adjust_pragmas.ml b/parsing_cocci/adjust_pragmas.ml
> index 73b5ff5f..537150e7 100644
> --- a/parsing_cocci/adjust_pragmas.ml
> +++ b/parsing_cocci/adjust_pragmas.ml
> @@ -171,6 +171,10 @@ let rec left_ty t =
>    | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>        call_right left_ty ty t
>  	(function ty -> Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))
> +  | Ast0.ParenType(lp,ty,rp) ->
> +      call_right left_ty ty t (function ty -> Ast0.ParenType(lp,ty,rp))

This doesn't look right, because the type is not the leftmost thing.

julia

> +  | Ast0.FunctionType(ty,lp,params,rp) ->
> +      call_right left_ty ty t (function ty -> Ast0.FunctionType(ty,lp,params,rp))
>    | Ast0.Array(ty,lb,size,rb) ->
>        call_right left_ty ty t (function ty -> Ast0.Array(ty,lb,size,rb))
>    | Ast0.Decimal(dec,lp,length,comma,precision_opt,rp) ->
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 15/26] parsing_cocci: compute_lines: Add cases for ParenType/FunctionType
  2020-03-16 10:03 ` [Cocci] [PATCH 15/26] parsing_cocci: compute_lines: " Jaskaran Singh
@ 2020-03-18 18:43   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 18:43 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> ParenType and FunctionType are now added to the SmPL ASTs. Add
> cases for these types in compute_lines.ml.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/compute_lines.ml | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml
> index f4b6f4d8..8231a0e7 100644
> --- a/parsing_cocci/compute_lines.ml
> +++ b/parsing_cocci/compute_lines.ml
> @@ -574,6 +574,17 @@ and typeC t =
>        let rp2 = normal_mcode rp2 in
>        mkres t (Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2))
>  	ty (promote_mcode rp2)
> +  | Ast0.ParenType(lp,ty,rp) ->
> +      let lp = normal_mcode lp in
> +      let rp = normal_mcode rp in
> +      let ty = typeC ty in
> +      mkres t (Ast0.ParenType(lp,ty,rp)) ty (promote_mcode rp)

The type is not the leftmost thing.  So the third argument should be
(promote_mcode lp).

julia

> +  | Ast0.FunctionType(ty,lp,params,rp) ->
> +      let ty = typeC ty in
> +      let lp = normal_mcode lp in
> +      let params = parameter_list (Some(promote_mcode lp)) params in
> +      let rp = normal_mcode rp in
> +      mkres t (Ast0.FunctionType(ty,lp,params,rp)) ty (promote_mcode rp)
>    | Ast0.Array(ty,lb,size,rb) ->
>        let ty = typeC ty in
>        let lb = normal_mcode lb in
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType
  2020-03-16 10:03 ` [Cocci] [PATCH 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType Jaskaran Singh
@ 2020-03-18 18:45   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 18:45 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> The order of the terms in ParenType require implementing a special
> case for ParenType. This case handles only the following:
>
>         <type> ( * id [ .* ] ) ( params )
>
> i.e., a function pointer or an array of function pointers, and will fail
> for any other cases. This is similar to the function used to print
> ParenType in Pretty_print_c.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/pretty_print_cocci.ml | 57 +++++++++++++++++++++++++++++
>  1 file changed, 57 insertions(+)
>
> diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml
> index 6338e464..ef60106c 100644
> --- a/parsing_cocci/pretty_print_cocci.ml
> +++ b/parsing_cocci/pretty_print_cocci.ml
> @@ -403,6 +403,54 @@ and print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2) fn =
>    mcode print_string rp1; mcode print_string lp1;
>    parameter_list params; mcode print_string rp2
>
> +and print_parentype (lp,ty,rp) fn =
> +  match Ast.unwrap ty with
> +   Ast.Type(_,_,fty1) ->
> +    (match Ast.unwrap fty1 with
> +      Ast.Pointer(ty1,star) ->
> +       (match Ast.unwrap ty1 with
> +         Ast.Type(_,_,fty2) ->
> +          (match Ast.unwrap fty2 with
> +            Ast.FunctionType(ty2,lp2,params,rp2) ->
> +             fullType ty2;
> +             print_space();
> +             mcode print_string lp;
> +             mcode print_string star;
> +             fn();
> +             mcode print_string rp;
> +             mcode print_string lp2;
> +             parameter_list params;
> +             mcode print_string rp2
> +         | _ -> failwith "ParenType Pretty_print_cocci")
> +       | _ -> failwith "ParenType Pretty_print_cocci")
> +    | Ast.Array(ty1,lb1,size1,rb1) ->
> +       (match Ast.unwrap ty1 with
> +         Ast.Type(_,_,fty2) ->
> +          (match Ast.unwrap fty2 with
> +            Ast.Pointer(ty2,star) ->
> +             (match Ast.unwrap ty2 with
> +               Ast.Type(_,_,fty3) ->
> +                (match Ast.unwrap fty3 with
> +                  Ast.FunctionType(ty3,lp3,params,rp3) ->
> +                  fullType ty3;
> +                  print_space();
> +                  mcode print_string lp;
> +                  mcode print_string star;
> +                  fn();
> +                  mcode print_string lb1;
> +                  print_option expression size1;
> +                  mcode print_string rb1;
> +                  mcode print_string rp;
> +                  mcode print_string lp3;
> +                  parameter_list params;
> +                  mcode print_string rp3
> +                | _ -> failwith "ParenType Pretty_print_cocci")
> +             | _ -> failwith "ParenType Pretty_print_cocci")
> +          | _ -> failwith "ParenType Pretty_print_cocci")
> +       | _ -> failwith "ParenType Pretty_print_cocci")
> +    | _ -> failwith "ParenType Pretty_print_cocci")
> +  | _ -> failwith "ParenType Pretty_print_cocci"

Can some code be shared here?

julia

> +
>  and varargs = function
>    | None -> ()
>    | Some (comma, ellipsis) ->
> @@ -424,6 +472,13 @@ and typeC ty =
>    | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>        print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
>  	(function _ -> ())
> +  | Ast.ParenType(lp,ty,rp) ->
> +      print_parentype (lp,ty,rp) (function _ -> ())
> +  | Ast.FunctionType(ty,lp,params,rp) ->
> +      fullType ty;
> +      mcode print_string lp;
> +      parameter_list params;
> +      mcode print_string rp
>    | Ast.Array(ty,lb,size,rb) ->
>        fullType ty; mcode print_string lb; print_option expression size;
>        mcode print_string rb
> @@ -498,6 +553,8 @@ and print_named_type ty id =
>  		| _ -> failwith "complex array types not supported")
>  	    | _ -> typeC ty; id(); k () in
>  	  loop ty1 (function _ -> ())
> +      | Ast.ParenType(lp,ty,rp) ->
> +          print_parentype (lp,ty,rp) (function _ -> id())
>        | _ -> fullType ty; id())
>    | _ -> fullType ty; id()
>
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 22/26] parsing_c: unparse_cocci: Print ParenType/FunctionType
  2020-03-16 10:03 ` [Cocci] [PATCH 22/26] parsing_c: unparse_cocci: " Jaskaran Singh
@ 2020-03-18 18:47   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 18:47 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> The order of the terms in ParenType require implementing a special
> case for ParenType. This case handles only the following:
>
>         <type> ( * id [ .* ] ) ( params )
>
> i.e., a function pointer or an array of function pointers, and will fail
> for any other cases. This is similar to the function used to print
> ParenType in Pretty_print_c.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_c/unparse_cocci.ml | 60 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
>
> diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
> index 30e755e9..9dd84821 100644
> --- a/parsing_c/unparse_cocci.ml
> +++ b/parsing_c/unparse_cocci.ml
> @@ -722,6 +722,13 @@ and typeC ty =
>    | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
>        print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
>  	(function _ -> ())
> +  | Ast.ParenType(lp,ty,rp) ->
> +      print_parentype (lp,ty,rp) (function _ -> ())
> +  | Ast.FunctionType(ty,lp,params,rp) ->
> +      fullType ty;
> +      mcode print_string lp;
> +      parameter_list params;
> +      mcode print_string rp
>    | Ast.Array(ty,lb,size,rb) ->
>        fullType ty; mcode print_string lb; print_option expression size;
>        mcode print_string rb
> @@ -786,6 +793,57 @@ and storage = function
>    | Ast.Register -> print_string "register"
>    | Ast.Extern -> print_string "extern"
>
> +(* --------------------------------------------------------------------- *)
> +(* ParenType *)
> +
> +and print_parentype (lp,ty,rp) fn =
> +  match Ast.unwrap ty with
> +   Ast.Type(_,_,fty1) ->
> +    (match Ast.unwrap fty1 with
> +      Ast.Pointer(ty1,star) ->
> +       (match Ast.unwrap ty1 with
> +         Ast.Type(_,_,fty2) ->
> +          (match Ast.unwrap fty2 with
> +            Ast.FunctionType(ty2,lp2,params,rp2) ->
> +             fullType ty2;
> +             pr_space();
> +             mcode print_string lp;
> +             mcode print_string star;
> +             fn();
> +             mcode print_string rp;
> +             mcode print_string lp2;
> +             parameter_list params;
> +             mcode print_string rp2
> +         | _ -> failwith "ParenType Unparse_cocci")
> +       | _ -> failwith "ParenType Unparse_cocci")
> +    | Ast.Array(ty1,lb1,size1,rb1) ->
> +       (match Ast.unwrap ty1 with
> +         Ast.Type(_,_,fty2) ->
> +          (match Ast.unwrap fty2 with
> +            Ast.Pointer(ty2,star) ->
> +             (match Ast.unwrap ty2 with
> +               Ast.Type(_,_,fty3) ->
> +                (match Ast.unwrap fty3 with
> +                  Ast.FunctionType(ty3,lp3,params,rp3) ->
> +                  fullType ty3;
> +                  pr_space();
> +                  mcode print_string lp;
> +                  mcode print_string star;
> +                  fn();
> +                  mcode print_string lb1;
> +                  print_option expression size1;
> +                  mcode print_string rb1;
> +                  mcode print_string rp;
> +                  mcode print_string lp3;
> +                  parameter_list params;
> +                  mcode print_string rp3
> +                | _ -> failwith "ParenType Unparse_cocci")
> +             | _ -> failwith "ParenType Unparse_cocci")
> +          | _ -> failwith "ParenType Unparse_cocci")
> +       | _ -> failwith "ParenType Unparse_cocci")
> +    | _ -> failwith "ParenType Unparse_cocci")
> +  | _ -> failwith "ParenType Unparse_cocci"

Can some code be shared?

> +
>  (* --------------------------------------------------------------------- *)
>  (* Variable declaration *)
>
> @@ -818,6 +876,8 @@ and print_named_type ty id =
>  		pretty_print_c.Pretty_print_c.type_with_ident ty
>  		  (function _ -> id())
>              | _ -> error name ty "type value expected")
> +      | Ast.ParenType(lp,ty,rp) ->
> +          print_parentype (lp,ty,rp) (function _ -> id())

Is it normal that there is no FunctionType case here?

julia

>      (*| should have a case here for pointer to array or function type
>          that would put ( * ) around the variable.  This makes one wonder
>          why we really need a special case for function pointer *)
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 26/26] tests: Add test case for array of function pointers
  2020-03-16 10:03 ` [Cocci] [PATCH 26/26] tests: Add test case for array of function pointers Jaskaran Singh
@ 2020-03-18 18:48   ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-18 18:48 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 16 Mar 2020, Jaskaran Singh wrote:

> Add a test case to match against an array of function pointers.
> This would previously not work due to differences in the C
> and SmPL ASTs.
>

Thanks for all of the changes in this series!

julia

> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  tests/funptr_array.c     | 1 +
>  tests/funptr_array.cocci | 9 +++++++++
>  tests/funptr_array.res   | 1 +
>  3 files changed, 11 insertions(+)
>  create mode 100644 tests/funptr_array.c
>  create mode 100644 tests/funptr_array.cocci
>  create mode 100644 tests/funptr_array.res
>
> diff --git a/tests/funptr_array.c b/tests/funptr_array.c
> new file mode 100644
> index 00000000..dac29ac6
> --- /dev/null
> +++ b/tests/funptr_array.c
> @@ -0,0 +1 @@
> +int (*x[2])(int x);
> diff --git a/tests/funptr_array.cocci b/tests/funptr_array.cocci
> new file mode 100644
> index 00000000..8027bcf4
> --- /dev/null
> +++ b/tests/funptr_array.cocci
> @@ -0,0 +1,9 @@
> +@@
> +type T;
> +identifier x;
> +@@
> +
> +T (*x[2])(
> +- int
> ++ char
> +  x);
> diff --git a/tests/funptr_array.res b/tests/funptr_array.res
> new file mode 100644
> index 00000000..72e1a14a
> --- /dev/null
> +++ b/tests/funptr_array.res
> @@ -0,0 +1 @@
> +int (*x[2])(char x);
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules
  2020-03-18 17:31   ` Julia Lawall
@ 2020-03-19  5:11     ` Jaskaran Singh
  2020-03-19  7:02       ` Julia Lawall
  0 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-19  5:11 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel-mentees, cocci

On Wed, 2020-03-18 at 18:31 +0100, Julia Lawall wrote:
> 
> On Mon, 16 Mar 2020, Jaskaran Singh wrote:
> 
> > The direct_declarator rule and the direct_abstract_d rule are
> > present in the C parser. Add similar rules to the SmPL parser so
> > that
> > declarators are parsed as they are in the C parser.
> > 
> > For the type ParenType, direct_declarator and direct_abstract_d
> > only
> > allow the following productions:
> > 
> > 	( * id  [ .* ] ) ( params )
> > 
> > i.e. a function pointer or an array of function pointers. The
> > compromise
> > is flexibility in the range of productions, mainly because
> > collateral
> > evolutions needed by having a flexible rule are very large and
> > distasteful.
> 
> It is not clear what is meant by flexible.  Can you give an example
> of
> what will not be supported?
> 

Well, it's mainly anything that uses ParenType for anything other than
a function pointer or an array of function pointers. Examples of
productions that aren't supported:

int (**x[])(params); // array of pointer to function pointer

int (*x[][])(params); // array of array of function pointers

int ((*x))(params); // ident wrapped in double parantheses

To be honest, I think the first two and similar ones (i.e. array of
array of ... pointer to pointer to ....) can be supported by
implementing some kind of loop, but don't know about other
productions.

Cheers,
Jaskaran.

> julia
> 
> > Replace usage of the older d_ident rule in the SmPL parser with the
> > above mentioned rules. All usages of d_ident, however, have not
> > been
> > removed due to reduce/reduce conflicts.
> > 
> > Remove rules/productions that parse function pointers with usage of
> > direct_declarator and direct_abstract_d.
> > 
> > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > ---
> >  parsing_cocci/parser_cocci_menhir.mly | 239 +++++++++++++---------
> > ----
> >  1 file changed, 116 insertions(+), 123 deletions(-)
> > 
> > diff --git a/parsing_cocci/parser_cocci_menhir.mly
> > b/parsing_cocci/parser_cocci_menhir.mly
> > index 26958f63..fade830f 100644
> > --- a/parsing_cocci/parser_cocci_menhir.mly
> > +++ b/parsing_cocci/parser_cocci_menhir.mly
> > @@ -1116,33 +1116,17 @@ struct_decl_one:
> >  	{ let (mids,code) = t in
> >  	Ast0.wrap
> >  	  (Ast0.ConjField(P.id2mcode lp,code,mids, P.id2mcode rp)) }
> > -    | t=ctype d=d_ident_option bf=struct_bitfield? pv=TPtVirg
> > +    | t=ctype d=direct_decl_option(disj_ident) bf=struct_bitfield?
> > pv=TPtVirg
> >  	 { let (id,fn) = d in
> >  	 Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) }
> > -    | t=ctype lp1=TOPar st=TMul d=d_ident_option rp1=TCPar
> > -	lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> > -	bf=struct_bitfield? pv=TPtVirg
> > -        { let (id,fn) = d in
> > -        let t =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > ")" rp1,
> > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > -        Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) }
> > -     | cv=ioption(const_vol) i=pure_ident_or_symbol
> > d=d_ident_option
> > +    | cv=ioption(const_vol) i=pure_ident_or_symbol
> > +      d=direct_decl_option(disj_ident)
> >  	 bf=struct_bitfield?
> >  	 pv=TPtVirg
> >  	 { let (id,fn) = d in
> >  	 let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode
> > i))) in
> >  	 Ast0.wrap(Ast0.Field(fn idtype,id,bf,P.clt2mcode ";" pv)) }
> > 
> > -d_ident_option:
> > -	 { None, (fun x -> x) }
> > -     | d=d_ident {
> > -       let (id, fn) = d in
> > -       (Some id, fn)
> > -    }
> > -
> >  struct_bitfield:
> >     c=TDotDot e=expr { (P.clt2mcode ":" c, e) }
> > 
> > @@ -1529,17 +1513,9 @@ storage:
> >         | s=Tregister    { P.clt2mcode Ast.Register s }
> >         | s=Textern      { P.clt2mcode Ast.Extern s }
> > 
> > -decl: t=ctype i=disj_ident a=list(array_dec)
> > -	{ let t = P.arrayify t a in Ast0.wrap(Ast0.Param(t, Some i)) }
> > +decl: t=ctype d=direct_declarator(disj_ident)
> > +	{ let (i,fn) = d in Ast0.wrap(Ast0.Param(fn t, Some i)) }
> >      | t=ctype { (*verify in FunDecl*) Ast0.wrap(Ast0.Param(t,
> > None)) }
> > -    | t=ctype lp=TOPar s=TMul i=disj_ident rp=TCPar
> > -	lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar
> > -        { let fnptr =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")"
> > rp,
> > -		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
> > -	Ast0.wrap(Ast0.Param(fnptr, Some i)) }
> >      | TMetaParam
> >  	{ let (nm,cstr,pure,clt) = $1 in
> >  	Ast0.wrap(Ast0.MetaParam(P.clt2mcode nm clt,cstr,pure)) }
> > @@ -1547,14 +1523,6 @@ decl: t=ctype i=disj_ident a=list(array_dec)
> > 
> >  name_opt_decl:
> >        decl  { $1 }
> > -    | t=ctype lp=TOPar s=TMul rp=TCPar
> > -	lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar
> > -        { let fnptr =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")"
> > rp,
> > -		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
> > -	Ast0.wrap(Ast0.Param(fnptr, None)) }
> > 
> >  const_vol:
> >        Tconst       { P.clt2mcode Ast.Const $1 }
> > @@ -1684,13 +1652,15 @@ decl_var:
> >      t=ctype pv=TPtVirg
> >        { [Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv))] }
> >    | TMetaDecl { [P.meta_decl $1] }
> > -  | s=ioption(storage) t=ctype d=comma_list(d_ident) pv=TPtVirg
> > +  | s=ioption(storage) t=ctype
> > +      d=comma_list(direct_declarator(disj_ident)) pv=TPtVirg
> >        { List.map
> >  	  (function (id,fn) ->
> >  	    Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv)))
> >  	  d }
> >    | f=funproto { [f] }
> > -  | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq
> > e=initialize
> > +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> > +    a=attr_list q=TEq e=initialize
> >        pv=TPtVirg
> >        {let (id,fn) = d in
> >        [Ast0.wrap
> > @@ -1711,18 +1681,6 @@ decl_var:
> >        let idtype = P.make_cv cv (Ast0.wrap
> > (Ast0.TypeName(P.id2mcode i))) in
> >        [Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
> >  			   P.clt2mcode ";" pv))] }
> > -  /* function pointer type */
> > -  | s=ioption(storage)
> > -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> > -    pv=TPtVirg
> > -      { let (id,fn) = d in
> > -        let t =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > ")" rp1,
> > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > -        [Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv))]
> > }
> >    | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option
> > c=TCPar
> >        p=TPtVirg
> >        { [Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e,
> > @@ -1735,56 +1693,25 @@ decl_var:
> >  	       (s,d,P.clt2mcode "(" o,e,
> >  		P.clt2mcode ")" c,P.clt2mcode "=" q,i,
> >  		P.clt2mcode ";" p))] }
> > -  | s=ioption(storage)
> > -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> > -    q=TEq e=initialize pv=TPtVirg
> > -      { let (id,fn) = d in
> > -        let t =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > ")" rp1,
> > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > -      [Ast0.wrap
> > -	  (Ast0.Init(s,fn t,id,[],P.clt2mcode "=" q,e,P.clt2mcode ";"
> > pv))]}
> > -  | s=Ttypedef t=typedef_ctype id=comma_list(typedef_ident)
> > pv=TPtVirg
> > +  | s=Ttypedef t=typedef_ctype
> > +      d=comma_list(direct_declarator(typedef_ident)) pv=TPtVirg
> >        { let s = P.clt2mcode "typedef" s in
> >          List.map
> > -	  (function id ->
> > -	    Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv)))
> > -	  id }
> > -  | s=Ttypedef t=typedef_ctype id=typedef_ident
> > -      l=TOCro i=eexpr r=TCCro pv=TPtVirg
> > -      { let s = P.clt2mcode "typedef" s in
> > -        let t = P.arrayify t [(l,Some i,r)] in
> > -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))] }
> > -  | s=Ttypedef t=typedef_ctype id=typedef_ident
> > -      l=TOCro i=eexpr r=TCCro
> > -      l2=TOCro i2=eexpr r2=TCCro pv=TPtVirg
> > -      { let s = P.clt2mcode "typedef" s in
> > -        let t = P.arrayify t [(l,Some i,r)] in
> > -        let t = P.arrayify t [(l2,Some i2,r2)] in
> > -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))] }
> > -  | s=Ttypedef
> > -    t=typedef_ctype lp1=TOPar st=TMul id=typedef_ident rp1=TCPar
> > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar pv=TPtVirg
> > -      { let s = P.clt2mcode "typedef" s in
> > -        let t =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > ")" rp1,
> > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))]}
> > +	  (function (id,fn) ->
> > +	    Ast0.wrap(Ast0.Typedef(s,fn t,id,P.clt2mcode ";" pv)))
> > +	  d }
> > 
> >  one_decl_var:
> >      t=ctype pv=TPtVirg
> >        { Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv)) }
> >    | TMetaDecl { P.meta_decl $1 }
> > -  | s=ioption(storage) t=ctype d=d_ident a=attr_list pv=TPtVirg
> > +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> > +      a=attr_list pv=TPtVirg
> >        { let (id,fn) = d in
> >          Ast0.wrap(Ast0.UnInit(s,fn t,id,a,P.clt2mcode ";" pv)) }
> >    | f=funproto { f }
> > -  | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq
> > e=initialize
> > +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> > +      a=attr_list q=TEq e=initialize
> >        pv=TPtVirg
> >        { let (id,fn) = d in
> >        Ast0.wrap
> > @@ -1802,18 +1729,6 @@ one_decl_var:
> >        let idtype = P.make_cv cv (Ast0.wrap
> > (Ast0.TypeName(P.id2mcode i))) in
> >        Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
> >  			   P.clt2mcode ";" pv)) }
> > -  /* function pointer type */
> > -  | s=ioption(storage)
> > -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> > -    pv=TPtVirg
> > -      { let (id,fn) = d in
> > -        let t =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > ")" rp1,
> > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > -        Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv)) }
> >    | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option
> > c=TCPar
> >        p=TPtVirg
> >        { Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e,
> > @@ -1826,19 +1741,103 @@ one_decl_var:
> >                 (s,d,P.clt2mcode "(" o,e,
> >                  P.clt2mcode ")" c,P.clt2mcode "=" q,i,
> >                  P.clt2mcode ";" p)) }
> > -  | s=ioption(storage)
> > -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar a=attr_list
> > -    q=TEq e=initialize pv=TPtVirg
> > -      { let (id,fn) = d in
> > -        let t =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > ")" rp1,
> > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > -      Ast0.wrap(Ast0.Init(s,fn t,id,a,P.clt2mcode "="
> > q,e,P.clt2mcode ";" pv))}
> > 
> > 
> > +direct_declarator(ident_type):
> > +    ident_type
> > +      { ($1, function x -> x) }
> > +  | o=TOPar m=list(TMul) d=direct_declarator(ident_type) c=TCPar
> > +      { let (id,fn) = d in
> > +        (id,
> > +         function t ->
> > +          let ty =  fn (P.pointerify t m) in
> > +          let _ =
> > +           match Ast0.unwrap ty with
> > +            Ast0.Pointer(ty1,_) ->
> > +             (match Ast0.unwrap ty1 with
> > +               Ast0.FunctionType(ty2,_,_,_) -> ()
> > +             | _ ->
> > +              raise (Semantic_cocci.Semantic "expected function
> > pointer"))
> > +           | Ast0.Array(ty1,_,_,_) ->
> > +              (match Ast0.unwrap ty1 with
> > +                Ast0.Pointer(ty2,_) ->(
> > +                 match Ast0.unwrap ty2 with
> > +                  Ast0.FunctionType(ty3,_,_,_) -> ()
> > +                 | _ ->
> > +                  raise (Semantic_cocci.Semantic "expected
> > function pointer"))
> > +             | _ ->
> > +              raise (Semantic_cocci.Semantic "expected function
> > pointer"))
> > +           | _ ->
> > +            raise (Semantic_cocci.Semantic "expected function
> > pointer") in
> > +          Ast0.wrap
> > +            (Ast0.ParenType
> > +               (P.clt2mcode "(" o,
> > +                ty,
> > +                P.clt2mcode ")" c))) }
> > +  | d=direct_declarator(ident_type) a=array_dec
> > +      { let (id,fn) = d in
> > +        (id, function t -> let r = P.arrayify t [a] in fn r) }
> > +  | d=direct_declarator(ident_type)
> > +      o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
> > +      { let (id,fn) = d in
> > +        (id, function t ->
> > +              let r =
> > +               Ast0.wrap
> > +                (Ast0.FunctionType
> > +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c))
> > in fn r) }
> > +
> > +
> > +direct_abstract_d:
> > +    o=TOPar m=list(TMul) d=direct_abstract_d c=TCPar
> > +      { function t ->
> > +          let ty = d (P.pointerify t m) in
> > +          let _ =
> > +           match Ast0.unwrap ty with
> > +            Ast0.Pointer(ty1,_) ->
> > +             (match Ast0.unwrap ty1 with
> > +               Ast0.FunctionType(ty2,_,_,_) ->()
> > +             | _ ->
> > +              raise (Semantic_cocci.Semantic "expected function
> > pointer"))
> > +           | Ast0.Array(ty1,_,_,_) ->
> > +              (match Ast0.unwrap ty1 with
> > +                Ast0.Pointer(ty2,_) ->(
> > +                 match Ast0.unwrap ty2 with
> > +                  Ast0.FunctionType(ty3,_,_,_) -> ()
> > +                 | _ ->
> > +                  raise (Semantic_cocci.Semantic "expected
> > function pointer"))
> > +             | _ ->
> > +              raise (Semantic_cocci.Semantic "expected function
> > pointer"))
> > +           | _ ->
> > +            raise (Semantic_cocci.Semantic "expected function
> > pointer") in
> > +          Ast0.wrap
> > +            (Ast0.ParenType
> > +               (P.clt2mcode "(" o,
> > +                ty,
> > +                P.clt2mcode ")" c))
> > +      }
> > +  | a=array_dec
> > +      { function t -> P.arrayify t [a] }
> > +  | d=direct_abstract_d a=array_dec
> > +      { function t -> let r = P.arrayify t [a] in d r }
> > +  | o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
> > +      { function t ->
> > +               Ast0.wrap
> > +                (Ast0.FunctionType
> > +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c))
> > }
> > +  | d=direct_abstract_d o=TOPar arglist=decl_list(name_opt_decl)
> > c=TCPar
> > +      { function t ->
> > +              let r =
> > +               Ast0.wrap
> > +                (Ast0.FunctionType
> > +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c))
> > in d r }
> > +
> > +
> > +direct_decl_option(ident_type):
> > +      { (None, function x -> x) }
> > +  | d=direct_declarator(ident_type)
> > +      { let (id,fn) = d in
> > +        (Some id, fn) }
> > +
> >  d_ident:
> >      disj_ident list(array_dec)
> >        { ($1, function t -> P.arrayify t $2) }
> > @@ -2151,16 +2150,10 @@ cast_expr(r,pe):
> >      unary_expr(r,pe)                      { $1 }
> >    | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe)
> >        { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t,
> > +                             P.clt2mcode ")" rp, e)) }
> > +  | lp=TOPar t=ctype d=direct_abstract_d rp=TCPar
> > e=cast_expr(r,pe)
> > +      { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t,
> >  			     P.clt2mcode ")" rp, e)) }
> > -  | lp=TOPar t=ctype lp1=TOPar s=TMul rp1=TCPar
> > -      lp2=TOPar d=decl_list(name_opt_decl) rp2=TCPar rp=TCPar
> > -      e=cast_expr(r,pe)
> > -      { let fnptr =
> > -	  Ast0.wrap
> > -	    (Ast0.FunctionPointer
> > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" s,P.clt2mcode ")"
> > rp1,
> > -		P.clt2mcode "(" lp2,d,P.clt2mcode ")" rp2)) in
> > -      Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, fnptr, P.clt2mcode
> > ")" rp, e)) }
> > 
> >  unary_expr(r,pe):
> >      postfix_expr(r,pe)                   { $1 }
> > --
> > 2.21.1
> > 
> > 

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

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

* Re: [Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules
  2020-03-19  5:11     ` Jaskaran Singh
@ 2020-03-19  7:02       ` Julia Lawall
  0 siblings, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-19  7:02 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Thu, 19 Mar 2020, Jaskaran Singh wrote:

> On Wed, 2020-03-18 at 18:31 +0100, Julia Lawall wrote:
> >
> > On Mon, 16 Mar 2020, Jaskaran Singh wrote:
> >
> > > The direct_declarator rule and the direct_abstract_d rule are
> > > present in the C parser. Add similar rules to the SmPL parser so
> > > that
> > > declarators are parsed as they are in the C parser.
> > >
> > > For the type ParenType, direct_declarator and direct_abstract_d
> > > only
> > > allow the following productions:
> > >
> > > 	( * id  [ .* ] ) ( params )
> > >
> > > i.e. a function pointer or an array of function pointers. The
> > > compromise
> > > is flexibility in the range of productions, mainly because
> > > collateral
> > > evolutions needed by having a flexible rule are very large and
> > > distasteful.
> >
> > It is not clear what is meant by flexible.  Can you give an example
> > of
> > what will not be supported?
> >
>
> Well, it's mainly anything that uses ParenType for anything other than
> a function pointer or an array of function pointers. Examples of
> productions that aren't supported:
>
> int (**x[])(params); // array of pointer to function pointer
>
> int (*x[][])(params); // array of array of function pointers
>
> int ((*x))(params); // ident wrapped in double parantheses
>
> To be honest, I think the first two and similar ones (i.e. array of
> array of ... pointer to pointer to ....) can be supported by
> implementing some kind of loop, but don't know about other
> productions.

OK.  You could add these to the log message for future reference.  The
double parentheses seem like a low priority.  Perhaps the first two could
be useful at some point.

thanks,
julia


>
> Cheers,
> Jaskaran.
>
> > julia
> >
> > > Replace usage of the older d_ident rule in the SmPL parser with the
> > > above mentioned rules. All usages of d_ident, however, have not
> > > been
> > > removed due to reduce/reduce conflicts.
> > >
> > > Remove rules/productions that parse function pointers with usage of
> > > direct_declarator and direct_abstract_d.
> > >
> > > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > > ---
> > >  parsing_cocci/parser_cocci_menhir.mly | 239 +++++++++++++---------
> > > ----
> > >  1 file changed, 116 insertions(+), 123 deletions(-)
> > >
> > > diff --git a/parsing_cocci/parser_cocci_menhir.mly
> > > b/parsing_cocci/parser_cocci_menhir.mly
> > > index 26958f63..fade830f 100644
> > > --- a/parsing_cocci/parser_cocci_menhir.mly
> > > +++ b/parsing_cocci/parser_cocci_menhir.mly
> > > @@ -1116,33 +1116,17 @@ struct_decl_one:
> > >  	{ let (mids,code) = t in
> > >  	Ast0.wrap
> > >  	  (Ast0.ConjField(P.id2mcode lp,code,mids, P.id2mcode rp)) }
> > > -    | t=ctype d=d_ident_option bf=struct_bitfield? pv=TPtVirg
> > > +    | t=ctype d=direct_decl_option(disj_ident) bf=struct_bitfield?
> > > pv=TPtVirg
> > >  	 { let (id,fn) = d in
> > >  	 Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) }
> > > -    | t=ctype lp1=TOPar st=TMul d=d_ident_option rp1=TCPar
> > > -	lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> > > -	bf=struct_bitfield? pv=TPtVirg
> > > -        { let (id,fn) = d in
> > > -        let t =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > > ")" rp1,
> > > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > > -        Ast0.wrap(Ast0.Field(fn t,id,bf,P.clt2mcode ";" pv)) }
> > > -     | cv=ioption(const_vol) i=pure_ident_or_symbol
> > > d=d_ident_option
> > > +    | cv=ioption(const_vol) i=pure_ident_or_symbol
> > > +      d=direct_decl_option(disj_ident)
> > >  	 bf=struct_bitfield?
> > >  	 pv=TPtVirg
> > >  	 { let (id,fn) = d in
> > >  	 let idtype = P.make_cv cv (Ast0.wrap (Ast0.TypeName(P.id2mcode
> > > i))) in
> > >  	 Ast0.wrap(Ast0.Field(fn idtype,id,bf,P.clt2mcode ";" pv)) }
> > >
> > > -d_ident_option:
> > > -	 { None, (fun x -> x) }
> > > -     | d=d_ident {
> > > -       let (id, fn) = d in
> > > -       (Some id, fn)
> > > -    }
> > > -
> > >  struct_bitfield:
> > >     c=TDotDot e=expr { (P.clt2mcode ":" c, e) }
> > >
> > > @@ -1529,17 +1513,9 @@ storage:
> > >         | s=Tregister    { P.clt2mcode Ast.Register s }
> > >         | s=Textern      { P.clt2mcode Ast.Extern s }
> > >
> > > -decl: t=ctype i=disj_ident a=list(array_dec)
> > > -	{ let t = P.arrayify t a in Ast0.wrap(Ast0.Param(t, Some i)) }
> > > +decl: t=ctype d=direct_declarator(disj_ident)
> > > +	{ let (i,fn) = d in Ast0.wrap(Ast0.Param(fn t, Some i)) }
> > >      | t=ctype { (*verify in FunDecl*) Ast0.wrap(Ast0.Param(t,
> > > None)) }
> > > -    | t=ctype lp=TOPar s=TMul i=disj_ident rp=TCPar
> > > -	lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar
> > > -        { let fnptr =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")"
> > > rp,
> > > -		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
> > > -	Ast0.wrap(Ast0.Param(fnptr, Some i)) }
> > >      | TMetaParam
> > >  	{ let (nm,cstr,pure,clt) = $1 in
> > >  	Ast0.wrap(Ast0.MetaParam(P.clt2mcode nm clt,cstr,pure)) }
> > > @@ -1547,14 +1523,6 @@ decl: t=ctype i=disj_ident a=list(array_dec)
> > >
> > >  name_opt_decl:
> > >        decl  { $1 }
> > > -    | t=ctype lp=TOPar s=TMul rp=TCPar
> > > -	lp1=TOPar d=decl_list(name_opt_decl) rp1=TCPar
> > > -        { let fnptr =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp,P.clt2mcode "*" s,P.clt2mcode ")"
> > > rp,
> > > -		P.clt2mcode "(" lp1,d,P.clt2mcode ")" rp1)) in
> > > -	Ast0.wrap(Ast0.Param(fnptr, None)) }
> > >
> > >  const_vol:
> > >        Tconst       { P.clt2mcode Ast.Const $1 }
> > > @@ -1684,13 +1652,15 @@ decl_var:
> > >      t=ctype pv=TPtVirg
> > >        { [Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv))] }
> > >    | TMetaDecl { [P.meta_decl $1] }
> > > -  | s=ioption(storage) t=ctype d=comma_list(d_ident) pv=TPtVirg
> > > +  | s=ioption(storage) t=ctype
> > > +      d=comma_list(direct_declarator(disj_ident)) pv=TPtVirg
> > >        { List.map
> > >  	  (function (id,fn) ->
> > >  	    Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv)))
> > >  	  d }
> > >    | f=funproto { [f] }
> > > -  | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq
> > > e=initialize
> > > +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> > > +    a=attr_list q=TEq e=initialize
> > >        pv=TPtVirg
> > >        {let (id,fn) = d in
> > >        [Ast0.wrap
> > > @@ -1711,18 +1681,6 @@ decl_var:
> > >        let idtype = P.make_cv cv (Ast0.wrap
> > > (Ast0.TypeName(P.id2mcode i))) in
> > >        [Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
> > >  			   P.clt2mcode ";" pv))] }
> > > -  /* function pointer type */
> > > -  | s=ioption(storage)
> > > -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> > > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> > > -    pv=TPtVirg
> > > -      { let (id,fn) = d in
> > > -        let t =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > > ")" rp1,
> > > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > > -        [Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv))]
> > > }
> > >    | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option
> > > c=TCPar
> > >        p=TPtVirg
> > >        { [Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e,
> > > @@ -1735,56 +1693,25 @@ decl_var:
> > >  	       (s,d,P.clt2mcode "(" o,e,
> > >  		P.clt2mcode ")" c,P.clt2mcode "=" q,i,
> > >  		P.clt2mcode ";" p))] }
> > > -  | s=ioption(storage)
> > > -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> > > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> > > -    q=TEq e=initialize pv=TPtVirg
> > > -      { let (id,fn) = d in
> > > -        let t =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > > ")" rp1,
> > > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > > -      [Ast0.wrap
> > > -	  (Ast0.Init(s,fn t,id,[],P.clt2mcode "=" q,e,P.clt2mcode ";"
> > > pv))]}
> > > -  | s=Ttypedef t=typedef_ctype id=comma_list(typedef_ident)
> > > pv=TPtVirg
> > > +  | s=Ttypedef t=typedef_ctype
> > > +      d=comma_list(direct_declarator(typedef_ident)) pv=TPtVirg
> > >        { let s = P.clt2mcode "typedef" s in
> > >          List.map
> > > -	  (function id ->
> > > -	    Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv)))
> > > -	  id }
> > > -  | s=Ttypedef t=typedef_ctype id=typedef_ident
> > > -      l=TOCro i=eexpr r=TCCro pv=TPtVirg
> > > -      { let s = P.clt2mcode "typedef" s in
> > > -        let t = P.arrayify t [(l,Some i,r)] in
> > > -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))] }
> > > -  | s=Ttypedef t=typedef_ctype id=typedef_ident
> > > -      l=TOCro i=eexpr r=TCCro
> > > -      l2=TOCro i2=eexpr r2=TCCro pv=TPtVirg
> > > -      { let s = P.clt2mcode "typedef" s in
> > > -        let t = P.arrayify t [(l,Some i,r)] in
> > > -        let t = P.arrayify t [(l2,Some i2,r2)] in
> > > -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))] }
> > > -  | s=Ttypedef
> > > -    t=typedef_ctype lp1=TOPar st=TMul id=typedef_ident rp1=TCPar
> > > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar pv=TPtVirg
> > > -      { let s = P.clt2mcode "typedef" s in
> > > -        let t =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > > ")" rp1,
> > > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > > -	[Ast0.wrap(Ast0.Typedef(s,t,id,P.clt2mcode ";" pv))]}
> > > +	  (function (id,fn) ->
> > > +	    Ast0.wrap(Ast0.Typedef(s,fn t,id,P.clt2mcode ";" pv)))
> > > +	  d }
> > >
> > >  one_decl_var:
> > >      t=ctype pv=TPtVirg
> > >        { Ast0.wrap(Ast0.TyDecl(t,P.clt2mcode ";" pv)) }
> > >    | TMetaDecl { P.meta_decl $1 }
> > > -  | s=ioption(storage) t=ctype d=d_ident a=attr_list pv=TPtVirg
> > > +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> > > +      a=attr_list pv=TPtVirg
> > >        { let (id,fn) = d in
> > >          Ast0.wrap(Ast0.UnInit(s,fn t,id,a,P.clt2mcode ";" pv)) }
> > >    | f=funproto { f }
> > > -  | s=ioption(storage) t=ctype d=d_ident a=attr_list q=TEq
> > > e=initialize
> > > +  | s=ioption(storage) t=ctype d=direct_declarator(disj_ident)
> > > +      a=attr_list q=TEq e=initialize
> > >        pv=TPtVirg
> > >        { let (id,fn) = d in
> > >        Ast0.wrap
> > > @@ -1802,18 +1729,6 @@ one_decl_var:
> > >        let idtype = P.make_cv cv (Ast0.wrap
> > > (Ast0.TypeName(P.id2mcode i))) in
> > >        Ast0.wrap(Ast0.Init(s,fn idtype,id,a,P.clt2mcode "=" q,e,
> > >  			   P.clt2mcode ";" pv)) }
> > > -  /* function pointer type */
> > > -  | s=ioption(storage)
> > > -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> > > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar
> > > -    pv=TPtVirg
> > > -      { let (id,fn) = d in
> > > -        let t =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > > ")" rp1,
> > > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > > -        Ast0.wrap(Ast0.UnInit(s,fn t,id,[],P.clt2mcode ";" pv)) }
> > >    | s=ioption(storage) d=decl_ident o=TOPar e=eexpr_list_option
> > > c=TCPar
> > >        p=TPtVirg
> > >        { Ast0.wrap(Ast0.MacroDecl(s,d,P.clt2mcode "(" o,e,
> > > @@ -1826,19 +1741,103 @@ one_decl_var:
> > >                 (s,d,P.clt2mcode "(" o,e,
> > >                  P.clt2mcode ")" c,P.clt2mcode "=" q,i,
> > >                  P.clt2mcode ";" p)) }
> > > -  | s=ioption(storage)
> > > -    t=ctype lp1=TOPar st=TMul d=d_ident rp1=TCPar
> > > -    lp2=TOPar p=decl_list(name_opt_decl) rp2=TCPar a=attr_list
> > > -    q=TEq e=initialize pv=TPtVirg
> > > -      { let (id,fn) = d in
> > > -        let t =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" st,P.clt2mcode
> > > ")" rp1,
> > > -		P.clt2mcode "(" lp2,p,P.clt2mcode ")" rp2)) in
> > > -      Ast0.wrap(Ast0.Init(s,fn t,id,a,P.clt2mcode "="
> > > q,e,P.clt2mcode ";" pv))}
> > >
> > >
> > > +direct_declarator(ident_type):
> > > +    ident_type
> > > +      { ($1, function x -> x) }
> > > +  | o=TOPar m=list(TMul) d=direct_declarator(ident_type) c=TCPar
> > > +      { let (id,fn) = d in
> > > +        (id,
> > > +         function t ->
> > > +          let ty =  fn (P.pointerify t m) in
> > > +          let _ =
> > > +           match Ast0.unwrap ty with
> > > +            Ast0.Pointer(ty1,_) ->
> > > +             (match Ast0.unwrap ty1 with
> > > +               Ast0.FunctionType(ty2,_,_,_) -> ()
> > > +             | _ ->
> > > +              raise (Semantic_cocci.Semantic "expected function
> > > pointer"))
> > > +           | Ast0.Array(ty1,_,_,_) ->
> > > +              (match Ast0.unwrap ty1 with
> > > +                Ast0.Pointer(ty2,_) ->(
> > > +                 match Ast0.unwrap ty2 with
> > > +                  Ast0.FunctionType(ty3,_,_,_) -> ()
> > > +                 | _ ->
> > > +                  raise (Semantic_cocci.Semantic "expected
> > > function pointer"))
> > > +             | _ ->
> > > +              raise (Semantic_cocci.Semantic "expected function
> > > pointer"))
> > > +           | _ ->
> > > +            raise (Semantic_cocci.Semantic "expected function
> > > pointer") in
> > > +          Ast0.wrap
> > > +            (Ast0.ParenType
> > > +               (P.clt2mcode "(" o,
> > > +                ty,
> > > +                P.clt2mcode ")" c))) }
> > > +  | d=direct_declarator(ident_type) a=array_dec
> > > +      { let (id,fn) = d in
> > > +        (id, function t -> let r = P.arrayify t [a] in fn r) }
> > > +  | d=direct_declarator(ident_type)
> > > +      o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
> > > +      { let (id,fn) = d in
> > > +        (id, function t ->
> > > +              let r =
> > > +               Ast0.wrap
> > > +                (Ast0.FunctionType
> > > +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c))
> > > in fn r) }
> > > +
> > > +
> > > +direct_abstract_d:
> > > +    o=TOPar m=list(TMul) d=direct_abstract_d c=TCPar
> > > +      { function t ->
> > > +          let ty = d (P.pointerify t m) in
> > > +          let _ =
> > > +           match Ast0.unwrap ty with
> > > +            Ast0.Pointer(ty1,_) ->
> > > +             (match Ast0.unwrap ty1 with
> > > +               Ast0.FunctionType(ty2,_,_,_) ->()
> > > +             | _ ->
> > > +              raise (Semantic_cocci.Semantic "expected function
> > > pointer"))
> > > +           | Ast0.Array(ty1,_,_,_) ->
> > > +              (match Ast0.unwrap ty1 with
> > > +                Ast0.Pointer(ty2,_) ->(
> > > +                 match Ast0.unwrap ty2 with
> > > +                  Ast0.FunctionType(ty3,_,_,_) -> ()
> > > +                 | _ ->
> > > +                  raise (Semantic_cocci.Semantic "expected
> > > function pointer"))
> > > +             | _ ->
> > > +              raise (Semantic_cocci.Semantic "expected function
> > > pointer"))
> > > +           | _ ->
> > > +            raise (Semantic_cocci.Semantic "expected function
> > > pointer") in
> > > +          Ast0.wrap
> > > +            (Ast0.ParenType
> > > +               (P.clt2mcode "(" o,
> > > +                ty,
> > > +                P.clt2mcode ")" c))
> > > +      }
> > > +  | a=array_dec
> > > +      { function t -> P.arrayify t [a] }
> > > +  | d=direct_abstract_d a=array_dec
> > > +      { function t -> let r = P.arrayify t [a] in d r }
> > > +  | o=TOPar arglist=decl_list(name_opt_decl) c=TCPar
> > > +      { function t ->
> > > +               Ast0.wrap
> > > +                (Ast0.FunctionType
> > > +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c))
> > > }
> > > +  | d=direct_abstract_d o=TOPar arglist=decl_list(name_opt_decl)
> > > c=TCPar
> > > +      { function t ->
> > > +              let r =
> > > +               Ast0.wrap
> > > +                (Ast0.FunctionType
> > > +                  (t,P.clt2mcode "(" o,arglist,P.clt2mcode ")" c))
> > > in d r }
> > > +
> > > +
> > > +direct_decl_option(ident_type):
> > > +      { (None, function x -> x) }
> > > +  | d=direct_declarator(ident_type)
> > > +      { let (id,fn) = d in
> > > +        (Some id, fn) }
> > > +
> > >  d_ident:
> > >      disj_ident list(array_dec)
> > >        { ($1, function t -> P.arrayify t $2) }
> > > @@ -2151,16 +2150,10 @@ cast_expr(r,pe):
> > >      unary_expr(r,pe)                      { $1 }
> > >    | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe)
> > >        { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t,
> > > +                             P.clt2mcode ")" rp, e)) }
> > > +  | lp=TOPar t=ctype d=direct_abstract_d rp=TCPar
> > > e=cast_expr(r,pe)
> > > +      { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t,
> > >  			     P.clt2mcode ")" rp, e)) }
> > > -  | lp=TOPar t=ctype lp1=TOPar s=TMul rp1=TCPar
> > > -      lp2=TOPar d=decl_list(name_opt_decl) rp2=TCPar rp=TCPar
> > > -      e=cast_expr(r,pe)
> > > -      { let fnptr =
> > > -	  Ast0.wrap
> > > -	    (Ast0.FunctionPointer
> > > -	       (t,P.clt2mcode "(" lp1,P.clt2mcode "*" s,P.clt2mcode ")"
> > > rp1,
> > > -		P.clt2mcode "(" lp2,d,P.clt2mcode ")" rp2)) in
> > > -      Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, fnptr, P.clt2mcode
> > > ")" rp, e)) }
> > >
> > >  unary_expr(r,pe):
> > >      postfix_expr(r,pe)                   { $1 }
> > > --
> > > 2.21.1
> > >
> > >
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
  2020-03-18 17:25   ` Julia Lawall
@ 2020-03-19 13:58     ` Jaskaran Singh
  2020-03-19 15:54       ` Julia Lawall
  0 siblings, 1 reply; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-19 13:58 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel-mentees, cocci

On Wed, 2020-03-18 at 18:25 +0100, Julia Lawall wrote:
> 
> On Mon, 16 Mar 2020, Jaskaran Singh wrote:
> 
> > To add the types ParenType and FunctionType to the SmPL AST, a
> > reduce/reduce conflict with the funproto rule of the SmPL parser
> > must be resolved. This requires explicitly identifying a function
> > prototype by use of a token (TFunProto).
> > 
> > While the correct method of identifying a function prototype would
> > be to
> > check if an identifier is preceded by a return type, it is
> > challenging
> > to implement. This is because implementing an OCaml function, to
> > correctly determine a C type in SmPL, without the aid of Yacc,
> > would
> > have to handle a number of cases (disjunctions, typeof expressions,
> > etc.).
> > 
> > Thus, a slightly hacky approach is taken to determine a function
> > prototype with not the best certainty but what works for most cases
> > in SmPL. If the identifier is preceded by any token that does not
> > seem to be part of a type, then it is not identified as a function
> > prototype. Else, it is.
> 
> This sacrifices the test case tests/p1p2.cocci:
> 

What do you mean by sacrifice?

The test case seems to work, but not with just 01 applied. Here's what
the debugger tells me about the AST:

Ast_cocci.FunProto
([Ast_cocci.FType
   {Ast_cocci.node =
     Ast_cocci.Type (false, None,
      {Ast_cocci.node =
        Ast_cocci.MetaType
         ((("rule starting on line 11", "T"),
           {Ast_cocci.line = 18; column = 1;
            strbef = []; straft = [];
            whitespace = " "},
           Ast_cocci.CONTEXT (Ast_cocci.NoPos,
            Ast_cocci.AFTER
             ([[Ast_cocci.Directive
                 [Ast_cocci.Space
                   "__attribute__((nonnull(2)))"]]],
             Ast_cocci.ONE)),
           []),

Maybe after the grammar changes, Menhir does some kind of lookahead?
I'm not sure.

Cheers,
Jaskaran.

> @@
> typedef Error;
> type T;
> identifier FN;
> parameter P1;
> @@
>  T
> +__attribute__((nonnull(1)))
>  FN(P1, Error **errp);
> 
> @@
> typedef Error;
> type T;
> identifier FN;
> parameter P1;
> parameter P2;
> @@
>  T
> +__attribute__((nonnull(2)))
>  FN(P1, P2, Error **errp);
> 
> Normally, the only way that you can have a ) before a function call
> is
> when there is a cast.  But hopefully in that case there would not be
> two
> )) before the function call.  Can that get around the problem?
> 
> julia
> 
> 
> 
> 
> > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > ---
> >  parsing_cocci/parse_cocci.ml          | 72
> > +++++++++++++++++++++++----
> >  parsing_cocci/parser_cocci_menhir.mly |  9 ++--
> >  2 files changed, 67 insertions(+), 14 deletions(-)
> > 
> > diff --git a/parsing_cocci/parse_cocci.ml
> > b/parsing_cocci/parse_cocci.ml
> > index 679d213a..4b2cb7e4 100644
> > --- a/parsing_cocci/parse_cocci.ml
> > +++ b/parsing_cocci/parse_cocci.ml
> > @@ -295,6 +295,7 @@ let token2c (tok,_) add_clt =
> >    | PC.TLineEnd(clt) -> "line end"
> >    | PC.TInvalid -> "invalid"
> >    | PC.TFunDecl(clt) -> "fundecl"
> > +  | PC.TFunProto(clt) -> "funproto"
> > 
> >    | PC.TIso -> "<=>"
> >    | PC.TRightIso -> "=>"
> > @@ -480,7 +481,7 @@ let get_clt (tok,_) =
> > 
> >    | PC.TOPar0(_,clt) | PC.TMid0(_,clt) | PC.TAnd0(_,clt) |
> > PC.TCPar0(_,clt)
> >    | PC.TOEllipsis(clt) | PC.TCEllipsis(clt)
> > -  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt)
> > +  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) | PC.TFunProto(clt)
> >    | PC.TFunDecl(clt) | PC.TDirective(_,clt) | PC.TAttr_(clt)
> >    | PC.TLineEnd(clt) -> clt
> >    | PC.TVAEllipsis(clt) -> clt
> > @@ -718,6 +719,7 @@ let update_clt (tok,x) clt =
> > 
> >    | PC.TLineEnd(_) -> (PC.TLineEnd(clt),x)
> >    | PC.TFunDecl(_) -> (PC.TFunDecl(clt),x)
> > +  | PC.TFunProto(_) -> (PC.TFunProto(clt),x)
> >    | PC.TTildeExclEq(_) -> (PC.TTildeExclEq(clt),x)
> >    | PC.TDirective(a,_) -> (PC.TDirective(a,clt),x)
> >    | PC.TAttr_(_) -> (PC.TAttr_(clt),x)
> > @@ -925,7 +927,7 @@ let split_token ((tok,_) as t) =
> >    | PC.TInitialize | PC.TFinalize -> ([t],[t])
> >    | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt)
> > -> split t clt
> > 
> > -  | PC.TFunDecl(clt)
> > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TLineEnd(clt)
> >    | PC.TEllipsis(clt)
> > @@ -1006,7 +1008,8 @@ let find_function_names l =
> >      | _ -> false in
> >    let rec split acc = function
> >        [] | [_] -> raise Irrelevant
> > -    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest
> > ->
> > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest
> > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TPtVirg(_),_) as t2) :: rest
> > ->
> >  	(List.rev (t1::acc),(t2::rest))
> >      | x::xs -> split (x::acc) xs in
> >    let rec balanced_name level = function
> > @@ -1037,7 +1040,48 @@ let find_function_names l =
> >      | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_ ->
> >  	raise Irrelevant
> >      | t::rest -> balanced_args level rest in
> > -  let rec loop = function
> > +  let rec is_permissible_proto = function
> > +      [] -> false
> > +    | (PC.TCPar0(_),_)::
> > +      ((PC.TMid0(_),_) | (PC.TAnd0(_),_))::
> > +      (PC.TOPar0(_),_)::_ -> false
> > +    | (PC.TOPar0(_),_)::rest
> > +    | (PC.TCPar0(_),_)::rest -> is_permissible_proto rest
> > +    | x::rest when is_mid x ->
> > +        let rec loop = function
> > +          [] -> false
> > +        | (PC.TOPar0(_),_)::xs -> is_permissible_proto xs
> > +        | x::xs -> loop xs in
> > +        loop rest
> > +    | _::((PC.TEq(_),_) | (PC.TNotEq(_),_))::(PC.TWhen(_),_)::_
> > +    | _::(PC.TWhen(_),_)::_
> > +    | (PC.TComma(_),_)::_
> > +    | (PC.TDirective(_),_)::_
> > +    | (PC.TElse(_),_)::_
> > +    | (PC.TReturn(_),_)::_
> > +    | (PC.TMetaStm(_),_)::_
> > +    | (PC.TMetaExp(_),_)::_
> > +    | (PC.TMetaId(_),_)::_
> > +    | (PC.TMetaLocalIdExp(_),_)::_
> > +    | (PC.TEq(_),_)::_
> > +    | (PC.TEllipsis(_),_)::_
> > +    | (PC.TOEllipsis(_),_)::_
> > +    | (PC.TCEllipsis(_),_)::_
> > +    | (PC.TPOEllipsis(_),_)::_
> > +    | (PC.TPCEllipsis(_),_)::_
> > +    | (PC.TPtVirg(_),_)::_
> > +    | (PC.TOBrace(_),_)::_
> > +    | (PC.TCBrace(_),_)::_
> > +    | (PC.TOPar(_),_)::_
> > +    | (PC.TCPar(_),_)::_
> > +    | (PC.TIdent(_),_)::_ -> false
> > +    | _ -> true in
> > +  let decl_or_proto clt info bef aft =
> > +    match aft with
> > +      (PC.TOBrace(_),_)::_ -> (((PC.TFunDecl(clt),info) :: bef),
> > aft)
> > +    | (PC.TPtVirg(_),_)::_ -> (((PC.TFunProto(clt),info) :: bef),
> > aft)
> > +    | _ -> raise Irrelevant in
> > +  let rec loop acc = function
> >        [] -> []
> >      | t :: rest ->
> >  	if is_par t || is_mid t || is_ident t
> > @@ -1046,26 +1090,30 @@ let find_function_names l =
> >  	    try
> >  	      let (bef,aft) = split [] (t::rest) in
> >  	      let rest = balanced_name 0 bef in
> > +              (match aft with
> > +                (PC.TPtVirg(_),_)::_
> > +                 when not(is_permissible_proto acc) -> raise
> > Irrelevant
> > +              | _ ->
> >  	      (match rest with
> >  		(PC.TOPar(_),_)::_ ->
> >  		  (match balanced_args 0 rest with
> >  		    [] ->
> >  		      let (_,info) as h = List.hd bef in
> >  		      let clt = get_clt h in
> > -		      (((PC.TFunDecl(clt),info) :: bef), aft)
> > +                      decl_or_proto clt info bef aft
> >  		  | (PC.TAttr_(_),_)::rest ->
> >  		      (match balanced_args 0 rest with
> >  			[] ->
> >  			  let (_,info) as h = List.hd bef in
> >  			  let clt = get_clt h in
> > -			  (((PC.TFunDecl(clt),info) :: bef), aft)
> > +                          decl_or_proto clt info bef aft
> >  		      | _ -> raise Irrelevant)
> >  		  | _ -> raise Irrelevant)
> > -	      | _ -> raise Irrelevant)
> > +	      | _ -> raise Irrelevant))
> >  	    with Irrelevant -> ([t],rest) in
> > -	  t @ (loop rest)
> > -	else t :: (loop rest) in
> > -  loop l
> > +          t @ (loop (t @ acc) rest)
> > +        else t :: (loop (t :: acc) rest) in
> > +  loop [] l
> > 
> >  (* -------------------------------------------------------------
> > ---------- *)
> >  (* an attribute is an identifier that precedes another identifier
> > and
> > @@ -1168,6 +1216,8 @@ let detect_types in_meta_decls l =
> >  	delim::newid::id::(loop false infn (ident::type_names) rest)
> >      | ((PC.TFunDecl(_),_) as fn)::rest ->
> >  	fn::(loop false 1 type_names rest)
> > +    | ((PC.TFunProto(_),_) as fn)::rest ->
> > +	fn::(loop false 1 type_names rest)
> >      | ((PC.TOPar(_),_) as lp)::rest when infn > 0 ->
> >  	lp::(loop false (infn + 1) type_names rest)
> >      | ((PC.TCPar(_),_) as rp)::rest when infn > 0 ->
> > @@ -1252,7 +1302,7 @@ let token2line (tok,_) =
> >    | PC.TMetaDParamList(_,_,_,_,clt) | PC.TMetaFunc(_,_,_,clt)
> >    | PC.TMetaLocalFunc(_,_,_,clt) | PC.TMetaPos(_,_,_,clt) |
> > PC.TMetaCom(_,_,clt)
> > 
> > -  | PC.TFunDecl(clt)
> > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TEllipsis(clt)
> > 
> > diff --git a/parsing_cocci/parser_cocci_menhir.mly
> > b/parsing_cocci/parser_cocci_menhir.mly
> > index 9e6c8a08..26958f63 100644
> > --- a/parsing_cocci/parser_cocci_menhir.mly
> > +++ b/parsing_cocci/parser_cocci_menhir.mly
> > @@ -239,7 +239,8 @@ let inline_id aft = function
> > 
> >  %token <Data.clt> TVAEllipsis
> >  %token <Data.clt> TIf TElse TWhile TFor TDo TSwitch TCase TDefault
> > TReturn
> > -%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof TFunDecl
> > Tdecimal Texec
> > +%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof TFunDecl
> > TFunProto
> > +%token <Data.clt> Tdecimal Texec
> >  %token <string * Data.clt> TIdent TTypeId TDeclarerId TIteratorId
> > TSymId
> >  %token <Ast_cocci.added_string * Data.clt> TDirective
> >  %token <Data.clt> TAttr_
> > @@ -1439,7 +1440,8 @@ reverse_separated_nonempty_llist(separator,
> > X):
> > 
> >  funproto:
> >    s=ioption(storage) i=ioption(Tinline) t=ctype
> > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar
> > pt=TPtVirg
> > +  TFunProto id=fn_ident
> > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> >        { let s = match s with None -> [] | Some s -> [Ast0.FStorage
> > s] in
> >          let i =
> >  	  match i with
> > @@ -1453,7 +1455,8 @@ funproto:
> >  	      P.clt2mcode "(" lp, args, vararg, P.clt2mcode ")" rp,
> >  	      P.clt2mcode ";" pt)) }
> >  | i=Tinline s=storage t=ctype
> > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar
> > pt=TPtVirg
> > +  TFunProto id=fn_ident
> > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> >        { let s = [Ast0.FStorage s] in
> >          let i = [Ast0.FInline (P.clt2mcode "inline" i)] in
> >  	let t = [Ast0.FType t] in
> > --
> > 2.21.1
> > 
> > 

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

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

* Re: [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
  2020-03-19 13:58     ` Jaskaran Singh
@ 2020-03-19 15:54       ` Julia Lawall
  2020-03-19 16:25         ` Jaskaran Singh
  0 siblings, 1 reply; 52+ messages in thread
From: Julia Lawall @ 2020-03-19 15:54 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Thu, 19 Mar 2020, Jaskaran Singh wrote:

> On Wed, 2020-03-18 at 18:25 +0100, Julia Lawall wrote:
> >
> > On Mon, 16 Mar 2020, Jaskaran Singh wrote:
> >
> > > To add the types ParenType and FunctionType to the SmPL AST, a
> > > reduce/reduce conflict with the funproto rule of the SmPL parser
> > > must be resolved. This requires explicitly identifying a function
> > > prototype by use of a token (TFunProto).
> > >
> > > While the correct method of identifying a function prototype would
> > > be to
> > > check if an identifier is preceded by a return type, it is
> > > challenging
> > > to implement. This is because implementing an OCaml function, to
> > > correctly determine a C type in SmPL, without the aid of Yacc,
> > > would
> > > have to handle a number of cases (disjunctions, typeof expressions,
> > > etc.).
> > >
> > > Thus, a slightly hacky approach is taken to determine a function
> > > prototype with not the best certainty but what works for most cases
> > > in SmPL. If the identifier is preceded by any token that does not
> > > seem to be part of a type, then it is not identified as a function
> > > prototype. Else, it is.
> >
> > This sacrifices the test case tests/p1p2.cocci:
> >
>
> What do you mean by sacrifice?

That it doesn't work after applying 01.

Does something that comes later make it work again?

julia

> The test case seems to work, but not with just 01 applied. Here's what
> the debugger tells me about the AST:
>
> Ast_cocci.FunProto
> ([Ast_cocci.FType
>    {Ast_cocci.node =
>      Ast_cocci.Type (false, None,
>       {Ast_cocci.node =
>         Ast_cocci.MetaType
>          ((("rule starting on line 11", "T"),
>            {Ast_cocci.line = 18; column = 1;
>             strbef = []; straft = [];
>             whitespace = " "},
>            Ast_cocci.CONTEXT (Ast_cocci.NoPos,
>             Ast_cocci.AFTER
>              ([[Ast_cocci.Directive
>                  [Ast_cocci.Space
>                    "__attribute__((nonnull(2)))"]]],
>              Ast_cocci.ONE)),
>            []),
>
> Maybe after the grammar changes, Menhir does some kind of lookahead?
> I'm not sure.
>
> Cheers,
> Jaskaran.
>
> > @@
> > typedef Error;
> > type T;
> > identifier FN;
> > parameter P1;
> > @@
> >  T
> > +__attribute__((nonnull(1)))
> >  FN(P1, Error **errp);
> >
> > @@
> > typedef Error;
> > type T;
> > identifier FN;
> > parameter P1;
> > parameter P2;
> > @@
> >  T
> > +__attribute__((nonnull(2)))
> >  FN(P1, P2, Error **errp);
> >
> > Normally, the only way that you can have a ) before a function call
> > is
> > when there is a cast.  But hopefully in that case there would not be
> > two
> > )) before the function call.  Can that get around the problem?
> >
> > julia
> >
> >
> >
> >
> > > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > > ---
> > >  parsing_cocci/parse_cocci.ml          | 72
> > > +++++++++++++++++++++++----
> > >  parsing_cocci/parser_cocci_menhir.mly |  9 ++--
> > >  2 files changed, 67 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/parsing_cocci/parse_cocci.ml
> > > b/parsing_cocci/parse_cocci.ml
> > > index 679d213a..4b2cb7e4 100644
> > > --- a/parsing_cocci/parse_cocci.ml
> > > +++ b/parsing_cocci/parse_cocci.ml
> > > @@ -295,6 +295,7 @@ let token2c (tok,_) add_clt =
> > >    | PC.TLineEnd(clt) -> "line end"
> > >    | PC.TInvalid -> "invalid"
> > >    | PC.TFunDecl(clt) -> "fundecl"
> > > +  | PC.TFunProto(clt) -> "funproto"
> > >
> > >    | PC.TIso -> "<=>"
> > >    | PC.TRightIso -> "=>"
> > > @@ -480,7 +481,7 @@ let get_clt (tok,_) =
> > >
> > >    | PC.TOPar0(_,clt) | PC.TMid0(_,clt) | PC.TAnd0(_,clt) |
> > > PC.TCPar0(_,clt)
> > >    | PC.TOEllipsis(clt) | PC.TCEllipsis(clt)
> > > -  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt)
> > > +  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) | PC.TFunProto(clt)
> > >    | PC.TFunDecl(clt) | PC.TDirective(_,clt) | PC.TAttr_(clt)
> > >    | PC.TLineEnd(clt) -> clt
> > >    | PC.TVAEllipsis(clt) -> clt
> > > @@ -718,6 +719,7 @@ let update_clt (tok,x) clt =
> > >
> > >    | PC.TLineEnd(_) -> (PC.TLineEnd(clt),x)
> > >    | PC.TFunDecl(_) -> (PC.TFunDecl(clt),x)
> > > +  | PC.TFunProto(_) -> (PC.TFunProto(clt),x)
> > >    | PC.TTildeExclEq(_) -> (PC.TTildeExclEq(clt),x)
> > >    | PC.TDirective(a,_) -> (PC.TDirective(a,clt),x)
> > >    | PC.TAttr_(_) -> (PC.TAttr_(clt),x)
> > > @@ -925,7 +927,7 @@ let split_token ((tok,_) as t) =
> > >    | PC.TInitialize | PC.TFinalize -> ([t],[t])
> > >    | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt)
> > > -> split t clt
> > >
> > > -  | PC.TFunDecl(clt)
> > > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> > >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> > >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TLineEnd(clt)
> > >    | PC.TEllipsis(clt)
> > > @@ -1006,7 +1008,8 @@ let find_function_names l =
> > >      | _ -> false in
> > >    let rec split acc = function
> > >        [] | [_] -> raise Irrelevant
> > > -    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest
> > > ->
> > > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) :: rest
> > > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TPtVirg(_),_) as t2) :: rest
> > > ->
> > >  	(List.rev (t1::acc),(t2::rest))
> > >      | x::xs -> split (x::acc) xs in
> > >    let rec balanced_name level = function
> > > @@ -1037,7 +1040,48 @@ let find_function_names l =
> > >      | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_ ->
> > >  	raise Irrelevant
> > >      | t::rest -> balanced_args level rest in
> > > -  let rec loop = function
> > > +  let rec is_permissible_proto = function
> > > +      [] -> false
> > > +    | (PC.TCPar0(_),_)::
> > > +      ((PC.TMid0(_),_) | (PC.TAnd0(_),_))::
> > > +      (PC.TOPar0(_),_)::_ -> false
> > > +    | (PC.TOPar0(_),_)::rest
> > > +    | (PC.TCPar0(_),_)::rest -> is_permissible_proto rest
> > > +    | x::rest when is_mid x ->
> > > +        let rec loop = function
> > > +          [] -> false
> > > +        | (PC.TOPar0(_),_)::xs -> is_permissible_proto xs
> > > +        | x::xs -> loop xs in
> > > +        loop rest
> > > +    | _::((PC.TEq(_),_) | (PC.TNotEq(_),_))::(PC.TWhen(_),_)::_
> > > +    | _::(PC.TWhen(_),_)::_
> > > +    | (PC.TComma(_),_)::_
> > > +    | (PC.TDirective(_),_)::_
> > > +    | (PC.TElse(_),_)::_
> > > +    | (PC.TReturn(_),_)::_
> > > +    | (PC.TMetaStm(_),_)::_
> > > +    | (PC.TMetaExp(_),_)::_
> > > +    | (PC.TMetaId(_),_)::_
> > > +    | (PC.TMetaLocalIdExp(_),_)::_
> > > +    | (PC.TEq(_),_)::_
> > > +    | (PC.TEllipsis(_),_)::_
> > > +    | (PC.TOEllipsis(_),_)::_
> > > +    | (PC.TCEllipsis(_),_)::_
> > > +    | (PC.TPOEllipsis(_),_)::_
> > > +    | (PC.TPCEllipsis(_),_)::_
> > > +    | (PC.TPtVirg(_),_)::_
> > > +    | (PC.TOBrace(_),_)::_
> > > +    | (PC.TCBrace(_),_)::_
> > > +    | (PC.TOPar(_),_)::_
> > > +    | (PC.TCPar(_),_)::_
> > > +    | (PC.TIdent(_),_)::_ -> false
> > > +    | _ -> true in
> > > +  let decl_or_proto clt info bef aft =
> > > +    match aft with
> > > +      (PC.TOBrace(_),_)::_ -> (((PC.TFunDecl(clt),info) :: bef),
> > > aft)
> > > +    | (PC.TPtVirg(_),_)::_ -> (((PC.TFunProto(clt),info) :: bef),
> > > aft)
> > > +    | _ -> raise Irrelevant in
> > > +  let rec loop acc = function
> > >        [] -> []
> > >      | t :: rest ->
> > >  	if is_par t || is_mid t || is_ident t
> > > @@ -1046,26 +1090,30 @@ let find_function_names l =
> > >  	    try
> > >  	      let (bef,aft) = split [] (t::rest) in
> > >  	      let rest = balanced_name 0 bef in
> > > +              (match aft with
> > > +                (PC.TPtVirg(_),_)::_
> > > +                 when not(is_permissible_proto acc) -> raise
> > > Irrelevant
> > > +              | _ ->
> > >  	      (match rest with
> > >  		(PC.TOPar(_),_)::_ ->
> > >  		  (match balanced_args 0 rest with
> > >  		    [] ->
> > >  		      let (_,info) as h = List.hd bef in
> > >  		      let clt = get_clt h in
> > > -		      (((PC.TFunDecl(clt),info) :: bef), aft)
> > > +                      decl_or_proto clt info bef aft
> > >  		  | (PC.TAttr_(_),_)::rest ->
> > >  		      (match balanced_args 0 rest with
> > >  			[] ->
> > >  			  let (_,info) as h = List.hd bef in
> > >  			  let clt = get_clt h in
> > > -			  (((PC.TFunDecl(clt),info) :: bef), aft)
> > > +                          decl_or_proto clt info bef aft
> > >  		      | _ -> raise Irrelevant)
> > >  		  | _ -> raise Irrelevant)
> > > -	      | _ -> raise Irrelevant)
> > > +	      | _ -> raise Irrelevant))
> > >  	    with Irrelevant -> ([t],rest) in
> > > -	  t @ (loop rest)
> > > -	else t :: (loop rest) in
> > > -  loop l
> > > +          t @ (loop (t @ acc) rest)
> > > +        else t :: (loop (t :: acc) rest) in
> > > +  loop [] l
> > >
> > >  (* -------------------------------------------------------------
> > > ---------- *)
> > >  (* an attribute is an identifier that precedes another identifier
> > > and
> > > @@ -1168,6 +1216,8 @@ let detect_types in_meta_decls l =
> > >  	delim::newid::id::(loop false infn (ident::type_names) rest)
> > >      | ((PC.TFunDecl(_),_) as fn)::rest ->
> > >  	fn::(loop false 1 type_names rest)
> > > +    | ((PC.TFunProto(_),_) as fn)::rest ->
> > > +	fn::(loop false 1 type_names rest)
> > >      | ((PC.TOPar(_),_) as lp)::rest when infn > 0 ->
> > >  	lp::(loop false (infn + 1) type_names rest)
> > >      | ((PC.TCPar(_),_) as rp)::rest when infn > 0 ->
> > > @@ -1252,7 +1302,7 @@ let token2line (tok,_) =
> > >    | PC.TMetaDParamList(_,_,_,_,clt) | PC.TMetaFunc(_,_,_,clt)
> > >    | PC.TMetaLocalFunc(_,_,_,clt) | PC.TMetaPos(_,_,_,clt) |
> > > PC.TMetaCom(_,_,clt)
> > >
> > > -  | PC.TFunDecl(clt)
> > > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> > >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> > >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TEllipsis(clt)
> > >
> > > diff --git a/parsing_cocci/parser_cocci_menhir.mly
> > > b/parsing_cocci/parser_cocci_menhir.mly
> > > index 9e6c8a08..26958f63 100644
> > > --- a/parsing_cocci/parser_cocci_menhir.mly
> > > +++ b/parsing_cocci/parser_cocci_menhir.mly
> > > @@ -239,7 +239,8 @@ let inline_id aft = function
> > >
> > >  %token <Data.clt> TVAEllipsis
> > >  %token <Data.clt> TIf TElse TWhile TFor TDo TSwitch TCase TDefault
> > > TReturn
> > > -%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof TFunDecl
> > > Tdecimal Texec
> > > +%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof TFunDecl
> > > TFunProto
> > > +%token <Data.clt> Tdecimal Texec
> > >  %token <string * Data.clt> TIdent TTypeId TDeclarerId TIteratorId
> > > TSymId
> > >  %token <Ast_cocci.added_string * Data.clt> TDirective
> > >  %token <Data.clt> TAttr_
> > > @@ -1439,7 +1440,8 @@ reverse_separated_nonempty_llist(separator,
> > > X):
> > >
> > >  funproto:
> > >    s=ioption(storage) i=ioption(Tinline) t=ctype
> > > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar
> > > pt=TPtVirg
> > > +  TFunProto id=fn_ident
> > > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> > >        { let s = match s with None -> [] | Some s -> [Ast0.FStorage
> > > s] in
> > >          let i =
> > >  	  match i with
> > > @@ -1453,7 +1455,8 @@ funproto:
> > >  	      P.clt2mcode "(" lp, args, vararg, P.clt2mcode ")" rp,
> > >  	      P.clt2mcode ";" pt)) }
> > >  | i=Tinline s=storage t=ctype
> > > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar
> > > pt=TPtVirg
> > > +  TFunProto id=fn_ident
> > > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> > >        { let s = [Ast0.FStorage s] in
> > >          let i = [Ast0.FInline (P.clt2mcode "inline" i)] in
> > >  	let t = [Ast0.FType t] in
> > > --
> > > 2.21.1
> > >
> > >
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
  2020-03-19 15:54       ` Julia Lawall
@ 2020-03-19 16:25         ` Jaskaran Singh
  2020-03-19 16:26           ` Jaskaran Singh
  2020-03-19 16:37           ` Julia Lawall
  0 siblings, 2 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-19 16:25 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel-mentees, cocci

On Thu, 2020-03-19 at 16:54 +0100, Julia Lawall wrote:
> 
> On Thu, 19 Mar 2020, Jaskaran Singh wrote:
> 
> > On Wed, 2020-03-18 at 18:25 +0100, Julia Lawall wrote:
> > > On Mon, 16 Mar 2020, Jaskaran Singh wrote:
> > > 
> > > > To add the types ParenType and FunctionType to the SmPL AST, a
> > > > reduce/reduce conflict with the funproto rule of the SmPL
> > > > parser
> > > > must be resolved. This requires explicitly identifying a
> > > > function
> > > > prototype by use of a token (TFunProto).
> > > > 
> > > > While the correct method of identifying a function prototype
> > > > would
> > > > be to
> > > > check if an identifier is preceded by a return type, it is
> > > > challenging
> > > > to implement. This is because implementing an OCaml function,
> > > > to
> > > > correctly determine a C type in SmPL, without the aid of Yacc,
> > > > would
> > > > have to handle a number of cases (disjunctions, typeof
> > > > expressions,
> > > > etc.).
> > > > 
> > > > Thus, a slightly hacky approach is taken to determine a
> > > > function
> > > > prototype with not the best certainty but what works for most
> > > > cases
> > > > in SmPL. If the identifier is preceded by any token that does
> > > > not
> > > > seem to be part of a type, then it is not identified as a
> > > > function
> > > > prototype. Else, it is.
> > > 
> > > This sacrifices the test case tests/p1p2.cocci:
> > > 
> > 
> > What do you mean by sacrifice?
> 
> That it doesn't work after applying 01.
> 
> Does something that comes later make it work again?
> 

Yes. I applied the series till 16/25 (Got a fatal error before that),
where the test worked again.

Cheers,
Jaskaran.

> julia
> 
> > The test case seems to work, but not with just 01 applied. Here's
> > what
> > the debugger tells me about the AST:
> > 
> > Ast_cocci.FunProto
> > ([Ast_cocci.FType
> >    {Ast_cocci.node =
> >      Ast_cocci.Type (false, None,
> >       {Ast_cocci.node =
> >         Ast_cocci.MetaType
> >          ((("rule starting on line 11", "T"),
> >            {Ast_cocci.line = 18; column = 1;
> >             strbef = []; straft = [];
> >             whitespace = " "},
> >            Ast_cocci.CONTEXT (Ast_cocci.NoPos,
> >             Ast_cocci.AFTER
> >              ([[Ast_cocci.Directive
> >                  [Ast_cocci.Space
> >                    "__attribute__((nonnull(2)))"]]],
> >              Ast_cocci.ONE)),
> >            []),
> > 
> > Maybe after the grammar changes, Menhir does some kind of
> > lookahead?
> > I'm not sure.
> > 
> > Cheers,
> > Jaskaran.
> > 
> > > @@
> > > typedef Error;
> > > type T;
> > > identifier FN;
> > > parameter P1;
> > > @@
> > >  T
> > > +__attribute__((nonnull(1)))
> > >  FN(P1, Error **errp);
> > > 
> > > @@
> > > typedef Error;
> > > type T;
> > > identifier FN;
> > > parameter P1;
> > > parameter P2;
> > > @@
> > >  T
> > > +__attribute__((nonnull(2)))
> > >  FN(P1, P2, Error **errp);
> > > 
> > > Normally, the only way that you can have a ) before a function
> > > call
> > > is
> > > when there is a cast.  But hopefully in that case there would not
> > > be
> > > two
> > > )) before the function call.  Can that get around the problem?
> > > 
> > > julia
> > > 
> > > 
> > > 
> > > 
> > > > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > > > ---
> > > >  parsing_cocci/parse_cocci.ml          | 72
> > > > +++++++++++++++++++++++----
> > > >  parsing_cocci/parser_cocci_menhir.mly |  9 ++--
> > > >  2 files changed, 67 insertions(+), 14 deletions(-)
> > > > 
> > > > diff --git a/parsing_cocci/parse_cocci.ml
> > > > b/parsing_cocci/parse_cocci.ml
> > > > index 679d213a..4b2cb7e4 100644
> > > > --- a/parsing_cocci/parse_cocci.ml
> > > > +++ b/parsing_cocci/parse_cocci.ml
> > > > @@ -295,6 +295,7 @@ let token2c (tok,_) add_clt =
> > > >    | PC.TLineEnd(clt) -> "line end"
> > > >    | PC.TInvalid -> "invalid"
> > > >    | PC.TFunDecl(clt) -> "fundecl"
> > > > +  | PC.TFunProto(clt) -> "funproto"
> > > > 
> > > >    | PC.TIso -> "<=>"
> > > >    | PC.TRightIso -> "=>"
> > > > @@ -480,7 +481,7 @@ let get_clt (tok,_) =
> > > > 
> > > >    | PC.TOPar0(_,clt) | PC.TMid0(_,clt) | PC.TAnd0(_,clt) |
> > > > PC.TCPar0(_,clt)
> > > >    | PC.TOEllipsis(clt) | PC.TCEllipsis(clt)
> > > > -  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt)
> > > > +  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) |
> > > > PC.TFunProto(clt)
> > > >    | PC.TFunDecl(clt) | PC.TDirective(_,clt) | PC.TAttr_(clt)
> > > >    | PC.TLineEnd(clt) -> clt
> > > >    | PC.TVAEllipsis(clt) -> clt
> > > > @@ -718,6 +719,7 @@ let update_clt (tok,x) clt =
> > > > 
> > > >    | PC.TLineEnd(_) -> (PC.TLineEnd(clt),x)
> > > >    | PC.TFunDecl(_) -> (PC.TFunDecl(clt),x)
> > > > +  | PC.TFunProto(_) -> (PC.TFunProto(clt),x)
> > > >    | PC.TTildeExclEq(_) -> (PC.TTildeExclEq(clt),x)
> > > >    | PC.TDirective(a,_) -> (PC.TDirective(a,clt),x)
> > > >    | PC.TAttr_(_) -> (PC.TAttr_(clt),x)
> > > > @@ -925,7 +927,7 @@ let split_token ((tok,_) as t) =
> > > >    | PC.TInitialize | PC.TFinalize -> ([t],[t])
> > > >    | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) |
> > > > PC.TMetaCom(_,_,clt)
> > > > -> split t clt
> > > > 
> > > > -  | PC.TFunDecl(clt)
> > > > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> > > >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> > > >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TLineEnd(clt)
> > > >    | PC.TEllipsis(clt)
> > > > @@ -1006,7 +1008,8 @@ let find_function_names l =
> > > >      | _ -> false in
> > > >    let rec split acc = function
> > > >        [] | [_] -> raise Irrelevant
> > > > -    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) ::
> > > > rest
> > > > ->
> > > > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) ::
> > > > rest
> > > > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TPtVirg(_),_) as t2) ::
> > > > rest
> > > > ->
> > > >  	(List.rev (t1::acc),(t2::rest))
> > > >      | x::xs -> split (x::acc) xs in
> > > >    let rec balanced_name level = function
> > > > @@ -1037,7 +1040,48 @@ let find_function_names l =
> > > >      | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_ ->
> > > >  	raise Irrelevant
> > > >      | t::rest -> balanced_args level rest in
> > > > -  let rec loop = function
> > > > +  let rec is_permissible_proto = function
> > > > +      [] -> false
> > > > +    | (PC.TCPar0(_),_)::
> > > > +      ((PC.TMid0(_),_) | (PC.TAnd0(_),_))::
> > > > +      (PC.TOPar0(_),_)::_ -> false
> > > > +    | (PC.TOPar0(_),_)::rest
> > > > +    | (PC.TCPar0(_),_)::rest -> is_permissible_proto rest
> > > > +    | x::rest when is_mid x ->
> > > > +        let rec loop = function
> > > > +          [] -> false
> > > > +        | (PC.TOPar0(_),_)::xs -> is_permissible_proto xs
> > > > +        | x::xs -> loop xs in
> > > > +        loop rest
> > > > +    | _::((PC.TEq(_),_) |
> > > > (PC.TNotEq(_),_))::(PC.TWhen(_),_)::_
> > > > +    | _::(PC.TWhen(_),_)::_
> > > > +    | (PC.TComma(_),_)::_
> > > > +    | (PC.TDirective(_),_)::_
> > > > +    | (PC.TElse(_),_)::_
> > > > +    | (PC.TReturn(_),_)::_
> > > > +    | (PC.TMetaStm(_),_)::_
> > > > +    | (PC.TMetaExp(_),_)::_
> > > > +    | (PC.TMetaId(_),_)::_
> > > > +    | (PC.TMetaLocalIdExp(_),_)::_
> > > > +    | (PC.TEq(_),_)::_
> > > > +    | (PC.TEllipsis(_),_)::_
> > > > +    | (PC.TOEllipsis(_),_)::_
> > > > +    | (PC.TCEllipsis(_),_)::_
> > > > +    | (PC.TPOEllipsis(_),_)::_
> > > > +    | (PC.TPCEllipsis(_),_)::_
> > > > +    | (PC.TPtVirg(_),_)::_
> > > > +    | (PC.TOBrace(_),_)::_
> > > > +    | (PC.TCBrace(_),_)::_
> > > > +    | (PC.TOPar(_),_)::_
> > > > +    | (PC.TCPar(_),_)::_
> > > > +    | (PC.TIdent(_),_)::_ -> false
> > > > +    | _ -> true in
> > > > +  let decl_or_proto clt info bef aft =
> > > > +    match aft with
> > > > +      (PC.TOBrace(_),_)::_ -> (((PC.TFunDecl(clt),info) ::
> > > > bef),
> > > > aft)
> > > > +    | (PC.TPtVirg(_),_)::_ -> (((PC.TFunProto(clt),info) ::
> > > > bef),
> > > > aft)
> > > > +    | _ -> raise Irrelevant in
> > > > +  let rec loop acc = function
> > > >        [] -> []
> > > >      | t :: rest ->
> > > >  	if is_par t || is_mid t || is_ident t
> > > > @@ -1046,26 +1090,30 @@ let find_function_names l =
> > > >  	    try
> > > >  	      let (bef,aft) = split [] (t::rest) in
> > > >  	      let rest = balanced_name 0 bef in
> > > > +              (match aft with
> > > > +                (PC.TPtVirg(_),_)::_
> > > > +                 when not(is_permissible_proto acc) -> raise
> > > > Irrelevant
> > > > +              | _ ->
> > > >  	      (match rest with
> > > >  		(PC.TOPar(_),_)::_ ->
> > > >  		  (match balanced_args 0 rest with
> > > >  		    [] ->
> > > >  		      let (_,info) as h = List.hd bef in
> > > >  		      let clt = get_clt h in
> > > > -		      (((PC.TFunDecl(clt),info) :: bef), aft)
> > > > +                      decl_or_proto clt info bef aft
> > > >  		  | (PC.TAttr_(_),_)::rest ->
> > > >  		      (match balanced_args 0 rest with
> > > >  			[] ->
> > > >  			  let (_,info) as h = List.hd bef in
> > > >  			  let clt = get_clt h in
> > > > -			  (((PC.TFunDecl(clt),info) :: bef),
> > > > aft)
> > > > +                          decl_or_proto clt info bef aft
> > > >  		      | _ -> raise Irrelevant)
> > > >  		  | _ -> raise Irrelevant)
> > > > -	      | _ -> raise Irrelevant)
> > > > +	      | _ -> raise Irrelevant))
> > > >  	    with Irrelevant -> ([t],rest) in
> > > > -	  t @ (loop rest)
> > > > -	else t :: (loop rest) in
> > > > -  loop l
> > > > +          t @ (loop (t @ acc) rest)
> > > > +        else t :: (loop (t :: acc) rest) in
> > > > +  loop [] l
> > > > 
> > > >  (* ---------------------------------------------------------
> > > > ----
> > > > ---------- *)
> > > >  (* an attribute is an identifier that precedes another
> > > > identifier
> > > > and
> > > > @@ -1168,6 +1216,8 @@ let detect_types in_meta_decls l =
> > > >  	delim::newid::id::(loop false infn (ident::type_names)
> > > > rest)
> > > >      | ((PC.TFunDecl(_),_) as fn)::rest ->
> > > >  	fn::(loop false 1 type_names rest)
> > > > +    | ((PC.TFunProto(_),_) as fn)::rest ->
> > > > +	fn::(loop false 1 type_names rest)
> > > >      | ((PC.TOPar(_),_) as lp)::rest when infn > 0 ->
> > > >  	lp::(loop false (infn + 1) type_names rest)
> > > >      | ((PC.TCPar(_),_) as rp)::rest when infn > 0 ->
> > > > @@ -1252,7 +1302,7 @@ let token2line (tok,_) =
> > > >    | PC.TMetaDParamList(_,_,_,_,clt) | PC.TMetaFunc(_,_,_,clt)
> > > >    | PC.TMetaLocalFunc(_,_,_,clt) | PC.TMetaPos(_,_,_,clt) |
> > > > PC.TMetaCom(_,_,clt)
> > > > 
> > > > -  | PC.TFunDecl(clt)
> > > > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> > > >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> > > >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TEllipsis(clt)
> > > > 
> > > > diff --git a/parsing_cocci/parser_cocci_menhir.mly
> > > > b/parsing_cocci/parser_cocci_menhir.mly
> > > > index 9e6c8a08..26958f63 100644
> > > > --- a/parsing_cocci/parser_cocci_menhir.mly
> > > > +++ b/parsing_cocci/parser_cocci_menhir.mly
> > > > @@ -239,7 +239,8 @@ let inline_id aft = function
> > > > 
> > > >  %token <Data.clt> TVAEllipsis
> > > >  %token <Data.clt> TIf TElse TWhile TFor TDo TSwitch TCase
> > > > TDefault
> > > > TReturn
> > > > -%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof
> > > > TFunDecl
> > > > Tdecimal Texec
> > > > +%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof
> > > > TFunDecl
> > > > TFunProto
> > > > +%token <Data.clt> Tdecimal Texec
> > > >  %token <string * Data.clt> TIdent TTypeId TDeclarerId
> > > > TIteratorId
> > > > TSymId
> > > >  %token <Ast_cocci.added_string * Data.clt> TDirective
> > > >  %token <Data.clt> TAttr_
> > > > @@ -1439,7 +1440,8 @@
> > > > reverse_separated_nonempty_llist(separator,
> > > > X):
> > > > 
> > > >  funproto:
> > > >    s=ioption(storage) i=ioption(Tinline) t=ctype
> > > > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl)
> > > > rp=TCPar
> > > > pt=TPtVirg
> > > > +  TFunProto id=fn_ident
> > > > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> > > >        { let s = match s with None -> [] | Some s ->
> > > > [Ast0.FStorage
> > > > s] in
> > > >          let i =
> > > >  	  match i with
> > > > @@ -1453,7 +1455,8 @@ funproto:
> > > >  	      P.clt2mcode "(" lp, args, vararg, P.clt2mcode ")"
> > > > rp,
> > > >  	      P.clt2mcode ";" pt)) }
> > > >  | i=Tinline s=storage t=ctype
> > > > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl)
> > > > rp=TCPar
> > > > pt=TPtVirg
> > > > +  TFunProto id=fn_ident
> > > > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> > > >        { let s = [Ast0.FStorage s] in
> > > >          let i = [Ast0.FInline (P.clt2mcode "inline" i)] in
> > > >  	let t = [Ast0.FType t] in
> > > > --
> > > > 2.21.1
> > > > 
> > > > 

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

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

* Re: [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
  2020-03-19 16:25         ` Jaskaran Singh
@ 2020-03-19 16:26           ` Jaskaran Singh
  2020-03-19 16:37           ` Julia Lawall
  1 sibling, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-19 16:26 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci

On Thu, 2020-03-19 at 21:55 +0530, Jaskaran Singh wrote:
> On Thu, 2020-03-19 at 16:54 +0100, Julia Lawall wrote:
> > On Thu, 19 Mar 2020, Jaskaran Singh wrote:
> > 
> > > On Wed, 2020-03-18 at 18:25 +0100, Julia Lawall wrote:
> > > > On Mon, 16 Mar 2020, Jaskaran Singh wrote:
> > > > 
> > > > > To add the types ParenType and FunctionType to the SmPL AST,
> > > > > a
> > > > > reduce/reduce conflict with the funproto rule of the SmPL
> > > > > parser
> > > > > must be resolved. This requires explicitly identifying a
> > > > > function
> > > > > prototype by use of a token (TFunProto).
> > > > > 
> > > > > While the correct method of identifying a function prototype
> > > > > would
> > > > > be to
> > > > > check if an identifier is preceded by a return type, it is
> > > > > challenging
> > > > > to implement. This is because implementing an OCaml function,
> > > > > to
> > > > > correctly determine a C type in SmPL, without the aid of
> > > > > Yacc,
> > > > > would
> > > > > have to handle a number of cases (disjunctions, typeof
> > > > > expressions,
> > > > > etc.).
> > > > > 
> > > > > Thus, a slightly hacky approach is taken to determine a
> > > > > function
> > > > > prototype with not the best certainty but what works for most
> > > > > cases
> > > > > in SmPL. If the identifier is preceded by any token that does
> > > > > not
> > > > > seem to be part of a type, then it is not identified as a
> > > > > function
> > > > > prototype. Else, it is.
> > > > 
> > > > This sacrifices the test case tests/p1p2.cocci:
> > > > 
> > > 
> > > What do you mean by sacrifice?
> > 
> > That it doesn't work after applying 01.
> > 
> > Does something that comes later make it work again?
> > 
> 
> Yes. I applied the series till 16/25 


Correction: 16/26*

Cheers,
Jaskaran.

> (Got a fatal error before that),
> where the test worked again.
> 
> Cheers,
> Jaskaran.
> 
> > julia
> > 
> > > The test case seems to work, but not with just 01 applied. Here's
> > > what
> > > the debugger tells me about the AST:
> > > 
> > > Ast_cocci.FunProto
> > > ([Ast_cocci.FType
> > >    {Ast_cocci.node =
> > >      Ast_cocci.Type (false, None,
> > >       {Ast_cocci.node =
> > >         Ast_cocci.MetaType
> > >          ((("rule starting on line 11", "T"),
> > >            {Ast_cocci.line = 18; column = 1;
> > >             strbef = []; straft = [];
> > >             whitespace = " "},
> > >            Ast_cocci.CONTEXT (Ast_cocci.NoPos,
> > >             Ast_cocci.AFTER
> > >              ([[Ast_cocci.Directive
> > >                  [Ast_cocci.Space
> > >                    "__attribute__((nonnull(2)))"]]],
> > >              Ast_cocci.ONE)),
> > >            []),
> > > 
> > > Maybe after the grammar changes, Menhir does some kind of
> > > lookahead?
> > > I'm not sure.
> > > 
> > > Cheers,
> > > Jaskaran.
> > > 
> > > > @@
> > > > typedef Error;
> > > > type T;
> > > > identifier FN;
> > > > parameter P1;
> > > > @@
> > > >  T
> > > > +__attribute__((nonnull(1)))
> > > >  FN(P1, Error **errp);
> > > > 
> > > > @@
> > > > typedef Error;
> > > > type T;
> > > > identifier FN;
> > > > parameter P1;
> > > > parameter P2;
> > > > @@
> > > >  T
> > > > +__attribute__((nonnull(2)))
> > > >  FN(P1, P2, Error **errp);
> > > > 
> > > > Normally, the only way that you can have a ) before a function
> > > > call
> > > > is
> > > > when there is a cast.  But hopefully in that case there would
> > > > not
> > > > be
> > > > two
> > > > )) before the function call.  Can that get around the problem?
> > > > 
> > > > julia
> > > > 
> > > > 
> > > > 
> > > > 
> > > > > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com
> > > > > >
> > > > > ---
> > > > >  parsing_cocci/parse_cocci.ml          | 72
> > > > > +++++++++++++++++++++++----
> > > > >  parsing_cocci/parser_cocci_menhir.mly |  9 ++--
> > > > >  2 files changed, 67 insertions(+), 14 deletions(-)
> > > > > 
> > > > > diff --git a/parsing_cocci/parse_cocci.ml
> > > > > b/parsing_cocci/parse_cocci.ml
> > > > > index 679d213a..4b2cb7e4 100644
> > > > > --- a/parsing_cocci/parse_cocci.ml
> > > > > +++ b/parsing_cocci/parse_cocci.ml
> > > > > @@ -295,6 +295,7 @@ let token2c (tok,_) add_clt =
> > > > >    | PC.TLineEnd(clt) -> "line end"
> > > > >    | PC.TInvalid -> "invalid"
> > > > >    | PC.TFunDecl(clt) -> "fundecl"
> > > > > +  | PC.TFunProto(clt) -> "funproto"
> > > > > 
> > > > >    | PC.TIso -> "<=>"
> > > > >    | PC.TRightIso -> "=>"
> > > > > @@ -480,7 +481,7 @@ let get_clt (tok,_) =
> > > > > 
> > > > >    | PC.TOPar0(_,clt) | PC.TMid0(_,clt) | PC.TAnd0(_,clt) |
> > > > > PC.TCPar0(_,clt)
> > > > >    | PC.TOEllipsis(clt) | PC.TCEllipsis(clt)
> > > > > -  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt)
> > > > > +  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) |
> > > > > PC.TFunProto(clt)
> > > > >    | PC.TFunDecl(clt) | PC.TDirective(_,clt) | PC.TAttr_(clt)
> > > > >    | PC.TLineEnd(clt) -> clt
> > > > >    | PC.TVAEllipsis(clt) -> clt
> > > > > @@ -718,6 +719,7 @@ let update_clt (tok,x) clt =
> > > > > 
> > > > >    | PC.TLineEnd(_) -> (PC.TLineEnd(clt),x)
> > > > >    | PC.TFunDecl(_) -> (PC.TFunDecl(clt),x)
> > > > > +  | PC.TFunProto(_) -> (PC.TFunProto(clt),x)
> > > > >    | PC.TTildeExclEq(_) -> (PC.TTildeExclEq(clt),x)
> > > > >    | PC.TDirective(a,_) -> (PC.TDirective(a,clt),x)
> > > > >    | PC.TAttr_(_) -> (PC.TAttr_(clt),x)
> > > > > @@ -925,7 +927,7 @@ let split_token ((tok,_) as t) =
> > > > >    | PC.TInitialize | PC.TFinalize -> ([t],[t])
> > > > >    | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) |
> > > > > PC.TMetaCom(_,_,clt)
> > > > > -> split t clt
> > > > > 
> > > > > -  | PC.TFunDecl(clt)
> > > > > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> > > > >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> > > > >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TLineEnd(clt)
> > > > >    | PC.TEllipsis(clt)
> > > > > @@ -1006,7 +1008,8 @@ let find_function_names l =
> > > > >      | _ -> false in
> > > > >    let rec split acc = function
> > > > >        [] | [_] -> raise Irrelevant
> > > > > -    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2)
> > > > > ::
> > > > > rest
> > > > > ->
> > > > > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2)
> > > > > ::
> > > > > rest
> > > > > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TPtVirg(_),_) as t2)
> > > > > ::
> > > > > rest
> > > > > ->
> > > > >  	(List.rev (t1::acc),(t2::rest))
> > > > >      | x::xs -> split (x::acc) xs in
> > > > >    let rec balanced_name level = function
> > > > > @@ -1037,7 +1040,48 @@ let find_function_names l =
> > > > >      | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_
> > > > > ->
> > > > >  	raise Irrelevant
> > > > >      | t::rest -> balanced_args level rest in
> > > > > -  let rec loop = function
> > > > > +  let rec is_permissible_proto = function
> > > > > +      [] -> false
> > > > > +    | (PC.TCPar0(_),_)::
> > > > > +      ((PC.TMid0(_),_) | (PC.TAnd0(_),_))::
> > > > > +      (PC.TOPar0(_),_)::_ -> false
> > > > > +    | (PC.TOPar0(_),_)::rest
> > > > > +    | (PC.TCPar0(_),_)::rest -> is_permissible_proto rest
> > > > > +    | x::rest when is_mid x ->
> > > > > +        let rec loop = function
> > > > > +          [] -> false
> > > > > +        | (PC.TOPar0(_),_)::xs -> is_permissible_proto xs
> > > > > +        | x::xs -> loop xs in
> > > > > +        loop rest
> > > > > +    | _::((PC.TEq(_),_) |
> > > > > (PC.TNotEq(_),_))::(PC.TWhen(_),_)::_
> > > > > +    | _::(PC.TWhen(_),_)::_
> > > > > +    | (PC.TComma(_),_)::_
> > > > > +    | (PC.TDirective(_),_)::_
> > > > > +    | (PC.TElse(_),_)::_
> > > > > +    | (PC.TReturn(_),_)::_
> > > > > +    | (PC.TMetaStm(_),_)::_
> > > > > +    | (PC.TMetaExp(_),_)::_
> > > > > +    | (PC.TMetaId(_),_)::_
> > > > > +    | (PC.TMetaLocalIdExp(_),_)::_
> > > > > +    | (PC.TEq(_),_)::_
> > > > > +    | (PC.TEllipsis(_),_)::_
> > > > > +    | (PC.TOEllipsis(_),_)::_
> > > > > +    | (PC.TCEllipsis(_),_)::_
> > > > > +    | (PC.TPOEllipsis(_),_)::_
> > > > > +    | (PC.TPCEllipsis(_),_)::_
> > > > > +    | (PC.TPtVirg(_),_)::_
> > > > > +    | (PC.TOBrace(_),_)::_
> > > > > +    | (PC.TCBrace(_),_)::_
> > > > > +    | (PC.TOPar(_),_)::_
> > > > > +    | (PC.TCPar(_),_)::_
> > > > > +    | (PC.TIdent(_),_)::_ -> false
> > > > > +    | _ -> true in
> > > > > +  let decl_or_proto clt info bef aft =
> > > > > +    match aft with
> > > > > +      (PC.TOBrace(_),_)::_ -> (((PC.TFunDecl(clt),info) ::
> > > > > bef),
> > > > > aft)
> > > > > +    | (PC.TPtVirg(_),_)::_ -> (((PC.TFunProto(clt),info) ::
> > > > > bef),
> > > > > aft)
> > > > > +    | _ -> raise Irrelevant in
> > > > > +  let rec loop acc = function
> > > > >        [] -> []
> > > > >      | t :: rest ->
> > > > >  	if is_par t || is_mid t || is_ident t
> > > > > @@ -1046,26 +1090,30 @@ let find_function_names l =
> > > > >  	    try
> > > > >  	      let (bef,aft) = split [] (t::rest) in
> > > > >  	      let rest = balanced_name 0 bef in
> > > > > +              (match aft with
> > > > > +                (PC.TPtVirg(_),_)::_
> > > > > +                 when not(is_permissible_proto acc) -> raise
> > > > > Irrelevant
> > > > > +              | _ ->
> > > > >  	      (match rest with
> > > > >  		(PC.TOPar(_),_)::_ ->
> > > > >  		  (match balanced_args 0 rest with
> > > > >  		    [] ->
> > > > >  		      let (_,info) as h = List.hd bef in
> > > > >  		      let clt = get_clt h in
> > > > > -		      (((PC.TFunDecl(clt),info) :: bef), aft)
> > > > > +                      decl_or_proto clt info bef aft
> > > > >  		  | (PC.TAttr_(_),_)::rest ->
> > > > >  		      (match balanced_args 0 rest with
> > > > >  			[] ->
> > > > >  			  let (_,info) as h = List.hd bef in
> > > > >  			  let clt = get_clt h in
> > > > > -			  (((PC.TFunDecl(clt),info) :: bef),
> > > > > aft)
> > > > > +                          decl_or_proto clt info bef aft
> > > > >  		      | _ -> raise Irrelevant)
> > > > >  		  | _ -> raise Irrelevant)
> > > > > -	      | _ -> raise Irrelevant)
> > > > > +	      | _ -> raise Irrelevant))
> > > > >  	    with Irrelevant -> ([t],rest) in
> > > > > -	  t @ (loop rest)
> > > > > -	else t :: (loop rest) in
> > > > > -  loop l
> > > > > +          t @ (loop (t @ acc) rest)
> > > > > +        else t :: (loop (t :: acc) rest) in
> > > > > +  loop [] l
> > > > > 
> > > > >  (* ---------------------------------------------------------
> > > > > ----
> > > > > ---------- *)
> > > > >  (* an attribute is an identifier that precedes another
> > > > > identifier
> > > > > and
> > > > > @@ -1168,6 +1216,8 @@ let detect_types in_meta_decls l =
> > > > >  	delim::newid::id::(loop false infn (ident::type_names)
> > > > > rest)
> > > > >      | ((PC.TFunDecl(_),_) as fn)::rest ->
> > > > >  	fn::(loop false 1 type_names rest)
> > > > > +    | ((PC.TFunProto(_),_) as fn)::rest ->
> > > > > +	fn::(loop false 1 type_names rest)
> > > > >      | ((PC.TOPar(_),_) as lp)::rest when infn > 0 ->
> > > > >  	lp::(loop false (infn + 1) type_names rest)
> > > > >      | ((PC.TCPar(_),_) as rp)::rest when infn > 0 ->
> > > > > @@ -1252,7 +1302,7 @@ let token2line (tok,_) =
> > > > >    | PC.TMetaDParamList(_,_,_,_,clt) |
> > > > > PC.TMetaFunc(_,_,_,clt)
> > > > >    | PC.TMetaLocalFunc(_,_,_,clt) | PC.TMetaPos(_,_,_,clt) |
> > > > > PC.TMetaCom(_,_,clt)
> > > > > 
> > > > > -  | PC.TFunDecl(clt)
> > > > > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> > > > >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> > > > >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TEllipsis(clt)
> > > > > 
> > > > > diff --git a/parsing_cocci/parser_cocci_menhir.mly
> > > > > b/parsing_cocci/parser_cocci_menhir.mly
> > > > > index 9e6c8a08..26958f63 100644
> > > > > --- a/parsing_cocci/parser_cocci_menhir.mly
> > > > > +++ b/parsing_cocci/parser_cocci_menhir.mly
> > > > > @@ -239,7 +239,8 @@ let inline_id aft = function
> > > > > 
> > > > >  %token <Data.clt> TVAEllipsis
> > > > >  %token <Data.clt> TIf TElse TWhile TFor TDo TSwitch TCase
> > > > > TDefault
> > > > > TReturn
> > > > > -%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof
> > > > > TFunDecl
> > > > > Tdecimal Texec
> > > > > +%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof
> > > > > TFunDecl
> > > > > TFunProto
> > > > > +%token <Data.clt> Tdecimal Texec
> > > > >  %token <string * Data.clt> TIdent TTypeId TDeclarerId
> > > > > TIteratorId
> > > > > TSymId
> > > > >  %token <Ast_cocci.added_string * Data.clt> TDirective
> > > > >  %token <Data.clt> TAttr_
> > > > > @@ -1439,7 +1440,8 @@
> > > > > reverse_separated_nonempty_llist(separator,
> > > > > X):
> > > > > 
> > > > >  funproto:
> > > > >    s=ioption(storage) i=ioption(Tinline) t=ctype
> > > > > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl)
> > > > > rp=TCPar
> > > > > pt=TPtVirg
> > > > > +  TFunProto id=fn_ident
> > > > > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar
> > > > > pt=TPtVirg
> > > > >        { let s = match s with None -> [] | Some s ->
> > > > > [Ast0.FStorage
> > > > > s] in
> > > > >          let i =
> > > > >  	  match i with
> > > > > @@ -1453,7 +1455,8 @@ funproto:
> > > > >  	      P.clt2mcode "(" lp, args, vararg, P.clt2mcode ")"
> > > > > rp,
> > > > >  	      P.clt2mcode ";" pt)) }
> > > > >  | i=Tinline s=storage t=ctype
> > > > > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl)
> > > > > rp=TCPar
> > > > > pt=TPtVirg
> > > > > +  TFunProto id=fn_ident
> > > > > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar
> > > > > pt=TPtVirg
> > > > >        { let s = [Ast0.FStorage s] in
> > > > >          let i = [Ast0.FInline (P.clt2mcode "inline" i)] in
> > > > >  	let t = [Ast0.FType t] in
> > > > > --
> > > > > 2.21.1
> > > > > 
> > > > > 

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

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

* Re: [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token
  2020-03-19 16:25         ` Jaskaran Singh
  2020-03-19 16:26           ` Jaskaran Singh
@ 2020-03-19 16:37           ` Julia Lawall
  1 sibling, 0 replies; 52+ messages in thread
From: Julia Lawall @ 2020-03-19 16:37 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Thu, 19 Mar 2020, Jaskaran Singh wrote:

> On Thu, 2020-03-19 at 16:54 +0100, Julia Lawall wrote:
> >
> > On Thu, 19 Mar 2020, Jaskaran Singh wrote:
> >
> > > On Wed, 2020-03-18 at 18:25 +0100, Julia Lawall wrote:
> > > > On Mon, 16 Mar 2020, Jaskaran Singh wrote:
> > > >
> > > > > To add the types ParenType and FunctionType to the SmPL AST, a
> > > > > reduce/reduce conflict with the funproto rule of the SmPL
> > > > > parser
> > > > > must be resolved. This requires explicitly identifying a
> > > > > function
> > > > > prototype by use of a token (TFunProto).
> > > > >
> > > > > While the correct method of identifying a function prototype
> > > > > would
> > > > > be to
> > > > > check if an identifier is preceded by a return type, it is
> > > > > challenging
> > > > > to implement. This is because implementing an OCaml function,
> > > > > to
> > > > > correctly determine a C type in SmPL, without the aid of Yacc,
> > > > > would
> > > > > have to handle a number of cases (disjunctions, typeof
> > > > > expressions,
> > > > > etc.).
> > > > >
> > > > > Thus, a slightly hacky approach is taken to determine a
> > > > > function
> > > > > prototype with not the best certainty but what works for most
> > > > > cases
> > > > > in SmPL. If the identifier is preceded by any token that does
> > > > > not
> > > > > seem to be part of a type, then it is not identified as a
> > > > > function
> > > > > prototype. Else, it is.
> > > >
> > > > This sacrifices the test case tests/p1p2.cocci:
> > > >
> > >
> > > What do you mean by sacrifice?
> >
> > That it doesn't work after applying 01.
> >
> > Does something that comes later make it work again?
> >
>
> Yes. I applied the series till 16/25 (Got a fatal error before that),
> where the test worked again.

I can see how 16 would fix some fatal errors, but I don't see why it would
fix the error in p1p2, which I see as:

plus: parse error:
  File "tests/p1p2.cocci", line 9, column 3, charpos = 93
  around = '(',
  whole content =  FN(P1, Error **errp);

This means that it failed in parsing the plus slice of the code, ie the
prototype with the attribute included.

julia


>
> Cheers,
> Jaskaran.
>
> > julia
> >
> > > The test case seems to work, but not with just 01 applied. Here's
> > > what
> > > the debugger tells me about the AST:
> > >
> > > Ast_cocci.FunProto
> > > ([Ast_cocci.FType
> > >    {Ast_cocci.node =
> > >      Ast_cocci.Type (false, None,
> > >       {Ast_cocci.node =
> > >         Ast_cocci.MetaType
> > >          ((("rule starting on line 11", "T"),
> > >            {Ast_cocci.line = 18; column = 1;
> > >             strbef = []; straft = [];
> > >             whitespace = " "},
> > >            Ast_cocci.CONTEXT (Ast_cocci.NoPos,
> > >             Ast_cocci.AFTER
> > >              ([[Ast_cocci.Directive
> > >                  [Ast_cocci.Space
> > >                    "__attribute__((nonnull(2)))"]]],
> > >              Ast_cocci.ONE)),
> > >            []),
> > >
> > > Maybe after the grammar changes, Menhir does some kind of
> > > lookahead?
> > > I'm not sure.
> > >
> > > Cheers,
> > > Jaskaran.
> > >
> > > > @@
> > > > typedef Error;
> > > > type T;
> > > > identifier FN;
> > > > parameter P1;
> > > > @@
> > > >  T
> > > > +__attribute__((nonnull(1)))
> > > >  FN(P1, Error **errp);
> > > >
> > > > @@
> > > > typedef Error;
> > > > type T;
> > > > identifier FN;
> > > > parameter P1;
> > > > parameter P2;
> > > > @@
> > > >  T
> > > > +__attribute__((nonnull(2)))
> > > >  FN(P1, P2, Error **errp);
> > > >
> > > > Normally, the only way that you can have a ) before a function
> > > > call
> > > > is
> > > > when there is a cast.  But hopefully in that case there would not
> > > > be
> > > > two
> > > > )) before the function call.  Can that get around the problem?
> > > >
> > > > julia
> > > >
> > > >
> > > >
> > > >
> > > > > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > > > > ---
> > > > >  parsing_cocci/parse_cocci.ml          | 72
> > > > > +++++++++++++++++++++++----
> > > > >  parsing_cocci/parser_cocci_menhir.mly |  9 ++--
> > > > >  2 files changed, 67 insertions(+), 14 deletions(-)
> > > > >
> > > > > diff --git a/parsing_cocci/parse_cocci.ml
> > > > > b/parsing_cocci/parse_cocci.ml
> > > > > index 679d213a..4b2cb7e4 100644
> > > > > --- a/parsing_cocci/parse_cocci.ml
> > > > > +++ b/parsing_cocci/parse_cocci.ml
> > > > > @@ -295,6 +295,7 @@ let token2c (tok,_) add_clt =
> > > > >    | PC.TLineEnd(clt) -> "line end"
> > > > >    | PC.TInvalid -> "invalid"
> > > > >    | PC.TFunDecl(clt) -> "fundecl"
> > > > > +  | PC.TFunProto(clt) -> "funproto"
> > > > >
> > > > >    | PC.TIso -> "<=>"
> > > > >    | PC.TRightIso -> "=>"
> > > > > @@ -480,7 +481,7 @@ let get_clt (tok,_) =
> > > > >
> > > > >    | PC.TOPar0(_,clt) | PC.TMid0(_,clt) | PC.TAnd0(_,clt) |
> > > > > PC.TCPar0(_,clt)
> > > > >    | PC.TOEllipsis(clt) | PC.TCEllipsis(clt)
> > > > > -  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt)
> > > > > +  | PC.TPOEllipsis(clt) | PC.TPCEllipsis(clt) |
> > > > > PC.TFunProto(clt)
> > > > >    | PC.TFunDecl(clt) | PC.TDirective(_,clt) | PC.TAttr_(clt)
> > > > >    | PC.TLineEnd(clt) -> clt
> > > > >    | PC.TVAEllipsis(clt) -> clt
> > > > > @@ -718,6 +719,7 @@ let update_clt (tok,x) clt =
> > > > >
> > > > >    | PC.TLineEnd(_) -> (PC.TLineEnd(clt),x)
> > > > >    | PC.TFunDecl(_) -> (PC.TFunDecl(clt),x)
> > > > > +  | PC.TFunProto(_) -> (PC.TFunProto(clt),x)
> > > > >    | PC.TTildeExclEq(_) -> (PC.TTildeExclEq(clt),x)
> > > > >    | PC.TDirective(a,_) -> (PC.TDirective(a,clt),x)
> > > > >    | PC.TAttr_(_) -> (PC.TAttr_(clt),x)
> > > > > @@ -925,7 +927,7 @@ let split_token ((tok,_) as t) =
> > > > >    | PC.TInitialize | PC.TFinalize -> ([t],[t])
> > > > >    | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) |
> > > > > PC.TMetaCom(_,_,clt)
> > > > > -> split t clt
> > > > >
> > > > > -  | PC.TFunDecl(clt)
> > > > > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> > > > >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> > > > >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TLineEnd(clt)
> > > > >    | PC.TEllipsis(clt)
> > > > > @@ -1006,7 +1008,8 @@ let find_function_names l =
> > > > >      | _ -> false in
> > > > >    let rec split acc = function
> > > > >        [] | [_] -> raise Irrelevant
> > > > > -    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) ::
> > > > > rest
> > > > > ->
> > > > > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TOBrace(_),_) as t2) ::
> > > > > rest
> > > > > +    | ((PC.TCPar(_),_) as t1) :: ((PC.TPtVirg(_),_) as t2) ::
> > > > > rest
> > > > > ->
> > > > >  	(List.rev (t1::acc),(t2::rest))
> > > > >      | x::xs -> split (x::acc) xs in
> > > > >    let rec balanced_name level = function
> > > > > @@ -1037,7 +1040,48 @@ let find_function_names l =
> > > > >      | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_ ->
> > > > >  	raise Irrelevant
> > > > >      | t::rest -> balanced_args level rest in
> > > > > -  let rec loop = function
> > > > > +  let rec is_permissible_proto = function
> > > > > +      [] -> false
> > > > > +    | (PC.TCPar0(_),_)::
> > > > > +      ((PC.TMid0(_),_) | (PC.TAnd0(_),_))::
> > > > > +      (PC.TOPar0(_),_)::_ -> false
> > > > > +    | (PC.TOPar0(_),_)::rest
> > > > > +    | (PC.TCPar0(_),_)::rest -> is_permissible_proto rest
> > > > > +    | x::rest when is_mid x ->
> > > > > +        let rec loop = function
> > > > > +          [] -> false
> > > > > +        | (PC.TOPar0(_),_)::xs -> is_permissible_proto xs
> > > > > +        | x::xs -> loop xs in
> > > > > +        loop rest
> > > > > +    | _::((PC.TEq(_),_) |
> > > > > (PC.TNotEq(_),_))::(PC.TWhen(_),_)::_
> > > > > +    | _::(PC.TWhen(_),_)::_
> > > > > +    | (PC.TComma(_),_)::_
> > > > > +    | (PC.TDirective(_),_)::_
> > > > > +    | (PC.TElse(_),_)::_
> > > > > +    | (PC.TReturn(_),_)::_
> > > > > +    | (PC.TMetaStm(_),_)::_
> > > > > +    | (PC.TMetaExp(_),_)::_
> > > > > +    | (PC.TMetaId(_),_)::_
> > > > > +    | (PC.TMetaLocalIdExp(_),_)::_
> > > > > +    | (PC.TEq(_),_)::_
> > > > > +    | (PC.TEllipsis(_),_)::_
> > > > > +    | (PC.TOEllipsis(_),_)::_
> > > > > +    | (PC.TCEllipsis(_),_)::_
> > > > > +    | (PC.TPOEllipsis(_),_)::_
> > > > > +    | (PC.TPCEllipsis(_),_)::_
> > > > > +    | (PC.TPtVirg(_),_)::_
> > > > > +    | (PC.TOBrace(_),_)::_
> > > > > +    | (PC.TCBrace(_),_)::_
> > > > > +    | (PC.TOPar(_),_)::_
> > > > > +    | (PC.TCPar(_),_)::_
> > > > > +    | (PC.TIdent(_),_)::_ -> false
> > > > > +    | _ -> true in
> > > > > +  let decl_or_proto clt info bef aft =
> > > > > +    match aft with
> > > > > +      (PC.TOBrace(_),_)::_ -> (((PC.TFunDecl(clt),info) ::
> > > > > bef),
> > > > > aft)
> > > > > +    | (PC.TPtVirg(_),_)::_ -> (((PC.TFunProto(clt),info) ::
> > > > > bef),
> > > > > aft)
> > > > > +    | _ -> raise Irrelevant in
> > > > > +  let rec loop acc = function
> > > > >        [] -> []
> > > > >      | t :: rest ->
> > > > >  	if is_par t || is_mid t || is_ident t
> > > > > @@ -1046,26 +1090,30 @@ let find_function_names l =
> > > > >  	    try
> > > > >  	      let (bef,aft) = split [] (t::rest) in
> > > > >  	      let rest = balanced_name 0 bef in
> > > > > +              (match aft with
> > > > > +                (PC.TPtVirg(_),_)::_
> > > > > +                 when not(is_permissible_proto acc) -> raise
> > > > > Irrelevant
> > > > > +              | _ ->
> > > > >  	      (match rest with
> > > > >  		(PC.TOPar(_),_)::_ ->
> > > > >  		  (match balanced_args 0 rest with
> > > > >  		    [] ->
> > > > >  		      let (_,info) as h = List.hd bef in
> > > > >  		      let clt = get_clt h in
> > > > > -		      (((PC.TFunDecl(clt),info) :: bef), aft)
> > > > > +                      decl_or_proto clt info bef aft
> > > > >  		  | (PC.TAttr_(_),_)::rest ->
> > > > >  		      (match balanced_args 0 rest with
> > > > >  			[] ->
> > > > >  			  let (_,info) as h = List.hd bef in
> > > > >  			  let clt = get_clt h in
> > > > > -			  (((PC.TFunDecl(clt),info) :: bef),
> > > > > aft)
> > > > > +                          decl_or_proto clt info bef aft
> > > > >  		      | _ -> raise Irrelevant)
> > > > >  		  | _ -> raise Irrelevant)
> > > > > -	      | _ -> raise Irrelevant)
> > > > > +	      | _ -> raise Irrelevant))
> > > > >  	    with Irrelevant -> ([t],rest) in
> > > > > -	  t @ (loop rest)
> > > > > -	else t :: (loop rest) in
> > > > > -  loop l
> > > > > +          t @ (loop (t @ acc) rest)
> > > > > +        else t :: (loop (t :: acc) rest) in
> > > > > +  loop [] l
> > > > >
> > > > >  (* ---------------------------------------------------------
> > > > > ----
> > > > > ---------- *)
> > > > >  (* an attribute is an identifier that precedes another
> > > > > identifier
> > > > > and
> > > > > @@ -1168,6 +1216,8 @@ let detect_types in_meta_decls l =
> > > > >  	delim::newid::id::(loop false infn (ident::type_names)
> > > > > rest)
> > > > >      | ((PC.TFunDecl(_),_) as fn)::rest ->
> > > > >  	fn::(loop false 1 type_names rest)
> > > > > +    | ((PC.TFunProto(_),_) as fn)::rest ->
> > > > > +	fn::(loop false 1 type_names rest)
> > > > >      | ((PC.TOPar(_),_) as lp)::rest when infn > 0 ->
> > > > >  	lp::(loop false (infn + 1) type_names rest)
> > > > >      | ((PC.TCPar(_),_) as rp)::rest when infn > 0 ->
> > > > > @@ -1252,7 +1302,7 @@ let token2line (tok,_) =
> > > > >    | PC.TMetaDParamList(_,_,_,_,clt) | PC.TMetaFunc(_,_,_,clt)
> > > > >    | PC.TMetaLocalFunc(_,_,_,clt) | PC.TMetaPos(_,_,_,clt) |
> > > > > PC.TMetaCom(_,_,clt)
> > > > >
> > > > > -  | PC.TFunDecl(clt)
> > > > > +  | PC.TFunDecl(clt) | PC.TFunProto(clt)
> > > > >    | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
> > > > >    | PC.TAny(clt) | PC.TStrict(clt) | PC.TEllipsis(clt)
> > > > >
> > > > > diff --git a/parsing_cocci/parser_cocci_menhir.mly
> > > > > b/parsing_cocci/parser_cocci_menhir.mly
> > > > > index 9e6c8a08..26958f63 100644
> > > > > --- a/parsing_cocci/parser_cocci_menhir.mly
> > > > > +++ b/parsing_cocci/parser_cocci_menhir.mly
> > > > > @@ -239,7 +239,8 @@ let inline_id aft = function
> > > > >
> > > > >  %token <Data.clt> TVAEllipsis
> > > > >  %token <Data.clt> TIf TElse TWhile TFor TDo TSwitch TCase
> > > > > TDefault
> > > > > TReturn
> > > > > -%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof
> > > > > TFunDecl
> > > > > Tdecimal Texec
> > > > > +%token <Data.clt> TBreak TContinue TGoto TSizeof TTypeof
> > > > > TFunDecl
> > > > > TFunProto
> > > > > +%token <Data.clt> Tdecimal Texec
> > > > >  %token <string * Data.clt> TIdent TTypeId TDeclarerId
> > > > > TIteratorId
> > > > > TSymId
> > > > >  %token <Ast_cocci.added_string * Data.clt> TDirective
> > > > >  %token <Data.clt> TAttr_
> > > > > @@ -1439,7 +1440,8 @@
> > > > > reverse_separated_nonempty_llist(separator,
> > > > > X):
> > > > >
> > > > >  funproto:
> > > > >    s=ioption(storage) i=ioption(Tinline) t=ctype
> > > > > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl)
> > > > > rp=TCPar
> > > > > pt=TPtVirg
> > > > > +  TFunProto id=fn_ident
> > > > > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> > > > >        { let s = match s with None -> [] | Some s ->
> > > > > [Ast0.FStorage
> > > > > s] in
> > > > >          let i =
> > > > >  	  match i with
> > > > > @@ -1453,7 +1455,8 @@ funproto:
> > > > >  	      P.clt2mcode "(" lp, args, vararg, P.clt2mcode ")"
> > > > > rp,
> > > > >  	      P.clt2mcode ";" pt)) }
> > > > >  | i=Tinline s=storage t=ctype
> > > > > -  id=fn_ident lp=TOPar arglist=arg_list(name_opt_decl)
> > > > > rp=TCPar
> > > > > pt=TPtVirg
> > > > > +  TFunProto id=fn_ident
> > > > > +  lp=TOPar arglist=arg_list(name_opt_decl) rp=TCPar pt=TPtVirg
> > > > >        { let s = [Ast0.FStorage s] in
> > > > >          let i = [Ast0.FInline (P.clt2mcode "inline" i)] in
> > > > >  	let t = [Ast0.FType t] in
> > > > > --
> > > > > 2.21.1
> > > > >
> > > > >
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] [PATCH 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType
  2020-03-16 19:20 [Cocci] [PATCH 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType Markus Elfring
@ 2020-03-17  5:28 ` Jaskaran Singh
  0 siblings, 0 replies; 52+ messages in thread
From: Jaskaran Singh @ 2020-03-17  5:28 UTC (permalink / raw)
  To: Markus Elfring; +Cc: linux-kernel-mentees, cocci

On Mon, 2020-03-16 at 20:20 +0100, Markus Elfring wrote:
> > ParenType and FunctionType are added to the SmPL ASTs.
> > Add cases for these types in ….ml.
> 
> A change description template was used several times.
> I wonder if there is really a need to modify only a single OCaml
> source file
> in these update steps.
> How do you think about to combine such changes in a bigger update
> step?
> 

These are separated this way so that it's easier for Julia to review.
She will probably just squash all 26 of these together and apply them
later.

Cheers,
Jaskaran.

> Regards,
> Markus

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

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

* Re: [Cocci] [PATCH 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType
@ 2020-03-16 19:20 Markus Elfring
  2020-03-17  5:28 ` Jaskaran Singh
  0 siblings, 1 reply; 52+ messages in thread
From: Markus Elfring @ 2020-03-16 19:20 UTC (permalink / raw)
  To: Jaskaran Singh, cocci; +Cc: linux-kernel-mentees

> ParenType and FunctionType are added to the SmPL ASTs.
> Add cases for these types in ….ml.

A change description template was used several times.
I wonder if there is really a need to modify only a single OCaml source file
in these update steps.
How do you think about to combine such changes in a bigger update step?

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

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

end of thread, back to index

Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 10:02 [Cocci] [PATCH 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
2020-03-16 10:02 ` [Cocci] [PATCH 01/26] parsing_cocci: Add Function Prototype token Jaskaran Singh
2020-03-18 17:25   ` Julia Lawall
2020-03-19 13:58     ` Jaskaran Singh
2020-03-19 15:54       ` Julia Lawall
2020-03-19 16:25         ` Jaskaran Singh
2020-03-19 16:26           ` Jaskaran Singh
2020-03-19 16:37           ` Julia Lawall
2020-03-16 10:02 ` [Cocci] [PATCH 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs Jaskaran Singh
2020-03-18 17:27   ` Julia Lawall
2020-03-16 10:02 ` [Cocci] [PATCH 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules Jaskaran Singh
2020-03-18 17:31   ` Julia Lawall
2020-03-19  5:11     ` Jaskaran Singh
2020-03-19  7:02       ` Julia Lawall
2020-03-16 10:02 ` [Cocci] [PATCH 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType Jaskaran Singh
2020-03-18 17:42   ` Julia Lawall
2020-03-16 10:02 ` [Cocci] [PATCH 05/26] " Jaskaran Singh
2020-03-17  5:59   ` [Cocci] [PATCH 05/26] parsing_cocci: visitor_ast: " Jaskaran Singh
2020-03-17  7:16     ` Julia Lawall
2020-03-17  8:43   ` [Cocci] [PATCH v2 " Jaskaran Singh
2020-03-18 17:45     ` Julia Lawall
2020-03-16 10:02 ` [Cocci] [PATCH 06/26] parsing_cocci: arity: " Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 07/26] parsing_cocci: index: " Jaskaran Singh
2020-03-18 18:35   ` Julia Lawall
2020-03-16 10:03 ` [Cocci] [PATCH 08/26] parsing_cocci: context_neg: " Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 09/26] parsing_cocci: unparse_ast0: " Jaskaran Singh
2020-03-18 18:36   ` Julia Lawall
2020-03-16 10:03 ` [Cocci] [PATCH 10/26] parsing_cocci: single_statement: " Jaskaran Singh
2020-03-18 18:37   ` Julia Lawall
2020-03-16 10:03 ` [Cocci] [PATCH 11/26] parsing_cocci: function_prototypes: " Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 12/26] parsing_cocci: check_meta: " Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 13/26] parsing_cocci: iso_pattern: " Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 14/26] parsing_cocci: adjust_pragmas: " Jaskaran Singh
2020-03-18 18:42   ` Julia Lawall
2020-03-16 10:03 ` [Cocci] [PATCH 15/26] parsing_cocci: compute_lines: " Jaskaran Singh
2020-03-18 18:43   ` Julia Lawall
2020-03-16 10:03 ` [Cocci] [PATCH 16/26] parsing_cocci: ast0toast: " Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 19/26] parsing_cocci: disjdistr: " Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 20/26] parsing_cocci: ast_cocci: " Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType Jaskaran Singh
2020-03-18 18:45   ` Julia Lawall
2020-03-16 10:03 ` [Cocci] [PATCH 22/26] parsing_c: unparse_cocci: " Jaskaran Singh
2020-03-18 18:47   ` Julia Lawall
2020-03-16 10:03 ` [Cocci] [PATCH 23/26] engine: Match A.ParenType and A.FunctionType Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 24/26] tools: spgen: Add cases for ParenType/FunctionType Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 25/26] cocci: Remove Ast_cocci.FunctionPointer Jaskaran Singh
2020-03-16 10:03 ` [Cocci] [PATCH 26/26] tests: Add test case for array of function pointers Jaskaran Singh
2020-03-18 18:48   ` Julia Lawall
2020-03-16 19:20 [Cocci] [PATCH 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType Markus Elfring
2020-03-17  5:28 ` Jaskaran Singh

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