| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 part of world_builder; | 5 part of world_builder; |
| 6 | 6 |
| 7 /// World builder specific to codegen. | 7 /// World builder specific to codegen. |
| 8 /// | 8 /// |
| 9 /// This adds additional access to liveness of selectors and elements. | 9 /// This adds additional access to liveness of selectors and elements. |
| 10 abstract class CodegenWorldBuilder implements WorldBuilder { | 10 abstract class CodegenWorldBuilder implements WorldBuilder { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 /// The set of all referenced static fields. | 44 /// The set of all referenced static fields. |
| 45 /// | 45 /// |
| 46 /// Invariant: Elements are declaration elements. | 46 /// Invariant: Elements are declaration elements. |
| 47 Iterable<FieldElement> get allReferencedStaticFields; | 47 Iterable<FieldElement> get allReferencedStaticFields; |
| 48 } | 48 } |
| 49 | 49 |
| 50 class CodegenWorldBuilderImpl implements CodegenWorldBuilder { | 50 class CodegenWorldBuilderImpl implements CodegenWorldBuilder { |
| 51 final NativeClassData _nativeData; | 51 final NativeClassData _nativeData; |
| 52 final ClosedWorld _world; | 52 final ClosedWorld _world; |
| 53 final JavaScriptConstantCompiler _constants; |
| 53 | 54 |
| 54 /// The set of all directly instantiated classes, that is, classes with a | 55 /// The set of all directly instantiated classes, that is, classes with a |
| 55 /// generative constructor that has been called directly and not only through | 56 /// generative constructor that has been called directly and not only through |
| 56 /// a super-call. | 57 /// a super-call. |
| 57 /// | 58 /// |
| 58 /// Invariant: Elements are declaration elements. | 59 /// Invariant: Elements are declaration elements. |
| 59 // TODO(johnniwinther): [_directlyInstantiatedClasses] and | 60 // TODO(johnniwinther): [_directlyInstantiatedClasses] and |
| 60 // [_instantiatedTypes] sets should be merged. | 61 // [_instantiatedTypes] sets should be merged. |
| 61 final Set<ClassElement> _directlyInstantiatedClasses = | 62 final Set<ClassElement> _directlyInstantiatedClasses = |
| 62 new Set<ClassElement>(); | 63 new Set<ClassElement>(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 110 |
| 110 /// Map containing instance methods of live classes that are not yet | 111 /// Map containing instance methods of live classes that are not yet |
| 111 /// closurized. | 112 /// closurized. |
| 112 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = | 113 final Map<String, Set<_MemberUsage>> _instanceFunctionsByName = |
| 113 <String, Set<_MemberUsage>>{}; | 114 <String, Set<_MemberUsage>>{}; |
| 114 | 115 |
| 115 final Set<ResolutionDartType> isChecks = new Set<ResolutionDartType>(); | 116 final Set<ResolutionDartType> isChecks = new Set<ResolutionDartType>(); |
| 116 | 117 |
| 117 final SelectorConstraintsStrategy selectorConstraintsStrategy; | 118 final SelectorConstraintsStrategy selectorConstraintsStrategy; |
| 118 | 119 |
| 119 CodegenWorldBuilderImpl( | 120 final Set<ConstantValue> _constantValues = new Set<ConstantValue>(); |
| 120 this._nativeData, this._world, this.selectorConstraintsStrategy); | 121 |
| 122 CodegenWorldBuilderImpl(this._nativeData, this._world, this._constants, |
| 123 this.selectorConstraintsStrategy); |
| 121 | 124 |
| 122 /// Calls [f] with every instance field, together with its declarer, in an | 125 /// Calls [f] with every instance field, together with its declarer, in an |
| 123 /// instance of [cls]. | 126 /// instance of [cls]. |
| 124 void forEachInstanceField( | 127 void forEachInstanceField( |
| 125 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) { | 128 ClassElement cls, void f(ClassEntity declarer, FieldEntity field)) { |
| 126 cls.implementation | 129 cls.implementation |
| 127 .forEachInstanceField(f, includeSuperAndInjectedMembers: true); | 130 .forEachInstanceField(f, includeSuperAndInjectedMembers: true); |
| 128 } | 131 } |
| 129 | 132 |
| 130 @override | 133 @override |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 classUsed(usage.cls, usage.instantiate()); | 478 classUsed(usage.cls, usage.instantiate()); |
| 476 return true; | 479 return true; |
| 477 } | 480 } |
| 478 return false; | 481 return false; |
| 479 } | 482 } |
| 480 | 483 |
| 481 while (cls != null && processClass(cls)) { | 484 while (cls != null && processClass(cls)) { |
| 482 cls = cls.superclass; | 485 cls = cls.superclass; |
| 483 } | 486 } |
| 484 } | 487 } |
| 488 |
| 489 /// Register the constant [use] with this world builder. Returns `true` if |
| 490 /// the constant use was new to the world. |
| 491 bool registerConstantUse(ConstantUse use) { |
| 492 if (use.kind == ConstantUseKind.DIRECT) { |
| 493 _constants.addCompileTimeConstantForEmission(use.value); |
| 494 } |
| 495 return _constantValues.add(use.value); |
| 496 } |
| 485 } | 497 } |
| OLD | NEW |