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 | 5 |
| 6 /** | 6 /** |
| 7 * If true, print a warning for each method that was resolved, but not | 7 * If true, print a warning for each method that was resolved, but not |
| 8 * compiled. | 8 * compiled. |
| 9 */ | 9 */ |
| 10 const bool REPORT_EXCESS_RESOLUTION = false; | 10 const bool REPORT_EXCESS_RESOLUTION = false; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 } finally { | 154 } finally { |
| 155 _currentElement = old; | 155 _currentElement = old; |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 List<CompilerTask> tasks; | 159 List<CompilerTask> tasks; |
| 160 ScannerTask scanner; | 160 ScannerTask scanner; |
| 161 DietParserTask dietParser; | 161 DietParserTask dietParser; |
| 162 ParserTask parser; | 162 ParserTask parser; |
| 163 PatchParserTask patchParser; | 163 PatchParserTask patchParser; |
| 164 LibraryLoader libraryLoader; | |
| 164 TreeValidatorTask validator; | 165 TreeValidatorTask validator; |
| 165 ResolverTask resolver; | 166 ResolverTask resolver; |
| 166 closureMapping.ClosureTask closureToClassMapper; | 167 closureMapping.ClosureTask closureToClassMapper; |
| 167 TypeCheckerTask checker; | 168 TypeCheckerTask checker; |
| 168 ti.TypesTask typesTask; | 169 ti.TypesTask typesTask; |
| 169 Backend backend; | 170 Backend backend; |
| 170 ConstantHandler constantHandler; | 171 ConstantHandler constantHandler; |
| 171 EnqueueTask enqueuer; | 172 EnqueueTask enqueuer; |
| 172 | 173 |
| 173 static const SourceString MAIN = const SourceString('main'); | 174 static const SourceString MAIN = const SourceString('main'); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 198 bool generateSourceMap = true, | 199 bool generateSourceMap = true, |
| 199 List<String> strips = const []]) | 200 List<String> strips = const []]) |
| 200 : libraries = new Map<String, LibraryElement>(), | 201 : libraries = new Map<String, LibraryElement>(), |
| 201 progress = new Stopwatch() { | 202 progress = new Stopwatch() { |
| 202 progress.start(); | 203 progress.start(); |
| 203 world = new World(this); | 204 world = new World(this); |
| 204 scanner = new ScannerTask(this); | 205 scanner = new ScannerTask(this); |
| 205 dietParser = new DietParserTask(this); | 206 dietParser = new DietParserTask(this); |
| 206 parser = new ParserTask(this); | 207 parser = new ParserTask(this); |
| 207 patchParser = new PatchParserTask(this); | 208 patchParser = new PatchParserTask(this); |
| 209 libraryLoader = new LibraryLoaderTask(this); | |
| 208 validator = new TreeValidatorTask(this); | 210 validator = new TreeValidatorTask(this); |
| 209 resolver = new ResolverTask(this); | 211 resolver = new ResolverTask(this); |
| 210 closureToClassMapper = new closureMapping.ClosureTask(this); | 212 closureToClassMapper = new closureMapping.ClosureTask(this); |
| 211 checker = new TypeCheckerTask(this); | 213 checker = new TypeCheckerTask(this); |
| 212 typesTask = new ti.TypesTask(this); | 214 typesTask = new ti.TypesTask(this); |
| 213 backend = emitJavaScript ? | 215 backend = emitJavaScript ? |
| 214 new js_backend.JavaScriptBackend(this, generateSourceMap) : | 216 new js_backend.JavaScriptBackend(this, generateSourceMap) : |
| 215 new dart_backend.DartBackend(this, strips); | 217 new dart_backend.DartBackend(this, strips); |
| 216 constantHandler = new ConstantHandler(this, backend.constantSystem); | 218 constantHandler = new ConstantHandler(this, backend.constantSystem); |
| 217 enqueuer = new EnqueueTask(this); | 219 enqueuer = new EnqueueTask(this); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 addForeignFunctions(interceptorsLibrary); | 383 addForeignFunctions(interceptorsLibrary); |
| 382 | 384 |
| 383 assertMethod = jsHelperLibrary.find(const SourceString('assert')); | 385 assertMethod = jsHelperLibrary.find(const SourceString('assert')); |
| 384 identicalFunction = coreLibrary.find(const SourceString('identical')); | 386 identicalFunction = coreLibrary.find(const SourceString('identical')); |
| 385 | 387 |
| 386 initializeSpecialClasses(); | 388 initializeSpecialClasses(); |
| 387 } | 389 } |
| 388 | 390 |
| 389 void loadCoreImplLibrary() { | 391 void loadCoreImplLibrary() { |
| 390 Uri coreImplUri = new Uri.fromComponents(scheme: 'dart', path: 'coreimpl'); | 392 Uri coreImplUri = new Uri.fromComponents(scheme: 'dart', path: 'coreimpl'); |
| 391 coreImplLibrary = scanner.loadLibrary(coreImplUri, null, coreImplUri); | 393 coreImplLibrary = libraryLoader.loadLibrary(coreImplUri, null, coreImplUri); |
| 392 } | 394 } |
| 393 | 395 |
| 394 void importHelperLibrary(LibraryElement library) { | 396 void importHelperLibrary(LibraryElement library) { |
| 395 if (jsHelperLibrary !== null) { | 397 if (jsHelperLibrary !== null) { |
| 396 scanner.importLibrary(library, jsHelperLibrary, null); | 398 LibraryLoader.importLibrary(this, library, jsHelperLibrary, null); |
|
Lasse Reichstein Nielsen
2012/10/10 08:07:33
capital 'L'?
Johnni Winther
2012/10/10 09:20:59
Done.
| |
| 397 } | 399 } |
| 398 } | 400 } |
| 399 | 401 |
| 400 void importCoreLibrary(LibraryElement library) { | |
| 401 if (coreLibrary === null) { | |
| 402 Uri coreUri = new Uri.fromComponents(scheme: 'dart', path: 'core'); | |
| 403 coreLibrary = scanner.loadLibrary(coreUri, null, coreUri); | |
| 404 } | |
| 405 scanner.importLibrary(library, | |
| 406 coreLibrary, | |
| 407 null, | |
| 408 library.entryCompilationUnit); | |
| 409 } | |
| 410 | |
| 411 void patchDartLibrary(LibraryElement library, String dartLibraryPath) { | |
| 412 if (library.isPatched) return; | |
| 413 Uri patchUri = resolvePatchUri(dartLibraryPath); | |
| 414 if (patchUri !== null) { | |
| 415 patchParser.patchLibrary(patchUri, library); | |
| 416 } | |
| 417 } | |
| 418 | |
| 419 /** | 402 /** |
| 420 * Get an [Uri] pointing to a patch for the dart: library with | 403 * Get an [Uri] pointing to a patch for the dart: library with |
| 421 * the given path. Returns null if there is no patch. | 404 * the given path. Returns null if there is no patch. |
| 422 */ | 405 */ |
| 423 abstract Uri resolvePatchUri(String dartLibraryPath); | 406 abstract Uri resolvePatchUri(String dartLibraryPath); |
| 424 | 407 |
| 425 /** Define the JS helper functions in the given library. */ | 408 /** Define the JS helper functions in the given library. */ |
| 426 void addForeignFunctions(LibraryElement library) { | 409 void addForeignFunctions(LibraryElement library) { |
| 427 library.addToScope(new ForeignElement( | 410 library.addToScope(new ForeignElement( |
| 428 const SourceString('JS'), library), this); | 411 const SourceString('JS'), library), this); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 452 findHelper(const SourceString('JavaScriptIndexingBehavior')); | 435 findHelper(const SourceString('JavaScriptIndexingBehavior')); |
| 453 if (jsIndexingBehaviorInterface !== null) { | 436 if (jsIndexingBehaviorInterface !== null) { |
| 454 library.addToScope(jsIndexingBehaviorInterface, this); | 437 library.addToScope(jsIndexingBehaviorInterface, this); |
| 455 } | 438 } |
| 456 } | 439 } |
| 457 } | 440 } |
| 458 | 441 |
| 459 void runCompiler(Uri uri) { | 442 void runCompiler(Uri uri) { |
| 460 log('compiling $uri ($BUILD_ID)'); | 443 log('compiling $uri ($BUILD_ID)'); |
| 461 scanBuiltinLibraries(); | 444 scanBuiltinLibraries(); |
| 462 mainApp = scanner.loadLibrary(uri, null, uri); | 445 mainApp = libraryLoader.loadLibrary(uri, null, uri); |
| 463 libraries.forEach((_, library) { | 446 libraries.forEach((_, library) { |
| 464 maybeEnableJSHelper(library); | 447 maybeEnableJSHelper(library); |
| 465 }); | 448 }); |
| 466 final Element main = mainApp.find(MAIN); | 449 final Element main = mainApp.find(MAIN); |
| 467 if (main === null) { | 450 if (main === null) { |
| 468 reportFatalError('Could not find $MAIN', mainApp); | 451 reportFatalError('Could not find $MAIN', mainApp); |
| 469 } else { | 452 } else { |
| 470 if (!main.isFunction()) reportFatalError('main is not a function', main); | 453 if (!main.isFunction()) reportFatalError('main is not a function', main); |
| 471 FunctionElement mainMethod = main; | 454 FunctionElement mainMethod = main; |
| 472 FunctionSignature parameters = mainMethod.computeSignature(this); | 455 FunctionSignature parameters = mainMethod.computeSignature(this); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 * be either a [:bool:] or a no-arg function returning a [:bool:]. | 825 * be either a [:bool:] or a no-arg function returning a [:bool:]. |
| 843 * | 826 * |
| 844 * Use this method to provide better information for assertion by calling | 827 * Use this method to provide better information for assertion by calling |
| 845 * [invariant] as the argument to an [:assert:] statement: | 828 * [invariant] as the argument to an [:assert:] statement: |
| 846 * | 829 * |
| 847 * assert(invariant(position, isValid)); | 830 * assert(invariant(position, isValid)); |
| 848 * | 831 * |
| 849 * [spannable] must be non-null and will be used to provide positional | 832 * [spannable] must be non-null and will be used to provide positional |
| 850 * information in the generated error message. | 833 * information in the generated error message. |
| 851 */ | 834 */ |
| 852 bool invariant(Spannable spannable, var condition, {String message: null}) { | 835 bool invariant(Spannable spannable, var condition, {String message: null}) { |
|
Lasse Reichstein Nielsen
2012/10/10 08:07:33
"Spannable" is a bad name. It's something that is
Johnni Winther
2012/10/10 09:20:59
Added a TODO.
| |
| 853 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 836 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 854 // information on assertion errors. | 837 // information on assertion errors. |
| 855 if (condition is Function){ | 838 if (condition is Function){ |
| 856 condition = condition(); | 839 condition = condition(); |
| 857 } | 840 } |
| 841 if (!condition) { | |
| 842 print('assertion failed: $message'); | |
| 843 } | |
| 858 return spannable != null && condition; | 844 return spannable != null && condition; |
| 859 } | 845 } |
| OLD | NEW |