diff --git a/pkg/front_end/lib/src/kernel/body_builder.dart b/pkg/front_end/lib/src/kernel/body_builder.dart index bf3ce8b7ac2..ad24d9d24bf 100644 --- a/pkg/front_end/lib/src/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/kernel/body_builder.dart @@ -7747,7 +7747,8 @@ class BodyBuilderImpl extends StackListenerImpl if (isClosureContextLoweringEnabled) { // TODO(cstefantsova): Add function parameters to the scope. - function.scope = new Scope([])..fileOffset = function.fileOffset; + function.scope = new Scope(contexts: []) + ..fileOffset = function.fileOffset; } if (declaration is FunctionDeclaration) { diff --git a/pkg/front_end/tool/ast_model.dart b/pkg/front_end/tool/ast_model.dart index 09460625327..577f6a7e77c 100644 --- a/pkg/front_end/tool/ast_model.dart +++ b/pkg/front_end/tool/ast_model.dart @@ -127,6 +127,7 @@ const Map> _fieldRuleMap = { 'VariableGet': {'variable': FieldRule(isDeclaration: false)}, 'VariableSet': {'variable': FieldRule(isDeclaration: false)}, 'LocalFunctionInvocation': {'variable': FieldRule(isDeclaration: false)}, + 'LocalVariable': {'variableInitialization': FieldRule(isDeclaration: false)}, 'BreakStatement': {'target': FieldRule(isDeclaration: false)}, 'ForStatement': {'variables': FieldRule(isDeclaration: true)}, 'ForInStatement': {'variable': FieldRule(isDeclaration: true)}, @@ -140,6 +141,9 @@ const Map> _fieldRuleMap = { 'FunctionType': {'typeParameters': FieldRule(isDeclaration: true)}, 'TypeParameterType': {'parameter': FieldRule(isDeclaration: false)}, 'StructuralParameterType': {'parameter': FieldRule(isDeclaration: false)}, + 'SyntheticVariable': { + 'variableInitialization': FieldRule(isDeclaration: false), + }, 'VariableStatement': {'_name': FieldRule(name: 'name')}, 'AssignedVariablePattern': {'variable': FieldRule(isDeclaration: false)}, 'InvalidPattern': {'declaredVariables': FieldRule(isDeclaration: true)}, diff --git a/pkg/kernel/lib/src/ast/statements.dart b/pkg/kernel/lib/src/ast/statements.dart index 8d17cce5035..f78fdc31c19 100644 --- a/pkg/kernel/lib/src/ast/statements.dart +++ b/pkg/kernel/lib/src/ast/statements.dart @@ -1946,37 +1946,173 @@ class FunctionDeclaration extends Statement implements LocalFunction { /// The statement that marks the declaration of the variable in the source Dart /// program. If the [initializer] is `null`, the variable was declared without /// an initializer. -class VariableInitialization extends Statement { +class VariableInitialization extends Statement implements VariableDeclaration { final ExpressionVariable variable; - final Expression? initializer; - - VariableInitialization({required this.variable, required this.initializer}); @override - R accept(StatementVisitor v) { - // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); + Expression? initializer; + + VariableInitialization({required this.variable, required this.initializer}) { + variable.variableInitialization = this; + } + + static const int FlagHasDeclaredInitializer = 1 << 0; + static const int FlagErroneouslyInitialized = 1 << 1; + + @override + int flags = 0; + + @override + bool get hasDeclaredInitializer => flags & FlagHasDeclaredInitializer != 0; + + @override + void set hasDeclaredInitializer(bool value) { + flags = value + ? (flags | FlagHasDeclaredInitializer) + : (flags & ~FlagHasDeclaredInitializer); } @override - R accept1(StatementVisitor1 v, A arg) { - // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); + bool get isErroneouslyInitialized => flags & FlagErroneouslyInitialized != 0; + + @override + void set isErroneouslyInitialized(bool value) { + flags = value + ? (flags | FlagErroneouslyInitialized) + : (flags & ~FlagErroneouslyInitialized); } + @override + bool get isConst => variable.isConst; + + @override + void set isConst(bool value) { + variable.isConst = value; + } + + @override + bool get isCovariantByClass => variable.isCovariantByClass; + + @override + void set isCovariantByClass(bool value) { + variable.isCovariantByClass = value; + } + + @override + bool get isCovariantByDeclaration => variable.isCovariantByDeclaration; + + @override + void set isCovariantByDeclaration(bool value) { + variable.isCovariantByDeclaration = value; + } + + @override + bool get isFinal => variable.isFinal; + + @override + void set isFinal(bool value) { + variable.isFinal = value; + } + + @override + bool get isHoisted => variable.isHoisted; + + @override + void set isHoisted(bool value) { + variable.isHoisted = value; + } + + @override + bool get isInitializingFormal => variable.isInitializingFormal; + + @override + void set isInitializingFormal(bool value) { + variable.isInitializingFormal = value; + } + + @override + bool get isLate => variable.isLate; + + @override + void set isLate(bool value) { + variable.isLate = value; + } + + @override + bool get isLowered => variable.isLowered; + + @override + void set isLowered(bool value) { + variable.isLowered = value; + } + + @override + bool get isRequired => variable.isRequired; + + @override + void set isRequired(bool value) { + variable.isRequired = value; + } + + @override + bool get isSuperInitializingFormal => variable.isSuperInitializingFormal; + + @override + void set isSuperInitializingFormal(bool value) { + variable.isSuperInitializingFormal = value; + } + + @override + bool get isSynthesized => variable.isSynthesized; + + @override + void set isSynthesized(bool value) { + variable.isSynthesized = value; + } + + @override + bool get isWildcard => variable.isWildcard; + + @override + void set isWildcard(bool value) { + variable.isWildcard = value; + } + + @override + R accept(StatementVisitor v) => v.visitVariableInitialization(this); + + @override + R accept1(StatementVisitor1 v, A arg) => + v.visitVariableInitialization(this, arg); + @override void transformChildren(Transformer v) { - // TODO(cstefantsova): Implement transformChildren. + // Note that [variable] is not owned by [VariableInitialization], so it's + // not visited. + v.transformList(annotations, this); + if (initializer != null) { + initializer = v.transform(initializer!); + initializer?.parent = this; + } } @override void transformOrRemoveChildren(RemovingTransformer v) { - // TODO(cstefantsova): Implement transformOrRemoveChildren. + // Note that [variable] is not owned by [VariableInitialization], so it's + // not visited. + v.transformExpressionList(annotations, this); + if (initializer != null) { + initializer = v.transformOrRemoveExpression(initializer!); + initializer?.parent = this; + } } @override void visitChildren(Visitor v) { - // TODO(cstefantsova): Implement visitChildren. + // Note that [variable] is not owned by [VariableInitialization], so it's + // not visited. + visitList(annotations, v); + initializer?.accept(v); } @override @@ -1993,4 +2129,45 @@ class VariableInitialization extends Statement { } printer.write(';'); } + + @override + List annotations = const []; + + @override + int binaryOffsetNoTag = TreeNode.noOffset; + + @override + int fileEqualsOffset = TreeNode.noOffset; + + @override + String? get name => variable.cosmeticName; + + @override + void set name(String? value) { + variable.cosmeticName = value; + } + + @override + DartType get type => variable.type; + + @override + void set type(DartType value) { + variable.type = value; + } + + @override + void addAnnotation(Expression node) { + if (annotations.isEmpty) { + annotations = []; + } + annotations.add(node..parent = this); + } + + @override + void clearAnnotations() { + annotations = const []; + } + + @override + bool get isAssignable => variable.isAssignable; } diff --git a/pkg/kernel/lib/src/ast/variables.dart b/pkg/kernel/lib/src/ast/variables.dart index 002bb31f526..4dda7ee98e7 100644 --- a/pkg/kernel/lib/src/ast/variables.dart +++ b/pkg/kernel/lib/src/ast/variables.dart @@ -8,11 +8,13 @@ part of '../../ast.dart'; sealed class Variable extends TreeNode { VariableContext get context => parent as VariableContext; - // CaptureKind get captureKind => context.captureKind; - /// The cosmetic name of the variable from the source code, if exists. String? get cosmeticName; + void set cosmeticName(String? value); + + int flags = 0; + @override void toTextInternal(AstPrinter printer) { printer.write(printer.getVariableName(this)); @@ -20,7 +22,30 @@ sealed class Variable extends TreeNode { } /// The root of the sealed hierarchy of non-type variables. -sealed class ExpressionVariable extends Variable {} +sealed class ExpressionVariable extends Variable { + /// Static type of the variable. + abstract DartType type; + + /// Initialization node for the variable, if available. + abstract VariableInitialization? variableInitialization; + + abstract bool isFinal; + abstract bool isConst; + abstract bool isHasDeclaredInitializer; + abstract bool isInitializingFormal; + abstract bool isCovariantByClass; + abstract bool isLate; + abstract bool isRequired; + abstract bool isCovariantByDeclaration; + abstract bool isLowered; + abstract bool isSynthesized; + abstract bool isHoisted; + abstract bool isWildcard; + abstract bool isSuperInitializingFormal; + abstract bool isErroneouslyInitialized; + + bool get isAssignable; +} /// Local variables. They aren't Statements. A [LocalVariable] is "declared" in /// the [VariableContext] it appears in. [VariableInitialization] @@ -30,35 +55,176 @@ class LocalVariable extends ExpressionVariable { @override String? cosmeticName; - LocalVariable({this.cosmeticName}); + @override + DartType type; @override - R accept(TreeVisitor v) { - // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); + VariableInitialization? variableInitialization; + + LocalVariable({this.cosmeticName, required DartType? type}) + : type = type ?? const DynamicType(); + + static const int FlagFinal = 1 << 0; + static const int FlagWildcard = 1 << 1; + static const int FlagConst = 1 << 2; + static const int FlagLate = 1 << 3; + static const int FlagLowered = 1 << 4; + static const int FlagHoisted = 1 << 5; + + @override + bool get isFinal => flags & FlagFinal != 0; + + @override + void set isFinal(bool value) { + flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); } @override - R accept1(TreeVisitor1 v, A arg) { - // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); + bool get isWildcard => flags & FlagWildcard != 0; + + @override + void set isWildcard(bool value) { + flags = value ? (flags | FlagWildcard) : (flags & ~FlagWildcard); } @override - void transformChildren(Transformer v) { - // TODO(cstefantsova): Implement transformChildren. + bool get isConst => flags & FlagConst != 0; + + @override + void set isConst(bool value) { + flags = value ? (flags | FlagConst) : (flags & ~FlagConst); } @override - void transformOrRemoveChildren(RemovingTransformer v) { - // TODO(cstefantsova): Implement transformOrRemoveChildren. + bool get isLate => flags & FlagLate != 0; + + @override + void set isLate(bool value) { + flags = value ? (flags | FlagLate) : (flags & ~FlagLate); } @override - void visitChildren(Visitor v) { - // TODO(cstefantsova): Implement visitChildren. + bool get isLowered => flags & FlagLowered != 0; + + @override + void set isLowered(bool value) { + flags = value ? (flags | FlagLowered) : (flags & ~FlagLowered); } + @override + bool get isHoisted => flags & FlagHoisted != 0; + + @override + void set isHoisted(bool value) { + flags = value ? (flags | FlagHoisted) : (flags & ~FlagHoisted); + } + + @override + bool get isCovariantByClass { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isCovariantByClass(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isCovariantByDeclaration { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isCovariantByDeclaration(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isErroneouslyInitialized { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isErroneouslyInitialized(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isHasDeclaredInitializer { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isHasDeclaredInitializer(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isInitializingFormal { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isInitializingFormal(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isRequired { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isRequired(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isSuperInitializingFormal { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isSuperInitializingFormal(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isSynthesized { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isSynthesized(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isAssignable { + if (isConst) return false; + if (isFinal) { + if (isLate) return variableInitialization?.initializer == null; + return false; + } + return true; + } + + @override + R accept(TreeVisitor v) => v.visitLocalVariable(this); + + @override + R accept1(TreeVisitor1 v, A arg) => + v.visitLocalVariable(this, arg); + + @override + void transformChildren(Transformer v) {} + + @override + void transformOrRemoveChildren(RemovingTransformer v) {} + + @override + void visitChildren(Visitor v) {} + @override String toString() { return "LocalVariable(${toStringInternal()})"; @@ -66,42 +232,199 @@ class LocalVariable extends ExpressionVariable { } /// Abstract parameter class, the parent for positional and named parameters. -sealed class FunctionParameter extends ExpressionVariable {} +sealed class FunctionParameter extends ExpressionVariable { + /// Function parameters can't be `const` or `late`, so they are assignable if + /// they aren't final. + @override + bool get isAssignable => !isFinal; + + /// Function parameters don't have initializers, only default values. + @override + VariableInitialization? get variableInitialization => null; + + @override + void set variableInitialization(VariableInitialization? value) {} + + static const int FlagFinal = 1 << 0; + static const int FlagWildcard = 1 << 1; + static const int FlagCovariantByClass = 1 << 2; + static const int FlagCovariantByDeclaration = 1 << 3; + static const int FlagInitializingFormal = 1 << 4; + static const int FlagSuperInitializingFormal = 1 << 5; + static const int FlagRequired = 1 << 6; + + @override + bool get isFinal => flags & FlagFinal != 0; + + @override + void set isFinal(bool value) { + flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); + } + + @override + bool get isWildcard => flags & FlagWildcard != 0; + + @override + void set isWildcard(bool value) { + flags = value ? (flags | FlagWildcard) : (flags & ~FlagWildcard); + } + + @override + bool get isCovariantByClass => flags & FlagCovariantByClass != 0; + + @override + void set isCovariantByClass(bool value) { + flags = value + ? (flags | FlagCovariantByClass) + : (flags & ~FlagCovariantByClass); + } + + @override + bool get isCovariantByDeclaration => flags & FlagCovariantByDeclaration != 0; + + @override + void set isCovariantByDeclaration(bool value) { + flags = value + ? (flags | FlagCovariantByDeclaration) + : (flags & ~FlagCovariantByDeclaration); + } + + @override + bool get isInitializingFormal => flags & FlagInitializingFormal != 0; + + @override + void set isInitializingFormal(bool value) { + flags = value + ? (flags | FlagInitializingFormal) + : (flags & ~FlagInitializingFormal); + } + + @override + bool get isSuperInitializingFormal => + flags & FlagSuperInitializingFormal != 0; + + @override + void set isSuperInitializingFormal(bool value) { + flags = value + ? (flags | FlagSuperInitializingFormal) + : (flags & ~FlagSuperInitializingFormal); + } + + @override + bool get isRequired => flags & FlagRequired != 0; + + @override + void set isRequired(bool value) { + flags = value ? (flags | FlagRequired) : (flags & ~FlagRequired); + } + + @override + bool get isErroneouslyInitialized { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isErroneouslyInitialized(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isHasDeclaredInitializer { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isHasDeclaredInitializer(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isSynthesized { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isSynthesized(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isConst { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isConst(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isLate { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isLate(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isHoisted { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isHoisted(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isLowered { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isLowered(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } +} /// Positional parameters. The [cosmeticName] field is optional and doesn't /// affect the runtime semantics of the program. class PositionalParameter extends FunctionParameter { @override - final String? cosmeticName; - - PositionalParameter(this.cosmeticName); + String? cosmeticName; @override - R accept(TreeVisitor v) { - // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); + DartType type; + + PositionalParameter({this.cosmeticName, required this.type}); + + @override + bool get isRequired { + throw new UnsupportedError("${this.runtimeType}"); } @override - R accept1(TreeVisitor1 v, A arg) { - // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); + void set isRequired(bool value) { + throw new UnsupportedError("${this.runtimeType}"); } @override - void transformChildren(Transformer v) { - // TODO(cstefantsova): Implement transformChildren. - } + R accept(TreeVisitor v) => v.visitPositionalParameter(this); @override - void transformOrRemoveChildren(RemovingTransformer v) { - // TODO(cstefantsova): Implement transformOrRemoveChildren. - } + R accept1(TreeVisitor1 v, A arg) => + v.visitPositionalParameter(this, arg); @override - void visitChildren(Visitor v) { - // TODO(cstefantsova): Implement visitChildren. - } + void transformChildren(Transformer v) {} + + @override + void transformOrRemoveChildren(RemovingTransformer v) {} + + @override + void visitChildren(Visitor v) {} @override String toString() { @@ -111,39 +434,36 @@ class PositionalParameter extends FunctionParameter { /// Named parameters. The [name] field is mandatory. class NamedParameter extends FunctionParameter { - final String name; + String name; @override String get cosmeticName => name; - NamedParameter({required this.name}); - @override - R accept(TreeVisitor v) { - // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); + void set cosmeticName(String? value) { + name = value!; } @override - R accept1(TreeVisitor1 v, A arg) { - // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); - } + DartType type; + + NamedParameter({required this.name, required this.type}); @override - void transformChildren(Transformer v) { - // TODO(cstefantsova): Implement transformChildren. - } + R accept(TreeVisitor v) => v.visitNamedParameter(this); @override - void transformOrRemoveChildren(RemovingTransformer v) { - // TODO(cstefantsova): Implement transformOrRemoveChildren. - } + R accept1(TreeVisitor1 v, A arg) => + v.visitNamedParameter(this, arg); @override - void visitChildren(Visitor v) { - // TODO(cstefantsova): Implement visitChildren. - } + void transformChildren(Transformer v) {} + + @override + void transformOrRemoveChildren(RemovingTransformer v) {} + + @override + void visitChildren(Visitor v) {} @override String toString() { @@ -156,39 +476,183 @@ class ThisVariable extends ExpressionVariable { @override String get cosmeticName => "this"; - ThisVariable(); + @override + void set cosmeticName(String? value) {} @override - R accept(TreeVisitor v) { - // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); + VariableInitialization? get variableInitialization => null; + + @override + void set variableInitialization(VariableInitialization? value) {} + + @override + DartType type; + + ThisVariable({required this.type}); + + @override + bool get isFinal { + throw new UnsupportedError("${this.runtimeType}"); } @override - R accept1(TreeVisitor1 v, A arg) { - // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); + void set isFinal(bool value) { + throw new UnsupportedError("${this.runtimeType}"); } @override - void transformChildren(Transformer v) { - // TODO(cstefantsova): Implement transformChildren. + bool get isWildcard { + throw new UnsupportedError("${this.runtimeType}"); } @override - void transformOrRemoveChildren(RemovingTransformer v) { - // TODO(cstefantsova): Implement transformOrRemoveChildren. + void set isWildcard(bool value) { + throw new UnsupportedError("${this.runtimeType}"); } @override - void visitChildren(Visitor v) { - // TODO(cstefantsova): Implement visitChildren. + bool get isCovariantByClass { + throw new UnsupportedError("${this.runtimeType}"); } + @override + void set isCovariantByClass(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isCovariantByDeclaration { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isCovariantByDeclaration(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isInitializingFormal { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isInitializingFormal(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isSuperInitializingFormal { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isSuperInitializingFormal(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isErroneouslyInitialized { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isErroneouslyInitialized(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isHasDeclaredInitializer { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isHasDeclaredInitializer(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isRequired { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isRequired(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isSynthesized { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isSynthesized(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isConst { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isConst(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isLate { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isLate(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isHoisted { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isHoisted(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isLowered { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isLowered(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + R accept(TreeVisitor v) => v.visitThisVariable(this); + + @override + R accept1(TreeVisitor1 v, A arg) => + v.visitThisVariable(this, arg); + + @override + void transformChildren(Transformer v) {} + + @override + void transformOrRemoveChildren(RemovingTransformer v) {} + + @override + void visitChildren(Visitor v) {} + @override String toString() { return "ThisVariable(${toStringInternal()})"; } + + @override + bool get isAssignable => false; } /// A variable introduced during desugaring. Such variables don't correspond to @@ -197,39 +661,175 @@ class SyntheticVariable extends ExpressionVariable { @override String? cosmeticName; - SyntheticVariable({this.cosmeticName}); + @override + DartType type; @override - R accept(TreeVisitor v) { - // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); + VariableInitialization? variableInitialization; + + SyntheticVariable({this.cosmeticName, required this.type}); + + static const int FlagFinal = 1 << 0; + static const int FlagLowered = 1 << 1; + static const int FlagHoisted = 1 << 2; + + @override + bool get isFinal => flags & FlagFinal != 0; + + @override + void set isFinal(bool value) { + flags = value ? (flags | FlagFinal) : (flags & ~FlagFinal); } @override - R accept1(TreeVisitor1 v, A arg) { - // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); + bool get isLowered => flags & FlagLowered != 0; + + @override + void set isLowered(bool value) { + flags = value ? (flags | FlagLowered) : (flags & ~FlagLowered); } @override - void transformChildren(Transformer v) { - // TODO(cstefantsova): Implement transformChildren. + bool get isHoisted => flags & FlagHoisted != 0; + + @override + void set isHoisted(bool value) { + flags = value ? (flags | FlagHoisted) : (flags & ~FlagHoisted); } @override - void transformOrRemoveChildren(RemovingTransformer v) { - // TODO(cstefantsova): Implement transformOrRemoveChildren. + bool get isCovariantByClass { + throw new UnsupportedError("${this.runtimeType}"); } @override - void visitChildren(Visitor v) { - // TODO(cstefantsova): Implement visitChildren. + void set isCovariantByClass(bool value) { + throw new UnsupportedError("${this.runtimeType}"); } + @override + bool get isCovariantByDeclaration { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isCovariantByDeclaration(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isErroneouslyInitialized { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isErroneouslyInitialized(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isHasDeclaredInitializer { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isHasDeclaredInitializer(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isInitializingFormal { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isInitializingFormal(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isRequired { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isRequired(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isSuperInitializingFormal { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isSuperInitializingFormal(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isSynthesized { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isSynthesized(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isConst { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isConst(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isLate { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isLate(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + bool get isWildcard { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + void set isWildcard(bool value) { + throw new UnsupportedError("${this.runtimeType}"); + } + + @override + R accept(TreeVisitor v) => v.visitSyntheticVariable(this); + + @override + R accept1(TreeVisitor1 v, A arg) => + v.visitSyntheticVariable(this, arg); + + @override + void transformChildren(Transformer v) {} + + @override + void transformOrRemoveChildren(RemovingTransformer v) {} + + @override + void visitChildren(Visitor v) {} + @override String toString() { return "SyntheticVariable(${toStringInternal()})"; } + + @override + bool get isAssignable => !isConst && !isFinal; } /// The enum reflecting the kind of a variable context. A context is @@ -253,13 +853,13 @@ class VariableContext extends TreeNode { @override R accept(TreeVisitor v) { // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); + throw new UnimplementedError(); } @override R accept1(TreeVisitor1 v, A arg) { // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); + throw new UnimplementedError(); } @override @@ -303,18 +903,18 @@ class VariableContext extends TreeNode { class Scope extends TreeNode { final List contexts; - Scope(this.contexts); + Scope({required this.contexts}); @override R accept(TreeVisitor v) { // TODO(cstefantsova): Implement accept. - throw UnimplementedError(); + throw new UnimplementedError(); } @override R accept1(TreeVisitor1 v, A arg) { // TODO(cstefantsova): Implement accept1. - throw UnimplementedError(); + throw new UnimplementedError(); } @override diff --git a/pkg/kernel/lib/src/equivalence.dart b/pkg/kernel/lib/src/equivalence.dart index a62e3c06d67..d9956715dc8 100644 --- a/pkg/kernel/lib/src/equivalence.dart +++ b/pkg/kernel/lib/src/equivalence.dart @@ -5384,6 +5384,18 @@ class EquivalenceStrategy { if (!checkVariableInitialization_initializer(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkVariableInitialization_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_annotations(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_binaryOffsetNoTag(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkVariableInitialization_fileEqualsOffset(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkVariableInitialization_fileOffset(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -5484,6 +5496,9 @@ class EquivalenceStrategy { if (!checkTypeVariable_parameter(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkTypeVariable_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkTypeVariable_fileOffset(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -5501,6 +5516,15 @@ class EquivalenceStrategy { if (!checkLocalVariable_cosmeticName(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkLocalVariable_type(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkLocalVariable_variableInitialization(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkLocalVariable_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkLocalVariable_fileOffset(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -5518,6 +5542,12 @@ class EquivalenceStrategy { if (!checkPositionalParameter_cosmeticName(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkPositionalParameter_type(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkPositionalParameter_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkPositionalParameter_fileOffset(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -5535,6 +5565,12 @@ class EquivalenceStrategy { if (!checkNamedParameter_name(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkNamedParameter_type(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkNamedParameter_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkNamedParameter_fileOffset(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -5549,6 +5585,12 @@ class EquivalenceStrategy { if (other is! ThisVariable) return false; visitor.pushNodeState(node, other); bool result = true; + if (!checkThisVariable_type(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkThisVariable_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkThisVariable_fileOffset(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -5566,6 +5608,15 @@ class EquivalenceStrategy { if (!checkSyntheticVariable_cosmeticName(visitor, node, other)) { result = visitor.resultOnInequivalence; } + if (!checkSyntheticVariable_type(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkSyntheticVariable_variableInitialization(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } + if (!checkSyntheticVariable_flags(visitor, node, other)) { + result = visitor.resultOnInequivalence; + } if (!checkSyntheticVariable_fileOffset(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -9750,6 +9801,29 @@ class EquivalenceStrategy { node.initializer, other.initializer, 'initializer'); } + bool checkVariableInitialization_flags(EquivalenceVisitor visitor, + VariableInitialization node, VariableInitialization other) { + return visitor.checkValues(node.flags, other.flags, 'flags'); + } + + bool checkVariableInitialization_annotations(EquivalenceVisitor visitor, + VariableInitialization node, VariableInitialization other) { + return visitor.checkLists( + node.annotations, other.annotations, visitor.checkNodes, 'annotations'); + } + + bool checkVariableInitialization_binaryOffsetNoTag(EquivalenceVisitor visitor, + VariableInitialization node, VariableInitialization other) { + return visitor.checkValues( + node.binaryOffsetNoTag, other.binaryOffsetNoTag, 'binaryOffsetNoTag'); + } + + bool checkVariableInitialization_fileEqualsOffset(EquivalenceVisitor visitor, + VariableInitialization node, VariableInitialization other) { + return visitor.checkValues( + node.fileEqualsOffset, other.fileEqualsOffset, 'fileEqualsOffset'); + } + bool checkVariableInitialization_fileOffset(EquivalenceVisitor visitor, VariableInitialization node, VariableInitialization other) { return checkStatement_fileOffset(visitor, node, other); @@ -9847,6 +9921,16 @@ class EquivalenceStrategy { node.parameter, other.parameter, 'parameter'); } + bool checkVariable_flags( + EquivalenceVisitor visitor, Variable node, Variable other) { + return visitor.checkValues(node.flags, other.flags, 'flags'); + } + + bool checkTypeVariable_flags( + EquivalenceVisitor visitor, TypeVariable node, TypeVariable other) { + return checkVariable_flags(visitor, node, other); + } + bool checkVariable_fileOffset( EquivalenceVisitor visitor, Variable node, Variable other) { return checkTreeNode_fileOffset(visitor, node, other); @@ -9863,6 +9947,27 @@ class EquivalenceStrategy { node.cosmeticName, other.cosmeticName, 'cosmeticName'); } + bool checkLocalVariable_type( + EquivalenceVisitor visitor, LocalVariable node, LocalVariable other) { + return visitor.checkNodes(node.type, other.type, 'type'); + } + + bool checkLocalVariable_variableInitialization( + EquivalenceVisitor visitor, LocalVariable node, LocalVariable other) { + return visitor.checkDeclarations(node.variableInitialization, + other.variableInitialization, 'variableInitialization'); + } + + bool checkExpressionVariable_flags(EquivalenceVisitor visitor, + ExpressionVariable node, ExpressionVariable other) { + return checkVariable_flags(visitor, node, other); + } + + bool checkLocalVariable_flags( + EquivalenceVisitor visitor, LocalVariable node, LocalVariable other) { + return checkExpressionVariable_flags(visitor, node, other); + } + bool checkExpressionVariable_fileOffset(EquivalenceVisitor visitor, ExpressionVariable node, ExpressionVariable other) { return checkVariable_fileOffset(visitor, node, other); @@ -9879,6 +9984,21 @@ class EquivalenceStrategy { node.cosmeticName, other.cosmeticName, 'cosmeticName'); } + bool checkPositionalParameter_type(EquivalenceVisitor visitor, + PositionalParameter node, PositionalParameter other) { + return visitor.checkNodes(node.type, other.type, 'type'); + } + + bool checkFunctionParameter_flags(EquivalenceVisitor visitor, + FunctionParameter node, FunctionParameter other) { + return checkExpressionVariable_flags(visitor, node, other); + } + + bool checkPositionalParameter_flags(EquivalenceVisitor visitor, + PositionalParameter node, PositionalParameter other) { + return checkFunctionParameter_flags(visitor, node, other); + } + bool checkFunctionParameter_fileOffset(EquivalenceVisitor visitor, FunctionParameter node, FunctionParameter other) { return checkExpressionVariable_fileOffset(visitor, node, other); @@ -9894,11 +10014,31 @@ class EquivalenceStrategy { return visitor.checkValues(node.name, other.name, 'name'); } + bool checkNamedParameter_type( + EquivalenceVisitor visitor, NamedParameter node, NamedParameter other) { + return visitor.checkNodes(node.type, other.type, 'type'); + } + + bool checkNamedParameter_flags( + EquivalenceVisitor visitor, NamedParameter node, NamedParameter other) { + return checkFunctionParameter_flags(visitor, node, other); + } + bool checkNamedParameter_fileOffset( EquivalenceVisitor visitor, NamedParameter node, NamedParameter other) { return checkFunctionParameter_fileOffset(visitor, node, other); } + bool checkThisVariable_type( + EquivalenceVisitor visitor, ThisVariable node, ThisVariable other) { + return visitor.checkNodes(node.type, other.type, 'type'); + } + + bool checkThisVariable_flags( + EquivalenceVisitor visitor, ThisVariable node, ThisVariable other) { + return checkExpressionVariable_flags(visitor, node, other); + } + bool checkThisVariable_fileOffset( EquivalenceVisitor visitor, ThisVariable node, ThisVariable other) { return checkExpressionVariable_fileOffset(visitor, node, other); @@ -9910,6 +10050,22 @@ class EquivalenceStrategy { node.cosmeticName, other.cosmeticName, 'cosmeticName'); } + bool checkSyntheticVariable_type(EquivalenceVisitor visitor, + SyntheticVariable node, SyntheticVariable other) { + return visitor.checkNodes(node.type, other.type, 'type'); + } + + bool checkSyntheticVariable_variableInitialization(EquivalenceVisitor visitor, + SyntheticVariable node, SyntheticVariable other) { + return visitor.checkDeclarations(node.variableInitialization, + other.variableInitialization, 'variableInitialization'); + } + + bool checkSyntheticVariable_flags(EquivalenceVisitor visitor, + SyntheticVariable node, SyntheticVariable other) { + return checkExpressionVariable_flags(visitor, node, other); + } + bool checkSyntheticVariable_fileOffset(EquivalenceVisitor visitor, SyntheticVariable node, SyntheticVariable other) { return checkExpressionVariable_fileOffset(visitor, node, other);