| // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| /// This file declares a "shadow hierarchy" of concrete classes which extend |
| /// the kernel class hierarchy, adding methods and fields needed by the |
| /// BodyBuilder. |
| /// |
| /// Instances of these classes may be created using the factory methods in |
| /// `ast_factory.dart`. |
| /// |
| /// Note that these classes represent the Dart language prior to desugaring. |
| /// When a single Dart construct desugars to a tree containing multiple kernel |
| /// AST nodes, the shadow class extends the kernel object at the top of the |
| /// desugared tree. |
| /// |
| /// This means that in some cases multiple shadow classes may extend the same |
| /// kernel class, because multiple constructs in Dart may desugar to a tree |
| /// with the same kind of root node. |
| library; |
| |
| import 'package:_fe_analyzer_shared/src/type_inference/type_analysis_result.dart' |
| as shared; |
| import 'package:_fe_analyzer_shared/src/types/shared_type.dart'; |
| import 'package:kernel/ast.dart'; |
| import 'package:kernel/names.dart'; |
| import 'package:kernel/src/printer.dart'; |
| import 'package:kernel/text/ast_to_text.dart' show Precedence; |
| import 'package:kernel/type_environment.dart'; |
| |
| import '../base/problems.dart' show unsupported; |
| import '../builder/declaration_builders.dart'; |
| import '../type_inference/inference_results.dart'; |
| import '../type_inference/inference_visitor.dart'; |
| import '../type_inference/type_schema.dart' show UnknownType; |
| |
| typedef SharedMatchContext = shared.MatchContext<TreeNode, Expression, Pattern, |
| SharedTypeView<DartType>, VariableDeclaration>; |
| |
| int getExtensionTypeParameterCount(Arguments arguments) { |
| if (arguments is ArgumentsImpl) { |
| return arguments._extensionTypeParameterCount; |
| } else { |
| // TODO(johnniwinther): Remove this path or assert why it is accepted. |
| return 0; |
| } |
| } |
| |
| List<DartType>? getExplicitExtensionTypeArguments(Arguments arguments) { |
| if (arguments is ArgumentsImpl) { |
| if (arguments._explicitExtensionTypeArgumentCount == 0) { |
| return null; |
| } else { |
| return arguments.types |
| .take(arguments._explicitExtensionTypeArgumentCount) |
| .toList(); |
| } |
| } else { |
| // TODO(johnniwinther): Remove this path or assert why it is accepted. |
| return null; |
| } |
| } |
| |
| /// Information about explicit/implicit type arguments used for error |
| /// reporting. |
| abstract class TypeArgumentsInfo { |
| const TypeArgumentsInfo(); |
| |
| /// Returns `true` if the [index]th type argument was inferred. |
| bool isInferred(int index); |
| |
| /// Returns the offset to use when reporting an error on the [index]th type |
| /// arguments, using [offset] as the default offset. |
| int getOffsetForIndex(int index, int offset) => offset; |
| } |
| |
| class AllInferredTypeArgumentsInfo extends TypeArgumentsInfo { |
| const AllInferredTypeArgumentsInfo(); |
| |
| @override |
| bool isInferred(int index) => true; |
| } |
| |
| class NoneInferredTypeArgumentsInfo extends TypeArgumentsInfo { |
| const NoneInferredTypeArgumentsInfo(); |
| |
| @override |
| bool isInferred(int index) => false; |
| } |
| |
| class ExtensionMethodTypeArgumentsInfo implements TypeArgumentsInfo { |
| final ArgumentsImpl arguments; |
| |
| ExtensionMethodTypeArgumentsInfo(this.arguments); |
| |
| @override |
| bool isInferred(int index) { |
| if (index < arguments._extensionTypeParameterCount) { |
| // The index refers to a type argument for a type parameter declared on |
| // the extension. Check whether we have enough explicit extension type |
| // arguments. |
| return index >= arguments._explicitExtensionTypeArgumentCount; |
| } |
| // The index refers to a type argument for a type parameter declared on |
| // the method. Check whether we have enough explicit regular type arguments. |
| return index - arguments._extensionTypeParameterCount >= |
| arguments._explicitTypeArgumentCount; |
| } |
| |
| @override |
| int getOffsetForIndex(int index, int offset) { |
| if (index < arguments._extensionTypeParameterCount) { |
| return arguments._extensionTypeArgumentOffset ?? offset; |
| } |
| return offset; |
| } |
| } |
| |
| TypeArgumentsInfo getTypeArgumentsInfo(Arguments arguments) { |
| if (arguments is ArgumentsImpl) { |
| if (arguments._extensionTypeParameterCount == 0) { |
| return arguments._explicitTypeArgumentCount == 0 |
| ? const AllInferredTypeArgumentsInfo() |
| : const NoneInferredTypeArgumentsInfo(); |
| } else { |
| return new ExtensionMethodTypeArgumentsInfo(arguments); |
| } |
| } else { |
| // Coverage-ignore-block(suite): Not run. |
| // This code path should only be taken in situations where there are no |
| // type arguments at all, e.g. calling a user-definable operator. |
| assert(arguments.types.isEmpty); |
| return const NoneInferredTypeArgumentsInfo(); |
| } |
| } |
| |
| List<DartType>? getExplicitTypeArguments(Arguments arguments) { |
| if (arguments is ArgumentsImpl) { |
| if (arguments._explicitTypeArgumentCount == 0) { |
| return null; |
| } else if (arguments._extensionTypeParameterCount == 0) { |
| return arguments.types; |
| } else { |
| return arguments.types |
| .skip(arguments._extensionTypeParameterCount) |
| .toList(); |
| } |
| } else { |
| // Coverage-ignore-block(suite): Not run. |
| // This code path should only be taken in situations where there are no |
| // type arguments at all, e.g. calling a user-definable operator. |
| assert(arguments.types.isEmpty); |
| return null; |
| } |
| } |
| |
| bool hasExplicitTypeArguments(Arguments arguments) { |
| return getExplicitTypeArguments(arguments) != null; |
| } |
| |
| mixin InternalTreeNode implements TreeNode { |
| @override |
| // Coverage-ignore(suite): Not run. |
| void replaceChild(TreeNode child, TreeNode replacement) { |
| // Do nothing. The node should not be part of the resulting AST, anyway. |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void transformChildren(Transformer v) { |
| unsupported( |
| "${runtimeType}.transformChildren on ${v.runtimeType}", -1, null); |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void transformOrRemoveChildren(RemovingTransformer v) { |
| unsupported("${runtimeType}.transformOrRemoveChildren on ${v.runtimeType}", |
| -1, null); |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void visitChildren(Visitor v) { |
| unsupported("${runtimeType}.visitChildren on ${v.runtimeType}", -1, null); |
| } |
| } |
| |
| // Coverage-ignore(suite): Not run. |
| /// Common base class for internal statements. |
| abstract class InternalStatement extends AuxiliaryStatement { |
| @override |
| void replaceChild(TreeNode child, TreeNode replacement) { |
| // Do nothing. The node should not be part of the resulting AST, anyway. |
| } |
| |
| @override |
| void transformChildren(Transformer v) => unsupported( |
| "${runtimeType}.transformChildren on ${v.runtimeType}", -1, null); |
| |
| @override |
| void transformOrRemoveChildren(RemovingTransformer v) => unsupported( |
| "${runtimeType}.transformOrRemoveChildren on ${v.runtimeType}", -1, null); |
| |
| @override |
| void visitChildren(Visitor v) => |
| unsupported("${runtimeType}.visitChildren on ${v.runtimeType}", -1, null); |
| |
| StatementInferenceResult acceptInference(InferenceVisitorImpl visitor); |
| } |
| |
| class ForInStatementWithSynthesizedVariable extends InternalStatement { |
| VariableDeclaration? variable; |
| Expression iterable; |
| Expression? syntheticAssignment; |
| Statement? expressionEffects; |
| Statement body; |
| final bool isAsync; |
| final bool hasProblem; |
| int bodyOffset = TreeNode.noOffset; |
| |
| ForInStatementWithSynthesizedVariable(this.variable, this.iterable, |
| this.syntheticAssignment, this.expressionEffects, this.body, |
| {required this.isAsync, required this.hasProblem}) { |
| variable?.parent = this; |
| iterable.parent = this; |
| syntheticAssignment?.parent = this; |
| expressionEffects?.parent = this; |
| body.parent = this; |
| } |
| |
| @override |
| StatementInferenceResult acceptInference(InferenceVisitorImpl visitor) { |
| return visitor.visitForInStatementWithSynthesizedVariable(this); |
| } |
| |
| @override |
| String toString() { |
| return "ForInStatementWithSynthesizedVariable(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter state) { |
| // TODO(johnniwinther): Implement this. |
| } |
| } |
| |
| class TryStatement extends InternalStatement { |
| Statement tryBlock; |
| List<Catch> catchBlocks; |
| Statement? finallyBlock; |
| |
| TryStatement(this.tryBlock, this.catchBlocks, this.finallyBlock) { |
| tryBlock.parent = this; |
| setParents(catchBlocks, this); |
| finallyBlock?.parent = this; |
| } |
| |
| @override |
| StatementInferenceResult acceptInference(InferenceVisitorImpl visitor) { |
| return visitor.visitTryStatement(this); |
| } |
| |
| @override |
| String toString() { |
| return "TryStatement(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write('try '); |
| printer.writeStatement(tryBlock); |
| for (Catch catchBlock in catchBlocks) { |
| printer.write(' '); |
| printer.writeCatch(catchBlock); |
| } |
| if (finallyBlock != null) { |
| printer.write(' finally '); |
| printer.writeStatement(finallyBlock!); |
| } |
| } |
| } |
| |
| class SwitchCaseImpl extends SwitchCase { |
| final List<int> caseOffsets; |
| final bool hasLabel; |
| |
| SwitchCaseImpl(this.caseOffsets, List<Expression> expressions, |
| List<int> expressionOffsets, Statement body, |
| {bool isDefault = false, required this.hasLabel}) |
| : super(expressions, expressionOffsets, body, isDefault: isDefault); |
| |
| @override |
| String toString() { |
| return "SwitchCaseImpl(${toStringInternal()})"; |
| } |
| } |
| |
| class BreakStatementImpl extends BreakStatement { |
| Statement? targetStatement; |
| final bool isContinue; |
| |
| BreakStatementImpl({required this.isContinue}) : super(dummyLabeledStatement); |
| |
| @override |
| String toString() { |
| return "BreakStatementImpl(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| if (isContinue) { |
| printer.write('continue '); |
| } else { |
| printer.write('break '); |
| } |
| printer.write(printer.getLabelName(target)); |
| printer.write(';'); |
| } |
| } |
| |
| // Coverage-ignore(suite): Not run. |
| /// Common base class for internal expressions. |
| abstract class InternalExpression extends AuxiliaryExpression { |
| @override |
| void replaceChild(TreeNode child, TreeNode replacement) { |
| // Do nothing. The node should not be part of the resulting AST, anyway. |
| } |
| |
| @override |
| DartType getStaticType(StaticTypeContext context) => |
| unsupported("${runtimeType}.getStaticType", -1, null); |
| |
| @override |
| DartType getStaticTypeInternal(StaticTypeContext context) => |
| unsupported("${runtimeType}.getStaticType", -1, null); |
| |
| @override |
| void visitChildren(Visitor<dynamic> v) => |
| unsupported("${runtimeType}.visitChildren", -1, null); |
| |
| @override |
| void transformChildren(Transformer v) => |
| unsupported("${runtimeType}.transformChildren", -1, null); |
| |
| @override |
| void transformOrRemoveChildren(RemovingTransformer v) => |
| unsupported("${runtimeType}.transformOrRemoveChildren", -1, null); |
| |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext); |
| |
| @override |
| void toTextInternal(AstPrinter printer) { |
| // TODO(johnniwinther): Implement this. |
| } |
| } |
| |
| // Coverage-ignore(suite): Not run. |
| /// Common base class for internal initializers. |
| abstract class InternalInitializer extends AuxiliaryInitializer { |
| @override |
| void visitChildren(Visitor<dynamic> v) => |
| unsupported("${runtimeType}.visitChildren", -1, null); |
| |
| @override |
| void transformChildren(Transformer v) => |
| unsupported("${runtimeType}.transformChildren", -1, null); |
| |
| @override |
| void transformOrRemoveChildren(RemovingTransformer v) => |
| unsupported("${runtimeType}.transformOrRemoveChildren", -1, null); |
| |
| InitializerInferenceResult acceptInference(InferenceVisitorImpl visitor); |
| } |
| |
| /// Front end specific implementation of [Argument]. |
| class ArgumentsImpl extends Arguments { |
| // TODO(johnniwinther): Move this to the static invocation instead. |
| final int _extensionTypeParameterCount; |
| |
| final int _explicitExtensionTypeArgumentCount; |
| |
| final int? _extensionTypeArgumentOffset; |
| |
| int _explicitTypeArgumentCount; |
| |
| List<Object?>? argumentsOriginalOrder; |
| |
| /// True if the arguments are passed to the super-constructor in a |
| /// super-initializer, and the positional parameters are super-initializer |
| /// parameters. It is true that either all of the positional parameters are |
| /// super-initializer parameters or none of them, so a simple boolean |
| /// accurately reflects the state. |
| bool positionalAreSuperParameters = false; |
| |
| /// Names of the named positional parameters. If none of the parameters are |
| /// super-positional, the field is null. |
| Set<String>? namedSuperParameterNames; |
| |
| ArgumentsImpl.internal( |
| {required List<Expression> positional, |
| required List<DartType>? types, |
| required List<NamedExpression>? named, |
| required int extensionTypeParameterCount, |
| required int explicitExtensionTypeArgumentCount, |
| required int? extensionTypeArgumentOffset, |
| required int explicitTypeArgumentCount}) |
| : this._extensionTypeParameterCount = extensionTypeParameterCount, |
| this._explicitExtensionTypeArgumentCount = |
| explicitExtensionTypeArgumentCount, |
| this._extensionTypeArgumentOffset = extensionTypeArgumentOffset, |
| this._explicitTypeArgumentCount = explicitTypeArgumentCount, |
| this.argumentsOriginalOrder = null, |
| super(positional, types: types, named: named); |
| |
| ArgumentsImpl(List<Expression> positional, |
| {List<DartType>? types, |
| List<NamedExpression>? named, |
| this.argumentsOriginalOrder}) |
| : _explicitTypeArgumentCount = types?.length ?? 0, |
| _extensionTypeParameterCount = 0, |
| _explicitExtensionTypeArgumentCount = 0, |
| // The offset is unused in this case. |
| _extensionTypeArgumentOffset = null, |
| super(positional, types: types, named: named); |
| |
| ArgumentsImpl.forExtensionMethod(int extensionTypeParameterCount, |
| int typeParameterCount, Expression receiver, |
| {List<DartType> extensionTypeArguments = const <DartType>[], |
| int? extensionTypeArgumentOffset, |
| List<DartType> typeArguments = const <DartType>[], |
| List<Expression> positionalArguments = const <Expression>[], |
| List<NamedExpression> namedArguments = const <NamedExpression>[], |
| this.argumentsOriginalOrder}) |
| : _extensionTypeParameterCount = extensionTypeParameterCount, |
| _explicitExtensionTypeArgumentCount = extensionTypeArguments.length, |
| _explicitTypeArgumentCount = typeArguments.length, |
| _extensionTypeArgumentOffset = extensionTypeArgumentOffset, |
| assert( |
| extensionTypeArguments.isEmpty || |
| extensionTypeArguments.length == extensionTypeParameterCount, |
| "Extension type arguments must be empty or complete."), |
| super(<Expression>[receiver]..addAll(positionalArguments), |
| named: namedArguments, |
| types: <DartType>[] |
| ..addAll(_normalizeTypeArguments( |
| extensionTypeParameterCount, extensionTypeArguments)) |
| ..addAll( |
| _normalizeTypeArguments(typeParameterCount, typeArguments))); |
| |
| static ArgumentsImpl clone(ArgumentsImpl node, List<Expression> positional, |
| List<NamedExpression> named, List<DartType> types) { |
| return new ArgumentsImpl.internal( |
| positional: positional, |
| named: named, |
| types: types, |
| extensionTypeParameterCount: node._extensionTypeParameterCount, |
| explicitExtensionTypeArgumentCount: |
| node._explicitExtensionTypeArgumentCount, |
| explicitTypeArgumentCount: node._explicitTypeArgumentCount, |
| extensionTypeArgumentOffset: node._extensionTypeArgumentOffset); |
| } |
| |
| static List<DartType> _normalizeTypeArguments( |
| int length, List<DartType> arguments) { |
| if (arguments.isEmpty && length > 0) { |
| return new List<DartType>.filled(length, const UnknownType()); |
| } |
| return arguments; |
| } |
| |
| static void setNonInferrableArgumentTypes( |
| ArgumentsImpl arguments, List<DartType> types) { |
| arguments.types.clear(); |
| arguments.types.addAll(types); |
| arguments._explicitTypeArgumentCount = types.length; |
| } |
| |
| static void removeNonInferrableArgumentTypes(ArgumentsImpl arguments) { |
| arguments.types.clear(); |
| arguments._explicitTypeArgumentCount = 0; |
| } |
| |
| @override |
| String toString() { |
| return "ArgumentsImpl(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing a cascade expression. |
| /// |
| /// A cascade expression of the form `a..b()..c()` is represented as the kernel |
| /// expression: |
| /// |
| /// let v = a in |
| /// let _ = v.b() in |
| /// let _ = v.c() in |
| /// v |
| /// |
| /// In the documentation that follows, `v` is referred to as the "cascade |
| /// variable"--this is the variable that remembers the value of the expression |
| /// preceding the first `..` while the cascades are being evaluated. |
| class Cascade extends InternalExpression { |
| /// The temporary variable holding the cascade receiver expression in its |
| /// initializer; |
| VariableDeclaration variable; |
| |
| final bool isNullAware; |
| |
| /// The expressions performed on [variable]. |
| final List<Expression> expressions = <Expression>[]; |
| |
| /// Creates a [Cascade] using [variable] as the cascade |
| /// variable. Caller is responsible for ensuring that [variable]'s |
| /// initializer is the expression preceding the first `..` of the cascade |
| /// expression. |
| Cascade(this.variable, {required this.isNullAware}) { |
| variable.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitCascade(this, typeContext); |
| } |
| |
| /// Adds [expression] to the list of [expressions] performed on [variable]. |
| void addCascadeExpression(Expression expression) { |
| expressions.add(expression); |
| expression.parent = this; |
| } |
| |
| @override |
| String toString() { |
| return "Cascade(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write('let '); |
| printer.writeVariableDeclaration(variable); |
| printer.write(' in cascade {'); |
| printer.incIndentation(); |
| for (Expression expression in expressions) { |
| printer.newLine(); |
| printer.writeExpression(expression); |
| printer.write(';'); |
| } |
| printer.decIndentation(); |
| if (expressions.isNotEmpty) { |
| printer.newLine(); |
| } |
| printer.write('} => '); |
| printer.write(printer.getVariableName(variable)); |
| } |
| } |
| |
| /// Internal expression representing a deferred check. |
| // TODO(johnniwinther): Change the representation to be direct and perform |
| // the [Let] encoding in the replacement. |
| class DeferredCheck extends InternalExpression { |
| VariableDeclaration variable; |
| Expression expression; |
| |
| DeferredCheck(this.variable, this.expression) { |
| variable.parent = this; |
| expression.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitDeferredCheck(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "DeferredCheck(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write('let '); |
| printer.writeVariableDeclaration(variable); |
| printer.write(' in '); |
| printer.writeExpression(expression); |
| } |
| } |
| |
| /// Common base class for shadow objects representing expressions in kernel |
| /// form. |
| abstract class ExpressionJudgment extends AuxiliaryExpression { |
| /// Calls back to [inferrer] to perform type inference for whatever concrete |
| /// type of [Expression] this is. |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext); |
| } |
| |
| /// Shadow object for [StaticInvocation] when the procedure being invoked is a |
| /// factory constructor. |
| class FactoryConstructorInvocation extends StaticInvocation |
| implements ExpressionJudgment { |
| bool hasBeenInferred = false; |
| |
| FactoryConstructorInvocation(Procedure target, Arguments arguments, |
| {bool isConst = false}) |
| : super(target, arguments, isConst: isConst); |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitFactoryConstructorInvocation(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "FactoryConstructorInvocation(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| if (isConst) { |
| printer.write('const '); |
| } else { |
| printer.write('new '); |
| } |
| printer.writeClassName(target.enclosingClass!.reference); |
| printer.writeTypeArguments(arguments.types); |
| if (target.name.text.isNotEmpty) { |
| printer.write('.'); |
| printer.write(target.name.text); |
| } |
| printer.writeArguments(arguments, includeTypeArguments: false); |
| } |
| } |
| |
| /// Shadow object for [ConstructorInvocation] when the procedure being invoked |
| /// is a type aliased constructor. |
| class TypeAliasedConstructorInvocation extends ConstructorInvocation |
| implements ExpressionJudgment { |
| bool hasBeenInferred = false; |
| final TypeAliasBuilder typeAliasBuilder; |
| |
| TypeAliasedConstructorInvocation( |
| this.typeAliasBuilder, Constructor target, Arguments arguments, |
| {bool isConst = false}) |
| : super(target, arguments, isConst: isConst); |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitTypeAliasedConstructorInvocation(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "TypeAliasedConstructorInvocation(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| if (isConst) { |
| printer.write('const '); |
| } else { |
| printer.write('new '); |
| } |
| printer.writeTypedefName(typeAliasBuilder.typedef.reference); |
| printer.writeTypeArguments(arguments.types); |
| if (target.name.text.isNotEmpty) { |
| printer.write('.'); |
| printer.write(target.name.text); |
| } |
| printer.writeArguments(arguments, includeTypeArguments: false); |
| } |
| } |
| |
| /// Shadow object for [StaticInvocation] when the procedure being invoked is a |
| /// type aliased factory constructor. |
| class TypeAliasedFactoryInvocation extends StaticInvocation |
| implements ExpressionJudgment { |
| bool hasBeenInferred = false; |
| final TypeAliasBuilder typeAliasBuilder; |
| |
| TypeAliasedFactoryInvocation( |
| this.typeAliasBuilder, Procedure target, Arguments arguments, |
| {bool isConst = false}) |
| : super(target, arguments, isConst: isConst); |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitTypeAliasedFactoryInvocation(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "TypeAliasedFactoryInvocation(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| if (isConst) { |
| printer.write('const '); |
| } else { |
| printer.write('new '); |
| } |
| printer.writeTypedefName(typeAliasBuilder.typedef.reference); |
| printer.writeTypeArguments(arguments.types); |
| if (target.name.text.isNotEmpty) { |
| printer.write('.'); |
| printer.write(target.name.text); |
| } |
| printer.writeArguments(arguments, includeTypeArguments: false); |
| } |
| } |
| |
| /// Front end specific implementation of [FunctionDeclaration]. |
| class FunctionDeclarationImpl extends FunctionDeclaration { |
| bool hasImplicitReturnType = false; |
| |
| FunctionDeclarationImpl(VariableDeclaration variable, FunctionNode function) |
| : super(variable, function); |
| |
| static void setHasImplicitReturnType( |
| FunctionDeclarationImpl declaration, bool hasImplicitReturnType) { |
| declaration.hasImplicitReturnType = hasImplicitReturnType; |
| } |
| |
| @override |
| String toString() { |
| return "FunctionDeclarationImpl(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an if-null expression. |
| /// |
| /// An if-null expression of the form `a ?? b` is encoded as: |
| /// |
| /// let v = a in v == null ? b : v |
| /// |
| class IfNullExpression extends InternalExpression { |
| Expression left; |
| Expression right; |
| |
| IfNullExpression(this.left, this.right) { |
| left.parent = this; |
| right.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIfNullExpression(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IfNullExpression(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(left, minimumPrecedence: Precedence.CONDITIONAL); |
| printer.write(' ?? '); |
| printer.writeExpression(right, |
| minimumPrecedence: Precedence.CONDITIONAL + 1); |
| } |
| } |
| |
| /// Common base class for shadow objects representing initializers in kernel |
| /// form. |
| abstract class InitializerJudgment implements AuxiliaryInitializer { |
| /// Performs type inference for whatever concrete type of |
| /// [InitializerJudgment] this is. |
| InitializerInferenceResult acceptInference(InferenceVisitorImpl visitor); |
| } |
| |
| /// Concrete shadow object representing an integer literal in kernel form. |
| class IntJudgment extends IntLiteral implements ExpressionJudgment { |
| /// The literal text of the number, as it appears in the source, which may |
| /// include digit separators (and may not be safe for parsing with |
| /// `int.parse`). |
| final String? literal; |
| |
| IntJudgment(int value, this.literal) : super(value); |
| |
| double? asDouble({bool negated = false}) { |
| if (value == 0 && negated) { |
| return -0.0; |
| } |
| BigInt intValue = new BigInt.from(negated ? -value : value); |
| double doubleValue = intValue.toDouble(); |
| return intValue == new BigInt.from(doubleValue) ? doubleValue : null; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIntJudgment(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IntJudgment(${toStringInternal()})"; |
| } |
| |
| @override |
| void toTextInternal(AstPrinter printer) { |
| if (literal == null) { |
| // Coverage-ignore-block(suite): Not run. |
| printer.write('$value'); |
| } else { |
| printer.write(literal!); |
| } |
| } |
| } |
| |
| class ShadowLargeIntLiteral extends IntLiteral implements ExpressionJudgment { |
| /// The parsable String source, stripped of any digit separators. |
| final String _strippedLiteral; |
| |
| /// The original textual source, possibly with digit separators. |
| final String literal; |
| @override |
| final int fileOffset; |
| bool isParenthesized = false; |
| |
| ShadowLargeIntLiteral(this._strippedLiteral, this.literal, this.fileOffset) |
| : super(0); |
| |
| double? asDouble({bool negated = false}) { |
| BigInt? intValue = |
| BigInt.tryParse(negated ? '-${_strippedLiteral}' : _strippedLiteral); |
| if (intValue == null) { |
| return null; |
| } |
| double doubleValue = intValue.toDouble(); |
| return !doubleValue.isNaN && |
| !doubleValue.isInfinite && |
| intValue == new BigInt.from(doubleValue) |
| ? doubleValue |
| : null; |
| } |
| |
| int? asInt64({bool negated = false}) { |
| return int.tryParse(negated ? '-${_strippedLiteral}' : _strippedLiteral); |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitShadowLargeIntLiteral(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "ShadowLargeIntLiteral(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write(literal); |
| } |
| } |
| |
| /// Concrete shadow object representing an invalid initializer in kernel form. |
| class ShadowInvalidInitializer extends LocalInitializer |
| implements InitializerJudgment { |
| ShadowInvalidInitializer(VariableDeclaration variable) : super(variable); |
| |
| @override |
| InitializerInferenceResult acceptInference(InferenceVisitorImpl visitor) { |
| return visitor.visitShadowInvalidInitializer(this); |
| } |
| |
| @override |
| String toString() { |
| return "ShadowInvalidInitializer(${toStringInternal()})"; |
| } |
| } |
| |
| /// Concrete shadow object representing an invalid initializer in kernel form. |
| class ShadowInvalidFieldInitializer extends LocalInitializer |
| implements InitializerJudgment { |
| DartType fieldType; |
| Expression value; |
| |
| ShadowInvalidFieldInitializer(this.fieldType, this.value, Expression effect) |
| : super(new VariableDeclaration.forValue(effect)) { |
| value.parent = this; |
| } |
| |
| @override |
| InitializerInferenceResult acceptInference(InferenceVisitorImpl visitor) { |
| return visitor.visitShadowInvalidFieldInitializer(this); |
| } |
| |
| @override |
| String toString() { |
| return "ShadowInvalidFieldInitializer(${toStringInternal()})"; |
| } |
| } |
| |
| class ExpressionInvocation extends InternalExpression { |
| Expression expression; |
| Arguments arguments; |
| |
| ExpressionInvocation(this.expression, this.arguments) { |
| expression.parent = this; |
| arguments.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitExpressionInvocation(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "ExpressionInvocation(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(expression); |
| printer.writeArguments(arguments); |
| } |
| } |
| |
| /// Internal expression representing a null-aware method invocation. |
| /// |
| /// A null-aware method invocation of the form `a?.b(...)` is encoded as: |
| /// |
| /// let v = a in v == null ? null : v.b(...) |
| /// |
| class NullAwareMethodInvocation extends InternalExpression { |
| /// The synthetic variable whose initializer hold the receiver. |
| VariableDeclarationImpl variable; |
| |
| /// The expression that invokes the method on [variable]. |
| Expression invocation; |
| |
| NullAwareMethodInvocation(this.variable, this.invocation) { |
| variable.parent = this; |
| invocation.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitNullAwareMethodInvocation(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "NullAwareMethodInvocation(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| Expression methodInvocation = invocation; |
| if (methodInvocation is InstanceInvocation) { |
| Expression receiver = methodInvocation.receiver; |
| if (receiver is VariableGet && receiver.variable == variable) { |
| // Special-case the usual use of this node. |
| printer.writeExpression(variable.initializer!); |
| printer.write('?.'); |
| printer.writeInterfaceMemberName( |
| methodInvocation.interfaceTargetReference, methodInvocation.name); |
| printer.writeArguments(methodInvocation.arguments); |
| return; |
| } |
| } else if (methodInvocation is DynamicInvocation) { |
| Expression receiver = methodInvocation.receiver; |
| if (receiver is VariableGet && receiver.variable == variable) { |
| // Special-case the usual use of this node. |
| printer.writeExpression(variable.initializer!); |
| printer.write('?.'); |
| printer.writeName(methodInvocation.name); |
| printer.writeArguments(methodInvocation.arguments); |
| return; |
| } |
| } |
| printer.write('let '); |
| printer.writeVariableDeclaration(variable); |
| printer.write(' in null-aware '); |
| printer.writeExpression(methodInvocation); |
| } |
| } |
| |
| /// Internal expression representing a null-aware read from a property. |
| /// |
| /// A null-aware property get of the form `a?.b` is encoded as: |
| /// |
| /// let v = a in v == null ? null : v.b |
| /// |
| class NullAwarePropertyGet extends InternalExpression { |
| /// The synthetic variable whose initializer hold the receiver. |
| VariableDeclarationImpl variable; |
| |
| /// The expression that reads the property from [variable]. |
| Expression read; |
| |
| NullAwarePropertyGet(this.variable, this.read) { |
| variable.parent = this; |
| read.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitNullAwarePropertyGet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "NullAwarePropertyGet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| Expression propertyGet = read; |
| if (propertyGet is PropertyGet) { |
| Expression receiver = propertyGet.receiver; |
| if (receiver is VariableGet && receiver.variable == variable) { |
| // Special-case the usual use of this node. |
| printer.writeExpression(variable.initializer!); |
| printer.write('?.'); |
| printer.writeName(propertyGet.name); |
| return; |
| } |
| } |
| printer.write('let '); |
| printer.writeVariableDeclaration(variable); |
| printer.write(' in null-aware '); |
| printer.writeExpression(propertyGet); |
| } |
| } |
| |
| /// Internal expression representing a null-aware read from a property. |
| /// |
| /// A null-aware property get of the form `a?.b = c` is encoded as: |
| /// |
| /// let v = a in v == null ? null : v.b = c |
| /// |
| class NullAwarePropertySet extends InternalExpression { |
| /// The synthetic variable whose initializer hold the receiver. |
| VariableDeclarationImpl variable; |
| |
| /// The expression that writes the value to the property in [variable]. |
| Expression write; |
| |
| NullAwarePropertySet(this.variable, this.write) { |
| variable.parent = this; |
| write.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitNullAwarePropertySet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "NullAwarePropertySet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| Expression propertySet = write; |
| if (propertySet is InstanceSet) { |
| Expression receiver = propertySet.receiver; |
| if (receiver is VariableGet && receiver.variable == variable) { |
| // Special-case the usual use of this node. |
| printer.writeExpression(variable.initializer!); |
| printer.write('?.'); |
| printer.writeInterfaceMemberName( |
| propertySet.interfaceTargetReference, propertySet.name); |
| printer.write(' = '); |
| printer.writeExpression(propertySet.value); |
| return; |
| } |
| } else if (propertySet is DynamicSet) { |
| Expression receiver = propertySet.receiver; |
| if (receiver is VariableGet && receiver.variable == variable) { |
| // Special-case the usual use of this node. |
| printer.writeExpression(variable.initializer!); |
| printer.write('?.'); |
| printer.writeName(propertySet.name); |
| printer.write(' = '); |
| printer.writeExpression(propertySet.value); |
| return; |
| } |
| } |
| printer.write('let '); |
| printer.writeVariableDeclaration(variable); |
| printer.write(' in null-aware '); |
| printer.writeExpression(propertySet); |
| } |
| } |
| |
| /// Front end specific implementation of [ReturnStatement]. |
| class ReturnStatementImpl extends ReturnStatement { |
| final bool isArrow; |
| |
| ReturnStatementImpl(this.isArrow, [Expression? expression]) |
| : super(expression); |
| |
| @override |
| String toString() { |
| return "ReturnStatementImpl(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| if (isArrow) { |
| printer.write('=>'); |
| } else { |
| printer.write('return'); |
| } |
| if (expression != null) { |
| printer.write(' '); |
| printer.writeExpression(expression!); |
| } |
| printer.write(';'); |
| } |
| } |
| |
| /// Front end specific implementation of [VariableDeclaration]. |
| class VariableDeclarationImpl extends VariableDeclaration { |
| final bool forSyntheticToken; |
| |
| /// Determine whether the given [VariableDeclarationImpl] had an implicit |
| /// type. |
| /// |
| /// This is static to avoid introducing a method that would be visible to |
| /// the kernel. |
| final bool isImplicitlyTyped; |
| |
| /// Determines whether the given [VariableDeclarationImpl] represents a |
| /// local function. |
| /// |
| /// This is static to avoid introducing a method that would be visible to the |
| /// kernel. |
| // TODO(ahe): Investigate if this can be removed. |
| final bool isLocalFunction; |
| |
| /// Whether the variable is final with no initializer in a null safe library. |
| /// |
| /// Such variables behave similar to those declared with the `late` keyword, |
| /// except that the don't have lazy evaluation semantics, and it is statically |
| /// verified by the front end that they are always assigned before they are |
| /// used. |
| bool isStaticLate; |
| |
| VariableDeclarationImpl(String? name, |
| {this.forSyntheticToken = false, |
| bool hasDeclaredInitializer = false, |
| Expression? initializer, |
| DartType? type, |
| bool isFinal = false, |
| bool isConst = false, |
| bool isInitializingFormal = false, |
| bool isCovariantByDeclaration = false, |
| bool isLocalFunction = false, |
| bool isLate = false, |
| bool isRequired = false, |
| bool isLowered = false, |
| bool isSynthesized = false, |
| this.isStaticLate = false, |
| bool isWildcard = false}) |
| : isImplicitlyTyped = type == null, |
| isLocalFunction = isLocalFunction, |
| super(name, |
| initializer: initializer, |
| type: type ?? const DynamicType(), |
| isFinal: isFinal, |
| isConst: isConst, |
| isInitializingFormal: isInitializingFormal, |
| isCovariantByDeclaration: isCovariantByDeclaration, |
| isLate: isLate, |
| isRequired: isRequired, |
| isLowered: isLowered, |
| isSynthesized: isSynthesized, |
| hasDeclaredInitializer: hasDeclaredInitializer, |
| isWildcard: isWildcard); |
| |
| VariableDeclarationImpl.forEffect(Expression initializer) |
| : forSyntheticToken = false, |
| isImplicitlyTyped = false, |
| isLocalFunction = false, |
| isStaticLate = false, |
| super.forValue(initializer); |
| |
| VariableDeclarationImpl.forValue(Expression initializer) |
| : forSyntheticToken = false, |
| isImplicitlyTyped = true, |
| isLocalFunction = false, |
| isStaticLate = false, |
| super.forValue(initializer); |
| |
| // The synthesized local getter function for a lowered late variable. |
| // |
| // This is set in `InferenceVisitor.visitVariableDeclaration` when late |
| // lowering is enabled. |
| VariableDeclaration? lateGetter; |
| |
| // The synthesized local setter function for an assignable lowered late |
| // variable. |
| // |
| // This is set in `InferenceVisitor.visitVariableDeclaration` when late |
| // lowering is enabled. |
| VariableDeclaration? lateSetter; |
| |
| // Is `true` if this a lowered late final variable without an initializer. |
| // |
| // This is set in `InferenceVisitor.visitVariableDeclaration` when late |
| // lowering is enabled. |
| bool isLateFinalWithoutInitializer = false; |
| |
| // The original type (declared or inferred) of a lowered late variable. |
| // |
| // This is set in `InferenceVisitor.visitVariableDeclaration` when late |
| // lowering is enabled. |
| DartType? lateType; |
| |
| // The original name of a lowered late variable. |
| // |
| // This is set in `InferenceVisitor.visitVariableDeclaration` when late |
| // lowering is enabled. |
| String? lateName; |
| |
| @override |
| bool get isAssignable { |
| if (isStaticLate) return true; |
| return super.isAssignable; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeVariableDeclaration(this, |
| isLate: isLate || lateGetter != null, type: lateType ?? type); |
| printer.write(';'); |
| } |
| |
| @override |
| String toString() { |
| return "VariableDeclarationImpl(${toStringInternal()})"; |
| } |
| } |
| |
| /// Front end specific implementation of [VariableGet]. |
| class VariableGetImpl extends VariableGet { |
| // TODO(johnniwinther): Remove the need for this by encoding all null aware |
| // expressions explicitly. |
| final bool forNullGuardedAccess; |
| |
| VariableGetImpl(VariableDeclaration variable, |
| {required this.forNullGuardedAccess}) |
| : super(variable); |
| |
| @override |
| String toString() { |
| return "VariableGetImpl(${toStringInternal()})"; |
| } |
| } |
| |
| /// Front end specific implementation of [LoadLibrary]. |
| class LoadLibraryImpl extends LoadLibrary { |
| final Arguments? arguments; |
| |
| LoadLibraryImpl(LibraryDependency import, this.arguments) : super(import); |
| |
| @override |
| String toString() { |
| return "LoadLibraryImpl(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write(import.name!); |
| printer.write('.loadLibrary'); |
| if (arguments != null) { |
| printer.writeArguments(arguments!); |
| } else { |
| printer.write('()'); |
| } |
| } |
| } |
| |
| /// Internal expression representing a tear-off of a `loadLibrary` function. |
| class LoadLibraryTearOff extends InternalExpression { |
| LibraryDependency import; |
| Procedure target; |
| |
| LoadLibraryTearOff(this.import, this.target); |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitLoadLibraryTearOff(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "LoadLibraryTearOff(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write(import.name!); |
| printer.write('.loadLibrary'); |
| } |
| } |
| |
| /// Internal expression representing an if-null property set. |
| /// |
| /// An if-null property set of the form `o.a ??= b` is, if used for value, |
| /// encoded as the expression: |
| /// |
| /// let v1 = o in let v2 = v1.a in v2 == null ? v1.a = b : v2 |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// let v1 = o in v1.a == null ? v1.a = b : null |
| /// |
| class IfNullPropertySet extends InternalExpression { |
| /// The receiver used for the read/write operations. |
| Expression receiver; |
| |
| /// Name of the property. |
| Name propertyName; |
| |
| /// The right-hand side of the binary operation. |
| Expression rhs; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| /// The file offset for the read operation. |
| final int readOffset; |
| |
| /// The file offset for the write operation. |
| final int writeOffset; |
| |
| IfNullPropertySet(this.receiver, this.propertyName, this.rhs, |
| {required this.forEffect, |
| required this.readOffset, |
| required this.writeOffset}) { |
| receiver.parent = this; |
| rhs.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIfNullPropertySet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IfNullPropertySet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver); |
| printer.write('.'); |
| printer.writeName(propertyName); |
| printer.write(' ??= '); |
| printer.writeExpression(rhs); |
| } |
| } |
| |
| /// Internal expression representing an if-null assignment. |
| /// |
| /// An if-null assignment of the form `a ??= b` is, if used for value, |
| /// encoded as the expression: |
| /// |
| /// let v1 = a in v1 == null ? a = b : v1 |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// a == null ? a = b : null |
| /// |
| class IfNullSet extends InternalExpression { |
| /// The expression that reads the property from [variable]. |
| Expression read; |
| |
| /// The expression that writes the value to the property on [variable]. |
| Expression write; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| IfNullSet(this.read, this.write, {required this.forEffect}) { |
| read.parent = this; |
| write.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIfNullSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IfNullSet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(read); |
| printer.write(' ?? '); |
| printer.writeExpression(write); |
| } |
| } |
| |
| /// Internal expression representing an compound extension assignment. |
| /// |
| /// An compound extension assignment of the form |
| /// |
| /// Extension(receiver).propertyName += rhs |
| /// |
| /// is, if used for value, encoded as the expression: |
| /// |
| /// let receiverVariable = receiver in |
| /// let valueVariable = |
| /// Extension|get#propertyName(receiverVariable) + rhs) in |
| /// let writeVariable = |
| /// Extension|set#propertyName(receiverVariable, valueVariable) in |
| /// valueVariable |
| /// |
| /// and if used for effect as: |
| /// |
| /// let receiverVariable = receiver in |
| /// Extension|set#propertyName(receiverVariable, |
| /// Extension|get#propertyName(receiverVariable) + rhs) |
| /// |
| /// If [readOnlyReceiver] is `true` the [receiverVariable] is not created |
| /// and the [receiver] is used directly. |
| class CompoundExtensionSet extends InternalExpression { |
| /// The extension in which the [setter] is declared. |
| final Extension extension; |
| |
| /// The explicit type arguments for the type parameters declared in |
| /// [extension]. |
| final List<DartType>? explicitTypeArguments; |
| |
| /// The receiver used for the read/write operations. |
| Expression receiver; |
| |
| /// The name of the property accessed by the read/write operations. |
| final Name propertyName; |
| |
| /// The member used for the read operation. |
| final Member? getter; |
| |
| /// The binary operation performed on the getter result and [rhs]. |
| final Name binaryName; |
| |
| /// The right-hand side of the binary operation. |
| Expression rhs; |
| |
| /// The member used for the write operation. |
| final Member? setter; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| /// The file offset for the read operation. |
| final int readOffset; |
| |
| /// The file offset for the binary operation. |
| final int binaryOffset; |
| |
| /// The file offset for the write operation. |
| final int writeOffset; |
| |
| CompoundExtensionSet( |
| this.extension, |
| this.explicitTypeArguments, |
| this.receiver, |
| this.propertyName, |
| this.getter, |
| this.binaryName, |
| this.rhs, |
| this.setter, |
| {required this.forEffect, |
| required this.readOffset, |
| required this.binaryOffset, |
| required this.writeOffset}) { |
| receiver.parent = this; |
| rhs.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitCompoundExtensionSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "CompoundExtensionSet(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an compound property assignment. |
| /// |
| /// An compound property assignment of the form |
| /// |
| /// receiver.propertyName += rhs |
| /// |
| /// is encoded as the expression: |
| /// |
| /// let receiverVariable = receiver in |
| /// receiverVariable.propertyName = receiverVariable.propertyName + rhs |
| /// |
| class CompoundPropertySet extends InternalExpression { |
| /// The receiver used for the read/write operations. |
| Expression receiver; |
| |
| /// The name of the property accessed by the read/write operations. |
| final Name propertyName; |
| |
| /// The binary operation performed on the getter result and [rhs]. |
| final Name binaryName; |
| |
| /// The right-hand side of the binary operation. |
| Expression rhs; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| /// The file offset for the read operation. |
| final int readOffset; |
| |
| /// The file offset for the binary operation. |
| final int binaryOffset; |
| |
| /// The file offset for the write operation. |
| final int writeOffset; |
| |
| CompoundPropertySet( |
| this.receiver, this.propertyName, this.binaryName, this.rhs, |
| {required this.forEffect, |
| required this.readOffset, |
| required this.binaryOffset, |
| required this.writeOffset}) { |
| receiver.parent = this; |
| rhs.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitCompoundPropertySet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "CompoundPropertySet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver); |
| printer.write('.'); |
| printer.writeName(propertyName); |
| printer.write(' '); |
| printer.writeName(binaryName); |
| printer.write('= '); |
| printer.writeExpression(rhs); |
| } |
| } |
| |
| /// Internal expression representing an compound property assignment. |
| /// |
| /// An compound property assignment of the form `o.a++` is encoded as the |
| /// expression: |
| /// |
| /// let v1 = o in let v2 = v1.a in let v3 = v1.a = v2 + 1 in v2 |
| /// |
| class PropertyPostIncDec extends InternalExpression { |
| /// The synthetic variable whose initializer hold the receiver. |
| /// |
| /// This is `null` if the receiver is read-only and therefore does not need to |
| /// be stored in a temporary variable. |
| VariableDeclarationImpl? variable; |
| |
| /// The expression that reads the property on [variable]. |
| VariableDeclarationImpl read; |
| |
| /// The expression that writes the result of the binary operation to the |
| /// property on [variable]. |
| VariableDeclarationImpl write; |
| |
| PropertyPostIncDec(this.variable, this.read, this.write) { |
| variable?.parent = this; |
| read.parent = this; |
| write.parent = this; |
| } |
| |
| PropertyPostIncDec.onReadOnly( |
| VariableDeclarationImpl read, VariableDeclarationImpl write) |
| : this(null, read, write); |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitPropertyPostIncDec(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "PropertyPostIncDec(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an local variable post inc/dec expression. |
| /// |
| /// An local variable post inc/dec expression of the form `a++` is encoded as |
| /// the expression: |
| /// |
| /// let v1 = a in let v2 = a = v1 + 1 in v1 |
| /// |
| class LocalPostIncDec extends InternalExpression { |
| /// The expression that reads the local variable. |
| VariableDeclarationImpl read; |
| |
| /// The expression that writes the result of the binary operation to the |
| /// local variable. |
| VariableDeclarationImpl write; |
| |
| LocalPostIncDec(this.read, this.write) { |
| read.parent = this; |
| write.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitLocalPostIncDec(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "LocalPostIncDec(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an static member post inc/dec expression. |
| /// |
| /// An local variable post inc/dec expression of the form `a++` is encoded as |
| /// the expression: |
| /// |
| /// let v1 = a in let v2 = a = v1 + 1 in v1 |
| /// |
| class StaticPostIncDec extends InternalExpression { |
| /// The expression that reads the static member. |
| VariableDeclarationImpl read; |
| |
| /// The expression that writes the result of the binary operation to the |
| /// static member. |
| VariableDeclarationImpl write; |
| |
| StaticPostIncDec(this.read, this.write) { |
| read.parent = this; |
| write.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitStaticPostIncDec(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "StaticPostIncDec(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an index get expression. |
| class IndexGet extends InternalExpression { |
| /// The receiver on which the index set operation is performed. |
| Expression receiver; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| IndexGet(this.receiver, this.index) { |
| receiver.parent = this; |
| index.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIndexGet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IndexGet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver); |
| printer.write('['); |
| printer.writeExpression(index); |
| printer.write(']'); |
| } |
| } |
| |
| /// Internal expression representing an index set expression. |
| /// |
| /// An index set expression of the form `o[a] = b` used for value is encoded as |
| /// the expression: |
| /// |
| /// let v1 = o in let v2 = a in let v3 = b in let _ = o.[]=(v2, v3) in v3 |
| /// |
| /// An index set expression used for effect is encoded as |
| /// |
| /// o.[]=(a, b) |
| /// |
| /// using [MethodInvocationImpl]. |
| /// |
| class IndexSet extends InternalExpression { |
| /// The receiver on which the index set operation is performed. |
| Expression receiver; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The value expression of the operation. |
| Expression value; |
| |
| final bool forEffect; |
| |
| IndexSet(this.receiver, this.index, this.value, {required this.forEffect}) { |
| receiver.parent = this; |
| index.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IndexSet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver); |
| printer.write('['); |
| printer.writeExpression(index); |
| printer.write('] = '); |
| printer.writeExpression(value); |
| } |
| } |
| |
| /// Internal expression representing a super index set expression. |
| /// |
| /// A super index set expression of the form `super[a] = b` used for value is |
| /// encoded as the expression: |
| /// |
| /// let v1 = a in let v2 = b in let _ = super.[]=(v1, v2) in v2 |
| /// |
| /// An index set expression used for effect is encoded as |
| /// |
| /// super.[]=(a, b) |
| /// |
| /// using [SuperMethodInvocation]. |
| /// |
| class SuperIndexSet extends InternalExpression { |
| /// The []= member. |
| Member setter; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The value expression of the operation. |
| Expression value; |
| |
| SuperIndexSet(this.setter, this.index, this.value) { |
| index.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitSuperIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "SuperIndexSet(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an extension index set expression. |
| /// |
| /// An extension index set expression of the form `Extension(o)[a] = b` used |
| /// for value is encoded as the expression: |
| /// |
| /// let receiverVariable = o |
| /// let indexVariable = a in |
| /// let valueVariable = b in ' |
| /// let writeVariable = |
| /// receiverVariable.[]=(indexVariable, valueVariable) in |
| /// valueVariable |
| /// |
| /// An extension index set expression used for effect is encoded as |
| /// |
| /// o.[]=(a, b) |
| /// |
| /// using [StaticInvocation]. |
| /// |
| class ExtensionIndexSet extends InternalExpression { |
| /// The extension in which the [setter] is declared. |
| final Extension extension; |
| |
| /// The explicit type arguments for the type parameters declared in |
| /// [extension]. |
| final List<DartType>? explicitTypeArguments; |
| |
| /// The receiver of the extension access. |
| Expression receiver; |
| |
| /// The []= member. |
| Member setter; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The value expression of the operation. |
| Expression value; |
| |
| ExtensionIndexSet(this.extension, this.explicitTypeArguments, this.receiver, |
| this.setter, this.index, this.value) |
| : assert(explicitTypeArguments == null || |
| explicitTypeArguments.length == extension.typeParameters.length) { |
| receiver.parent = this; |
| index.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitExtensionIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "ExtensionIndexSet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write(extension.name); |
| if (explicitTypeArguments != null) { |
| printer.writeTypeArguments(explicitTypeArguments!); |
| } |
| printer.write('('); |
| printer.writeExpression(receiver); |
| printer.write(')['); |
| printer.writeExpression(index); |
| printer.write('] = '); |
| printer.writeExpression(value); |
| } |
| } |
| |
| /// Internal expression representing an if-null index assignment. |
| /// |
| /// An if-null index assignment of the form `o[a] ??= b` is, if used for value, |
| /// encoded as the expression: |
| /// |
| /// let v1 = o in |
| /// let v2 = a in |
| /// let v3 = v1[v2] in |
| /// v3 == null |
| /// ? (let v4 = b in |
| /// let _ = v1.[]=(v2, v4) in |
| /// v4) |
| /// : v3 |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// let v1 = o in |
| /// let v2 = a in |
| /// let v3 = v1[v2] in |
| /// v3 == null ? v1.[]=(v2, b) : null |
| /// |
| /// If the [readOnlyReceiver] is true, no temporary variable is created for the |
| /// receiver and its use is inlined. |
| class IfNullIndexSet extends InternalExpression { |
| /// The receiver on which the index set operation is performed. |
| Expression receiver; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The value expression of the operation. |
| Expression value; |
| |
| /// The file offset for the [] operation. |
| final int readOffset; |
| |
| /// The file offset for the == operation. |
| final int testOffset; |
| |
| /// The file offset for the []= operation. |
| final int writeOffset; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| IfNullIndexSet(this.receiver, this.index, this.value, |
| {required this.readOffset, |
| required this.testOffset, |
| required this.writeOffset, |
| required this.forEffect}) { |
| receiver.parent = this; |
| index.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIfNullIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IfNullIndexSet(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an if-null super index set expression. |
| /// |
| /// An if-null super index set expression of the form `super[a] ??= b` is, if |
| /// used for value, encoded as the expression: |
| /// |
| /// let v1 = a in |
| /// let v2 = super.[](v1) in |
| /// v2 == null |
| /// ? (let v3 = b in |
| /// let _ = super.[]=(v1, v3) in |
| /// v3) |
| /// : v2 |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// let v1 = a in |
| /// let v2 = super.[](v1) in |
| /// v2 == null ? super.[]=(v1, b) : null |
| /// |
| class IfNullSuperIndexSet extends InternalExpression { |
| /// The [] member; |
| Member? getter; |
| |
| /// The []= member; |
| Member? setter; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The value expression of the operation. |
| Expression value; |
| |
| /// The file offset for the [] operation. |
| final int readOffset; |
| |
| /// The file offset for the == operation. |
| final int testOffset; |
| |
| /// The file offset for the []= operation. |
| final int writeOffset; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| IfNullSuperIndexSet(this.getter, this.setter, this.index, this.value, |
| {required this.readOffset, |
| required this.testOffset, |
| required this.writeOffset, |
| required this.forEffect}) { |
| index.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIfNullSuperIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IfNullSuperIndexSet(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an if-null super index set expression. |
| /// |
| /// An if-null super index set expression of the form `super[a] ??= b` is, if |
| /// used for value, encoded as the expression: |
| /// |
| /// let v1 = a in |
| /// let v2 = super.[](v1) in |
| /// v2 == null |
| /// ? (let v3 = b in |
| /// let _ = super.[]=(v1, v3) in |
| /// v3) |
| /// : v2 |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// let v1 = a in |
| /// let v2 = super.[](v1) in |
| /// v2 == null ? super.[]=(v1, b) : null |
| /// |
| class IfNullExtensionIndexSet extends InternalExpression { |
| final Extension extension; |
| |
| final List<DartType>? explicitTypeArguments; |
| |
| /// The extension receiver; |
| Expression receiver; |
| |
| /// The [] member; |
| Member? getter; |
| |
| /// The []= member; |
| Member? setter; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The value expression of the operation. |
| Expression value; |
| |
| /// The file offset for the [] operation. |
| final int readOffset; |
| |
| /// The file offset for the == operation. |
| final int testOffset; |
| |
| /// The file offset for the []= operation. |
| final int writeOffset; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| IfNullExtensionIndexSet(this.extension, this.explicitTypeArguments, |
| this.receiver, this.getter, this.setter, this.index, this.value, |
| {required this.readOffset, |
| required this.testOffset, |
| required this.writeOffset, |
| required this.forEffect}) |
| : assert(explicitTypeArguments == null || |
| explicitTypeArguments.length == extension.typeParameters.length) { |
| receiver.parent = this; |
| index.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitIfNullExtensionIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "IfNullExtensionIndexSet(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing a compound index assignment. |
| /// |
| /// An if-null index assignment of the form `o[a] += b` is, if used for value, |
| /// encoded as the expression: |
| /// |
| /// let v1 = o in |
| /// let v2 = a in |
| /// let v3 = v1.[](v2) + b |
| /// let v4 = v1.[]=(v2, c3) in v3 |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// let v1 = o in let v2 = a in v1.[]=(v2, v1.[](v2) + b) |
| /// |
| class CompoundIndexSet extends InternalExpression { |
| /// The receiver on which the index set operation is performed. |
| Expression receiver; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The name of the binary operation. |
| Name binaryName; |
| |
| /// The right-hand side of the binary expression. |
| Expression rhs; |
| |
| /// The file offset for the [] operation. |
| final int readOffset; |
| |
| /// The file offset for the []= operation. |
| final int writeOffset; |
| |
| /// The file offset for the binary operation. |
| final int binaryOffset; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| /// If `true`, the expression is a post-fix inc/dec expression. |
| final bool forPostIncDec; |
| |
| CompoundIndexSet(this.receiver, this.index, this.binaryName, this.rhs, |
| {required this.readOffset, |
| required this.binaryOffset, |
| required this.writeOffset, |
| required this.forEffect, |
| required this.forPostIncDec}) { |
| receiver.parent = this; |
| index.parent = this; |
| rhs.parent = this; |
| fileOffset = binaryOffset; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitCompoundIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "CompoundIndexSet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver); |
| printer.write('['); |
| printer.writeExpression(index); |
| printer.write(']'); |
| if (forPostIncDec && |
| (binaryName.text == '+' || binaryName.text == '-') && |
| rhs is IntLiteral && |
| (rhs as IntLiteral).value == 1) { |
| if (binaryName.text == '+') { |
| printer.write('++'); |
| } else { |
| printer.write('--'); |
| } |
| } else { |
| printer.write(' '); |
| printer.write(binaryName.text); |
| printer.write('= '); |
| printer.writeExpression(rhs); |
| } |
| } |
| } |
| |
| /// Internal expression representing a null-aware compound assignment. |
| /// |
| /// A null-aware compound assignment of the form |
| /// |
| /// receiver?.property binaryName= rhs |
| /// |
| /// is, if used for value as a normal compound or prefix operation, encoded as |
| /// the expression: |
| /// |
| /// let receiverVariable = receiver in |
| /// receiverVariable == null ? null : |
| /// let leftVariable = receiverVariable.propertyName in |
| /// let valueVariable = leftVariable binaryName rhs in |
| /// let writeVariable = |
| /// receiverVariable.propertyName = valueVariable in |
| /// valueVariable |
| /// |
| /// and, if used for value as a postfix operation, encoded as |
| /// |
| /// let receiverVariable = receiver in |
| /// receiverVariable == null ? null : |
| /// let leftVariable = receiverVariable.propertyName in |
| /// let writeVariable = |
| /// receiverVariable.propertyName = |
| /// leftVariable binaryName rhs in |
| /// leftVariable |
| /// |
| /// and, if used for effect, encoded as: |
| /// |
| /// let receiverVariable = receiver in |
| /// receiverVariable == null ? null : |
| /// receiverVariable.propertyName = receiverVariable.propertyName + rhs |
| /// |
| class NullAwareCompoundSet extends InternalExpression { |
| /// The receiver on which the null aware operation is performed. |
| Expression receiver; |
| |
| /// The name of the null-aware property. |
| Name propertyName; |
| |
| /// The name of the binary operation. |
| Name binaryName; |
| |
| /// The right-hand side of the binary expression. |
| Expression rhs; |
| |
| /// The file offset for the read operation. |
| final int readOffset; |
| |
| /// The file offset for the write operation. |
| final int writeOffset; |
| |
| /// The file offset for the binary operation. |
| final int binaryOffset; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| /// If `true`, the expression is a postfix inc/dec expression. |
| final bool forPostIncDec; |
| |
| NullAwareCompoundSet( |
| this.receiver, this.propertyName, this.binaryName, this.rhs, |
| {required this.readOffset, |
| required this.binaryOffset, |
| required this.writeOffset, |
| required this.forEffect, |
| required this.forPostIncDec}) { |
| receiver.parent = this; |
| rhs.parent = this; |
| fileOffset = binaryOffset; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitNullAwareCompoundSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "NullAwareCompoundSet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver); |
| printer.write('?.'); |
| printer.writeName(propertyName); |
| if (forPostIncDec && |
| rhs is IntLiteral && |
| (rhs as IntLiteral).value == 1 && |
| (binaryName == plusName || binaryName == minusName)) { |
| if (binaryName == plusName) { |
| printer.write('++'); |
| } else { |
| printer.write('--'); |
| } |
| } else { |
| printer.write(' '); |
| printer.writeName(binaryName); |
| printer.write('= '); |
| printer.writeExpression(rhs); |
| } |
| } |
| } |
| |
| /// Internal expression representing an null-aware if-null property set. |
| /// |
| /// A null-aware if-null property set of the form |
| /// |
| /// receiver?.name ??= value |
| /// |
| /// is, if used for value, encoded as the expression: |
| /// |
| /// let receiverVariable = receiver in |
| /// receiverVariable == null ? null : |
| /// (let readVariable = receiverVariable.name in |
| /// readVariable == null ? |
| /// receiverVariable.name = value : readVariable) |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// let receiverVariable = receiver in |
| /// receiverVariable == null ? null : |
| /// (receiverVariable.name == null ? |
| /// receiverVariable.name = value : null) |
| /// |
| /// |
| class NullAwareIfNullSet extends InternalExpression { |
| /// The synthetic variable whose initializer hold the receiver. |
| Expression receiver; |
| |
| /// The expression that reads the property from [variable]. |
| Name name; |
| |
| /// The expression that writes the value to the property on [variable]. |
| Expression value; |
| |
| /// The file offset for the read operation. |
| final int readOffset; |
| |
| /// The file offset for the write operation. |
| final int writeOffset; |
| |
| /// The file offset for the == operation. |
| final int testOffset; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| NullAwareIfNullSet(this.receiver, this.name, this.value, |
| {required this.readOffset, |
| required this.writeOffset, |
| required this.testOffset, |
| required this.forEffect}) { |
| receiver.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitNullAwareIfNullSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "NullAwareIfNullSet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver); |
| printer.write('?.'); |
| printer.writeName(name); |
| printer.write(' ??= '); |
| printer.writeExpression(value); |
| } |
| } |
| |
| /// Internal expression representing a compound super index assignment. |
| /// |
| /// An if-null index assignment of the form `super[a] += b` is, if used for |
| /// value, encoded as the expression: |
| /// |
| /// let v1 = a in |
| /// let v2 = super.[](v1) + b |
| /// let v3 = super.[]=(v1, v2) in v2 |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// let v1 = a in super.[]=(v2, super.[](v2) + b) |
| /// |
| class CompoundSuperIndexSet extends InternalExpression { |
| /// The [] member. |
| Member getter; |
| |
| /// The []= member. |
| Member setter; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The name of the binary operation. |
| Name binaryName; |
| |
| /// The right-hand side of the binary expression. |
| Expression rhs; |
| |
| /// The file offset for the [] operation. |
| final int readOffset; |
| |
| /// The file offset for the []= operation. |
| final int writeOffset; |
| |
| /// The file offset for the binary operation. |
| final int binaryOffset; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| /// If `true`, the expression is a post-fix inc/dec expression. |
| final bool forPostIncDec; |
| |
| CompoundSuperIndexSet( |
| this.getter, this.setter, this.index, this.binaryName, this.rhs, |
| {required this.readOffset, |
| required this.binaryOffset, |
| required this.writeOffset, |
| required this.forEffect, |
| required this.forPostIncDec}) { |
| index.parent = this; |
| rhs.parent = this; |
| fileOffset = binaryOffset; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitCompoundSuperIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "CompoundSuperIndexSet(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing a compound extension index assignment. |
| /// |
| /// An compound extension index assignment of the form `Extension(o)[a] += b` |
| /// is, if used for value, encoded as the expression: |
| /// |
| /// let receiverVariable = o; |
| /// let indexVariable = a in |
| /// let valueVariable = receiverVariable.[](indexVariable) + b |
| /// let writeVariable = |
| /// receiverVariable.[]=(indexVariable, valueVariable) in |
| /// valueVariable |
| /// |
| /// and, if used for effect, encoded as the expression: |
| /// |
| /// let receiverVariable = o; |
| /// let indexVariable = a in |
| /// receiverVariable.[]=(indexVariable, |
| /// receiverVariable.[](indexVariable) + b) |
| /// |
| class CompoundExtensionIndexSet extends InternalExpression { |
| final Extension extension; |
| |
| final List<DartType>? explicitTypeArguments; |
| |
| Expression receiver; |
| |
| /// The [] member. |
| Member? getter; |
| |
| /// The []= member. |
| Member? setter; |
| |
| /// The index expression of the operation. |
| Expression index; |
| |
| /// The name of the binary operation. |
| Name binaryName; |
| |
| /// The right-hand side of the binary expression. |
| Expression rhs; |
| |
| /// The file offset for the [] operation. |
| final int readOffset; |
| |
| /// The file offset for the []= operation. |
| final int writeOffset; |
| |
| /// The file offset for the binary operation. |
| final int binaryOffset; |
| |
| /// If `true`, the expression is only need for effect and not for its value. |
| final bool forEffect; |
| |
| /// If `true`, the expression is a post-fix inc/dec expression. |
| final bool forPostIncDec; |
| |
| CompoundExtensionIndexSet( |
| this.extension, |
| this.explicitTypeArguments, |
| this.receiver, |
| this.getter, |
| this.setter, |
| this.index, |
| this.binaryName, |
| this.rhs, |
| {required this.readOffset, |
| required this.binaryOffset, |
| required this.writeOffset, |
| required this.forEffect, |
| required this.forPostIncDec}) |
| : assert(explicitTypeArguments == null || |
| explicitTypeArguments.length == extension.typeParameters.length) { |
| receiver.parent = this; |
| index.parent = this; |
| rhs.parent = this; |
| fileOffset = binaryOffset; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitCompoundExtensionIndexSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "CompoundExtensionIndexSet(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an assignment to an extension setter. |
| /// |
| /// An extension set of the form `receiver.target = value` is, if used for |
| /// value, encoded as the expression: |
| /// |
| /// let receiverVariable = receiver in |
| /// let valueVariable = value in |
| /// let writeVariable = target(receiverVariable, valueVariable) in |
| /// valueVariable |
| /// |
| /// or if the receiver is read-only, like `this` or a final variable, |
| /// |
| /// let valueVariable = value in |
| /// let writeVariable = target(receiver, valueVariable) in |
| /// valueVariable |
| /// |
| /// and, if used for effect, encoded as a [StaticInvocation]: |
| /// |
| /// target(receiver, value) |
| /// |
| // TODO(johnniwinther): Rename read-only to side-effect-free. |
| class ExtensionSet extends InternalExpression { |
| final Extension extension; |
| |
| final List<DartType>? explicitTypeArguments; |
| |
| /// The receiver for the assignment. |
| Expression receiver; |
| |
| /// The extension member called for the assignment. |
| Procedure target; |
| |
| /// The right-hand side value of the assignment. |
| Expression value; |
| |
| /// If `true` the assignment is only needed for effect and not its result |
| /// value. |
| final bool forEffect; |
| |
| ExtensionSet(this.extension, this.explicitTypeArguments, this.receiver, |
| this.target, this.value, {required this.forEffect}) |
| : assert(explicitTypeArguments == null || |
| explicitTypeArguments.length == extension.typeParameters.length) { |
| receiver.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitExtensionSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "ExtensionSet(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression representing an null-aware extension expression. |
| /// |
| /// An null-aware extension expression of the form `Extension(receiver)?.target` |
| /// is encoded as the expression: |
| /// |
| /// let variable = receiver in |
| /// variable == null ? null : expression |
| /// |
| /// where `expression` is an encoding of `receiverVariable.target`. |
| class NullAwareExtension extends InternalExpression { |
| VariableDeclarationImpl variable; |
| Expression expression; |
| |
| NullAwareExtension(this.variable, this.expression) { |
| variable.parent = this; |
| expression.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitNullAwareExtension(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "NullAwareExtension(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal representation of a read of an extension instance member. |
| /// |
| /// A read of an extension instance member `o.foo` is encoded as the |
| /// [StaticInvocation] |
| /// |
| /// extension|foo(o) |
| /// |
| /// where `extension|foo` is the top level method created for reading the |
| /// `foo` member. If `foo` is an extension instance method, then `extension|foo` |
| /// the special tear-off function created for extension instance methods. |
| /// Otherwise `extension|foo` is the top level method corresponding to the |
| /// extension instance getter being read. |
| class ExtensionTearOff extends InternalExpression { |
| /// The top-level method that is that target for the read operation. |
| Procedure target; |
| |
| /// The arguments provided to the top-level method. |
| Arguments arguments; |
| |
| ExtensionTearOff(this.target, this.arguments) { |
| arguments.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitExtensionTearOff(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "ExtensionTearOff(${toStringInternal()})"; |
| } |
| } |
| |
| /// Internal expression for an equals or not-equals expression. |
| class EqualsExpression extends InternalExpression { |
| Expression left; |
| Expression right; |
| bool isNot; |
| |
| EqualsExpression(this.left, this.right, {required this.isNot}) { |
| left.parent = this; |
| right.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitEquals(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "EqualsExpression(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(left, minimumPrecedence: Precedence.EQUALITY); |
| if (isNot) { |
| printer.write(' != '); |
| } else { |
| printer.write(' == '); |
| } |
| printer.writeExpression(right, minimumPrecedence: Precedence.EQUALITY + 1); |
| } |
| } |
| |
| /// Internal expression for a binary expression. |
| class BinaryExpression extends InternalExpression { |
| Expression left; |
| Name binaryName; |
| Expression right; |
| |
| BinaryExpression(this.left, this.binaryName, this.right) { |
| left.parent = this; |
| right.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitBinary(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "BinaryExpression(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| int get precedence => Precedence.binaryPrecedence[binaryName.text]!; |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(left, minimumPrecedence: precedence); |
| printer.write(' ${binaryName.text} '); |
| printer.writeExpression(right, minimumPrecedence: precedence); |
| } |
| } |
| |
| /// Internal expression for a unary expression. |
| class UnaryExpression extends InternalExpression { |
| Name unaryName; |
| Expression expression; |
| |
| UnaryExpression(this.unaryName, this.expression) { |
| expression.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitUnary(this, typeContext); |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| int get precedence => Precedence.PREFIX; |
| |
| @override |
| String toString() { |
| return "UnaryExpression(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| if (unaryName == unaryMinusName) { |
| printer.write('-'); |
| } else { |
| printer.write('${unaryName.text}'); |
| } |
| printer.writeExpression(expression, minimumPrecedence: precedence); |
| } |
| } |
| |
| /// Internal expression for a parenthesized expression. |
| class ParenthesizedExpression extends InternalExpression { |
| Expression expression; |
| |
| ParenthesizedExpression(this.expression) { |
| expression.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitParenthesized(this, typeContext); |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| int get precedence => Precedence.CALLEE; |
| |
| @override |
| String toString() { |
| return "ParenthesizedExpression(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write('('); |
| printer.writeExpression(expression); |
| printer.write(')'); |
| } |
| } |
| |
| /// Returns `true` if [node] is a pure expression. |
| /// |
| /// A pure expression is an expression that is deterministic and side effect |
| /// free, such as `this` or a variable get of a final variable. |
| bool isPureExpression(Expression node) { |
| if (node is ThisExpression) { |
| return true; |
| } else if (node is VariableGet) { |
| return node.variable.isFinal && !node.variable.isLate; |
| } |
| return false; |
| } |
| |
| /// Returns a clone of [node]. |
| /// |
| /// This assumes that `isPureExpression(node)` is `true`. |
| Expression clonePureExpression(Expression node) { |
| if (node is ThisExpression) { |
| return new ThisExpression()..fileOffset = node.fileOffset; |
| } else if (node is VariableGet) { |
| assert( |
| node.variable.isFinal && !node.variable.isLate, |
| // Coverage-ignore(suite): Not run. |
| "Trying to clone VariableGet of non-final variable" |
| " ${node.variable}."); |
| return new VariableGet(node.variable, node.promotedType) |
| ..fileOffset = node.fileOffset; |
| } |
| // Coverage-ignore-block(suite): Not run. |
| throw new UnsupportedError("Clone not supported for ${node.runtimeType}."); |
| } |
| |
| /// A dynamically bound method invocation of the form `o.foo()`. |
| /// |
| /// This will be transformed into an [InstanceInvocation], [DynamicInvocation], |
| /// [FunctionInvocation] or [StaticInvocation] (for implicit extension method |
| /// invocation) after type inference. |
| class MethodInvocation extends InternalExpression { |
| Expression receiver; |
| |
| Name name; |
| |
| Arguments arguments; |
| |
| MethodInvocation(this.receiver, this.name, this.arguments) { |
| receiver.parent = this; |
| arguments.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitMethodInvocation(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "MethodInvocation(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| int get precedence => Precedence.PRIMARY; |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver, minimumPrecedence: Precedence.PRIMARY); |
| printer.write('.'); |
| printer.writeName(name); |
| printer.writeArguments(arguments); |
| } |
| } |
| |
| /// A dynamically bound property read of the form `o.foo`. |
| /// |
| /// This will be transformed into an [InstanceGet], [InstanceTearOff], |
| /// [DynamicGet], [FunctionTearOff] or [StaticInvocation] (for implicit |
| /// extension member access) after type inference. |
| class PropertyGet extends InternalExpression { |
| Expression receiver; |
| |
| Name name; |
| |
| PropertyGet(this.receiver, this.name) { |
| receiver.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitPropertyGet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "PropertyGet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| int get precedence => Precedence.PRIMARY; |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver, minimumPrecedence: Precedence.PRIMARY); |
| printer.write('.'); |
| printer.writeName(name); |
| } |
| } |
| |
| /// A dynamically bound property write of the form `o.foo = e`. |
| /// |
| /// This will be transformed into an [InstanceSet], [DynamicSet], or |
| /// [StaticInvocation] (for implicit extension member access) after type |
| /// inference. |
| class PropertySet extends InternalExpression { |
| Expression receiver; |
| Name name; |
| Expression value; |
| |
| /// If `true` the assignment is need for its effect and not for its value. |
| final bool forEffect; |
| |
| /// If `true` the receiver can be cloned and doesn't need a temporary variable |
| /// for multiple reads. |
| final bool readOnlyReceiver; |
| |
| PropertySet(this.receiver, this.name, this.value, |
| {required this.forEffect, required this.readOnlyReceiver}) { |
| receiver.parent = this; |
| value.parent = this; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitPropertySet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "PropertySet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeExpression(receiver, minimumPrecedence: Precedence.PRIMARY); |
| printer.write('.'); |
| printer.writeName(name); |
| printer.write(' = '); |
| printer.writeExpression(value); |
| } |
| } |
| |
| /// An augment super invocation of the form `augment super()`. |
| /// |
| /// This will be transformed into an [InstanceInvocation], [InstanceGet] plus |
| /// [FunctionInvocation], or [StaticInvocation] after type inference. |
| class AugmentSuperInvocation extends InternalExpression { |
| final Member target; |
| |
| Arguments arguments; |
| |
| AugmentSuperInvocation(this.target, this.arguments, |
| {required int fileOffset}) { |
| arguments.parent = this; |
| this.fileOffset = fileOffset; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitAugmentSuperInvocation(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "AugmentSuperInvocation(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| int get precedence => Precedence.PRIMARY; |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write('augment super'); |
| printer.writeArguments(arguments); |
| } |
| } |
| |
| /// An augment super read of the form `augment super`. |
| /// |
| /// This will be transformed into an [InstanceGet], [InstanceTearOff], |
| /// [DynamicGet], [FunctionTearOff] or [StaticInvocation] (for implicit |
| /// extension member access) after type inference. |
| class AugmentSuperGet extends InternalExpression { |
| final Member target; |
| |
| AugmentSuperGet(this.target, {required int fileOffset}) { |
| this.fileOffset = fileOffset; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitAugmentSuperGet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "AugmentSuperGet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| int get precedence => Precedence.PRIMARY; |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write('augment super'); |
| } |
| } |
| |
| /// An augment super write of the form `augment super = e`. |
| /// |
| /// This will be transformed into an [InstanceSet], or [StaticSet] after type |
| /// inference. |
| class AugmentSuperSet extends InternalExpression { |
| final Member target; |
| |
| Expression value; |
| |
| /// If `true` the assignment is need for its effect and not for its value. |
| final bool forEffect; |
| |
| AugmentSuperSet(this.target, this.value, |
| {required this.forEffect, required int fileOffset}) { |
| value.parent = this; |
| this.fileOffset = fileOffset; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitAugmentSuperSet(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "AugmentSuperSet(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write('augment super = '); |
| printer.writeExpression(value); |
| } |
| } |
| |
| class InternalRecordLiteral extends InternalExpression { |
| final List<Expression> positional; |
| final List<NamedExpression> named; |
| final Map<String, NamedExpression>? namedElements; |
| final List<Object /*Expression|NamedExpression*/ > originalElementOrder; |
| final bool isConst; |
| |
| InternalRecordLiteral(this.positional, this.named, this.namedElements, |
| this.originalElementOrder, |
| {required this.isConst, required int offset}) { |
| fileOffset = offset; |
| } |
| |
| @override |
| ExpressionInferenceResult acceptInference( |
| InferenceVisitorImpl visitor, DartType typeContext) { |
| return visitor.visitInternalRecordLiteral(this, typeContext); |
| } |
| |
| @override |
| String toString() { |
| return "InternalRecordLiteral(${toStringInternal()})"; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| if (isConst) { |
| printer.write('const '); |
| } |
| printer.write('('); |
| String comma = ''; |
| for (Object element in originalElementOrder) { |
| printer.write(comma); |
| if (element is NamedExpression) { |
| printer.write(element.name); |
| printer.write(': '); |
| printer.writeExpression(element.value); |
| } else { |
| printer.writeExpression(element as Expression); |
| } |
| comma = ', '; |
| } |
| printer.write(')'); |
| } |
| } |
| |
| /// Data structure used by the body builder in place of [ObjectPattern], to |
| /// allow additional information to be captured that is needed during type |
| /// inference. |
| class ObjectPatternInternal extends ObjectPattern { |
| /// If the type name in the object pattern refers to a typedef, the typedef in |
| /// question; otherwise `null`. |
| final Typedef? typedef; |
| |
| /// Indicates whether the object pattern included explicit type arguments; if |
| /// `true` this means that no further type inference needs to be performed. |
| final bool hasExplicitTypeArguments; |
| |
| ObjectPatternInternal(super.requiredType, super.fields, this.typedef, |
| {required this.hasExplicitTypeArguments}); |
| } |
| |
| class ExtensionTypeRedirectingInitializer extends InternalInitializer { |
| Reference targetReference; |
| Arguments arguments; |
| |
| ExtensionTypeRedirectingInitializer(Procedure target, Arguments arguments) |
| : this.byReference( |
| // Getter vs setter doesn't matter for procedures. |
| getNonNullableMemberReferenceGetter(target), |
| arguments); |
| |
| ExtensionTypeRedirectingInitializer.byReference( |
| this.targetReference, this.arguments) { |
| arguments.parent = this; |
| } |
| |
| Procedure get target => targetReference.asProcedure; |
| |
| // Coverage-ignore(suite): Not run. |
| void set target(Procedure target) { |
| // Getter vs setter doesn't matter for procedures. |
| targetReference = getNonNullableMemberReferenceGetter(target); |
| } |
| |
| @override |
| InitializerInferenceResult acceptInference(InferenceVisitorImpl visitor) { |
| return visitor.visitExtensionTypeRedirectingInitializer(this); |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.write('this'); |
| if (target.name.text.isNotEmpty) { |
| printer.write('.'); |
| printer.write(target.name.text); |
| } |
| printer.writeArguments(arguments, includeTypeArguments: false); |
| } |
| |
| @override |
| String toString() => |
| 'ExtensionTypeRedirectingInitializer(${toStringInternal()})'; |
| } |
| |
| /// Internal expression for an explicit initialization of an extension type |
| /// declaration representation field. |
| class ExtensionTypeRepresentationFieldInitializer extends InternalInitializer { |
| Reference fieldReference; |
| Expression value; |
| |
| ExtensionTypeRepresentationFieldInitializer(Procedure field, this.value) |
| : assert(field.stubKind == ProcedureStubKind.RepresentationField), |
| this.fieldReference = field.reference { |
| value.parent = this; |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void transformChildren(Transformer v) { |
| value = v.transform(value)..parent = this; |
| } |
| |
| /// [Procedure] that represents the representation field. |
| Procedure get field => fieldReference.asProcedure; |
| |
| @override |
| InitializerInferenceResult acceptInference(InferenceVisitorImpl visitor) { |
| return visitor.visitExtensionTypeRepresentationFieldInitializer(this); |
| } |
| |
| @override |
| // Coverage-ignore(suite): Not run. |
| void toTextInternal(AstPrinter printer) { |
| printer.writeMemberName(fieldReference); |
| printer.write(" = "); |
| printer.writeExpression(value); |
| } |
| |
| @override |
| String toString() => |
| 'ExtensionTypeRepresentationFieldInitializer(${toStringInternal()})'; |
| } |