| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ClassElement boolClass; | 108 ClassElement boolClass; |
| 109 ClassElement numClass; | 109 ClassElement numClass; |
| 110 ClassElement intClass; | 110 ClassElement intClass; |
| 111 ClassElement doubleClass; | 111 ClassElement doubleClass; |
| 112 ClassElement stringClass; | 112 ClassElement stringClass; |
| 113 ClassElement functionClass; | 113 ClassElement functionClass; |
| 114 ClassElement nullClass; | 114 ClassElement nullClass; |
| 115 ClassElement listClass; | 115 ClassElement listClass; |
| 116 Element assertMethod; | 116 Element assertMethod; |
| 117 | 117 |
| 118 /** | |
| 119 * Interface used to determine if an object has the JavaScript | |
| 120 * indexing behavior. The interface is only visible to specific | |
| 121 * libraries. | |
| 122 */ | |
| 123 ClassElement jsIndexingBehaviorInterface; | |
| 124 | |
| 125 Element get currentElement => _currentElement; | 118 Element get currentElement => _currentElement; |
| 126 withCurrentElement(Element element, f()) { | 119 withCurrentElement(Element element, f()) { |
| 127 Element old = currentElement; | 120 Element old = currentElement; |
| 128 _currentElement = element; | 121 _currentElement = element; |
| 129 try { | 122 try { |
| 130 return f(); | 123 return f(); |
| 131 } on CompilerCancelledException catch (ex) { | 124 } on CompilerCancelledException catch (ex) { |
| 132 throw; | 125 throw; |
| 133 } on StackOverflowException catch (ex) { | 126 } on StackOverflowException catch (ex) { |
| 134 // We cannot report anything useful in this case, because we | 127 // We cannot report anything useful in this case, because we |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 stringClass = lookupSpecialClass(const SourceString('String')); | 341 stringClass = lookupSpecialClass(const SourceString('String')); |
| 349 functionClass = lookupSpecialClass(const SourceString('Function')); | 342 functionClass = lookupSpecialClass(const SourceString('Function')); |
| 350 listClass = lookupSpecialClass(const SourceString('List')); | 343 listClass = lookupSpecialClass(const SourceString('List')); |
| 351 closureClass = lookupSpecialClass(const SourceString('Closure')); | 344 closureClass = lookupSpecialClass(const SourceString('Closure')); |
| 352 dynamicClass = lookupSpecialClass(const SourceString('Dynamic')); | 345 dynamicClass = lookupSpecialClass(const SourceString('Dynamic')); |
| 353 nullClass = lookupSpecialClass(const SourceString('Null')); | 346 nullClass = lookupSpecialClass(const SourceString('Null')); |
| 354 types = new Types(this, dynamicClass); | 347 types = new Types(this, dynamicClass); |
| 355 if (!coreLibValid) { | 348 if (!coreLibValid) { |
| 356 cancel('core library does not contain required classes'); | 349 cancel('core library does not contain required classes'); |
| 357 } | 350 } |
| 358 | |
| 359 jsIndexingBehaviorInterface = | |
| 360 findHelper(const SourceString('JavaScriptIndexingBehavior')); | |
| 361 } | 351 } |
| 362 | 352 |
| 363 void scanBuiltinLibraries() { | 353 void scanBuiltinLibraries() { |
| 364 coreImplLibrary = scanBuiltinLibrary('coreimpl'); | 354 coreImplLibrary = scanBuiltinLibrary('coreimpl'); |
| 365 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); | 355 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); |
| 366 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); | 356 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); |
| 367 | 357 |
| 368 addForeignFunctions(jsHelperLibrary); | 358 addForeignFunctions(jsHelperLibrary); |
| 369 addForeignFunctions(interceptorsLibrary); | 359 addForeignFunctions(interceptorsLibrary); |
| 370 | 360 |
| 371 libraries['dart:core'] = coreLibrary; | 361 libraries['dart:core'] = coreLibrary; |
| 372 libraries['dart:coreimpl'] = coreImplLibrary; | 362 libraries['dart:coreimpl'] = coreImplLibrary; |
| 373 | 363 |
| 374 assertMethod = coreLibrary.find(const SourceString('assert')); | 364 assertMethod = coreLibrary.find(const SourceString('assert')); |
| 375 | 365 |
| 376 initializeSpecialClasses(); | 366 initializeSpecialClasses(); |
| 377 | |
| 378 //patchDartLibrary(coreLibrary, 'core'); | |
| 379 //patchDartLibrary(coreImplLibrary, 'coreimpl'); | |
| 380 } | 367 } |
| 381 | 368 |
| 382 void importCoreLibrary(LibraryElement library) { | 369 void importCoreLibrary(LibraryElement library) { |
| 383 Uri coreUri = new Uri.fromComponents(scheme: 'dart', path: 'core'); | 370 Uri coreUri = new Uri.fromComponents(scheme: 'dart', path: 'core'); |
| 384 if (coreLibrary === null) { | 371 if (coreLibrary === null) { |
| 385 coreLibrary = scanner.loadLibrary(coreUri, null, coreUri); | 372 coreLibrary = scanner.loadLibrary(coreUri, null, coreUri); |
| 386 } | 373 } |
| 387 scanner.importLibrary(library, | 374 scanner.importLibrary(library, |
| 388 coreLibrary, | 375 coreLibrary, |
| 389 null, | 376 null, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 library.addToScope(new ForeignElement( | 499 library.addToScope(new ForeignElement( |
| 513 const SourceString('JS_HAS_EQUALS'), library), this); | 500 const SourceString('JS_HAS_EQUALS'), library), this); |
| 514 library.addToScope(new ForeignElement( | 501 library.addToScope(new ForeignElement( |
| 515 const SourceString('JS_CURRENT_ISOLATE'), library), this); | 502 const SourceString('JS_CURRENT_ISOLATE'), library), this); |
| 516 library.addToScope(new ForeignElement( | 503 library.addToScope(new ForeignElement( |
| 517 const SourceString('JS_CALL_IN_ISOLATE'), library), this); | 504 const SourceString('JS_CALL_IN_ISOLATE'), library), this); |
| 518 library.addToScope(new ForeignElement( | 505 library.addToScope(new ForeignElement( |
| 519 const SourceString('DART_CLOSURE_TO_JS'), library), this); | 506 const SourceString('DART_CLOSURE_TO_JS'), library), this); |
| 520 } | 507 } |
| 521 | 508 |
| 509 // TODO(karlklose,floitsch): move this to the javascript backend. |
| 522 /** Enable the 'JS' helper for a library if needed. */ | 510 /** Enable the 'JS' helper for a library if needed. */ |
| 523 void maybeEnableJSHelper(library) { | 511 void maybeEnableJSHelper(library) { |
| 524 String libraryName = library.uri.toString(); | 512 String libraryName = library.uri.toString(); |
| 525 if (library.entryCompilationUnit.script.name.contains( | 513 if (library.entryCompilationUnit.script.name.contains( |
| 526 'dart/tests/compiler/dart2js_native') | 514 'dart/tests/compiler/dart2js_native') |
| 527 || libraryName == 'dart:isolate' | 515 || libraryName == 'dart:isolate' |
| 528 || libraryName == 'dart:math' | 516 || libraryName == 'dart:math' |
| 529 || libraryName == 'dart:html') { | 517 || libraryName == 'dart:html') { |
| 530 library.addToScope(findHelper(const SourceString('JS')), this); | 518 library.addToScope(findHelper(const SourceString('JS')), this); |
| 519 Element jsIndexingBehaviorInterface = |
| 520 findHelper(const SourceString('JavaScriptIndexingBehavior')); |
| 531 if (jsIndexingBehaviorInterface !== null) { | 521 if (jsIndexingBehaviorInterface !== null) { |
| 532 library.addToScope(jsIndexingBehaviorInterface, this); | 522 library.addToScope(jsIndexingBehaviorInterface, this); |
| 533 } | 523 } |
| 534 } | 524 } |
| 535 } | 525 } |
| 536 | 526 |
| 537 void runCompiler(Uri uri) { | 527 void runCompiler(Uri uri) { |
| 538 log('compiling $uri ($BUILD_ID)'); | 528 log('compiling $uri ($BUILD_ID)'); |
| 539 scanBuiltinLibraries(); | 529 scanBuiltinLibraries(); |
| 540 mainApp = scanner.loadLibrary(uri, null, uri); | 530 mainApp = scanner.loadLibrary(uri, null, uri); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 phase = PHASE_COMPILING; | 562 phase = PHASE_COMPILING; |
| 573 processQueue(enqueuer.codegen, main); | 563 processQueue(enqueuer.codegen, main); |
| 574 log("Recompiling ${enqueuer.codegen.recompilationCandidates.length} " | 564 log("Recompiling ${enqueuer.codegen.recompilationCandidates.length} " |
| 575 "methods..."); | 565 "methods..."); |
| 576 phase = PHASE_RECOMPILING; | 566 phase = PHASE_RECOMPILING; |
| 577 processRecompilationQueue(enqueuer.codegen); | 567 processRecompilationQueue(enqueuer.codegen); |
| 578 log('Compiled ${codegenWorld.generatedCode.length} methods.'); | 568 log('Compiled ${codegenWorld.generatedCode.length} methods.'); |
| 579 | 569 |
| 580 if (compilationFailed) return; | 570 if (compilationFailed) return; |
| 581 | 571 |
| 572 // TODO(karlklose): also take the instantiated types into account and move |
| 573 // this computation to before codegen. |
| 574 enqueuer.codegen.universe.computeRequiredTypes( |
| 575 enqueuer.resolution.universe.isChecks); |
| 576 |
| 582 backend.assembleProgram(); | 577 backend.assembleProgram(); |
| 583 | 578 |
| 584 checkQueues(); | 579 checkQueues(); |
| 585 } | 580 } |
| 586 | 581 |
| 587 void processQueue(Enqueuer world, Element main) { | 582 void processQueue(Enqueuer world, Element main) { |
| 588 backend.processNativeClasses(world, libraries.getValues()); | 583 backend.processNativeClasses(world, libraries.getValues()); |
| 589 world.addToWorkList(main); | 584 world.addToWorkList(main); |
| 590 progress.reset(); | 585 progress.reset(); |
| 591 world.forEach((WorkItem work) { | 586 world.forEach((WorkItem work) { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 final endOffset = end.charOffset + end.slowCharCount; | 921 final endOffset = end.charOffset + end.slowCharCount; |
| 927 | 922 |
| 928 // [begin] and [end] might be the same for the same empty token. This | 923 // [begin] and [end] might be the same for the same empty token. This |
| 929 // happens for instance when scanning '$$'. | 924 // happens for instance when scanning '$$'. |
| 930 assert(endOffset >= beginOffset); | 925 assert(endOffset >= beginOffset); |
| 931 return f(beginOffset, endOffset); | 926 return f(beginOffset, endOffset); |
| 932 } | 927 } |
| 933 | 928 |
| 934 String toString() => 'SourceSpan($uri, $begin, $end)'; | 929 String toString() => 'SourceSpan($uri, $begin, $end)'; |
| 935 } | 930 } |
| OLD | NEW |