linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs
@ 2020-04-28 17:01 Jaskaran Singh
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name Jaskaran Singh
                   ` (31 more replies)
  0 siblings, 32 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:01 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

This patch series aims to add cast attributes to the C and SmPL ASTs, and
match them in C source code. This is a continuation of the series "cocci:
Improve C parsing of attributes"[1].

Three test cases are included:

- detect_cast_attr: Test case to detect a parameter attribute.

- remove_cast_attr: Test case to remove a parameter attribute as per the
  given SmPL.

- remove_cast_attr_allminus: Test case to replace a type in a cast and
  checking if the attribute is removed as well.

[1]https://www.mail-archive.com/cocci@systeme.lip6.fr/msg07133.html

Jaskaran Singh (32):
      parsing_c: parser: Pass attribute list from type_name
      parsing_cocci: ast0_cocci: Add cast attributes
      parsing_cocci: parser: Parse cast attributes
      parsing_cocci: visitor_ast0: Visit cast attributes
      parsing_cocci: unparse_ast0: Reflect cast attributes
      parsing_cocci: index: Reflect Cast attributes
      parsing_cocci: iso_pattern: Reflect Cast attributes
      parsing_cocci: type_infer: Reflect Cast attributes
      parsing_cocci: arity: Reflect Cast attributes
      parsing_cocci: check_meta: Reflect Cast attributes
      parsing_cocci: compute_lines: Reflect Cast attributes
      parsing_cocci: context_neg: Reflect Cast attributes
      parsing_cocci: single_statement: Reflect Cast attributes
      parsing_cocci: ast_cocci: Add cast attributes
      parsing_cocci: visitor_ast: Visit cast attributes
      parsing_cocci: pretty_print_cocci: Print cast attributes
      parsing_cocci: ast0toast: Reflect Cast attributes
      parsing_cocci: disjdistr: Reflect Cast attributes
      parsing_cocci: unify_ast: Reflect Cast attributes
      parsing_c: ast_c: Add Cast attributes
      parsing_c: parser: Parse Cast attributes
      parsing_c: pretty_print_c: Reflect Cast attributes
      parsing_c: type_annoter_c: Reflect Cast attributes
      parsing_c: unparse_cocci: Reflect Cast attributes
      parsing_c: visitor_c: Visit Cast attributes
      engine: check_exhaustive_pattern: Reflect Cast attributes
      engine: cocci_vs_c: Match Cast attributes
      ocaml: coccilib: Reflect Cast attributes
      tools: spgen: Reflect Cast attrs
      tests: Add test case to check cast attribute allminus
      tests: Add test case to remove cast attributes
      tests: Add test case to detect cast attributes

 engine/check_exhaustive_pattern.ml       |    2 +-
 engine/cocci_vs_c.ml                     |   24 +++++++++++++++++-------
 ocaml/coccilib.mli                       |    9 +++++----
 parsing_c/ast_c.ml                       |    2 +-
 parsing_c/ast_c.mli                      |    2 +-
 parsing_c/parse_c.ml                     |    4 +++-
 parsing_c/parser_c.mly                   |   19 ++++++++++---------
 parsing_c/pretty_print_c.ml              |    7 ++++---
 parsing_c/type_annoter_c.ml              |    4 ++--
 parsing_c/unparse_cocci.ml               |    6 ++++--
 parsing_c/visitor_c.ml                   |   10 ++++++++--
 parsing_cocci/arity.ml                   |    5 +++--
 parsing_cocci/ast0_cocci.ml              |    4 ++--
 parsing_cocci/ast0_cocci.mli             |    4 ++--
 parsing_cocci/ast0toast.ml               |    5 +++--
 parsing_cocci/ast_cocci.ml               |    4 ++--
 parsing_cocci/ast_cocci.mli              |    4 ++--
 parsing_cocci/check_meta.ml              |    3 ++-
 parsing_cocci/compute_lines.ml           |    5 +++--
 parsing_cocci/context_neg.ml             |    2 +-
 parsing_cocci/disjdistr.ml               |    5 +++--
 parsing_cocci/index.ml                   |    2 +-
 parsing_cocci/iso_pattern.ml             |   12 +++++++++---
 parsing_cocci/parser_cocci_menhir.mly    |    9 +++++----
 parsing_cocci/pretty_print_cocci.ml      |    4 +++-
 parsing_cocci/single_statement.ml        |    2 +-
 parsing_cocci/type_infer.ml              |    2 +-
 parsing_cocci/unify_ast.ml               |    6 ++++--
 parsing_cocci/unparse_ast0.ml            |    4 +++-
 parsing_cocci/visitor_ast.ml             |   10 ++++++----
 parsing_cocci/visitor_ast0.ml            |    6 ++++--
 tests/detect_cast_attr.c                 |   10 ++++++++++
 tests/detect_cast_attr.cocci             |   11 +++++++++++
 tests/detect_cast_attr.res               |   10 ++++++++++
 tests/remove_cast_attr.c                 |   10 ++++++++++
 tests/remove_cast_attr.cocci             |   10 ++++++++++
 tests/remove_cast_attr.res               |   10 ++++++++++
 tests/remove_cast_attr_allminus.c        |   10 ++++++++++
 tests/remove_cast_attr_allminus.cocci    |    9 +++++++++
 tests/remove_cast_attr_allminus.res      |   10 ++++++++++
 tools/spgen/source/position_generator.ml |    4 ++--
 41 files changed, 208 insertions(+), 73 deletions(-)


_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
@ 2020-04-28 17:01 ` Jaskaran Singh
  2020-05-03 19:23   ` Julia Lawall
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 02/32] parsing_cocci: ast0_cocci: Add cast attributes Jaskaran Singh
                   ` (30 subsequent siblings)
  31 siblings, 1 reply; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:01 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

To add Cast attributes to the C AST, pass attributes from the type_name
rule of the C parser.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 ocaml/coccilib.mli     |  3 ++-
 parsing_c/parse_c.ml   |  4 +++-
 parsing_c/parser_c.mly | 16 ++++++++--------
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 0e807c9a..a305d616 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -791,7 +791,8 @@ module Parser_c :
       (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.statement
     val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.expression
     val type_name :
-      (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.fullType
+      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
+      Ast_c.attribute list * Ast_c.fullType
   end
 module Lexer_c :
   sig
diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
index 0d3a189a..5f8d5e2d 100644
--- a/parsing_c/parse_c.ml
+++ b/parsing_c/parse_c.ml
@@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s =
   result
 
 (* Please DO NOT remove this code, even though most of it is not used *)
-let type_of_string       = parse_gen ~cpp:false ~tos:true Parser_c.type_name
+let type_of_string s     =
+  let typname = parse_gen ~cpp:false ~tos:true Parser_c.type_name s in
+  Common.snd typname
 let statement_of_string  = parse_gen ~cpp:false ~tos:false Parser_c.statement
 let expression_of_string = parse_gen ~cpp:false ~tos:false Parser_c.expr
 let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false Parser_c.expr
diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
index aedde179..0abcc9b0 100644
--- a/parsing_c/parser_c.mly
+++ b/parsing_c/parser_c.mly
@@ -665,7 +665,7 @@ let postfakeInfo pii  =
 
 %type <Ast_c.statement> statement
 %type <Ast_c.expression> expr
-%type <Ast_c.fullType> type_name
+%type <Ast_c.attribute list * Ast_c.fullType> type_name
 
 %%
 /*(*************************************************************************)*/
@@ -818,7 +818,7 @@ arith_expr:
 
 cast_expr:
  | unary_expr                        { $1 }
- | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4)) [$1;$3] }
+ | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4)) [$1;$3] }
 /*
 It could be useful to have the following, but there is no place for the
 attribute in the AST.
@@ -831,7 +831,7 @@ unary_expr:
  | TDec unary_expr                 { mk_e(Infix ($2, Dec))    [$1] }
  | unary_op cast_expr              { mk_e(Unary ($2, fst $1)) [snd $1] }
  | Tsizeof unary_expr              { mk_e(SizeOfExpr ($2))    [$1] }
- | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType ($3))    [$1;$2;$4] }
+ | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType (snd $3))    [$1;$2;$4] }
  | Tnew new_argument               { mk_e(New (None, $2))     [$1] }
  | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New (Some $3, $5))             [$1; $2; $4] }
  | Tdelete cast_expr               { mk_e(Delete(false, $2))  [$1] }
@@ -897,9 +897,9 @@ postfix_expr:
 
  /*(* gccext: also called compound literals *)*/
  | topar2 type_name tcpar2 TOBrace TCBrace
-     { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3] }
+     { mk_e(Constructor (snd $2, (InitList [], [$4;$5]))) [$1;$3] }
  | topar2 type_name tcpar2 TOBrace initialize_list gcc_comma_opt_struct TCBrace
-     { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] }
+     { mk_e(Constructor (snd $2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] }
 
 
 primary_expr:
@@ -1298,7 +1298,7 @@ type_spec2:
        Right3 (TypeName (name, Ast_c.noTypedefDef())),[] }
 
  | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)), [$1;$2;$4] }
- | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType ($3)), [$1;$2;$4] }
+ | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType (snd $3)), [$1;$2;$4] }
 
 /*(*----------------------------*)*/
 /*(* workarounds *)*/
@@ -1531,12 +1531,12 @@ type_qualif_list:
 type_name:
  | spec_qualif_list
      { let (attrs, ds) = $1 in
-       let (returnType, _) = fixDeclSpecForDecl ds in returnType }
+       let (returnType, _) = fixDeclSpecForDecl ds in (attrs, returnType) }
  | spec_qualif_list abstract_declaratort
      { let (attrs1, ds) = $1 in
        let (attrs2, fn) = $2 in
        let (returnType, _) = fixDeclSpecForDecl ds in
-       fn returnType }
+       (attrs1@attrs2, fn returnType) }
 
 
 
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 02/32] parsing_cocci: ast0_cocci: Add cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name Jaskaran Singh
@ 2020-04-28 17:01 ` Jaskaran Singh
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 03/32] parsing_cocci: parser: Parse " Jaskaran Singh
                   ` (29 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:01 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Add cast attributes to AST0 of SmPL. This is a list of attributes in the
Cast type of AST0.

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

diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index a06d99ae..b65400be 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -123,8 +123,8 @@ and base_expression =
 	              string mcode (* ] *)
   | RecordAccess   of expression * string mcode (* . *) * ident
   | RecordPtAccess of expression * string mcode (* -> *) * ident
-  | Cast           of string mcode (* ( *) * typeC * string mcode (* ) *) *
-                      expression
+  | Cast           of string mcode (* ( *) * typeC * attr list *
+                      string mcode (* ) *) * expression
   | SizeOfExpr     of string mcode (* sizeof *) * expression
   | SizeOfType     of string mcode (* sizeof *) * string mcode (* ( *) *
                       typeC * string mcode (* ) *)
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 5c2520be..08a4b33b 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -114,8 +114,8 @@ and base_expression =
 	              string mcode (* ] *)
   | RecordAccess   of expression * string mcode (* . *) * ident
   | RecordPtAccess of expression * string mcode (* -> *) * ident
