Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs
@ 2020-03-20  7:01 Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 01/26] parsing_cocci: Add Function Prototype token Jaskaran Singh
                   ` (25 more replies)
  0 siblings, 26 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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, a rule similar to that of the C parser's direct
declarator rule is implemented, and used wherever suitable.
The direct declarator rule produces 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.

Changes in v3:
--------------
- Patch 01/26:
    - Add case for __attribute__((.*)) in is_permissible_proto
      so that the p1p2 test case passes successfully with just
      01/26 applied.
    - Add case for typeof(.*) in is_permissible_proto.
    - Change the function balanced_args in find_function_names
      by adding a new argument "reverse". reverse is a bool that
      indicates whether the given list is reversed, and if it is
      then when to return the rest of the tokens and how to increment
      or decrement the current depth/level of the parentheses.
- Patch 02/26:
    Briefly describe how the new constructs are used in
    the SmPL AST.
- Patch 03/26:
    State examples of productions that are not supported
    by the direct_declarator and direct_abstract_d rules, and how some
    of these could be supported.
- Patch 04/26:
    - Group together repeated code in a function.
    - Place match statement on a single line.
    - Change spaces to tabs in a ParenType/FunctionType cases of
      named_type and named_type_typedef.
- Patch 05/26:
    - Group together repeated code in a function.
    - Place match statement on a single line.
- Patch 07/26:
    Change the comment in the head of index.ml to indicate
    which indexes have now been used.
- Patch 09/26:
    Group together repeated code in a function.
- Patch 10/26:
    Change ParenType's case as per what term is to the
    left.
- Patch 14/26:
    Change ParenType's case as per what term is to the
    left.
- Patch 15/26:
    Change promote_mcode rp to promote_mcode lp for
    ParenType's case.
- Patch 21/26:
    Group together repeated code in a function.
- Patch 22/26:
    - Group together repeated code in a function.
    - Add FunctionType case to named_type function.

Changes in v2:
--------------
- Patch 05/26: Change "visitor_ast0" in patch subject to "visitor_ast"

[PATCH v3 01/26] parsing_cocci: Add Function Prototype token
[PATCH v3 02/26] parsing_cocci: AST: Add ParenType and FunctionType
[PATCH v3 03/26] parsing_cocci: parser: Add
[PATCH v3 04/26] parsing_cocci: visitor_ast0: Add cases for
[PATCH v3 05/26] parsing_cocci: visitor_ast: Add cases for
[PATCH v3 06/26] parsing_cocci: arity: Add cases for
[PATCH v3 07/26] parsing_cocci: index: Add cases for
[PATCH v3 08/26] parsing_cocci: context_neg: Add cases for
[PATCH v3 09/26] parsing_cocci: unparse_ast0: Add cases for
[PATCH v3 10/26] parsing_cocci: single_statement: Add cases for
[PATCH v3 11/26] parsing_cocci: function_prototypes: Add cases for
[PATCH v3 12/26] parsing_cocci: check_meta: Add cases for
[PATCH v3 13/26] parsing_cocci: iso_pattern: Add cases for
[PATCH v3 14/26] parsing_cocci: adjust_pragmas: Add cases for
[PATCH v3 15/26] parsing_cocci: compute_lines: Add cases for
[PATCH v3 16/26] parsing_cocci: ast0toast: Add cases for
[PATCH v3 17/26] parsing_cocci: type_cocci: Add
[PATCH v3 18/26] parsing_cocci: unify_ast: Add cases for
[PATCH v3 19/26] parsing_cocci: disjdistr: Add cases for
[PATCH v3 20/26] parsing_cocci: ast_cocci: Add cases for
[PATCH v3 21/26] parsing_cocci: pretty_print_cocci: Print
[PATCH v3 22/26] parsing_c: unparse_cocci: Print
[PATCH v3 23/26] engine: Match A.ParenType and A.FunctionType
[PATCH v3 24/26] tools: spgen: Add cases for ParenType/FunctionType
[PATCH v3 25/26] cocci: Remove Ast_cocci.FunctionPointer
[PATCH v3 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               |   72 +++++++--
 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                   |    5 
 parsing_cocci/iso_pattern.ml             |   17 --
 parsing_cocci/parse_cocci.ml             |   97 +++++++++---
 parsing_cocci/parser_cocci_menhir.mly    |  248 +++++++++++++++----------------
 parsing_cocci/pretty_print_cocci.ml      |   64 ++++++--
 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            |   51 ++++--
 parsing_cocci/visitor_ast.ml             |   92 ++++++++---
 parsing_cocci/visitor_ast0.ml            |  198 ++++++++++++++++++------
 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, 732 insertions(+), 416 deletions(-)


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

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

* [Cocci] [PATCH v3 01/26] parsing_cocci: Add Function Prototype token
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs Jaskaran Singh
                   ` (24 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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          | 97 +++++++++++++++++++++------
 parsing_cocci/parser_cocci_menhir.mly |  9 ++-
 2 files changed, 83 insertions(+), 23 deletions(-)

diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml
index 679d213a..e92a01d0 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
@@ -1024,20 +1027,68 @@ let find_function_names l =
     | t::rest when is_ident t && level = 0 -> rest
     | t::rest when is_ident t || is_mid t -> balanced_name level rest
     | _ -> raise Irrelevant in
-  let rec balanced_args level = function
+  let rec balanced_args level reverse = function
       [] -> raise Irrelevant
     | (PC.TCPar(_),_)::rest ->
-	let level = level - 1 in
-	if level = 0
+	let level = if reverse then level + 1 else level - 1 in
+	if level = 0 && not(reverse)
 	then rest
-	else balanced_args level rest
+	else balanced_args level reverse rest
     | (PC.TOPar(_),_)::rest ->
-	let level = level + 1 in
-	balanced_args level rest
+	let level = if reverse then level - 1 else level + 1 in
+	if level = 0 && reverse
+	then rest
+	else balanced_args level reverse rest
     | (PC.TArobArob,_)::_ | (PC.TArob,_)::_ | (PC.EOF,_)::_ ->
 	raise Irrelevant
-    | t::rest -> balanced_args level rest in
-  let rec loop = function
+    | t::rest -> balanced_args level reverse rest in
+  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.TCPar(_),_)::rest as l) ->
+      let l = balanced_args 0 true l in
+      let x = match l with
+        (PC.TAttr_(_),_)::rest -> is_permissible_proto rest
+      | (PC.TTypeof(_),_)::_ -> true
+      | _ -> false in x
+    | _::((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.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 +1097,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
+		  (match balanced_args 0 false 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
+		      (match balanced_args 0 false 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 +1223,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 +1309,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] 27+ messages in thread

* [Cocci] [PATCH v3 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 01/26] parsing_cocci: Add Function Prototype token Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules Jaskaran Singh
                   ` (23 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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.

For a function pointer as follows:

int (*x)(params)

The SmPL AST would be as follows:

ParenType -> Pointer -> FunctionType params -> BaseType int

For an array of function pointers as follows:

int (*x[2])(params)

The SmPL AST would be as follows:

ParenType -> Array 2 -> Pointer -> FunctionType params -> BaseType int

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] 27+ messages in thread

* [Cocci] [PATCH v3 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 01/26] parsing_cocci: Add Function Prototype token Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 02/26] parsing_cocci: AST: Add ParenType and FunctionType to SmPL ASTs Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType Jaskaran Singh
                   ` (22 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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. Examples of productions that are not supported are as
follows:

- int (*x[][])(params)
  An array of arrays of function pointers

- int (**x[])(params)
  An array of pointers to function pointers

- int ((*x))(params)

The first two can be supported by implementing a loop of some kind to
check for array of array of ... and pointer to pointer to ...

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] 27+ messages in thread

* [Cocci] [PATCH v3 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (2 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 03/26] parsing_cocci: parser: Add direct_declarator/direct_abstract_d rules Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 05/26] parsing_cocci: visitor_ast: " Jaskaran Singh
                   ` (21 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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 | 147 ++++++++++++++++++++++++++++++++++
 1 file changed, 147 insertions(+)

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index c282e1f8..76ec4e5c 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,68 @@ 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) =
+    let function_pointer ty1 array_decs =
+      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 (array_n, array_t) =
+                match array_decs with
+                  Some(lb1,size1,rb1) ->
+                    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
+                    ([lb1_n;size_n;rb1_n],
+                     Some(lb1,size1,rb1))
+                | None -> ([], None) 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
+              let bind_val =
+                multibind ([ty_n;lp_n;star_n]
+                @ idl @ array_n @ [rp_n;lp3_n;params_n;rp3_n]) in
+              let inner_type =
+                let inner_type1 =
+                  Ast0.rewrap ty2
+                    (Ast0.Pointer
+                       (Ast0.rewrap ty3
+                          (Ast0.FunctionType
+                             (typ,lp3,params,rp3)),star)) in
+                match array_t with
+                    Some(lb1,size1,rb1) ->
+                      Ast0.rewrap ty1
+                        (Ast0.Array(inner_type1,lb1,size1,rb1))
+                  | None -> inner_type1 in
+              ((bind_val, Ast0.ParenType (lp,inner_type,rp)), idu)
+        | _ -> failwith "ParenType Visitor_ast0")
+      | _ -> failwith "ParenType Visitor_ast0" in
+    match Ast0.unwrap ty with
+      Ast0.Array(ty1,lb1,size,rb1) ->
+        function_pointer ty1 (Some(lb1,size,rb1))
+    | Ast0.Pointer(ty1,star) ->
+        function_pointer ty None
+    | _ -> 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 +514,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 +555,69 @@ 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) =
+    let function_pointer ty1 array_decs =
+      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) = typeC a in ([b],Some c)
+                | None -> ([],None) in
+              let (array_n, array_t) =
+                match array_decs with
+                  Some(lb1,size1,rb1) ->
+                    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
+                    ([lb1_n;size_n;rb1_n],
+                     Some(lb1,size1,rb1))
+                | None -> ([], None) 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
+              let bind_val =
+                multibind ([ty_n;lp_n;star_n]
+                @ idl @ array_n @ [rp_n;lp3_n;params_n;rp3_n]) in
+              let inner_type =
+                let inner_type1 =
+                Ast0.rewrap ty2
+                  (Ast0.Pointer
+                     (Ast0.rewrap ty3
+                        (Ast0.FunctionType
+                           (typ,lp3,params,rp3)),star)) in
+                match array_t with
+                    Some(lb1,size1,rb1) ->
+                      Ast0.rewrap ty1
+                        (Ast0.Array(inner_type1,lb1,size1,rb1))
+                  | None -> inner_type1 in
+              ((bind_val, Ast0.ParenType (lp,inner_type,rp)), idu)
+        | _ -> failwith "ParenType Visitor_ast0")
+      | _ -> failwith "ParenType Visitor_ast0" in
+    match Ast0.unwrap ty with
+      Ast0.Array(ty1,lb1,size,rb1) ->
+        function_pointer ty1 (Some(lb1,size,rb1))
+    | Ast0.Pointer(ty1,star) ->
+        function_pointer ty None
+    | _ -> 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 +629,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] 27+ messages in thread

* [Cocci] [PATCH v3 05/26] parsing_cocci: visitor_ast: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (3 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 04/26] parsing_cocci: visitor_ast0: Add cases for ParenType/FunctionType Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 06/26] parsing_cocci: arity: " Jaskaran Singh
                   ` (20 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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 | 66 ++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 3d5de794..6f2e3dab 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -318,6 +318,52 @@ 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) =
+    let function_pointer ty1 array_dec =
+      match Ast.unwrap ty1 with
+       Ast.Type(_,_,fty1) ->
+        (match Ast.unwrap fty1 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 ltyp = fullType ty3 in
+                 let llp = string_mcode lp in
+                 let lstar = string_mcode star in
+                 let lid =
+                   match id with
+                     Some idd -> [ident idd]
+                   | None -> [] in
+                 let larray =
+                   match array_dec with
+                     Some(lb1,size1,rb1) ->
+                       let llb1 = string_mcode lb1 in
+                       let lsize1 = get_option expression size1 in
+                       let lrb1 = string_mcode rb1 in
+                       [llb1;lsize1;lrb1]
+                   | None -> [] in
+                 let lrp = string_mcode rp in
+                 let llp3 = string_mcode lp3 in
+                 let lparams = parameter_dots params in
+                 let lrp3 = string_mcode rp3 in
+                 multibind
+                   ([ltyp;llp;lstar] @ lid @ larray @
+                    [lrp;llp3;lparams;lrp3])
+             | _ -> failwith "ParenType Visitor_ast")
+           | _ -> failwith "ParenType Visitor_ast")
+         | _ -> failwith "ParenType Visitor_ast")
+       | _ -> failwith "ParenType Visitor_ast" in
+    match Ast.unwrap ty with
+      Ast.Type(_,_,fty1) ->
+        (match Ast.unwrap fty1 with
+          Ast.Array(ty1,lb1,size,rb1) ->
+            function_pointer ty1 (Some(lb1,size,rb1))
+        | Ast.Pointer(ty1,star) ->
+            function_pointer ty None
+        | _ -> failwith "ParenType Visitor_ast")
+     | _ -> failwith "ParenType Visitor_ast"
+
   and typeC ty =
     let k ty =
       match Ast.unwrap ty with
@@ -332,6 +378,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 +438,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 +1308,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] 27+ messages in thread

