~npalix/coccinelle/upstream

« back to all changes in this revision

Viewing changes to parsing_c/pretty_print_c.ml

  • Committer: Julia Lawall
  • Author(s): Keisuke Nishimura
  • Date: 2021-04-03 14:00:06 UTC
  • Revision ID: git-v1:17111cabe41de50075481c4511757701dec5db10
parsing_cocci: ast0: Add support for __attribute__ with one argument

This series adds support for __attribute__ with one argument.

Current Coccinelle is having a problem with attrs and endattrs in C
parser.
Here is an example of AST for C.
 #1
struct { int i;} __attr;

attrs = []
endattrs = [ __attr]

 #2
struct { int i;} __attribute__((pack));

attrs = [__attribute__((pack))]
endattrs = []

__attribute__((pack)) in #2 should be interpreted as attrs.

This problem results from the implementation of parsing_c/parser_c.mly
and parsing_c/parsing_hacks.ml.

The current implementation in parsing_hacks.ml only checks the next
couple of tokens and whether it can match some regular expressions to
replace a specific token type for another token type. (e.g. regarding
endattrs, Coccinelle will check "^__.*$" and whether the next token is
";" or "=" etc..., and replace TIdent for TMacroEndAttr).
And parser_c.mly attempt to create AST based on the token processed
by parsing_hacks.ml.

To solve this problem, the algorithm used in current parsing_hacks.ml
needs to be revised totally. Maybe we can also solve it by changing
parser_c.mly. But it requires more complex works and a lot of time.

Signed-off-by: Keisuke Nishimura <mumumu0722@gmail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
1151
1151
    match (e,ii) with
1152
1152
      Attribute(a), ii  ->
1153
1153
        pp_attr_arg a
 
1154
    | GccAttribute(a), ii ->
 
1155
        let (i1,i2,i3,i4,i5) = Common.tuple_of_list5 ii in
 
1156
        pr_elem i1; pr_elem i2; pr_elem i3;
 
1157
        pp_attr_arg a; pr_elem i4; pr_elem i5;
1154
1158
 
1155
1159
  and pp_attr_arg (e,ii) =
1156
1160
    match (e,ii) with