cl: loadMacro - #725
Merged
Merged
cl: loadMacro#725
Conversation
Contributor
There was a problem hiding this comment.
Review: macro constant-expression evaluation
Nice, compact operator-precedence evaluator, and the presumedFiles set + Config.PresumedFiles removal cleanly internalizes file filtering. The Tokenize/dispose lifecycle is correct and presumedFiles is properly nil-guarded in loadFiles. I did find one definite correctness bug (unary -/~ are no-ops) plus a cluster of panic-on-malformed-input risks worth addressing before merge — macro bodies come from arbitrary headers and none of the compiles closures run under recover(), so a panic aborts the whole generation.
Also worth considering (no reliable inline anchor):
- Unknown binary operators silently truncate.
parseExpr(const_expr.go:71-78) exits the loop on any operator not inopPrecs(==,&&,||,?:, etc.) and, unlessneedRParen, returnsok=truewith only the left-hand value. So#define X (1 && 0)would emit1. Encountering an unknown operator mid-expression should forceok=falserather than returning the truncated prefix.evalConstExpralso discardsleft; assertinglen(left)==0at the top level would catch trailing garbage. - Scientific-notation float misclassified.
parseOperanddistinguishes int vs float by scanning for.(const_expr.go:186), so1e10takes theParseIntpath, fails, and the constant is silently dropped. Consider also checking fore/E/p/P. - Performance:
PresumedFilenow returns a Gostring(clang.go:238), allocating + copying a C string for every visited cursor inloadFiles/cppdumppurely to do a map/==test on a path where most cursors are filtered out. Consider comparing without materializing a Go string, or caching byclang.File.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.