* [Cocci] [PATCH v3 06/26] parsing_cocci: arity: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (4 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 05/26] parsing_cocci: visitor_ast: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 07/26] parsing_cocci: index: " Jaskaran Singh
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 07/26] parsing_cocci: index: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (5 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 06/26] parsing_cocci: arity: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 08/26] parsing_cocci: context_neg: " Jaskaran Singh
                   ` (18 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
index a1103503..088db18a 100644
--- a/parsing_cocci/index.ml
+++ b/parsing_cocci/index.ml
@@ -6,7 +6,7 @@
 
 (* create an index for each constructor *)
 (* current max is 188, also unused: 8-9, 15, 39, 40, 42, 46, 57, 65, 85-86,
- 113-115, 138-140, 162 *)
+ 113-115, 140, 162 *)
 
 (* doesn't really work - requires that identical terms with no token
 subterms (eg dots) not appear on the same line *)
@@ -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] 27+ messages in thread

* [Cocci] [PATCH v3 08/26] parsing_cocci: context_neg: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (6 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 07/26] parsing_cocci: index: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 09/26] parsing_cocci: unparse_ast0: " Jaskaran Singh
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 09/26] parsing_cocci: unparse_ast0: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (7 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 08/26] parsing_cocci: context_neg: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 10/26] parsing_cocci: single_statement: " Jaskaran Singh
                   ` (16 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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 | 38 +++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index 5d450e0e..76288087 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -292,6 +292,35 @@ 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 =
+  let function_pointer ty1 array_decs =
+    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;
+            let _ =
+              match array_decs with
+                Some(lb1,size,rb1) ->
+                  mcode print_string lb1;
+                  print_option expression size;
+                  mcode print_string rb1
+              | None -> () in
+            mcode print_string rp;
+            mcode print_string lp3;
+            parameter_list params;
+            mcode print_string rp3;
+	| _ -> failwith "ParenType Unparse_ast0")
+    | _ -> failwith "ParenType Unparse_ast0" in
+  match Ast0.unwrap ty with
+    Ast0.Array(ty1,lb1,size,rb1) ->
+      function_pointer ty1 (Some(lb1,size,rb1))
+  | Ast0.Pointer(ty1,star) ->
+      function_pointer ty None
+  | _ -> failwith "ParenType Unparse_ast0"
+
 and typeC t =
   print_context t
     (function _ ->
@@ -306,6 +335,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 +403,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] 27+ messages in thread

