[cfe][Contexts] Split VariableDeclaration and VariableStatement

This separates VariableDeclaration from Statement. VariableDeclaration no longer implements Statement and variable declared in a block or in a for-statement are now wrapped by a VariableStatement.

Currently there are two VariableStatement implementations; LegacyVariableStatement for variables in the current model, called LegacyVariable, and VariableInitialization for variables used in the new, still experimental, encoding that supports scope computation.

This CL is a step towards realigning the AST nodes to the new model in which each kind of variable has its own distinct subclass. (LocalVariable, PositionalParameter, NamedParameter, SyntheticVariable, etc.)

Note that it is not the intent to use VariableStatement in ForStatement going forward but that will be handled in a follow-up.

TEST=existing.

Change-Id: I5b309cd62c9b138f95b74fb054686edffa49a393
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502681
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther
2026-05-18 05:49:28 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 046d473d5e
commit e30cd0322c
78 changed files with 1341 additions and 1132 deletions
@@ -4832,13 +4832,18 @@ class BytecodeGenerator extends RecursiveVisitor {
}
@override
void visitVariableDeclaration(VariableDeclaration node) {
void defaultVariableDeclaration(VariableDeclaration node) {
_handleVariableInitialization(node);
}
@override
void visitLegacyVariableStatement(LegacyVariableStatement node) {
_handleVariableInitialization(node.variable);
}
@override
void visitVariableInitialization(VariableInitialization node) {
_handleVariableInitialization(node);
_handleVariableInitialization(node.variable);
}
void _handleVariableInitialization(VariableDeclaration node) {
+2 -41
View File
@@ -527,41 +527,11 @@ class _ScopeBuilder extends RecursiveVisitor {
}
@override
void visitVariableDeclaration(VariableDeclaration node) {
_handleVariableInitialization(node);
}
@override
void visitVariableInitialization(VariableInitialization node) {
_handleVariableInitialization(node);
}
void _handleVariableInitialization(VariableDeclaration node) {
void defaultVariableDeclaration(VariableDeclaration node) {
_declareVariable(node.variable);
node.visitChildren(this);
}
@override
void visitPositionalParameter(PositionalParameter node) {
_handleFunctionParameter(node);
}
@override
void visitNamedParameter(NamedParameter node) {
_handleFunctionParameter(node);
}
void _handleFunctionParameter(FunctionParameter node) {
_declareVariable(node);
node.visitChildren(this);
}
@override
void visitCatchVariable(CatchVariable node) {
_declareVariable(node);
node.visitChildren(this);
}
@override
void visitVariableGet(VariableGet node) {
_useVariable(node.variable);
@@ -1063,16 +1033,7 @@ class _Allocator extends RecursiveVisitor {
}
@override
void visitVariableDeclaration(VariableDeclaration node) {
_handleVariableInitialization(node);
}
@override
void visitVariableInitialization(VariableInitialization node) {
_handleVariableInitialization(node);
}
void _handleVariableInitialization(VariableDeclaration node) {
void defaultVariableDeclaration(VariableDeclaration node) {
_allocateVariable(node.variable);
node.visitChildren(this);
}