Skip to content

cl: loadMacro - #725

Merged
xushiwei merged 3 commits into
goplus:devfrom
xushiwei:q
Sep 16, 2026
Merged

xushiwei merged 3 commits into
goplus:devfrom
xushiwei:q

Conversation

@xushiwei

Copy link
Copy Markdown
Member

No description provided.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in opPrecs (==, &&, ||, ?:, etc.) and, unless needRParen, returns ok=true with only the left-hand value. So #define X (1 && 0) would emit 1. Encountering an unknown operator mid-expression should force ok=false rather than returning the truncated prefix. evalConstExpr also discards left; asserting len(left)==0 at the top level would catch trailing garbage.
  • Scientific-notation float misclassified. parseOperand distinguishes int vs float by scanning for . (const_expr.go:186), so 1e10 takes the ParseInt path, fails, and the constant is silently dropped. Consider also checking for e/E/p/P.
  • Performance: PresumedFile now returns a Go string (clang.go:238), allocating + copying a C string for every visited cursor in loadFiles/cppdump purely to do a map/== test on a path where most cursors are filtered out. Consider comparing without materializing a Go string, or caching by clang.File.

Comment thread cl/const_expr.go
Comment thread cl/const_expr.go
Comment thread cl/compile.go Outdated
Comment thread cl/const_expr.go
@xushiwei
xushiwei merged commit 282bf1f into goplus:dev Sep 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant