Skip to content

Commit

Permalink
feat: add builtin_va_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Aug 9, 2023
1 parent b3a29bf commit b9f85ed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ module.exports = grammar({
$.sizeof_expression,
$.alignof_expression,
$.offsetof_expression,
$.builtin_va_arg,
$.generic_expression,
$.subscript_expression,
$.call_expression,
Expand Down Expand Up @@ -953,6 +954,15 @@ module.exports = grammar({
seq('(', field('type', $.type_descriptor), ',', field('member', $._field_identifier), ')'),
)),

builtin_va_arg: $ => prec(PREC.CALL, seq(
'__builtin_va_arg',
'(',
field('argument', $._expression),
',',
field('type', $.type_descriptor),
')',
)),

generic_expression: $ => prec(PREC.CALL, seq(
'_Generic',
'(',
Expand Down
29 changes: 29 additions & 0 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1250,3 +1250,32 @@ void fn (int *__restrict__ rptr) {
(pointer_expression
(identifier))
(number_literal))))))

================================================================================
Builtin va_arg Function
================================================================================

int main() {
const char*s=__builtin_va_arg(argp, char*);
}

--------------------------------------------------------------------------------

(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(declaration
(type_qualifier)
(primitive_type)
(init_declarator
(pointer_declarator
(identifier))
(builtin_va_arg
(identifier)
(type_descriptor
(primitive_type)
(abstract_pointer_declarator))))))))

0 comments on commit b9f85ed

Please sign in to comment.