Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library elements.modelx; | 5 library elements.modelx; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show Resolution, Parsing; | 8 import '../common/resolution.dart' show Resolution, Parsing; |
| 9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
| 10 import '../constants/constant_constructors.dart'; | 10 import '../constants/constant_constructors.dart'; |
| 11 import '../constants/constructors.dart'; | 11 import '../constants/constructors.dart'; |
| 12 import '../constants/expressions.dart'; | 12 import '../constants/expressions.dart'; |
| 13 import '../dart_types.dart'; | 13 import '../dart_types.dart'; |
| 14 import '../diagnostics/messages.dart' show MessageTemplate; | 14 import '../diagnostics/messages.dart' show MessageTemplate; |
| 15 import '../ordered_typeset.dart' show OrderedTypeSet; | 15 import '../ordered_typeset.dart' show OrderedTypeSet; |
| 16 import '../resolution/class_members.dart' show ClassMemberMixin; | 16 import '../resolution/class_members.dart' show ClassMemberMixin; |
| 17 import '../resolution/scope.dart' | 17 import '../resolution/scope.dart' |
| 18 show ClassScope, LibraryScope, Scope, TypeDeclarationScope; | 18 show ClassScope, LibraryScope, MixinApplicationScope, NoScope, Scope, |
| 19 TypeDeclarationScope; | |
| 19 import '../resolution/resolution.dart' show AnalyzableElementX; | 20 import '../resolution/resolution.dart' show AnalyzableElementX; |
| 20 import '../resolution/tree_elements.dart' show TreeElements; | 21 import '../resolution/tree_elements.dart' show TreeElements; |
| 21 import '../resolution/typedefs.dart' show TypedefCyclicVisitor; | 22 import '../resolution/typedefs.dart' show TypedefCyclicVisitor; |
| 22 import '../script.dart'; | 23 import '../script.dart'; |
| 23 import '../tokens/token.dart' show ErrorToken, Token; | 24 import '../tokens/token.dart' show ErrorToken, Token; |
| 24 import '../tokens/token_constants.dart' as Tokens show EOF_TOKEN; | 25 import '../tokens/token_constants.dart' as Tokens show EOF_TOKEN; |
| 25 import '../tree/tree.dart'; | 26 import '../tree/tree.dart'; |
| 26 import '../util/util.dart'; | 27 import '../util/util.dart'; |
| 27 | 28 |
| 28 import 'common.dart'; | 29 import 'common.dart'; |
| (...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1374 List<MetadataAnnotation> metadataInternal; | 1375 List<MetadataAnnotation> metadataInternal; |
| 1375 | 1376 |
| 1376 VariableList(Modifiers this.modifiers); | 1377 VariableList(Modifiers this.modifiers); |
| 1377 | 1378 |
| 1378 VariableList.node(VariableDefinitions node, this.type) | 1379 VariableList.node(VariableDefinitions node, this.type) |
| 1379 : this.definitions = node, | 1380 : this.definitions = node, |
| 1380 this.modifiers = node.modifiers { | 1381 this.modifiers = node.modifiers { |
| 1381 assert(modifiers != null); | 1382 assert(modifiers != null); |
| 1382 } | 1383 } |
| 1383 | 1384 |
| 1385 VariableList.internal(this.modifiers); | |
| 1386 | |
| 1384 Iterable<MetadataAnnotation> get metadata { | 1387 Iterable<MetadataAnnotation> get metadata { |
| 1385 return metadataInternal != null | 1388 return metadataInternal != null |
| 1386 ? metadataInternal | 1389 ? metadataInternal |
| 1387 : const <MetadataAnnotation>[]; | 1390 : const <MetadataAnnotation>[]; |
| 1388 } | 1391 } |
| 1389 | 1392 |
| 1390 void set metadata(List<MetadataAnnotation> metadata) { | 1393 void set metadata(List<MetadataAnnotation> metadata) { |
| 1391 if (metadata.isEmpty) { | 1394 if (metadata.isEmpty) { |
| 1392 // For a multi declaration like: | 1395 // For a multi declaration like: |
| 1393 // | 1396 // |
| 1394 // @foo @bar var a, b, c | 1397 // @foo @bar var a, b, c |
| 1395 // | 1398 // |
| 1396 // the metadata list is reported through the declaration of `a`, and `b` | 1399 // the metadata list is reported through the declaration of `a`, and `b` |
| 1397 // and `c` report an empty list of metadata. | 1400 // and `c` report an empty list of metadata. |
| 1398 return; | 1401 return; |
| 1399 } | 1402 } |
| 1400 assert(metadataInternal == null); | 1403 assert(metadataInternal == null); |
| 1401 metadataInternal = metadata; | 1404 metadataInternal = metadata; |
| 1402 } | 1405 } |
| 1403 | 1406 |
| 1404 VariableDefinitions parseNode(Element element, Parsing parsing) { | 1407 VariableDefinitions parseNode(Element element, Parsing parsing) { |
| 1405 return definitions; | 1408 return definitions; |
| 1406 } | 1409 } |
| 1407 | 1410 |
| 1408 DartType computeType(Element element, Resolution resolution) => type; | 1411 DartType computeType(Element element, Resolution resolution) => type; |
| 1409 | 1412 |
| 1410 bool get isMalformed => false; | 1413 bool get isMalformed => false; |
| 1414 | |
| 1415 VariableList copy() { | |
| 1416 return new VariableList.internal(modifiers) | |
| 1417 ..definitions = definitions | |
| 1418 ..type = type | |
| 1419 ..metadataInternal = metadataInternal; | |
| 1420 } | |
| 1411 } | 1421 } |
| 1412 | 1422 |
| 1413 abstract class ConstantVariableMixin implements VariableElement { | 1423 abstract class ConstantVariableMixin implements VariableElement { |
| 1414 ConstantExpression constantCache; | 1424 ConstantExpression constantCache; |
| 1415 | 1425 |
| 1416 ConstantExpression get constant { | 1426 ConstantExpression get constant { |
| 1417 if (isPatch) { | 1427 if (isPatch) { |
| 1418 ConstantVariableMixin originVariable = origin; | 1428 ConstantVariableMixin originVariable = origin; |
| 1419 return originVariable.constant; | 1429 return originVariable.constant; |
| 1420 } | 1430 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1588 | 1598 |
| 1589 bool get isMalformed => variables.isMalformed; | 1599 bool get isMalformed => variables.isMalformed; |
| 1590 | 1600 |
| 1591 void reuseElement() { | 1601 void reuseElement() { |
| 1592 super.reuseElement(); | 1602 super.reuseElement(); |
| 1593 nestedClosures.clear(); | 1603 nestedClosures.clear(); |
| 1594 } | 1604 } |
| 1595 | 1605 |
| 1596 FieldElementX copyWithEnclosing(Element enclosingElement) { | 1606 FieldElementX copyWithEnclosing(Element enclosingElement) { |
| 1597 return new FieldElementX( | 1607 return new FieldElementX( |
| 1598 new Identifier(token), enclosingElement, variables); | 1608 new Identifier(token), enclosingElement, variables.copy()); |
| 1599 } | 1609 } |
| 1600 } | 1610 } |
| 1601 | 1611 |
| 1602 /// A field that was synthesized to recover from a compile-time error. | 1612 /// A field that was synthesized to recover from a compile-time error. |
| 1603 class ErroneousFieldElementX extends ElementX | 1613 class ErroneousFieldElementX extends ElementX |
| 1604 with ConstantVariableMixin | 1614 with ConstantVariableMixin |
| 1605 implements FieldElementX { | 1615 implements FieldElementX { |
| 1606 final VariableList variables; | 1616 final VariableList variables; |
| 1607 | 1617 |
| 1608 ErroneousFieldElementX(Identifier name, Element enclosingElement) | 1618 ErroneousFieldElementX(Identifier name, Element enclosingElement) |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2824 SourceSpan get sourcePosition { | 2834 SourceSpan get sourcePosition { |
| 2825 return new SourceSpan( | 2835 return new SourceSpan( |
| 2826 enclosingClass.sourcePosition.uri, | 2836 enclosingClass.sourcePosition.uri, |
| 2827 position.charOffset, position.charEnd); | 2837 position.charOffset, position.charEnd); |
| 2828 } | 2838 } |
| 2829 } | 2839 } |
| 2830 | 2840 |
| 2831 abstract class MixinApplicationElementX extends BaseClassElementX | 2841 abstract class MixinApplicationElementX extends BaseClassElementX |
| 2832 with MixinApplicationElementCommon | 2842 with MixinApplicationElementCommon |
| 2833 implements MixinApplicationElement { | 2843 implements MixinApplicationElement { |
| 2834 Link<ConstructorElement> constructors = new Link<ConstructorElement>(); | 2844 Link<ConstructorElement> constructors = const Link<ConstructorElement>(); |
| 2845 Link<Element> members = const Link<Element>(); | |
| 2835 | 2846 |
| 2836 InterfaceType mixinType; | 2847 InterfaceType mixinType; |
| 2837 | 2848 |
| 2838 MixinApplicationElementX(String name, Element enclosing, int id) | 2849 MixinApplicationElementX(String name, Element enclosing, int id) |
| 2839 : super(name, enclosing, id, STATE_NOT_STARTED); | 2850 : super(name, enclosing, id, STATE_NOT_STARTED); |
| 2840 | 2851 |
| 2841 ClassElement get mixin => mixinType != null ? mixinType.element : null; | 2852 ClassElement get mixin => mixinType != null ? mixinType.element : null; |
| 2842 | 2853 |
| 2843 bool get isMixinApplication => true; | 2854 bool get isMixinApplication => true; |
| 2844 bool get isUnnamedMixinApplication => node is! NamedMixinApplication; | |
| 2845 bool get hasConstructor => !constructors.isEmpty; | 2855 bool get hasConstructor => !constructors.isEmpty; |
| 2846 bool get hasLocalScopeMembers => !constructors.isEmpty; | 2856 bool get hasLocalScopeMembers => !constructors.isEmpty; |
| 2847 | 2857 |
| 2848 get patch => null; | 2858 get patch => null; |
| 2849 get origin => null; | 2859 get origin => null; |
| 2850 | 2860 |
| 2851 bool get hasNode => true; | 2861 bool get hasNode => true; |
| 2852 | 2862 |
| 2853 Token get position => node.getBeginToken(); | 2863 Token get position => node.getBeginToken(); |
| 2854 | 2864 |
| 2855 Node parseNode(Parsing parsing) => node; | 2865 Node parseNode(Parsing parsing) => node; |
| 2856 | 2866 |
| 2857 void addMember(Element element, DiagnosticReporter reporter) { | 2867 void addMember(Element element, DiagnosticReporter reporter) { |
| 2858 throw new UnsupportedError("Cannot add member to $this."); | 2868 members = members.prepend(element); |
| 2859 } | 2869 } |
| 2860 | 2870 |
| 2861 void addToScope(Element element, DiagnosticReporter reporter) { | 2871 void addToScope(Element element, DiagnosticReporter reporter) { |
| 2862 reporter.internalError(this, 'Cannot add to scope of $this.'); | 2872 reporter.internalError(this, 'Cannot add to scope of $this.'); |
| 2863 } | 2873 } |
| 2864 | 2874 |
| 2865 void addConstructor(FunctionElement constructor) { | 2875 void addConstructor(FunctionElement constructor) { |
| 2866 constructors = constructors.prepend(constructor); | 2876 constructors = constructors.prepend(constructor); |
| 2867 } | 2877 } |
| 2868 | 2878 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2879 node, | 2889 node, |
| 2880 "Type variables on unnamed mixin applications must be set on " | 2890 "Type variables on unnamed mixin applications must be set on " |
| 2881 "creation."); | 2891 "creation."); |
| 2882 } | 2892 } |
| 2883 return createTypeVariables(named.typeParameters); | 2893 return createTypeVariables(named.typeParameters); |
| 2884 } | 2894 } |
| 2885 | 2895 |
| 2886 accept(ElementVisitor visitor, arg) { | 2896 accept(ElementVisitor visitor, arg) { |
| 2887 return visitor.visitMixinApplicationElement(this, arg); | 2897 return visitor.visitMixinApplicationElement(this, arg); |
| 2888 } | 2898 } |
| 2899 | |
| 2900 @override | |
| 2901 void forEachLocalMember(void f(Element member)) { | |
| 2902 constructors.forEach(f); | |
| 2903 members.forEach(f); | |
| 2904 } | |
| 2905 | |
| 2906 buildScope() { | |
|
Johnni Winther
2016/06/30 14:16:30
Add @override and return type.
| |
| 2907 Scope parentScope = mixin?.buildScope(); | |
| 2908 if (parentScope == null) { | |
| 2909 parentScope = new NoScope(); | |
| 2910 } | |
| 2911 return new MixinApplicationScope(parentScope, this); | |
| 2912 } | |
| 2889 } | 2913 } |
| 2890 | 2914 |
| 2891 class NamedMixinApplicationElementX extends MixinApplicationElementX | 2915 class NamedMixinApplicationElementX extends MixinApplicationElementX |
| 2892 implements DeclarationSite { | 2916 implements DeclarationSite { |
| 2893 final NamedMixinApplication node; | 2917 final NamedMixinApplication node; |
| 2894 | 2918 |
| 2895 NamedMixinApplicationElementX( | 2919 NamedMixinApplicationElementX( |
| 2896 String name, CompilationUnitElement enclosing, int id, this.node) | 2920 String name, CompilationUnitElement enclosing, int id, this.node) |
| 2897 : super(name, enclosing, id); | 2921 : super(name, enclosing, id); |
| 2898 | 2922 |
| 2899 Modifiers get modifiers => node.modifiers; | 2923 Modifiers get modifiers => node.modifiers; |
| 2900 | 2924 |
| 2901 DeclarationSite get declarationSite => this; | 2925 DeclarationSite get declarationSite => this; |
| 2926 | |
| 2927 bool get isUnnamedMixinApplication => false; | |
| 2902 } | 2928 } |
| 2903 | 2929 |
| 2904 class UnnamedMixinApplicationElementX extends MixinApplicationElementX { | 2930 class UnnamedMixinApplicationElementX extends MixinApplicationElementX { |
| 2905 final Node node; | 2931 final Node node; |
| 2906 | 2932 |
| 2907 UnnamedMixinApplicationElementX( | 2933 UnnamedMixinApplicationElementX( |
| 2908 String name, CompilationUnitElement enclosing, int id, this.node) | 2934 String name, CompilationUnitElement enclosing, int id, this.node) |
| 2909 : super(name, enclosing, id); | 2935 : super(name, enclosing, id); |
| 2910 | 2936 |
| 2911 bool get isAbstract => true; | 2937 bool get isAbstract => true; |
| 2938 | |
| 2939 bool get isUnnamedMixinApplication => true; | |
| 2912 } | 2940 } |
| 2913 | 2941 |
| 2914 class LabelDefinitionX implements LabelDefinition { | 2942 class LabelDefinitionX implements LabelDefinition { |
| 2915 final Label label; | 2943 final Label label; |
| 2916 final String labelName; | 2944 final String labelName; |
| 2917 final JumpTarget target; | 2945 final JumpTarget target; |
| 2918 bool isBreakTarget = false; | 2946 bool isBreakTarget = false; |
| 2919 bool isContinueTarget = false; | 2947 bool isContinueTarget = false; |
| 2920 | 2948 |
| 2921 LabelDefinitionX(Label label, String labelName, this.target) | 2949 LabelDefinitionX(Label label, String labelName, this.target) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3127 | 3155 |
| 3128 bool get hasResolvedAst { | 3156 bool get hasResolvedAst { |
| 3129 return definingElement.hasNode && definingElement.hasTreeElements; | 3157 return definingElement.hasNode && definingElement.hasTreeElements; |
| 3130 } | 3158 } |
| 3131 | 3159 |
| 3132 ResolvedAst get resolvedAst { | 3160 ResolvedAst get resolvedAst { |
| 3133 return new ResolvedAst( | 3161 return new ResolvedAst( |
| 3134 declaration, definingElement.node, definingElement.treeElements); | 3162 declaration, definingElement.node, definingElement.treeElements); |
| 3135 } | 3163 } |
| 3136 } | 3164 } |
| OLD | NEW |