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 library dart2js.resolution.scope; | 5 library dart2js.resolution.scope; |
6 | 6 |
7 import '../dart_types.dart'; | 7 import '../dart_types.dart'; |
8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
9 | 9 |
10 abstract class Scope { | 10 abstract class Scope { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 variableReferencedInInitializer = true; | 51 variableReferencedInInitializer = true; |
52 } | 52 } |
53 return null; | 53 return null; |
54 } | 54 } |
55 | 55 |
56 Element add(Element newElement) { | 56 Element add(Element newElement) { |
57 throw "Cannot add element to VariableDefinitionScope"; | 57 throw "Cannot add element to VariableDefinitionScope"; |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 /// [TypeVariablesScope] defines the outer scope in a context where some type | 61 /** |
62 /// variables are declared and the entities in the enclosing scope are | 62 * [TypeDeclarationScope] defines the outer scope of a type declaration in |
63 /// available, but where locally declared and inherited members are not | 63 * which the declared type variables and the entities in the enclosing scope are |
64 /// available. | 64 * available but where declared and inherited members are not available. This |
65 abstract class TypeVariablesScope extends NestedScope { | 65 * scope is only used for class declarations during resolution of the |
66 List<DartType> get typeVariables; | 66 * class hierarchy. In all other cases [ClassScope] is used. |
| 67 */ |
| 68 class TypeDeclarationScope extends NestedScope { |
| 69 final TypeDeclarationElement element; |
67 | 70 |
68 TypeVariablesScope(Scope parent) : super(parent) { | 71 TypeDeclarationScope(parent, this.element) : super(parent) { |
69 assert(parent != null); | 72 assert(parent != null); |
70 } | 73 } |
71 | 74 |
72 Element add(Element newElement) { | 75 Element add(Element newElement) { |
73 throw "Cannot add element to TypeDeclarationScope"; | 76 throw "Cannot add element to TypeDeclarationScope"; |
74 } | 77 } |
75 | 78 |
76 Element lookupTypeVariable(String name) { | 79 Element lookupTypeVariable(String name) { |
| 80 List<DartType> typeVariables = element.typeVariables; |
77 for (TypeVariableType type in typeVariables) { | 81 for (TypeVariableType type in typeVariables) { |
78 if (type.name == name) { | 82 if (type.name == name) { |
79 return type.element; | 83 return type.element; |
80 } | 84 } |
81 } | 85 } |
82 return null; | 86 return null; |
83 } | 87 } |
84 | 88 |
85 Element localLookup(String name) => lookupTypeVariable(name); | 89 Element localLookup(String name) => lookupTypeVariable(name); |
86 } | |
87 | |
88 /** | |
89 * [TypeDeclarationScope] defines the outer scope of a type declaration in | |
90 * which the declared type variables and the entities in the enclosing scope are | |
91 * available but where declared and inherited members are not available. This | |
92 * scope is used for class declarations during resolution of the class hierarchy | |
93 * and when resolving typedef signatures. In other cases [ClassScope] is used. | |
94 */ | |
95 class TypeDeclarationScope extends TypeVariablesScope { | |
96 final GenericElement element; | |
97 | |
98 @override | |
99 List<DartType> get typeVariables => element.typeVariables; | |
100 | |
101 TypeDeclarationScope(Scope parent, this.element) : super(parent); | |
102 | 90 |
103 String toString() => 'TypeDeclarationScope($element)'; | 91 String toString() => 'TypeDeclarationScope($element)'; |
104 } | 92 } |
105 | 93 |
106 abstract class MutableScope extends NestedScope { | 94 abstract class MutableScope extends NestedScope { |
107 final Map<String, Element> elements; | 95 final Map<String, Element> elements; |
108 | 96 |
109 MutableScope(Scope parent) | 97 MutableScope(Scope parent) |
110 : super(parent), | 98 : super(parent), |
111 this.elements = new Map<String, Element>() { | 99 this.elements = new Map<String, Element>() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 166 |
179 Element localLookup(String name) => library.find(name); | 167 Element localLookup(String name) => library.find(name); |
180 Element lookup(String name) => localLookup(name); | 168 Element lookup(String name) => localLookup(name); |
181 | 169 |
182 Element add(Element newElement) { | 170 Element add(Element newElement) { |
183 throw "Cannot add an element to a library scope"; | 171 throw "Cannot add an element to a library scope"; |
184 } | 172 } |
185 | 173 |
186 String toString() => 'LibraryScope($library)'; | 174 String toString() => 'LibraryScope($library)'; |
187 } | 175 } |
OLD | NEW |