| 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 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 return element; | 1169 return element; |
| 1170 } | 1170 } |
| 1171 | 1171 |
| 1172 Element useElement(Node node, Element element) { | 1172 Element useElement(Node node, Element element) { |
| 1173 if (element === null) return null; | 1173 if (element === null) return null; |
| 1174 return mapping[node] = element; | 1174 return mapping[node] = element; |
| 1175 } | 1175 } |
| 1176 | 1176 |
| 1177 DartType useType(TypeAnnotation annotation, DartType type) { | 1177 DartType useType(TypeAnnotation annotation, DartType type) { |
| 1178 if (type !== null) { | 1178 if (type !== null) { |
| 1179 if (type.element.isTypeVariable() && enclosingElement.inStaticContext()) { |
| 1180 error(annotation, |
| 1181 MessageKind.CANNOT_ACCESS_TYPE_VARIABLE_IN_STATIC_CONTEXT, |
| 1182 [type.name]); |
| 1183 } |
| 1179 mapping.setType(annotation, type); | 1184 mapping.setType(annotation, type); |
| 1180 useElement(annotation, type.element); | 1185 useElement(annotation, type.element); |
| 1181 } | 1186 } |
| 1182 return type; | 1187 return type; |
| 1183 } | 1188 } |
| 1184 | 1189 |
| 1185 void setupFunction(FunctionExpression node, FunctionElement function) { | 1190 void setupFunction(FunctionExpression node, FunctionElement function) { |
| 1186 // If [function] is the [enclosingElement], the [scope] has | 1191 // If [function] is the [enclosingElement], the [scope] has |
| 1187 // already been set in the constructor of [ResolverVisitor]. | 1192 // already been set in the constructor of [ResolverVisitor]. |
| 1188 if (function != enclosingElement) scope = new MethodScope(scope, function); | 1193 if (function != enclosingElement) scope = new MethodScope(scope, function); |
| (...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2813 | 2818 |
| 2814 Element lexicalLookup(SourceString name) { | 2819 Element lexicalLookup(SourceString name) { |
| 2815 Element result = localLookup(name); | 2820 Element result = localLookup(name); |
| 2816 if (result != null) return result; | 2821 if (result != null) return result; |
| 2817 return parent.lexicalLookup(name); | 2822 return parent.lexicalLookup(name); |
| 2818 } | 2823 } |
| 2819 | 2824 |
| 2820 abstract Element localLookup(SourceString name); | 2825 abstract Element localLookup(SourceString name); |
| 2821 } | 2826 } |
| 2822 | 2827 |
| 2823 class VariableScope extends Scope { | |
| 2824 VariableScope(parent, element) : super(parent, element); | |
| 2825 | |
| 2826 Element add(Element newElement) { | |
| 2827 throw "Cannot add element to VariableScope"; | |
| 2828 } | |
| 2829 | |
| 2830 Element localLookup(SourceString name) => null; | |
| 2831 | |
| 2832 String toString() => '$element > $parent'; | |
| 2833 } | |
| 2834 | |
| 2835 /** | 2828 /** |
| 2836 * [TypeDeclarationScope] defines the outer scope of a type declaration in | 2829 * [TypeDeclarationScope] defines the outer scope of a type declaration in |
| 2837 * which the declared type variables and the entities in the enclosing scope are | 2830 * which the declared type variables and the entities in the enclosing scope are |
| 2838 * available but where declared and inherited members are not available. This | 2831 * available but where declared and inherited members are not available. This |
| 2839 * scope is only used for class/interface declarations during resolution of the | 2832 * scope is only used for class/interface declarations during resolution of the |
| 2840 * class hierarchy. In all other cases [ClassScope] is used. | 2833 * class hierarchy. In all other cases [ClassScope] is used. |
| 2841 */ | 2834 */ |
| 2842 class TypeDeclarationScope extends Scope { | 2835 class TypeDeclarationScope extends Scope { |
| 2843 TypeDeclarationElement get element => super.element; | 2836 TypeDeclarationElement get element => super.element; |
| 2844 | 2837 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2894 | 2887 |
| 2895 String toString() => 'block${elements.getKeys()}'; | 2888 String toString() => 'block${elements.getKeys()}'; |
| 2896 } | 2889 } |
| 2897 | 2890 |
| 2898 /** | 2891 /** |
| 2899 * [ClassScope] defines the inner scope of a class/interface declaration in | 2892 * [ClassScope] defines the inner scope of a class/interface declaration in |
| 2900 * which declared members, declared type variables, entities in the enclosing | 2893 * which declared members, declared type variables, entities in the enclosing |
| 2901 * scope and inherited members are available, in the given order. | 2894 * scope and inherited members are available, in the given order. |
| 2902 */ | 2895 */ |
| 2903 class ClassScope extends TypeDeclarationScope { | 2896 class ClassScope extends TypeDeclarationScope { |
| 2904 bool inStaticContext = false; | |
| 2905 | |
| 2906 ClassScope(Scope parentScope, ClassElement element) | 2897 ClassScope(Scope parentScope, ClassElement element) |
| 2907 : super(parentScope, element) { | 2898 : super(parentScope, element) { |
| 2908 assert(parent !== null); | 2899 assert(parent !== null); |
| 2909 } | 2900 } |
| 2910 | 2901 |
| 2911 Element localLookup(SourceString name) { | 2902 Element localLookup(SourceString name) { |
| 2912 ClassElement cls = element; | 2903 ClassElement cls = element; |
| 2913 Element result = cls.lookupLocalMember(name); | 2904 Element result = cls.lookupLocalMember(name); |
| 2914 if (result !== null) return result; | 2905 if (result !== null) return result; |
| 2915 if (!inStaticContext) { | 2906 return super.localLookup(name); |
| 2916 // If not in a static context, we can lookup in the | |
| 2917 // TypeDeclaration scope, which contains the type variables of | |
| 2918 // the class. | |
| 2919 result = super.localLookup(name); | |
| 2920 } | |
| 2921 return result; | |
| 2922 } | 2907 } |
| 2923 | 2908 |
| 2924 Element lookup(SourceString name) { | 2909 Element lookup(SourceString name) { |
| 2925 Element result = localLookup(name); | 2910 Element result = localLookup(name); |
| 2926 if (result !== null) return result; | 2911 if (result !== null) return result; |
| 2927 result = parent.lookup(name); | 2912 result = parent.lookup(name); |
| 2928 if (result !== null) return result; | 2913 if (result !== null) return result; |
| 2929 ClassElement cls = element; | 2914 ClassElement cls = element; |
| 2930 return cls.lookupSuperMember(name); | 2915 return cls.lookupSuperMember(name); |
| 2931 } | 2916 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3055 return result; | 3040 return result; |
| 3056 } | 3041 } |
| 3057 Element lookup(SourceString name) => localLookup(name); | 3042 Element lookup(SourceString name) => localLookup(name); |
| 3058 Element lexicalLookup(SourceString name) => localLookup(name); | 3043 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3059 | 3044 |
| 3060 Element add(Element newElement) { | 3045 Element add(Element newElement) { |
| 3061 throw "Cannot add an element in a patch library scope"; | 3046 throw "Cannot add an element in a patch library scope"; |
| 3062 } | 3047 } |
| 3063 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3048 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3064 } | 3049 } |
| OLD | NEW |