OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 abstract class TreeElements { | 5 abstract class TreeElements { |
6 Element operator[](Node node); | 6 Element operator[](Node node); |
7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
8 DartType getType(TypeAnnotation annotation); | 8 DartType getType(TypeAnnotation annotation); |
9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
10 } | 10 } |
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1123 return element; | 1123 return element; |
1124 } | 1124 } |
1125 | 1125 |
1126 Element useElement(Node node, Element element) { | 1126 Element useElement(Node node, Element element) { |
1127 if (element === null) return null; | 1127 if (element === null) return null; |
1128 return mapping[node] = element; | 1128 return mapping[node] = element; |
1129 } | 1129 } |
1130 | 1130 |
1131 DartType useType(TypeAnnotation annotation, DartType type) { | 1131 DartType useType(TypeAnnotation annotation, DartType type) { |
1132 if (type !== null) { | 1132 if (type !== null) { |
1133 if (type.element.isTypeVariable() && enclosingElement.inStaticContext()) { | |
1134 error(annotation, | |
1135 MessageKind.CANNOT_ACCESS_TYPE_VARIABLE_IN_STATIC_CONTEXT, | |
1136 [type.name]); | |
1137 } | |
1133 mapping.setType(annotation, type); | 1138 mapping.setType(annotation, type); |
1134 useElement(annotation, type.element); | 1139 useElement(annotation, type.element); |
1135 } | 1140 } |
1136 return type; | 1141 return type; |
1137 } | 1142 } |
1138 | 1143 |
1139 void setupFunction(FunctionExpression node, FunctionElement function) { | 1144 void setupFunction(FunctionExpression node, FunctionElement function) { |
1140 // If [function] is the [enclosingElement], the [scope] has | 1145 // If [function] is the [enclosingElement], the [scope] has |
1141 // already been set in the constructor of [ResolverVisitor]. | 1146 // already been set in the constructor of [ResolverVisitor]. |
1142 if (function != enclosingElement) scope = new MethodScope(scope, function); | 1147 if (function != enclosingElement) scope = new MethodScope(scope, function); |
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2753 | 2758 |
2754 Element lexicalLookup(SourceString name) { | 2759 Element lexicalLookup(SourceString name) { |
2755 Element result = localLookup(name); | 2760 Element result = localLookup(name); |
2756 if (result != null) return result; | 2761 if (result != null) return result; |
2757 return parent.lexicalLookup(name); | 2762 return parent.lexicalLookup(name); |
2758 } | 2763 } |
2759 | 2764 |
2760 abstract Element localLookup(SourceString name); | 2765 abstract Element localLookup(SourceString name); |
2761 } | 2766 } |
2762 | 2767 |
2763 class VariableScope extends Scope { | 2768 class VariableScope extends Scope { |
ahe
2012/10/02 07:50:25
I think we should get rid of this one as well.
Johnni Winther
2012/10/02 09:07:30
I agree. Remove this class.
aam-me
2012/10/02 12:50:39
Thanks, done!
| |
2764 VariableScope(parent, element) : super(parent, element); | 2769 VariableScope(parent, element) : super(parent, element); |
2765 | 2770 |
2766 Element add(Element newElement) { | 2771 Element add(Element newElement) { |
2767 throw "Cannot add element to VariableScope"; | 2772 throw "Cannot add element to VariableScope"; |
2768 } | 2773 } |
2769 | 2774 |
2770 Element localLookup(SourceString name) => null; | 2775 Element localLookup(SourceString name) => null; |
2771 | 2776 |
2772 String toString() => '$element > $parent'; | 2777 String toString() => '$element > $parent'; |
2773 } | 2778 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2834 | 2839 |
2835 String toString() => 'block${elements.getKeys()} > $parent'; | 2840 String toString() => 'block${elements.getKeys()} > $parent'; |
2836 } | 2841 } |
2837 | 2842 |
2838 /** | 2843 /** |
2839 * [ClassScope] defines the inner scope of a class/interface declaration in | 2844 * [ClassScope] defines the inner scope of a class/interface declaration in |
2840 * which declared members, declared type variables, entities in the enclosing | 2845 * which declared members, declared type variables, entities in the enclosing |
2841 * scope and inherited members are available, in the given order. | 2846 * scope and inherited members are available, in the given order. |
2842 */ | 2847 */ |
2843 class ClassScope extends TypeDeclarationScope { | 2848 class ClassScope extends TypeDeclarationScope { |
2844 bool inStaticContext = false; | |
ahe
2012/10/02 07:50:25
This is great.
| |
2845 | |
2846 ClassScope(Scope parentScope, ClassElement element) | 2849 ClassScope(Scope parentScope, ClassElement element) |
2847 : super(parentScope, element); | 2850 : super(parentScope, element); |
2848 | 2851 |
2849 Element localLookup(SourceString name) { | 2852 Element localLookup(SourceString name) { |
2850 ClassElement cls = element; | 2853 ClassElement cls = element; |
2851 Element result = cls.lookupLocalMember(name); | 2854 Element result = cls.lookupLocalMember(name); |
2852 if (result !== null) return result; | 2855 if (result !== null) return result; |
2853 if (!inStaticContext) { | 2856 return super.localLookup(name); |
2854 // If not in a static context, we can lookup in the | |
2855 // TypeDeclaration scope, which contains the type variables of | |
2856 // the class. | |
2857 return super.localLookup(name); | |
2858 } | |
2859 return null; | |
2860 } | 2857 } |
2861 | 2858 |
2862 Element lookup(SourceString name) { | 2859 Element lookup(SourceString name) { |
2863 Element result = super.lookup(name); | 2860 Element result = super.lookup(name); |
2864 if (result !== null) return result; | 2861 if (result !== null) return result; |
2865 ClassElement cls = element; | 2862 ClassElement cls = element; |
2866 return cls.lookupSuperMember(name); | 2863 return cls.lookupSuperMember(name); |
2867 } | 2864 } |
2868 | 2865 |
2869 Element add(Element newElement) { | 2866 Element add(Element newElement) { |
(...skipping 10 matching lines...) Expand all Loading... | |
2880 | 2877 |
2881 Element localLookup(SourceString name) => library.find(name); | 2878 Element localLookup(SourceString name) => library.find(name); |
2882 Element lookup(SourceString name) => localLookup(name); | 2879 Element lookup(SourceString name) => localLookup(name); |
2883 Element lexicalLookup(SourceString name) => localLookup(name); | 2880 Element lexicalLookup(SourceString name) => localLookup(name); |
2884 | 2881 |
2885 Element add(Element newElement) { | 2882 Element add(Element newElement) { |
2886 throw "Cannot add an element in the top scope"; | 2883 throw "Cannot add an element in the top scope"; |
2887 } | 2884 } |
2888 String toString() => '$element'; | 2885 String toString() => '$element'; |
2889 } | 2886 } |
OLD | NEW |