* [Cocci] [PATCH v3 10/26] parsing_cocci: single_statement: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (8 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 09/26] parsing_cocci: unparse_ast0: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 11/26] parsing_cocci: function_prototypes: " Jaskaran Singh
                   ` (15 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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..2bd4c202 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) -> modif_before_mcode lp
+  | 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] 27+ messages in thread

* [Cocci] [PATCH v3 11/26] parsing_cocci: function_prototypes: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (9 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 10/26] parsing_cocci: single_statement: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 12/26] parsing_cocci: check_meta: " Jaskaran Singh
                   ` (14 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 12/26] parsing_cocci: check_meta: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (10 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 11/26] parsing_cocci: function_prototypes: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 13/26] parsing_cocci: iso_pattern: " Jaskaran Singh
                   ` (13 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 13/26] parsing_cocci: iso_pattern: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (11 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 12/26] parsing_cocci: check_meta: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 14/26] parsing_cocci: adjust_pragmas: " Jaskaran Singh
                   ` (12 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 14/26] parsing_cocci: adjust_pragmas: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (12 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 13/26] parsing_cocci: iso_pattern: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 15/26] parsing_cocci: compute_lines: " Jaskaran Singh
                   ` (11 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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..6d2a9c5d 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_mcode lp t (function lp -> 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] 27+ messages in thread

* [Cocci] [PATCH v3 15/26] parsing_cocci: compute_lines: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (13 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 14/26] parsing_cocci: adjust_pragmas: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 16/26] parsing_cocci: ast0toast: " Jaskaran Singh
                   ` (10 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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..c47a06ba 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 lp)
