Skip to contentSkip to conversation

cocci: Add cast attributes to C and SmPL ASTs

PATCH Superseded Jaskaran Singh 2 participants 43 messages Apr 28, 2020 – May 4, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover cocci: Add cast attributes to C and SmPL ASTs

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/[email protected]/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
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#1 lore raw

PATCH 1/32 parsing_c: parser: Pass attribute list from type_name

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

---
 ocaml/coccilib.mli     |  3 ++-
 parsing_c/parse_c.ml   |  4 +++-
 parsing_c/parser_c.mly | 16 ++++++++--------
 3 files changed, 13 insertions(+), 10 deletions(-)
ocaml/coccilib.mli +2 -1
index 0e807c9a..a305d616 100644
@@ -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
parsing_c/parse_c.ml +3 -1
index 0d3a189a..5f8d5e2d 100644
@@ -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
parsing_c/parser_c.mly +8 -8
index aedde179..0abcc9b0 100644
@@ -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) }
 
 
 
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#2 lore raw

Re: [Cocci] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name

Quoted 2 lines · Jaskaran Singh

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.

Quoted 60 lines
---
 ocaml/coccilib.mli     |  3 ++-
 parsing_c/parse_c.ml   |  4 +++-
 parsing_c/parser_c.mly | 16 ++++++++--------
 3 files changed, 13 insertions(+), 10 deletions(-)
ocaml/coccilib.mli +2 -1
index 0e807c9a..a305d616 100644
@@ -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
parsing_c/parse_c.ml +3 -1
index 0d3a189a..5f8d5e2d 100644
@@ -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
parsing_c/parser_c.mly +2 -2
index aedde179..0abcc9b0 100644
@@ -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.

parsing_c/parser_c.mly unary_expr: · line 834

Quoted 5 lines
parsing_c/parser_c.mly +1 -1
@@ -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

Quoted 40 lines
parsing_c/parser_c.mly +5 -6
  | 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) }
 
 
 
--
Quoted 3 lines

2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#3 lore raw

Re: [Cocci] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name

Quoted 11 lines · Julia Lawall
Quoted 3 lines · Jaskaran Singh

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.

Quoted 135 lines
Quoted 77 lines
---
 ocaml/coccilib.mli     |  3 ++-
 parsing_c/parse_c.ml   |  4 +++-
 parsing_c/parser_c.mly | 16 ++++++++--------
 3 files changed, 13 insertions(+), 10 deletions(-)
ocaml/coccilib.mli +0 -0
index 0e807c9a..a305d616 100644
@@ -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 :

ocaml/coccilib.mli +2 -1
-      (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
parsing_c/parse_c.ml +0 -1
index 0d3a189a..5f8d5e2d 100644
@@ -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

parsing_c/parse_c.ml +2 -0
+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

parsing_c/parser_c.mly +1 -1
index aedde179..0abcc9b0 100644
@@ -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
 
 %%
 /*(***************************************************************

**********)*/

parsing_c/parser_c.mly +1 -1
@@ -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.

parsing_c/parser_c.mly +0 -1
@@ -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
Quoted 3 lines

($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

Quoted 50 lines

| 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]
}

parsing_c/parser_c.mly +1 -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:

parsing_c/parser_c.mly +1 -1
@@ -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 *)*/

parsing_c/parser_c.mly +2 -2
@@ -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) }
 
 
Quoted 4 lines
Quoted 4 lines

--
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#4 lore raw

Re: [Cocci] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name

Quoted 13 lines · Jaskaran Singh
Quoted 11 lines · Julia Lawall
Quoted 3 lines · Jaskaran Singh

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.

Quoted 5 lines

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

Quoted 141 lines

(or if there is a specific term for it in
parser-terminology, then that).

Cheers,
Jaskaran.

Quoted 135 lines
Quoted 77 lines
---
 ocaml/coccilib.mli     |  3 ++-
 parsing_c/parse_c.ml   |  4 +++-
 parsing_c/parser_c.mly | 16 ++++++++--------
 3 files changed, 13 insertions(+), 10 deletions(-)
ocaml/coccilib.mli +0 -0
index 0e807c9a..a305d616 100644
@@ -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 :

