Skip to content

Commit

Permalink
chore(c): optimize macro processing for better performance #24
Browse files Browse the repository at this point in the history
- Modify `chapi-ast-c/src/main/antlr/C.g4` to remove unnecessary code in `singleLineMacroDeclaration`.
- Modify `chapi-ast-c/src/test/kotlin/chapi/ast/cast/CFullIdentListenerTest.kt` to remove printing of seconds in `println` statement.
- Add `recording.jsonl` to `.gitignore`.
- Update `README.md` to include information about the performance impact of using macros extensively.
- Update Kotlin implementation to include `warpTargetFullType` for accessing classes in the same package.
  • Loading branch information
phodal committed Jan 31, 2024
1 parent ff26513 commit 3d33371
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ api.json
nodes.json
nohup.out
*.tokens
recording.jsonl

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Algol Family [https://wiki.c2.com/?AlgolFamily](https://wiki.c2.com/?AlgolFamily
- import analysis support
- in C#, import `namespace` can use call in namespace

### C issue

Since Macro can be everywhere, If your code includes lots of Macro, it will be slow.

### Kotlin

- need to implementation `warpTargetFullType` to got Class in same package.
Expand Down
2 changes: 1 addition & 1 deletion chapi-ast-c/src/main/antlr/C.g4
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ macroStatement

singleLineMacroDeclaration
: '#' include (StringLiteral | ('<' includeIdentifier '>' )) #includeDeclaration
| '#' macroKeywords expression* (',' (expression | singleLineMacroDeclaration))* #defineDeclaration
| '#' macroKeywords expression* #defineDeclaration
| '#' '#'? Identifier #macroCastDeclaration
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class CFullIdentListenerTest {
CAnalyser().analysis(it.readText(), it.name)
val end = System.currentTimeMillis()
val seconds = (end - start) / 1000
println("cost ${end - start}ms ~ ${seconds}s")
println("cost ${end - start}ms")
}
}
}
Expand Down

0 comments on commit 3d33371

Please sign in to comment.