Mentions légales du service

Skip to content

parsing_cocci: ast0: Add support for __attribute__ with one argument

LAWALL Julia requested to merge attr2 into master

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

Merge request reports