| 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.common.resolution; | 5 library dart2js.common.resolution; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../compile_time_constants.dart'; | 8 import '../compile_time_constants.dart'; |
| 9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
| 10 import '../constants/expressions.dart' show ConstantExpression; | 10 import '../constants/expressions.dart' show ConstantExpression; |
| 11 import '../constants/values.dart' show ConstantValue; | 11 import '../constants/values.dart' show ConstantValue; |
| 12 import '../core_types.dart' show CoreClasses, CoreTypes; | 12 import '../core_types.dart' show CoreClasses, CoreTypes; |
| 13 import '../dart_types.dart' show DartType, InterfaceType, Types; | 13 import '../dart_types.dart' show DartType, Types; |
| 14 import '../elements/elements.dart' | 14 import '../elements/elements.dart' |
| 15 show | 15 show |
| 16 AstElement, | 16 AstElement, |
| 17 ClassElement, | 17 ClassElement, |
| 18 ConstructorElement, | 18 ConstructorElement, |
| 19 Element, | 19 Element, |
| 20 ExecutableElement, | 20 ExecutableElement, |
| 21 FunctionElement, | 21 FunctionElement, |
| 22 FunctionSignature, | 22 FunctionSignature, |
| 23 LibraryElement, | 23 LibraryElement, |
| 24 MetadataAnnotation, | 24 MetadataAnnotation, |
| 25 MethodElement, | 25 MethodElement, |
| 26 ResolvedAst, | 26 ResolvedAst, |
| 27 TypedefElement; | 27 TypedefElement; |
| 28 import '../enqueue.dart' show ResolutionEnqueuer; | 28 import '../enqueue.dart' show ResolutionEnqueuer; |
| 29 import '../id_generator.dart'; | 29 import '../id_generator.dart'; |
| 30 import '../mirrors_used.dart'; | 30 import '../mirrors_used.dart'; |
| 31 import '../options.dart' show CompilerOptions, ParserOptions; | 31 import '../options.dart' show CompilerOptions, ParserOptions; |
| 32 import '../parser/element_listener.dart' show ScannerOptions; | 32 import '../parser/element_listener.dart' show ScannerOptions; |
| 33 import '../parser/parser_task.dart'; | 33 import '../parser/parser_task.dart'; |
| 34 import '../patch_parser.dart'; | 34 import '../patch_parser.dart'; |
| 35 import '../resolution/resolution.dart'; | 35 import '../resolution/resolution.dart'; |
| 36 import '../tree/tree.dart' show Send, TypeAnnotation; | 36 import '../tree/tree.dart' show Send, TypeAnnotation; |
| 37 import '../universe/call_structure.dart' show CallStructure; | 37 import '../universe/call_structure.dart' show CallStructure; |
| 38 import '../universe/world_impact.dart' show WorldImpact; | 38 import '../universe/world_impact.dart' show WorldImpact; |
| 39 import '../universe/feature.dart'; |
| 39 import 'backend_api.dart'; | 40 import 'backend_api.dart'; |
| 40 import 'work.dart' show ItemCompilationContext, WorkItem; | 41 import 'work.dart' show ItemCompilationContext, WorkItem; |
| 41 | 42 |
| 42 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. | 43 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. |
| 43 class ResolutionWorkItem extends WorkItem { | 44 class ResolutionWorkItem extends WorkItem { |
| 44 bool _isAnalyzed = false; | 45 bool _isAnalyzed = false; |
| 45 | 46 |
| 46 ResolutionWorkItem( | 47 ResolutionWorkItem( |
| 47 AstElement element, ItemCompilationContext compilationContext) | 48 AstElement element, ItemCompilationContext compilationContext) |
| 48 : super(element, compilationContext); | 49 : super(element, compilationContext); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 62 Iterable<Feature> get features => const <Feature>[]; | 63 Iterable<Feature> get features => const <Feature>[]; |
| 63 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[]; | 64 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[]; |
| 64 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[]; | 65 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[]; |
| 65 Iterable<String> get constSymbolNames => const <String>[]; | 66 Iterable<String> get constSymbolNames => const <String>[]; |
| 66 Iterable<ConstantExpression> get constantLiterals => | 67 Iterable<ConstantExpression> get constantLiterals => |
| 67 const <ConstantExpression>[]; | 68 const <ConstantExpression>[]; |
| 68 | 69 |
| 69 Iterable<dynamic> get nativeData => const <dynamic>[]; | 70 Iterable<dynamic> get nativeData => const <dynamic>[]; |
| 70 } | 71 } |
| 71 | 72 |
| 72 /// A language feature seen during resolution. | |
| 73 // TODO(johnniwinther): Should mirror usage be part of this? | |
| 74 enum Feature { | |
| 75 /// Invocation of a generative construction on an abstract class. | |
| 76 ABSTRACT_CLASS_INSTANTIATION, | |
| 77 | |
| 78 /// An assert statement with no message. | |
| 79 ASSERT, | |
| 80 | |
| 81 /// An assert statement with a message. | |
| 82 ASSERT_WITH_MESSAGE, | |
| 83 | |
| 84 /// A method with an `async` body modifier. | |
| 85 ASYNC, | |
| 86 | |
| 87 /// An asynchronous for in statement like `await for (var e in i) {}`. | |
| 88 ASYNC_FOR_IN, | |
| 89 | |
| 90 /// A method with an `async*` body modifier. | |
| 91 ASYNC_STAR, | |
| 92 | |
| 93 /// A catch statement. | |
| 94 CATCH_STATEMENT, | |
| 95 | |
| 96 /// A compile time error. | |
| 97 COMPILE_TIME_ERROR, | |
| 98 | |
| 99 /// A fall through in a switch case. | |
| 100 FALL_THROUGH_ERROR, | |
| 101 | |
| 102 /// A ++/-- operation. | |
| 103 INC_DEC_OPERATION, | |
| 104 | |
| 105 /// A field whose initialization is not a constant. | |
| 106 LAZY_FIELD, | |
| 107 | |
| 108 /// A catch clause with a variable for the stack trace. | |
| 109 STACK_TRACE_IN_CATCH, | |
| 110 | |
| 111 /// String interpolation. | |
| 112 STRING_INTERPOLATION, | |
| 113 | |
| 114 /// String juxtaposition. | |
| 115 STRING_JUXTAPOSITION, | |
| 116 | |
| 117 /// An implicit call to `super.noSuchMethod`, like calling an unresolved | |
| 118 /// super method. | |
| 119 SUPER_NO_SUCH_METHOD, | |
| 120 | |
| 121 /// A redirection to the `Symbol` constructor. | |
| 122 SYMBOL_CONSTRUCTOR, | |
| 123 | |
| 124 /// An synchronous for in statement, like `for (var e in i) {}`. | |
| 125 SYNC_FOR_IN, | |
| 126 | |
| 127 /// A method with a `sync*` body modifier. | |
| 128 SYNC_STAR, | |
| 129 | |
| 130 /// A throw expression. | |
| 131 THROW_EXPRESSION, | |
| 132 | |
| 133 /// An implicit throw of a `NoSuchMethodError`, like calling an unresolved | |
| 134 /// static method. | |
| 135 THROW_NO_SUCH_METHOD, | |
| 136 | |
| 137 /// An implicit throw of a runtime error, like | |
| 138 THROW_RUNTIME_ERROR, | |
| 139 | |
| 140 /// The need for a type variable bound check, like instantiation of a generic | |
| 141 /// type whose type variable have non-trivial bounds. | |
| 142 TYPE_VARIABLE_BOUNDS_CHECK, | |
| 143 } | |
| 144 | |
| 145 /// A use of a map literal seen during resolution. | |
| 146 class MapLiteralUse { | |
| 147 final InterfaceType type; | |
| 148 final bool isConstant; | |
| 149 final bool isEmpty; | |
| 150 | |
| 151 MapLiteralUse(this.type, {this.isConstant: false, this.isEmpty: false}); | |
| 152 | |
| 153 int get hashCode { | |
| 154 return type.hashCode * 13 + | |
| 155 isConstant.hashCode * 17 + | |
| 156 isEmpty.hashCode * 19; | |
| 157 } | |
| 158 | |
| 159 bool operator ==(other) { | |
| 160 if (identical(this, other)) return true; | |
| 161 if (other is! MapLiteralUse) return false; | |
| 162 return type == other.type && | |
| 163 isConstant == other.isConstant && | |
| 164 isEmpty == other.isEmpty; | |
| 165 } | |
| 166 | |
| 167 String toString() { | |
| 168 return 'MapLiteralUse($type,isConstant:$isConstant,isEmpty:$isEmpty)'; | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 /// A use of a list literal seen during resolution. | |
| 173 class ListLiteralUse { | |
| 174 final InterfaceType type; | |
| 175 final bool isConstant; | |
| 176 final bool isEmpty; | |
| 177 | |
| 178 ListLiteralUse(this.type, {this.isConstant: false, this.isEmpty: false}); | |
| 179 | |
| 180 int get hashCode { | |
| 181 return type.hashCode * 13 + | |
| 182 isConstant.hashCode * 17 + | |
| 183 isEmpty.hashCode * 19; | |
| 184 } | |
| 185 | |
| 186 bool operator ==(other) { | |
| 187 if (identical(this, other)) return true; | |
| 188 if (other is! ListLiteralUse) return false; | |
| 189 return type == other.type && | |
| 190 isConstant == other.isConstant && | |
| 191 isEmpty == other.isEmpty; | |
| 192 } | |
| 193 | |
| 194 String toString() { | |
| 195 return 'ListLiteralUse($type,isConstant:$isConstant,isEmpty:$isEmpty)'; | |
| 196 } | |
| 197 } | |
| 198 | 73 |
| 199 /// Interface for the accessing the front-end analysis. | 74 /// Interface for the accessing the front-end analysis. |
| 200 // TODO(johnniwinther): Find a better name for this. | 75 // TODO(johnniwinther): Find a better name for this. |
| 201 abstract class Frontend { | 76 abstract class Frontend { |
| 202 /// Returns the [ResolutionImpact] for [element]. | 77 /// Returns the [ResolutionImpact] for [element]. |
| 203 ResolutionImpact getResolutionImpact(Element element); | 78 ResolutionImpact getResolutionImpact(Element element); |
| 204 } | 79 } |
| 205 | 80 |
| 206 /// Interface defining target-specific behavior for resolution. | 81 /// Interface defining target-specific behavior for resolution. |
| 207 abstract class Target { | 82 abstract class Target { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 if (cls.isPatch) { | 259 if (cls.isPatch) { |
| 385 patchParser.parsePatchClassNode(cls); | 260 patchParser.parsePatchClassNode(cls); |
| 386 } | 261 } |
| 387 }); | 262 }); |
| 388 } | 263 } |
| 389 | 264 |
| 390 @override | 265 @override |
| 391 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( | 266 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( |
| 392 canUseNative: backend.canLibraryUseNative(element.library)); | 267 canUseNative: backend.canLibraryUseNative(element.library)); |
| 393 } | 268 } |
| OLD | NEW |