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