| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 bool isAnalyzed() => resolutionTree != null; | 51 bool isAnalyzed() => resolutionTree != null; |
| 52 | 52 |
| 53 void run(Compiler compiler, Enqueuer world) { | 53 void run(Compiler compiler, Enqueuer world) { |
| 54 CodeBuffer codeBuffer = world.universe.generatedCode[element]; | 54 CodeBuffer codeBuffer = world.universe.generatedCode[element]; |
| 55 if (codeBuffer != null) return; | 55 if (codeBuffer != null) return; |
| 56 resolutionTree = compiler.analyze(this, world); | 56 resolutionTree = compiler.analyze(this, world); |
| 57 compiler.codegen(this, world); | 57 compiler.codegen(this, world); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 class ReadingFilesTask extends CompilerTask { |
| 62 ReadingFilesTask(Compiler compiler) : super(compiler); |
| 63 String get name => 'Reading input files'; |
| 64 } |
| 65 |
| 61 abstract class Backend { | 66 abstract class Backend { |
| 62 final Compiler compiler; | 67 final Compiler compiler; |
| 63 final ConstantSystem constantSystem; | 68 final ConstantSystem constantSystem; |
| 64 | 69 |
| 65 Backend(this.compiler, | 70 Backend(this.compiler, |
| 66 [ConstantSystem constantSystem = DART_CONSTANT_SYSTEM]) | 71 [ConstantSystem constantSystem = DART_CONSTANT_SYSTEM]) |
| 67 : this.constantSystem = constantSystem; | 72 : this.constantSystem = constantSystem; |
| 68 | 73 |
| 69 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { | 74 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { |
| 70 lib.forEachExport((Element e) { | 75 lib.forEachExport((Element e) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 ItemCompilationContext createItemCompilationContext() { | 98 ItemCompilationContext createItemCompilationContext() { |
| 94 return new ItemCompilationContext(); | 99 return new ItemCompilationContext(); |
| 95 } | 100 } |
| 96 | 101 |
| 97 SourceString getCheckedModeHelper(DartType type) => null; | 102 SourceString getCheckedModeHelper(DartType type) => null; |
| 98 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} | 103 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} |
| 99 } | 104 } |
| 100 | 105 |
| 101 abstract class Compiler implements DiagnosticListener { | 106 abstract class Compiler implements DiagnosticListener { |
| 102 final Map<String, LibraryElement> libraries; | 107 final Map<String, LibraryElement> libraries; |
| 108 final Stopwatch totalCompileTime = new Stopwatch(); |
| 103 int nextFreeClassId = 0; | 109 int nextFreeClassId = 0; |
| 104 World world; | 110 World world; |
| 105 String assembledCode; | 111 String assembledCode; |
| 106 Types types; | 112 Types types; |
| 107 | 113 |
| 108 final bool enableMinification; | 114 final bool enableMinification; |
| 109 final bool enableTypeAssertions; | 115 final bool enableTypeAssertions; |
| 110 final bool enableUserAssertions; | 116 final bool enableUserAssertions; |
| 111 final bool enableConcreteTypeInference; | 117 final bool enableConcreteTypeInference; |
| 112 final bool analyzeAll; | 118 final bool analyzeAll; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 PatchParserTask patchParser; | 189 PatchParserTask patchParser; |
| 184 LibraryLoader libraryLoader; | 190 LibraryLoader libraryLoader; |
| 185 TreeValidatorTask validator; | 191 TreeValidatorTask validator; |
| 186 ResolverTask resolver; | 192 ResolverTask resolver; |
| 187 closureMapping.ClosureTask closureToClassMapper; | 193 closureMapping.ClosureTask closureToClassMapper; |
| 188 TypeCheckerTask checker; | 194 TypeCheckerTask checker; |
| 189 ti.TypesTask typesTask; | 195 ti.TypesTask typesTask; |
| 190 Backend backend; | 196 Backend backend; |
| 191 ConstantHandler constantHandler; | 197 ConstantHandler constantHandler; |
| 192 EnqueueTask enqueuer; | 198 EnqueueTask enqueuer; |
| 199 CompilerTask fileReadingTask; |
| 193 | 200 |
| 194 static const SourceString MAIN = const SourceString('main'); | 201 static const SourceString MAIN = const SourceString('main'); |
| 195 static const SourceString CALL_OPERATOR_NAME = const SourceString('call'); | 202 static const SourceString CALL_OPERATOR_NAME = const SourceString('call'); |
| 196 static const SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); | 203 static const SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); |
| 197 static const int NO_SUCH_METHOD_ARG_COUNT = 1; | 204 static const int NO_SUCH_METHOD_ARG_COUNT = 1; |
| 198 static const SourceString INVOKE_ON = const SourceString('invokeOn'); | 205 static const SourceString INVOKE_ON = const SourceString('invokeOn'); |
| 199 static const SourceString RUNTIME_TYPE = const SourceString('runtimeType'); | 206 static const SourceString RUNTIME_TYPE = const SourceString('runtimeType'); |
| 200 static const SourceString START_ROOT_ISOLATE = | 207 static const SourceString START_ROOT_ISOLATE = |
| 201 const SourceString('startRootIsolate'); | 208 const SourceString('startRootIsolate'); |
| 202 bool enabledNoSuchMethod = false; | 209 bool enabledNoSuchMethod = false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 225 bool generateSourceMap: true, | 232 bool generateSourceMap: true, |
| 226 bool disallowUnsafeEval: false, | 233 bool disallowUnsafeEval: false, |
| 227 this.analyzeAll: false, | 234 this.analyzeAll: false, |
| 228 this.rejectDeprecatedFeatures: false, | 235 this.rejectDeprecatedFeatures: false, |
| 229 this.checkDeprecationInSdk: false, | 236 this.checkDeprecationInSdk: false, |
| 230 List<String> strips: const []}) | 237 List<String> strips: const []}) |
| 231 : libraries = new Map<String, LibraryElement>(), | 238 : libraries = new Map<String, LibraryElement>(), |
| 232 progress = new Stopwatch() { | 239 progress = new Stopwatch() { |
| 233 progress.start(); | 240 progress.start(); |
| 234 world = new World(this); | 241 world = new World(this); |
| 235 scanner = new ScannerTask(this); | |
| 236 dietParser = new DietParserTask(this); | |
| 237 parser = new ParserTask(this); | |
| 238 patchParser = new PatchParserTask(this); | |
| 239 libraryLoader = new LibraryLoaderTask(this); | |
| 240 validator = new TreeValidatorTask(this); | |
| 241 resolver = new ResolverTask(this); | |
| 242 closureToClassMapper = new closureMapping.ClosureTask(this); | |
| 243 checker = new TypeCheckerTask(this); | |
| 244 typesTask = new ti.TypesTask(this, enableConcreteTypeInference); | |
| 245 backend = emitJavaScript ? | 242 backend = emitJavaScript ? |
| 246 new js_backend.JavaScriptBackend(this, | 243 new js_backend.JavaScriptBackend(this, |
| 247 generateSourceMap, | 244 generateSourceMap, |
| 248 disallowUnsafeEval) : | 245 disallowUnsafeEval) : |
| 249 new dart_backend.DartBackend(this, strips); | 246 new dart_backend.DartBackend(this, strips); |
| 250 constantHandler = new ConstantHandler(this, backend.constantSystem); | 247 |
| 251 enqueuer = new EnqueueTask(this); | 248 // No-op in production mode. |
| 252 tasks = [scanner, dietParser, parser, patchParser, libraryLoader, | 249 validator = new TreeValidatorTask(this); |
| 253 resolver, closureToClassMapper, checker, typesTask, | 250 |
| 254 constantHandler, enqueuer]; | 251 tasks = [ |
| 252 fileReadingTask = new ReadingFilesTask(this), |
| 253 libraryLoader = new LibraryLoaderTask(this), |
| 254 scanner = new ScannerTask(this), |
| 255 dietParser = new DietParserTask(this), |
| 256 parser = new ParserTask(this), |
| 257 patchParser = new PatchParserTask(this), |
| 258 resolver = new ResolverTask(this), |
| 259 closureToClassMapper = new closureMapping.ClosureTask(this), |
| 260 checker = new TypeCheckerTask(this), |
| 261 typesTask = new ti.TypesTask(this, enableConcreteTypeInference), |
| 262 constantHandler = new ConstantHandler(this, backend.constantSystem), |
| 263 enqueuer = new EnqueueTask(this)]; |
| 264 |
| 255 tasks.addAll(backend.tasks); | 265 tasks.addAll(backend.tasks); |
| 256 } | 266 } |
| 257 | 267 |
| 258 Universe get resolverWorld => enqueuer.resolution.universe; | 268 Universe get resolverWorld => enqueuer.resolution.universe; |
| 259 Universe get codegenWorld => enqueuer.codegen.universe; | 269 Universe get codegenWorld => enqueuer.codegen.universe; |
| 260 | 270 |
| 261 int getNextFreeClassId() => nextFreeClassId++; | 271 int getNextFreeClassId() => nextFreeClassId++; |
| 262 | 272 |
| 263 void ensure(bool condition) { | 273 void ensure(bool condition) { |
| 264 if (!condition) cancel('failed assertion in leg'); | 274 if (!condition) cancel('failed assertion in leg'); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 cancel(reason, node: node, token: token, instruction: instruction, | 343 cancel(reason, node: node, token: token, instruction: instruction, |
| 334 element: element); | 344 element: element); |
| 335 }); | 345 }); |
| 336 } | 346 } |
| 337 | 347 |
| 338 void log(message) { | 348 void log(message) { |
| 339 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); | 349 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); |
| 340 } | 350 } |
| 341 | 351 |
| 342 bool run(Uri uri) { | 352 bool run(Uri uri) { |
| 353 totalCompileTime.start(); |
| 343 try { | 354 try { |
| 344 runCompiler(uri); | 355 runCompiler(uri); |
| 345 } on CompilerCancelledException catch (exception) { | 356 } on CompilerCancelledException catch (exception) { |
| 346 log('Error: $exception'); | 357 log('Error: $exception'); |
| 347 return false; | 358 return false; |
| 359 } finally { |
| 360 tracer.close(); |
| 361 totalCompileTime.stop(); |
| 348 } | 362 } |
| 349 tracer.close(); | |
| 350 return true; | 363 return true; |
| 351 } | 364 } |
| 352 | 365 |
| 353 void enableNoSuchMethod(Element element) { | 366 void enableNoSuchMethod(Element element) { |
| 354 // TODO(ahe): Move this method to Enqueuer. | 367 // TODO(ahe): Move this method to Enqueuer. |
| 355 if (enabledNoSuchMethod) return; | 368 if (enabledNoSuchMethod) return; |
| 356 if (identical(element.getEnclosingClass(), objectClass)) { | 369 if (identical(element.getEnclosingClass(), objectClass)) { |
| 357 enqueuer.resolution.registerDynamicInvocationOf(element); | 370 enqueuer.resolution.registerDynamicInvocationOf(element); |
| 358 return; | 371 return; |
| 359 } | 372 } |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 class CompilerTask { | 869 class CompilerTask { |
| 857 final Compiler compiler; | 870 final Compiler compiler; |
| 858 final Stopwatch watch; | 871 final Stopwatch watch; |
| 859 | 872 |
| 860 CompilerTask(this.compiler) : watch = new Stopwatch(); | 873 CompilerTask(this.compiler) : watch = new Stopwatch(); |
| 861 | 874 |
| 862 String get name => 'Unknown task'; | 875 String get name => 'Unknown task'; |
| 863 int get timing => watch.elapsedMilliseconds; | 876 int get timing => watch.elapsedMilliseconds; |
| 864 | 877 |
| 865 measure(Function action) { | 878 measure(Function action) { |
| 866 // TODO(kasperl): Do we have to worry about exceptions here? | |
| 867 CompilerTask previous = compiler.measuredTask; | 879 CompilerTask previous = compiler.measuredTask; |
| 880 if (identical(this, previous)) return action(); |
| 868 compiler.measuredTask = this; | 881 compiler.measuredTask = this; |
| 869 if (previous != null) previous.watch.stop(); | 882 if (previous != null) previous.watch.stop(); |
| 870 watch.start(); | 883 watch.start(); |
| 871 var result = action(); | 884 try { |
| 872 watch.stop(); | 885 return action(); |
| 873 if (previous != null) previous.watch.start(); | 886 } finally { |
| 874 compiler.measuredTask = previous; | 887 watch.stop(); |
| 875 return result; | 888 if (previous != null) previous.watch.start(); |
| 889 compiler.measuredTask = previous; |
| 890 } |
| 876 } | 891 } |
| 877 } | 892 } |
| 878 | 893 |
| 879 class CompilerCancelledException implements Exception { | 894 class CompilerCancelledException implements Exception { |
| 880 final String reason; | 895 final String reason; |
| 881 CompilerCancelledException(this.reason); | 896 CompilerCancelledException(this.reason); |
| 882 | 897 |
| 883 String toString() { | 898 String toString() { |
| 884 String banner = 'compiler cancelled'; | 899 String banner = 'compiler cancelled'; |
| 885 return (reason != null) ? '$banner: $reason' : '$banner'; | 900 return (reason != null) ? '$banner: $reason' : '$banner'; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 953 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 939 // information on assertion errors. | 954 // information on assertion errors. |
| 940 if (condition is Function){ | 955 if (condition is Function){ |
| 941 condition = condition(); | 956 condition = condition(); |
| 942 } | 957 } |
| 943 if (spannable == null || !condition) { | 958 if (spannable == null || !condition) { |
| 944 throw new SpannableAssertionFailure(spannable, message); | 959 throw new SpannableAssertionFailure(spannable, message); |
| 945 } | 960 } |
| 946 return true; | 961 return true; |
| 947 } | 962 } |
| OLD | NEW |