ocaml/coccilib.mli +2 -1
-      (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
parsing_c/parse_c.ml +0 -1
index 0d3a189a..5f8d5e2d 100644
@@ -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

parsing_c/parse_c.ml +2 -0
+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

parsing_c/parser_c.mly +1 -1
index aedde179..0abcc9b0 100644
@@ -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
 
 %%
 /*(***************************************************************

**********)*/

parsing_c/parser_c.mly +1 -1
@@ -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.

parsing_c/parser_c.mly +0 -1
@@ -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
Quoted 3 lines

($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

Quoted 50 lines

| 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]
}

parsing_c/parser_c.mly +1 -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:

parsing_c/parser_c.mly +1 -1
@@ -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 *)*/

parsing_c/parser_c.mly +2 -2
@@ -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) }
 
 
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

--
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#5 lore raw

Re: [Cocci] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name

Quoted 20 lines · Julia Lawall
Quoted 17 lines · Jaskaran Singh
Quoted 11 lines · Julia Lawall
Quoted 3 lines · Jaskaran Singh

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).

Quoted 9 lines
Quoted 3 lines

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.

Quoted 161 lines

julia

Quoted 159 lines

(or if there is a specific term for it in
parser-terminology, then that).

Cheers,
Jaskaran.

Quoted 153 lines
Quoted 82 lines
---
 ocaml/coccilib.mli     |  3 ++-
 parsing_c/parse_c.ml   |  4 +++-
 parsing_c/parser_c.mly | 16 ++++++++--------
 3 files changed, 13 insertions(+), 10 deletions(-)
ocaml/coccilib.mli +0 -0
index 0e807c9a..a305d616 100644
@@ -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

ocaml/coccilib.mli +2 -0
+      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
+      Ast_c.attribute list * Ast_c.fullType
   end
 module Lexer_c :
   sig
parsing_c/parse_c.ml +0 -0
index 0d3a189a..5f8d5e2d 100644
@@ -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

parsing_c/parse_c.ml +2 -0
+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

parsing_c/parser_c.mly +1 -1
index aedde179..0abcc9b0 100644
@@ -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
 
 %%
 /*(***********************************************************

****
**********)*/

parsing_c/parser_c.mly +0 -1
@@ -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.

parsing_c/parser_c.mly +0 -0
@@ -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

Quoted 8 lines

$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

Quoted 58 lines

| 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]
}

parsing_c/parser_c.mly +1 -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:

parsing_c/parser_c.mly +1 -1
@@ -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 *)*/

parsing_c/parser_c.mly +2 -2
@@ -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) }
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

--
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#6 lore raw

Re: [Cocci] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name

Quoted 25 lines · Jaskaran Singh
Quoted 24 lines · Julia Lawall
Quoted 20 lines · Jaskaran Singh
Quoted 11 lines · Julia Lawall
Quoted 3 lines · Jaskaran Singh

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"

Quoted 8 lines
Quoted 5 lines

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

Quoted 165 lines

Cheers,
Jaskaran.

Quoted 161 lines

julia

Quoted 159 lines

(or if there is a specific term for it in
parser-terminology, then that).

Cheers,
Jaskaran.

Quoted 153 lines
Quoted 82 lines
---
 ocaml/coccilib.mli     |  3 ++-
 parsing_c/parse_c.ml   |  4 +++-
 parsing_c/parser_c.mly | 16 ++++++++--------
 3 files changed, 13 insertions(+), 10 deletions(-)
ocaml/coccilib.mli +0 -0
index 0e807c9a..a305d616 100644
@@ -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

ocaml/coccilib.mli +2 -0
+      (Lexing.lexbuf -> token) -> Lexing.lexbuf ->
+      Ast_c.attribute list * Ast_c.fullType
   end
 module Lexer_c :
   sig
parsing_c/parse_c.ml +0 -0
index 0d3a189a..5f8d5e2d 100644
@@ -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

parsing_c/parse_c.ml +2 -0
+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

parsing_c/parser_c.mly +1 -1
index aedde179..0abcc9b0 100644
@@ -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
 
 %%
 /*(***********************************************************

****
**********)*/

parsing_c/parser_c.mly +0 -1
@@ -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.

parsing_c/parser_c.mly +0 -0
@@ -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

