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

Implement static class access #24

Open
Brofian opened this issue Jan 23, 2025 · 0 comments
Open

Implement static class access #24

Brofian opened this issue Jan 23, 2025 · 0 comments

Comments

@Brofian
Copy link
Owner

Brofian commented Jan 23, 2025

In the case of static properties, the class identifier is wrongly detected as a VarRef. For example:

String numAsString = String.valueOf(34);

is currently evaluating the expression on the right as

MethodCall(VarRef(String),valueOf,List(Literal(34))

In this case, String is used as a reference to the static context of the java.lang.String class. The parser has no way of knowing that, the typeCheck can test this against all known variables and all known imports, but this should not be necessary to do in the bytecode generation.

My solution would be:

  1. Create new AST Node StaticClassRef(className) that is not used by the AstBuilder
  2. Once the TypeCheck encounters a VarRef towards an unknown variable that starts with an uppercase letter, it can convert it into a StaticClassRef
  3. The Bytecode generation can then include a special case for accessing static class members via their static context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant