| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } finally { | 155 } finally { |
| 156 _currentElement = old; | 156 _currentElement = old; |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 List<CompilerTask> tasks; | 160 List<CompilerTask> tasks; |
| 161 ScannerTask scanner; | 161 ScannerTask scanner; |
| 162 DietParserTask dietParser; | 162 DietParserTask dietParser; |
| 163 ParserTask parser; | 163 ParserTask parser; |
| 164 PatchParserTask patchParser; | 164 PatchParserTask patchParser; |
| 165 LibraryLoader libraryLoader; |
| 165 TreeValidatorTask validator; | 166 TreeValidatorTask validator; |
| 166 ResolverTask resolver; | 167 ResolverTask resolver; |
| 167 closureMapping.ClosureTask closureToClassMapper; | 168 closureMapping.ClosureTask closureToClassMapper; |
| 168 TypeCheckerTask checker; | 169 TypeCheckerTask checker; |
| 169 ti.TypesTask typesTask; | 170 ti.TypesTask typesTask; |
| 170 Backend backend; | 171 Backend backend; |
| 171 ConstantHandler constantHandler; | 172 ConstantHandler constantHandler; |
| 172 EnqueueTask enqueuer; | 173 EnqueueTask enqueuer; |
| 173 | 174 |
| 174 static const SourceString MAIN = const SourceString('main'); | 175 static const SourceString MAIN = const SourceString('main'); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 200 bool generateSourceMap = true, | 201 bool generateSourceMap = true, |
| 201 List<String> strips = const []]) | 202 List<String> strips = const []]) |
| 202 : libraries = new Map<String, LibraryElement>(), | 203 : libraries = new Map<String, LibraryElement>(), |
| 203 progress = new Stopwatch() { | 204 progress = new Stopwatch() { |
| 204 progress.start(); | 205 progress.start(); |
| 205 world = new World(this); | 206 world = new World(this); |
| 206 scanner = new ScannerTask(this); | 207 scanner = new ScannerTask(this); |
| 207 dietParser = new DietParserTask(this); | 208 dietParser = new DietParserTask(this); |
| 208 parser = new ParserTask(this); | 209 parser = new ParserTask(this); |
| 209 patchParser = new PatchParserTask(this); | 210 patchParser = new PatchParserTask(this); |
| 211 libraryLoader = new LibraryLoaderTask(this); |
| 210 validator = new TreeValidatorTask(this); | 212 validator = new TreeValidatorTask(this); |
| 211 resolver = new ResolverTask(this); | 213 resolver = new ResolverTask(this); |
| 212 closureToClassMapper = new closureMapping.ClosureTask(this); | 214 closureToClassMapper = new closureMapping.ClosureTask(this); |
| 213 checker = new TypeCheckerTask(this); | 215 checker = new TypeCheckerTask(this); |
| 214 typesTask = new ti.TypesTask(this); | 216 typesTask = new ti.TypesTask(this); |
| 215 backend = emitJavaScript ? | 217 backend = emitJavaScript ? |
| 216 new js_backend.JavaScriptBackend(this, generateSourceMap) : | 218 new js_backend.JavaScriptBackend(this, generateSourceMap) : |
| 217 new dart_backend.DartBackend(this, strips); | 219 new dart_backend.DartBackend(this, strips); |
| 218 constantHandler = new ConstantHandler(this, backend.constantSystem); | 220 constantHandler = new ConstantHandler(this, backend.constantSystem); |
| 219 enqueuer = new EnqueueTask(this); | 221 enqueuer = new EnqueueTask(this); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 enqueuer.resolution.addToWorkList(isolateLibrary.find(START_ROOT_ISOLATE)); | 322 enqueuer.resolution.addToWorkList(isolateLibrary.find(START_ROOT_ISOLATE)); |
| 321 enqueuer.resolution.addToWorkList( | 323 enqueuer.resolution.addToWorkList( |
| 322 isolateLibrary.find(const SourceString('_currentIsolate'))); | 324 isolateLibrary.find(const SourceString('_currentIsolate'))); |
| 323 enqueuer.resolution.addToWorkList( | 325 enqueuer.resolution.addToWorkList( |
| 324 isolateLibrary.find(const SourceString('_callInIsolate'))); | 326 isolateLibrary.find(const SourceString('_callInIsolate'))); |
| 325 enqueuer.codegen.addToWorkList(isolateLibrary.find(START_ROOT_ISOLATE)); | 327 enqueuer.codegen.addToWorkList(isolateLibrary.find(START_ROOT_ISOLATE)); |
| 326 } | 328 } |
| 327 | 329 |
| 328 bool hasIsolateSupport() => isolateLibrary !== null; | 330 bool hasIsolateSupport() => isolateLibrary !== null; |
| 329 | 331 |
| 330 void onLibraryLoaded(LibraryElement library, Uri uri) { | 332 /** |
| 333 * This method is called before [library] import and export scopes have been |
| 334 * set up. |
| 335 */ |
| 336 void onLibraryScanned(LibraryElement library, Uri uri) { |
| 331 if (dynamicClass !== null) { | 337 if (dynamicClass !== null) { |
| 332 // When loading the built-in libraries, dynamicClass is null. We | 338 // When loading the built-in libraries, dynamicClass is null. We |
| 333 // take advantage of this as core and coreimpl import js_helper | 339 // take advantage of this as core and coreimpl import js_helper |
| 334 // and see Dynamic this way. | 340 // and see Dynamic this way. |
| 335 withCurrentElement(dynamicClass, () { | 341 withCurrentElement(dynamicClass, () { |
| 336 library.addToScope(dynamicClass, this); | 342 library.addToScope(dynamicClass, this); |
| 337 }); | 343 }); |
| 338 } | 344 } |
| 339 } | 345 } |
| 340 | 346 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 393 |
| 388 initializeSpecialClasses(); | 394 initializeSpecialClasses(); |
| 389 | 395 |
| 390 functionClass.ensureResolved(this); | 396 functionClass.ensureResolved(this); |
| 391 functionApplyMethod = | 397 functionApplyMethod = |
| 392 functionClass.lookupLocalMember(const SourceString('apply')); | 398 functionClass.lookupLocalMember(const SourceString('apply')); |
| 393 } | 399 } |
| 394 | 400 |
| 395 void loadCoreImplLibrary() { | 401 void loadCoreImplLibrary() { |
| 396 Uri coreImplUri = new Uri.fromComponents(scheme: 'dart', path: 'coreimpl'); | 402 Uri coreImplUri = new Uri.fromComponents(scheme: 'dart', path: 'coreimpl'); |
| 397 coreImplLibrary = scanner.loadLibrary(coreImplUri, null, coreImplUri); | 403 coreImplLibrary = libraryLoader.loadLibrary(coreImplUri, null, coreImplUri); |
| 398 } | 404 } |
| 399 | 405 |
| 400 void importHelperLibrary(LibraryElement library) { | 406 void importHelperLibrary(LibraryElement library) { |
| 401 if (jsHelperLibrary !== null) { | 407 if (jsHelperLibrary !== null) { |
| 402 scanner.importLibrary(library, jsHelperLibrary, null); | 408 libraryLoader.importLibrary(library, jsHelperLibrary, null); |
| 403 } | 409 } |
| 404 } | 410 } |
| 405 | 411 |
| 406 void importCoreLibrary(LibraryElement library) { | |
| 407 if (coreLibrary === null) { | |
| 408 Uri coreUri = new Uri.fromComponents(scheme: 'dart', path: 'core'); | |
| 409 coreLibrary = scanner.loadLibrary(coreUri, null, coreUri); | |
| 410 } | |
| 411 scanner.importLibrary(library, | |
| 412 coreLibrary, | |
| 413 null, | |
| 414 library.entryCompilationUnit); | |
| 415 } | |
| 416 | |
| 417 void patchDartLibrary(LibraryElement library, String dartLibraryPath) { | |
| 418 if (library.isPatched) return; | |
| 419 Uri patchUri = resolvePatchUri(dartLibraryPath); | |
| 420 if (patchUri !== null) { | |
| 421 patchParser.patchLibrary(patchUri, library); | |
| 422 } | |
| 423 } | |
| 424 | |
| 425 /** | 412 /** |
| 426 * Get an [Uri] pointing to a patch for the dart: library with | 413 * Get an [Uri] pointing to a patch for the dart: library with |
| 427 * the given path. Returns null if there is no patch. | 414 * the given path. Returns null if there is no patch. |
| 428 */ | 415 */ |
| 429 abstract Uri resolvePatchUri(String dartLibraryPath); | 416 abstract Uri resolvePatchUri(String dartLibraryPath); |
| 430 | 417 |
| 431 /** Define the JS helper functions in the given library. */ | 418 /** Define the JS helper functions in the given library. */ |
| 432 void addForeignFunctions(LibraryElement library) { | 419 void addForeignFunctions(LibraryElement library) { |
| 433 library.addToScope(new ForeignElement( | 420 library.addToScope(new ForeignElement( |
| 434 const SourceString('JS'), library), this); | 421 const SourceString('JS'), library), this); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 458 findHelper(const SourceString('JavaScriptIndexingBehavior')); | 445 findHelper(const SourceString('JavaScriptIndexingBehavior')); |
| 459 if (jsIndexingBehaviorInterface !== null) { | 446 if (jsIndexingBehaviorInterface !== null) { |
| 460 library.addToScope(jsIndexingBehaviorInterface, this); | 447 library.addToScope(jsIndexingBehaviorInterface, this); |
| 461 } | 448 } |
| 462 } | 449 } |
| 463 } | 450 } |
| 464 | 451 |
| 465 void runCompiler(Uri uri) { | 452 void runCompiler(Uri uri) { |
| 466 log('compiling $uri ($BUILD_ID)'); | 453 log('compiling $uri ($BUILD_ID)'); |
| 467 scanBuiltinLibraries(); | 454 scanBuiltinLibraries(); |
| 468 mainApp = scanner.loadLibrary(uri, null, uri); | 455 mainApp = libraryLoader.loadLibrary(uri, null, uri); |
| 469 libraries.forEach((_, library) { | 456 libraries.forEach((_, library) { |
| 470 maybeEnableJSHelper(library); | 457 maybeEnableJSHelper(library); |
| 471 }); | 458 }); |
| 472 final Element main = mainApp.find(MAIN); | 459 final Element main = mainApp.find(MAIN); |
| 473 if (main === null) { | 460 if (main === null) { |
| 474 reportFatalError('Could not find $MAIN', mainApp); | 461 reportFatalError('Could not find $MAIN', mainApp); |
| 475 } else { | 462 } else { |
| 476 if (!main.isFunction()) reportFatalError('main is not a function', main); | 463 if (!main.isFunction()) reportFatalError('main is not a function', main); |
| 477 FunctionElement mainMethod = main; | 464 FunctionElement mainMethod = main; |
| 478 FunctionSignature parameters = mainMethod.computeSignature(this); | 465 FunctionSignature parameters = mainMethod.computeSignature(this); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 * | 841 * |
| 855 * [spannable] must be non-null and will be used to provide positional | 842 * [spannable] must be non-null and will be used to provide positional |
| 856 * information in the generated error message. | 843 * information in the generated error message. |
| 857 */ | 844 */ |
| 858 bool invariant(Spannable spannable, var condition, {String message: null}) { | 845 bool invariant(Spannable spannable, var condition, {String message: null}) { |
| 859 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 846 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 860 // information on assertion errors. | 847 // information on assertion errors. |
| 861 if (condition is Function){ | 848 if (condition is Function){ |
| 862 condition = condition(); | 849 condition = condition(); |
| 863 } | 850 } |
| 851 if (!condition && message != null) { |
| 852 print('assertion failed: $message'); |
| 853 } |
| 864 return spannable != null && condition; | 854 return spannable != null && condition; |
| 865 } | 855 } |
| OLD | NEW |