Quoted 8 lines

$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

Quoted 58 lines

| 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]
}

parsing_c/parser_c.mly +1 -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:

parsing_c/parser_c.mly +1 -1
@@ -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 *)*/

parsing_c/parser_c.mly +2 -2
@@ -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) }
 
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

--
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#7 lore raw

PATCH 2/32 parsing_cocci: ast0_cocci: Add cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/ast0_cocci.ml  | 4 ++--
 parsing_cocci/ast0_cocci.mli | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
parsing_cocci/ast0_cocci.ml +2 -2
index a06d99ae..b65400be 100644
@@ -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 (* ) *)
parsing_cocci/ast0_cocci.mli +2 -2
index 5c2520be..08a4b33b 100644
@@ -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 (* ) *)
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#8 lore raw

PATCH 3/32 parsing_cocci: parser: Parse cast attributes

In reply to Jaskaran Singh

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.

---
 parsing_cocci/parser_cocci_menhir.mly | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
parsing_cocci/parser_cocci_menhir.mly +5 -4
index db5661bd..38b0e039 100644
@@ -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):
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#9 lore raw

Re: [Cocci] [PATCH 03/32] parsing_cocci: parser: Parse cast attributes

Quoted 3 lines · Jaskaran Singh

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

Quoted 28 lines
---
 parsing_cocci/parser_cocci_menhir.mly | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
parsing_cocci/parser_cocci_menhir.mly +5 -5
index db5661bd..38b0e039 100644
@@ -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):
--
Quoted 3 lines

2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#10 lore raw

PATCH 4/32 parsing_cocci: visitor_ast0: Visit cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/visitor_ast0.ml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
parsing_cocci/visitor_ast0.ml +4 -2
index d9e340ed..2ccdb0bb 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#11 lore raw

PATCH 5/32 parsing_cocci: unparse_ast0: Reflect cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/unparse_ast0.ml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
parsing_cocci/unparse_ast0.ml +3 -1
index fdaf6cfa..7f554b37 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#12 lore raw

PATCH 6/32 parsing_cocci: index: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/index.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/index.ml +1 -1
index f7ae48b4..a3b92c12 100644
@@ -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 *)
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#13 lore raw

PATCH 7/32 parsing_cocci: iso_pattern: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/iso_pattern.ml | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
parsing_cocci/iso_pattern.ml +9 -3
index 9df21fb9..b57e293e 100644
@@ -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),
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#14 lore raw

PATCH 8/32 parsing_cocci: type_infer: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/type_infer.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/type_infer.ml +1 -1
index e8aad810..2c1cc73b 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#15 lore raw

PATCH 9/32 parsing_cocci: arity: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/arity.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/arity.ml +3 -2
index 8ee6d33f..880cd7a3 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#16 lore raw

Re: [Cocci] [PATCH 09/32] parsing_cocci: arity: Reflect Cast attributes

Quoted 13 lines · Jaskaran Singh

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

---
 parsing_cocci/arity.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/arity.ml +0 -0
index 8ee6d33f..880cd7a3 100644

parsing_cocci/arity.ml let rec top_expression opt_allowed tgt expr = · line 261

Quoted 9 lines
parsing_cocci/arity.ml +2 -1
@@ -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

Quoted 11 lines
parsing_cocci/arity.ml +1 -2
       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
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#17 lore raw

PATCH 10/32 parsing_cocci: check_meta: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/check_meta.ml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
parsing_cocci/check_meta.ml +2 -1
index 5a348ba3..4f7db813 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#18 lore raw

PATCH 11/32 parsing_cocci: compute_lines: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/compute_lines.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/compute_lines.ml +3 -2
index 1361d842..e945914b 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#19 lore raw

PATCH 12/32 parsing_cocci: context_neg: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/context_neg.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/context_neg.ml +1 -1
index dd768a61..b6378512 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#20 lore raw

PATCH 13/32 parsing_cocci: single_statement: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/single_statement.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
parsing_cocci/single_statement.ml +1 -1
index 4ad1c4e4..73554e9c 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#21 lore raw

PATCH 14/32 parsing_cocci: ast_cocci: Add cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/ast_cocci.ml  | 4 ++--
 parsing_cocci/ast_cocci.mli | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
