| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 final bool enableMinification; | 186 final bool enableMinification; |
| 187 final bool enableTypeAssertions; | 187 final bool enableTypeAssertions; |
| 188 final bool enableUserAssertions; | 188 final bool enableUserAssertions; |
| 189 final bool enableConcreteTypeInference; | 189 final bool enableConcreteTypeInference; |
| 190 /** | 190 /** |
| 191 * The maximum size of a concrete type before it widens to dynamic during | 191 * The maximum size of a concrete type before it widens to dynamic during |
| 192 * concrete type inference. | 192 * concrete type inference. |
| 193 */ | 193 */ |
| 194 final int maxConcreteTypeSize; | 194 final int maxConcreteTypeSize; |
| 195 final bool analyzeAll; | 195 final bool analyzeAll; |
| 196 final bool analyzeOnly; | |
| 197 final bool enableNativeLiveTypeAnalysis; | 196 final bool enableNativeLiveTypeAnalysis; |
| 198 final bool rejectDeprecatedFeatures; | 197 final bool rejectDeprecatedFeatures; |
| 199 final bool checkDeprecationInSdk; | 198 final bool checkDeprecationInSdk; |
| 200 | 199 |
| 201 /** | 200 /** |
| 202 * If [:true:], comment tokens are collected in [commentMap] during scanning. | 201 * If [:true:], comment tokens are collected in [commentMap] during scanning. |
| 203 */ | 202 */ |
| 204 final bool preserveComments; | 203 final bool preserveComments; |
| 205 | 204 |
| 206 bool disableInlining = false; | 205 bool disableInlining = false; |
| 207 | 206 |
| 208 List<Uri> librariesToAnalyzeWhenRun; | |
| 209 | |
| 210 final Tracer tracer; | 207 final Tracer tracer; |
| 211 | 208 |
| 212 CompilerTask measuredTask; | 209 CompilerTask measuredTask; |
| 213 Element _currentElement; | 210 Element _currentElement; |
| 214 LibraryElement coreLibrary; | 211 LibraryElement coreLibrary; |
| 215 LibraryElement isolateLibrary; | 212 LibraryElement isolateLibrary; |
| 216 LibraryElement isolateHelperLibrary; | 213 LibraryElement isolateHelperLibrary; |
| 217 LibraryElement jsHelperLibrary; | 214 LibraryElement jsHelperLibrary; |
| 218 LibraryElement interceptorsLibrary; | 215 LibraryElement interceptorsLibrary; |
| 219 LibraryElement foreignLibrary; | 216 LibraryElement foreignLibrary; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 this.enableTypeAssertions: false, | 317 this.enableTypeAssertions: false, |
| 321 this.enableUserAssertions: false, | 318 this.enableUserAssertions: false, |
| 322 this.enableConcreteTypeInference: false, | 319 this.enableConcreteTypeInference: false, |
| 323 this.maxConcreteTypeSize: 5, | 320 this.maxConcreteTypeSize: 5, |
| 324 this.enableMinification: false, | 321 this.enableMinification: false, |
| 325 this.enableNativeLiveTypeAnalysis: false, | 322 this.enableNativeLiveTypeAnalysis: false, |
| 326 bool emitJavaScript: true, | 323 bool emitJavaScript: true, |
| 327 bool generateSourceMap: true, | 324 bool generateSourceMap: true, |
| 328 bool disallowUnsafeEval: false, | 325 bool disallowUnsafeEval: false, |
| 329 this.analyzeAll: false, | 326 this.analyzeAll: false, |
| 330 this.analyzeOnly: false, | |
| 331 this.rejectDeprecatedFeatures: false, | 327 this.rejectDeprecatedFeatures: false, |
| 332 this.checkDeprecationInSdk: false, | 328 this.checkDeprecationInSdk: false, |
| 333 this.preserveComments: false, | 329 this.preserveComments: false, |
| 334 List<String> strips: const []}) | 330 List<String> strips: const []}) |
| 335 : libraries = new Map<String, LibraryElement>(), | 331 : libraries = new Map<String, LibraryElement>(), |
| 336 progress = new Stopwatch() { | 332 progress = new Stopwatch() { |
| 337 progress.start(); | 333 progress.start(); |
| 338 world = new World(this); | 334 world = new World(this); |
| 339 | 335 |
| 340 closureMapping.ClosureNamer closureNamer; | 336 closureMapping.ClosureNamer closureNamer; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 if (libraryName == 'dart:isolate' | 627 if (libraryName == 'dart:isolate' |
| 632 || libraryName == 'dart:html' | 628 || libraryName == 'dart:html' |
| 633 // TODO(floitsch): create a separate async-helper library instead of | 629 // TODO(floitsch): create a separate async-helper library instead of |
| 634 // importing the isolate-library just for TimerImpl. | 630 // importing the isolate-library just for TimerImpl. |
| 635 || libraryName == 'dart:async') { | 631 || libraryName == 'dart:async') { |
| 636 importIsolateHelperLibrary(library); | 632 importIsolateHelperLibrary(library); |
| 637 } | 633 } |
| 638 } | 634 } |
| 639 | 635 |
| 640 void runCompiler(Uri uri) { | 636 void runCompiler(Uri uri) { |
| 641 assert(uri != null || analyzeOnly); | 637 log('compiling $uri ($BUILD_ID)'); |
| 642 scanBuiltinLibraries(); | 638 scanBuiltinLibraries(); |
| 643 if (librariesToAnalyzeWhenRun != null) { | 639 mainApp = libraryLoader.loadLibrary(uri, null, uri); |
| 644 for (Uri libraryUri in librariesToAnalyzeWhenRun) { | |
| 645 log('analyzing $libraryUri ($BUILD_ID)'); | |
| 646 libraryLoader.loadLibrary(libraryUri, null, libraryUri); | |
| 647 } | |
| 648 } | |
| 649 if (uri != null) { | |
| 650 if (analyzeOnly) { | |
| 651 log('analyzing $uri ($BUILD_ID)'); | |
| 652 } else { | |
| 653 log('compiling $uri ($BUILD_ID)'); | |
| 654 } | |
| 655 mainApp = libraryLoader.loadLibrary(uri, null, uri); | |
| 656 } | |
| 657 libraries.forEach((_, library) { | 640 libraries.forEach((_, library) { |
| 658 maybeEnableJSHelper(library); | 641 maybeEnableJSHelper(library); |
| 659 maybeEnableIsolateHelper(library); | 642 maybeEnableIsolateHelper(library); |
| 660 }); | 643 }); |
| 661 Element main = null; | 644 final Element main = mainApp.find(MAIN); |
| 662 if (mainApp != null) { | 645 if (main == null) { |
| 663 main = mainApp.find(MAIN); | 646 reportFatalError('Could not find $MAIN', mainApp); |
| 664 if (main == null) { | 647 } else { |
| 665 if (!analyzeOnly) { | 648 if (!main.isFunction()) reportFatalError('main is not a function', main); |
| 666 // Allow analyze only of libraries with no main. | 649 FunctionElement mainMethod = main; |
| 667 reportFatalError('Could not find $MAIN', mainApp); | 650 FunctionSignature parameters = mainMethod.computeSignature(this); |
| 668 } else if (!analyzeAll) { | 651 parameters.forEachParameter((Element parameter) { |
| 669 reportFatalError( | 652 reportFatalError('main cannot have parameters', parameter); |
| 670 "Could not find $MAIN. " | 653 }); |
| 671 "No source will be analyzed. " | |
| 672 "Use '--analyze-all' to analyze all code in the library.", | |
| 673 mainApp); | |
| 674 } | |
| 675 } else { | |
| 676 if (!main.isFunction()) { | |
| 677 reportFatalError('main is not a function', main); | |
| 678 } | |
| 679 FunctionElement mainMethod = main; | |
| 680 FunctionSignature parameters = mainMethod.computeSignature(this); | |
| 681 parameters.forEachParameter((Element parameter) { | |
| 682 reportFatalError('main cannot have parameters', parameter); | |
| 683 }); | |
| 684 } | |
| 685 } | 654 } |
| 686 | 655 |
| 687 log('Resolving...'); | 656 log('Resolving...'); |
| 688 phase = PHASE_RESOLVING; | 657 phase = PHASE_RESOLVING; |
| 689 if (analyzeAll) { | 658 if (analyzeAll) libraries.forEach((_, lib) => fullyEnqueueLibrary(lib)); |
| 690 libraries.forEach((_, lib) => fullyEnqueueLibrary(lib)); | |
| 691 } | |
| 692 backend.enqueueHelpers(enqueuer.resolution); | 659 backend.enqueueHelpers(enqueuer.resolution); |
| 693 processQueue(enqueuer.resolution, main); | 660 processQueue(enqueuer.resolution, main); |
| 694 enqueuer.resolution.logSummary(log); | 661 enqueuer.resolution.logSummary(log); |
| 695 | 662 |
| 696 if (compilationFailed) return; | 663 if (compilationFailed) return; |
| 697 if (analyzeOnly) return; | |
| 698 assert(main != null); | |
| 699 | 664 |
| 700 log('Inferring types...'); | 665 log('Inferring types...'); |
| 701 typesTask.onResolutionComplete(main); | 666 typesTask.onResolutionComplete(main); |
| 702 | 667 |
| 703 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution | 668 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution |
| 704 // should know this. | 669 // should know this. |
| 705 world.populate(); | 670 world.populate(); |
| 706 | 671 |
| 707 log('Compiling...'); | 672 log('Compiling...'); |
| 708 phase = PHASE_COMPILING; | 673 phase = PHASE_COMPILING; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 728 | 693 |
| 729 void fullyEnqueueLibrary(LibraryElement library) { | 694 void fullyEnqueueLibrary(LibraryElement library) { |
| 730 library.forEachLocalMember(fullyEnqueueTopLevelElement); | 695 library.forEachLocalMember(fullyEnqueueTopLevelElement); |
| 731 } | 696 } |
| 732 | 697 |
| 733 void fullyEnqueueTopLevelElement(Element element) { | 698 void fullyEnqueueTopLevelElement(Element element) { |
| 734 if (element.isClass()) { | 699 if (element.isClass()) { |
| 735 ClassElement cls = element; | 700 ClassElement cls = element; |
| 736 cls.ensureResolved(this); | 701 cls.ensureResolved(this); |
| 737 cls.forEachLocalMember(enqueuer.resolution.addToWorkList); | 702 cls.forEachLocalMember(enqueuer.resolution.addToWorkList); |
| 738 } else if (element.isTypedef()) { | |
| 739 TypedefElement typdef = element; | |
| 740 typdef.computeType(this); | |
| 741 } else { | 703 } else { |
| 742 enqueuer.resolution.addToWorkList(element); | 704 enqueuer.resolution.addToWorkList(element); |
| 743 } | 705 } |
| 744 } | 706 } |
| 745 | 707 |
| 746 void processQueue(Enqueuer world, Element main) { | 708 void processQueue(Enqueuer world, Element main) { |
| 747 world.nativeEnqueuer.processNativeClasses(libraries.values); | 709 world.nativeEnqueuer.processNativeClasses(libraries.values); |
| 748 if (main != null) { | 710 world.addToWorkList(main); |
| 749 world.addToWorkList(main); | |
| 750 } | |
| 751 progress.reset(); | 711 progress.reset(); |
| 752 world.forEach((WorkItem work) { | 712 world.forEach((WorkItem work) { |
| 753 withCurrentElement(work.element, () => work.run(this, world)); | 713 withCurrentElement(work.element, () => work.run(this, world)); |
| 754 }); | 714 }); |
| 755 world.queueIsClosed = true; | 715 world.queueIsClosed = true; |
| 756 if (compilationFailed) return; | 716 if (compilationFailed) return; |
| 757 assert(world.checkNoEnqueuedInvokedInstanceMethods()); | 717 assert(world.checkNoEnqueuedInvokedInstanceMethods()); |
| 758 if (DUMP_INFERRED_TYPES && phase == PHASE_COMPILING) { | 718 if (DUMP_INFERRED_TYPES && phase == PHASE_COMPILING) { |
| 759 backend.dumpInferredTypes(); | 719 backend.dumpInferredTypes(); |
| 760 } | 720 } |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 1079 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 1120 // information on assertion errors. | 1080 // information on assertion errors. |
| 1121 if (condition is Function){ | 1081 if (condition is Function){ |
| 1122 condition = condition(); | 1082 condition = condition(); |
| 1123 } | 1083 } |
| 1124 if (spannable == null || !condition) { | 1084 if (spannable == null || !condition) { |
| 1125 throw new SpannableAssertionFailure(spannable, message); | 1085 throw new SpannableAssertionFailure(spannable, message); |
| 1126 } | 1086 } |
| 1127 return true; | 1087 return true; |
| 1128 } | 1088 } |
| OLD | NEW |