-  | Cast           of string mcode (* ( *) * typeC * string mcode (* ) *) *
-                      expression
+  | Cast           of string mcode (* ( *) * typeC * attr list *
+                      string mcode (* ) *) * expression
   | SizeOfExpr     of string mcode (* sizeof *) * expression
   | SizeOfType     of string mcode (* sizeof *) * string mcode (* ( *) *
                       typeC * string mcode (* ) *)
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 03/32] parsing_cocci: parser: Parse cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name Jaskaran Singh
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 02/32] parsing_cocci: ast0_cocci: Add cast attributes Jaskaran Singh
@ 2020-04-28 17:01 ` Jaskaran Singh
  2020-05-03 19:26   ` Julia Lawall
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 04/32] parsing_cocci: visitor_ast0: Visit " Jaskaran Singh
                   ` (28 subsequent siblings)
  31 siblings, 1 reply; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:01 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL ASTs. Parse these attributes in
the SmPL parser and place them in the SmPL AST. The added production
only supports attributes after the type and before the expression.

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

diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
index db5661bd..38b0e039 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -2176,11 +2176,12 @@ arith_expr_bis:
 
 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,
+  | lp=TOPar t=ctype ar=attr_list rp=TCPar e=cast_expr(r,pe)
+      { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t, ar,
                              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,
+  | lp=TOPar t=ctype d=direct_abstract_d ar=attr_list rp=TCPar
+    e=cast_expr(r,pe)
+      { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t, ar,
 			     P.clt2mcode ")" rp, e)) }
 
 unary_expr(r,pe):
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 04/32] parsing_cocci: visitor_ast0: Visit cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (2 preceding siblings ...)
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 03/32] parsing_cocci: parser: Parse " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 05/32] parsing_cocci: unparse_ast0: Reflect " Jaskaran Singh
                   ` (27 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to AST0 of SmPL. Visit these attributes in the
AST0 visitor of SmPL.

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

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index d9e340ed..2ccdb0bb 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -184,12 +184,14 @@ let visitor mode bind option_default
 	    let (ar_n,ar) = string_mcode ar in
 	    let (field_n,field) = ident field in
 	    (multibind [exp_n;ar_n;field_n], Ast0.RecordPtAccess(exp,ar,field))
-	| Ast0.Cast(lp,ty,rp,exp) ->
+	| Ast0.Cast(lp,ty,attr,rp,exp) ->
 	    let (lp_n,lp) = string_mcode lp in
 	    let (ty_n,ty) = typeC ty in
+	    let (attr_n,attr) = map_split_bind string_mcode attr in
 	    let (rp_n,rp) = string_mcode rp in
 	    let (exp_n,exp) = expression exp in
-	    (multibind [lp_n;ty_n;rp_n;exp_n], Ast0.Cast(lp,ty,rp,exp))
+            (multibind [lp_n;ty_n;attr_n;rp_n;exp_n],
+             Ast0.Cast(lp,ty,attr,rp,exp))
 	| Ast0.SizeOfExpr(szf,exp) ->
 	    let (szf_n,szf) = string_mcode szf in
 	    let (exp_n,exp) = expression exp in
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 05/32] parsing_cocci: unparse_ast0: Reflect cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (3 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 04/32] parsing_cocci: visitor_ast0: Visit " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 06/32] parsing_cocci: index: Reflect Cast attributes Jaskaran Singh
                   ` (26 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
unparse_ast0.ml.

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

diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index fdaf6cfa..7f554b37 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -221,8 +221,10 @@ let rec expression e =
 	  expression exp; mcode print_string pt; ident field
       | Ast0.RecordPtAccess(exp,ar,field) ->
 	  expression exp; mcode print_string ar; ident field
-      | Ast0.Cast(lp,ty,rp,exp) ->
+      | Ast0.Cast(lp,ty,attr,rp,exp) ->
 	  mcode print_string_box lp; typeC ty; close_box();
+	  (if not (attr = []) then print_string " ");
+	  print_between (fun _ -> print_string " ") (mcode print_string) attr;
 	  mcode print_string rp; expression exp
       | Ast0.SizeOfExpr(szf,exp) ->
 	  mcode print_string szf; expression exp
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 06/32] parsing_cocci: index: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (4 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 05/32] parsing_cocci: unparse_ast0: Reflect " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 07/32] parsing_cocci: iso_pattern: " Jaskaran Singh
                   ` (25 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
index.ml.

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

diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
index f7ae48b4..a3b92c12 100644
--- a/parsing_cocci/index.ml
+++ b/parsing_cocci/index.ml
@@ -61,7 +61,7 @@ let expression e =
   | Ast0.ArrayAccess(exp1,lb,exp2,rb) -> [27]
   | Ast0.RecordAccess(exp,pt,field) -> [28]
   | Ast0.RecordPtAccess(exp,ar,field) -> [29]
-  | Ast0.Cast(lp,ty,rp,exp) -> [30]
+  | Ast0.Cast(lp,ty,attr,rp,exp) -> [30]
   | Ast0.SizeOfExpr(szf,exp) -> [98] (* added after *)
   | Ast0.SizeOfType(szf,lp,ty,rp) -> [99] (* added after *)
   | Ast0.TypeExp(ty) -> [123] (* added after *)
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 07/32] parsing_cocci: iso_pattern: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (5 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 06/32] parsing_cocci: index: Reflect Cast attributes Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 08/32] parsing_cocci: type_infer: " Jaskaran Singh
                   ` (24 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
iso_pattern.ml.

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

diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 9df21fb9..b57e293e 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -575,7 +575,7 @@ let match_maker checks_needed context_required whencode_allowed =
 			(* all caps is a const *)
 			Str.string_match all_caps nm 0
 		    | _ -> false)
-		| Ast0.Cast(lp,ty,rp,e) -> matches e
+		| Ast0.Cast(lp,ty,attr,rp,e) -> matches e
 		| Ast0.SizeOfExpr(se,exp) -> true
 		| Ast0.SizeOfType(se,lp,ty,rp) -> true
 		| Ast0.MetaExpr(nm,_,_,Ast.CONST,p,_bitfield) ->
@@ -586,7 +586,7 @@ let match_maker checks_needed context_required whencode_allowed =
 	      let rec matches e =
 		match Ast0.unwrap e with
 		  Ast0.Ident(c) -> true
-		| Ast0.Cast(lp,ty,rp,e) -> matches e
+		| Ast0.Cast(lp,ty,attr,rp,e) -> matches e
 		| Ast0.MetaExpr(nm,_,_,Ast.ID,p,_bitfield) ->
 		    (Ast0.lub_pure p pure) = pure
 		| _ -> false in
@@ -757,10 +757,16 @@ let match_maker checks_needed context_required whencode_allowed =
 	       conjunct_many_bindings
 		 [check_mcode opa op; match_expr expa expb;
 		   match_ident fielda fieldb]
-	  | (Ast0.Cast(lp1,tya,rp1,expa),Ast0.Cast(lp,tyb,rp,expb)) ->
+	  | (Ast0.Cast(lp1,tya,attra,rp1,expa),
+             Ast0.Cast(lp,tyb,attrb,rp,expb)) ->
+              if (List.length attra = List.length attrb &&
+                  List.fold_left2 (fun p a b -> p && mcode_equal a b) true
+                  attra attrb)
+              then
 	      conjunct_many_bindings
 		[check_mcode lp1 lp; check_mcode rp1 rp;
 		  match_typeC tya tyb; match_expr expa expb]
+              else return false
 	  | (Ast0.SizeOfExpr(szf1,expa),Ast0.SizeOfExpr(szf,expb)) ->
 	      conjunct_bindings (check_mcode szf1 szf) (match_expr expa expb)
 	  | (Ast0.SizeOfType(szf1,lp1,tya,rp1),
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 08/32] parsing_cocci: type_infer: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (6 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 07/32] parsing_cocci: iso_pattern: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 09/32] parsing_cocci: arity: " Jaskaran Singh
                   ` (23 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
type_infer.ml.

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

diff --git a/parsing_cocci/type_infer.ml b/parsing_cocci/type_infer.ml
index e8aad810..2c1cc73b 100644
--- a/parsing_cocci/type_infer.ml
+++ b/parsing_cocci/type_infer.ml
@@ -291,7 +291,7 @@ let rec propagate_types env =
                | Some x ->
                    let ty = Ast0.wrap x in
                    err exp ty "non-structure pointer type in field ref")
-	| Ast0.Cast(lp,ty,rp,exp) -> Some ty
+	| Ast0.Cast(lp,ty,attr,rp,exp) -> Some ty
 	| Ast0.SizeOfExpr(szf,exp) -> Some (Ast0.wrap int_type)
 	| Ast0.SizeOfType(szf,lp,ty,rp) -> Some (Ast0.wrap int_type)
 	| Ast0.TypeExp(ty) -> None
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 09/32] parsing_cocci: arity: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (7 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 08/32] parsing_cocci: type_infer: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-05-03 19:28   ` Julia Lawall
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 10/32] parsing_cocci: check_meta: " Jaskaran Singh
                   ` (22 subsequent siblings)
  31 siblings, 1 reply; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
arity.ml.

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

diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
index 8ee6d33f..880cd7a3 100644
--- a/parsing_cocci/arity.ml
+++ b/parsing_cocci/arity.ml
@@ -254,13 +254,14 @@ let rec top_expression opt_allowed tgt expr =
       let ar = mcode ar in
       let field = ident false arity field in
       make_exp expr tgt arity (Ast0.RecordPtAccess(exp,ar,field))
-  | Ast0.Cast(lp,ty,rp,exp) ->
+  | Ast0.Cast(lp,ty,attr,rp,exp) ->
       let arity = exp_same (mcode2line lp) [mcode2arity lp;mcode2arity rp] in
       let lp = mcode lp in
       let ty = typeC arity ty in
+      let attr = List.map mcode attr in
       let rp = mcode rp in
       let exp = expression arity exp in
-      make_exp expr tgt arity (Ast0.Cast(lp,ty,rp,exp))
+      make_exp expr tgt arity (Ast0.Cast(lp,ty,attr,rp,exp))
   | Ast0.SizeOfExpr(szf,exp) ->
       let arity = exp_same (mcode2line szf) [mcode2arity szf] in
       let szf = mcode szf in
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 10/32] parsing_cocci: check_meta: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (8 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 09/32] parsing_cocci: arity: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 11/32] parsing_cocci: compute_lines: " Jaskaran Singh
                   ` (21 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
check_meta.ml.

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

diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml
index 5a348ba3..4f7db813 100644
--- a/parsing_cocci/check_meta.ml
+++ b/parsing_cocci/check_meta.ml
@@ -172,7 +172,8 @@ let rec expression context old_metas table minus e =
   | Ast0.RecordPtAccess(exp,ar,field) ->
       expression ID old_metas table minus exp;
       ident FIELD old_metas table minus field
-  | Ast0.Cast(lp,ty,rp,exp) ->
+  | Ast0.Cast(lp,ty,attr,rp,exp) ->
+      (* No meta attribute yet *)
       typeC old_metas table minus ty; expression ID old_metas table minus exp
   | Ast0.SizeOfExpr(szf,exp) -> expression ID old_metas table minus exp
   | Ast0.SizeOfType(szf,lp,ty,rp) -> typeC old_metas table minus ty
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 11/32] parsing_cocci: compute_lines: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (9 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 10/32] parsing_cocci: check_meta: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 12/32] parsing_cocci: context_neg: " Jaskaran Singh
                   ` (20 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
compute_lines.ml.

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

diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml
index 1361d842..e945914b 100644
--- a/parsing_cocci/compute_lines.ml
+++ b/parsing_cocci/compute_lines.ml
@@ -425,11 +425,12 @@ let rec expression e =
       let ar = normal_mcode ar in
       let field = ident field in
       mkres e (Ast0.RecordPtAccess(exp,ar,field)) exp field
-  | Ast0.Cast(lp,ty,rp,exp) ->
+  | Ast0.Cast(lp,ty,attr,rp,exp) ->
       let lp = normal_mcode lp in
       let exp = expression exp in
+      let attr = List.map normal_mcode attr in
       let rp = normal_mcode rp in
-      mkres e (Ast0.Cast(lp,typeC ty,rp,exp)) (promote_mcode lp) exp
+      mkres e (Ast0.Cast(lp,typeC ty,attr,rp,exp)) (promote_mcode lp) exp
   | Ast0.SizeOfExpr(szf,exp) ->
       let szf = normal_mcode szf in
       let exp = expression exp in
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 12/32] parsing_cocci: context_neg: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (10 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 11/32] parsing_cocci: compute_lines: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 13/32] parsing_cocci: single_statement: " Jaskaran Singh
                   ` (19 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
context_neg.ml.

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

diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml
index dd768a61..b6378512 100644
--- a/parsing_cocci/context_neg.ml
+++ b/parsing_cocci/context_neg.ml
@@ -628,7 +628,7 @@ let rec equal_expression e1 e2 =
       equal_mcode pt1 pt2
   | (Ast0.RecordPtAccess(_,ar1,_),Ast0.RecordPtAccess(_,ar2,_)) ->
       equal_mcode ar1 ar2
-  | (Ast0.Cast(lp1,_,rp1,_),Ast0.Cast(lp2,_,rp2,_)) ->
+  | (Ast0.Cast(lp1,_,_,rp1,_),Ast0.Cast(lp2,_,_,rp2,_)) ->
       equal_mcode lp1 lp2 && equal_mcode rp1 rp2
   | (Ast0.SizeOfExpr(szf1,_),Ast0.SizeOfExpr(szf2,_)) ->
       equal_mcode szf1 szf2
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 13/32] parsing_cocci: single_statement: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (11 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 12/32] parsing_cocci: context_neg: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 14/32] parsing_cocci: ast_cocci: Add cast attributes Jaskaran Singh
                   ` (18 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
single_statement.ml.

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

diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml
index 4ad1c4e4..73554e9c 100644
--- a/parsing_cocci/single_statement.ml
+++ b/parsing_cocci/single_statement.ml
@@ -138,7 +138,7 @@ let rec left_expression e =
   | Ast0.ArrayAccess(exp1,lb,exp2,rb) -> left_expression exp1
   | Ast0.RecordAccess(exp,pt,field) -> left_expression exp
   | Ast0.RecordPtAccess(exp,ar,field) -> left_expression exp
-  | Ast0.Cast(lp,ty,rp,exp) -> modif_before_mcode lp
+  | Ast0.Cast(lp,ty,attr,rp,exp) -> modif_before_mcode lp
   | Ast0.SizeOfExpr(szf,exp) -> modif_before_mcode szf
   | Ast0.SizeOfType(szf,lp,ty,rp) -> modif_before_mcode szf
   | Ast0.TypeExp(ty) -> left_typeC ty
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 14/32] parsing_cocci: ast_cocci: Add cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (12 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 13/32] parsing_cocci: single_statement: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 15/32] parsing_cocci: visitor_ast: Visit " Jaskaran Singh
                   ` (17 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Add cast attributes to the SmPL AST. This is a list of attributes in the
Cast type of the SmPL AST.

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

diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index 9b147e5c..b0190fa1 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -194,8 +194,8 @@ and base_expression =
 	              string mcode (* ] *)
   | RecordAccess   of expression * string mcode (* . *) * ident
   | RecordPtAccess of expression * string mcode (* -> *) * ident
-  | Cast           of string mcode (* ( *) * fullType * string mcode (* ) *) *
-                      expression
+  | Cast           of string mcode (* ( *) * fullType * attr list *
+                      string mcode (* ) *) * expression
   | SizeOfExpr     of string mcode (* sizeof *) * expression
   | SizeOfType     of string mcode (* sizeof *) * string mcode (* ( *) *
                       fullType * string mcode (* ) *)
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index c56bba88..ff81692c 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -178,8 +178,8 @@ and base_expression =
 	              string mcode (* ] *)
   | RecordAccess   of expression * string mcode (* . *) * ident
   | RecordPtAccess of expression * string mcode (* -> *) * ident
-  | Cast           of string mcode (* ( *) * fullType * string mcode (* ) *) *
-                      expression
+  | Cast           of string mcode (* ( *) * fullType * attr list *
+                      string mcode (* ) *) * expression
 
   | SizeOfExpr     of string mcode (* sizeof *) * expression
   | SizeOfType     of string mcode (* sizeof *) * string mcode (* ( *) *
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 15/32] parsing_cocci: visitor_ast: Visit cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (13 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 14/32] parsing_cocci: ast_cocci: Add cast attributes Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-05-03 19:29   ` Julia Lawall
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 16/32] parsing_cocci: pretty_print_cocci: Print " Jaskaran Singh
                   ` (16 subsequent siblings)
  31 siblings, 1 reply; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to AST0 of SmPL. Visit these attributes in the
SmPL AST visitor.

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

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 8e530114..644bcd5d 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -198,12 +198,13 @@ let combiner bind option_default
 	  let lar = string_mcode ar in
 	  let lfield = ident field in
 	  multibind [lexp; lar; lfield]
-      | Ast.Cast(lp,ty,rp,exp) ->
+      | Ast.Cast(lp,ty,attr,rp,exp) ->
 	  let llp = string_mcode lp in
 	  let lty = fullType ty in
+	  let lattr = multibind (List.map string_mcode attr) in
 	  let lrp = string_mcode rp in
 	  let lexp = expression exp in
-	  multibind [llp; lty; lrp; lexp]
+          multibind [llp; lty; lattr; lrp; lexp]
       | Ast.SizeOfExpr(szf,exp) ->
 	  let lszf = string_mcode szf in
 	  let lexp = expression exp in
@@ -1184,12 +1185,13 @@ let rebuilder
 	    let lar = string_mcode ar in
 	    let lfield = ident field in
 	    Ast.RecordPtAccess(lexp, lar, lfield)
-	| Ast.Cast(lp,ty,rp,exp) ->
+	| Ast.Cast(lp,ty,attr,rp,exp) ->
 	    let llp = string_mcode lp in
 	    let lty = fullType ty in
+	    let lattr = List.map string_mcode attr in
 	    let lrp = string_mcode rp in
 	    let lexp = expression exp in
-	    Ast.Cast(llp, lty, lrp, lexp)
+	    Ast.Cast(llp, lty, lattr, lrp, lexp)
 	| Ast.SizeOfExpr(szf,exp) ->
 	    let lszf = string_mcode szf in
 	    let lexp = expression exp in
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 16/32] parsing_cocci: pretty_print_cocci: Print cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (14 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 15/32] parsing_cocci: visitor_ast: Visit " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 17/32] parsing_cocci: ast0toast: Reflect Cast attributes Jaskaran Singh
                   ` (15 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
pretty_print_cocci.ml by printing these attributes.

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

diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml
index 7628882b..2ace0b44 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -249,8 +249,10 @@ let rec expression e =
       expression exp; mcode print_string pt; ident field
   | Ast.RecordPtAccess(exp,ar,field) ->
       expression exp; mcode print_string ar; ident field
-  | Ast.Cast(lp,ty,rp,exp) ->
+  | Ast.Cast(lp,ty,attr,rp,exp) ->
       mcode print_string_box lp; fullType ty; close_box();
+      (if not (attr = []) then print_string " ");
+      print_between print_space (mcode print_string) attr;
       mcode print_string rp; expression exp
   | Ast.SizeOfExpr(sizeof,exp) ->
       mcode print_string sizeof; expression exp
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 17/32] parsing_cocci: ast0toast: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (15 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 16/32] parsing_cocci: pretty_print_cocci: Print " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 18/32] parsing_cocci: disjdistr: " Jaskaran Singh
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
ast0toast.ml.

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

diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index 09c28c06..56f684ee 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -439,9 +439,10 @@ and expression e =
 	Ast.RecordAccess(expression exp,mcode pt,ident field)
     | Ast0.RecordPtAccess(exp,ar,field) ->
 	Ast.RecordPtAccess(expression exp,mcode ar,ident field)
-    | Ast0.Cast(lp,ty,rp,exp) ->
+    | Ast0.Cast(lp,ty,attr,rp,exp) ->
 	let allminus = check_allminus.VT0.combiner_rec_expression e in
-	Ast.Cast(mcode lp,typeC allminus ty,mcode rp,expression exp)
+	let attr = List.map mcode attr in
+	Ast.Cast(mcode lp,typeC allminus ty,attr,mcode rp,expression exp)
     | Ast0.SizeOfExpr(szf,exp) ->
 	Ast.SizeOfExpr(mcode szf,expression exp)
     | Ast0.SizeOfType(szf,lp,ty,rp) ->
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 18/32] parsing_cocci: disjdistr: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (16 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 17/32] parsing_cocci: ast0toast: Reflect Cast attributes Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 19/32] parsing_cocci: unify_ast: " Jaskaran Singh
                   ` (13 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
disjdistr.ml.

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

diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml
index 6724bb25..e171e6ea 100644
--- a/parsing_cocci/disjdistr.ml
+++ b/parsing_cocci/disjdistr.ml
@@ -219,9 +219,10 @@ and disjexp e =
   | Ast.RecordPtAccess(exp,ar,field) ->
       disjmult2 (disjexp exp) (disjident field)
 	(fun exp field -> Ast.rewrap e (Ast.RecordPtAccess(exp,ar,field)))
-  | Ast.Cast(lp,ty,rp,exp) ->
+  | Ast.Cast(lp,ty,attr,rp,exp) ->
       disjmult2 (disjty ty) (disjexp exp)
-	(function ty -> function exp -> Ast.rewrap e (Ast.Cast(lp,ty,rp,exp)))
+	(function ty -> function exp ->
+          Ast.rewrap e (Ast.Cast(lp,ty,attr,rp,exp)))
   | Ast.SizeOfExpr(szf,exp) ->
       let exp = disjexp exp in
       List.map (function exp -> Ast.rewrap e (Ast.SizeOfExpr(szf,exp))) exp
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 19/32] parsing_cocci: unify_ast: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (17 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 18/32] parsing_cocci: disjdistr: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 20/32] parsing_c: ast_c: Add " Jaskaran Singh
                   ` (12 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
unify_ast.ml.

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

diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml
index 68cb6613..25287503 100644
--- a/parsing_cocci/unify_ast.ml
+++ b/parsing_cocci/unify_ast.ml
@@ -220,8 +220,10 @@ and unify_expression e1 e2 =
       unify_expression e1 e2 && unify_ident fld1 fld2
   | (Ast.RecordPtAccess(e1,pt1,fld1),Ast.RecordPtAccess(e2,pt2,fld2)) ->
       unify_expression e1 e2 && unify_ident fld1 fld2
-  | (Ast.Cast(lp1,ty1,rp1,e1),Ast.Cast(lp2,ty2,rp2,e2)) ->
-      unify_fullType ty1 ty2 && unify_expression e1 e2
+  | (Ast.Cast(lp1,ty1,attr1,rp1,e1),Ast.Cast(lp2,ty2,attr2,rp2,e2)) ->
+      if List.for_all2 unify_mcode attr1 attr2
+      then unify_fullType ty1 ty2 && unify_expression e1 e2
+      else false
   | (Ast.SizeOfExpr(szf1,e1),Ast.SizeOfExpr(szf2,e2)) ->
       unify_expression e1 e2
   | (Ast.SizeOfType(szf1,lp1,ty1,rp1),Ast.SizeOfType(szf2,lp2,ty2,rp2)) ->
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 20/32] parsing_c: ast_c: Add Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (18 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 19/32] parsing_cocci: unify_ast: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-05-03 19:31   ` Julia Lawall
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 21/32] parsing_c: parser: Parse " Jaskaran Singh
                   ` (11 subsequent siblings)
  31 siblings, 1 reply; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Add cast attributes to the C AST. This is a list of attributes in the
Cast type of the C AST.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_c/ast_c.ml  | 2 +-
 parsing_c/ast_c.mli | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/parsing_c/ast_c.ml b/parsing_c/ast_c.ml
index f25f9b55..6a828943 100644
--- a/parsing_c/ast_c.ml
+++ b/parsing_c/ast_c.ml
@@ -343,7 +343,7 @@ and expression = (expressionbis * exp_info ref (* semantic: *)) wrap3
 
   | SizeOfExpr     of expression
   | SizeOfType     of fullType
-  | Cast           of fullType * expression
+  | Cast           of fullType * expression * attribute list
 
   (* gccext: *)
   | StatementExpr of compound wrap (* ( )     new scope *)
diff --git a/parsing_c/ast_c.mli b/parsing_c/ast_c.mli
index 8923a335..8a9a6f66 100644
--- a/parsing_c/ast_c.mli
+++ b/parsing_c/ast_c.mli
@@ -104,7 +104,7 @@ and expressionbis =
   | RecordPtAccess of expression * name
   | SizeOfExpr of expression
   | SizeOfType of fullType
