[cfe][InternalNodes] Implement InternalVariable directly

This updates the InternalVariable hierarchy to be based on a sealed base class InternalVariable with no connection to IVariable. IVariable is removed and unused properties of InternalVariable are removed.

TEST=existing

Change-Id: Iacfbe9ab21d1c9aab043712099cd1ee6e4cee174
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510825
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther
2026-06-11 02:43:16 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent c390eb0931
commit 8e2d140fa5
18 changed files with 128 additions and 722 deletions
+11 -154
View File
@@ -21,15 +21,20 @@ sealed class VariableBase extends TreeNode implements Annotatable {
}
}
/// This is a helper class to enable mixing a mixin into concrete
/// implementations of the sealed class [Variable]. It's not supposed
/// to be used as a type annotation, but purely for declaring the class
/// hierarchy.
abstract interface class IVariable implements TreeNode, Annotatable {
/// The root of the sealed hierarchy of non-type variables.
sealed class Variable extends VariableBase implements ContextConsumer {
/// Static type of the variable.
abstract DartType type;
abstract String? cosmeticName;
/// Declaration node for the variable, if available.
abstract VariableDeclaration? variableDeclaration;
/// Derived from [variableDeclaration], if available.
abstract Expression? initializer;
@override
abstract List<Expression> annotations;
abstract bool isFinal;
abstract bool isConst;
abstract bool isLate;
@@ -48,78 +53,9 @@ abstract interface class IVariable implements TreeNode, Annotatable {
// The following is due to [VariableDeclaration] implementing
// [VariableInitialization].
abstract int binaryOffsetNoTag;
abstract List<VariableContext>? capturedContexts;
abstract int fileEqualsOffset;
abstract Variable variable;
void clearAnnotations();
VariableContext? get context;
void set context(VariableContext value);
bool get isAssignable;
bool get hasIsFinal;
bool get hasIsConst;
bool get hasIsLate;
bool get hasIsInitializingFormal;
bool get hasIsSynthesized;
bool get hasIsHoisted;
bool get hasHasDeclaredInitializer;
bool get hasIsCovariantByClass;
bool get hasIsRequired;
bool get hasIsCovariantByDeclaration;
bool get hasIsLowered;
bool get hasIsWildcard;
bool get hasIsSuperInitializingFormal;
bool get hasIsErroneouslyInitialized;
}
/// The root of the sealed hierarchy of non-type variables.
sealed class Variable extends VariableBase
implements IVariable, ContextConsumer {
/// Static type of the variable.
@override
abstract DartType type;
/// Declaration node for the variable, if available.
@override
abstract VariableDeclaration? variableDeclaration;
/// Derived from [variableDeclaration], if available.
@override
abstract Expression? initializer;
@override
abstract List<Expression> annotations;
@override
abstract bool isFinal;
@override
abstract bool isConst;
@override
abstract bool isLate;
@override
abstract bool isInitializingFormal;
@override
abstract bool isSynthesized;
@override
abstract bool isHoisted;
@override
abstract bool hasDeclaredInitializer;
@override
abstract bool isCovariantByClass;
@override
abstract bool isRequired;
@override
abstract bool isCovariantByDeclaration;
@override
abstract bool isLowered;
@override
abstract bool isWildcard;
@override
abstract bool isSuperInitializingFormal;
@override
abstract bool isErroneouslyInitialized;
factory(
String? name, {
Expression? initializer,
@@ -153,36 +89,21 @@ sealed class Variable extends VariableBase
new empty();
@override
bool get hasIsFinal;
@override
bool get hasIsConst;
@override
bool get hasIsLate;
@override
bool get hasIsInitializingFormal;
@override
bool get hasIsSynthesized;
@override
bool get hasIsHoisted;
@override
bool get hasHasDeclaredInitializer;
@override
bool get hasIsCovariantByClass;
@override
bool get hasIsRequired;
@override
bool get hasIsCovariantByDeclaration;
@override
bool get hasIsLowered;
@override
bool get hasIsWildcard;
@override
bool get hasIsSuperInitializingFormal;
@override
bool get hasIsErroneouslyInitialized;
@override
bool get isAssignable;
abstract String? name;
@@ -642,14 +563,6 @@ class LegacyVariable extends TreeNode implements Variable, Annotatable {
throw new UnsupportedError("${this.runtimeType}.context=");
}
@override
Variable get variable => this;
@override
void set variable(Variable value) {
throw new UnsupportedError("${this.runtimeType}.variable=");
}
@override
bool get hasHasDeclaredInitializer => true;
@@ -989,14 +902,6 @@ class LocalVariable extends Variable {
@override
int fileEqualsOffset = TreeNode.noOffset;
@override
Variable get variable => this;
@override
void set variable(Variable variable) {
throw new UnsupportedError("${this.runtimeType}.variable=");
}
@override
void clearAnnotations() {
annotations.clear();
@@ -1302,14 +1207,6 @@ class LateVariable extends Variable {
@override
int fileEqualsOffset = TreeNode.noOffset;
@override
Variable get variable => this;
@override
void set variable(Variable variable) {
throw new UnsupportedError("${this.runtimeType}.variable=");
}
@override
void clearAnnotations() {
annotations.clear();
@@ -1618,14 +1515,6 @@ class CatchVariable extends Variable {
@override
int fileEqualsOffset = TreeNode.noOffset;
@override
Variable get variable => this;
@override
void set variable(Variable variable) {
throw new UnsupportedError("${this.runtimeType}.variable=");
}
@override
void clearAnnotations() {
annotations.clear();
@@ -1976,14 +1865,6 @@ class PositionalParameter extends FunctionParameter {
@override
int fileEqualsOffset = TreeNode.noOffset;
@override
Variable get variable => this;
@override
void set variable(Variable value) {
throw new UnsupportedError("${this.runtimeType}");
}
}
/// Named parameters. The [name] field is mandatory.
@@ -2129,14 +2010,6 @@ class NamedParameter extends FunctionParameter {
void set name(String? value) {
parameterName = value!;
}
@override
Variable get variable => this;
@override
void set variable(Variable value) {
throw new UnsupportedError("${this.runtimeType}");
}
}
/// The variable storage for `this`.
@@ -2409,14 +2282,6 @@ class ThisVariable extends Variable {
@override
int fileEqualsOffset = TreeNode.noOffset;
@override
Variable get variable => this;
@override
void set variable(Variable variable) {
throw new UnsupportedError("${this.runtimeType}.variable=");
}
@override
void clearAnnotations() {
annotations.clear();
@@ -2702,14 +2567,6 @@ class SyntheticVariable extends Variable {
@override
int fileEqualsOffset = TreeNode.noOffset;
@override
Variable get variable => this;
@override
void set variable(Variable variable) {
throw new UnsupportedError("${this.runtimeType}.variable=");
}
@override
void clearAnnotations() {
annotations.clear();
+1 -1
View File
@@ -573,7 +573,7 @@ class AstPrinter {
_sb.write(' ');
}
}
_sb.write(getVariableName(node.variable));
_sb.write(getVariableName(node));
if (includeInitializer && node.initializer != null && !node.isRequired) {
_sb.write(' = ');
writeExpression(node.initializer!);
+1 -1
View File
@@ -2867,7 +2867,7 @@ class Printer extends VisitorDefault<void> with VisitorVoidMixin {
'has-no-declared-initializer',
);
}
writeWord(getVariableName(variable.variable));
writeWord(getVariableName(variable));
Expression? initializer = variable.initializer;
if (initializer != null) {
writeSpaced(':=');
+1 -1
View File
@@ -1277,7 +1277,7 @@ class VerifyingVisitor extends RecursiveResultVisitor<void> {
void _verifyVariableDeclaration(Variable node) {
enterTreeNode(node);
visitChildren(node);
declareVariable(node.variable);
declareVariable(node);
if (afterConst && node.isConst && constantLocalsShouldBeRemoved) {
Expression? initializer = node.initializer;
if (!(initializer is InvalidExpression ||