From 0eb39a6becfc7d4b717f86e93c3575071fd44e97 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 31 Jan 2024 17:13:24 +0800 Subject: [PATCH] fix(c): modify singleLineMacroDeclaration and macroKeywords #24 - Modify singleLineMacroDeclaration to include Identifier as an option for include - Modify macroKeywords to include 'ifndef' as an option These changes ensure that singleLineMacroDeclaration and macroKeywords are more flexible and can handle different scenarios. --- chapi-ast-c/src/main/antlr/C.g4 | 6 +++--- .../test/kotlin/chapi/ast/cast/CFullIdentListenerTest.kt | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/chapi-ast-c/src/main/antlr/C.g4 b/chapi-ast-c/src/main/antlr/C.g4 index c3a0fc9d..733f301a 100644 --- a/chapi-ast-c/src/main/antlr/C.g4 +++ b/chapi-ast-c/src/main/antlr/C.g4 @@ -470,16 +470,16 @@ macroStatement ; singleLineMacroDeclaration - : '#' include (StringLiteral | ('<' includeIdentifier '>' )) #includeDeclaration + : '#' include (StringLiteral | Identifier | ('<' includeIdentifier '>' )) #includeDeclaration | '#' 'define' expression* '#' 'undef' identifierList? #macroExpansionDeclaration - | '#' ('ifdef' | 'endif') Identifier expression* '#' 'endif' Identifier? #ifdefDeclaration + | '#' ('ifdef' | 'ifndef' |'if') Identifier expression* '#' 'endif' Identifier? #ifdefDeclaration | '#' macroKeywords #defineDeclaration | '#' '#'? Identifier #macroCastDeclaration | '#' macroKeywords expression* '#' macroKeywords identifierList? #macroExpansionDeclaration2 ; macroKeywords - : 'if' | 'undef' | 'else' | 'pragma' | 'endif' | 'ifdef' | 'ifndef' | 'elif' | 'define' + : 'if' | 'undef' | 'else' | 'pragma' | 'endif' | 'ifdef' | 'ifndef' | 'elif' | 'define' | 'ifndef' ; labeledStatement diff --git a/chapi-ast-c/src/test/kotlin/chapi/ast/cast/CFullIdentListenerTest.kt b/chapi-ast-c/src/test/kotlin/chapi/ast/cast/CFullIdentListenerTest.kt index 3e6690de..5b4b86b5 100644 --- a/chapi-ast-c/src/test/kotlin/chapi/ast/cast/CFullIdentListenerTest.kt +++ b/chapi-ast-c/src/test/kotlin/chapi/ast/cast/CFullIdentListenerTest.kt @@ -258,10 +258,11 @@ typedef struct { #include "redismodule.h" #include #include + #include LUA_USER_H """.trimIndent() val codeFile = CAnalyser().analysis(code, "helloworld.c") - assertEquals(codeFile.Imports.size, 6) + assertEquals(codeFile.Imports.size, 7) } @Test