| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
| 9 * compiled. | 9 * compiled. |
| 10 */ | 10 */ |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 FunctionElement helperForBadMain() => null; | 517 FunctionElement helperForBadMain() => null; |
| 518 | 518 |
| 519 FunctionElement helperForMissingMain() => null; | 519 FunctionElement helperForMissingMain() => null; |
| 520 | 520 |
| 521 FunctionElement helperForMainArity() => null; | 521 FunctionElement helperForMainArity() => null; |
| 522 | 522 |
| 523 void forgetElement(Element element) {} | 523 void forgetElement(Element element) {} |
| 524 | 524 |
| 525 void registerMainHasArguments(Enqueuer enqueuer) {} | 525 void registerMainHasArguments(Enqueuer enqueuer) {} |
| 526 | 526 |
| 527 void registerAsyncMarker( | 527 void registerAsyncMarker(FunctionElement element, |
| 528 FunctionElement element, | 528 Enqueuer enqueuer, |
| 529 Enqueuer enqueuer, | 529 Registry registry) {} |
| 530 Registry registry) {} | |
| 531 } | 530 } |
| 532 | 531 |
| 533 /// Backend callbacks function specific to the resolution phase. | 532 /// Backend callbacks function specific to the resolution phase. |
| 534 class ResolutionCallbacks { | 533 class ResolutionCallbacks { |
| 535 /// Register that [node] is a call to `assert`. | 534 /// Register that [node] is a call to `assert`. |
| 536 void onAssert(Send node, Registry registry) {} | 535 void onAssert(Send node, Registry registry) {} |
| 537 | 536 |
| 538 /// Called during resolution to notify to the backend that the | 537 /// Called during resolution to notify to the backend that the |
| 539 /// program uses string interpolation. | 538 /// program uses string interpolation. |
| 540 void onStringInterpolation(Registry registry) {} | 539 void onStringInterpolation(Registry registry) {} |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 586 |
| 588 /// Register that a super call will end up calling | 587 /// Register that a super call will end up calling |
| 589 /// [: super.noSuchMethod :]. | 588 /// [: super.noSuchMethod :]. |
| 590 void onSuperNoSuchMethod(Registry registry) {} | 589 void onSuperNoSuchMethod(Registry registry) {} |
| 591 | 590 |
| 592 /// Register that the application creates a constant map. | 591 /// Register that the application creates a constant map. |
| 593 void onConstantMap(Registry registry) {} | 592 void onConstantMap(Registry registry) {} |
| 594 | 593 |
| 595 /// Called when resolving the `Symbol` constructor. | 594 /// Called when resolving the `Symbol` constructor. |
| 596 void onSymbolConstructor(Registry registry) {} | 595 void onSymbolConstructor(Registry registry) {} |
| 597 | |
| 598 /// Called when resolving a literal int. | |
| 599 void onLiteralInt(Registry registry) {} | |
| 600 | |
| 601 /// Called when resolving a literal double. | |
| 602 void onLiteralDouble(Registry registry) {} | |
| 603 | |
| 604 /// Called when resolving a literal bool. | |
| 605 void onLiteralBool(Registry registry) {} | |
| 606 | |
| 607 /// Called when resolving a literal String. | |
| 608 void onLiteralString(Registry registry) {} | |
| 609 | |
| 610 /// Called when resolving a literal null. | |
| 611 void onLiteralNull(Registry registry) {} | |
| 612 | |
| 613 /// Called when resolving a literal Symbol. | |
| 614 void onLiteralSymbol(Registry registry) {} | |
| 615 | |
| 616 /// Called when resolving a literal Function (aka a closure). | |
| 617 void onLiteralFunction(Registry registry) {} | |
| 618 } | 596 } |
| 619 | 597 |
| 620 /** | 598 /** |
| 621 * Key class used in [TokenMap] in which the hash code for a token is based | 599 * Key class used in [TokenMap] in which the hash code for a token is based |
| 622 * on the [charOffset]. | 600 * on the [charOffset]. |
| 623 */ | 601 */ |
| 624 class TokenKey { | 602 class TokenKey { |
| 625 final Token token; | 603 final Token token; |
| 626 TokenKey(this.token); | 604 TokenKey(this.token); |
| 627 int get hashCode => token.charOffset; | 605 int get hashCode => token.charOffset; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 ClassElement get symbolClass => _coreTypes.symbolClass; | 798 ClassElement get symbolClass => _coreTypes.symbolClass; |
| 821 ClassElement get stackTraceClass => _coreTypes.stackTraceClass; | 799 ClassElement get stackTraceClass => _coreTypes.stackTraceClass; |
| 822 ClassElement get futureClass => _coreTypes.futureClass; | 800 ClassElement get futureClass => _coreTypes.futureClass; |
| 823 ClassElement get iterableClass => _coreTypes.iterableClass; | 801 ClassElement get iterableClass => _coreTypes.iterableClass; |
| 824 ClassElement get streamClass => _coreTypes.streamClass; | 802 ClassElement get streamClass => _coreTypes.streamClass; |
| 825 | 803 |
| 826 CoreTypes get coreTypes => _coreTypes; | 804 CoreTypes get coreTypes => _coreTypes; |
| 827 | 805 |
| 828 ClassElement typedDataClass; | 806 ClassElement typedDataClass; |
| 829 | 807 |
| 830 /// The class for the [proxy] value defined in dart:core. | 808 /// The constant for the [proxy] variable defined in dart:core. |
| 831 ClassElement proxyClass; | 809 ConstantValue proxyConstant; |
| 832 | 810 |
| 833 // TODO(johnniwinther): Move this to the JavaScriptBackend. | 811 // TODO(johnniwinther): Move this to the JavaScriptBackend. |
| 834 /// The class for patch annotation defined in dart:_js_helper. | 812 /// The class for patch annotation defined in dart:_js_helper. |
| 835 ClassElement patchAnnotationClass; | 813 ClassElement patchAnnotationClass; |
| 836 | 814 |
| 837 // TODO(johnniwinther): Move this to the JavaScriptBackend. | 815 // TODO(johnniwinther): Move this to the JavaScriptBackend. |
| 838 ClassElement nativeAnnotationClass; | 816 ClassElement nativeAnnotationClass; |
| 839 | 817 |
| 840 // Initialized after symbolClass has been resolved. | 818 // Initialized after symbolClass has been resolved. |
| 841 FunctionElement symbolConstructor; | 819 FunctionElement symbolConstructor; |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 }); | 1324 }); |
| 1347 reportWarning(NO_LOCATION_SPANNABLE, | 1325 reportWarning(NO_LOCATION_SPANNABLE, |
| 1348 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, | 1326 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS, |
| 1349 {'importChain': importChains.join( | 1327 {'importChain': importChains.join( |
| 1350 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}); | 1328 MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}); |
| 1351 } | 1329 } |
| 1352 | 1330 |
| 1353 functionClass.ensureResolved(this); | 1331 functionClass.ensureResolved(this); |
| 1354 functionApplyMethod = functionClass.lookupLocalMember('apply'); | 1332 functionApplyMethod = functionClass.lookupLocalMember('apply'); |
| 1355 | 1333 |
| 1334 proxyConstant = |
| 1335 resolver.constantCompiler.compileConstant( |
| 1336 coreLibrary.find('proxy')).value; |
| 1337 |
| 1356 if (preserveComments) { | 1338 if (preserveComments) { |
| 1357 return libraryLoader.loadLibrary(DART_MIRRORS) | 1339 return libraryLoader.loadLibrary(DART_MIRRORS) |
| 1358 .then((LibraryElement libraryElement) { | 1340 .then((LibraryElement libraryElement) { |
| 1359 documentClass = libraryElement.find('Comment'); | 1341 documentClass = libraryElement.find('Comment'); |
| 1360 }); | 1342 }); |
| 1361 } | 1343 } |
| 1362 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); | 1344 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); |
| 1363 } | 1345 } |
| 1364 | 1346 |
| 1365 Element findRequiredElement(LibraryElement library, String name) { | 1347 Element findRequiredElement(LibraryElement library, String name) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 _coreTypes.doubleClass = lookupCoreClass('double'); | 1396 _coreTypes.doubleClass = lookupCoreClass('double'); |
| 1415 _coreTypes.stringClass = lookupCoreClass('String'); | 1397 _coreTypes.stringClass = lookupCoreClass('String'); |
| 1416 _coreTypes.functionClass = lookupCoreClass('Function'); | 1398 _coreTypes.functionClass = lookupCoreClass('Function'); |
| 1417 _coreTypes.listClass = lookupCoreClass('List'); | 1399 _coreTypes.listClass = lookupCoreClass('List'); |
| 1418 _coreTypes.typeClass = lookupCoreClass('Type'); | 1400 _coreTypes.typeClass = lookupCoreClass('Type'); |
| 1419 _coreTypes.mapClass = lookupCoreClass('Map'); | 1401 _coreTypes.mapClass = lookupCoreClass('Map'); |
| 1420 _coreTypes.nullClass = lookupCoreClass('Null'); | 1402 _coreTypes.nullClass = lookupCoreClass('Null'); |
| 1421 _coreTypes.stackTraceClass = lookupCoreClass('StackTrace'); | 1403 _coreTypes.stackTraceClass = lookupCoreClass('StackTrace'); |
| 1422 _coreTypes.iterableClass = lookupCoreClass('Iterable'); | 1404 _coreTypes.iterableClass = lookupCoreClass('Iterable'); |
| 1423 _coreTypes.symbolClass = lookupCoreClass('Symbol'); | 1405 _coreTypes.symbolClass = lookupCoreClass('Symbol'); |
| 1424 proxyClass = lookupCoreClass('_Proxy'); | |
| 1425 if (!missingCoreClasses.isEmpty) { | 1406 if (!missingCoreClasses.isEmpty) { |
| 1426 internalError( | 1407 internalError( |
| 1427 coreLibrary, | 1408 coreLibrary, |
| 1428 'dart:core library does not contain required classes: ' | 1409 'dart:core library does not contain required classes: ' |
| 1429 '$missingCoreClasses'); | 1410 '$missingCoreClasses'); |
| 1430 } | 1411 } |
| 1431 } | 1412 } |
| 1432 | 1413 |
| 1433 Element _unnamedListConstructor; | 1414 Element _unnamedListConstructor; |
| 1434 Element get unnamedListConstructor { | 1415 Element get unnamedListConstructor { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 } | 1667 } |
| 1687 } | 1668 } |
| 1688 } | 1669 } |
| 1689 } | 1670 } |
| 1690 | 1671 |
| 1691 void processQueue(Enqueuer world, Element main) { | 1672 void processQueue(Enqueuer world, Element main) { |
| 1692 world.nativeEnqueuer.processNativeClasses(libraryLoader.libraries); | 1673 world.nativeEnqueuer.processNativeClasses(libraryLoader.libraries); |
| 1693 if (main != null && !main.isErroneous) { | 1674 if (main != null && !main.isErroneous) { |
| 1694 FunctionElement mainMethod = main; | 1675 FunctionElement mainMethod = main; |
| 1695 if (mainMethod.computeSignature(this).parameterCount != 0) { | 1676 if (mainMethod.computeSignature(this).parameterCount != 0) { |
| 1677 // The first argument could be a list of strings. |
| 1678 world.registerInstantiatedClass( |
| 1679 backend.listImplementation, globalDependencies); |
| 1680 world.registerInstantiatedClass( |
| 1681 backend.stringImplementation, globalDependencies); |
| 1682 |
| 1696 backend.registerMainHasArguments(world); | 1683 backend.registerMainHasArguments(world); |
| 1697 } | 1684 } |
| 1698 world.addToWorkList(main); | 1685 world.addToWorkList(main); |
| 1699 } | 1686 } |
| 1700 if (verbose) { | 1687 if (verbose) { |
| 1701 progress.reset(); | 1688 progress.reset(); |
| 1702 } | 1689 } |
| 1703 world.forEach((WorkItem work) { | 1690 world.forEach((WorkItem work) { |
| 1704 withCurrentElement(work.element, () => work.run(this, world)); | 1691 withCurrentElement(work.element, () => work.run(this, world)); |
| 1705 }); | 1692 }); |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2421 return futureClass.computeType(compiler).createInstantiation([elementType]); | 2408 return futureClass.computeType(compiler).createInstantiation([elementType]); |
| 2422 } | 2409 } |
| 2423 | 2410 |
| 2424 @override | 2411 @override |
| 2425 InterfaceType streamType([DartType elementType = const DynamicType()]) { | 2412 InterfaceType streamType([DartType elementType = const DynamicType()]) { |
| 2426 return streamClass.computeType(compiler).createInstantiation([elementType]); | 2413 return streamClass.computeType(compiler).createInstantiation([elementType]); |
| 2427 } | 2414 } |
| 2428 } | 2415 } |
| 2429 | 2416 |
| 2430 typedef void InternalErrorFunction(Spannable location, String message); | 2417 typedef void InternalErrorFunction(Spannable location, String message); |
| OLD | NEW |