Skip to content

AST: use simpler MemberExpr nodes#435

Merged
bvdberg merged 1 commit intoc2lang:masterfrom
chqrlie:simple-member
Feb 10, 2026
Merged

AST: use simpler MemberExpr nodes#435
bvdberg merged 1 commit intoc2lang:masterfrom
chqrlie:simple-member

Conversation

@chqrlie
Copy link
Contributor

@chqrlie chqrlie commented Feb 9, 2026

  • restrict MemberExpr nodes to <expr>.b and a.b forms
  • store a single SrcLoc for the member name (size is always 32 bytes)
  • use bitfield to avoid using strlen for SrcLoc computations
  • simplify Parser.parseCastExpr, p.parsePureMemberExpr and Parser.parseImpureMemberExpr: no longer use peekToken on identifiers.
  • store name length in IdentifierExpr nodes to simplify end location computation
  • rename MemberExpr.getExprBase as MemberExpr.getBaseExpr for consistency
  • merge Generator.emitMemberExprBase into Generator.emitMemberExpr
  • disable bogus const check in conversion_checker.Checker.check
  • improve Analyser.analyseToContainer for const/volatile correctness
  • fix Analyser.findMemberOffset for member expression chains should support ̀to_container(s, array[n].ptr, ptr)`?
  • this simplifies the code and reduces memory usage by 100KB

@chqrlie chqrlie force-pushed the simple-member branch 2 times, most recently from ba9d1d1 to afde52a Compare February 9, 2026 12:09
need_dot = true;
fn bool Generator.needBaseDecl(Generator* gen, Expr* base) {
Decl* d;
if (base.isIdentifier()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can this happen? If i put an assert here, it does not seem to trigger

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it is no longer used anywhere. This function is a recursive type function, the compiler does not detect that it is unused: the test for self reference should be improved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have rebased the branch and removed this function

Copy link
Member

Choose a reason for hiding this comment

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

Weird, the comment i have was actually about part of an If-statement.. lol. This comment also applies. I made my changes in another commit on top, after i merged you pull request. It indeed appears to be a bit faster. Nice!

* restrict `MemberExpr` nodes to `<expr>.b` and `a.b` forms
* store a single `SrcLoc` for the member name (size is always 32 bytes)
* use bitfield to avoid using `strlen` for SrcLoc computations
* simplify `Parser.parseCastExpr`, `p.parsePureMemberExpr` and `Parser.parseImpureMemberExpr`:
  no longer use `peekToken` on identifiers, remove `Parser.parseIdentifier`
* store name length in `IdentifierExpr` nodes to simplify end location computation
* rename `MemberExpr.getExprBase` as `MemberExpr.getBaseExpr` for consistency
* merge `Generator.emitMemberExprBase` into `Generator.emitMemberExpr`
* disable bogus const check in `conversion_checker.Checker.check`
* improve `Analyser.analyseToContainer` for const/volatile correctness
* fix `Analyser.findMemberOffset` for member expression chains
  should support  ̀to_container(s, array[n].ptr, ptr)`?
* this simplifies the code and reduces memory usage by 100KB
@bvdberg bvdberg merged commit ab1f939 into c2lang:master Feb 10, 2026
2 checks passed
@chqrlie chqrlie deleted the simple-member branch February 10, 2026 22:28
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.

2 participants