Open edogrigqv2 opened 7 months ago
This is another example from preprocessed sqlite3:
extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
__gnuc_va_list);
if we add a declarator to __gnuc_va_list
then it parses fine:
extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
__gnuc_va_list va);
And here another related error:
*__builtin_va_arg(ap, int*) = val;
It seems that va_list
and va_arg
need a special treatment by the parser/grammar.
There are several others like the above:
pArgList = __builtin_va_arg(ap, PrintfArguments*);
v = __builtin_va_arg(ap, long int);
longvalue = __builtin_va_arg(ap, unsigned long int);
*(__builtin_va_arg(ap, int*)) = pAccum->nChar;
...
With this changes I can get this project to parse va_arg
expressions:
---------------------------------- grammar.js ----------------------------------
index 2a9fe20..2ff12e2 100644
@@ -904,6 +904,7 @@ module.exports = grammar({
$.sizeof_expression,
$.alignof_expression,
$.offsetof_expression,
+ $.va_arg_expression,
$.generic_expression,
$.subscript_expression,
$.call_expression,
@@ -1045,6 +1046,11 @@ module.exports = grammar({
seq('(', field('type', $.type_descriptor), ',', field('member', $._field_identifier), ')'),
)),
+ va_arg_expression: $ => prec(PREC.CALL, seq(
+ choice('va_arg', '__builtin_va_arg'),
+ seq('(', field('member', $._field_identifier), ',', field('type', $.type_descriptor), ')'),
+ )),
+
generic_expression: $ => prec(PREC.CALL, seq(
'_Generic',
'(',
sqlite3Config.mutex = *__builtin_va_arg(ap, sqlite3_mutex_methods*);
tree-sitter parse cparser-nb/test-va.c
(translation_unit [0, 0] - [1, 0]
(expression_statement [0, 0] - [0, 68]
(assignment_expression [0, 0] - [0, 67]
left: (field_expression [0, 0] - [0, 19]
argument: (identifier [0, 0] - [0, 13])
field: (field_identifier [0, 14] - [0, 19]))
right: (pointer_expression [0, 22] - [0, 67]
argument: (va_arg_expression [0, 23] - [0, 67]
member: (field_identifier [0, 40] - [0, 42])
type: (type_descriptor [0, 44] - [0, 66]
type: (type_identifier [0, 44] - [0, 65])
declarator: (abstract_pointer_declarator [0, 65] - [0, 66])))))))
Did you check existing issues?
Tree-Sitter CLI Version, if relevant (output of
tree-sitter --version
)9f398ca955d3329110d31ed523dac5275074948f
Describe the bug
Parser do not recognize macro attribute in function declaration
Steps To Reproduce/Bad Parse Tree
This outputs
Expected Behavior/Parse Tree
I believe it is possible for parser to recognize macro calls here and recognize that there are part of function declaration without ERRORs
Repro
No response