-  | Cast of fullType * expression
+  | Cast of fullType * expression * attribute list
   | StatementExpr of compound wrap
   | Constructor of fullType * initialiser
   | ParenExpr of expression
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 21/32] parsing_c: parser: Parse Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (19 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 20/32] parsing_c: ast_c: Add " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 22/32] parsing_c: pretty_print_c: Reflect " Jaskaran Singh
                   ` (10 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the C AST. Parse cast attributes in the C
parser and place them in the C AST. The attributes are taken from the
type_name rule of the C parser.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_c/parser_c.mly | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
index 0abcc9b0..9e640ba5 100644
--- a/parsing_c/parser_c.mly
+++ b/parsing_c/parser_c.mly
@@ -818,7 +818,8 @@ arith_expr:
 
 cast_expr:
  | unary_expr                        { $1 }
- | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4)) [$1;$3] }
+ | topar2 type_name tcpar2 cast_expr
+   { mk_e(Cast (snd $2, $4, fst $2)) [$1;$3] }
 /*
 It could be useful to have the following, but there is no place for the
 attribute in the AST.
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 22/32] parsing_c: pretty_print_c: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (20 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 21/32] parsing_c: parser: Parse " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-05-03 19:32   ` Julia Lawall
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 23/32] parsing_c: type_annoter_c: " Jaskaran Singh
                   ` (9 subsequent siblings)
  31 siblings, 1 reply; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Print these attributes in
pretty_print_c.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_c/pretty_print_c.ml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml
index 99a7e0ed..96a11d72 100644
--- a/parsing_c/pretty_print_c.ml
+++ b/parsing_c/pretty_print_c.ml
@@ -146,8 +146,9 @@ let mk_pretty_printers
 	pp_expression e
     | SizeOfType  (t),     [i1;i2;i3] ->
         pr_elem i1; pr_elem i2; pp_type t; pr_elem i3
-    | Cast    (t, e),      [i1;i2] ->
-        pr_elem i1; pp_type t; pr_elem i2; pp_expression e
+    | Cast    (t, e, a),      [i1;i2] ->
+        pr_elem i1; pp_type t; pr_elem i2; pp_expression e;
+        a +> pp_attributes pr_elem pr_space
 
     | StatementExpr (statxs, [ii1;ii2]),  [i1;i2] ->
         pr_elem i1;
@@ -184,7 +185,7 @@ let mk_pretty_printers
     | CondExpr (_,_,_) | Sequence (_,_) | Assignment (_,_,_)
     | Postfix (_,_) | Infix (_,_) | Unary (_,_) | Binary (_,_,_)
     | ArrayAccess (_,_) | RecordAccess (_,_) | RecordPtAccess (_,_)
-    | SizeOfExpr (_) | SizeOfType (_) | Cast (_,_)
+    | SizeOfExpr (_) | SizeOfType (_) | Cast (_,_,_)
     | StatementExpr (_) | Constructor _
     | ParenExpr (_) | New (_) | Delete (_,_)
     | Defined (_)),_ -> raise (Impossible 95)
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 23/32] parsing_c: type_annoter_c: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (21 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 22/32] parsing_c: pretty_print_c: Reflect " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 24/32] parsing_c: unparse_cocci: " Jaskaran Singh
                   ` (8 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
type_annoter_c.ml.

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

diff --git a/parsing_c/type_annoter_c.ml b/parsing_c/type_annoter_c.ml
index dfd363b2..c42ac5e9 100644
--- a/parsing_c/type_annoter_c.ml
+++ b/parsing_c/type_annoter_c.ml
@@ -525,7 +525,7 @@ let rec is_simple_expr expr =
       true
   | Binary (e1, op, e2) ->
       true
-  | Cast (t, e) ->
+  | Cast (t, e, a) ->
       true
   | ParenExpr (e) -> is_simple_expr e
 
@@ -961,7 +961,7 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
 
 
     (* -------------------------------------------------- *)
-    | Cast (t, e) ->
+    | Cast (t, e, a) ->
         k expr;
         (* todo: if infer, can "push" info ? add_types_expr [t] e ? *)
         make_info_def_fix (Lib.al_type t)
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 24/32] parsing_c: unparse_cocci: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (22 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 23/32] parsing_c: type_annoter_c: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 25/32] parsing_c: visitor_c: Visit " Jaskaran Singh
                   ` (7 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
unparse_cocci.ml.

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

diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index 395b3a3c..081bcdd9 100644
--- a/parsing_c/unparse_cocci.ml
+++ b/parsing_c/unparse_cocci.ml
@@ -455,7 +455,7 @@ let rec expression e =
     | Ast_c.RecordPtAccess (e, name) -> postfix
     | Ast_c.SizeOfExpr (e) -> unary
     | Ast_c.SizeOfType (t) -> unary
-    | Ast_c.Cast (t, e) -> cast
+    | Ast_c.Cast (t, e, a) -> cast
     | Ast_c.StatementExpr (statxs, _) -> top
     | Ast_c.Constructor (t, init) -> unary
     | Ast_c.ParenExpr (e) -> primary
@@ -503,8 +503,10 @@ let rec expression e =
       loop exp postfix; mcode print_string pt; ident field
   | Ast.RecordPtAccess(exp,ar,field) ->
       loop exp postfix; mcode print_string ar; ident field
-  | Ast.Cast(lp,ty,rp,exp) ->
+  | Ast.Cast(lp,ty,attr,rp,exp) ->
       mcode print_string_box lp; fullType ty; close_box();
+      (if not (attr = []) then pr_space());
+      print_between pr_space (mcode print_string) attr;
       mcode print_string rp; loop exp cast
   | Ast.SizeOfExpr(sizeof,exp) ->
       mcode print_string sizeof; loop exp unary
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 25/32] parsing_c: visitor_c: Visit Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (23 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 24/32] parsing_c: unparse_cocci: " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 26/32] engine: check_exhaustive_pattern: Reflect " Jaskaran Singh
                   ` (6 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the C AST. Visit these attributes in
the C AST visitor.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_c/visitor_c.ml | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/parsing_c/visitor_c.ml b/parsing_c/visitor_c.ml
index 57b5f32b..1a522413 100644
--- a/parsing_c/visitor_c.ml
+++ b/parsing_c/visitor_c.ml
@@ -324,7 +324,9 @@ let rec vk_expr = fun bigf expr ->
 
     | SizeOfExpr  (e) -> exprf e
     | SizeOfType  (t) -> vk_type bigf t
-    | Cast    (t, e) -> vk_type bigf t; exprf e
+    | Cast    (t, e, a) ->
+        vk_type bigf t; exprf e;
+        a +> List.iter (vk_attribute bigf)
 
     (* old: | StatementExpr (((declxs, statxs), is)), is2 ->
      *          List.iter (vk_decl bigf) declxs;
@@ -1188,7 +1190,11 @@ let rec vk_expr_s = fun bigf expr ->
 
       | SizeOfExpr  (e) -> SizeOfExpr (exprf e)
       | SizeOfType  (t) -> SizeOfType (vk_type_s bigf t)
-      | Cast    (t, e)  -> Cast (vk_type_s bigf t, exprf e)
+      | Cast    (t, e, a)  ->
+          Cast
+            (vk_type_s bigf t,
+             exprf e,
+             a +> List.map (vk_attribute_s bigf))
 
       | StatementExpr (statxs, is) ->
           StatementExpr (
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 26/32] engine: check_exhaustive_pattern: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (24 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 25/32] parsing_c: visitor_c: Visit " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 27/32] engine: cocci_vs_c: Match " Jaskaran Singh
                   ` (5 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
check_exhaustive_pattern.ml.

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 engine/check_exhaustive_pattern.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/engine/check_exhaustive_pattern.ml b/engine/check_exhaustive_pattern.ml
index 903c32ff..d7785fc7 100644
--- a/engine/check_exhaustive_pattern.ml
+++ b/engine/check_exhaustive_pattern.ml
@@ -123,7 +123,7 @@ let dumb_astcocci_expr = function
  | A.ArrayAccess (ea1, _, ea2, _) -> ()
  | A.RecordAccess (ea, _, ida) -> ()
  | A.RecordPtAccess (ea, _, ida) -> ()
- | A.Cast (_, typa, _, ea) -> ()
+ | A.Cast (_, typa, attra, _, ea) -> ()
  | A.SizeOfExpr (_, ea) -> ()
  | A.SizeOfType (_, _, typa, _) -> ()
  | A.TypeExp (typa) -> ()
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 27/32] engine: cocci_vs_c: Match Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (25 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 26/32] engine: check_exhaustive_pattern: Reflect " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 28/32] ocaml: coccilib: Reflect " Jaskaran Singh
                   ` (4 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the C and SmPL ASTs. Match these attributes
in cocci_vs_c.ml.

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

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index 317fa71e..0001ec2a 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -1121,7 +1121,7 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) =
        * differentiate between different cases *)
       let rec matches_id = function
 	  B.Ident(name) -> true
-	| B.Cast(ty,e) -> matches_id (B.unwrap_expr e)
+	| B.Cast(ty,e,a) -> matches_id (B.unwrap_expr e)
 	| _ -> false in
       let form_ok =
 	match (form,expr) with
@@ -1137,7 +1137,7 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) =
 		    true
                   end
                   else false
-	      | B.Cast(ty,e) -> matches (B.unwrap_expr e)
+	      | B.Cast(ty,e,a) -> matches (B.unwrap_expr e)
 	      |	B.Unary(e,B.UnMinus) -> matches (B.unwrap_expr e)
 	      | B.SizeOfExpr(exp) -> true
 	      | B.SizeOfType(ty) -> true
@@ -1525,16 +1525,26 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) =
    *    by trying | ea, B.Case (typb, eb) -> match_e_e ea eb ?
    *)
 
-  | A.Cast (ia1, typa, ia2, ea), ((B.Cast (typb, eb), typ),ii) ->
+  | A.Cast (ia1, typa, attrsa, ia2, ea),
+    ((B.Cast (typb, eb, attrsb), typ),ii) ->
+
+      let attr_allminus =
+        let mcode_is_not_context = function
+          | (_,_,A.CONTEXT(_,_),_) -> false
+          | _ -> true in
+        check_allminus.Visitor_ast.combiner_fullType typa &&
+        List.for_all mcode_is_not_context attrsa in
+
       let (ib1, ib2) = tuple_of_list2 ii in
       fullType typa typb >>= (fun typa typb ->
+      attribute_list attr_allminus attrsa attrsb >>= (fun attrsa attrsb ->
       expression ea eb >>= (fun ea eb ->
       tokenf ia1 ib1 >>= (fun ia1 ib1 ->
       tokenf ia2 ib2 >>= (fun ia2 ib2 ->
         return (
-          ((A.Cast (ia1, typa, ia2, ea))) +> wa,
-          ((B.Cast (typb, eb),typ),[ib1;ib2])
-        )))))
+          ((A.Cast (ia1, typa, attrsa, ia2, ea))) +> wa,
+          ((B.Cast (typb, eb, attrsb),typ),[ib1;ib2])
+        ))))))
 
   | A.SizeOfExpr (ia1, ea), ((B.SizeOfExpr (eb), typ),ii) ->
       let ib1 = tuple_of_list1 ii in
@@ -1641,7 +1651,7 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) =
 
 
   | _,
-     (((B.Cast (_, _)|B.ParenExpr _|B.SizeOfType _|B.SizeOfExpr _|
+     (((B.Cast (_, _, _)|B.ParenExpr _|B.SizeOfType _|B.SizeOfExpr _|
      B.Constructor (_, _)|
      B.RecordPtAccess (_, _)|
      B.RecordAccess (_, _)|B.ArrayAccess (_, _)|
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 28/32] ocaml: coccilib: Reflect Cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (26 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 27/32] engine: cocci_vs_c: Match " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 29/32] tools: spgen: Reflect Cast attrs Jaskaran Singh
                   ` (3 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the C and SmPL ASTs. Reflect these changes
in coccilib.mli.

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

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index a305d616..0c379547 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -146,7 +146,7 @@ module Ast_c :
       | RecordPtAccess of expression * name
       | SizeOfExpr of expression
       | SizeOfType of fullType
-      | Cast of fullType * expression
+      | Cast of fullType * expression * attribute list
       | StatementExpr of compound wrap
       | Constructor of fullType * initialiser
       | ParenExpr of expression
@@ -2569,7 +2569,7 @@ module Ast_cocci :
       | ArrayAccess of expression * string mcode * expression * string mcode
       | RecordAccess of expression * string mcode * ident
       | RecordPtAccess of expression * string mcode * ident
-      | Cast of string mcode * fullType * string mcode * expression
+      | Cast of string mcode * fullType * attr list * string mcode * expression
       | SizeOfExpr of string mcode * expression
       | SizeOfType of string mcode * string mcode * fullType * string mcode
       | TypeExp of fullType
@@ -3305,7 +3305,7 @@ module Ast0_cocci :
       | ArrayAccess of expression * string mcode * expression * string mcode
       | RecordAccess of expression * string mcode * ident
       | RecordPtAccess of expression * string mcode * ident
-      | Cast of string mcode * typeC * string mcode * expression
+      | Cast of string mcode * typeC * attr list * string mcode * expression
       | SizeOfExpr of string mcode * expression
       | SizeOfType of string mcode * string mcode * typeC * string mcode
       | TypeExp of typeC
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 29/32] tools: spgen: Reflect Cast attrs
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (27 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 28/32] ocaml: coccilib: Reflect " Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 30/32] tests: Add test case to check cast attribute allminus Jaskaran Singh
                   ` (2 subsequent siblings)
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Cast attributes are added to the SmPL AST. Reflect these changes in
position_generator.ml.

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

diff --git a/tools/spgen/source/position_generator.ml b/tools/spgen/source/position_generator.ml
index 757faf5f..9143a474 100644
--- a/tools/spgen/source/position_generator.ml
+++ b/tools/spgen/source/position_generator.ml
@@ -359,9 +359,9 @@ let rec expression_pos exp snp
       let c ~exp ~id = Ast0.RecordPtAccess(exp, arrow, id) in
       let alt() = id_wrap ~id ~constructor:(c ~exp) snp in
       exp_wrap ~exp ~constructor:(c ~id) ~alt snp
-  | Ast0.Cast(lp, typec, rp, exp) ->
+  | Ast0.Cast(lp, typec, attr, rp, exp) ->
       let _ = type_pos typec snp in (* sanity check for disj *)
-      let c ~exp ~mc = Ast0.Cast(lp, typec, mc, exp) in
+      let c ~exp ~mc = Ast0.Cast(lp, typec, attr, mc, exp) in
       let alt() = mcode_wrap ~mc:rp ~constructor:(c ~exp) snp in
       exp_wrap ~exp ~constructor:(c ~mc:rp) ~alt snp
   | Ast0.SizeOfExpr(sizeofmc, exp) ->
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 30/32] tests: Add test case to check cast attribute allminus
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (28 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 29/32] tools: spgen: Reflect Cast attrs Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 31/32] tests: Add test case to remove cast attributes Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 32/32] tests: Add test case to detect " Jaskaran Singh
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Add a test case to check allminus for cast attributes. The test case
replaces all the cast types in the C program. Cases covered are for when
the attribute is:

- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.

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

diff --git a/tests/remove_cast_attr_allminus.c b/tests/remove_cast_attr_allminus.c
new file mode 100644
index 00000000..4f6da3e4
--- /dev/null
+++ b/tests/remove_cast_attr_allminus.c
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+	int *a = (int __cast_attr) x;
+	int *a = (__cast_attr int) x;
+	int *a = (int __cast_attr *) x;
+	int *a = (int *__cast_attr) x;
+	int *a = (int) x;
+}
diff --git a/tests/remove_cast_attr_allminus.cocci b/tests/remove_cast_attr_allminus.cocci
new file mode 100644
index 00000000..320fee93
--- /dev/null
+++ b/tests/remove_cast_attr_allminus.cocci
@@ -0,0 +1,9 @@
+@r0@
+type T;
+identifier x;
+@@
+
+  (
+-	T
++	int *
+  ) x
diff --git a/tests/remove_cast_attr_allminus.res b/tests/remove_cast_attr_allminus.res
new file mode 100644
index 00000000..befec630
--- /dev/null
+++ b/tests/remove_cast_attr_allminus.res
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+	int *a = (int *) x;
+	int *a = (int *) x;
+	int *a = (int *) x;
+	int *a = (int *) x;
+	int *a = (int *) x;
+}
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 31/32] tests: Add test case to remove cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (29 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 30/32] tests: Add test case to check cast attribute allminus Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 32/32] tests: Add test case to detect " Jaskaran Singh
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Add a test case to remove a cast attribute. The following cases are
covered for when a attribute is:

- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.

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

diff --git a/tests/remove_cast_attr.c b/tests/remove_cast_attr.c
new file mode 100644
index 00000000..4f6da3e4
--- /dev/null
+++ b/tests/remove_cast_attr.c
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+	int *a = (int __cast_attr) x;
+	int *a = (__cast_attr int) x;
+	int *a = (int __cast_attr *) x;
+	int *a = (int *__cast_attr) x;
+	int *a = (int) x;
+}
diff --git a/tests/remove_cast_attr.cocci b/tests/remove_cast_attr.cocci
new file mode 100644
index 00000000..f171d44d
--- /dev/null
+++ b/tests/remove_cast_attr.cocci
@@ -0,0 +1,10 @@
+@r0@
+type T;
+attribute name __cast_attr;
+identifier x;
+@@
+
+  (
+	T
+-	__cast_attr
+  ) x
diff --git a/tests/remove_cast_attr.res b/tests/remove_cast_attr.res
new file mode 100644
index 00000000..fb5001b9
--- /dev/null
+++ b/tests/remove_cast_attr.res
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+	int *a = (int) x;
+	int *a = (int) x;
+	int *a = (int *) x;
+	int *a = (int *) x;
+	int *a = (int) x;
+}
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH 32/32] tests: Add test case to detect cast attributes
  2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
                   ` (30 preceding siblings ...)
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 31/32] tests: Add test case to remove cast attributes Jaskaran Singh
@ 2020-04-28 17:02 ` Jaskaran Singh
  31 siblings, 0 replies; 43+ messages in thread
From: Jaskaran Singh @ 2020-04-28 17:02 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

Add a test case to detect a cast attribute. The following cases are
covered for when a attribute is:

- Before the cast type.
- After the cast type.
- After the cast type and before the *.
- After the cast type and *.

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

diff --git a/tests/detect_cast_attr.c b/tests/detect_cast_attr.c
new file mode 100644
index 00000000..2458ef05
--- /dev/null
+++ b/tests/detect_cast_attr.c
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+	char *a = (int __cast_attr) x;
+	char *a = (__cast_attr int) x;
+	char *a = (int __cast_attr *) x;
+	char *a = (int *__cast_attr) x;
+	char *a = (int) x;
+}
diff --git a/tests/detect_cast_attr.cocci b/tests/detect_cast_attr.cocci
new file mode 100644
index 00000000..d626048f
--- /dev/null
+++ b/tests/detect_cast_attr.cocci
@@ -0,0 +1,11 @@
+@r0@
+type T;
+attribute name __cast_attr;
+identifier x;
+@@
+
+  (
+-	T
++	char *
+ 	__cast_attr
+  ) x
diff --git a/tests/detect_cast_attr.res b/tests/detect_cast_attr.res
new file mode 100644
index 00000000..2a273316
--- /dev/null
+++ b/tests/detect_cast_attr.res
@@ -0,0 +1,10 @@
+#define __cast_attr MACROANNOTATION
+
+int func()
+{
+	char *a = (char *__cast_attr) x;
+	char *a = (__cast_attr char *) x;
+	char *a = (char *__cast_attr) x;
+	char *a = (char *__cast_attr) x;
+	char *a = (int) x;
+}
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name Jaskaran Singh
@ 2020-05-03 19:23   ` Julia Lawall
  2020-05-04  9:06     ` Jaskaran Singh
  0 siblings, 1 reply; 43+ messages in thread
From: Julia Lawall @ 2020-05-03 19:23 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Tue, 28 Apr 2020, Jaskaran Singh wrote:

> To add Cast attributes to the C AST, pass attributes from the type_name
> rule of the C parser.

I'm not sure what you mean by "pass".  Normally, one passes something to
something else, but it's not clear what the something else is.

>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  ocaml/coccilib.mli     |  3 ++-
>  parsing_c/parse_c.ml   |  4 +++-
>  parsing_c/parser_c.mly | 16 ++++++++--------
>  3 files changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
> index 0e807c9a..a305d616 100644
> --- a/ocaml/coccilib.mli
> +++ b/ocaml/coccilib.mli
> @@ -791,7 +791,8 @@ module Parser_c :
>        (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.statement
>      val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.expression
>      val type_name :
> -      (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.fullType
> +      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> +      Ast_c.attribute list * Ast_c.fullType
>    end
>  module Lexer_c :
>    sig
> diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
> index 0d3a189a..5f8d5e2d 100644
> --- a/parsing_c/parse_c.ml
> +++ b/parsing_c/parse_c.ml
> @@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s =
>    result
>
>  (* Please DO NOT remove this code, even though most of it is not used *)
> -let type_of_string       = parse_gen ~cpp:false ~tos:true Parser_c.type_name
> +let type_of_string s     =
> +  let typname = parse_gen ~cpp:false ~tos:true Parser_c.type_name s in
> +  Common.snd typname
>  let statement_of_string  = parse_gen ~cpp:false ~tos:false Parser_c.statement
>  let expression_of_string = parse_gen ~cpp:false ~tos:false Parser_c.expr
>  let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false Parser_c.expr
> diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
> index aedde179..0abcc9b0 100644
> --- a/parsing_c/parser_c.mly
> +++ b/parsing_c/parser_c.mly
> @@ -665,7 +665,7 @@ let postfakeInfo pii  =
>
>  %type <Ast_c.statement> statement
>  %type <Ast_c.expression> expr
> -%type <Ast_c.fullType> type_name
> +%type <Ast_c.attribute list * Ast_c.fullType> type_name
>
>  %%
>  /*(*************************************************************************)*/
> @@ -818,7 +818,7 @@ arith_expr:
>
>  cast_expr:
>   | unary_expr                        { $1 }
> - | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4)) [$1;$3] }
> + | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4)) [$1;$3] }
>  /*
>  It could be useful to have the following, but there is no place for the
>  attribute in the AST.
> @@ -831,7 +831,7 @@ unary_expr:
>   | TDec unary_expr                 { mk_e(Infix ($2, Dec))    [$1] }
>   | unary_op cast_expr              { mk_e(Unary ($2, fst $1)) [snd $1] }
>   | Tsizeof unary_expr              { mk_e(SizeOfExpr ($2))    [$1] }
> - | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType ($3))    [$1;$2;$4] }
> + | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType (snd $3))    [$1;$2;$4] }

There could be less white space in front of the [

julia

>   | Tnew new_argument               { mk_e(New (None, $2))     [$1] }
>   | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New (Some $3, $5))             [$1; $2; $4] }
>   | Tdelete cast_expr               { mk_e(Delete(false, $2))  [$1] }
> @@ -897,9 +897,9 @@ postfix_expr:
>
>   /*(* gccext: also called compound literals *)*/
>   | topar2 type_name tcpar2 TOBrace TCBrace
> -     { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3] }
> +     { mk_e(Constructor (snd $2, (InitList [], [$4;$5]))) [$1;$3] }
>   | topar2 type_name tcpar2 TOBrace initialize_list gcc_comma_opt_struct TCBrace
> -     { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] }
> +     { mk_e(Constructor (snd $2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] }
>
>
>  primary_expr:
> @@ -1298,7 +1298,7 @@ type_spec2:
>         Right3 (TypeName (name, Ast_c.noTypedefDef())),[] }
>
>   | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)), [$1;$2;$4] }
> - | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType ($3)), [$1;$2;$4] }
> + | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType (snd $3)), [$1;$2;$4] }
>
>  /*(*----------------------------*)*/
>  /*(* workarounds *)*/
> @@ -1531,12 +1531,12 @@ type_qualif_list:
>  type_name:
>   | spec_qualif_list
>       { let (attrs, ds) = $1 in
> -       let (returnType, _) = fixDeclSpecForDecl ds in returnType }
> +       let (returnType, _) = fixDeclSpecForDecl ds in (attrs, returnType) }
>   | spec_qualif_list abstract_declaratort
>       { let (attrs1, ds) = $1 in
>         let (attrs2, fn) = $2 in
>         let (returnType, _) = fixDeclSpecForDecl ds in
> -       fn returnType }
> +       (attrs1@attrs2, fn returnType) }
>
>
>
> --
> 2.21.1
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 03/32] parsing_cocci: parser: Parse cast attributes
  2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 03/32] parsing_cocci: parser: Parse " Jaskaran Singh
@ 2020-05-03 19:26   ` Julia Lawall
  0 siblings, 0 replies; 43+ messages in thread
From: Julia Lawall @ 2020-05-03 19:26 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Tue, 28 Apr 2020, Jaskaran Singh wrote:

> Cast attributes are added to the SmPL ASTs. Parse these attributes in
> the SmPL parser and place them in the SmPL AST. The added production
> only supports attributes after the type and before the expression.

It would be good to say that on matching the attributes will be searched
for anywhere, if that is the case.

julia

>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/parser_cocci_menhir.mly | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
> index db5661bd..38b0e039 100644
> --- a/parsing_cocci/parser_cocci_menhir.mly
> +++ b/parsing_cocci/parser_cocci_menhir.mly
> @@ -2176,11 +2176,12 @@ arith_expr_bis:
>
>  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,
> +  | lp=TOPar t=ctype ar=attr_list rp=TCPar e=cast_expr(r,pe)
> +      { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t, ar,
>                               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,
> +  | lp=TOPar t=ctype d=direct_abstract_d ar=attr_list rp=TCPar
> +    e=cast_expr(r,pe)
> +      { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t, ar,
>  			     P.clt2mcode ")" rp, e)) }
>
>  unary_expr(r,pe):
> --
> 2.21.1
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 09/32] parsing_cocci: arity: Reflect Cast attributes
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 09/32] parsing_cocci: arity: " Jaskaran Singh
@ 2020-05-03 19:28   ` Julia Lawall
  0 siblings, 0 replies; 43+ messages in thread
From: Julia Lawall @ 2020-05-03 19:28 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: julia.lawall, linux-kernel-mentees, cocci



On Tue, 28 Apr 2020, Jaskaran Singh wrote:

> Cast attributes are added to the SmPL AST. Reflect these changes in
> arity.ml.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/arity.ml | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
> index 8ee6d33f..880cd7a3 100644
> --- a/parsing_cocci/arity.ml
> +++ b/parsing_cocci/arity.ml
> @@ -254,13 +254,14 @@ let rec top_expression opt_allowed tgt expr =
>        let ar = mcode ar in
>        let field = ident false arity field in
>        make_exp expr tgt arity (Ast0.RecordPtAccess(exp,ar,field))
> -  | Ast0.Cast(lp,ty,rp,exp) ->
> +  | Ast0.Cast(lp,ty,attr,rp,exp) ->
>        let arity = exp_same (mcode2line lp) [mcode2arity lp;mcode2arity rp] in
>        let lp = mcode lp in
>        let ty = typeC arity ty in
> +      let attr = List.map mcode attr in

Since attrs are mcodes, they should be reflected in the list that is given
to exp_same.

julia


