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 js_backend.backend; | 5 library js_backend.backend; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
10 | 10 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 FunctionInlineCache inlineCache = new FunctionInlineCache(); | 330 FunctionInlineCache inlineCache = new FunctionInlineCache(); |
331 | 331 |
332 /// If [true], the compiler will emit code that logs whenever a method is | 332 /// If [true], the compiler will emit code that logs whenever a method is |
333 /// called. When TRACE_METHOD is 'console' this will be logged | 333 /// called. When TRACE_METHOD is 'console' this will be logged |
334 /// directly in the JavaScript console. When TRACE_METHOD is 'post' the | 334 /// directly in the JavaScript console. When TRACE_METHOD is 'post' the |
335 /// information will be sent to a server via a POST request. | 335 /// information will be sent to a server via a POST request. |
336 static const String TRACE_METHOD = const String.fromEnvironment('traceCalls'); | 336 static const String TRACE_METHOD = const String.fromEnvironment('traceCalls'); |
337 static const bool TRACE_CALLS = | 337 static const bool TRACE_CALLS = |
338 TRACE_METHOD == 'post' || TRACE_METHOD == 'console'; | 338 TRACE_METHOD == 'post' || TRACE_METHOD == 'console'; |
339 | 339 |
340 TypeMask get stringType => compiler.closedWorld.commonMasks.stringType; | |
341 TypeMask get doubleType => compiler.closedWorld.commonMasks.doubleType; | |
342 TypeMask get intType => compiler.closedWorld.commonMasks.intType; | |
343 TypeMask get uint32Type => compiler.closedWorld.commonMasks.uint32Type; | |
344 TypeMask get uint31Type => compiler.closedWorld.commonMasks.uint31Type; | |
345 TypeMask get positiveIntType => | |
346 compiler.closedWorld.commonMasks.positiveIntType; | |
347 TypeMask get numType => compiler.closedWorld.commonMasks.numType; | |
348 TypeMask get boolType => compiler.closedWorld.commonMasks.boolType; | |
349 TypeMask get dynamicType => compiler.closedWorld.commonMasks.dynamicType; | |
350 TypeMask get nullType => compiler.closedWorld.commonMasks.nullType; | |
351 TypeMask get emptyType => const TypeMask.nonNullEmpty(); | |
352 TypeMask get nonNullType => compiler.closedWorld.commonMasks.nonNullType; | |
353 | |
354 TypeMask _indexablePrimitiveTypeCache; | |
355 TypeMask get indexablePrimitiveType { | |
356 if (_indexablePrimitiveTypeCache == null) { | |
357 _indexablePrimitiveTypeCache = new TypeMask.nonNullSubtype( | |
358 helpers.jsIndexableClass, compiler.closedWorld); | |
359 } | |
360 return _indexablePrimitiveTypeCache; | |
361 } | |
362 | |
363 TypeMask _readableArrayTypeCache; | |
364 TypeMask get readableArrayType { | |
365 if (_readableArrayTypeCache == null) { | |
366 _readableArrayTypeCache = new TypeMask.nonNullSubclass( | |
367 helpers.jsArrayClass, compiler.closedWorld); | |
368 } | |
369 return _readableArrayTypeCache; | |
370 } | |
371 | |
372 TypeMask _mutableArrayTypeCache; | |
373 TypeMask get mutableArrayType { | |
374 if (_mutableArrayTypeCache == null) { | |
375 _mutableArrayTypeCache = new TypeMask.nonNullSubclass( | |
376 helpers.jsMutableArrayClass, compiler.closedWorld); | |
377 } | |
378 return _mutableArrayTypeCache; | |
379 } | |
380 | |
381 TypeMask _fixedArrayTypeCache; | |
382 TypeMask get fixedArrayType { | |
383 if (_fixedArrayTypeCache == null) { | |
384 _fixedArrayTypeCache = new TypeMask.nonNullExact( | |
385 helpers.jsFixedArrayClass, compiler.closedWorld); | |
386 } | |
387 return _fixedArrayTypeCache; | |
388 } | |
389 | |
390 TypeMask _extendableArrayTypeCache; | |
391 TypeMask get extendableArrayType { | |
392 if (_extendableArrayTypeCache == null) { | |
393 _extendableArrayTypeCache = new TypeMask.nonNullExact( | |
394 helpers.jsExtendableArrayClass, compiler.closedWorld); | |
395 } | |
396 return _extendableArrayTypeCache; | |
397 } | |
398 | |
399 TypeMask _unmodifiableArrayTypeCache; | |
400 TypeMask get unmodifiableArrayType { | |
401 if (_unmodifiableArrayTypeCache == null) { | |
402 _unmodifiableArrayTypeCache = new TypeMask.nonNullExact( | |
403 helpers.jsUnmodifiableArrayClass, compiler.closedWorld); | |
404 } | |
405 return _fixedArrayTypeCache; | |
406 } | |
407 | |
408 /// Maps special classes to their implementation (JSXxx) class. | 340 /// Maps special classes to their implementation (JSXxx) class. |
409 Map<ClassElement, ClassElement> implementationClasses; | 341 Map<ClassElement, ClassElement> implementationClasses; |
410 | 342 |
411 bool needToInitializeIsolateAffinityTag = false; | 343 bool needToInitializeIsolateAffinityTag = false; |
412 bool needToInitializeDispatchProperty = false; | 344 bool needToInitializeDispatchProperty = false; |
413 | 345 |
414 final Namer namer; | 346 final Namer namer; |
415 | 347 |
416 /** | 348 /** |
417 * A collection of selectors that must have a one shot interceptor | 349 * A collection of selectors that must have a one shot interceptor |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 | 1412 |
1481 bool classNeedsRtiField(ClassElement cls) { | 1413 bool classNeedsRtiField(ClassElement cls) { |
1482 if (cls.rawType.typeArguments.isEmpty) return false; | 1414 if (cls.rawType.typeArguments.isEmpty) return false; |
1483 if (hasRuntimeTypeSupport) return true; | 1415 if (hasRuntimeTypeSupport) return true; |
1484 return rti.classesNeedingRti.contains(cls.declaration); | 1416 return rti.classesNeedingRti.contains(cls.declaration); |
1485 } | 1417 } |
1486 | 1418 |
1487 bool isComplexNoSuchMethod(FunctionElement element) => | 1419 bool isComplexNoSuchMethod(FunctionElement element) => |
1488 noSuchMethodRegistry.isComplex(element); | 1420 noSuchMethodRegistry.isComplex(element); |
1489 | 1421 |
1490 bool isDefaultEqualityImplementation(Element element) { | |
1491 assert(element.name == '=='); | |
1492 ClassElement classElement = element.enclosingClass; | |
1493 return classElement == coreClasses.objectClass || | |
1494 classElement == helpers.jsInterceptorClass || | |
1495 classElement == helpers.jsNullClass; | |
1496 } | |
1497 | |
1498 bool methodNeedsRti(FunctionElement function) { | 1422 bool methodNeedsRti(FunctionElement function) { |
1499 return rti.methodsNeedingRti.contains(function) || hasRuntimeTypeSupport; | 1423 return rti.methodsNeedingRti.contains(function) || hasRuntimeTypeSupport; |
1500 } | 1424 } |
1501 | 1425 |
1502 CodegenEnqueuer get codegenEnqueuer => compiler.enqueuer.codegen; | 1426 CodegenEnqueuer get codegenEnqueuer => compiler.enqueuer.codegen; |
1503 | 1427 |
1504 CodegenEnqueuer createCodegenEnqueuer(CompilerTask task, Compiler compiler) { | 1428 CodegenEnqueuer createCodegenEnqueuer(CompilerTask task, Compiler compiler) { |
1505 return new CodegenEnqueuer( | 1429 return new CodegenEnqueuer( |
1506 task, compiler, const TreeShakingEnqueuerStrategy()); | 1430 task, compiler, const TreeShakingEnqueuerStrategy()); |
1507 } | 1431 } |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 * reflection. | 2016 * reflection. |
2093 * | 2017 * |
2094 * We have to precompute this set as we cannot easily answer the need for | 2018 * We have to precompute this set as we cannot easily answer the need for |
2095 * reflection locally when looking at the member: We lack the information by | 2019 * reflection locally when looking at the member: We lack the information by |
2096 * which classes a member is inherited. Called after resolution is complete. | 2020 * which classes a member is inherited. Called after resolution is complete. |
2097 * | 2021 * |
2098 * We filter out private libraries here, as their elements should not | 2022 * We filter out private libraries here, as their elements should not |
2099 * be visible by reflection unless some other interfaces makes them | 2023 * be visible by reflection unless some other interfaces makes them |
2100 * accessible. | 2024 * accessible. |
2101 */ | 2025 */ |
2102 computeMembersNeededForReflection() { | 2026 void computeMembersNeededForReflection() { |
2103 if (_membersNeededForReflection != null) return; | 2027 if (_membersNeededForReflection != null) return; |
2104 if (compiler.commonElements.mirrorsLibrary == null) { | 2028 if (compiler.commonElements.mirrorsLibrary == null) { |
2105 _membersNeededForReflection = const ImmutableEmptySet<Element>(); | 2029 _membersNeededForReflection = const ImmutableEmptySet<Element>(); |
2106 return; | 2030 return; |
2107 } | 2031 } |
2108 // Compute a mapping from class to the closures it contains, so we | 2032 // Compute a mapping from class to the closures it contains, so we |
2109 // can include the correct ones when including the class. | 2033 // can include the correct ones when including the class. |
2110 Map<ClassElement, List<LocalFunctionElement>> closureMap = | 2034 Map<ClassElement, List<LocalFunctionElement>> closureMap = |
2111 new Map<ClassElement, List<LocalFunctionElement>>(); | 2035 new Map<ClassElement, List<LocalFunctionElement>>(); |
2112 for (LocalFunctionElement closure in compiler.resolverWorld.allClosures) { | 2036 for (LocalFunctionElement closure in compiler.resolverWorld.allClosures) { |
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3280 JavaScriptBackendClasses(this.helpers); | 3204 JavaScriptBackendClasses(this.helpers); |
3281 | 3205 |
3282 ClassElement get intImplementation => helpers.jsIntClass; | 3206 ClassElement get intImplementation => helpers.jsIntClass; |
3283 ClassElement get uint32Implementation => helpers.jsUInt32Class; | 3207 ClassElement get uint32Implementation => helpers.jsUInt32Class; |
3284 ClassElement get uint31Implementation => helpers.jsUInt31Class; | 3208 ClassElement get uint31Implementation => helpers.jsUInt31Class; |
3285 ClassElement get positiveIntImplementation => helpers.jsPositiveIntClass; | 3209 ClassElement get positiveIntImplementation => helpers.jsPositiveIntClass; |
3286 ClassElement get doubleImplementation => helpers.jsDoubleClass; | 3210 ClassElement get doubleImplementation => helpers.jsDoubleClass; |
3287 ClassElement get numImplementation => helpers.jsNumberClass; | 3211 ClassElement get numImplementation => helpers.jsNumberClass; |
3288 ClassElement get stringImplementation => helpers.jsStringClass; | 3212 ClassElement get stringImplementation => helpers.jsStringClass; |
3289 ClassElement get listImplementation => helpers.jsArrayClass; | 3213 ClassElement get listImplementation => helpers.jsArrayClass; |
| 3214 ClassElement get mutableListImplementation => helpers.jsMutableArrayClass; |
3290 ClassElement get constListImplementation => helpers.jsUnmodifiableArrayClass; | 3215 ClassElement get constListImplementation => helpers.jsUnmodifiableArrayClass; |
3291 ClassElement get fixedListImplementation => helpers.jsFixedArrayClass; | 3216 ClassElement get fixedListImplementation => helpers.jsFixedArrayClass; |
3292 ClassElement get growableListImplementation => helpers.jsExtendableArrayClass; | 3217 ClassElement get growableListImplementation => helpers.jsExtendableArrayClass; |
3293 ClassElement get mapImplementation => helpers.mapLiteralClass; | 3218 ClassElement get mapImplementation => helpers.mapLiteralClass; |
3294 ClassElement get constMapImplementation => helpers.constMapLiteralClass; | 3219 ClassElement get constMapImplementation => helpers.constMapLiteralClass; |
3295 ClassElement get typeImplementation => helpers.typeLiteralClass; | 3220 ClassElement get typeImplementation => helpers.typeLiteralClass; |
3296 ClassElement get boolImplementation => helpers.jsBoolClass; | 3221 ClassElement get boolImplementation => helpers.jsBoolClass; |
3297 ClassElement get nullImplementation => helpers.jsNullClass; | 3222 ClassElement get nullImplementation => helpers.jsNullClass; |
3298 ClassElement get syncStarIterableImplementation => helpers.syncStarIterable; | 3223 ClassElement get syncStarIterableImplementation => helpers.syncStarIterable; |
3299 ClassElement get asyncFutureImplementation => helpers.futureImplementation; | 3224 ClassElement get asyncFutureImplementation => helpers.futureImplementation; |
3300 ClassElement get asyncStarStreamImplementation => helpers.controllerStream; | 3225 ClassElement get asyncStarStreamImplementation => helpers.controllerStream; |
3301 ClassElement get functionImplementation => helpers.coreClasses.functionClass; | 3226 ClassElement get functionImplementation => helpers.coreClasses.functionClass; |
| 3227 ClassElement get indexableImplementation => helpers.jsIndexableClass; |
| 3228 ClassElement get mutableIndexableImplementation => |
| 3229 helpers.jsMutableIndexableClass; |
| 3230 |
| 3231 bool isDefaultEqualityImplementation(Element element) { |
| 3232 assert(element.name == '=='); |
| 3233 ClassElement classElement = element.enclosingClass; |
| 3234 return classElement == helpers.coreClasses.objectClass || |
| 3235 classElement == helpers.jsInterceptorClass || |
| 3236 classElement == helpers.jsNullClass; |
| 3237 } |
3302 } | 3238 } |
OLD | NEW |