parsing_cocci/ast_cocci.ml +2 -2
index 9b147e5c..b0190fa1 100644
@@ -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 (* ) *)
parsing_cocci/ast_cocci.mli +2 -2
index c56bba88..ff81692c 100644
@@ -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 (* ( *) *
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#22 lore raw

PATCH 15/32 parsing_cocci: visitor_ast: Visit cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/visitor_ast.ml | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
parsing_cocci/visitor_ast.ml +6 -4
index 8e530114..644bcd5d 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#23 lore raw

Re: [Cocci] [PATCH 15/32] parsing_cocci: visitor_ast: Visit cast attributes

Quoted 1 line · Jaskaran Singh

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

AST0 -> AST

julia

Quoted 44 lines

SmPL AST visitor.

---
 parsing_cocci/visitor_ast.ml | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
parsing_cocci/visitor_ast.ml +6 -5
index 8e530114..644bcd5d 100644
@@ -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
--
Quoted 3 lines

2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#24 lore raw

PATCH 16/32 parsing_cocci: pretty_print_cocci: Print cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/pretty_print_cocci.ml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
parsing_cocci/pretty_print_cocci.ml +3 -1
index 7628882b..2ace0b44 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#25 lore raw

PATCH 17/32 parsing_cocci: ast0toast: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/ast0toast.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/ast0toast.ml +3 -2
index 09c28c06..56f684ee 100644
@@ -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) ->
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#26 lore raw

PATCH 18/32 parsing_cocci: disjdistr: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/disjdistr.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
parsing_cocci/disjdistr.ml +3 -2
index 6724bb25..e171e6ea 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#27 lore raw

PATCH 19/32 parsing_cocci: unify_ast: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_cocci/unify_ast.ml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
parsing_cocci/unify_ast.ml +4 -2
index 68cb6613..25287503 100644
@@ -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)) ->
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#28 lore raw

PATCH 20/32 parsing_c: ast_c: Add Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_c/ast_c.ml  | 2 +-
 parsing_c/ast_c.mli | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
parsing_c/ast_c.ml +1 -1
index f25f9b55..6a828943 100644
@@ -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 *)
parsing_c/ast_c.mli +1 -1
index 8923a335..8a9a6f66 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#29 lore raw

Re: [Cocci] [PATCH 20/32] parsing_c: ast_c: Add Cast attributes

Quoted 27 lines · Jaskaran Singh

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

---
 parsing_c/ast_c.ml  | 2 +-
 parsing_c/ast_c.mli | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
parsing_c/ast_c.ml +1 -1
index f25f9b55..6a828943 100644
@@ -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 *)
parsing_c/ast_c.mli +0 -0
index 8923a335..8a9a6f66 100644

parsing_c/ast_c.mli and expressionbis = · line 107

Quoted 5 lines
parsing_c/ast_c.mli +1 -1
@@ -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

Quoted 7 lines
parsing_c/ast_c.mli +0 -1
   | StatementExpr of compound wrap
   | Constructor of fullType * initialiser
   | ParenExpr of expression
--

2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#30 lore raw

PATCH 21/32 parsing_c: parser: Parse Cast attributes

In reply to Jaskaran Singh

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.

---
 parsing_c/parser_c.mly | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
parsing_c/parser_c.mly +2 -1
index 0abcc9b0..9e640ba5 100644
@@ -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.
Signature · 6 lines
2.21.1

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#31 lore raw

PATCH 22/32 parsing_c: pretty_print_c: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_c/pretty_print_c.ml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
parsing_c/pretty_print_c.ml +4 -3
index 99a7e0ed..96a11d72 100644
@@ -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)
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#32 lore raw

Re: [Cocci] [PATCH 22/32] parsing_c: pretty_print_c: Reflect Cast attributes

Quoted 13 lines · Jaskaran Singh

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

---
 parsing_c/pretty_print_c.ml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
parsing_c/pretty_print_c.ml +0 -0
index 99a7e0ed..96a11d72 100644

parsing_c/pretty_print_c.ml let mk_pretty_printers · line 149

Quoted 6 lines
parsing_c/pretty_print_c.ml +1 -2
@@ -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

