Skip to content

Commit

Permalink
fix(c): modify singleLineMacroDeclaration and macroKeywords #24
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
phodal committed Jan 31, 2024
1 parent 2d2eecf commit 0eb39a6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions chapi-ast-c/src/main/antlr/C.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ typedef struct {
#include "redismodule.h"
#include <sys/mman.h>
#include <float.h>
#include LUA_USER_H
""".trimIndent()

val codeFile = CAnalyser().analysis(code, "helloworld.c")
assertEquals(codeFile.Imports.size, 6)
assertEquals(codeFile.Imports.size, 7)
}

@Test
Expand Down

0 comments on commit 0eb39a6

Please sign in to comment.