>        let rp = mcode rp in
>        let exp = expression arity exp in
> -      make_exp expr tgt arity (Ast0.Cast(lp,ty,rp,exp))
> +      make_exp expr tgt arity (Ast0.Cast(lp,ty,attr,rp,exp))
>    | Ast0.SizeOfExpr(szf,exp) ->
>        let arity = exp_same (mcode2line szf) [mcode2arity szf] in
>        let szf = mcode szf in
> --
> 2.21.1
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 15/32] parsing_cocci: visitor_ast: Visit cast attributes
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 15/32] parsing_cocci: visitor_ast: Visit " Jaskaran Singh
@ 2020-05-03 19:29   ` Julia Lawall
  0 siblings, 0 replies; 43+ messages in thread
From: Julia Lawall @ 2020-05-03 19:29 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: julia.lawall, linux-kernel-mentees, cocci



On Tue, 28 Apr 2020, Jaskaran Singh wrote:

> Cast attributes are added to AST0 of SmPL. Visit these attributes in the

AST0 -> AST

julia

> SmPL AST visitor.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_cocci/visitor_ast.ml | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
> index 8e530114..644bcd5d 100644
> --- a/parsing_cocci/visitor_ast.ml
> +++ b/parsing_cocci/visitor_ast.ml
> @@ -198,12 +198,13 @@ let combiner bind option_default
>  	  let lar = string_mcode ar in
>  	  let lfield = ident field in
>  	  multibind [lexp; lar; lfield]
> -      | Ast.Cast(lp,ty,rp,exp) ->
> +      | Ast.Cast(lp,ty,attr,rp,exp) ->
>  	  let llp = string_mcode lp in
>  	  let lty = fullType ty in
> +	  let lattr = multibind (List.map string_mcode attr) in
>  	  let lrp = string_mcode rp in
>  	  let lexp = expression exp in
> -	  multibind [llp; lty; lrp; lexp]
> +          multibind [llp; lty; lattr; lrp; lexp]
>        | Ast.SizeOfExpr(szf,exp) ->
>  	  let lszf = string_mcode szf in
>  	  let lexp = expression exp in
> @@ -1184,12 +1185,13 @@ let rebuilder
>  	    let lar = string_mcode ar in
>  	    let lfield = ident field in
>  	    Ast.RecordPtAccess(lexp, lar, lfield)
> -	| Ast.Cast(lp,ty,rp,exp) ->
> +	| Ast.Cast(lp,ty,attr,rp,exp) ->
>  	    let llp = string_mcode lp in
>  	    let lty = fullType ty in
> +	    let lattr = List.map string_mcode attr in
>  	    let lrp = string_mcode rp in
>  	    let lexp = expression exp in
> -	    Ast.Cast(llp, lty, lrp, lexp)
> +	    Ast.Cast(llp, lty, lattr, lrp, lexp)
>  	| Ast.SizeOfExpr(szf,exp) ->
>  	    let lszf = string_mcode szf in
>  	    let lexp = expression exp in
> --
> 2.21.1
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 20/32] parsing_c: ast_c: Add Cast attributes
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 20/32] parsing_c: ast_c: Add " Jaskaran Singh
@ 2020-05-03 19:31   ` Julia Lawall
  0 siblings, 0 replies; 43+ messages in thread
From: Julia Lawall @ 2020-05-03 19:31 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Tue, 28 Apr 2020, Jaskaran Singh wrote:

> Add cast attributes to the C AST. This is a list of attributes in the
> Cast type of the C AST.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_c/ast_c.ml  | 2 +-
>  parsing_c/ast_c.mli | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/parsing_c/ast_c.ml b/parsing_c/ast_c.ml
> index f25f9b55..6a828943 100644
> --- a/parsing_c/ast_c.ml
> +++ b/parsing_c/ast_c.ml
> @@ -343,7 +343,7 @@ and expression = (expressionbis * exp_info ref (* semantic: *)) wrap3
>
>    | SizeOfExpr     of expression
>    | SizeOfType     of fullType
> -  | Cast           of fullType * expression
> +  | Cast           of fullType * expression * attribute list
>
>    (* gccext: *)
>    | StatementExpr of compound wrap (* ( )     new scope *)
> diff --git a/parsing_c/ast_c.mli b/parsing_c/ast_c.mli
> index 8923a335..8a9a6f66 100644
> --- a/parsing_c/ast_c.mli
> +++ b/parsing_c/ast_c.mli
> @@ -104,7 +104,7 @@ and expressionbis =
>    | RecordPtAccess of expression * name
>    | SizeOfExpr of expression
>    | SizeOfType of fullType
> -  | Cast of fullType * expression
> +  | Cast of fullType * expression * attribute list

Maybe it would make more sense to put the attribute list after the
fullType, as is done for the SmPL AST?

julia

>    | StatementExpr of compound wrap
>    | Constructor of fullType * initialiser
>    | ParenExpr of expression
> --
> 2.21.1
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 22/32] parsing_c: pretty_print_c: Reflect Cast attributes
  2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 22/32] parsing_c: pretty_print_c: Reflect " Jaskaran Singh
@ 2020-05-03 19:32   ` Julia Lawall
  0 siblings, 0 replies; 43+ messages in thread
From: Julia Lawall @ 2020-05-03 19:32 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Tue, 28 Apr 2020, Jaskaran Singh wrote:

> Cast attributes are added to the SmPL AST. Print these attributes in
> pretty_print_c.ml.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_c/pretty_print_c.ml | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml
> index 99a7e0ed..96a11d72 100644
> --- a/parsing_c/pretty_print_c.ml
> +++ b/parsing_c/pretty_print_c.ml
> @@ -146,8 +146,9 @@ let mk_pretty_printers
>  	pp_expression e
>      | SizeOfType  (t),     [i1;i2;i3] ->
>          pr_elem i1; pr_elem i2; pp_type t; pr_elem i3
> -    | Cast    (t, e),      [i1;i2] ->
> -        pr_elem i1; pp_type t; pr_elem i2; pp_expression e
> +    | Cast    (t, e, a),      [i1;i2] ->

Less space in front of the [

julia

> +        pr_elem i1; pp_type t; pr_elem i2; pp_expression e;
> +        a +> pp_attributes pr_elem pr_space
>
>      | StatementExpr (statxs, [ii1;ii2]),  [i1;i2] ->
>          pr_elem i1;
> @@ -184,7 +185,7 @@ let mk_pretty_printers
>      | CondExpr (_,_,_) | Sequence (_,_) | Assignment (_,_,_)
>      | Postfix (_,_) | Infix (_,_) | Unary (_,_) | Binary (_,_,_)
>      | ArrayAccess (_,_) | RecordAccess (_,_) | RecordPtAccess (_,_)
> -    | SizeOfExpr (_) | SizeOfType (_) | Cast (_,_)
> +    | SizeOfExpr (_) | SizeOfType (_) | Cast (_,_,_)
>      | StatementExpr (_) | Constructor _
>      | ParenExpr (_) | New (_) | Delete (_,_)
>      | Defined (_)),_ -> raise (Impossible 95)
> --
> 2.21.1
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name
  2020-05-03 19:23   ` Julia Lawall
@ 2020-05-04  9:06     ` Jaskaran Singh
  2020-05-04  9:17       ` Julia Lawall
  0 siblings, 1 reply; 43+ messages in thread
From: Jaskaran Singh @ 2020-05-04  9:06 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel-mentees, cocci

On Sun, 2020-05-03 at 21:23 +0200, Julia Lawall wrote:
> 
> On Tue, 28 Apr 2020, Jaskaran Singh wrote:
> 
> > To add Cast attributes to the C AST, pass attributes from the
> > type_name
> > rule of the C parser.
> 
> I'm not sure what you mean by "pass".  Normally, one passes something
> to
> something else, but it's not clear what the something else is.
> 

The something else would be the cast_expr rule (and basically any other
rule that uses the type_name rule).

I guess a better way to say it would be "return the attributes from the
type_name rule as well" (or if there is a specific term for it in
parser-terminology, then that).

Cheers,
Jaskaran.

> > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > ---
> >  ocaml/coccilib.mli     |  3 ++-
> >  parsing_c/parse_c.ml   |  4 +++-
> >  parsing_c/parser_c.mly | 16 ++++++++--------
> >  3 files changed, 13 insertions(+), 10 deletions(-)
> > 
> > diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
> > index 0e807c9a..a305d616 100644
> > --- a/ocaml/coccilib.mli
> > +++ b/ocaml/coccilib.mli
> > @@ -791,7 +791,8 @@ module Parser_c :
> >        (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.statement
> >      val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > Ast_c.expression
> >      val type_name :
> > -      (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.fullType
> > +      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > +      Ast_c.attribute list * Ast_c.fullType
> >    end
> >  module Lexer_c :
> >    sig
> > diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
> > index 0d3a189a..5f8d5e2d 100644
> > --- a/parsing_c/parse_c.ml
> > +++ b/parsing_c/parse_c.ml
> > @@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s =
> >    result
> > 
> >  (* Please DO NOT remove this code, even though most of it is not
> > used *)
> > -let type_of_string       = parse_gen ~cpp:false ~tos:true
> > Parser_c.type_name
> > +let type_of_string s     =
> > +  let typname = parse_gen ~cpp:false ~tos:true Parser_c.type_name
> > s in
> > +  Common.snd typname
> >  let statement_of_string  = parse_gen ~cpp:false ~tos:false
> > Parser_c.statement
> >  let expression_of_string = parse_gen ~cpp:false ~tos:false
> > Parser_c.expr
> >  let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false
> > Parser_c.expr
> > diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
> > index aedde179..0abcc9b0 100644
> > --- a/parsing_c/parser_c.mly
> > +++ b/parsing_c/parser_c.mly
> > @@ -665,7 +665,7 @@ let postfakeInfo pii  =
> > 
> >  %type <Ast_c.statement> statement
> >  %type <Ast_c.expression> expr
> > -%type <Ast_c.fullType> type_name
> > +%type <Ast_c.attribute list * Ast_c.fullType> type_name
> > 
> >  %%
> >  /*(***************************************************************
> > **********)*/
> > @@ -818,7 +818,7 @@ arith_expr:
> > 
> >  cast_expr:
> >   | unary_expr                        { $1 }
> > - | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4)) [$1;$3]
> > }
> > + | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4))
> > [$1;$3] }
> >  /*
> >  It could be useful to have the following, but there is no place
> > for the
> >  attribute in the AST.
> > @@ -831,7 +831,7 @@ unary_expr:
> >   | TDec unary_expr                 { mk_e(Infix ($2, Dec))    [$1]
> > }
> >   | unary_op cast_expr              { mk_e(Unary ($2, fst $1)) [snd
> > $1] }
> >   | Tsizeof unary_expr              { mk_e(SizeOfExpr ($2))    [$1]
> > }
> > - | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType
> > ($3))    [$1;$2;$4] }
> > + | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType (snd
> > $3))    [$1;$2;$4] }
> 
> There could be less white space in front of the [
> 
> julia
> 
> >   | Tnew new_argument               { mk_e(New (None, $2))     [$1]
> > }
> >   | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New (Some
> > $3, $5))             [$1; $2; $4] }
> >   | Tdelete cast_expr               { mk_e(Delete(false, $2))  [$1]
> > }
> > @@ -897,9 +897,9 @@ postfix_expr:
> > 
> >   /*(* gccext: also called compound literals *)*/
> >   | topar2 type_name tcpar2 TOBrace TCBrace
> > -     { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3] }
> > +     { mk_e(Constructor (snd $2, (InitList [], [$4;$5]))) [$1;$3]
> > }
> >   | topar2 type_name tcpar2 TOBrace initialize_list
> > gcc_comma_opt_struct TCBrace
> > -     { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @
> > $6))) [$1;$3] }
> > +     { mk_e(Constructor (snd $2, (InitList (List.rev $5),[$4;$7] @
> > $6))) [$1;$3] }
> > 
> > 
> >  primary_expr:
> > @@ -1298,7 +1298,7 @@ type_spec2:
> >         Right3 (TypeName (name, Ast_c.noTypedefDef())),[] }
> > 
> >   | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)),
> > [$1;$2;$4] }
> > - | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType ($3)),
> > [$1;$2;$4] }
> > + | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType (snd $3)),
> > [$1;$2;$4] }
> > 
> >  /*(*----------------------------*)*/
> >  /*(* workarounds *)*/
> > @@ -1531,12 +1531,12 @@ type_qualif_list:
> >  type_name:
> >   | spec_qualif_list
> >       { let (attrs, ds) = $1 in
> > -       let (returnType, _) = fixDeclSpecForDecl ds in returnType }
> > +       let (returnType, _) = fixDeclSpecForDecl ds in (attrs,
> > returnType) }
> >   | spec_qualif_list abstract_declaratort
> >       { let (attrs1, ds) = $1 in
> >         let (attrs2, fn) = $2 in
> >         let (returnType, _) = fixDeclSpecForDecl ds in
> > -       fn returnType }
> > +       (attrs1@attrs2, fn returnType) }
> > 
> > 
> > 
> > --
> > 2.21.1
> > 
> > 

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name
  2020-05-04  9:06     ` Jaskaran Singh
@ 2020-05-04  9:17       ` Julia Lawall
  2020-05-04  9:20         ` Jaskaran Singh
  0 siblings, 1 reply; 43+ messages in thread
From: Julia Lawall @ 2020-05-04  9:17 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 4 May 2020, Jaskaran Singh wrote:

> On Sun, 2020-05-03 at 21:23 +0200, Julia Lawall wrote:
> >
> > On Tue, 28 Apr 2020, Jaskaran Singh wrote:
> >
> > > To add Cast attributes to the C AST, pass attributes from the
> > > type_name
> > > rule of the C parser.
> >
> > I'm not sure what you mean by "pass".  Normally, one passes something
> > to
> > something else, but it's not clear what the something else is.
> >
>
> The something else would be the cast_expr rule (and basically any other
> rule that uses the type_name rule).
>
> I guess a better way to say it would be "return the attributes from the
> type_name rule as well"

This seems fine, thanks!

In this patch there are a lot of places where the information is just
discarded.  Will it be used in the future?

julia

> (or if there is a specific term for it in
> parser-terminology, then that).
>
> Cheers,
> Jaskaran.
>
> > > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > > ---
> > >  ocaml/coccilib.mli     |  3 ++-
> > >  parsing_c/parse_c.ml   |  4 +++-
> > >  parsing_c/parser_c.mly | 16 ++++++++--------
> > >  3 files changed, 13 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
> > > index 0e807c9a..a305d616 100644
> > > --- a/ocaml/coccilib.mli
> > > +++ b/ocaml/coccilib.mli
> > > @@ -791,7 +791,8 @@ module Parser_c :
> > >        (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.statement
> > >      val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > Ast_c.expression
> > >      val type_name :
> > > -      (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.fullType
> > > +      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > +      Ast_c.attribute list * Ast_c.fullType
> > >    end
> > >  module Lexer_c :
> > >    sig
> > > diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
> > > index 0d3a189a..5f8d5e2d 100644
> > > --- a/parsing_c/parse_c.ml
> > > +++ b/parsing_c/parse_c.ml
> > > @@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s =
> > >    result
> > >
> > >  (* Please DO NOT remove this code, even though most of it is not
> > > used *)
> > > -let type_of_string       = parse_gen ~cpp:false ~tos:true
> > > Parser_c.type_name
> > > +let type_of_string s     =
> > > +  let typname = parse_gen ~cpp:false ~tos:true Parser_c.type_name
> > > s in
> > > +  Common.snd typname
> > >  let statement_of_string  = parse_gen ~cpp:false ~tos:false
> > > Parser_c.statement
> > >  let expression_of_string = parse_gen ~cpp:false ~tos:false
> > > Parser_c.expr
> > >  let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false
> > > Parser_c.expr
> > > diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
> > > index aedde179..0abcc9b0 100644
> > > --- a/parsing_c/parser_c.mly
> > > +++ b/parsing_c/parser_c.mly
> > > @@ -665,7 +665,7 @@ let postfakeInfo pii  =
> > >
> > >  %type <Ast_c.statement> statement
> > >  %type <Ast_c.expression> expr
> > > -%type <Ast_c.fullType> type_name
> > > +%type <Ast_c.attribute list * Ast_c.fullType> type_name
> > >
> > >  %%
> > >  /*(***************************************************************
> > > **********)*/
> > > @@ -818,7 +818,7 @@ arith_expr:
> > >
> > >  cast_expr:
> > >   | unary_expr                        { $1 }
> > > - | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4)) [$1;$3]
> > > }
> > > + | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4))
> > > [$1;$3] }
> > >  /*
> > >  It could be useful to have the following, but there is no place
> > > for the
> > >  attribute in the AST.
> > > @@ -831,7 +831,7 @@ unary_expr:
> > >   | TDec unary_expr                 { mk_e(Infix ($2, Dec))    [$1]
> > > }
> > >   | unary_op cast_expr              { mk_e(Unary ($2, fst $1)) [snd
> > > $1] }
> > >   | Tsizeof unary_expr              { mk_e(SizeOfExpr ($2))    [$1]
> > > }
> > > - | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType
> > > ($3))    [$1;$2;$4] }
> > > + | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType (snd
> > > $3))    [$1;$2;$4] }
> >
> > There could be less white space in front of the [
> >
> > julia
> >
> > >   | Tnew new_argument               { mk_e(New (None, $2))     [$1]
> > > }
> > >   | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New (Some
> > > $3, $5))             [$1; $2; $4] }
> > >   | Tdelete cast_expr               { mk_e(Delete(false, $2))  [$1]
> > > }
> > > @@ -897,9 +897,9 @@ postfix_expr:
> > >
> > >   /*(* gccext: also called compound literals *)*/
> > >   | topar2 type_name tcpar2 TOBrace TCBrace
> > > -     { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3] }
> > > +     { mk_e(Constructor (snd $2, (InitList [], [$4;$5]))) [$1;$3]
> > > }
> > >   | topar2 type_name tcpar2 TOBrace initialize_list
> > > gcc_comma_opt_struct TCBrace
> > > -     { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @
> > > $6))) [$1;$3] }
> > > +     { mk_e(Constructor (snd $2, (InitList (List.rev $5),[$4;$7] @
> > > $6))) [$1;$3] }
> > >
> > >
> > >  primary_expr:
> > > @@ -1298,7 +1298,7 @@ type_spec2:
> > >         Right3 (TypeName (name, Ast_c.noTypedefDef())),[] }
> > >
> > >   | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)),
> > > [$1;$2;$4] }
> > > - | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType ($3)),
> > > [$1;$2;$4] }
> > > + | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType (snd $3)),
> > > [$1;$2;$4] }
> > >
> > >  /*(*----------------------------*)*/
> > >  /*(* workarounds *)*/
> > > @@ -1531,12 +1531,12 @@ type_qualif_list:
> > >  type_name:
> > >   | spec_qualif_list
> > >       { let (attrs, ds) = $1 in
> > > -       let (returnType, _) = fixDeclSpecForDecl ds in returnType }
> > > +       let (returnType, _) = fixDeclSpecForDecl ds in (attrs,
> > > returnType) }
> > >   | spec_qualif_list abstract_declaratort
> > >       { let (attrs1, ds) = $1 in
> > >         let (attrs2, fn) = $2 in
> > >         let (returnType, _) = fixDeclSpecForDecl ds in
> > > -       fn returnType }
> > > +       (attrs1@attrs2, fn returnType) }
> > >
> > >
> > >
> > > --
> > > 2.21.1
> > >
> > >
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name
  2020-05-04  9:17       ` Julia Lawall
@ 2020-05-04  9:20         ` Jaskaran Singh
  2020-05-04 13:18           ` Julia Lawall
  0 siblings, 1 reply; 43+ messages in thread
From: Jaskaran Singh @ 2020-05-04  9:20 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel-mentees, cocci

On Mon, 2020-05-04 at 11:17 +0200, Julia Lawall wrote:
> 
> On Mon, 4 May 2020, Jaskaran Singh wrote:
> 
> > On Sun, 2020-05-03 at 21:23 +0200, Julia Lawall wrote:
> > > On Tue, 28 Apr 2020, Jaskaran Singh wrote:
> > > 
> > > > To add Cast attributes to the C AST, pass attributes from the
> > > > type_name
> > > > rule of the C parser.
> > > 
> > > I'm not sure what you mean by "pass".  Normally, one passes
> > > something
> > > to
> > > something else, but it's not clear what the something else is.
> > > 
> > 
> > The something else would be the cast_expr rule (and basically any
> > other
> > rule that uses the type_name rule).
> > 
> > I guess a better way to say it would be "return the attributes from
> > the
> > type_name rule as well"
> 
> This seems fine, thanks!
> 
> In this patch there are a lot of places where the information is just
> discarded.  Will it be used in the future?
> 

We could add support for those attributes as well (ex. typeof, sizeof,
etc.). This patch only adds support for cast attributes though.

Cheers,
Jaskaran.

> julia
> 
> > (or if there is a specific term for it in
> > parser-terminology, then that).
> > 
> > Cheers,
> > Jaskaran.
> > 
> > > > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > > > ---
> > > >  ocaml/coccilib.mli     |  3 ++-
> > > >  parsing_c/parse_c.ml   |  4 +++-
> > > >  parsing_c/parser_c.mly | 16 ++++++++--------
> > > >  3 files changed, 13 insertions(+), 10 deletions(-)
> > > > 
> > > > diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
> > > > index 0e807c9a..a305d616 100644
> > > > --- a/ocaml/coccilib.mli
> > > > +++ b/ocaml/coccilib.mli
> > > > @@ -791,7 +791,8 @@ module Parser_c :
> > > >        (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > > Ast_c.statement
> > > >      val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > > Ast_c.expression
> > > >      val type_name :
> > > > -      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > > Ast_c.fullType
> > > > +      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > > +      Ast_c.attribute list * Ast_c.fullType
> > > >    end
> > > >  module Lexer_c :
> > > >    sig
> > > > diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
> > > > index 0d3a189a..5f8d5e2d 100644
> > > > --- a/parsing_c/parse_c.ml
> > > > +++ b/parsing_c/parse_c.ml
> > > > @@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s =
> > > >    result
> > > > 
> > > >  (* Please DO NOT remove this code, even though most of it is
> > > > not
> > > > used *)
> > > > -let type_of_string       = parse_gen ~cpp:false ~tos:true
> > > > Parser_c.type_name
> > > > +let type_of_string s     =
> > > > +  let typname = parse_gen ~cpp:false ~tos:true
> > > > Parser_c.type_name
> > > > s in
> > > > +  Common.snd typname
> > > >  let statement_of_string  = parse_gen ~cpp:false ~tos:false
> > > > Parser_c.statement
> > > >  let expression_of_string = parse_gen ~cpp:false ~tos:false
> > > > Parser_c.expr
> > > >  let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false
> > > > Parser_c.expr
> > > > diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
> > > > index aedde179..0abcc9b0 100644
> > > > --- a/parsing_c/parser_c.mly
> > > > +++ b/parsing_c/parser_c.mly
> > > > @@ -665,7 +665,7 @@ let postfakeInfo pii  =
> > > > 
> > > >  %type <Ast_c.statement> statement
> > > >  %type <Ast_c.expression> expr
> > > > -%type <Ast_c.fullType> type_name
> > > > +%type <Ast_c.attribute list * Ast_c.fullType> type_name
> > > > 
> > > >  %%
> > > >  /*(***********************************************************
> > > > ****
> > > > **********)*/
> > > > @@ -818,7 +818,7 @@ arith_expr:
> > > > 
> > > >  cast_expr:
> > > >   | unary_expr                        { $1 }
> > > > - | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4))
> > > > [$1;$3]
> > > > }
> > > > + | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4))
> > > > [$1;$3] }
> > > >  /*
> > > >  It could be useful to have the following, but there is no
> > > > place
> > > > for the
> > > >  attribute in the AST.
> > > > @@ -831,7 +831,7 @@ unary_expr:
> > > >   | TDec unary_expr                 { mk_e(Infix ($2,
> > > > Dec))    [$1]
> > > > }
> > > >   | unary_op cast_expr              { mk_e(Unary ($2, fst $1))
> > > > [snd
> > > > $1] }
> > > >   | Tsizeof unary_expr              { mk_e(SizeOfExpr
> > > > ($2))    [$1]
> > > > }
> > > > - | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType
> > > > ($3))    [$1;$2;$4] }
> > > > + | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType (snd
> > > > $3))    [$1;$2;$4] }
> > > 
> > > There could be less white space in front of the [
> > > 
> > > julia
> > > 
> > > >   | Tnew new_argument               { mk_e(New (None,
> > > > $2))     [$1]
> > > > }
> > > >   | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New
> > > > (Some
> > > > $3, $5))             [$1; $2; $4] }
> > > >   | Tdelete cast_expr               { mk_e(Delete(false,
> > > > $2))  [$1]
> > > > }
> > > > @@ -897,9 +897,9 @@ postfix_expr:
> > > > 
> > > >   /*(* gccext: also called compound literals *)*/
> > > >   | topar2 type_name tcpar2 TOBrace TCBrace
> > > > -     { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3]
> > > > }
> > > > +     { mk_e(Constructor (snd $2, (InitList [], [$4;$5])))
> > > > [$1;$3]
> > > > }
> > > >   | topar2 type_name tcpar2 TOBrace initialize_list
> > > > gcc_comma_opt_struct TCBrace
> > > > -     { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @
> > > > $6))) [$1;$3] }
> > > > +     { mk_e(Constructor (snd $2, (InitList (List.rev
> > > > $5),[$4;$7] @
> > > > $6))) [$1;$3] }
> > > > 
> > > > 
> > > >  primary_expr:
> > > > @@ -1298,7 +1298,7 @@ type_spec2:
> > > >         Right3 (TypeName (name, Ast_c.noTypedefDef())),[] }
> > > > 
> > > >   | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)),
> > > > [$1;$2;$4] }
> > > > - | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType ($3)),
> > > > [$1;$2;$4] }
> > > > + | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType (snd
> > > > $3)),
> > > > [$1;$2;$4] }
> > > > 
> > > >  /*(*----------------------------*)*/
> > > >  /*(* workarounds *)*/
> > > > @@ -1531,12 +1531,12 @@ type_qualif_list:
> > > >  type_name:
> > > >   | spec_qualif_list
> > > >       { let (attrs, ds) = $1 in
> > > > -       let (returnType, _) = fixDeclSpecForDecl ds in
> > > > returnType }
> > > > +       let (returnType, _) = fixDeclSpecForDecl ds in (attrs,
> > > > returnType) }
> > > >   | spec_qualif_list abstract_declaratort
> > > >       { let (attrs1, ds) = $1 in
> > > >         let (attrs2, fn) = $2 in
> > > >         let (returnType, _) = fixDeclSpecForDecl ds in
> > > > -       fn returnType }
> > > > +       (attrs1@attrs2, fn returnType) }
> > > > 
> > > > 
> > > > 
> > > > --
> > > > 2.21.1
> > > > 
> > > > 

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name
  2020-05-04  9:20         ` Jaskaran Singh
@ 2020-05-04 13:18           ` Julia Lawall
  0 siblings, 0 replies; 43+ messages in thread