Quoted 15 lines
parsing_c/pretty_print_c.ml +3 -2
+        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)
--
Quoted 3 lines

2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#33 lore raw

PATCH 23/32 parsing_c: type_annoter_c: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_c/type_annoter_c.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
parsing_c/type_annoter_c.ml +2 -2
index dfd363b2..c42ac5e9 100644
@@ -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)
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#34 lore raw

PATCH 24/32 parsing_c: unparse_cocci: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_c/unparse_cocci.ml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
parsing_c/unparse_cocci.ml +4 -2
index 395b3a3c..081bcdd9 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#35 lore raw

PATCH 25/32 parsing_c: visitor_c: Visit Cast attributes

In reply to Jaskaran Singh

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

---
 parsing_c/visitor_c.ml | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
parsing_c/visitor_c.ml +8 -2
index 57b5f32b..1a522413 100644
@@ -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 (
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#36 lore raw

PATCH 26/32 engine: check_exhaustive_pattern: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 engine/check_exhaustive_pattern.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
engine/check_exhaustive_pattern.ml +1 -1
index 903c32ff..d7785fc7 100644
@@ -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) -> ()
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#37 lore raw

PATCH 27/32 engine: cocci_vs_c: Match Cast attributes

In reply to Jaskaran Singh

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

---
 engine/cocci_vs_c.ml | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
engine/cocci_vs_c.ml +17 -7
index 317fa71e..0001ec2a 100644
@@ -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 (_, _)|
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#38 lore raw

PATCH 28/32 ocaml: coccilib: Reflect Cast attributes

In reply to Jaskaran Singh

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

---
 ocaml/coccilib.mli | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
ocaml/coccilib.mli +3 -3
index a305d616..0c379547 100644
@@ -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
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#39 lore raw

PATCH 29/32 tools: spgen: Reflect Cast attrs

In reply to Jaskaran Singh

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

---
 tools/spgen/source/position_generator.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/spgen/source/position_generator.ml +2 -2
index 757faf5f..9143a474 100644
@@ -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) ->
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#40 lore raw

PATCH 30/32 tests: Add test case to check cast attribute allminus

In reply to Jaskaran Singh

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 *.

---
 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
tests/remove_cast_attr_allminus.c new file +10 -0
new file mode 100644
index 00000000..4f6da3e4
@@ -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;
+}
tests/remove_cast_attr_allminus.cocci new file +9 -0
new file mode 100644
index 00000000..320fee93
@@ -0,0 +1,9 @@
+@r0@
+type T;
+identifier x;
+@@
+
+  (
+-	T
++	int *
+  ) x
tests/remove_cast_attr_allminus.res new file +10 -0
new file mode 100644
index 00000000..befec630
@@ -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;
+}
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#41 lore raw

PATCH 31/32 tests: Add test case to remove cast attributes

In reply to Jaskaran Singh

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 *.

---
 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
tests/remove_cast_attr.c new file +10 -0
new file mode 100644
index 00000000..4f6da3e4
@@ -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;
+}
tests/remove_cast_attr.cocci new file +10 -0
new file mode 100644
index 00000000..f171d44d
@@ -0,0 +1,10 @@
+@r0@
+type T;
+attribute name __cast_attr;
+identifier x;
+@@
+
+  (
+	T
+-	__cast_attr
+  ) x
tests/remove_cast_attr.res new file +10 -0
new file mode 100644
index 00000000..fb5001b9
@@ -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;
+}
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#42 lore raw

PATCH 32/32 tests: Add test case to detect cast attributes

In reply to Jaskaran Singh

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 *.

---
 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
tests/detect_cast_attr.c new file +10 -0
new file mode 100644
index 00000000..2458ef05
@@ -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;
+}
tests/detect_cast_attr.cocci new file +11 -0
new file mode 100644
index 00000000..d626048f
@@ -0,0 +1,11 @@
+@r0@
+type T;
+attribute name __cast_attr;
+identifier x;
+@@
+
+  (
+-	T
++	char *
+ 	__cast_attr
+  ) x
tests/detect_cast_attr.res new file +10 -0
new file mode 100644
index 00000000..2a273316
@@ -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;
+}
Signature · 6 lines
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees