| Index: pkg/compiler/lib/src/resolution/semantic_visitor.dart
|
| diff --git a/pkg/compiler/lib/src/resolution/semantic_visitor.dart b/pkg/compiler/lib/src/resolution/semantic_visitor.dart
|
| index 3957d1d84d77d251ec5e8c62522653785cc6a2bb..90c628e4cd25856fd07f72ed5bbbcddfe822da34 100644
|
| --- a/pkg/compiler/lib/src/resolution/semantic_visitor.dart
|
| +++ b/pkg/compiler/lib/src/resolution/semantic_visitor.dart
|
| @@ -20,11 +20,10 @@ import 'send_structure.dart';
|
| part 'semantic_visitor_mixins.dart';
|
| part 'send_resolver.dart';
|
|
|
| -abstract class SemanticVisitor<R, A> extends Visitor<R>
|
| - with SendResolverMixin {
|
| - TreeElements elements;
|
| -
|
| - SemanticVisitor(this.elements);
|
| +/// Mixin that couples a [SendResolverMixin] to a [SemanticSendVisitor] in a
|
| +/// [Visitor].
|
| +abstract class SemanticSendResolvedMixin<R, A>
|
| + implements Visitor<R>, SendResolverMixin {
|
|
|
| SemanticSendVisitor<R, A> get sendVisitor;
|
|
|
| @@ -72,6 +71,79 @@ abstract class SemanticVisitor<R, A> extends Visitor<R>
|
| }
|
| }
|
|
|
| +/// Mixin that couples a [DeclResolverMixin] to a [SemanticDeclVisitor] in a
|
| +/// [Visitor].
|
| +abstract class SemanticDeclResolvedMixin<R, A>
|
| + implements Visitor<R>, DeclResolverMixin {
|
| +
|
| + SemanticDeclVisitor<R, A> get declVisitor;
|
| +
|
| + @override
|
| + R visitFunctionExpression(FunctionExpression node) {
|
| + // TODO(johnniwinther): Support argument.
|
| + A arg = null;
|
| +
|
| + DeclStructure structure = computeFunctionStructure(node);
|
| + if (structure == null) {
|
| + return internalError(node, 'No structure for $node');
|
| + } else {
|
| + return structure.dispatch(declVisitor, node, arg);
|
| + }
|
| + }
|
| +
|
| + visitInitializers(NodeList initializers, A arg) {
|
| + if (initializers != null) {
|
| + for (Node node in initializers) {
|
| + InitializerStructure structure = computeInitializerStructure(node);
|
| + if (structure == null) {
|
| + return internalError(node, 'No structure for $node');
|
| + } else {
|
| + return structure.dispatch(declVisitor, node, arg);
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + visitParameters(NodeList parameters, A arg) {
|
| + computeParameterStructures(
|
| + parameters,
|
| + (VariableDefinitions definitions, ParameterStructure structure) {
|
| + if (structure == null) {
|
| + return internalError(definitions, 'No structure for $definitions');
|
| + } else {
|
| + return structure.dispatch(declVisitor, definitions, arg);
|
| + }
|
| + });
|
| + }
|
| +
|
| + @override
|
| + R visitVariableDefinitions(VariableDefinitions definitions) {
|
| + // TODO(johnniwinther): Support argument.
|
| + A arg = null;
|
| +
|
| + computeVariableStructures(
|
| + definitions,
|
| + (Node node, VariableStructure structure) {
|
| + if (structure == null) {
|
| + return internalError(node, 'No structure for $node');
|
| + } else {
|
| + return structure.dispatch(declVisitor, node, arg);
|
| + }
|
| + });
|
| + return null;
|
| + }
|
| +}
|
| +
|
| +abstract class SemanticVisitor<R, A> extends Visitor<R>
|
| + with SemanticSendResolvedMixin<R, A>,
|
| + SendResolverMixin,
|
| + SemanticDeclResolvedMixin<R, A>,
|
| + DeclResolverMixin {
|
| + TreeElements elements;
|
| +
|
| + SemanticVisitor(this.elements);
|
| +}
|
| +
|
| // TODO(johnniwinther): Add visits for [visitLocalConstantGet],
|
| // [visitLocalConstantInvoke], [visitStaticConstantGet], etc.
|
| abstract class SemanticSendVisitor<R, A> {
|
| @@ -2945,3 +3017,552 @@ abstract class SemanticSendVisitor<R, A> {
|
| Selector selector,
|
| A arg);
|
| }
|
| +
|
| +abstract class SemanticDeclVisitor<R, A> {
|
| + R apply(Node node, A arg);
|
| +
|
| + /// Apply this visitor to the [parameters].
|
| + applyParameters(NodeList parameters, A arg);
|
| +
|
| + /// Apply this visitor to the constructor [initializers].
|
| + applyInitializers(NodeList initializers, A arg);
|
| +
|
| + /// A declaration of a top level [getter].
|
| + ///
|
| + /// For instance
|
| + /// get m => 42;
|
| + ///
|
| + R visitTopLevelGetterDecl(
|
| + FunctionExpression node,
|
| + MethodElement getter,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a top level [setter].
|
| + ///
|
| + /// For instance
|
| + /// set m(a) {}
|
| + ///
|
| + R visitTopLevelSetterDecl(
|
| + FunctionExpression node,
|
| + MethodElement setter,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a top level [function].
|
| + ///
|
| + /// For instance
|
| + /// m(a) {}
|
| + ///
|
| + R visitTopLevelFunctionDecl(
|
| + FunctionExpression node,
|
| + MethodElement function,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a static [getter].
|
| + ///
|
| + /// For instance
|
| + /// class C {
|
| + /// static get m => 42;
|
| + /// }
|
| + ///
|
| + R visitStaticGetterDecl(
|
| + FunctionExpression node,
|
| + MethodElement getter,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a static [setter].
|
| + ///
|
| + /// For instance
|
| + /// class C {
|
| + /// static set m(a) {}
|
| + /// }
|
| + ///
|
| + R visitStaticSetterDecl(
|
| + FunctionExpression node,
|
| + MethodElement setter,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a static [function].
|
| + ///
|
| + /// For instance
|
| + /// class C {
|
| + /// static m(a) {}
|
| + /// }
|
| + ///
|
| + R visitStaticFunctionDecl(
|
| + FunctionExpression node,
|
| + MethodElement function,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of an abstract instance [getter].
|
| + ///
|
| + /// For instance
|
| + /// abstract class C {
|
| + /// get m;
|
| + /// }
|
| + ///
|
| + R visitAbstractGetterDecl(
|
| + FunctionExpression node,
|
| + MethodElement getter,
|
| + A arg);
|
| +
|
| + /// A declaration of an abstract instance [setter].
|
| + ///
|
| + /// For instance
|
| + /// abstract class C {
|
| + /// set m(a);
|
| + /// }
|
| + ///
|
| + R visitAbstractSetterDecl(
|
| + FunctionExpression node,
|
| + MethodElement setter,
|
| + NodeList parameters,
|
| + A arg);
|
| +
|
| + /// A declaration of an abstract instance [method].
|
| + ///
|
| + /// For instance
|
| + /// abstract class C {
|
| + /// m(a);
|
| + /// }
|
| + ///
|
| + R visitAbstractMethodDecl(
|
| + FunctionExpression node,
|
| + MethodElement method,
|
| + NodeList parameters,
|
| + A arg);
|
| +
|
| + /// A declaration of an instance [getter].
|
| + ///
|
| + /// For instance
|
| + /// class C {
|
| + /// get m => 42;
|
| + /// }
|
| + ///
|
| + R visitInstanceGetterDecl(
|
| + FunctionExpression node,
|
| + MethodElement getter,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of an instance [setter].
|
| + ///
|
| + /// For instance
|
| + /// class C {
|
| + /// set m(a) {}
|
| + /// }
|
| + ///
|
| + R visitInstanceSetterDecl(
|
| + FunctionExpression node,
|
| + MethodElement setter,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of an instance [method].
|
| + ///
|
| + /// For instance
|
| + /// class C {
|
| + /// m(a) {}
|
| + /// }
|
| + ///
|
| + R visitInstanceMethodDecl(
|
| + FunctionExpression node,
|
| + MethodElement method,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a local [function].
|
| + ///
|
| + /// For instance `local` in
|
| + /// m() {
|
| + /// local(a) {}
|
| + /// }
|
| + ///
|
| + R visitLocalFunctionDecl(
|
| + FunctionExpression node,
|
| + LocalFunctionElement function,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a [closure].
|
| + ///
|
| + /// For instance `(a) {}` in
|
| + /// m() {
|
| + /// var closure = (a) {};
|
| + /// }
|
| + ///
|
| + R visitClosureDecl(
|
| + FunctionExpression node,
|
| + LocalFunctionElement closure,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of the [index]th [parameter] in a constructor, setter,
|
| + /// method or function.
|
| + ///
|
| + /// For instance `a` in
|
| + /// m(a) {}
|
| + ///
|
| + R visitParameterDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + ParameterElement parameter,
|
| + int index,
|
| + A arg);
|
| +
|
| + /// A declaration of the [index]th optional [parameter] in a constructor,
|
| + /// method or function with the explicit [defaultValue]. If no default value
|
| + /// is declared, [defaultValue] is `null`.
|
| + ///
|
| + /// For instance `a` in
|
| + /// m([a = 42]) {}
|
| + ///
|
| + R visitOptionalParameterDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + ParameterElement parameter,
|
| + ConstantExpression defaultValue,
|
| + int index,
|
| + A arg);
|
| +
|
| + /// A declaration of a named [parameter] in a constructor, method or function
|
| + /// with the explicit [defaultValue]. If no default value is declared,
|
| + /// [defaultValue] is `null`.
|
| + ///
|
| + /// For instance `a` in
|
| + /// m({a: 42}) {}
|
| + ///
|
| + R visitNamedParameterDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + ParameterElement parameter,
|
| + ConstantExpression defaultValue,
|
| + A arg);
|
| +
|
| + /// A declaration of the [index]th [parameter] as an initializing formal in a
|
| + /// constructor.
|
| + ///
|
| + /// For instance `a` in
|
| + /// class C {
|
| + /// var a;
|
| + /// C(this.a);
|
| + /// }
|
| + ///
|
| + R visitInitializingFormalDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + InitializingFormalElement parameter,
|
| + int index,
|
| + A arg);
|
| +
|
| + /// A declaration of the [index]th optional [parameter] as an initializing
|
| + /// formal in a constructor with the explicit [defaultValue]. If no default
|
| + /// value is declared, [defaultValue] is `null`.
|
| + ///
|
| + /// For instance `a` in
|
| + /// class C {
|
| + /// var a;
|
| + /// C([this.a = 42]);
|
| + /// }
|
| + ///
|
| + R visitOptionalInitializingFormalDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + InitializingFormalElement parameter,
|
| + ConstantExpression defaultValue,
|
| + int index,
|
| + A arg);
|
| +
|
| + /// A declaration of a named [parameter] as an initializing formal in a
|
| + /// constructor with the explicit [defaultValue]. If no default value is
|
| + /// declared, [defaultValue] is `null`.
|
| + ///
|
| + /// For instance `a` in
|
| + /// class C {
|
| + /// var a;
|
| + /// C({this.a: 42});
|
| + /// }
|
| + ///
|
| + R visitNamedInitializingFormalDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + InitializingFormalElement parameter,
|
| + ConstantExpression defaultValue,
|
| + A arg);
|
| +
|
| + /// A declaration of a local [variable] with the explicit [initializer]. If
|
| + /// no initializer is declared, [initializer] is `null`.
|
| + ///
|
| + /// For instance `a` in
|
| + /// m() {
|
| + /// var a = 42;
|
| + /// }
|
| + ///
|
| + R visitLocalVariableDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + LocalVariableElement variable,
|
| + Node initializer,
|
| + A arg);
|
| +
|
| + /// A declaration of a local constant [variable] initialized to [constant].
|
| + ///
|
| + /// For instance `a` in
|
| + /// m() {
|
| + /// const a = 42;
|
| + /// }
|
| + ///
|
| + R visitLocalConstantDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + LocalVariableElement variable,
|
| + ConstantExpression constant,
|
| + A arg);
|
| +
|
| + /// A declaration of a top level [field] with the explicit [initializer].
|
| + /// If no initializer is declared, [initializer] is `null`.
|
| + ///
|
| + /// For instance `a` in
|
| + /// var a = 42;
|
| + ///
|
| + R visitTopLevelFieldDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + FieldElement field,
|
| + Node initializer,
|
| + A arg);
|
| +
|
| + /// A declaration of a top level constant [field] initialized to [constant].
|
| + ///
|
| + /// For instance `a` in
|
| + /// const a = 42;
|
| + ///
|
| + R visitTopLevelConstantDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + FieldElement field,
|
| + ConstantExpression constant,
|
| + A arg);
|
| +
|
| + /// A declaration of a static [field] with the explicit [initializer].
|
| + /// If no initializer is declared, [initializer] is `null`.
|
| + ///
|
| + /// For instance `a` in
|
| + /// class C {
|
| + /// static var a = 42;
|
| + /// }
|
| + ///
|
| + R visitStaticFieldDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + FieldElement field,
|
| + Node initializer,
|
| + A arg);
|
| +
|
| + /// A declaration of a static constant [field] initialized to [constant].
|
| + ///
|
| + /// For instance `a` in
|
| + /// class C {
|
| + /// static const a = 42;
|
| + /// }
|
| + ///
|
| + R visitStaticConstantDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + FieldElement field,
|
| + ConstantExpression constant,
|
| + A arg);
|
| +
|
| + /// A declaration of an instance [field] with the explicit [initializer].
|
| + /// If no initializer is declared, [initializer] is `null`.
|
| + ///
|
| + /// For instance `a` in
|
| + /// class C {
|
| + /// var a = 42;
|
| + /// }
|
| + ///
|
| + R visitInstanceFieldDecl(
|
| + VariableDefinitions node,
|
| + Node definition,
|
| + FieldElement field,
|
| + Node initializer,
|
| + A arg);
|
| +
|
| + /// A declaration of a generative [constructor] with the explicit constructor
|
| + /// [initializers].
|
| + ///
|
| + /// For instance `C` in
|
| + /// class C {
|
| + /// var a;
|
| + /// C(a) : this.a = a, super();
|
| + /// }
|
| + ///
|
| + R visitGenerativeConstructorDecl(
|
| + FunctionExpression node,
|
| + ConstructorElement constructor,
|
| + NodeList parameters,
|
| + NodeList initializers,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a redirecting generative [constructor] with
|
| + /// [initializers] containing the redirecting constructor invocation.
|
| + ///
|
| + /// For instance `C` in
|
| + /// class C {
|
| + /// C() : this._();
|
| + /// C._();
|
| + /// }
|
| + ///
|
| + R visitRedirectingGenerativeConstructorDecl(
|
| + FunctionExpression node,
|
| + ConstructorElement constructor,
|
| + NodeList parameters,
|
| + NodeList initializers,
|
| + A arg);
|
| +
|
| + /// A declaration of a factory [constructor].
|
| + ///
|
| + /// For instance `C` in
|
| + /// class C {
|
| + /// factory C(a) => null;
|
| + /// }
|
| + ///
|
| + R visitFactoryConstructorDecl(
|
| + FunctionExpression node,
|
| + ConstructorElement constructor,
|
| + NodeList parameters,
|
| + Node body,
|
| + A arg);
|
| +
|
| + /// A declaration of a redirecting factory [constructor]. The immediate
|
| + /// redirection target and its type is provided in [redirectionTarget] and
|
| + /// [redirectionType], respectively.
|
| + ///
|
| + /// For instance
|
| + /// class C<T> {
|
| + /// factory C() = C<int>.a;
|
| + /// factory C.a() = C<C<T>>.b;
|
| + /// C.b();
|
| + /// }
|
| + /// where `C` has the redirection target `C.a` of type `C<int>` and `C.a` has
|
| + /// the redirection target `C.b` of type `C<C<T>>`.
|
| + ///
|
| + R visitRedirectingFactoryConstructorDecl(
|
| + FunctionExpression node,
|
| + ConstructorElement constructor,
|
| + NodeList parameters,
|
| + InterfaceType redirectionType,
|
| + ConstructorElement redirectionTarget,
|
| + A arg);
|
| +
|
| + /// An initializer of [field] with [initializer] as found in constructor
|
| + /// initializers.
|
| + ///
|
| + /// For instance `this.a = 42` in
|
| + /// class C {
|
| + /// var a;
|
| + /// C() : this.a = 42;
|
| + /// }
|
| + ///
|
| + R visitFieldInitializer(
|
| + SendSet node,
|
| + FieldElement field,
|
| + Node initializer,
|
| + A arg);
|
| +
|
| + /// An initializer of an unresolved field with [initializer] as found in
|
| + /// generative constructor initializers.
|
| + ///
|
| + /// For instance `this.a = 42` in
|
| + /// class C {
|
| + /// C() : this.a = 42;
|
| + /// }
|
| + ///
|
| + R errorUnresolvedFieldInitializer(
|
| + SendSet node,
|
| + Element element,
|
| + Node initializer,
|
| + A arg);
|
| +
|
| + /// An super constructor invocation of [superConstructor] with [arguments] as
|
| + /// found in generative constructor initializers.
|
| + ///
|
| + /// For instance `super(42)` in
|
| + /// class B {
|
| + /// B(a);
|
| + /// }
|
| + /// class C extends B {
|
| + /// C() : super(42);
|
| + /// }
|
| + ///
|
| + R visitSuperConstructorInvoke(
|
| + Send node,
|
| + ConstructorElement superConstructor,
|
| + InterfaceType type,
|
| + NodeList arguments,
|
| + Selector selector,
|
| + A arg);
|
| +
|
| + /// An super constructor invocation of an unresolved with [arguments] as
|
| + /// found in generative constructor initializers.
|
| + ///
|
| + /// For instance `super(42)` in
|
| + /// class B {
|
| + /// B(a);
|
| + /// }
|
| + /// class C extends B {
|
| + /// C() : super.unresolved(42);
|
| + /// }
|
| + ///
|
| + R errorUnresolvedSuperConstructorInvoke(
|
| + Send node,
|
| + Element element,
|
| + NodeList arguments,
|
| + Selector selector,
|
| + A arg);
|
| +
|
| + /// An this constructor invocation of [thisConstructor] with [arguments] as
|
| + /// found in a redirecting generative constructors initializer.
|
| + ///
|
| + /// For instance `this._(42)` in
|
| + /// class C {
|
| + /// C() : this._(42);
|
| + /// C._(a);
|
| + /// }
|
| + ///
|
| + R visitThisConstructorInvoke(
|
| + Send node,
|
| + ConstructorElement thisConstructor,
|
| + NodeList arguments,
|
| + Selector selector,
|
| + A arg);
|
| +
|
| + /// An this constructor invocation of an unresolved constructor with
|
| + /// [arguments] as found in a redirecting generative constructors initializer.
|
| + ///
|
| + /// For instance `this._(42)` in
|
| + /// class C {
|
| + /// C() : this._(42);
|
| + /// }
|
| + ///
|
| + R errorUnresolvedThisConstructorInvoke(
|
| + Send node,
|
| + Element element,
|
| + NodeList arguments,
|
| + Selector selector,
|
| + A arg);
|
| +}
|
|
|