| 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 '../compiler.dart' show | 8 import '../compiler.dart' show |
| 9 Compiler; | 9 Compiler; |
| 10 import '../core_types.dart' show | 10 import '../core_types.dart' show |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return impact; | 58 return impact; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool get isAnalyzed => _isAnalyzed; | 61 bool get isAnalyzed => _isAnalyzed; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // TODO(johnniwinther): Rename this to something like `BackendResolutionApi` | 64 // TODO(johnniwinther): Rename this to something like `BackendResolutionApi` |
| 65 // and clean up the interface. | 65 // and clean up the interface. |
| 66 /// Backend callbacks function specific to the resolution phase. | 66 /// Backend callbacks function specific to the resolution phase. |
| 67 class ResolutionCallbacks { | 67 class ResolutionCallbacks { |
| 68 /// | 68 /// Transform the [ResolutionWorldImpact] into a [WorldImpact] adding the |
| 69 /// backend dependencies for features used in [worldImpact]. |
| 69 WorldImpact transformImpact(ResolutionWorldImpact worldImpact) => worldImpact; | 70 WorldImpact transformImpact(ResolutionWorldImpact worldImpact) => worldImpact; |
| 70 | |
| 71 /// Register that an assert has been seen. | |
| 72 void onAssert(bool hasMessage, Registry registry) {} | |
| 73 | |
| 74 /// Register that an 'await for' has been seen. | |
| 75 void onAsyncForIn(AsyncForIn node, Registry registry) {} | |
| 76 | |
| 77 /// Called during resolution to notify to the backend that the | |
| 78 /// program uses string interpolation. | |
| 79 void onStringInterpolation(Registry registry) {} | |
| 80 | |
| 81 /// Called during resolution to notify to the backend that the | |
| 82 /// program has a catch statement. | |
| 83 void onCatchStatement(Registry registry) {} | |
| 84 | |
| 85 /// Called during resolution to notify to the backend that the | |
| 86 /// program explicitly throws an exception. | |
| 87 void onThrowExpression(Registry registry) {} | |
| 88 | |
| 89 /// Called during resolution to notify to the backend that the | |
| 90 /// program has a global variable with a lazy initializer. | |
| 91 void onLazyField(Registry registry) {} | |
| 92 | |
| 93 /// Called during resolution to notify to the backend that the | |
| 94 /// program uses a type variable as an expression. | |
| 95 void onTypeVariableExpression(Registry registry, | |
| 96 TypeVariableElement variable) {} | |
| 97 | |
| 98 /// Called during resolution to notify to the backend that the | |
| 99 /// program uses a type literal. | |
| 100 void onTypeLiteral(DartType type, Registry registry) {} | |
| 101 | |
| 102 /// Called during resolution to notify to the backend that the | |
| 103 /// program has a catch statement with a stack trace. | |
| 104 void onStackTraceInCatch(Registry registry) {} | |
| 105 | |
| 106 /// Register an is check to the backend. | |
| 107 void onIsCheck(DartType type, Registry registry) {} | |
| 108 | |
| 109 /// Called during resolution to notify to the backend that the | |
| 110 /// program has a for-in loop. | |
| 111 void onSyncForIn(Registry registry) {} | |
| 112 | |
| 113 /// Register an as check to the backend. | |
| 114 void onAsCheck(DartType type, Registry registry) {} | |
| 115 | |
| 116 /// Registers that a type variable bounds check might occur at runtime. | |
| 117 void onTypeVariableBoundCheck(Registry registry) {} | |
| 118 | |
| 119 /// Register that the application may throw a [NoSuchMethodError]. | |
| 120 void onThrowNoSuchMethod(Registry registry) {} | |
| 121 | |
| 122 /// Register that the application may throw a [RuntimeError]. | |
| 123 void onThrowRuntimeError(Registry registry) {} | |
| 124 | |
| 125 /// Register that the application has a compile time error. | |
| 126 void onCompileTimeError(Registry registry, ErroneousElement error) {} | |
| 127 | |
| 128 /// Register that the application may throw an | |
| 129 /// [AbstractClassInstantiationError]. | |
| 130 void onAbstractClassInstantiation(Registry registry) {} | |
| 131 | |
| 132 /// Register that the application may throw a [FallThroughError]. | |
| 133 void onFallThroughError(Registry registry) {} | |
| 134 | |
| 135 /// Register that a super call will end up calling | |
| 136 /// [: super.noSuchMethod :]. | |
| 137 void onSuperNoSuchMethod(Registry registry) {} | |
| 138 | |
| 139 /// Register that the application creates a constant map. | |
| 140 void onMapLiteral(Registry registry, DartType type, bool isConstant) {} | |
| 141 | |
| 142 /// Called when resolving the `Symbol` constructor. | |
| 143 void onSymbolConstructor(Registry registry) {} | |
| 144 | |
| 145 /// Called when resolving a prefix or postfix expression. | |
| 146 void onIncDecOperation(Registry registry) {} | |
| 147 } | 71 } |
| 148 | 72 |
| 149 class ResolutionWorldImpact extends WorldImpact { | 73 class ResolutionWorldImpact extends WorldImpact { |
| 150 const ResolutionWorldImpact(); | 74 const ResolutionWorldImpact(); |
| 151 | 75 |
| 152 // TODO(johnniwinther): Remove this. | 76 // TODO(johnniwinther): Remove this. |
| 153 void registerDependency(Element element) {} | 77 void registerDependency(Element element) {} |
| 154 | 78 |
| 155 Iterable<Feature> get features => const <Feature>[]; | 79 Iterable<Feature> get features => const <Feature>[]; |
| 156 Iterable<DartType> get requiredTypes => const <DartType>[]; | 80 Iterable<DartType> get requiredTypes => const <DartType>[]; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 178 /// A catch statement. | 102 /// A catch statement. |
| 179 CATCH_STATEMENT, | 103 CATCH_STATEMENT, |
| 180 /// A compile time error. | 104 /// A compile time error. |
| 181 COMPILE_TIME_ERROR, | 105 COMPILE_TIME_ERROR, |
| 182 /// A fall through in a switch case. | 106 /// A fall through in a switch case. |
| 183 FALL_THROUGH_ERROR, | 107 FALL_THROUGH_ERROR, |
| 184 /// A ++/-- operation. | 108 /// A ++/-- operation. |
| 185 INC_DEC_OPERATION, | 109 INC_DEC_OPERATION, |
| 186 /// A field whose initialization is not a constant. | 110 /// A field whose initialization is not a constant. |
| 187 LAZY_FIELD, | 111 LAZY_FIELD, |
| 188 /// A call to `new Symbol`. | |
| 189 NEW_SYMBOL, | |
| 190 /// A catch clause with a variable for the stack trace. | 112 /// A catch clause with a variable for the stack trace. |
| 191 STACK_TRACE_IN_CATCH, | 113 STACK_TRACE_IN_CATCH, |
| 192 /// String interpolation. | 114 /// String interpolation. |
| 193 STRING_INTERPOLATION, | 115 STRING_INTERPOLATION, |
| 194 /// An implicit call to `super.noSuchMethod`, like calling an unresolved | 116 /// An implicit call to `super.noSuchMethod`, like calling an unresolved |
| 195 /// super method. | 117 /// super method. |
| 196 SUPER_NO_SUCH_METHOD, | 118 SUPER_NO_SUCH_METHOD, |
| 197 /// A redirection to the `Symbol` constructor. | 119 /// A redirection to the `Symbol` constructor. |
| 198 SYMBOL_CONSTRUCTOR, | 120 SYMBOL_CONSTRUCTOR, |
| 199 /// An synchronous for in statement, like `for (var e in i) {}`. | 121 /// An synchronous for in statement, like `for (var e in i) {}`. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 type == other.type && | 181 type == other.type && |
| 260 isConstant == other.isConstant && | 182 isConstant == other.isConstant && |
| 261 isEmpty == other.isEmpty; | 183 isEmpty == other.isEmpty; |
| 262 } | 184 } |
| 263 } | 185 } |
| 264 | 186 |
| 265 /// Mutable implementation of [WorldImpact] used to transform | 187 /// Mutable implementation of [WorldImpact] used to transform |
| 266 /// [ResolutionWorldImpact] to [WorldImpact]. | 188 /// [ResolutionWorldImpact] to [WorldImpact]. |
| 267 // TODO(johnniwinther): Remove [Registry] when dependency is tracked directly | 189 // TODO(johnniwinther): Remove [Registry] when dependency is tracked directly |
| 268 // on [WorldImpact]. | 190 // on [WorldImpact]. |
| 269 class TransformedWorldImpact implements WorldImpact, Registry { | 191 class TransformedWorldImpact implements WorldImpact { |
| 270 final ResolutionWorldImpact worldImpact; | 192 final ResolutionWorldImpact worldImpact; |
| 271 | 193 |
| 272 Setlet<Element> _staticUses; | 194 Setlet<Element> _staticUses; |
| 273 Setlet<InterfaceType> _instantiatedTypes; | 195 Setlet<InterfaceType> _instantiatedTypes; |
| 274 Setlet<UniverseSelector> _dynamicGetters; | 196 Setlet<UniverseSelector> _dynamicGetters; |
| 275 Setlet<UniverseSelector> _dynamicInvocations; | 197 Setlet<UniverseSelector> _dynamicInvocations; |
| 276 Setlet<UniverseSelector> _dynamicSetters; | 198 Setlet<UniverseSelector> _dynamicSetters; |
| 277 | 199 |
| 278 TransformedWorldImpact(this.worldImpact); | 200 TransformedWorldImpact(this.worldImpact); |
| 279 | 201 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 310 Iterable<DartType> get isChecks => worldImpact.isChecks; | 232 Iterable<DartType> get isChecks => worldImpact.isChecks; |
| 311 | 233 |
| 312 @override | 234 @override |
| 313 Iterable<Element> get staticUses { | 235 Iterable<Element> get staticUses { |
| 314 if (_staticUses == null) { | 236 if (_staticUses == null) { |
| 315 return worldImpact.staticUses; | 237 return worldImpact.staticUses; |
| 316 } | 238 } |
| 317 return _staticUses; | 239 return _staticUses; |
| 318 } | 240 } |
| 319 | 241 |
| 320 @override | |
| 321 bool get isForResolution => true; | |
| 322 | |
| 323 _unsupported(String message) => throw new UnsupportedError(message); | 242 _unsupported(String message) => throw new UnsupportedError(message); |
| 324 | 243 |
| 325 @override | |
| 326 Iterable<Element> get otherDependencies => _unsupported('otherDependencies'); | |
| 327 | |
| 328 // TODO(johnniwinther): Remove this. | |
| 329 @override | |
| 330 void registerAssert(bool hasMessage) => _unsupported('registerAssert'); | |
| 331 | |
| 332 @override | |
| 333 void registerDependency(Element element) { | |
| 334 worldImpact.registerDependency(element); | |
| 335 } | |
| 336 | |
| 337 @override | |
| 338 void registerDynamicGetter(UniverseSelector selector) { | 244 void registerDynamicGetter(UniverseSelector selector) { |
| 339 if (_dynamicGetters == null) { | 245 if (_dynamicGetters == null) { |
| 340 _dynamicGetters = new Setlet<UniverseSelector>(); | 246 _dynamicGetters = new Setlet<UniverseSelector>(); |
| 341 _dynamicGetters.addAll(worldImpact.dynamicGetters); | 247 _dynamicGetters.addAll(worldImpact.dynamicGetters); |
| 342 } | 248 } |
| 343 _dynamicGetters.add(selector); | 249 _dynamicGetters.add(selector); |
| 344 } | 250 } |
| 345 | 251 |
| 346 @override | |
| 347 void registerDynamicInvocation(UniverseSelector selector) { | 252 void registerDynamicInvocation(UniverseSelector selector) { |
| 348 if (_dynamicInvocations == null) { | 253 if (_dynamicInvocations == null) { |
| 349 _dynamicInvocations = new Setlet<UniverseSelector>(); | 254 _dynamicInvocations = new Setlet<UniverseSelector>(); |
| 350 _dynamicInvocations.addAll(worldImpact.dynamicInvocations); | 255 _dynamicInvocations.addAll(worldImpact.dynamicInvocations); |
| 351 } | 256 } |
| 352 _dynamicInvocations.add(selector); | 257 _dynamicInvocations.add(selector); |
| 353 } | 258 } |
| 354 | 259 |
| 355 @override | |
| 356 void registerDynamicSetter(UniverseSelector selector) { | 260 void registerDynamicSetter(UniverseSelector selector) { |
| 357 if (_dynamicSetters == null) { | 261 if (_dynamicSetters == null) { |
| 358 _dynamicSetters = new Setlet<UniverseSelector>(); | 262 _dynamicSetters = new Setlet<UniverseSelector>(); |
| 359 _dynamicSetters.addAll(worldImpact.dynamicSetters); | 263 _dynamicSetters.addAll(worldImpact.dynamicSetters); |
| 360 } | 264 } |
| 361 _dynamicSetters.add(selector); | 265 _dynamicSetters.add(selector); |
| 362 } | 266 } |
| 363 | 267 |
| 364 @override | 268 void registerInstantiatedType(InterfaceType type) { |
| 365 void registerGetOfStaticFunction(FunctionElement element) { | |
| 366 _unsupported('registerGetOfStaticFunction($element)'); | |
| 367 } | |
| 368 | |
| 369 @override | |
| 370 void registerInstantiation(InterfaceType type) { | |
| 371 // TODO(johnniwinther): Remove this when dependency tracking is done on | 269 // TODO(johnniwinther): Remove this when dependency tracking is done on |
| 372 // the world impact itself. | 270 // the world impact itself. |
| 373 registerDependency(type.element); | 271 worldImpact.registerDependency(type.element); |
| 374 if (_instantiatedTypes == null) { | 272 if (_instantiatedTypes == null) { |
| 375 _instantiatedTypes = new Setlet<InterfaceType>(); | 273 _instantiatedTypes = new Setlet<InterfaceType>(); |
| 376 } | 274 } |
| 377 _instantiatedTypes.add(type); | 275 _instantiatedTypes.add(type); |
| 378 } | 276 } |
| 379 | 277 |
| 380 @override | 278 @override |
| 381 Iterable<InterfaceType> get instantiatedTypes { | 279 Iterable<InterfaceType> get instantiatedTypes { |
| 382 return _instantiatedTypes != null | 280 return _instantiatedTypes != null |
| 383 ? _instantiatedTypes : const <InterfaceType>[]; | 281 ? _instantiatedTypes : const <InterfaceType>[]; |
| 384 } | 282 } |
| 385 | 283 |
| 386 @override | 284 void registerStaticUse(Element element) { |
| 387 void registerStaticInvocation(Element element) { | |
| 388 // TODO(johnniwinther): Remove this when dependency tracking is done on | 285 // TODO(johnniwinther): Remove this when dependency tracking is done on |
| 389 // the world impact itself. | 286 // the world impact itself. |
| 390 registerDependency(element); | 287 worldImpact.registerDependency(element); |
| 391 if (_staticUses == null) { | 288 if (_staticUses == null) { |
| 392 _staticUses = new Setlet<Element>(); | 289 _staticUses = new Setlet<Element>(); |
| 393 } | 290 } |
| 394 _staticUses.add(element); | 291 _staticUses.add(element); |
| 395 } | 292 } |
| 396 | 293 |
| 397 @override | 294 @override |
| 398 Iterable<LocalFunctionElement> get closures => worldImpact.closures; | 295 Iterable<LocalFunctionElement> get closures => worldImpact.closures; |
| 399 } | 296 } |
| 400 | 297 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 414 bool hasBeenResolved(Element element); | 311 bool hasBeenResolved(Element element); |
| 415 ResolutionWorldImpact analyzeElement(Element element); | 312 ResolutionWorldImpact analyzeElement(Element element); |
| 416 } | 313 } |
| 417 | 314 |
| 418 // TODO(johnniwinther): Rename to `Parser` or `ParsingContext`. | 315 // TODO(johnniwinther): Rename to `Parser` or `ParsingContext`. |
| 419 abstract class Parsing { | 316 abstract class Parsing { |
| 420 DiagnosticReporter get reporter; | 317 DiagnosticReporter get reporter; |
| 421 void parsePatchClass(ClassElement cls); | 318 void parsePatchClass(ClassElement cls); |
| 422 measure(f()); | 319 measure(f()); |
| 423 } | 320 } |
| OLD | NEW |