| OLD | NEW |
| 1 | 1 |
| 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 library dart2js.common.resolution; | 6 library dart2js.common.resolution; |
| 7 | 7 |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../compiler.dart' show | 9 import '../compiler.dart' show |
| 10 Compiler; | 10 Compiler; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 TypedefElement, | 26 TypedefElement, |
| 27 TypeVariableElement; | 27 TypeVariableElement; |
| 28 import '../enqueue.dart' show | 28 import '../enqueue.dart' show |
| 29 ResolutionEnqueuer; | 29 ResolutionEnqueuer; |
| 30 import '../parser/element_listener.dart' show | 30 import '../parser/element_listener.dart' show |
| 31 ScannerOptions; | 31 ScannerOptions; |
| 32 import '../tree/tree.dart' show | 32 import '../tree/tree.dart' show |
| 33 AsyncForIn, | 33 AsyncForIn, |
| 34 Send, | 34 Send, |
| 35 TypeAnnotation; | 35 TypeAnnotation; |
| 36 import '../universe/universe.dart' show | |
| 37 UniverseSelector; | |
| 38 import '../universe/world_impact.dart' show | 36 import '../universe/world_impact.dart' show |
| 39 WorldImpact; | 37 WorldImpact; |
| 40 import '../util/util.dart' show | |
| 41 Setlet; | |
| 42 import 'work.dart' show | 38 import 'work.dart' show |
| 43 ItemCompilationContext, | 39 ItemCompilationContext, |
| 44 WorkItem; | 40 WorkItem; |
| 45 | 41 |
| 46 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. | 42 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. |
| 47 class ResolutionWorkItem extends WorkItem { | 43 class ResolutionWorkItem extends WorkItem { |
| 48 bool _isAnalyzed = false; | 44 bool _isAnalyzed = false; |
| 49 | 45 |
| 50 ResolutionWorkItem(AstElement element, | 46 ResolutionWorkItem(AstElement element, |
| 51 ItemCompilationContext compilationContext) | 47 ItemCompilationContext compilationContext) |
| 52 : super(element, compilationContext); | 48 : super(element, compilationContext); |
| 53 | 49 |
| 54 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { | 50 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { |
| 55 WorldImpact impact = compiler.analyze(this, world); | 51 WorldImpact impact = compiler.analyze(this, world); |
| 56 _isAnalyzed = true; | 52 _isAnalyzed = true; |
| 57 return impact; | 53 return impact; |
| 58 } | 54 } |
| 59 | 55 |
| 60 bool get isAnalyzed => _isAnalyzed; | 56 bool get isAnalyzed => _isAnalyzed; |
| 61 } | 57 } |
| 62 | 58 |
| 63 // TODO(johnniwinther): Rename this to something like `BackendResolutionApi` | |
| 64 // and clean up the interface. | |
| 65 /// Backend callbacks function specific to the resolution phase. | |
| 66 class ResolutionCallbacks { | |
| 67 /// Transform the [ResolutionImpact] into a [WorldImpact] adding the | |
| 68 /// backend dependencies for features used in [worldImpact]. | |
| 69 WorldImpact transformImpact(ResolutionImpact worldImpact) => worldImpact; | |
| 70 } | |
| 71 | |
| 72 class ResolutionImpact extends WorldImpact { | 59 class ResolutionImpact extends WorldImpact { |
| 73 const ResolutionImpact(); | 60 const ResolutionImpact(); |
| 74 | 61 |
| 75 // TODO(johnniwinther): Remove this. | 62 // TODO(johnniwinther): Remove this. |
| 76 void registerDependency(Element element) {} | 63 void registerDependency(Element element) {} |
| 77 | 64 |
| 78 Iterable<Feature> get features => const <Feature>[]; | 65 Iterable<Feature> get features => const <Feature>[]; |
| 79 Iterable<DartType> get requiredTypes => const <DartType>[]; | 66 Iterable<DartType> get requiredTypes => const <DartType>[]; |
| 80 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[]; | 67 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[]; |
| 81 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[]; | 68 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[]; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 bool operator ==(other) { | 163 bool operator ==(other) { |
| 177 if (identical(this, other)) return true; | 164 if (identical(this, other)) return true; |
| 178 if (other is! ListLiteralUse) return false; | 165 if (other is! ListLiteralUse) return false; |
| 179 return | 166 return |
| 180 type == other.type && | 167 type == other.type && |
| 181 isConstant == other.isConstant && | 168 isConstant == other.isConstant && |
| 182 isEmpty == other.isEmpty; | 169 isEmpty == other.isEmpty; |
| 183 } | 170 } |
| 184 } | 171 } |
| 185 | 172 |
| 186 /// Mutable implementation of [WorldImpact] used to transform | |
| 187 /// [ResolutionImpact] to [WorldImpact]. | |
| 188 class TransformedWorldImpact implements WorldImpact { | |
| 189 final ResolutionImpact worldImpact; | |
| 190 | |
| 191 Setlet<Element> _staticUses; | |
| 192 Setlet<InterfaceType> _instantiatedTypes; | |
| 193 Setlet<UniverseSelector> _dynamicGetters; | |
| 194 Setlet<UniverseSelector> _dynamicInvocations; | |
| 195 Setlet<UniverseSelector> _dynamicSetters; | |
| 196 | |
| 197 TransformedWorldImpact(this.worldImpact); | |
| 198 | |
| 199 @override | |
| 200 Iterable<DartType> get asCasts => worldImpact.asCasts; | |
| 201 | |
| 202 @override | |
| 203 Iterable<DartType> get checkedModeChecks => worldImpact.checkedModeChecks; | |
| 204 | |
| 205 @override | |
| 206 Iterable<MethodElement> get closurizedFunctions { | |
| 207 return worldImpact.closurizedFunctions; | |
| 208 } | |
| 209 | |
| 210 @override | |
| 211 Iterable<UniverseSelector> get dynamicGetters { | |
| 212 return _dynamicGetters != null | |
| 213 ? _dynamicGetters : worldImpact.dynamicGetters; | |
| 214 } | |
| 215 | |
| 216 @override | |
| 217 Iterable<UniverseSelector> get dynamicInvocations { | |
| 218 return _dynamicInvocations != null | |
| 219 ? _dynamicInvocations : worldImpact.dynamicInvocations; | |
| 220 } | |
| 221 | |
| 222 @override | |
| 223 Iterable<UniverseSelector> get dynamicSetters { | |
| 224 return _dynamicSetters != null | |
| 225 ? _dynamicSetters : worldImpact.dynamicSetters; | |
| 226 } | |
| 227 | |
| 228 @override | |
| 229 Iterable<DartType> get isChecks => worldImpact.isChecks; | |
| 230 | |
| 231 @override | |
| 232 Iterable<DartType> get onCatchTypes => worldImpact.onCatchTypes; | |
| 233 | |
| 234 _unsupported(String message) => throw new UnsupportedError(message); | |
| 235 | |
| 236 void registerDynamicGetter(UniverseSelector selector) { | |
| 237 if (_dynamicGetters == null) { | |
| 238 _dynamicGetters = new Setlet<UniverseSelector>(); | |
| 239 _dynamicGetters.addAll(worldImpact.dynamicGetters); | |
| 240 } | |
| 241 _dynamicGetters.add(selector); | |
| 242 } | |
| 243 | |
| 244 void registerDynamicInvocation(UniverseSelector selector) { | |
| 245 if (_dynamicInvocations == null) { | |
| 246 _dynamicInvocations = new Setlet<UniverseSelector>(); | |
| 247 _dynamicInvocations.addAll(worldImpact.dynamicInvocations); | |
| 248 } | |
| 249 _dynamicInvocations.add(selector); | |
| 250 } | |
| 251 | |
| 252 void registerDynamicSetter(UniverseSelector selector) { | |
| 253 if (_dynamicSetters == null) { | |
| 254 _dynamicSetters = new Setlet<UniverseSelector>(); | |
| 255 _dynamicSetters.addAll(worldImpact.dynamicSetters); | |
| 256 } | |
| 257 _dynamicSetters.add(selector); | |
| 258 } | |
| 259 | |
| 260 void registerInstantiatedType(InterfaceType type) { | |
| 261 if (_instantiatedTypes == null) { | |
| 262 _instantiatedTypes = new Setlet<InterfaceType>(); | |
| 263 _instantiatedTypes.addAll(worldImpact.instantiatedTypes); | |
| 264 } | |
| 265 _instantiatedTypes.add(type); | |
| 266 } | |
| 267 | |
| 268 @override | |
| 269 Iterable<InterfaceType> get instantiatedTypes { | |
| 270 return _instantiatedTypes != null | |
| 271 ? _instantiatedTypes : worldImpact.instantiatedTypes; | |
| 272 } | |
| 273 | |
| 274 @override | |
| 275 Iterable<DartType> get typeLiterals { | |
| 276 return worldImpact.typeLiterals; | |
| 277 } | |
| 278 | |
| 279 void registerStaticUse(Element element) { | |
| 280 if (_staticUses == null) { | |
| 281 _staticUses = new Setlet<Element>(); | |
| 282 _staticUses.addAll(worldImpact.staticUses); | |
| 283 } | |
| 284 _staticUses.add(element); | |
| 285 } | |
| 286 | |
| 287 @override | |
| 288 Iterable<Element> get staticUses { | |
| 289 return _staticUses != null ? _staticUses : worldImpact.staticUses; | |
| 290 } | |
| 291 | |
| 292 @override | |
| 293 Iterable<LocalFunctionElement> get closures => worldImpact.closures; | |
| 294 | |
| 295 String toString() { | |
| 296 StringBuffer sb = new StringBuffer(); | |
| 297 sb.write('TransformedWorldImpact($worldImpact)'); | |
| 298 WorldImpact.printOn(sb, this); | |
| 299 return sb.toString(); | |
| 300 } | |
| 301 } | |
| 302 | |
| 303 // TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`. | 173 // TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`. |
| 304 abstract class Resolution { | 174 abstract class Resolution { |
| 305 Parsing get parsing; | 175 Parsing get parsing; |
| 306 DiagnosticReporter get reporter; | 176 DiagnosticReporter get reporter; |
| 307 CoreTypes get coreTypes; | 177 CoreTypes get coreTypes; |
| 308 | 178 |
| 309 void resolveTypedef(TypedefElement typdef); | 179 void resolveTypedef(TypedefElement typdef); |
| 310 void resolveClass(ClassElement cls); | 180 void resolveClass(ClassElement cls); |
| 311 void registerClass(ClassElement cls); | 181 void registerClass(ClassElement cls); |
| 312 void resolveMetadataAnnotation(MetadataAnnotation metadataAnnotation); | 182 void resolveMetadataAnnotation(MetadataAnnotation metadataAnnotation); |
| 313 FunctionSignature resolveSignature(FunctionElement function); | 183 FunctionSignature resolveSignature(FunctionElement function); |
| 314 DartType resolveTypeAnnotation(Element element, TypeAnnotation node); | 184 DartType resolveTypeAnnotation(Element element, TypeAnnotation node); |
| 315 | 185 |
| 316 bool hasBeenResolved(Element element); | 186 bool hasBeenResolved(Element element); |
| 317 WorldImpact getWorldImpact(Element element); | 187 WorldImpact getWorldImpact(Element element); |
| 318 WorldImpact computeWorldImpact(Element element); | 188 WorldImpact computeWorldImpact(Element element); |
| 319 } | 189 } |
| 320 | 190 |
| 321 // TODO(johnniwinther): Rename to `Parser` or `ParsingContext`. | 191 // TODO(johnniwinther): Rename to `Parser` or `ParsingContext`. |
| 322 abstract class Parsing { | 192 abstract class Parsing { |
| 323 DiagnosticReporter get reporter; | 193 DiagnosticReporter get reporter; |
| 324 void parsePatchClass(ClassElement cls); | 194 void parsePatchClass(ClassElement cls); |
| 325 measure(f()); | 195 measure(f()); |
| 326 ScannerOptions getScannerOptionsFor(Element element); | 196 ScannerOptions getScannerOptionsFor(Element element); |
| 327 } | 197 } |
| OLD | NEW |