tree-sitter-c
tree-sitter-c copied to clipboard
Support for __attribute__ With structs
Currently, __attribute__
is not parsed correctly when following or preceding a struct definition:
typedef struct {
int x;
} __attribute__((__packed__)) foo_t;
translation_unit [0, 0] - [3, 0]
type_definition [0, 0] - [2, 36]
type: struct_specifier [0, 8] - [2, 1]
body: field_declaration_list [0, 15] - [2, 1]
field_declaration [1, 2] - [1, 8]
type: primitive_type [1, 2] - [1, 5]
declarator: field_identifier [1, 6] - [1, 7]
declarator: function_declarator [2, 2] - [2, 29]
declarator: type_identifier [2, 2] - [2, 15]
parameters: parameter_list [2, 15] - [2, 29]
parameter_declaration [2, 16] - [2, 28]
type: MISSING type_identifier [2, 16] - [2, 16]
declarator: abstract_function_declarator [2, 16] - [2, 28]
parameters: parameter_list [2, 16] - [2, 28]
parameter_declaration [2, 17] - [2, 27]
type: type_identifier [2, 17] - [2, 27]
ERROR [2, 30] - [2, 35]
identifier [2, 30] - [2, 35]
struct __attribute__((__packed__)) foo_t {
int x;
};
translation_unit [0, 0] - [3, 0]
function_definition [0, 0] - [2, 1]
type: struct_specifier [0, 0] - [0, 20]
name: type_identifier [0, 7] - [0, 20]
declarator: parenthesized_declarator [0, 20] - [0, 34]
parenthesized_declarator [0, 21] - [0, 33]
identifier [0, 22] - [0, 32]
ERROR [0, 35] - [0, 40]
identifier [0, 35] - [0, 40]
body: compound_statement [0, 41] - [2, 1]
declaration [1, 2] - [1, 8]
type: primitive_type [1, 2] - [1, 5]
declarator: identifier [1, 6] - [1, 7]
expression_statement [2, 1] - [2, 2]
This could possibly be addressed by adding _declaration_specifiers
in the relevant positions of struct_specifier
.
Same with
struct foo {
char gap;
int bar __attribute__((__aligned__(4)));
};
it produces:
translation_unit [0, 0] - [1, 0]
struct_specifier [0, 0] - [0, 63]
name: type_identifier [0, 7] - [0, 10]
body: field_declaration_list [0, 11] - [0, 63]
field_declaration [0, 12] - [0, 21]
type: primitive_type [0, 12] - [0, 16]
declarator: field_identifier [0, 17] - [0, 20]
field_declaration [0, 22] - [0, 29]
type: primitive_type [0, 22] - [0, 25]
declarator: field_identifier [0, 26] - [0, 29]
MISSING ; [0, 29] - [0, 29]
field_declaration [0, 30] - [0, 62]
attribute_specifier [0, 30] - [0, 61]
argument_list [0, 44] - [0, 60]
call_expression [0, 45] - [0, 59]
function: identifier [0, 45] - [0, 56]
arguments: argument_list [0, 56] - [0, 59]
number_literal [0, 57] - [0, 58]
type: MISSING type_identifier [0, 61] - [0, 61]