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 AST validation #29

Open
DaniPopes opened this issue Jul 6, 2024 · 1 comment
Open

Implement AST validation #29

DaniPopes opened this issue Jul 6, 2024 · 1 comment
Labels
A-parser Area: parsing source code to an AST C-enhancement Category: an issue proposing an enhancement or a PR with one E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. P-medium Medium priority

Comments

@DaniPopes
Copy link
Member

DaniPopes commented Jul 6, 2024

We must verify correctness of the parsed AST.

A few examples:

  • enums must have at least 1 variant and no more than 256
  • continue and break are only allowed inside of a loop
  • unchecked {} blocks can only be used inside of regular blocks
  • placeholder statements (_;) are only allowed in modifiers
  • variable declaration statements are not allowed as the body of a loop (for, while, do while), meaning they must be inside of a block

Solc is more strict in the parser, so some of these checks can be found in the parser, while others are found in visitors, like SyntaxChecker and ContractLevelChecker.

@DaniPopes DaniPopes added C-enhancement Category: an issue proposing an enhancement or a PR with one P-high High priority A-parser Area: parsing source code to an AST E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Jul 6, 2024
@DaniPopes DaniPopes mentioned this issue Jul 6, 2024
68 tasks
@DaniPopes DaniPopes added P-medium Medium priority and removed P-high High priority labels Oct 25, 2024
@0xalpharush
Copy link
Contributor

0xalpharush commented Nov 14, 2024

To implement "placeholder statements (_;) are only allowed in modifiers" and maybe also #116, it'd be nice to have something like Rowan's red-green trees to get the nearest enclosing lexical scope. For example, one can see whether a given AST node is in an assembly block, block scope {}, function, contract, or file by recursively looking up its parent.

However, it's probably simplest to create a scope tree like rustc https://github.com/rust-lang/rust/blob/8adb4b30f40e6fbd21dc1ba26c3301c7eeb6de3c/compiler/rustc_hir_analysis/src/check/region.rs#L779-L782

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: parsing source code to an AST C-enhancement Category: an issue proposing an enhancement or a PR with one E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

2 participants