+  | 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] 27+ messages in thread

* [Cocci] [PATCH v3 16/26] parsing_cocci: ast0toast: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (14 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 15/26] parsing_cocci: compute_lines: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types Jaskaran Singh
                   ` (9 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (15 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 16/26] parsing_cocci: ast0toast: " Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType Jaskaran Singh
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (16 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 17/26] parsing_cocci: type_cocci: Add ParenType/FunctionType to types Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 19/26] parsing_cocci: disjdistr: " Jaskaran Singh
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 19/26] parsing_cocci: disjdistr: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (17 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 18/26] parsing_cocci: unify_ast: Add cases for ParenType/FunctionType Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 20/26] parsing_cocci: ast_cocci: " Jaskaran Singh
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 20/26] parsing_cocci: ast_cocci: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (18 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 19/26] parsing_cocci: disjdistr: " Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType Jaskaran Singh
                   ` (5 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (19 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 20/26] parsing_cocci: ast_cocci: " Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 22/26] parsing_c: unparse_cocci: " Jaskaran Singh
                   ` (4 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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 | 50 +++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml
index 6338e464..8055ba3b 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -403,6 +403,47 @@ 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 =
+  let function_pointer ty1 array_dec =
+    match Ast.unwrap ty1 with
+     Ast.Type(_,_,fty1) ->
+      (match Ast.unwrap fty1 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();
+               let _ =
+                 match array_dec with
+                   Some(lb1,size,rb1) ->
+                      mcode print_string lb1;
+                      print_option expression size;
+                      mcode print_string rb1
+                 | None -> () in
+               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" in
+  match Ast.unwrap ty with
+    Ast.Type(_,_,fty1) ->
+      (match Ast.unwrap fty1 with
+        Ast.Array(ty1,lb1,size,rb1) ->
+          function_pointer ty1 (Some(lb1,size,rb1))
+      | Ast.Pointer(ty1,star) ->
+          function_pointer ty None
+      | _ -> failwith "ParenType Pretty_print_cocci")
+   | _ -> failwith "ParenType Pretty_print_cocci"
+
+
 and varargs = function
   | None -> ()
   | Some (comma, ellipsis) ->
@@ -424,6 +465,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 +546,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] 27+ messages in thread

* [Cocci] [PATCH v3 22/26] parsing_c: unparse_cocci: Print ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (20 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 21/26] parsing_cocci: pretty_print_cocci: Print ParenType/FunctionType Jaskaran Singh
@ 2020-03-20  7:01 ` " Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 23/26] engine: Match A.ParenType and A.FunctionType Jaskaran Singh
                   ` (3 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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 | 58 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index 30e755e9..1fa3115a 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,49 @@ and storage = function
   | Ast.Register -> print_string "register"
   | Ast.Extern -> print_string "extern"
 
+(* --------------------------------------------------------------------- *)
+(* ParenType *)
+
+and print_parentype (lp,ty,rp) fn =
+  let function_pointer ty1 array_dec =
+    match Ast.unwrap ty1 with
+     Ast.Type(_,_,fty1) ->
+      (match Ast.unwrap fty1 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();
+               let _ =
+                 match array_dec with
+                   Some(lb1,size,rb1) ->
+                    mcode print_string lb1;
+                    print_option expression size;
+                    mcode print_string rb1
+                 | None -> () in
+               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" in
+  match Ast.unwrap ty with
+    Ast.Type(_,_,fty1) ->
+      (match Ast.unwrap fty1 with
+        Ast.Array(ty1,lb1,size,rb1) ->
+          function_pointer ty1 (Some(lb1,size,rb1))
+      | Ast.Pointer(ty1,star) ->
+          function_pointer ty None
+      | _ -> failwith "ParenType Unparse_cocci")
+   | _ -> failwith "ParenType Unparse_cocci"
+
 (* --------------------------------------------------------------------- *)
 (* Variable declaration *)
 
@@ -818,6 +868,14 @@ 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())
+      | Ast.FunctionType(ty,lp,params,rp) ->
+          fullType ty;
+          id();
+          mcode print_string lp;
+          parameter_list params;
+          mcode print_string rp
     (*| 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] 27+ messages in thread

* [Cocci] [PATCH v3 23/26] engine: Match A.ParenType and A.FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (21 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 22/26] parsing_c: unparse_cocci: " Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 24/26] tools: spgen: Add cases for ParenType/FunctionType Jaskaran Singh
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 24/26] tools: spgen: Add cases for ParenType/FunctionType
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (22 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 23/26] engine: Match A.ParenType and A.FunctionType Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 25/26] cocci: Remove Ast_cocci.FunctionPointer Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 26/26] tests: Add test case for array of function pointers Jaskaran Singh
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

* [Cocci] [PATCH v3 25/26] cocci: Remove Ast_cocci.FunctionPointer
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (23 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 24/26] tools: spgen: Add cases for ParenType/FunctionType Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  2020-03-20  7:01 ` [Cocci] [PATCH v3 26/26] tests: Add test case for array of function pointers Jaskaran Singh
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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 1fa3115a..718b466c 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) ->
@@ -843,10 +834,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 6d2a9c5d..fb2e63de 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_mcode lp t (function lp -> 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 c47a06ba..2b2606ad 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 088db18a..56eed017 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 8055ba3b..770e117c 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 =
   let function_pointer ty1 array_dec =
     match Ast.unwrap ty1 with
@@ -462,9 +456,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) ->
@@ -525,10 +516,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 2bd4c202..4e23aef3 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) -> modif_before_mcode lp
   | 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 76288087..c3e0df9c 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 =
   let function_pointer ty1 array_decs =
     match Ast0.unwrap ty1 with
@@ -332,9 +327,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) ->
@@ -388,10 +380,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 6f2e3dab..6f435ee6 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
@@ -376,8 +363,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) ->
@@ -435,8 +420,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
@@ -1299,15 +1282,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 76ec4e5c..adc2fc99 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
@@ -505,12 +485,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)
@@ -526,23 +501,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
@@ -620,12 +578,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] 27+ messages in thread

* [Cocci] [PATCH v3 26/26] tests: Add test case for array of function pointers
  2020-03-20  7:01 [Cocci] [PATCH v3 00/26] cocci: Add ParenType/FunctionType to SmPL ASTs Jaskaran Singh
                   ` (24 preceding siblings ...)
  2020-03-20  7:01 ` [Cocci] [PATCH v3 25/26] cocci: Remove Ast_cocci.FunctionPointer Jaskaran Singh
@ 2020-03-20  7:01 ` Jaskaran Singh
  25 siblings, 0 replies; 27+ messages in thread
From: Jaskaran Singh @ 2020-03-20  7:01 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] 27+ messages in thread

end of thread, back to index

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