From: Julia Lawall @ 2020-05-04 13:18 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Mon, 4 May 2020, Jaskaran Singh wrote:

> On Mon, 2020-05-04 at 11:17 +0200, Julia Lawall wrote:
> >
> > On Mon, 4 May 2020, Jaskaran Singh wrote:
> >
> > > On Sun, 2020-05-03 at 21:23 +0200, Julia Lawall wrote:
> > > > On Tue, 28 Apr 2020, Jaskaran Singh wrote:
> > > >
> > > > > To add Cast attributes to the C AST, pass attributes from the
> > > > > type_name
> > > > > rule of the C parser.
> > > >
> > > > I'm not sure what you mean by "pass".  Normally, one passes
> > > > something
> > > > to
> > > > something else, but it's not clear what the something else is.
> > > >
> > >
> > > The something else would be the cast_expr rule (and basically any
> > > other
> > > rule that uses the type_name rule).
> > >
> > > I guess a better way to say it would be "return the attributes from
> > > the
> > > type_name rule as well"
> >
> > This seems fine, thanks!
> >
> > In this patch there are a lot of places where the information is just
> > discarded.  Will it be used in the future?
> >
>
> We could add support for those attributes as well (ex. typeof, sizeof,
> etc.). This patch only adds support for cast attributes though.

OK.  I'm not sure that attributes make sense for sizeof.  Perhaps give a
warning rather than just dropping it.

julia

>
> Cheers,
> Jaskaran.
>
> > julia
> >
> > > (or if there is a specific term for it in
> > > parser-terminology, then that).
> > >
> > > Cheers,
> > > Jaskaran.
> > >
> > > > > Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> > > > > ---
> > > > >  ocaml/coccilib.mli     |  3 ++-
> > > > >  parsing_c/parse_c.ml   |  4 +++-
> > > > >  parsing_c/parser_c.mly | 16 ++++++++--------
> > > > >  3 files changed, 13 insertions(+), 10 deletions(-)
> > > > >
> > > > > diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
> > > > > index 0e807c9a..a305d616 100644
> > > > > --- a/ocaml/coccilib.mli
> > > > > +++ b/ocaml/coccilib.mli
> > > > > @@ -791,7 +791,8 @@ module Parser_c :
> > > > >        (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > > > Ast_c.statement
> > > > >      val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > > > Ast_c.expression
> > > > >      val type_name :
> > > > > -      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > > > Ast_c.fullType
> > > > > +      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
> > > > > +      Ast_c.attribute list * Ast_c.fullType
> > > > >    end
> > > > >  module Lexer_c :
> > > > >    sig
> > > > > diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
> > > > > index 0d3a189a..5f8d5e2d 100644
> > > > > --- a/parsing_c/parse_c.ml
> > > > > +++ b/parsing_c/parse_c.ml
> > > > > @@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s =
> > > > >    result
> > > > >
> > > > >  (* Please DO NOT remove this code, even though most of it is
> > > > > not
> > > > > used *)
> > > > > -let type_of_string       = parse_gen ~cpp:false ~tos:true
> > > > > Parser_c.type_name
> > > > > +let type_of_string s     =
> > > > > +  let typname = parse_gen ~cpp:false ~tos:true
> > > > > Parser_c.type_name
> > > > > s in
> > > > > +  Common.snd typname
> > > > >  let statement_of_string  = parse_gen ~cpp:false ~tos:false
> > > > > Parser_c.statement
> > > > >  let expression_of_string = parse_gen ~cpp:false ~tos:false
> > > > > Parser_c.expr
> > > > >  let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false
> > > > > Parser_c.expr
> > > > > diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
> > > > > index aedde179..0abcc9b0 100644
> > > > > --- a/parsing_c/parser_c.mly
> > > > > +++ b/parsing_c/parser_c.mly
> > > > > @@ -665,7 +665,7 @@ let postfakeInfo pii  =
> > > > >
> > > > >  %type <Ast_c.statement> statement
> > > > >  %type <Ast_c.expression> expr
> > > > > -%type <Ast_c.fullType> type_name
> > > > > +%type <Ast_c.attribute list * Ast_c.fullType> type_name
> > > > >
> > > > >  %%
> > > > >  /*(***********************************************************
> > > > > ****
> > > > > **********)*/
> > > > > @@ -818,7 +818,7 @@ arith_expr:
> > > > >
> > > > >  cast_expr:
> > > > >   | unary_expr                        { $1 }
> > > > > - | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4))
> > > > > [$1;$3]
> > > > > }
> > > > > + | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4))
> > > > > [$1;$3] }
> > > > >  /*
> > > > >  It could be useful to have the following, but there is no
> > > > > place
> > > > > for the
> > > > >  attribute in the AST.
> > > > > @@ -831,7 +831,7 @@ unary_expr:
> > > > >   | TDec unary_expr                 { mk_e(Infix ($2,
> > > > > Dec))    [$1]
> > > > > }
> > > > >   | unary_op cast_expr              { mk_e(Unary ($2, fst $1))
> > > > > [snd
> > > > > $1] }
> > > > >   | Tsizeof unary_expr              { mk_e(SizeOfExpr
> > > > > ($2))    [$1]
> > > > > }
> > > > > - | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType
> > > > > ($3))    [$1;$2;$4] }
> > > > > + | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType (snd
> > > > > $3))    [$1;$2;$4] }
> > > >
> > > > There could be less white space in front of the [
> > > >
> > > > julia
> > > >
> > > > >   | Tnew new_argument               { mk_e(New (None,
> > > > > $2))     [$1]
> > > > > }
> > > > >   | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New
> > > > > (Some
> > > > > $3, $5))             [$1; $2; $4] }
> > > > >   | Tdelete cast_expr               { mk_e(Delete(false,
> > > > > $2))  [$1]
> > > > > }
> > > > > @@ -897,9 +897,9 @@ postfix_expr:
> > > > >
> > > > >   /*(* gccext: also called compound literals *)*/
> > > > >   | topar2 type_name tcpar2 TOBrace TCBrace
> > > > > -     { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3]
> > > > > }
> > > > > +     { mk_e(Constructor (snd $2, (InitList [], [$4;$5])))
> > > > > [$1;$3]
> > > > > }
> > > > >   | topar2 type_name tcpar2 TOBrace initialize_list
> > > > > gcc_comma_opt_struct TCBrace
> > > > > -     { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @
> > > > > $6))) [$1;$3] }
> > > > > +     { mk_e(Constructor (snd $2, (InitList (List.rev
> > > > > $5),[$4;$7] @
> > > > > $6))) [$1;$3] }
> > > > >
> > > > >
> > > > >  primary_expr:
> > > > > @@ -1298,7 +1298,7 @@ type_spec2:
> > > > >         Right3 (TypeName (name, Ast_c.noTypedefDef())),[] }
> > > > >
> > > > >   | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)),
> > > > > [$1;$2;$4] }
> > > > > - | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType ($3)),
> > > > > [$1;$2;$4] }
> > > > > + | Ttypeof TOPar type_name   TCPar { Right3 (TypeOfType (snd
> > > > > $3)),
> > > > > [$1;$2;$4] }
> > > > >
> > > > >  /*(*----------------------------*)*/
> > > > >  /*(* workarounds *)*/
> > > > > @@ -1531,12 +1531,12 @@ type_qualif_list:
> > > > >  type_name:
> > > > >   | spec_qualif_list
> > > > >       { let (attrs, ds) = $1 in
> > > > > -       let (returnType, _) = fixDeclSpecForDecl ds in
> > > > > returnType }
> > > > > +       let (returnType, _) = fixDeclSpecForDecl ds in (attrs,
> > > > > returnType) }
> > > > >   | spec_qualif_list abstract_declaratort
> > > > >       { let (attrs1, ds) = $1 in
> > > > >         let (attrs2, fn) = $2 in
> > > > >         let (returnType, _) = fixDeclSpecForDecl ds in
> > > > > -       fn returnType }
> > > > > +       (attrs1@attrs2, fn returnType) }
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > 2.21.1
> > > > >
> > > > >
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

end of thread, other threads:[~2020-05-04 13:19 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 17:01 [Linux-kernel-mentees] [PATCH 00/32] cocci: Add cast attributes to C and SmPL ASTs Jaskaran Singh
2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name Jaskaran Singh
2020-05-03 19:23   ` Julia Lawall
2020-05-04  9:06     ` Jaskaran Singh
2020-05-04  9:17       ` Julia Lawall
2020-05-04  9:20         ` Jaskaran Singh
2020-05-04 13:18           ` Julia Lawall
2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 02/32] parsing_cocci: ast0_cocci: Add cast attributes Jaskaran Singh
2020-04-28 17:01 ` [Linux-kernel-mentees] [PATCH 03/32] parsing_cocci: parser: Parse " Jaskaran Singh
2020-05-03 19:26   ` Julia Lawall
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 04/32] parsing_cocci: visitor_ast0: Visit " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 05/32] parsing_cocci: unparse_ast0: Reflect " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 06/32] parsing_cocci: index: Reflect Cast attributes Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 07/32] parsing_cocci: iso_pattern: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 08/32] parsing_cocci: type_infer: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 09/32] parsing_cocci: arity: " Jaskaran Singh
2020-05-03 19:28   ` Julia Lawall
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 10/32] parsing_cocci: check_meta: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 11/32] parsing_cocci: compute_lines: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 12/32] parsing_cocci: context_neg: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 13/32] parsing_cocci: single_statement: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 14/32] parsing_cocci: ast_cocci: Add cast attributes Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 15/32] parsing_cocci: visitor_ast: Visit " Jaskaran Singh
2020-05-03 19:29   ` Julia Lawall
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 16/32] parsing_cocci: pretty_print_cocci: Print " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 17/32] parsing_cocci: ast0toast: Reflect Cast attributes Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 18/32] parsing_cocci: disjdistr: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 19/32] parsing_cocci: unify_ast: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 20/32] parsing_c: ast_c: Add " Jaskaran Singh
2020-05-03 19:31   ` Julia Lawall
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 21/32] parsing_c: parser: Parse " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 22/32] parsing_c: pretty_print_c: Reflect " Jaskaran Singh
2020-05-03 19:32   ` Julia Lawall
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 23/32] parsing_c: type_annoter_c: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 24/32] parsing_c: unparse_cocci: " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 25/32] parsing_c: visitor_c: Visit " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 26/32] engine: check_exhaustive_pattern: Reflect " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 27/32] engine: cocci_vs_c: Match " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 28/32] ocaml: coccilib: Reflect " Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 29/32] tools: spgen: Reflect Cast attrs Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 30/32] tests: Add test case to check cast attribute allminus Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 31/32] tests: Add test case to remove cast attributes Jaskaran Singh
2020-04-28 17:02 ` [Linux-kernel-mentees] [PATCH 32/32] tests: Add test case to detect " Jaskaran Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).