From 8744a9d5891c9272edb7a35d5c2081c3e54fb983 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 31 Jan 2024 20:22:13 +0800 Subject: [PATCH] feat(c): add support for macro alias declaration #24 This commit adds support for macro alias declaration in the chapi-ast-c file. The macroFunctionExpression rule has been modified to allow for parameterTypeList and expressionStatement. --- chapi-ast-c/src/main/antlr/C.g4 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chapi-ast-c/src/main/antlr/C.g4 b/chapi-ast-c/src/main/antlr/C.g4 index 4c5ba91b..e31a041e 100644 --- a/chapi-ast-c/src/main/antlr/C.g4 +++ b/chapi-ast-c/src/main/antlr/C.g4 @@ -480,18 +480,19 @@ macroStatement singleLineMacroDeclaration : include (StringLiteral | Identifier | ('<' includeIdentifier '>' )) #includeDeclaration | macroKeywords Identifier structOrUnionSpecifier #macroStructureDeclaration + | 'define' expressionStatement macroFunctionExpression #macroAliasDeclaration | macroKeywords (expressionStatement)* ('#' macroKeywords)? identifierList? #macroDefineDeclaration - | 'define' macroFunctionExpression macroFunctionExpression #macroAliasDeclaration | '#'? Identifier #macroCastDeclaration ; macroFunctionExpression - : Identifier '(' (macroFunctionExpression | macroType | expression | macroKeywords)* ')' + : Identifier '(' ( parameterTypeList| (macroType (',' macroType)*) ) ')' ; macroType : typeQualifier? (typeKeywords | Identifier | '==' | '!=' | comparator) (Identifier | typeKeywords)* pointer? + | expressionStatement ;