Chromium Code Reviews| 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 bool isDefaultNoSuchMethodImplementation(Element element) { | 390 bool isDefaultNoSuchMethodImplementation(Element element) { |
| 391 assert(element.name == Compiler.NO_SUCH_METHOD); | 391 assert(element.name == Compiler.NO_SUCH_METHOD); |
| 392 ClassElement classElement = element.enclosingClass; | 392 ClassElement classElement = element.enclosingClass; |
| 393 return classElement == compiler.objectClass; | 393 return classElement == compiler.objectClass; |
| 394 } | 394 } |
| 395 | 395 |
| 396 bool isInterceptorClass(ClassElement element) => false; | 396 bool isInterceptorClass(ClassElement element) => false; |
| 397 | 397 |
| 398 void registerStaticUse(Element element, Enqueuer enqueuer) {} | 398 void registerStaticUse(Element element, Enqueuer enqueuer) {} |
| 399 | 399 |
| 400 Future onLibraryLoaded(LibraryElement library, Uri uri) { | 400 void onLibraryCreated(LibraryElement library) {} |
| 401 | |
| 402 void onLibraryScanned(LibraryElement library) {} | |
| 403 | |
| 404 Future onLibrariesLoaded(Map<Uri, LibraryElement> loadedLibraries) { | |
| 401 return new Future.value(); | 405 return new Future.value(); |
| 402 } | 406 } |
| 403 | 407 |
| 404 /// Called by [MirrorUsageAnalyzerTask] after it has merged all @MirrorsUsed | 408 /// Called by [MirrorUsageAnalyzerTask] after it has merged all @MirrorsUsed |
| 405 /// annotations. The arguments corresponds to the unions of the corresponding | 409 /// annotations. The arguments corresponds to the unions of the corresponding |
| 406 /// fields of the annotations. | 410 /// fields of the annotations. |
| 407 void registerMirrorUsage(Set<String> symbols, | 411 void registerMirrorUsage(Set<String> symbols, |
| 408 Set<Element> targets, | 412 Set<Element> targets, |
| 409 Set<Element> metaTargets) {} | 413 Set<Element> metaTargets) {} |
| 410 | 414 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 | 477 |
| 474 abstract class Compiler implements DiagnosticListener { | 478 abstract class Compiler implements DiagnosticListener { |
| 475 static final Uri DART_CORE = new Uri(scheme: 'dart', path: 'core'); | 479 static final Uri DART_CORE = new Uri(scheme: 'dart', path: 'core'); |
| 476 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); | 480 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); |
| 477 static final Uri DART_INTERCEPTORS = | 481 static final Uri DART_INTERCEPTORS = |
| 478 new Uri(scheme: 'dart', path: '_interceptors'); | 482 new Uri(scheme: 'dart', path: '_interceptors'); |
| 479 static final Uri DART_FOREIGN_HELPER = | 483 static final Uri DART_FOREIGN_HELPER = |
| 480 new Uri(scheme: 'dart', path: '_foreign_helper'); | 484 new Uri(scheme: 'dart', path: '_foreign_helper'); |
| 481 static final Uri DART_ISOLATE_HELPER = | 485 static final Uri DART_ISOLATE_HELPER = |
| 482 new Uri(scheme: 'dart', path: '_isolate_helper'); | 486 new Uri(scheme: 'dart', path: '_isolate_helper'); |
| 487 static final Uri DART_MIRRORS = new Uri(scheme: 'dart', path: 'mirrors'); | |
| 488 static final Uri DART_NATIVE_TYPED_DATA = | |
| 489 new Uri(scheme: 'dart', path: '_native_typed_data'); | |
| 490 static final Uri DART_INTERNAL = new Uri(scheme: 'dart', path: '_internal'); | |
| 491 static final Uri DART_ASYNC = new Uri(scheme: 'dart', path: 'async'); | |
| 492 | |
| 493 // TODO(johnniwinther): Change to map from [Uri] to [LibraryElement]. | |
| 483 final Map<String, LibraryElement> libraries = | 494 final Map<String, LibraryElement> libraries = |
| 484 new Map<String, LibraryElement>(); | 495 new Map<String, LibraryElement>(); |
| 485 final Stopwatch totalCompileTime = new Stopwatch(); | 496 final Stopwatch totalCompileTime = new Stopwatch(); |
| 486 int nextFreeClassId = 0; | 497 int nextFreeClassId = 0; |
| 487 World world; | 498 World world; |
| 488 String assembledCode; | 499 String assembledCode; |
| 489 Types types; | 500 Types types; |
| 490 | 501 |
| 491 /** | 502 /** |
| 492 * Map from token to the first preceeding comment token. | 503 * Map from token to the first preceeding comment token. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 | 604 |
| 594 List<Uri> librariesToAnalyzeWhenRun; | 605 List<Uri> librariesToAnalyzeWhenRun; |
| 595 | 606 |
| 596 Tracer tracer; | 607 Tracer tracer; |
| 597 | 608 |
| 598 CompilerTask measuredTask; | 609 CompilerTask measuredTask; |
| 599 Element _currentElement; | 610 Element _currentElement; |
| 600 LibraryElement coreLibrary; | 611 LibraryElement coreLibrary; |
| 601 LibraryElement isolateLibrary; | 612 LibraryElement isolateLibrary; |
| 602 LibraryElement isolateHelperLibrary; | 613 LibraryElement isolateHelperLibrary; |
| 614 // TODO(johnniwinther): Move JavaScript specific libraries to the JavaScript | |
| 615 // backend. | |
| 603 LibraryElement jsHelperLibrary; | 616 LibraryElement jsHelperLibrary; |
| 604 LibraryElement interceptorsLibrary; | 617 LibraryElement interceptorsLibrary; |
| 605 LibraryElement foreignLibrary; | 618 LibraryElement foreignLibrary; |
| 606 | 619 |
| 607 LibraryElement mainApp; | 620 LibraryElement mainApp; |
| 608 FunctionElement mainFunction; | 621 FunctionElement mainFunction; |
| 609 | 622 |
| 610 /// Initialized when dart:mirrors is loaded. | 623 /// Initialized when dart:mirrors is loaded. |
| 611 LibraryElement mirrorsLibrary; | 624 LibraryElement mirrorsLibrary; |
| 612 | 625 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 | 803 |
| 791 bool hasCrashed = false; | 804 bool hasCrashed = false; |
| 792 | 805 |
| 793 /// Set by the backend if real reflection is detected in use of dart:mirrors. | 806 /// Set by the backend if real reflection is detected in use of dart:mirrors. |
| 794 bool disableTypeInferenceForMirrors = false; | 807 bool disableTypeInferenceForMirrors = false; |
| 795 | 808 |
| 796 Compiler({this.enableTypeAssertions: false, | 809 Compiler({this.enableTypeAssertions: false, |
| 797 this.enableUserAssertions: false, | 810 this.enableUserAssertions: false, |
| 798 this.trustTypeAnnotations: false, | 811 this.trustTypeAnnotations: false, |
| 799 this.enableConcreteTypeInference: false, | 812 this.enableConcreteTypeInference: false, |
| 800 this.disableTypeInferenceFlag: false, | 813 bool disableTypeInferenceFlag: false, |
| 801 this.maxConcreteTypeSize: 5, | 814 this.maxConcreteTypeSize: 5, |
| 802 this.enableMinification: false, | 815 this.enableMinification: false, |
| 803 this.enableNativeLiveTypeAnalysis: false, | 816 this.enableNativeLiveTypeAnalysis: false, |
| 804 bool emitJavaScript: true, | 817 bool emitJavaScript: true, |
| 805 bool generateSourceMap: true, | 818 bool generateSourceMap: true, |
| 806 bool analyzeAllFlag: false, | 819 bool analyzeAllFlag: false, |
| 807 bool analyzeOnly: false, | 820 bool analyzeOnly: false, |
| 808 this.analyzeMain: false, | 821 this.analyzeMain: false, |
| 809 bool analyzeSignaturesOnly: false, | 822 bool analyzeSignaturesOnly: false, |
| 810 this.preserveComments: false, | 823 this.preserveComments: false, |
| 811 this.verbose: false, | 824 this.verbose: false, |
| 812 this.sourceMapUri: null, | 825 this.sourceMapUri: null, |
| 813 this.outputUri: null, | 826 this.outputUri: null, |
| 814 this.buildId: UNDETERMINED_BUILD_ID, | 827 this.buildId: UNDETERMINED_BUILD_ID, |
| 815 this.terseDiagnostics: false, | 828 this.terseDiagnostics: false, |
| 816 this.disableDeferredLoading: false, | 829 this.disableDeferredLoading: false, |
| 817 this.dumpInfo: false, | 830 this.dumpInfo: false, |
| 818 this.showPackageWarnings: false, | 831 this.showPackageWarnings: false, |
| 819 this.useContentSecurityPolicy: false, | 832 this.useContentSecurityPolicy: false, |
| 820 this.suppressWarnings: false, | 833 this.suppressWarnings: false, |
| 821 outputProvider, | 834 outputProvider, |
| 822 List<String> strips: const []}) | 835 List<String> strips: const []}) |
| 823 : this.analyzeOnly = | 836 : this.disableTypeInferenceFlag = |
| 837 disableTypeInferenceFlag || !emitJavaScript, | |
| 838 this.analyzeOnly = | |
| 824 analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag, | 839 analyzeOnly || analyzeSignaturesOnly || analyzeAllFlag, |
| 825 this.analyzeSignaturesOnly = analyzeSignaturesOnly, | 840 this.analyzeSignaturesOnly = analyzeSignaturesOnly, |
| 826 this.analyzeAllFlag = analyzeAllFlag, | 841 this.analyzeAllFlag = analyzeAllFlag, |
| 827 this.outputProvider = (outputProvider == null) | 842 this.outputProvider = (outputProvider == null) |
| 828 ? NullSink.outputProvider | 843 ? NullSink.outputProvider |
| 829 : outputProvider { | 844 : outputProvider { |
| 830 world = new World(this); | 845 world = new World(this); |
| 846 types = new Types(this); | |
| 831 tracer = new Tracer(this.outputProvider); | 847 tracer = new Tracer(this.outputProvider); |
| 832 | 848 |
| 833 closureMapping.ClosureNamer closureNamer; | 849 closureMapping.ClosureNamer closureNamer; |
| 834 if (emitJavaScript) { | 850 if (emitJavaScript) { |
| 835 js_backend.JavaScriptBackend jsBackend = | 851 js_backend.JavaScriptBackend jsBackend = |
| 836 new js_backend.JavaScriptBackend(this, generateSourceMap); | 852 new js_backend.JavaScriptBackend(this, generateSourceMap); |
| 837 closureNamer = jsBackend.namer; | 853 closureNamer = jsBackend.namer; |
| 838 backend = jsBackend; | 854 backend = jsBackend; |
| 839 } else { | 855 } else { |
| 840 closureNamer = new closureMapping.ClosureNamer(); | 856 closureNamer = new closureMapping.ClosureNamer(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 }).whenComplete(() { | 995 }).whenComplete(() { |
| 980 tracer.close(); | 996 tracer.close(); |
| 981 totalCompileTime.stop(); | 997 totalCompileTime.stop(); |
| 982 }).then((_) { | 998 }).then((_) { |
| 983 return !compilationFailed; | 999 return !compilationFailed; |
| 984 }); | 1000 }); |
| 985 } | 1001 } |
| 986 | 1002 |
| 987 bool hasIsolateSupport() => isolateLibrary != null; | 1003 bool hasIsolateSupport() => isolateLibrary != null; |
| 988 | 1004 |
| 989 /** | 1005 /// This method is called immediately after the [LibraryElement] [library] has |
|
karlklose
2014/06/17 12:30:25
Move first part of the comments to the abstract cl
Johnni Winther
2014/06/17 12:52:28
Done.
| |
| 990 * This method is called before [library] import and export scopes have been | 1006 /// been created. |
| 991 * set up. | 1007 /// |
| 992 */ | 1008 /// Use this callback method to store references to specific libraries. |
| 993 Future onLibraryLoaded(LibraryElement library, Uri uri) { | 1009 /// Note that [library] has not been scanned yet, nor has its imports/exports |
| 994 if (uri == new Uri(scheme: 'dart', path: 'mirrors')) { | 1010 /// been resolved. |
| 1011 void onLibraryCreated(LibraryElement library) { | |
| 1012 Uri uri = library.canonicalUri; | |
| 1013 if (uri == DART_CORE) { | |
| 1014 coreLibrary = library; | |
| 1015 } else if (uri == DART_JS_HELPER) { | |
| 1016 jsHelperLibrary = library; | |
| 1017 } else if (uri == DART_INTERCEPTORS) { | |
| 1018 interceptorsLibrary = library; | |
| 1019 } else if (uri == DART_FOREIGN_HELPER) { | |
| 1020 foreignLibrary = library; | |
| 1021 } else if (uri == DART_ISOLATE_HELPER) { | |
| 1022 isolateHelperLibrary = library; | |
| 1023 } else if (uri == DART_NATIVE_TYPED_DATA) { | |
| 1024 typedDataLibrary = library; | |
| 1025 } else if (uri == DART_MIRRORS) { | |
| 995 mirrorsLibrary = library; | 1026 mirrorsLibrary = library; |
| 996 mirrorSystemClass = | |
| 997 findRequiredElement(library, 'MirrorSystem'); | |
| 998 mirrorsUsedClass = | |
| 999 findRequiredElement(library, 'MirrorsUsed'); | |
| 1000 } else if (uri == new Uri(scheme: 'dart', path: '_native_typed_data')) { | |
| 1001 typedDataLibrary = library; | |
| 1002 typedDataClass = | |
| 1003 findRequiredElement(library, 'NativeTypedData'); | |
| 1004 } else if (uri == new Uri(scheme: 'dart', path: '_internal')) { | |
| 1005 symbolImplementationClass = | |
| 1006 findRequiredElement(library, 'Symbol'); | |
| 1007 } else if (uri == new Uri(scheme: 'dart', path: 'async')) { | |
| 1008 deferredLibraryClass = | |
| 1009 findRequiredElement(library, 'DeferredLibrary'); | |
| 1010 } else if (isolateHelperLibrary == null | |
| 1011 && (uri == new Uri(scheme: 'dart', path: '_isolate_helper'))) { | |
| 1012 isolateHelperLibrary = library; | |
| 1013 } else if (foreignLibrary == null | |
| 1014 && (uri == new Uri(scheme: 'dart', path: '_foreign_helper'))) { | |
| 1015 foreignLibrary = library; | |
| 1016 } | 1027 } |
| 1017 return backend.onLibraryLoaded(library, uri); | 1028 backend.onLibraryCreated(library); |
| 1029 } | |
| 1030 | |
| 1031 /// This method is called immediately after the [library] and its parts have | |
| 1032 /// been scanned. | |
| 1033 /// | |
| 1034 /// Use this callback method to store references to specific member declared | |
| 1035 /// in certain libraries. Note that [library] has not been patched yet, nor | |
| 1036 /// has its imports/exports been resolved. | |
| 1037 void onLibraryScanned(LibraryElement library) { | |
| 1038 Uri uri = library.canonicalUri; | |
| 1039 if (uri == DART_CORE) { | |
| 1040 initializeCoreClasses(); | |
| 1041 identicalFunction = coreLibrary.find('identical'); | |
| 1042 } else if (uri == DART_JS_HELPER) { | |
| 1043 initializeHelperClasses(); | |
| 1044 assertMethod = jsHelperLibrary.find('assertHelper'); | |
| 1045 } else if (uri == DART_INTERNAL) { | |
| 1046 symbolImplementationClass = findRequiredElement(library, 'Symbol'); | |
| 1047 } else if (uri == DART_MIRRORS) { | |
| 1048 mirrorSystemClass = findRequiredElement(library, 'MirrorSystem'); | |
| 1049 mirrorsUsedClass = findRequiredElement(library, 'MirrorsUsed'); | |
| 1050 } else if (uri == DART_ASYNC) { | |
| 1051 deferredLibraryClass = findRequiredElement(library, 'DeferredLibrary'); | |
| 1052 } else if (uri == DART_NATIVE_TYPED_DATA) { | |
| 1053 typedDataClass = findRequiredElement(library, 'NativeTypedData'); | |
| 1054 } | |
| 1055 backend.onLibraryScanned(library); | |
| 1056 } | |
| 1057 | |
| 1058 /// This method is called when all new libraries loaded through | |
| 1059 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | |
| 1060 /// have been computed. | |
| 1061 /// | |
| 1062 /// [loadedLibraries] contains the newly loaded libraries. | |
| 1063 /// | |
| 1064 /// The method returns a [Future] allowing for the loading of additional | |
| 1065 /// libraries. | |
| 1066 Future onLibrariesLoaded(Map<Uri, LibraryElement> loadedLibraries) { | |
| 1067 return new Future.sync(() { | |
| 1068 if (!loadedLibraries.containsKey(DART_CORE)) return new Future.value(); | |
| 1069 | |
| 1070 functionClass.ensureResolved(this); | |
| 1071 functionApplyMethod = functionClass.lookupLocalMember('apply'); | |
| 1072 | |
| 1073 proxyConstant = | |
| 1074 resolver.constantCompiler.compileConstant(coreLibrary.find('proxy')); | |
| 1075 | |
| 1076 if (jsInvocationMirrorClass != null) { | |
| 1077 jsInvocationMirrorClass.ensureResolved(this); | |
| 1078 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); | |
| 1079 } | |
| 1080 | |
| 1081 if (preserveComments) { | |
| 1082 return libraryLoader.loadLibrary(DART_MIRRORS) | |
| 1083 .then((LibraryElement libraryElement) { | |
| 1084 documentClass = libraryElement.find('Comment'); | |
| 1085 }); | |
| 1086 } | |
| 1087 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); | |
| 1018 } | 1088 } |
| 1019 | 1089 |
| 1020 Element findRequiredElement(LibraryElement library, String name) { | 1090 Element findRequiredElement(LibraryElement library, String name) { |
| 1021 var element = library.find(name); | 1091 var element = library.find(name); |
| 1022 if (element == null) { | 1092 if (element == null) { |
| 1023 internalError(library, | 1093 internalError(library, |
| 1024 "The library '${library.canonicalUri}' does not contain required " | 1094 "The library '${library.canonicalUri}' does not contain required " |
| 1025 "element: '$name'."); | 1095 "element: '$name'."); |
| 1026 } | 1096 } |
| 1027 return element; | 1097 return element; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1041 } else if (intClass == cls) { | 1111 } else if (intClass == cls) { |
| 1042 intEnvironment = intClass.lookupConstructor(fromEnvironmentSelector); | 1112 intEnvironment = intClass.lookupConstructor(fromEnvironmentSelector); |
| 1043 } else if (stringClass == cls) { | 1113 } else if (stringClass == cls) { |
| 1044 stringEnvironment = | 1114 stringEnvironment = |
| 1045 stringClass.lookupConstructor(fromEnvironmentSelector); | 1115 stringClass.lookupConstructor(fromEnvironmentSelector); |
| 1046 } else if (boolClass == cls) { | 1116 } else if (boolClass == cls) { |
| 1047 boolEnvironment = boolClass.lookupConstructor(fromEnvironmentSelector); | 1117 boolEnvironment = boolClass.lookupConstructor(fromEnvironmentSelector); |
| 1048 } | 1118 } |
| 1049 } | 1119 } |
| 1050 | 1120 |
| 1051 Future<LibraryElement> scanBuiltinLibrary(String filename); | 1121 void initializeCoreClasses() { |
| 1052 | |
| 1053 void initializeSpecialClasses() { | |
| 1054 final List missingCoreClasses = []; | 1122 final List missingCoreClasses = []; |
| 1055 ClassElement lookupCoreClass(String name) { | 1123 ClassElement lookupCoreClass(String name) { |
| 1056 ClassElement result = coreLibrary.find(name); | 1124 ClassElement result = coreLibrary.find(name); |
| 1057 if (result == null) { | 1125 if (result == null) { |
| 1058 missingCoreClasses.add(name); | 1126 missingCoreClasses.add(name); |
| 1059 } | 1127 } |
| 1060 return result; | 1128 return result; |
| 1061 } | 1129 } |
| 1062 objectClass = lookupCoreClass('Object'); | 1130 objectClass = lookupCoreClass('Object'); |
| 1063 boolClass = lookupCoreClass('bool'); | 1131 boolClass = lookupCoreClass('bool'); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1074 if (!missingCoreClasses.isEmpty) { | 1142 if (!missingCoreClasses.isEmpty) { |
| 1075 internalError(coreLibrary, | 1143 internalError(coreLibrary, |
| 1076 'dart:core library does not contain required classes: ' | 1144 'dart:core library does not contain required classes: ' |
| 1077 '$missingCoreClasses'); | 1145 '$missingCoreClasses'); |
| 1078 } | 1146 } |
| 1079 | 1147 |
| 1080 // The Symbol class may not exist during unit testing. | 1148 // The Symbol class may not exist during unit testing. |
| 1081 // TODO(ahe): It is possible that we have to require the presence | 1149 // TODO(ahe): It is possible that we have to require the presence |
| 1082 // of Symbol as we change how we implement noSuchMethod. | 1150 // of Symbol as we change how we implement noSuchMethod. |
| 1083 symbolClass = lookupCoreClass('Symbol'); | 1151 symbolClass = lookupCoreClass('Symbol'); |
| 1152 } | |
| 1084 | 1153 |
| 1154 void initializeHelperClasses() { | |
| 1085 final List missingHelperClasses = []; | 1155 final List missingHelperClasses = []; |
| 1086 ClassElement lookupHelperClass(String name) { | 1156 ClassElement lookupHelperClass(String name) { |
| 1087 ClassElement result = jsHelperLibrary.find(name); | 1157 ClassElement result = jsHelperLibrary.find(name); |
| 1088 if (result == null) { | 1158 if (result == null) { |
| 1089 missingHelperClasses.add(name); | 1159 missingHelperClasses.add(name); |
| 1090 } | 1160 } |
| 1091 return result; | 1161 return result; |
| 1092 } | 1162 } |
| 1093 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); | 1163 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); |
| 1094 boundClosureClass = lookupHelperClass('BoundClosure'); | 1164 boundClosureClass = lookupHelperClass('BoundClosure'); |
| 1095 closureClass = lookupHelperClass('Closure'); | 1165 closureClass = lookupHelperClass('Closure'); |
| 1096 if (!missingHelperClasses.isEmpty) { | 1166 if (!missingHelperClasses.isEmpty) { |
| 1097 internalError(jsHelperLibrary, | 1167 internalError(jsHelperLibrary, |
| 1098 'dart:_js_helper library does not contain required classes: ' | 1168 'dart:_js_helper library does not contain required classes: ' |
| 1099 '$missingHelperClasses'); | 1169 '$missingHelperClasses'); |
| 1100 } | 1170 } |
| 1101 | |
| 1102 if (types == null) { | |
| 1103 types = new Types(this); | |
| 1104 } | |
| 1105 backend.initializeHelperClasses(); | |
| 1106 | |
| 1107 proxyConstant = | |
| 1108 resolver.constantCompiler.compileConstant(coreLibrary.find('proxy')); | |
| 1109 } | 1171 } |
| 1110 | 1172 |
| 1111 Element _unnamedListConstructor; | 1173 Element _unnamedListConstructor; |
| 1112 Element get unnamedListConstructor { | 1174 Element get unnamedListConstructor { |
| 1113 if (_unnamedListConstructor != null) return _unnamedListConstructor; | 1175 if (_unnamedListConstructor != null) return _unnamedListConstructor; |
| 1114 Selector callConstructor = new Selector.callConstructor( | 1176 Selector callConstructor = new Selector.callConstructor( |
| 1115 "", listClass.library); | 1177 "", listClass.library); |
| 1116 return _unnamedListConstructor = | 1178 return _unnamedListConstructor = |
| 1117 listClass.lookupConstructor(callConstructor); | 1179 listClass.lookupConstructor(callConstructor); |
| 1118 } | 1180 } |
| 1119 | 1181 |
| 1120 Element _filledListConstructor; | 1182 Element _filledListConstructor; |
| 1121 Element get filledListConstructor { | 1183 Element get filledListConstructor { |
| 1122 if (_filledListConstructor != null) return _filledListConstructor; | 1184 if (_filledListConstructor != null) return _filledListConstructor; |
| 1123 Selector callConstructor = new Selector.callConstructor( | 1185 Selector callConstructor = new Selector.callConstructor( |
| 1124 "filled", listClass.library); | 1186 "filled", listClass.library); |
| 1125 return _filledListConstructor = | 1187 return _filledListConstructor = |
| 1126 listClass.lookupConstructor(callConstructor); | 1188 listClass.lookupConstructor(callConstructor); |
| 1127 } | 1189 } |
| 1128 | 1190 |
| 1129 Future scanBuiltinLibraries() { | |
| 1130 return scanBuiltinLibrary('_js_helper').then((LibraryElement library) { | |
| 1131 jsHelperLibrary = library; | |
| 1132 return scanBuiltinLibrary('_interceptors'); | |
| 1133 }).then((LibraryElement library) { | |
| 1134 interceptorsLibrary = library; | |
| 1135 | |
| 1136 assertMethod = jsHelperLibrary.find('assertHelper'); | |
| 1137 identicalFunction = coreLibrary.find('identical'); | |
| 1138 | |
| 1139 initializeSpecialClasses(); | |
| 1140 | |
| 1141 functionClass.ensureResolved(this); | |
| 1142 functionApplyMethod = | |
| 1143 functionClass.lookupLocalMember('apply'); | |
| 1144 jsInvocationMirrorClass.ensureResolved(this); | |
| 1145 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); | |
| 1146 | |
| 1147 if (preserveComments) { | |
| 1148 var uri = new Uri(scheme: 'dart', path: 'mirrors'); | |
| 1149 return libraryLoader.loadLibrary(uri, null, uri).then( | |
| 1150 (LibraryElement libraryElement) { | |
| 1151 documentClass = libraryElement.find('Comment'); | |
| 1152 }); | |
| 1153 } | |
| 1154 }); | |
| 1155 } | |
| 1156 | |
| 1157 void importHelperLibrary(LibraryElement library) { | |
| 1158 if (jsHelperLibrary != null) { | |
| 1159 libraryLoader.importLibrary(library, jsHelperLibrary, null); | |
| 1160 } | |
| 1161 } | |
| 1162 | |
| 1163 /** | 1191 /** |
| 1164 * Get an [Uri] pointing to a patch for the dart: library with | 1192 * Get an [Uri] pointing to a patch for the dart: library with |
| 1165 * the given path. Returns null if there is no patch. | 1193 * the given path. Returns null if there is no patch. |
| 1166 */ | 1194 */ |
| 1167 Uri resolvePatchUri(String dartLibraryPath); | 1195 Uri resolvePatchUri(String dartLibraryPath); |
| 1168 | 1196 |
| 1169 Future runCompiler(Uri uri) { | 1197 Future runCompiler(Uri uri) { |
| 1170 // TODO(ahe): This prevents memory leaks when invoking the compiler | 1198 // TODO(ahe): This prevents memory leaks when invoking the compiler |
| 1171 // multiple times. Implement a better mechanism where we can store | 1199 // multiple times. Implement a better mechanism where we can store |
| 1172 // such caches in the compiler and get access to them through a | 1200 // such caches in the compiler and get access to them through a |
| 1173 // suitably maintained static reference to the current compiler. | 1201 // suitably maintained static reference to the current compiler. |
| 1174 StringToken.canonicalizedSubstrings.clear(); | 1202 StringToken.canonicalizedSubstrings.clear(); |
| 1175 Selector.canonicalizedValues.clear(); | 1203 Selector.canonicalizedValues.clear(); |
| 1176 TypedSelector.canonicalizedValues.clear(); | 1204 TypedSelector.canonicalizedValues.clear(); |
| 1177 | 1205 |
| 1178 assert(uri != null || analyzeOnly); | 1206 assert(uri != null || analyzeOnly); |
| 1179 return scanBuiltinLibraries().then((_) { | 1207 return new Future.sync(() { |
| 1180 if (librariesToAnalyzeWhenRun != null) { | 1208 if (librariesToAnalyzeWhenRun != null) { |
| 1181 return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) { | 1209 return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) { |
| 1182 log('Analyzing $libraryUri ($buildId)'); | 1210 log('Analyzing $libraryUri ($buildId)'); |
| 1183 return libraryLoader.loadLibrary(libraryUri, null, libraryUri); | 1211 return libraryLoader.loadLibrary(libraryUri); |
| 1184 }); | 1212 }); |
| 1185 } | 1213 } |
| 1186 }).then((_) { | 1214 }).then((_) { |
| 1187 if (uri != null) { | 1215 if (uri != null) { |
| 1188 if (analyzeOnly) { | 1216 if (analyzeOnly) { |
| 1189 log('Analyzing $uri ($buildId)'); | 1217 log('Analyzing $uri ($buildId)'); |
| 1190 } else { | 1218 } else { |
| 1191 log('Compiling $uri ($buildId)'); | 1219 log('Compiling $uri ($buildId)'); |
| 1192 } | 1220 } |
| 1193 return libraryLoader.loadLibrary(uri, null, uri) | 1221 return libraryLoader.loadLibrary(uri).then((LibraryElement library) { |
| 1194 .then((LibraryElement library) { | |
| 1195 mainApp = library; | 1222 mainApp = library; |
| 1196 }); | 1223 }); |
| 1197 } | 1224 } |
| 1198 }).then((_) { | 1225 }).then((_) { |
| 1199 compileLoadedLibraries(); | 1226 if (!compilationFailed) { |
| 1227 // TODO(johnniwinther): Reenable analysis of programs with load failures | |
| 1228 // when these are handled as erroneous libraries/compilation units. | |
| 1229 compileLoadedLibraries(); | |
| 1230 } | |
| 1200 }); | 1231 }); |
| 1201 } | 1232 } |
| 1202 | 1233 |
| 1203 /// Performs the compilation when all libraries have been loaded. | 1234 /// Performs the compilation when all libraries have been loaded. |
| 1204 void compileLoadedLibraries() { | 1235 void compileLoadedLibraries() { |
| 1205 Element main = null; | 1236 Element main = null; |
| 1206 if (mainApp != null) { | 1237 if (mainApp != null) { |
| 1207 main = mainApp.findExported(MAIN); | 1238 main = mainApp.findExported(MAIN); |
| 1208 if (main == null) { | 1239 if (main == null) { |
| 1209 if (!analyzeOnly) { | 1240 if (!analyzeOnly) { |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1952 static NullSink outputProvider(String name, String extension) { | 1983 static NullSink outputProvider(String name, String extension) { |
| 1953 return new NullSink('$name.$extension'); | 1984 return new NullSink('$name.$extension'); |
| 1954 } | 1985 } |
| 1955 } | 1986 } |
| 1956 | 1987 |
| 1957 /// Information about suppressed warnings and hints for a given library. | 1988 /// Information about suppressed warnings and hints for a given library. |
| 1958 class SuppressionInfo { | 1989 class SuppressionInfo { |
| 1959 int warnings = 0; | 1990 int warnings = 0; |
| 1960 int hints = 0; | 1991 int hints = 0; |
| 1961 } | 1992 } |
| OLD | NEW |