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 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 ClassElement boolClass; | 299 ClassElement boolClass; |
| 300 ClassElement numClass; | 300 ClassElement numClass; |
| 301 ClassElement intClass; | 301 ClassElement intClass; |
| 302 ClassElement doubleClass; | 302 ClassElement doubleClass; |
| 303 ClassElement stringClass; | 303 ClassElement stringClass; |
| 304 ClassElement functionClass; | 304 ClassElement functionClass; |
| 305 ClassElement nullClass; | 305 ClassElement nullClass; |
| 306 ClassElement listClass; | 306 ClassElement listClass; |
| 307 ClassElement typeClass; | 307 ClassElement typeClass; |
| 308 ClassElement mapClass; | 308 ClassElement mapClass; |
| 309 ClassElement symbolClass; | |
| 310 | |
| 311 // Initialized after mirrorSystemClass has been resolved. | |
| 312 FunctionElement symbolConstructor; | |
| 313 | |
| 314 // Initialized when dart:mirrors is loaded. | |
| 315 ClassElement mirrorSystemClass; | |
| 316 | |
| 317 // Initialized after mirrorSystemClass has been resolved. | |
| 318 FunctionElement mirrorSystemGetNameFunction; | |
| 319 | |
| 320 // Initialized when dart:_collection-dev is loaded. | |
| 321 ClassElement symbolImplementationClass; | |
| 322 | |
| 323 // Initialized when symbolImplementationClass has been resolved. | |
| 324 FunctionElement symbolValidatedConstructor; | |
| 325 | |
| 309 ClassElement jsInvocationMirrorClass; | 326 ClassElement jsInvocationMirrorClass; |
| 310 /// Document class from dart:mirrors. | 327 /// Document class from dart:mirrors. |
| 311 ClassElement documentClass; | 328 ClassElement documentClass; |
| 312 Element assertMethod; | 329 Element assertMethod; |
| 313 Element identicalFunction; | 330 Element identicalFunction; |
| 314 Element functionApplyMethod; | 331 Element functionApplyMethod; |
| 315 Element invokeOnMethod; | 332 Element invokeOnMethod; |
| 316 Element createInvocationMirrorElement; | 333 Element createInvocationMirrorElement; |
| 317 | 334 |
| 318 Element get currentElement => _currentElement; | 335 Element get currentElement => _currentElement; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 const SourceString('startRootIsolate'); | 395 const SourceString('startRootIsolate'); |
| 379 | 396 |
| 380 final Selector iteratorSelector = | 397 final Selector iteratorSelector = |
| 381 new Selector.getter(const SourceString('iterator'), null); | 398 new Selector.getter(const SourceString('iterator'), null); |
| 382 final Selector currentSelector = | 399 final Selector currentSelector = |
| 383 new Selector.getter(const SourceString('current'), null); | 400 new Selector.getter(const SourceString('current'), null); |
| 384 final Selector moveNextSelector = | 401 final Selector moveNextSelector = |
| 385 new Selector.call(const SourceString('moveNext'), null, 0); | 402 new Selector.call(const SourceString('moveNext'), null, 0); |
| 386 final Selector noSuchMethodSelector = new Selector.call( | 403 final Selector noSuchMethodSelector = new Selector.call( |
| 387 Compiler.NO_SUCH_METHOD, null, Compiler.NO_SUCH_METHOD_ARG_COUNT); | 404 Compiler.NO_SUCH_METHOD, null, Compiler.NO_SUCH_METHOD_ARG_COUNT); |
| 405 final Selector symbolValidatedConstructorSelector = new Selector.call( | |
| 406 const SourceString('validated'), null, 1); | |
| 388 | 407 |
| 389 bool enabledNoSuchMethod = false; | 408 bool enabledNoSuchMethod = false; |
| 390 bool enabledRuntimeType = false; | 409 bool enabledRuntimeType = false; |
| 391 bool enabledFunctionApply = false; | 410 bool enabledFunctionApply = false; |
| 392 bool enabledInvokeOn = false; | 411 bool enabledInvokeOn = false; |
| 393 | 412 |
| 394 Stopwatch progress; | 413 Stopwatch progress; |
| 395 | 414 |
| 396 static const int PHASE_SCANNING = 0; | 415 static const int PHASE_SCANNING = 0; |
| 397 static const int PHASE_RESOLVING = 1; | 416 static const int PHASE_RESOLVING = 1; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 */ | 628 */ |
| 610 void onLibraryScanned(LibraryElement library, Uri uri) { | 629 void onLibraryScanned(LibraryElement library, Uri uri) { |
| 611 if (dynamicClass != null) { | 630 if (dynamicClass != null) { |
| 612 // When loading the built-in libraries, dynamicClass is null. We | 631 // When loading the built-in libraries, dynamicClass is null. We |
| 613 // take advantage of this as core imports js_helper and sees [dynamic] | 632 // take advantage of this as core imports js_helper and sees [dynamic] |
| 614 // this way. | 633 // this way. |
| 615 withCurrentElement(dynamicClass, () { | 634 withCurrentElement(dynamicClass, () { |
| 616 library.addToScope(dynamicClass, this); | 635 library.addToScope(dynamicClass, this); |
| 617 }); | 636 }); |
| 618 } | 637 } |
| 638 if (uri == Uri.parse('dart:mirrors')) { | |
| 639 mirrorSystemClass = library.find(const SourceString('MirrorSystem')); | |
| 640 } else if (uri == Uri.parse('dart:_collection-dev')) { | |
| 641 symbolImplementationClass = library.find(const SourceString('Symbol')); | |
| 642 } | |
| 643 } | |
| 644 | |
| 645 void onClassResolved(ClassElement cls) { | |
| 646 if (mirrorSystemClass == cls) { | |
| 647 mirrorSystemGetNameFunction = | |
| 648 cls.lookupLocalMember(const SourceString('getName')); | |
| 649 } else if (symbolClass == cls) { | |
| 650 symbolConstructor = cls.constructors.head; | |
| 651 } else if (symbolImplementationClass == cls) { | |
| 652 symbolValidatedConstructor = symbolImplementationClass.lookupConstructor( | |
| 653 symbolValidatedConstructorSelector); | |
| 654 } | |
| 619 } | 655 } |
| 620 | 656 |
| 621 LibraryElement scanBuiltinLibrary(String filename); | 657 LibraryElement scanBuiltinLibrary(String filename); |
| 622 | 658 |
| 623 void initializeSpecialClasses() { | 659 void initializeSpecialClasses() { |
| 624 final List missingCoreClasses = []; | 660 final List missingCoreClasses = []; |
| 625 ClassElement lookupCoreClass(String name) { | 661 ClassElement lookupCoreClass(String name) { |
| 626 ClassElement result = coreLibrary.find(new SourceString(name)); | 662 ClassElement result = coreLibrary.find(new SourceString(name)); |
| 627 if (result == null) { | 663 if (result == null) { |
| 628 missingCoreClasses.add(name); | 664 missingCoreClasses.add(name); |
| 629 } | 665 } |
| 630 return result; | 666 return result; |
| 631 } | 667 } |
| 632 objectClass = lookupCoreClass('Object'); | 668 objectClass = lookupCoreClass('Object'); |
| 633 boolClass = lookupCoreClass('bool'); | 669 boolClass = lookupCoreClass('bool'); |
| 634 numClass = lookupCoreClass('num'); | 670 numClass = lookupCoreClass('num'); |
| 635 intClass = lookupCoreClass('int'); | 671 intClass = lookupCoreClass('int'); |
| 636 doubleClass = lookupCoreClass('double'); | 672 doubleClass = lookupCoreClass('double'); |
| 637 stringClass = lookupCoreClass('String'); | 673 stringClass = lookupCoreClass('String'); |
| 638 functionClass = lookupCoreClass('Function'); | 674 functionClass = lookupCoreClass('Function'); |
| 639 listClass = lookupCoreClass('List'); | 675 listClass = lookupCoreClass('List'); |
| 640 typeClass = lookupCoreClass('Type'); | 676 typeClass = lookupCoreClass('Type'); |
| 641 mapClass = lookupCoreClass('Map'); | 677 mapClass = lookupCoreClass('Map'); |
| 642 if (!missingCoreClasses.isEmpty) { | 678 if (!missingCoreClasses.isEmpty) { |
| 643 internalErrorOnElement(coreLibrary, | 679 internalErrorOnElement(coreLibrary, |
| 644 'dart:core library does not contain required classes: ' | 680 'dart:core library does not contain required classes: ' |
| 645 '$missingCoreClasses'); | 681 '$missingCoreClasses'); |
| 646 } | 682 } |
| 647 | 683 |
| 684 // The following classes may not exist. | |
|
Johnni Winther
2013/04/18 19:01:39
classes? I only see Symbol.
ahe
2013/04/18 19:23:47
Done.
| |
| 685 // TODO(ahe): It is possible that we have to require the presence | |
| 686 // of Symbol as we change how we implement noSuchMethod. | |
| 687 symbolClass = lookupCoreClass('Symbol'); | |
| 688 | |
| 648 final List missingHelperClasses = []; | 689 final List missingHelperClasses = []; |
| 649 ClassElement lookupHelperClass(String name) { | 690 ClassElement lookupHelperClass(String name) { |
| 650 ClassElement result = jsHelperLibrary.find(new SourceString(name)); | 691 ClassElement result = jsHelperLibrary.find(new SourceString(name)); |
| 651 if (result == null) { | 692 if (result == null) { |
| 652 missingHelperClasses.add(name); | 693 missingHelperClasses.add(name); |
| 653 } | 694 } |
| 654 return result; | 695 return result; |
| 655 } | 696 } |
| 656 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); | 697 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); |
| 657 closureClass = lookupHelperClass('Closure'); | 698 closureClass = lookupHelperClass('Closure'); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1006 } | 1047 } |
| 1007 | 1048 |
| 1008 // TODO(ahe): Rename to reportError when that method has been removed. | 1049 // TODO(ahe): Rename to reportError when that method has been removed. |
| 1009 void reportErrorCode(Spannable node, MessageKind errorCode, | 1050 void reportErrorCode(Spannable node, MessageKind errorCode, |
| 1010 [Map arguments = const {}]) { | 1051 [Map arguments = const {}]) { |
| 1011 reportMessage(spanFromSpannable(node), | 1052 reportMessage(spanFromSpannable(node), |
| 1012 errorCode.error(arguments), | 1053 errorCode.error(arguments), |
| 1013 api.Diagnostic.ERROR); | 1054 api.Diagnostic.ERROR); |
| 1014 } | 1055 } |
| 1015 | 1056 |
| 1057 // TODO(ahe): Rename to reportWarning when that method has been removed. | |
| 1058 void reportWarningCode(Spannable node, MessageKind errorCode, | |
| 1059 [Map arguments = const {}]) { | |
| 1060 reportMessage(spanFromSpannable(node), | |
| 1061 errorCode.error(arguments), | |
| 1062 api.Diagnostic.WARNING); | |
| 1063 } | |
| 1064 | |
| 1016 void reportMessage(SourceSpan span, Diagnostic message, api.Diagnostic kind) { | 1065 void reportMessage(SourceSpan span, Diagnostic message, api.Diagnostic kind) { |
| 1017 // TODO(ahe): The names Diagnostic and api.Diagnostic are in | 1066 // TODO(ahe): The names Diagnostic and api.Diagnostic are in |
| 1018 // conflict. Fix it. | 1067 // conflict. Fix it. |
| 1019 reportDiagnostic(span, "$message", kind); | 1068 reportDiagnostic(span, "$message", kind); |
| 1020 } | 1069 } |
| 1021 | 1070 |
| 1022 /// Returns true if a diagnostic was emitted. | 1071 /// Returns true if a diagnostic was emitted. |
| 1023 bool onDeprecatedFeature(Spannable span, String feature) { | 1072 bool onDeprecatedFeature(Spannable span, String feature) { |
| 1024 if (currentElement == null) | 1073 if (currentElement == null) |
| 1025 throw new SpannableAssertionFailure(span, feature); | 1074 throw new SpannableAssertionFailure(span, feature); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 | 1328 |
| 1280 void close() {} | 1329 void close() {} |
| 1281 | 1330 |
| 1282 toString() => name; | 1331 toString() => name; |
| 1283 | 1332 |
| 1284 /// Convenience method for getting an [api.CompilerOutputProvider]. | 1333 /// Convenience method for getting an [api.CompilerOutputProvider]. |
| 1285 static NullSink outputProvider(String name, String extension) { | 1334 static NullSink outputProvider(String name, String extension) { |
| 1286 return new NullSink('$name.$extension'); | 1335 return new NullSink('$name.$extension'); |
| 1287 } | 1336 } |
| 1288 } | 1337 } |
| OLD | NEW |