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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 final bool enableUserAssertions; | 103 final bool enableUserAssertions; |
104 final bool enableConcreteTypeInference; | 104 final bool enableConcreteTypeInference; |
105 | 105 |
106 bool disableInlining = false; | 106 bool disableInlining = false; |
107 | 107 |
108 final Tracer tracer; | 108 final Tracer tracer; |
109 | 109 |
110 CompilerTask measuredTask; | 110 CompilerTask measuredTask; |
111 Element _currentElement; | 111 Element _currentElement; |
112 LibraryElement coreLibrary; | 112 LibraryElement coreLibrary; |
113 LibraryElement coreImplLibrary; | |
114 LibraryElement isolateLibrary; | 113 LibraryElement isolateLibrary; |
115 LibraryElement jsHelperLibrary; | 114 LibraryElement jsHelperLibrary; |
116 LibraryElement interceptorsLibrary; | 115 LibraryElement interceptorsLibrary; |
117 LibraryElement mainApp; | 116 LibraryElement mainApp; |
118 | 117 |
119 ClassElement objectClass; | 118 ClassElement objectClass; |
120 ClassElement closureClass; | 119 ClassElement closureClass; |
121 ClassElement dynamicClass; | 120 ClassElement dynamicClass; |
122 ClassElement boolClass; | 121 ClassElement boolClass; |
123 ClassElement numClass; | 122 ClassElement numClass; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 368 |
370 bool hasIsolateSupport() => isolateLibrary != null; | 369 bool hasIsolateSupport() => isolateLibrary != null; |
371 | 370 |
372 /** | 371 /** |
373 * This method is called before [library] import and export scopes have been | 372 * This method is called before [library] import and export scopes have been |
374 * set up. | 373 * set up. |
375 */ | 374 */ |
376 void onLibraryScanned(LibraryElement library, Uri uri) { | 375 void onLibraryScanned(LibraryElement library, Uri uri) { |
377 if (dynamicClass != null) { | 376 if (dynamicClass != null) { |
378 // When loading the built-in libraries, dynamicClass is null. We | 377 // When loading the built-in libraries, dynamicClass is null. We |
379 // take advantage of this as core and coreimpl import js_helper | 378 // take advantage of this as core imports js_helper and sees [dynamic] |
380 // and see Dynamic this way. | 379 // this way. |
381 withCurrentElement(dynamicClass, () { | 380 withCurrentElement(dynamicClass, () { |
382 library.addToScope(dynamicClass, this); | 381 library.addToScope(dynamicClass, this); |
383 }); | 382 }); |
384 } | 383 } |
385 } | 384 } |
386 | 385 |
387 LibraryElement scanBuiltinLibrary(String filename); | 386 LibraryElement scanBuiltinLibrary(String filename); |
388 | 387 |
389 void initializeSpecialClasses() { | 388 void initializeSpecialClasses() { |
390 bool coreLibValid = true; | 389 bool coreLibValid = true; |
(...skipping 20 matching lines...) Expand all Loading... |
411 closureClass = lookupSpecialClass(const SourceString('Closure')); | 410 closureClass = lookupSpecialClass(const SourceString('Closure')); |
412 dynamicClass = lookupSpecialClass(const SourceString('Dynamic_')); | 411 dynamicClass = lookupSpecialClass(const SourceString('Dynamic_')); |
413 nullClass = lookupSpecialClass(const SourceString('Null')); | 412 nullClass = lookupSpecialClass(const SourceString('Null')); |
414 types = new Types(this, dynamicClass); | 413 types = new Types(this, dynamicClass); |
415 if (!coreLibValid) { | 414 if (!coreLibValid) { |
416 cancel('core library does not contain required classes'); | 415 cancel('core library does not contain required classes'); |
417 } | 416 } |
418 } | 417 } |
419 | 418 |
420 void scanBuiltinLibraries() { | 419 void scanBuiltinLibraries() { |
421 loadCoreImplLibrary(); | |
422 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); | 420 jsHelperLibrary = scanBuiltinLibrary('_js_helper'); |
423 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); | 421 interceptorsLibrary = scanBuiltinLibrary('_interceptors'); |
424 | 422 |
425 // The core and coreimpl libraries were loaded and patched before | 423 // The core library was loaded and patched before jsHelperLibrary was |
426 // jsHelperLibrary was initialized, so it wasn't imported into those | 424 // initialized, so it wasn't imported into those two libraries during |
427 // two libraries during patching. | 425 // patching. |
428 importHelperLibrary(coreLibrary); | 426 importHelperLibrary(coreLibrary); |
429 importHelperLibrary(coreImplLibrary); | |
430 importHelperLibrary(interceptorsLibrary); | 427 importHelperLibrary(interceptorsLibrary); |
431 | 428 |
432 addForeignFunctions(jsHelperLibrary); | 429 addForeignFunctions(jsHelperLibrary); |
433 addForeignFunctions(interceptorsLibrary); | 430 addForeignFunctions(interceptorsLibrary); |
434 | 431 |
435 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); | 432 assertMethod = jsHelperLibrary.find(const SourceString('assertHelper')); |
436 identicalFunction = coreLibrary.find(const SourceString('identical')); | 433 identicalFunction = coreLibrary.find(const SourceString('identical')); |
437 | 434 |
438 initializeSpecialClasses(); | 435 initializeSpecialClasses(); |
439 | 436 |
440 functionClass.ensureResolved(this); | 437 functionClass.ensureResolved(this); |
441 functionApplyMethod = | 438 functionApplyMethod = |
442 functionClass.lookupLocalMember(const SourceString('apply')); | 439 functionClass.lookupLocalMember(const SourceString('apply')); |
443 jsInvocationMirrorClass.ensureResolved(this); | 440 jsInvocationMirrorClass.ensureResolved(this); |
444 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( | 441 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember( |
445 const SourceString('invokeOn')); | 442 const SourceString('invokeOn')); |
446 } | 443 } |
447 | 444 |
448 void loadCoreImplLibrary() { | |
449 Uri coreImplUri = new Uri.fromComponents(scheme: 'dart', path: 'coreimpl'); | |
450 coreImplLibrary = libraryLoader.loadLibrary(coreImplUri, null, coreImplUri); | |
451 } | |
452 | |
453 void importHelperLibrary(LibraryElement library) { | 445 void importHelperLibrary(LibraryElement library) { |
454 if (jsHelperLibrary != null) { | 446 if (jsHelperLibrary != null) { |
455 libraryLoader.importLibrary(library, jsHelperLibrary, null); | 447 libraryLoader.importLibrary(library, jsHelperLibrary, null); |
456 } | 448 } |
457 } | 449 } |
458 | 450 |
459 /** | 451 /** |
460 * Get an [Uri] pointing to a patch for the dart: library with | 452 * Get an [Uri] pointing to a patch for the dart: library with |
461 * the given path. Returns null if there is no patch. | 453 * the given path. Returns null if there is no patch. |
462 */ | 454 */ |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 902 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
911 // information on assertion errors. | 903 // information on assertion errors. |
912 if (condition is Function){ | 904 if (condition is Function){ |
913 condition = condition(); | 905 condition = condition(); |
914 } | 906 } |
915 if (spannable == null || !condition) { | 907 if (spannable == null || !condition) { |
916 throw new SpannableAssertionFailure(spannable, message); | 908 throw new SpannableAssertionFailure(spannable, message); |
917 } | 909 } |
918 return true; | 910 return true; |
919 } | 911 } |
OLD | NEW |