Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track symbol references #42

Open
3 of 5 tasks
DonIsaac opened this issue Nov 8, 2024 · 1 comment · Fixed by #86
Open
3 of 5 tasks

Track symbol references #42

DonIsaac opened this issue Nov 8, 2024 · 1 comment · Fixed by #86
Labels
A-semantic Area - semantic analysis C-enhancement Category - New feature or request

Comments

@DonIsaac
Copy link
Owner

DonIsaac commented Nov 8, 2024

Record where symbols are referenced and how they are used.

Create a Reference struct and store it in the SymbolTable. It should include the following fields

  • node_id: the Ast.Node.Index of the AST node making the reference. Note that .identifier does not have its own AST node.
  • token_id: the TokenIndex of the .identifier token.
  • symbol_id: The symbol being referenced. null if it could not be resolved.
  • flags: ReferenceFlags describing how it's being used. This is a packed struct (i.e. a struct only containing bitflags) with these fields:
    • read: symbol's value is being read. Also set for LHS of field_access nodes.
    • write: symbol's value is being modified.
    • call: symbol is being called.
    • type: symbol is used in a type alias (const Foo = std.ArrayList(Bar)), function signature, or type annotation.

Acceptance Criteria

  • References are stored as an SoA within SymbolTable
  • yet-unresolved references are recorded by SemanticBuilder. Each time it exits a scope, it should attempt to resolve references.

Reference flags edge cases:

  • given var x = 1; x += 1, x is both .read and .write
  • given foo.bar(), foo is only .read, while bar is .call

TODO

  • add .type flag to type references
  • visit variable type annotations
  • handle .alias reference flags
  • add builtin flag? add it to null, undefined, builtin types, and builtin functions?
  • handle .member reference flags. I don't think field accesses are bound correctly yet.
@DonIsaac DonIsaac added C-enhancement Category - New feature or request A-semantic Area - semantic analysis labels Nov 8, 2024
@DonIsaac DonIsaac linked a pull request Nov 20, 2024 that will close this issue
@DonIsaac
Copy link
Owner Author

#90
#94

DonIsaac added a commit that referenced this issue Nov 23, 2024
Part of #42 

- fix: visit return types in function declarations
- fix: add `type` reference flags to returned identifiers
- fix: return types are in same scope as the rest of the function's
prototype
- fix: simple function prototype nodes not being visited
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-semantic Area - semantic analysis C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant