Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // TODO(sigmund): rename and move to common/elements.dart | 5 // TODO(sigmund): rename and move to common/elements.dart |
| 6 library dart2js.type_system; | 6 library dart2js.type_system; |
| 7 | 7 |
| 8 import 'common/names.dart' show Uris; | 8 import 'common/names.dart' show Identifiers, Uris; |
| 9 import 'js_backend/constant_system_javascript.dart'; | |
| 9 import 'elements/types.dart'; | 10 import 'elements/types.dart'; |
| 11 import 'elements/elements.dart' show PublicName; | |
| 10 import 'elements/entities.dart'; | 12 import 'elements/entities.dart'; |
| 13 import 'js_backend/backend.dart' show JavaScriptBackend; | |
| 14 import 'universe/call_structure.dart' show CallStructure; | |
| 15 import 'universe/selector.dart' show Selector; | |
| 11 import 'universe/call_structure.dart'; | 16 import 'universe/call_structure.dart'; |
| 12 | 17 |
| 13 /// The common elements and types in Dart. | 18 /// The common elements and types in Dart. |
| 14 abstract class CommonElements { | 19 class CommonElements { |
| 20 final ElementEnvironment _env; | |
| 21 | |
| 22 CommonElements(this._env); | |
| 23 | |
| 15 /// The `Object` class defined in 'dart:core'. | 24 /// The `Object` class defined in 'dart:core'. |
| 16 ClassEntity get objectClass; | 25 ClassEntity _objectClass; |
| 26 ClassEntity get objectClass => | |
| 27 _objectClass ??= _findClass(coreLibrary, 'Object'); | |
| 17 | 28 |
| 18 /// The `bool` class defined in 'dart:core'. | 29 /// The `bool` class defined in 'dart:core'. |
| 19 ClassEntity get boolClass; | 30 ClassEntity _boolClass; |
| 31 ClassEntity get boolClass => _boolClass ??= _findClass(coreLibrary, 'bool'); | |
| 20 | 32 |
| 21 /// The `num` class defined in 'dart:core'. | 33 /// The `num` class defined in 'dart:core'. |
| 22 ClassEntity get numClass; | 34 ClassEntity _numClass; |
| 35 ClassEntity get numClass => _numClass ??= _findClass(coreLibrary, 'num'); | |
| 23 | 36 |
| 24 /// The `int` class defined in 'dart:core'. | 37 /// The `int` class defined in 'dart:core'. |
| 25 ClassEntity get intClass; | 38 ClassEntity _intClass; |
| 39 ClassEntity get intClass => _intClass ??= _findClass(coreLibrary, 'int'); | |
| 26 | 40 |
| 27 /// The `double` class defined in 'dart:core'. | 41 /// The `double` class defined in 'dart:core'. |
| 28 ClassEntity get doubleClass; | 42 ClassEntity _doubleClass; |
| 43 ClassEntity get doubleClass => | |
| 44 _doubleClass ??= _findClass(coreLibrary, 'double'); | |
| 45 | |
| 46 /// The `String` class defined in 'dart:core'. | |
| 47 ClassEntity _stringClass; | |
| 48 ClassEntity get stringClass => | |
| 49 _stringClass ??= _findClass(coreLibrary, 'String'); | |
| 50 | |
| 51 /// The `Function` class defined in 'dart:core'. | |
| 52 ClassEntity _functionClass; | |
| 53 ClassEntity get functionClass => | |
| 54 _functionClass ??= _findClass(coreLibrary, 'Function'); | |
| 29 | 55 |
| 30 /// The `Resource` class defined in 'dart:core'. | 56 /// The `Resource` class defined in 'dart:core'. |
| 31 ClassEntity get resourceClass; | 57 ClassEntity _resourceClass; |
| 32 | 58 ClassEntity get resourceClass => |
| 33 /// The `String` class defined in 'dart:core'. | 59 _resourceClass ??= _findClass(coreLibrary, 'Resource'); |
| 34 ClassEntity get stringClass; | |
| 35 | 60 |
| 36 /// The `Symbol` class defined in 'dart:core'. | 61 /// The `Symbol` class defined in 'dart:core'. |
| 37 ClassEntity get symbolClass; | 62 ClassEntity _symbolClass; |
| 38 | 63 ClassEntity get symbolClass => |
| 39 /// The `Function` class defined in 'dart:core'. | 64 _symbolClass ??= _findClass(coreLibrary, 'Symbol'); |
| 40 ClassEntity get functionClass; | |
| 41 | 65 |
| 42 /// The `Null` class defined in 'dart:core'. | 66 /// The `Null` class defined in 'dart:core'. |
| 43 ClassEntity get nullClass; | 67 ClassEntity _nullClass; |
| 68 ClassEntity get nullClass => _nullClass ??= _findClass(coreLibrary, 'Null'); | |
| 44 | 69 |
| 45 /// The `Type` class defined in 'dart:core'. | 70 /// The `Type` class defined in 'dart:core'. |
| 46 ClassEntity get typeClass; | 71 ClassEntity _typeClass; |
| 72 ClassEntity get typeClass => _typeClass ??= _findClass(coreLibrary, 'Type'); | |
| 47 | 73 |
| 48 /// The `StackTrace` class defined in 'dart:core'; | 74 /// The `StackTrace` class defined in 'dart:core'; |
| 49 ClassEntity get stackTraceClass; | 75 ClassEntity _stackTraceClass; |
| 76 ClassEntity get stackTraceClass => | |
| 77 _stackTraceClass ??= _findClass(coreLibrary, 'StackTrace'); | |
| 50 | 78 |
| 51 /// The `List` class defined in 'dart:core'; | 79 /// The `List` class defined in 'dart:core'; |
| 52 ClassEntity get listClass; | 80 ClassEntity _listClass; |
| 81 ClassEntity get listClass => _listClass ??= _findClass(coreLibrary, 'List'); | |
| 53 | 82 |
| 54 /// The `Map` class defined in 'dart:core'; | 83 /// The `Map` class defined in 'dart:core'; |
| 55 ClassEntity get mapClass; | 84 ClassEntity _mapClass; |
| 85 ClassEntity get mapClass => _mapClass ??= _findClass(coreLibrary, 'Map'); | |
| 56 | 86 |
| 57 /// The `Iterable` class defined in 'dart:core'; | 87 /// The `Iterable` class defined in 'dart:core'; |
| 58 ClassEntity get iterableClass; | 88 ClassEntity _iterableClass; |
| 89 ClassEntity get iterableClass => | |
| 90 _iterableClass ??= _findClass(coreLibrary, 'Iterable'); | |
| 59 | 91 |
| 60 /// The `Future` class defined in 'async';. | 92 /// The `Future` class defined in 'async';. |
| 61 ClassEntity get futureClass; | 93 ClassEntity _futureClass; |
| 94 ClassEntity get futureClass => | |
| 95 _futureClass ??= _findClass(asyncLibrary, 'Future'); | |
| 62 | 96 |
| 63 /// The `Stream` class defined in 'async'; | 97 /// The `Stream` class defined in 'async'; |
| 64 ClassEntity get streamClass; | 98 ClassEntity _streamClass; |
| 99 ClassEntity get streamClass => | |
| 100 _streamClass ??= _findClass(asyncLibrary, 'Stream'); | |
| 65 | 101 |
| 66 /// The dart:core library. | 102 /// The dart:core library. |
| 67 LibraryEntity get coreLibrary; | 103 LibraryEntity _coreLibrary; |
| 104 LibraryEntity get coreLibrary => | |
| 105 _coreLibrary ??= _env.lookupLibrary(Uris.dart_core, required: true); | |
| 68 | 106 |
| 69 /// The dart:async library. | 107 /// The dart:async library. |
| 70 LibraryEntity get asyncLibrary; | 108 LibraryEntity _asyncLibrary; |
| 109 LibraryEntity get asyncLibrary => | |
| 110 _asyncLibrary ??= _env.lookupLibrary(Uris.dart_async); | |
| 71 | 111 |
| 72 /// The dart:mirrors library. Null if the program doesn't access dart:mirrors. | 112 /// The dart:mirrors library. Null if the program doesn't access dart:mirrors. |
| 73 LibraryEntity get mirrorsLibrary; | 113 LibraryEntity _mirrorsLibrary; |
| 114 LibraryEntity get mirrorsLibrary => | |
| 115 _mirrorsLibrary ??= _env.lookupLibrary(Uris.dart_mirrors); | |
| 74 | 116 |
| 75 /// The dart:typed_data library. | 117 /// The dart:typed_data library. |
| 76 LibraryEntity get typedDataLibrary; | 118 LibraryEntity _typedDataLibrary; |
| 119 LibraryEntity get typedDataLibrary => | |
| 120 _typedDataLibrary ??= _env.lookupLibrary(Uris.dart__native_typed_data); | |
| 121 | |
| 122 LibraryEntity _jsHelperLibrary; | |
| 123 LibraryEntity get jsHelperLibrary => | |
| 124 _jsHelperLibrary ??= _env.lookupLibrary(Uris.dart__js_helper); | |
| 125 | |
| 126 LibraryEntity _interceptorsLibrary; | |
| 127 LibraryEntity get interceptorsLibrary => | |
| 128 _interceptorsLibrary ??= _env.lookupLibrary(Uris.dart__interceptors); | |
| 129 | |
| 130 LibraryEntity _foreignLibrary; | |
| 131 LibraryEntity get foreignLibrary => | |
| 132 _foreignLibrary ??= _env.lookupLibrary(Uris.dart__foreign_helper); | |
| 133 | |
| 134 LibraryEntity _isolateHelperLibrary; | |
| 135 LibraryEntity get isolateHelperLibrary => | |
| 136 _isolateHelperLibrary ??= _env.lookupLibrary(Uris.dart__isolate_helper); | |
| 137 | |
| 138 /// Reference to the internal library to lookup functions to always inline. | |
| 139 LibraryEntity _internalLibrary; | |
| 140 LibraryEntity get internalLibrary => | |
| 141 _internalLibrary ??= _env.lookupLibrary(Uris.dart__internal); | |
| 77 | 142 |
| 78 /// The `NativeTypedData` class from dart:typed_data. | 143 /// The `NativeTypedData` class from dart:typed_data. |
| 79 ClassEntity get typedDataClass; | 144 ClassEntity _typedDataClass; |
| 145 ClassEntity get typedDataClass => | |
| 146 _typedDataClass ??= _findClass(typedDataLibrary, 'NativeTypedData'); | |
| 80 | 147 |
| 81 /// Constructor of the `Symbol` class. This getter will ensure that `Symbol` | 148 /// Constructor of the `Symbol` class. This getter will ensure that `Symbol` |
| 82 /// is resolved and lookup the constructor on demand. | 149 /// is resolved and lookup the constructor on demand. |
| 83 ConstructorEntity get symbolConstructor; | 150 ConstructorEntity _symbolConstructor; |
| 151 ConstructorEntity get symbolConstructor => | |
| 152 _symbolConstructor ??= _findConstructor(symbolClass, ''); | |
| 84 | 153 |
| 85 /// Whether [element] is the same as [symbolConstructor]. Used to check | 154 /// Whether [element] is the same as [symbolConstructor]. Used to check |
| 86 /// for the constructor without computing it until it is likely to be seen. | 155 /// for the constructor without computing it until it is likely to be seen. |
| 87 // TODO(johnniwinther): Change type of [e] to [MemberEntity]. | 156 // TODO(johnniwinther): Change type of [e] to [MemberEntity]. |
| 88 bool isSymbolConstructor(Entity e); | 157 bool isSymbolConstructor(Entity e) => e == symbolConstructor; |
| 89 | 158 |
| 90 /// The `MirrorSystem` class in dart:mirrors. | 159 /// The `MirrorSystem` class in dart:mirrors. |
| 91 ClassEntity get mirrorSystemClass; | 160 ClassEntity _mirrorSystemClass; |
| 161 ClassEntity get mirrorSystemClass => _mirrorSystemClass ??= | |
| 162 _findClass(mirrorsLibrary, 'MirrorSystem', required: false); | |
| 92 | 163 |
| 93 /// Whether [element] is `MirrorClass.getName`. Used to check for the use of | 164 /// Whether [element] is `MirrorClass.getName`. Used to check for the use of |
| 94 /// that static method without forcing the resolution of the `MirrorSystem` | 165 /// that static method without forcing the resolution of the `MirrorSystem` |
| 95 /// class until it is necessary. | 166 /// class until it is necessary. |
| 96 bool isMirrorSystemGetNameFunction(MemberEntity element); | 167 FunctionEntity _mirrorSystemGetNameFunction; |
| 168 bool isMirrorSystemGetNameFunction(MemberEntity element) { | |
| 169 if (_mirrorSystemGetNameFunction == null) { | |
| 170 if (!element.isFunction || mirrorsLibrary == null) return false; | |
| 171 ClassEntity cls = mirrorSystemClass; | |
| 172 if (element.enclosingClass != cls) return false; | |
| 173 if (cls != null) { | |
| 174 _mirrorSystemGetNameFunction = | |
| 175 _findClassMember(cls, 'getName', required: false); | |
| 176 } | |
| 177 } | |
| 178 return element == _mirrorSystemGetNameFunction; | |
| 179 } | |
| 97 | 180 |
| 98 /// The `MirrorsUsed` annotation in dart:mirrors. | 181 /// The `MirrorsUsed` annotation in dart:mirrors. |
| 99 ClassEntity get mirrorsUsedClass; | 182 ClassEntity _mirrorsUsedClass; |
| 183 ClassEntity get mirrorsUsedClass => _mirrorsUsedClass ??= | |
| 184 _findClass(mirrorsLibrary, 'MirrorsUsed', required: false); | |
| 100 | 185 |
| 101 /// Whether [element] is the constructor of the `MirrorsUsed` class. Used to | 186 /// Whether [element] is the constructor of the `MirrorsUsed` class. Used to |
| 102 /// check for the constructor without forcing the resolution of the | 187 /// check for the constructor without forcing the resolution of the |
| 103 /// `MirrorsUsed` class until it is necessary. | 188 /// `MirrorsUsed` class until it is necessary. |
| 104 bool isMirrorsUsedConstructor(ConstructorEntity element); | 189 bool isMirrorsUsedConstructor(ConstructorEntity element) => |
| 190 mirrorsLibrary != null && mirrorsUsedClass == element.enclosingClass; | |
| 105 | 191 |
| 106 /// The `DeferredLibrary` annotation in dart:async that was used before the | 192 /// The `DeferredLibrary` annotation in dart:async that was used before the |
| 107 /// deferred import syntax was introduced. | 193 /// deferred import syntax was introduced. |
| 108 // TODO(sigmund): drop support for this old syntax? | 194 // TODO(sigmund): drop support for this old syntax? |
| 109 ClassEntity get deferredLibraryClass; | 195 ClassEntity _deferredLibraryClass; |
| 196 ClassEntity get deferredLibraryClass => | |
| 197 _deferredLibraryClass ??= _findClass(asyncLibrary, "DeferredLibrary"); | |
| 110 | 198 |
| 111 /// The function `identical` in dart:core. | 199 /// The function `identical` in dart:core. |
| 112 FunctionEntity get identicalFunction; | 200 FunctionEntity _identicalFunction; |
| 201 FunctionEntity get identicalFunction => | |
| 202 _identicalFunction ??= _findLibraryMember(coreLibrary, 'identical'); | |
| 113 | 203 |
| 114 /// The method `Function.apply`. | 204 /// The method `Function.apply`. |
| 115 FunctionEntity get functionApplyMethod; | 205 FunctionEntity _functionApplyMethod; |
| 206 FunctionEntity get functionApplyMethod => | |
| 207 _functionApplyMethod ??= _findClassMember(functionClass, 'apply'); | |
| 116 | 208 |
| 117 /// Whether [element] is the same as [functionApplyMethod]. This will not | 209 /// Whether [element] is the same as [functionApplyMethod]. This will not |
| 118 /// resolve the apply method if it hasn't been seen yet during compilation. | 210 /// resolve the apply method if it hasn't been seen yet during compilation. |
| 119 bool isFunctionApplyMethod(MemberEntity element); | 211 bool isFunctionApplyMethod(MemberEntity element) => |
| 212 element.name == 'apply' && element.enclosingClass == functionClass; | |
| 120 | 213 |
| 121 /// Returns `true` if [element] is the unnamed constructor of `List`. This | 214 /// Returns `true` if [element] is the unnamed constructor of `List`. This |
| 122 /// will not resolve the constructor if it hasn't been seen yet during | 215 /// will not resolve the constructor if it hasn't been seen yet during |
| 123 /// compilation. | 216 /// compilation. |
| 124 bool isUnnamedListConstructor(ConstructorEntity element); | 217 bool isUnnamedListConstructor(ConstructorEntity element) => |
| 218 element.name == '' && element.enclosingClass == listClass; | |
| 125 | 219 |
| 126 /// Returns `true` if [element] is the 'filled' constructor of `List`. This | 220 /// Returns `true` if [element] is the 'filled' constructor of `List`. This |
| 127 /// will not resolve the constructor if it hasn't been seen yet during | 221 /// will not resolve the constructor if it hasn't been seen yet during |
| 128 /// compilation. | 222 /// compilation. |
| 129 bool isFilledListConstructor(ConstructorEntity element); | 223 bool isFilledListConstructor(ConstructorEntity element) => |
| 224 element.name == 'filled' && element.enclosingClass == listClass; | |
| 130 | 225 |
| 131 /// The `dynamic` type. | 226 /// The `dynamic` type. |
| 132 DynamicType get dynamicType; | 227 DynamicType get dynamicType => _env.dynamicType; |
| 133 | 228 |
| 134 /// The `Object` type defined in 'dart:core'. | 229 /// The `Object` type defined in 'dart:core'. |
| 135 InterfaceType get objectType; | 230 InterfaceType get objectType => _getRawType(objectClass); |
| 136 | 231 |
| 137 /// The `bool` type defined in 'dart:core'. | 232 /// The `bool` type defined in 'dart:core'. |
| 138 InterfaceType get boolType; | 233 InterfaceType get boolType => _getRawType(boolClass); |
| 139 | 234 |
| 140 /// The `num` type defined in 'dart:core'. | 235 /// The `num` type defined in 'dart:core'. |
| 141 InterfaceType get numType; | 236 InterfaceType get numType => _getRawType(numClass); |
| 142 | 237 |
| 143 /// The `int` type defined in 'dart:core'. | 238 /// The `int` type defined in 'dart:core'. |
| 144 InterfaceType get intType; | 239 InterfaceType get intType => _getRawType(intClass); |
| 145 | 240 |
| 146 /// The `double` type defined in 'dart:core'. | 241 /// The `double` type defined in 'dart:core'. |
| 147 InterfaceType get doubleType; | 242 InterfaceType get doubleType => _getRawType(doubleClass); |
| 148 | 243 |
| 149 /// The `Resource` type defined in 'dart:core'. | 244 /// The `Resource` type defined in 'dart:core'. |
| 150 InterfaceType get resourceType; | 245 InterfaceType get resourceType => _getRawType(resourceClass); |
| 151 | 246 |
| 152 /// The `String` type defined in 'dart:core'. | 247 /// The `String` type defined in 'dart:core'. |
| 153 InterfaceType get stringType; | 248 InterfaceType get stringType => _getRawType(stringClass); |
| 154 | 249 |
| 155 /// The `Symbol` type defined in 'dart:core'. | 250 /// The `Symbol` type defined in 'dart:core'. |
| 156 InterfaceType get symbolType; | 251 InterfaceType get symbolType => _getRawType(symbolClass); |
| 157 | 252 |
| 158 /// The `Function` type defined in 'dart:core'. | 253 /// The `Function` type defined in 'dart:core'. |
| 159 InterfaceType get functionType; | 254 InterfaceType get functionType => _getRawType(functionClass); |
| 160 | 255 |
| 161 /// The `Null` type defined in 'dart:core'. | 256 /// The `Null` type defined in 'dart:core'. |
| 162 InterfaceType get nullType; | 257 InterfaceType get nullType => _getRawType(nullClass); |
| 163 | 258 |
| 164 /// The `Type` type defined in 'dart:core'. | 259 /// The `Type` type defined in 'dart:core'. |
| 165 InterfaceType get typeType; | 260 InterfaceType get typeType => _getRawType(typeClass); |
| 166 | 261 |
| 167 /// The `StackTrace` type defined in 'dart:core'; | 262 /// The `StackTrace` type defined in 'dart:core'; |
| 168 InterfaceType get stackTraceType; | 263 InterfaceType get stackTraceType => _getRawType(stackTraceClass); |
| 169 | 264 |
| 170 /// Returns an instance of the `List` type defined in 'dart:core' with | 265 /// Returns an instance of the `List` type defined in 'dart:core' with |
| 171 /// [elementType] as its type argument. | 266 /// [elementType] as its type argument. |
| 172 /// | 267 /// |
| 173 /// If no type argument is provided, the canonical raw type is returned. | 268 /// If no type argument is provided, the canonical raw type is returned. |
| 174 InterfaceType listType([DartType elementType]); | 269 InterfaceType listType([DartType elementType]) { |
| 270 if (elementType == null) { | |
| 271 return _getRawType(listClass); | |
| 272 } | |
| 273 return _createInterfaceType(listClass, [elementType]); | |
| 274 } | |
| 175 | 275 |
| 176 /// Returns an instance of the `Map` type defined in 'dart:core' with | 276 /// Returns an instance of the `Map` type defined in 'dart:core' with |
| 177 /// [keyType] and [valueType] as its type arguments. | 277 /// [keyType] and [valueType] as its type arguments. |
| 178 /// | 278 /// |
| 179 /// If no type arguments are provided, the canonical raw type is returned. | 279 /// If no type arguments are provided, the canonical raw type is returned. |
| 180 InterfaceType mapType([DartType keyType, DartType valueType]); | 280 InterfaceType mapType([DartType keyType, DartType valueType]) { |
| 281 if (keyType == null && valueType == null) { | |
| 282 return _getRawType(mapClass); | |
| 283 } else if (keyType == null) { | |
| 284 keyType = dynamicType; | |
| 285 } else if (valueType == null) { | |
| 286 valueType = dynamicType; | |
| 287 } | |
| 288 return _createInterfaceType(mapClass, [keyType, valueType]); | |
| 289 } | |
| 181 | 290 |
| 182 /// Returns an instance of the `Iterable` type defined in 'dart:core' with | 291 /// Returns an instance of the `Iterable` type defined in 'dart:core' with |
| 183 /// [elementType] as its type argument. | 292 /// [elementType] as its type argument. |
| 184 /// | 293 /// |
| 185 /// If no type argument is provided, the canonical raw type is returned. | 294 /// If no type argument is provided, the canonical raw type is returned. |
| 186 InterfaceType iterableType([DartType elementType]); | 295 InterfaceType iterableType([DartType elementType]) { |
| 296 if (elementType == null) { | |
| 297 return _getRawType(iterableClass); | |
| 298 } | |
| 299 return _createInterfaceType(iterableClass, [elementType]); | |
| 300 } | |
| 187 | 301 |
| 188 /// Returns an instance of the `Future` type defined in 'dart:async' with | 302 /// Returns an instance of the `Future` type defined in 'dart:async' with |
| 189 /// [elementType] as its type argument. | 303 /// [elementType] as its type argument. |
| 190 /// | 304 /// |
| 191 /// If no type argument is provided, the canonical raw type is returned. | 305 /// If no type argument is provided, the canonical raw type is returned. |
| 192 InterfaceType futureType([DartType elementType]); | 306 InterfaceType futureType([DartType elementType]) { |
| 307 if (elementType == null) { | |
| 308 return _getRawType(futureClass); | |
| 309 } | |
| 310 return _createInterfaceType(futureClass, [elementType]); | |
| 311 } | |
| 193 | 312 |
| 194 /// Returns an instance of the `Stream` type defined in 'dart:async' with | 313 /// Returns an instance of the `Stream` type defined in 'dart:async' with |
| 195 /// [elementType] as its type argument. | 314 /// [elementType] as its type argument. |
| 196 /// | 315 /// |
| 197 /// If no type argument is provided, the canonical raw type is returned. | 316 /// If no type argument is provided, the canonical raw type is returned. |
| 198 InterfaceType streamType([DartType elementType]); | 317 InterfaceType streamType([DartType elementType]) { |
| 318 if (elementType == null) { | |
| 319 return _getRawType(streamClass); | |
| 320 } | |
| 321 return _createInterfaceType(streamClass, [elementType]); | |
| 322 } | |
| 199 | 323 |
| 200 /// Returns `true` if [element] is a superclass of `String` or `num`. | 324 /// Returns `true` if [element] is a superclass of `String` or `num`. |
| 201 bool isNumberOrStringSupertype(ClassEntity element); | 325 // TODO(johnniwinther): Change types to `ClassEntity` when these are not |
| 326 // called with unrelated elements. | |
| 327 bool isNumberOrStringSupertype(/*Class*/ Entity element) { | |
| 328 return element == _findClass(coreLibrary, 'Comparable', required: false); | |
| 329 } | |
| 202 | 330 |
| 203 /// Returns `true` if [element] is a superclass of `String`. | 331 /// Returns `true` if [element] is a superclass of `String`. |
| 204 bool isStringOnlySupertype(ClassEntity element); | 332 // TODO(johnniwinther): Change types to `ClassEntity` when these are not |
| 333 // called with unrelated elements. | |
| 334 bool isStringOnlySupertype(/*Class*/ Entity element) { | |
| 335 return element == _findClass(coreLibrary, 'Pattern', required: false); | |
| 336 } | |
| 205 | 337 |
| 206 /// Returns `true` if [element] is a superclass of `List`. | 338 /// Returns `true` if [element] is a superclass of `List`. |
| 207 bool isListSupertype(ClassEntity element); | 339 bool isListSupertype(ClassEntity element) => element == iterableClass; |
| 208 } | 340 } |
| 209 | 341 |
| 210 /// Interface for accessing libraries, classes and members. | 342 /// Interface for accessing libraries, classes and members. |
| 211 /// | 343 /// |
| 212 /// The _env makes private and injected members directly available and | 344 /// The _env makes private and injected members directly available and |
| 213 /// should therefore not be used to determine scopes. | 345 /// should therefore not be used to determine scopes. |
| 214 abstract class ElementEnvironment { | 346 abstract class ElementEnvironment { |
| 215 /// Returns the main library for the compilation. | 347 /// Returns the main library for the compilation. |
| 216 LibraryEntity get mainLibrary; | 348 LibraryEntity get mainLibrary; |
| 217 | 349 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 425 |
| 294 /// Returns the [CallStructure] corresponding to calling [entity] with all | 426 /// Returns the [CallStructure] corresponding to calling [entity] with all |
| 295 /// arguments, both required and optional. | 427 /// arguments, both required and optional. |
| 296 CallStructure getCallStructure(FunctionEntity entity); | 428 CallStructure getCallStructure(FunctionEntity entity); |
| 297 | 429 |
| 298 /// Returns `true` if [member] a the synthetic getter `loadLibrary` injected | 430 /// Returns `true` if [member] a the synthetic getter `loadLibrary` injected |
| 299 /// on deferred libraries. | 431 /// on deferred libraries. |
| 300 bool isDeferredLoadLibraryGetter(MemberEntity member); | 432 bool isDeferredLoadLibraryGetter(MemberEntity member); |
| 301 } | 433 } |
| 302 | 434 |
| 303 class CommonElementsImpl implements CommonElements { | 435 class CommonElementsImpl implements CommonElements { |
|
Johnni Winther
2017/04/11 09:16:00
It looks like something's gone wrong in the merge.
Emily Fortuna
2017/04/11 21:31:35
oh geez. sorry about that. I did the merge last mi
| |
| 304 final ElementEnvironment _env; | 436 final ElementEnvironment _env; |
| 305 | 437 |
| 306 CommonElementsImpl(this._env); | 438 CommonElementsImpl(this._env); |
| 307 | 439 |
| 308 ClassEntity findClass(LibraryEntity library, String name, | 440 ClassEntity _findClass(LibraryEntity library, String name, |
| 309 {bool required: true}) { | 441 {bool required: true}) { |
| 310 if (library == null) return null; | 442 if (library == null) return null; |
| 311 return _env.lookupClass(library, name, required: required); | 443 return _env.lookupClass(library, name, required: required); |
| 312 } | 444 } |
| 313 | 445 |
| 314 MemberEntity findLibraryMember(LibraryEntity library, String name, | 446 MemberEntity _findLibraryMember(LibraryEntity library, String name, |
| 315 {bool setter: false, bool required: true}) { | 447 {bool setter: false, bool required: true}) { |
| 316 if (library == null) return null; | 448 if (library == null) return null; |
| 317 return _env.lookupLibraryMember(library, name, | 449 return _env.lookupLibraryMember(library, name, |
| 318 setter: setter, required: required); | 450 setter: setter, required: required); |
| 319 } | 451 } |
| 320 | 452 |
| 321 MemberEntity findClassMember(ClassEntity cls, String name, | 453 MemberEntity _findClassMember(ClassEntity cls, String name, |
| 322 {bool setter: false, bool required: true}) { | 454 {bool setter: false, bool required: true}) { |
| 323 return _env.lookupClassMember(cls, name, | 455 return _env.lookupClassMember(cls, name, |
| 324 setter: setter, required: required); | 456 setter: setter, required: required); |
| 325 } | 457 } |
| 326 | 458 |
| 327 ConstructorEntity findConstructor(ClassEntity cls, String name, | 459 ConstructorEntity _findConstructor(ClassEntity cls, String name, |
| 328 {bool required: true}) { | 460 {bool required: true}) { |
| 329 return _env.lookupConstructor(cls, name, required: required); | 461 return _env.lookupConstructor(cls, name, required: required); |
| 330 } | 462 } |
| 331 | 463 |
| 332 DartType get dynamicType => _env.dynamicType; | |
| 333 | |
| 334 /// Return the raw type of [cls]. | 464 /// Return the raw type of [cls]. |
| 335 InterfaceType getRawType(ClassEntity cls) { | 465 InterfaceType _getRawType(ClassEntity cls) { |
| 336 return _env.getRawType(cls); | 466 return _env.getRawType(cls); |
| 337 } | 467 } |
| 338 | 468 |
| 339 /// Create the instantiation of [cls] with the given [typeArguments]. | 469 /// Create the instantiation of [cls] with the given [typeArguments]. |
| 470 InterfaceType _createInterfaceType( | |
| 471 ClassEntity cls, List<DartType> typeArguments) { | |
| 472 return _env.createInterfaceType(cls, typeArguments); | |
| 473 } | |
| 474 | |
| 475 // From dart:core | |
| 476 FunctionEntity get malformedTypeError => | |
| 477 _cachedCoreHelper('_malformedTypeError'); | |
| 478 FunctionEntity get genericNoSuchMethod => | |
| 479 _cachedCoreHelper('_genericNoSuchMethod'); | |
| 480 FunctionEntity get unresolvedConstructorError => | |
| 481 _cachedCoreHelper('_unresolvedConstructorError'); | |
| 482 FunctionEntity get unresolvedStaticGetterError => | |
| 483 _cachedCoreHelper('_unresolvedStaticGetterError'); | |
| 484 FunctionEntity get unresolvedStaticSetterError => | |
| 485 _cachedCoreHelper('_unresolvedStaticSetterError'); | |
| 486 FunctionEntity get unresolvedStaticMethodError => | |
| 487 _cachedCoreHelper('_unresolvedStaticMethodError'); | |
| 488 FunctionEntity get unresolvedTopLevelGetterError => | |
| 489 _cachedCoreHelper('_unresolvedTopLevelGetterError'); | |
| 490 FunctionEntity get unresolvedTopLevelSetterError => | |
| 491 _cachedCoreHelper('_unresolvedTopLevelSetterError'); | |
| 492 FunctionEntity get unresolvedTopLevelMethodError => | |
| 493 _cachedCoreHelper('_unresolvedTopLevelMethodError'); | |
| 494 | |
| 495 Map<String, FunctionEntity> _cachedCoreHelpers = <String, FunctionEntity>{}; | |
| 496 FunctionEntity _cachedCoreHelper(String name) => _cachedCoreHelpers[name] ??= | |
| 497 _env.lookupLibraryMember(coreLibrary, name, required: true); | |
| 498 | |
| 499 FunctionEntity _objectEquals; | |
| 500 FunctionEntity get objectEquals => | |
| 501 _objectEquals ??= _findClassMember(objectClass, '=='); | |
| 502 | |
| 503 ClassEntity _mapLiteralClass; | |
| 504 ClassEntity get mapLiteralClass { | |
| 505 if (_mapLiteralClass == null) { | |
| 506 _mapLiteralClass = _env.lookupClass(coreLibrary, 'LinkedHashMap'); | |
| 507 if (_mapLiteralClass == null) { | |
| 508 _mapLiteralClass = _findClass( | |
| 509 _env.lookupLibrary(Uris.dart_collection), 'LinkedHashMap'); | |
| 510 } | |
| 511 } | |
| 512 return _mapLiteralClass; | |
| 513 } | |
| 514 | |
| 515 ConstructorEntity _mapLiteralConstructor; | |
| 516 ConstructorEntity _mapLiteralConstructorEmpty; | |
| 517 FunctionEntity _mapLiteralUntypedMaker; | |
| 518 FunctionEntity _mapLiteralUntypedEmptyMaker; | |
| 519 void _ensureMapLiteralHelpers() { | |
| 520 if (_mapLiteralConstructor != null) return; | |
| 521 | |
| 522 _mapLiteralConstructor = | |
| 523 _env.lookupConstructor(mapLiteralClass, '_literal'); | |
| 524 _mapLiteralConstructorEmpty = | |
| 525 _env.lookupConstructor(mapLiteralClass, '_empty'); | |
| 526 _mapLiteralUntypedMaker = | |
| 527 _env.lookupClassMember(mapLiteralClass, '_makeLiteral'); | |
| 528 _mapLiteralUntypedEmptyMaker = | |
| 529 _env.lookupClassMember(mapLiteralClass, '_makeEmpty'); | |
| 530 } | |
| 531 | |
| 532 ConstructorEntity get mapLiteralConstructor { | |
| 533 _ensureMapLiteralHelpers(); | |
| 534 return _mapLiteralConstructor; | |
| 535 } | |
| 536 | |
| 537 ConstructorEntity get mapLiteralConstructorEmpty { | |
| 538 _ensureMapLiteralHelpers(); | |
| 539 return _mapLiteralConstructorEmpty; | |
| 540 } | |
| 541 | |
| 542 FunctionEntity get mapLiteralUntypedMaker { | |
| 543 _ensureMapLiteralHelpers(); | |
| 544 return _mapLiteralUntypedMaker; | |
| 545 } | |
| 546 | |
| 547 FunctionEntity get mapLiteralUntypedEmptyMaker { | |
| 548 _ensureMapLiteralHelpers(); | |
| 549 return _mapLiteralUntypedEmptyMaker; | |
| 550 } | |
| 551 | |
| 552 FunctionEntity _objectNoSuchMethod; | |
| 553 FunctionEntity get objectNoSuchMethod { | |
| 554 return _objectNoSuchMethod ??= | |
| 555 _env.lookupClassMember(objectClass, Identifiers.noSuchMethod_); | |
| 556 } | |
| 557 | |
| 558 bool isDefaultNoSuchMethodImplementation(FunctionEntity element) { | |
| 559 ClassEntity classElement = element.enclosingClass; | |
| 560 return classElement == objectClass || | |
| 561 classElement == jsInterceptorClass || | |
| 562 classElement == jsNullClass; | |
| 563 } | |
| 564 | |
| 565 // From dart:async | |
| 566 ClassEntity _findAsyncHelperClass(String name) => | |
| 567 _findClass(asyncLibrary, name); | |
| 568 | |
| 569 FunctionEntity _findAsyncHelperFunction(String name) => | |
| 570 _findLibraryMember(asyncLibrary, name); | |
| 571 | |
| 572 FunctionEntity get asyncHelper => _findAsyncHelperFunction("_asyncHelper"); | |
| 573 | |
| 574 FunctionEntity get wrapBody => | |
| 575 _findAsyncHelperFunction("_wrapJsFunctionForAsync"); | |
| 576 | |
| 577 FunctionEntity get yieldStar => _env.lookupClassMember( | |
| 578 _findAsyncHelperClass("_IterationMarker"), "yieldStar"); | |
| 579 | |
| 580 FunctionEntity get yieldSingle => _env.lookupClassMember( | |
| 581 _findAsyncHelperClass("_IterationMarker"), "yieldSingle"); | |
| 582 | |
| 583 FunctionEntity get syncStarUncaughtError => _env.lookupClassMember( | |
| 584 _findAsyncHelperClass("_IterationMarker"), "uncaughtError"); | |
| 585 | |
| 586 FunctionEntity get asyncStarHelper => | |
| 587 _findAsyncHelperFunction("_asyncStarHelper"); | |
| 588 | |
| 589 FunctionEntity get streamOfController => | |
| 590 _findAsyncHelperFunction("_streamOfController"); | |
| 591 | |
| 592 FunctionEntity get endOfIteration => _env.lookupClassMember( | |
| 593 _findAsyncHelperClass("_IterationMarker"), "endOfIteration"); | |
| 594 | |
| 595 ClassEntity get syncStarIterable => | |
| 596 _findAsyncHelperClass("_SyncStarIterable"); | |
| 597 | |
| 598 ClassEntity get futureImplementation => _findAsyncHelperClass('_Future'); | |
| 599 | |
| 600 ClassEntity get controllerStream => | |
| 601 _findAsyncHelperClass("_ControllerStream"); | |
| 602 | |
| 603 ConstructorEntity get syncStarIterableConstructor => | |
| 604 _env.lookupConstructor(syncStarIterable, ""); | |
| 605 | |
| 606 ConstructorEntity get syncCompleterConstructor => | |
| 607 _env.lookupConstructor(_findAsyncHelperClass("Completer"), "sync"); | |
| 608 | |
| 609 ClassEntity get asyncStarController => | |
| 610 _findAsyncHelperClass("_AsyncStarStreamController"); | |
| 611 | |
| 612 ConstructorEntity get asyncStarControllerConstructor => | |
| 613 _env.lookupConstructor(asyncStarController, "", required: true); | |
| 614 | |
| 615 ConstructorEntity get streamIteratorConstructor => | |
| 616 _env.lookupConstructor(_findAsyncHelperClass("StreamIterator"), ""); | |
| 617 | |
| 618 // From dart:mirrors | |
| 619 FunctionEntity _findMirrorsFunction(String name) { | |
| 620 LibraryEntity library = _env.lookupLibrary(Uris.dart__js_mirrors); | |
| 621 if (library == null) return null; | |
| 622 return _env.lookupLibraryMember(library, name, required: true); | |
| 623 } | |
| 624 | |
| 625 /// Holds the method "disableTreeShaking" in js_mirrors when | |
| 626 /// dart:mirrors has been loaded. | |
| 627 FunctionEntity _disableTreeShakingMarker; | |
| 628 FunctionEntity get disableTreeShakingMarker => | |
| 629 _disableTreeShakingMarker ??= _findMirrorsFunction('disableTreeShaking'); | |
| 630 | |
| 631 /// Holds the method "preserveNames" in js_mirrors when | |
| 632 /// dart:mirrors has been loaded. | |
| 633 FunctionEntity _preserveNamesMarker; | |
| 634 FunctionEntity get preserveNamesMarker { | |
| 635 if (_preserveNamesMarker == null) { | |
| 636 LibraryEntity library = _env.lookupLibrary(Uris.dart__js_names); | |
| 637 if (library != null) { | |
| 638 _preserveNamesMarker = _findLibraryMember(library, 'preserveNames'); | |
| 639 } | |
| 640 } | |
| 641 return _preserveNamesMarker; | |
| 642 } | |
| 643 | |
| 644 /// Holds the method "preserveMetadata" in js_mirrors when | |
| 645 /// dart:mirrors has been loaded. | |
| 646 FunctionEntity _preserveMetadataMarker; | |
| 647 FunctionEntity get preserveMetadataMarker => | |
| 648 _preserveMetadataMarker ??= _findMirrorsFunction('preserveMetadata'); | |
| 649 | |
| 650 /// Holds the method "preserveUris" in js_mirrors when | |
| 651 /// dart:mirrors has been loaded. | |
| 652 FunctionEntity _preserveUrisMarker; | |
| 653 FunctionEntity get preserveUrisMarker => | |
| 654 _preserveUrisMarker ??= _findMirrorsFunction('preserveUris'); | |
| 655 | |
| 656 /// Holds the method "preserveLibraryNames" in js_mirrors when | |
| 657 /// dart:mirrors has been loaded. | |
| 658 FunctionEntity _preserveLibraryNamesMarker; | |
| 659 FunctionEntity get preserveLibraryNamesMarker => | |
| 660 _preserveLibraryNamesMarker ??= | |
| 661 _findMirrorsFunction('preserveLibraryNames'); | |
| 662 | |
| 663 // From dart:_interceptors | |
| 664 ClassEntity _findInterceptorsClass(String name) => | |
| 665 _findClass(interceptorsLibrary, name); | |
| 666 | |
| 667 FunctionEntity _findInterceptorsFunction(String name) => | |
| 668 _findLibraryMember(interceptorsLibrary, name); | |
| 669 | |
| 670 ClassEntity _jsInterceptorClass; | |
| 671 ClassEntity get jsInterceptorClass => | |
| 672 _jsInterceptorClass ??= _findInterceptorsClass('Interceptor'); | |
| 673 | |
| 674 ClassEntity _jsStringClass; | |
| 675 ClassEntity get jsStringClass => | |
| 676 _jsStringClass ??= _findInterceptorsClass('JSString'); | |
| 677 | |
| 678 ClassEntity _jsArrayClass; | |
| 679 ClassEntity get jsArrayClass => | |
| 680 _jsArrayClass ??= _findInterceptorsClass('JSArray'); | |
| 681 | |
| 682 ClassEntity _jsNumberClass; | |
| 683 ClassEntity get jsNumberClass => | |
| 684 _jsNumberClass ??= _findInterceptorsClass('JSNumber'); | |
| 685 | |
| 686 ClassEntity _jsIntClass; | |
| 687 ClassEntity get jsIntClass => _jsIntClass ??= _findInterceptorsClass('JSInt'); | |
| 688 | |
| 689 ClassEntity _jsDoubleClass; | |
| 690 ClassEntity get jsDoubleClass => | |
| 691 _jsDoubleClass ??= _findInterceptorsClass('JSDouble'); | |
| 692 | |
| 693 ClassEntity _jsNullClass; | |
| 694 ClassEntity get jsNullClass => | |
| 695 _jsNullClass ??= _findInterceptorsClass('JSNull'); | |
| 696 | |
| 697 ClassEntity _jsBoolClass; | |
| 698 ClassEntity get jsBoolClass => | |
| 699 _jsBoolClass ??= _findInterceptorsClass('JSBool'); | |
| 700 | |
| 701 ClassEntity _jsPlainJavaScriptObjectClass; | |
| 702 ClassEntity get jsPlainJavaScriptObjectClass => | |
| 703 _jsPlainJavaScriptObjectClass ??= | |
| 704 _findInterceptorsClass('PlainJavaScriptObject'); | |
| 705 | |
| 706 ClassEntity _jsUnknownJavaScriptObjectClass; | |
| 707 ClassEntity get jsUnknownJavaScriptObjectClass => | |
| 708 _jsUnknownJavaScriptObjectClass ??= | |
| 709 _findInterceptorsClass('UnknownJavaScriptObject'); | |
| 710 | |
| 711 ClassEntity _jsJavaScriptFunctionClass; | |
| 712 ClassEntity get jsJavaScriptFunctionClass => _jsJavaScriptFunctionClass ??= | |
| 713 _findInterceptorsClass('JavaScriptFunction'); | |
| 714 | |
| 715 ClassEntity _jsJavaScriptObjectClass; | |
| 716 ClassEntity get jsJavaScriptObjectClass => | |
| 717 _jsJavaScriptObjectClass ??= _findInterceptorsClass('JavaScriptObject'); | |
| 718 | |
| 719 ClassEntity _jsIndexableClass; | |
| 720 ClassEntity get jsIndexableClass => | |
| 721 _jsIndexableClass ??= _findInterceptorsClass('JSIndexable'); | |
| 722 | |
| 723 ClassEntity _jsMutableIndexableClass; | |
| 724 ClassEntity get jsMutableIndexableClass => | |
| 725 _jsMutableIndexableClass ??= _findInterceptorsClass('JSMutableIndexable'); | |
| 726 | |
| 727 ClassEntity _jsMutableArrayClass; | |
| 728 ClassEntity get jsMutableArrayClass => | |
| 729 _jsMutableArrayClass ??= _findInterceptorsClass('JSMutableArray'); | |
| 730 | |
| 731 ClassEntity _jsFixedArrayClass; | |
| 732 ClassEntity get jsFixedArrayClass => | |
| 733 _jsFixedArrayClass ??= _findInterceptorsClass('JSFixedArray'); | |
| 734 | |
| 735 ClassEntity _jsExtendableArrayClass; | |
| 736 ClassEntity get jsExtendableArrayClass => | |
| 737 _jsExtendableArrayClass ??= _findInterceptorsClass('JSExtendableArray'); | |
| 738 | |
| 739 ClassEntity _jsUnmodifiableArrayClass; | |
| 740 ClassEntity get jsUnmodifiableArrayClass => _jsUnmodifiableArrayClass ??= | |
| 741 _findInterceptorsClass('JSUnmodifiableArray'); | |
| 742 | |
| 743 ClassEntity _jsPositiveIntClass; | |
| 744 ClassEntity get jsPositiveIntClass => | |
| 745 _jsPositiveIntClass ??= _findInterceptorsClass('JSPositiveInt'); | |
| 746 | |
| 747 ClassEntity _jsUInt32Class; | |
| 748 ClassEntity get jsUInt32Class => | |
| 749 _jsUInt32Class ??= _findInterceptorsClass('JSUInt32'); | |
| 750 | |
| 751 ClassEntity _jsUInt31Class; | |
| 752 ClassEntity get jsUInt31Class => | |
| 753 _jsUInt31Class ??= _findInterceptorsClass('JSUInt31'); | |
| 754 | |
| 755 FunctionEntity _findIndexForNativeSubclassType; | |
| 756 FunctionEntity get findIndexForNativeSubclassType => | |
| 757 _findIndexForNativeSubclassType ??= _findLibraryMember( | |
| 758 interceptorsLibrary, 'findIndexForNativeSubclassType'); | |
| 759 | |
| 760 FunctionEntity _getInterceptorMethod; | |
| 761 FunctionEntity get getInterceptorMethod => | |
| 762 _getInterceptorMethod ??= _findInterceptorsFunction('getInterceptor'); | |
| 763 | |
| 764 FunctionEntity _getNativeInterceptorMethod; | |
| 765 FunctionEntity get getNativeInterceptorMethod => | |
| 766 _getNativeInterceptorMethod ??= | |
| 767 _findInterceptorsFunction('getNativeInterceptor'); | |
| 768 | |
| 769 MemberEntity _jsIndexableLength; | |
| 770 MemberEntity get jsIndexableLength => | |
| 771 _jsIndexableLength ??= _findClassMember(jsIndexableClass, 'length'); | |
| 772 | |
| 773 ConstructorEntity _jsArrayTypedConstructor; | |
| 774 ConstructorEntity get jsArrayTypedConstructor => | |
| 775 _jsArrayTypedConstructor ??= _findConstructor(jsArrayClass, 'typed'); | |
| 776 | |
| 777 FunctionEntity _jsArrayRemoveLast; | |
| 778 FunctionEntity get jsArrayRemoveLast => | |
| 779 _jsArrayRemoveLast ??= _findClassMember(jsArrayClass, 'removeLast'); | |
| 780 | |
| 781 FunctionEntity _jsArrayAdd; | |
| 782 FunctionEntity get jsArrayAdd => | |
| 783 _jsArrayAdd ??= _findClassMember(jsArrayClass, 'add'); | |
| 784 | |
| 785 FunctionEntity _jsStringSplit; | |
| 786 FunctionEntity get jsStringSplit => | |
| 787 _jsStringSplit ??= _findClassMember(jsStringClass, 'split'); | |
| 788 | |
| 789 FunctionEntity _jsStringToString; | |
| 790 FunctionEntity get jsStringToString => | |
| 791 _jsStringToString ??= _findClassMember(jsStringClass, 'toString'); | |
| 792 | |
| 793 FunctionEntity _jsStringOperatorAdd; | |
| 794 FunctionEntity get jsStringOperatorAdd => | |
| 795 _jsStringOperatorAdd ??= _findClassMember(jsStringClass, '+'); | |
| 796 | |
| 797 // From package:js | |
| 798 ClassEntity _jsAnnotationClass; | |
| 799 ClassEntity get jsAnnotationClass { | |
| 800 if (_jsAnnotationClass == null) { | |
| 801 LibraryEntity library = _env.lookupLibrary(Uris.package_js); | |
| 802 if (library == null) return null; | |
| 803 _jsAnnotationClass = _findClass(library, 'JS'); | |
| 804 } | |
| 805 return _jsAnnotationClass; | |
| 806 } | |
| 807 | |
| 808 ClassEntity _jsAnonymousClass; | |
| 809 ClassEntity get jsAnonymousClass { | |
| 810 if (_jsAnonymousClass == null) { | |
| 811 LibraryEntity library = _env.lookupLibrary(Uris.package_js); | |
| 812 if (library == null) return null; | |
| 813 _jsAnonymousClass = _findClass(library, '_Anonymous'); | |
| 814 } | |
| 815 return _jsAnonymousClass; | |
| 816 } | |
| 817 | |
| 818 // From dart:_js_helper | |
| 819 // TODO(johnniwinther): Avoid the need for this (from [CheckedModeHelper]). | |
| 820 FunctionEntity findHelperFunction(String name) => _findHelperFunction(name); | |
| 821 | |
| 822 FunctionEntity _findHelperFunction(String name) => | |
| 823 _findLibraryMember(jsHelperLibrary, name); | |
| 824 | |
| 825 ClassEntity _findHelperClass(String name) => | |
| 826 _findClass(jsHelperLibrary, name); | |
| 827 | |
| 828 ClassEntity _closureClass; | |
| 829 ClassEntity get closureClass => _closureClass ??= _findHelperClass('Closure'); | |
| 830 | |
| 831 ClassEntity _boundClosureClass; | |
| 832 ClassEntity get boundClosureClass => | |
| 833 _boundClosureClass ??= _findHelperClass('BoundClosure'); | |
| 834 | |
| 835 ClassEntity _typeLiteralClass; | |
| 836 ClassEntity get typeLiteralClass => | |
| 837 _typeLiteralClass ??= _findHelperClass('TypeImpl'); | |
| 838 | |
| 839 ClassEntity _constMapLiteralClass; | |
| 840 ClassEntity get constMapLiteralClass => | |
| 841 _constMapLiteralClass ??= _findHelperClass('ConstantMap'); | |
| 842 | |
| 843 ClassEntity _typeVariableClass; | |
| 844 ClassEntity get typeVariableClass => | |
| 845 _typeVariableClass ??= _findHelperClass('TypeVariable'); | |
| 846 | |
| 847 ClassEntity _noSideEffectsClass; | |
| 848 ClassEntity get noSideEffectsClass => | |
| 849 _noSideEffectsClass ??= _findHelperClass('NoSideEffects'); | |
| 850 | |
| 851 ClassEntity _noThrowsClass; | |
| 852 ClassEntity get noThrowsClass => | |
| 853 _noThrowsClass ??= _findHelperClass('NoThrows'); | |
| 854 | |
| 855 ClassEntity _noInlineClass; | |
| 856 ClassEntity get noInlineClass => | |
| 857 _noInlineClass ??= _findHelperClass('NoInline'); | |
| 858 | |
| 859 ClassEntity _forceInlineClass; | |
| 860 ClassEntity get forceInlineClass => | |
| 861 _forceInlineClass ??= _findHelperClass('ForceInline'); | |
| 862 | |
| 863 ClassEntity _irRepresentationClass; | |
| 864 ClassEntity get irRepresentationClass => | |
| 865 _irRepresentationClass ??= _findHelperClass('IrRepresentation'); | |
| 866 | |
| 867 ClassEntity _jsInvocationMirrorClass; | |
| 868 ClassEntity get jsInvocationMirrorClass => | |
| 869 _jsInvocationMirrorClass ??= _findHelperClass('JSInvocationMirror'); | |
| 870 | |
| 871 /// Interface used to determine if an object has the JavaScript | |
| 872 /// indexing behavior. The interface is only visible to specific libraries. | |
| 873 ClassEntity _jsIndexingBehaviorInterface; | |
| 874 ClassEntity get jsIndexingBehaviorInterface => | |
| 875 _jsIndexingBehaviorInterface ??= | |
| 876 _findHelperClass('JavaScriptIndexingBehavior'); | |
| 877 | |
| 878 ClassEntity get VoidRuntimeType => _findHelperClass('VoidRuntimeType'); | |
| 879 | |
| 880 ClassEntity get stackTraceHelperClass => _findHelperClass('_StackTrace'); | |
| 881 | |
| 882 ClassEntity get constantMapClass => | |
| 883 _findHelperClass(JavaScriptMapConstant.DART_CLASS); | |
| 884 ClassEntity get constantStringMapClass => | |
| 885 _findHelperClass(JavaScriptMapConstant.DART_STRING_CLASS); | |
| 886 ClassEntity get constantProtoMapClass => | |
| 887 _findHelperClass(JavaScriptMapConstant.DART_PROTO_CLASS); | |
| 888 ClassEntity get generalConstantMapClass => | |
| 889 _findHelperClass(JavaScriptMapConstant.DART_GENERAL_CLASS); | |
| 890 | |
| 891 ClassEntity get annotationCreatesClass => _findHelperClass('Creates'); | |
| 892 | |
| 893 ClassEntity get annotationReturnsClass => _findHelperClass('Returns'); | |
| 894 | |
| 895 ClassEntity get annotationJSNameClass => _findHelperClass('JSName'); | |
| 896 | |
| 897 /// The class for patch annotations defined in dart:_js_helper. | |
| 898 ClassEntity _patchAnnotationClass; | |
| 899 ClassEntity get patchAnnotationClass => | |
| 900 _patchAnnotationClass ??= _findHelperClass('_Patch'); | |
| 901 | |
| 902 /// The class for native annotations defined in dart:_js_helper. | |
| 903 ClassEntity _nativeAnnotationClass; | |
| 904 ClassEntity get nativeAnnotationClass => | |
| 905 _nativeAnnotationClass ??= _findHelperClass('Native'); | |
| 906 | |
| 907 ConstructorEntity _typeVariableConstructor; | |
| 908 ConstructorEntity get typeVariableConstructor => _typeVariableConstructor ??= | |
| 909 _env.lookupConstructor(typeVariableClass, ''); | |
| 910 | |
| 911 FunctionEntity _invokeOnMethod; | |
| 912 FunctionEntity get invokeOnMethod => _invokeOnMethod ??= | |
| 913 _env.lookupClassMember(jsInvocationMirrorClass, '_getCachedInvocation'); | |
| 914 | |
| 915 FunctionEntity _assertTest; | |
| 916 FunctionEntity get assertTest => | |
| 917 _assertTest ??= _findHelperFunction('assertTest'); | |
| 918 | |
| 919 FunctionEntity _assertThrow; | |
| 920 FunctionEntity get assertThrow => | |
| 921 _assertThrow ??= _findHelperFunction('assertThrow'); | |
| 922 | |
| 923 FunctionEntity _assertHelper; | |
| 924 FunctionEntity get assertHelper => | |
| 925 _assertHelper ??= _findHelperFunction('assertHelper'); | |
| 926 | |
| 927 FunctionEntity _assertUnreachableMethod; | |
| 928 FunctionEntity get assertUnreachableMethod => | |
| 929 _assertUnreachableMethod ??= _findHelperFunction('assertUnreachable'); | |
| 930 | |
| 931 /// Holds the method "getIsolateAffinityTag" when dart:_js_helper has been | |
| 932 /// loaded. | |
| 933 FunctionEntity _getIsolateAffinityTagMarker; | |
| 934 FunctionEntity get getIsolateAffinityTagMarker => | |
| 935 _getIsolateAffinityTagMarker ??= | |
| 936 _findHelperFunction('getIsolateAffinityTag'); | |
| 937 | |
| 938 /// Holds the method "requiresPreamble" in _js_helper. | |
| 939 FunctionEntity _requiresPreambleMarker; | |
| 940 FunctionEntity get requiresPreambleMarker => | |
| 941 _requiresPreambleMarker ??= _findHelperFunction('requiresPreamble'); | |
| 942 | |
| 943 FunctionEntity get badMain => _findHelperFunction('badMain'); | |
| 944 | |
| 945 FunctionEntity get missingMain => _findHelperFunction('missingMain'); | |
| 946 | |
| 947 FunctionEntity get mainHasTooManyParameters => | |
| 948 _findHelperFunction('mainHasTooManyParameters'); | |
| 949 | |
| 950 FunctionEntity get loadLibraryWrapper => | |
| 951 _findHelperFunction("_loadLibraryWrapper"); | |
| 952 | |
| 953 FunctionEntity get boolConversionCheck => | |
| 954 _findHelperFunction('boolConversionCheck'); | |
| 955 | |
| 956 FunctionEntity get _consoleTraceHelper => | |
| 957 _findHelperFunction('consoleTraceHelper'); | |
| 958 | |
| 959 FunctionEntity get _postTraceHelper => _findHelperFunction('postTraceHelper'); | |
| 960 | |
| 961 FunctionEntity _traceHelper; | |
| 962 FunctionEntity get traceHelper { | |
| 963 return _traceHelper ??= JavaScriptBackend.TRACE_METHOD == 'console' | |
| 964 ? _consoleTraceHelper | |
| 965 : _postTraceHelper; | |
| 966 } | |
| 967 | |
| 968 FunctionEntity get closureFromTearOff => | |
| 969 _findHelperFunction('closureFromTearOff'); | |
| 970 | |
| 971 FunctionEntity get isJsIndexable => _findHelperFunction('isJsIndexable'); | |
| 972 | |
| 973 FunctionEntity get throwIllegalArgumentException => | |
| 974 _findHelperFunction('iae'); | |
| 975 | |
| 976 FunctionEntity get throwIndexOutOfRangeException => | |
| 977 _findHelperFunction('ioore'); | |
| 978 | |
| 979 FunctionEntity get exceptionUnwrapper => | |
| 980 _findHelperFunction('unwrapException'); | |
| 981 | |
| 982 FunctionEntity get throwRuntimeError => | |
| 983 _findHelperFunction('throwRuntimeError'); | |
| 984 | |
| 985 FunctionEntity get throwTypeError => _findHelperFunction('throwTypeError'); | |
| 986 | |
| 987 FunctionEntity get throwAbstractClassInstantiationError => | |
| 988 _findHelperFunction('throwAbstractClassInstantiationError'); | |
| 989 | |
| 990 FunctionEntity _cachedCheckConcurrentModificationError; | |
| 991 FunctionEntity get checkConcurrentModificationError => | |
| 992 _cachedCheckConcurrentModificationError ??= | |
| 993 _findHelperFunction('checkConcurrentModificationError'); | |
| 994 | |
| 995 FunctionEntity get throwConcurrentModificationError => | |
| 996 _findHelperFunction('throwConcurrentModificationError'); | |
| 997 | |
| 998 FunctionEntity _checkInt; | |
| 999 FunctionEntity get checkInt => _checkInt ??= _findHelperFunction('checkInt'); | |
| 1000 | |
| 1001 FunctionEntity _checkNum; | |
| 1002 FunctionEntity get checkNum => _checkNum ??= _findHelperFunction('checkNum'); | |
| 1003 | |
| 1004 FunctionEntity _checkString; | |
| 1005 FunctionEntity get checkString => | |
| 1006 _checkString ??= _findHelperFunction('checkString'); | |
| 1007 | |
| 1008 FunctionEntity get stringInterpolationHelper => _findHelperFunction('S'); | |
| 1009 | |
| 1010 FunctionEntity get wrapExceptionHelper => | |
| 1011 _findHelperFunction('wrapException'); | |
| 1012 | |
| 1013 FunctionEntity get throwExpressionHelper => | |
| 1014 _findHelperFunction('throwExpression'); | |
| 1015 | |
| 1016 FunctionEntity get closureConverter => | |
| 1017 _findHelperFunction('convertDartClosureToJS'); | |
| 1018 | |
| 1019 FunctionEntity get traceFromException => | |
| 1020 _findHelperFunction('getTraceFromException'); | |
| 1021 | |
| 1022 FunctionEntity get setRuntimeTypeInfo => | |
| 1023 _findHelperFunction('setRuntimeTypeInfo'); | |
| 1024 | |
| 1025 FunctionEntity get getRuntimeTypeInfo => | |
| 1026 _findHelperFunction('getRuntimeTypeInfo'); | |
| 1027 | |
| 1028 FunctionEntity get getTypeArgumentByIndex => | |
| 1029 _findHelperFunction('getTypeArgumentByIndex'); | |
| 1030 | |
| 1031 FunctionEntity get computeSignature => | |
| 1032 _findHelperFunction('computeSignature'); | |
| 1033 | |
| 1034 FunctionEntity get getRuntimeTypeArguments => | |
| 1035 _findHelperFunction('getRuntimeTypeArguments'); | |
| 1036 | |
| 1037 FunctionEntity get getRuntimeTypeArgument => | |
| 1038 _findHelperFunction('getRuntimeTypeArgument'); | |
| 1039 | |
| 1040 FunctionEntity get runtimeTypeToString => | |
| 1041 _findHelperFunction('runtimeTypeToString'); | |
| 1042 | |
| 1043 FunctionEntity get assertIsSubtype => _findHelperFunction('assertIsSubtype'); | |
| 1044 | |
| 1045 FunctionEntity get checkSubtype => _findHelperFunction('checkSubtype'); | |
| 1046 | |
| 1047 FunctionEntity get assertSubtype => _findHelperFunction('assertSubtype'); | |
| 1048 | |
| 1049 FunctionEntity get subtypeCast => _findHelperFunction('subtypeCast'); | |
| 1050 | |
| 1051 FunctionEntity get functionTypeTest => | |
| 1052 _findHelperFunction('functionTypeTest'); | |
| 1053 | |
| 1054 FunctionEntity get checkSubtypeOfRuntimeType => | |
| 1055 _findHelperFunction('checkSubtypeOfRuntimeType'); | |
| 1056 | |
| 1057 FunctionEntity get assertSubtypeOfRuntimeType => | |
| 1058 _findHelperFunction('assertSubtypeOfRuntimeType'); | |
| 1059 | |
| 1060 FunctionEntity get subtypeOfRuntimeTypeCast => | |
| 1061 _findHelperFunction('subtypeOfRuntimeTypeCast'); | |
| 1062 | |
| 1063 FunctionEntity get checkDeferredIsLoaded => | |
| 1064 _findHelperFunction('checkDeferredIsLoaded'); | |
| 1065 | |
| 1066 FunctionEntity get throwNoSuchMethod => | |
| 1067 _findHelperFunction('throwNoSuchMethod'); | |
| 1068 | |
| 1069 FunctionEntity get createRuntimeType => | |
| 1070 _findHelperFunction('createRuntimeType'); | |
| 1071 | |
| 1072 FunctionEntity get fallThroughError => | |
| 1073 _findHelperFunction("getFallThroughError"); | |
| 1074 | |
| 1075 FunctionEntity get createInvocationMirror => | |
| 1076 _findHelperFunction('createInvocationMirror'); | |
| 1077 | |
| 1078 FunctionEntity get cyclicThrowHelper => | |
| 1079 _findHelperFunction("throwCyclicInit"); | |
| 1080 | |
| 1081 FunctionEntity get defineProperty => _findHelperFunction('defineProperty'); | |
| 1082 | |
| 1083 FunctionEntity get convertRtiToRuntimeType => | |
| 1084 _findHelperFunction('convertRtiToRuntimeType'); | |
| 1085 | |
| 1086 FunctionEntity get toStringForNativeObject => | |
| 1087 _findHelperFunction('toStringForNativeObject'); | |
| 1088 | |
| 1089 FunctionEntity get hashCodeForNativeObject => | |
| 1090 _findHelperFunction('hashCodeForNativeObject'); | |
| 1091 | |
| 1092 // From dart:_internal | |
| 1093 | |
| 1094 ClassEntity _symbolImplementationClass; | |
| 1095 ClassEntity get symbolImplementationClass => | |
| 1096 _symbolImplementationClass ??= _findClass(internalLibrary, 'Symbol'); | |
| 1097 | |
| 1098 final Selector symbolValidatedConstructorSelector = | |
| 1099 new Selector.call(const PublicName('validated'), CallStructure.ONE_ARG); | |
| 1100 | |
| 1101 ConstructorEntity get symbolValidatedConstructor => | |
| 1102 _symbolValidatedConstructor ??= _findConstructor( | |
| 1103 symbolImplementationClass, symbolValidatedConstructorSelector.name); | |
| 1104 | |
| 1105 /// Returns the field that holds the internal name in the implementation class | |
| 1106 /// for `Symbol`. | |
| 1107 FieldEntity _symbolImplementationField; | |
| 1108 FieldEntity get symbolImplementationField => _symbolImplementationField ??= | |
| 1109 _env.lookupClassMember(symbolImplementationClass, '_name', | |
| 1110 required: true); | |
| 1111 | |
| 1112 ConstructorEntity _symbolValidatedConstructor; | |
| 1113 bool isSymbolValidatedConstructor(ConstructorEntity element) { | |
| 1114 if (_symbolValidatedConstructor != null) { | |
| 1115 return element == _symbolValidatedConstructor; | |
| 1116 } | |
| 1117 return false; | |
| 1118 } | |
| 1119 | |
| 1120 // From dart:_native_typed_data | |
| 1121 | |
| 1122 ClassEntity _typedArrayClass; | |
| 1123 ClassEntity get typedArrayClass => _typedArrayClass ??= _findClass( | |
| 1124 _env.lookupLibrary(Uris.dart__native_typed_data, required: true), | |
| 1125 'NativeTypedArray'); | |
| 1126 | |
| 1127 ClassEntity _typedArrayOfIntClass; | |
| 1128 ClassEntity get typedArrayOfIntClass => _typedArrayOfIntClass ??= _findClass( | |
| 1129 _env.lookupLibrary(Uris.dart__native_typed_data, required: true), | |
| 1130 'NativeTypedArrayOfInt'); | |
| 1131 | |
| 1132 // From dart:_js_embedded_names | |
| 1133 | |
| 1134 /// Holds the class for the [JsGetName] enum. | |
| 1135 ClassEntity _jsGetNameEnum; | |
| 1136 ClassEntity get jsGetNameEnum => _jsGetNameEnum ??= _findClass( | |
| 1137 _env.lookupLibrary(Uris.dart__js_embedded_names, required: true), | |
| 1138 'JsGetName'); | |
| 1139 | |
| 1140 /// Holds the class for the [JsBuiltins] enum. | |
| 1141 ClassEntity _jsBuiltinEnum; | |
| 1142 ClassEntity get jsBuiltinEnum => _jsBuiltinEnum ??= _findClass( | |
| 1143 _env.lookupLibrary(Uris.dart__js_embedded_names, required: true), | |
| 1144 'JsBuiltin'); | |
| 1145 | |
| 1146 // From dart:_isolate_helper | |
| 1147 | |
| 1148 FunctionEntity get startRootIsolate => | |
| 1149 _findLibraryMember(isolateHelperLibrary, 'startRootIsolate'); | |
| 1150 | |
| 1151 FunctionEntity get currentIsolate => | |
| 1152 _findLibraryMember(isolateHelperLibrary, '_currentIsolate'); | |
| 1153 | |
| 1154 FunctionEntity get callInIsolate => | |
| 1155 _findLibraryMember(isolateHelperLibrary, '_callInIsolate'); | |
| 1156 } | |
| 1157 | |
| 1158 /// Interface for accessing libraries, classes and members. | |
| 1159 /// | |
| 1160 /// The _env makes private and injected members directly available and | |
| 1161 /// should therefore not be used to determine scopes. | |
| 1162 abstract class ElementEnvironment { | |
|
Johnni Winther
2017/04/11 09:16:00
Again, bad merge. [ElementEnvironment] is also dec
Emily Fortuna
2017/04/11 21:31:35
fixed up. thanks!
| |
| 1163 /// Returns the main library for the compilation. | |
| 1164 LibraryEntity get mainLibrary; | |
| 1165 | |
| 1166 /// Returns the main method for the compilation. | |
| 1167 FunctionEntity get mainFunction; | |
| 1168 | |
| 1169 /// Lookup the library with the canonical [uri], fail if the library is | |
| 1170 /// missing and [required]; | |
| 1171 LibraryEntity lookupLibrary(Uri uri, {bool required: false}); | |
| 1172 | |
| 1173 /// Lookup the class [name] in [library], fail if the class is missing and | |
| 1174 /// [required]. | |
| 1175 ClassEntity lookupClass(LibraryEntity library, String name, | |
| 1176 {bool required: false}); | |
| 1177 | |
| 1178 /// Lookup the member [name] in [library], fail if the class is missing and | |
| 1179 /// [required]. | |
| 1180 MemberEntity lookupLibraryMember(LibraryEntity library, String name, | |
| 1181 {bool setter: false, bool required: false}); | |
| 1182 | |
| 1183 /// Lookup the member [name] in [cls], fail if the class is missing and | |
| 1184 /// [required]. | |
| 1185 MemberEntity lookupClassMember(ClassEntity cls, String name, | |
| 1186 {bool setter: false, bool required: false}); | |
| 1187 | |
| 1188 /// Lookup the constructor [name] in [cls], fail if the class is missing and | |
| 1189 /// [required]. | |
| 1190 ConstructorEntity lookupConstructor(ClassEntity cls, String name, | |
| 1191 {bool required: false}); | |
| 1192 | |
| 1193 /// Calls [f] for each class member declared or inherited in [cls] together | |
| 1194 /// with the class that declared the member. | |
| 1195 /// | |
| 1196 /// TODO(johnniwinther): This should not include static members of | |
| 1197 /// superclasses. | |
| 1198 void forEachClassMember( | |
| 1199 ClassEntity cls, void f(ClassEntity declarer, MemberEntity member)); | |
| 1200 | |
| 1201 /// Returns the declared superclass of [cls]. | |
| 1202 /// | |
| 1203 /// Unnamed mixin applications are skipped, for instance for these classes | |
| 1204 /// | |
| 1205 /// class S {} | |
| 1206 /// class M {} | |
| 1207 /// class C extends S with M {} | |
| 1208 /// | |
| 1209 /// the result of `getSuperClass(C)` is `S` and not the unnamed mixin | |
| 1210 /// application typically named `S+M`. | |
| 1211 ClassEntity getSuperClass(ClassEntity cls); | |
| 1212 | |
| 1213 /// Calls [f] for each class that is mixed into [cls] or one of its | |
| 1214 /// superclasses. | |
| 1215 void forEachMixin(ClassEntity cls, void f(ClassEntity mixin)); | |
| 1216 | |
| 1217 /// Create the instantiation of [cls] with the given [typeArguments]. | |
| 340 InterfaceType createInterfaceType( | 1218 InterfaceType createInterfaceType( |
| 341 ClassEntity cls, List<DartType> typeArguments) { | 1219 ClassEntity cls, List<DartType> typeArguments); |
| 342 return _env.createInterfaceType(cls, typeArguments); | 1220 |
| 343 } | 1221 /// Returns the `dynamic` type. |
| 344 | 1222 // TODO(johnniwinther): Remove this when `ResolutionDynamicType` is no longer |
| 345 LibraryEntity _coreLibrary; | 1223 // needed. |
| 346 LibraryEntity get coreLibrary => | 1224 DartType get dynamicType; |
| 347 _coreLibrary ??= _env.lookupLibrary(Uris.dart_core, required: true); | 1225 |
| 348 | 1226 /// Returns the 'raw type' of [cls]. That is, the instantiation of [cls] |
| 349 LibraryEntity _typedDataLibrary; | 1227 /// where all types arguments are `dynamic`. |
| 350 LibraryEntity get typedDataLibrary => | 1228 InterfaceType getRawType(ClassEntity cls); |
| 351 _typedDataLibrary ??= _env.lookupLibrary(Uris.dart__native_typed_data); | 1229 |
| 352 | 1230 /// Returns the 'this type' of [cls]. That is, the instantiation of [cls] |
| 353 LibraryEntity _mirrorsLibrary; | 1231 /// where the type arguments are the type variables of [cls]. |
| 354 LibraryEntity get mirrorsLibrary => | 1232 InterfaceType getThisType(ClassEntity cls); |
| 355 _mirrorsLibrary ??= _env.lookupLibrary(Uris.dart_mirrors); | 1233 |
| 356 | 1234 /// Returns `true` if [a] is a subtype of [b]. |
| 357 LibraryEntity _asyncLibrary; | 1235 bool isSubtype(DartType a, DartType b); |
| 358 LibraryEntity get asyncLibrary => | |
| 359 _asyncLibrary ??= _env.lookupLibrary(Uris.dart_async); | |
| 360 | |
| 361 // From dart:core | |
| 362 | |
| 363 ClassEntity _objectClass; | |
| 364 ClassEntity get objectClass => | |
| 365 _objectClass ??= findClass(coreLibrary, 'Object'); | |
| 366 | |
| 367 ClassEntity _boolClass; | |
| 368 ClassEntity get boolClass => _boolClass ??= findClass(coreLibrary, 'bool'); | |
| 369 | |
| 370 ClassEntity _numClass; | |
| 371 ClassEntity get numClass => _numClass ??= findClass(coreLibrary, 'num'); | |
| 372 | |
| 373 ClassEntity _intClass; | |
| 374 ClassEntity get intClass => _intClass ??= findClass(coreLibrary, 'int'); | |
| 375 | |
| 376 ClassEntity _doubleClass; | |
| 377 ClassEntity get doubleClass => | |
| 378 _doubleClass ??= findClass(coreLibrary, 'double'); | |
| 379 | |
| 380 ClassEntity _stringClass; | |
| 381 ClassEntity get stringClass => | |
| 382 _stringClass ??= findClass(coreLibrary, 'String'); | |
| 383 | |
| 384 ClassEntity _functionClass; | |
| 385 ClassEntity get functionClass => | |
| 386 _functionClass ??= findClass(coreLibrary, 'Function'); | |
| 387 | |
| 388 FunctionEntity _functionApplyMethod; | |
| 389 FunctionEntity get functionApplyMethod => | |
| 390 _functionApplyMethod ??= findClassMember(functionClass, 'apply'); | |
| 391 | |
| 392 bool isFunctionApplyMethod(MemberEntity element) => | |
| 393 element.name == 'apply' && element.enclosingClass == functionClass; | |
| 394 | |
| 395 ClassEntity _nullClass; | |
| 396 ClassEntity get nullClass => _nullClass ??= findClass(coreLibrary, 'Null'); | |
| 397 | |
| 398 ClassEntity _listClass; | |
| 399 ClassEntity get listClass => _listClass ??= findClass(coreLibrary, 'List'); | |
| 400 | |
| 401 ClassEntity _typeClass; | |
| 402 ClassEntity get typeClass => _typeClass ??= findClass(coreLibrary, 'Type'); | |
| 403 | |
| 404 ClassEntity _mapClass; | |
| 405 ClassEntity get mapClass => _mapClass ??= findClass(coreLibrary, 'Map'); | |
| 406 | |
| 407 ClassEntity _symbolClass; | |
| 408 ClassEntity get symbolClass => | |
| 409 _symbolClass ??= findClass(coreLibrary, 'Symbol'); | |
| 410 | |
| 411 ConstructorEntity _symbolConstructor; | |
| 412 ConstructorEntity get symbolConstructor => | |
| 413 _symbolConstructor ??= findConstructor(symbolClass, ''); | |
| 414 | |
| 415 bool isSymbolConstructor(Entity e) => e == symbolConstructor; | |
| 416 | |
| 417 ClassEntity _stackTraceClass; | |
| 418 ClassEntity get stackTraceClass => | |
| 419 _stackTraceClass ??= findClass(coreLibrary, 'StackTrace'); | |
| 420 | |
| 421 ClassEntity _iterableClass; | |
| 422 ClassEntity get iterableClass => | |
| 423 _iterableClass ??= findClass(coreLibrary, 'Iterable'); | |
| 424 | |
| 425 ClassEntity _resourceClass; | |
| 426 ClassEntity get resourceClass => | |
| 427 _resourceClass ??= findClass(coreLibrary, 'Resource'); | |
| 428 | |
| 429 FunctionEntity _identicalFunction; | |
| 430 FunctionEntity get identicalFunction => | |
| 431 _identicalFunction ??= findLibraryMember(coreLibrary, 'identical'); | |
| 432 | |
| 433 // From dart:async | |
| 434 | |
| 435 ClassEntity _futureClass; | |
| 436 ClassEntity get futureClass => | |
| 437 _futureClass ??= findClass(asyncLibrary, 'Future'); | |
| 438 | |
| 439 ClassEntity _streamClass; | |
| 440 ClassEntity get streamClass => | |
| 441 _streamClass ??= findClass(asyncLibrary, 'Stream'); | |
| 442 | |
| 443 ClassEntity _deferredLibraryClass; | |
| 444 ClassEntity get deferredLibraryClass => | |
| 445 _deferredLibraryClass ??= findClass(asyncLibrary, "DeferredLibrary"); | |
| 446 | |
| 447 // From dart:mirrors | |
| 448 | |
| 449 ClassEntity _mirrorSystemClass; | |
| 450 ClassEntity get mirrorSystemClass => _mirrorSystemClass ??= | |
| 451 findClass(mirrorsLibrary, 'MirrorSystem', required: false); | |
| 452 | |
| 453 FunctionEntity _mirrorSystemGetNameFunction; | |
| 454 bool isMirrorSystemGetNameFunction(MemberEntity element) { | |
| 455 if (_mirrorSystemGetNameFunction == null) { | |
| 456 if (!element.isFunction || mirrorsLibrary == null) return false; | |
| 457 ClassEntity cls = mirrorSystemClass; | |
| 458 if (element.enclosingClass != cls) return false; | |
| 459 if (cls != null) { | |
| 460 _mirrorSystemGetNameFunction = | |
| 461 findClassMember(cls, 'getName', required: false); | |
| 462 } | |
| 463 } | |
| 464 return element == _mirrorSystemGetNameFunction; | |
| 465 } | |
| 466 | |
| 467 ClassEntity _mirrorsUsedClass; | |
| 468 ClassEntity get mirrorsUsedClass => _mirrorsUsedClass ??= | |
| 469 findClass(mirrorsLibrary, 'MirrorsUsed', required: false); | |
| 470 | |
| 471 bool isMirrorsUsedConstructor(ConstructorEntity element) => | |
| 472 mirrorsLibrary != null && mirrorsUsedClass == element.enclosingClass; | |
| 473 | |
| 474 // From dart:typed_data | |
| 475 | |
| 476 ClassEntity _typedDataClass; | |
| 477 ClassEntity get typedDataClass => | |
| 478 _typedDataClass ??= findClass(typedDataLibrary, 'NativeTypedData'); | |
| 479 | |
| 480 bool isUnnamedListConstructor(ConstructorEntity element) => | |
| 481 element.name == '' && element.enclosingClass == listClass; | |
| 482 | |
| 483 bool isFilledListConstructor(ConstructorEntity element) => | |
| 484 element.name == 'filled' && element.enclosingClass == listClass; | |
| 485 | |
| 486 // TODO(johnniwinther): Change types to `ClassEntity` when these are not | |
| 487 // called with unrelated elements. | |
| 488 bool isNumberOrStringSupertype(/*Class*/ Entity element) { | |
| 489 return element == findClass(coreLibrary, 'Comparable', required: false); | |
| 490 } | |
| 491 | |
| 492 bool isStringOnlySupertype(/*Class*/ Entity element) { | |
| 493 return element == findClass(coreLibrary, 'Pattern', required: false); | |
| 494 } | |
| 495 | |
| 496 bool isListSupertype(/*Class*/ Entity element) => element == iterableClass; | |
| 497 | |
| 498 @override | |
| 499 InterfaceType get objectType => getRawType(objectClass); | |
| 500 | |
| 501 @override | |
| 502 InterfaceType get boolType => getRawType(boolClass); | |
| 503 | |
| 504 @override | |
| 505 InterfaceType get doubleType => getRawType(doubleClass); | |
| 506 | |
| 507 @override | |
| 508 InterfaceType get functionType => getRawType(functionClass); | |
| 509 | |
| 510 @override | |
| 511 InterfaceType get intType => getRawType(intClass); | |
| 512 | |
| 513 @override | |
| 514 InterfaceType get resourceType => getRawType(resourceClass); | |
| 515 | |
| 516 @override | |
| 517 InterfaceType listType([DartType elementType]) { | |
| 518 if (elementType == null) { | |
| 519 return getRawType(listClass); | |
| 520 } | |
| 521 return createInterfaceType(listClass, [elementType]); | |
| 522 } | |
| 523 | |
| 524 @override | |
| 525 InterfaceType mapType([DartType keyType, DartType valueType]) { | |
| 526 if (keyType == null && valueType == null) { | |
| 527 return getRawType(mapClass); | |
| 528 } else if (keyType == null) { | |
| 529 keyType = dynamicType; | |
| 530 } else if (valueType == null) { | |
| 531 valueType = dynamicType; | |
| 532 } | |
| 533 return createInterfaceType(mapClass, [keyType, valueType]); | |
| 534 } | |
| 535 | |
| 536 @override | |
| 537 InterfaceType get nullType => getRawType(nullClass); | |
| 538 | |
| 539 @override | |
| 540 InterfaceType get numType => getRawType(numClass); | |
| 541 | |
| 542 @override | |
| 543 InterfaceType get stringType => getRawType(stringClass); | |
| 544 | |
| 545 @override | |
| 546 InterfaceType get symbolType => getRawType(symbolClass); | |
| 547 | |
| 548 @override | |
| 549 InterfaceType get typeType => getRawType(typeClass); | |
| 550 | |
| 551 @override | |
| 552 InterfaceType get stackTraceType => getRawType(stackTraceClass); | |
| 553 | |
| 554 @override | |
| 555 InterfaceType iterableType([DartType elementType]) { | |
| 556 if (elementType == null) { | |
| 557 return getRawType(iterableClass); | |
| 558 } | |
| 559 return createInterfaceType(iterableClass, [elementType]); | |
| 560 } | |
| 561 | |
| 562 @override | |
| 563 InterfaceType futureType([DartType elementType]) { | |
| 564 if (elementType == null) { | |
| 565 return getRawType(futureClass); | |
| 566 } | |
| 567 return createInterfaceType(futureClass, [elementType]); | |
| 568 } | |
| 569 | |
| 570 @override | |
| 571 InterfaceType streamType([DartType elementType]) { | |
| 572 if (elementType == null) { | |
| 573 return getRawType(streamClass); | |
| 574 } | |
| 575 return createInterfaceType(streamClass, [elementType]); | |
| 576 } | |
| 577 } | 1236 } |
| OLD | NEW |