| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.resolution.constructors; | 5 library dart2js.resolution.constructors; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show | 8 import '../common/resolution.dart' show |
| 9 Feature; | 9 Feature; |
| 10 import '../compiler.dart' show | 10 import '../compiler.dart' show |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 478 |
| 479 ConstructorResult reportAndCreateErroneousConstructorElement( | 479 ConstructorResult reportAndCreateErroneousConstructorElement( |
| 480 Spannable diagnosticNode, | 480 Spannable diagnosticNode, |
| 481 ConstructorResultKind resultKind, | 481 ConstructorResultKind resultKind, |
| 482 DartType type, | 482 DartType type, |
| 483 Element enclosing, | 483 Element enclosing, |
| 484 String name, | 484 String name, |
| 485 MessageKind kind, | 485 MessageKind kind, |
| 486 Map arguments, | 486 Map arguments, |
| 487 {bool isError: false, | 487 {bool isError: false, |
| 488 bool missingConstructor: false}) { | 488 bool missingConstructor: false, |
| 489 List<DiagnosticMessage> infos: const <DiagnosticMessage>[]}) { |
| 489 if (missingConstructor) { | 490 if (missingConstructor) { |
| 490 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 491 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 491 } else { | 492 } else { |
| 492 registry.registerFeature(Feature.THROW_RUNTIME_ERROR); | 493 registry.registerFeature(Feature.THROW_RUNTIME_ERROR); |
| 493 } | 494 } |
| 495 DiagnosticMessage message = |
| 496 reporter.createMessage(diagnosticNode, kind, arguments); |
| 494 if (isError || inConstContext) { | 497 if (isError || inConstContext) { |
| 495 reporter.reportErrorMessage( | 498 reporter.reportError(message, infos); |
| 496 diagnosticNode, kind, arguments); | |
| 497 } else { | 499 } else { |
| 498 reporter.reportWarningMessage( | 500 reporter.reportWarning(message, infos); |
| 499 diagnosticNode, kind, arguments); | |
| 500 } | 501 } |
| 501 ErroneousElement error = new ErroneousConstructorElementX( | 502 ErroneousElement error = new ErroneousConstructorElementX( |
| 502 kind, arguments, name, enclosing); | 503 kind, arguments, name, enclosing); |
| 503 if (type == null) { | 504 if (type == null) { |
| 504 type = new MalformedType(error, null); | 505 type = new MalformedType(error, null); |
| 505 } | 506 } |
| 506 return new ConstructorResult.forError(resultKind, error, type); | 507 return new ConstructorResult.forError(resultKind, error, type); |
| 507 } | 508 } |
| 508 | 509 |
| 509 ConstructorResult resolveConstructor( | 510 ConstructorResult resolveConstructor( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 // constructor. Therefore we allow deferred types. | 610 // constructor. Therefore we allow deferred types. |
| 610 DartType type = resolver.resolveTypeAnnotation( | 611 DartType type = resolver.resolveTypeAnnotation( |
| 611 node, | 612 node, |
| 612 malformedIsError: inConstContext, | 613 malformedIsError: inConstContext, |
| 613 deferredIsMalformed: false); | 614 deferredIsMalformed: false); |
| 614 Send send = node.typeName.asSend(); | 615 Send send = node.typeName.asSend(); |
| 615 PrefixElement prefix; | 616 PrefixElement prefix; |
| 616 if (send != null) { | 617 if (send != null) { |
| 617 // The type name is of the form [: prefix . identifier :]. | 618 // The type name is of the form [: prefix . identifier :]. |
| 618 String name = send.receiver.asIdentifier().source; | 619 String name = send.receiver.asIdentifier().source; |
| 619 Element element = resolver.reportLookupErrorIfAny( | 620 Element element = lookupInScope(reporter, send, resolver.scope, name); |
| 620 lookupInScope(reporter, send, resolver.scope, name), node, name); | |
| 621 if (element != null && element.isPrefix) { | 621 if (element != null && element.isPrefix) { |
| 622 prefix = element; | 622 prefix = element; |
| 623 } | 623 } |
| 624 } | 624 } |
| 625 return constructorResultForType(node, type, prefix: prefix); | 625 return constructorResultForType(node, type, prefix: prefix); |
| 626 } | 626 } |
| 627 | 627 |
| 628 ConstructorResult visitSend(Send node) { | 628 ConstructorResult visitSend(Send node) { |
| 629 ConstructorResult receiver = visit(node.receiver); | 629 ConstructorResult receiver = visit(node.receiver); |
| 630 assert(invariant(node.receiver, receiver != null, | 630 assert(invariant(node.receiver, receiver != null, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 659 return constructorResultForElement( | 659 return constructorResultForElement( |
| 660 node, name.source, member, prefix: prefix); | 660 node, name.source, member, prefix: prefix); |
| 661 } else { | 661 } else { |
| 662 return reporter.internalError( | 662 return reporter.internalError( |
| 663 node.receiver, 'unexpected receiver $receiver'); | 663 node.receiver, 'unexpected receiver $receiver'); |
| 664 } | 664 } |
| 665 } | 665 } |
| 666 | 666 |
| 667 ConstructorResult visitIdentifier(Identifier node) { | 667 ConstructorResult visitIdentifier(Identifier node) { |
| 668 String name = node.source; | 668 String name = node.source; |
| 669 Element element = resolver.reportLookupErrorIfAny( | 669 Element element = lookupInScope(reporter, node, resolver.scope, name); |
| 670 lookupInScope(reporter, node, resolver.scope, name), node, name); | |
| 671 registry.useElement(node, element); | 670 registry.useElement(node, element); |
| 672 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. | |
| 673 return constructorResultForElement(node, name, element); | 671 return constructorResultForElement(node, name, element); |
| 674 } | 672 } |
| 675 | 673 |
| 676 /// Assumed to be called by [resolveRedirectingFactory]. | 674 /// Assumed to be called by [resolveRedirectingFactory]. |
| 677 ConstructorResult visitRedirectingFactoryBody(RedirectingFactoryBody node) { | 675 ConstructorResult visitRedirectingFactoryBody(RedirectingFactoryBody node) { |
| 678 Node constructorReference = node.constructorReference; | 676 Node constructorReference = node.constructorReference; |
| 679 return finishConstructorReference(visit(constructorReference), | 677 return finishConstructorReference(visit(constructorReference), |
| 680 constructorReference, node); | 678 constructorReference, node); |
| 681 } | 679 } |
| 682 | 680 |
| 683 ConstructorResult constructorResultForElement( | 681 ConstructorResult constructorResultForElement( |
| 684 Node node, String name, Element element, | 682 Node node, String name, Element element, |
| 685 {PrefixElement prefix}) { | 683 {PrefixElement prefix}) { |
| 686 element = Elements.unwrap(element, reporter, node); | 684 element = Elements.unwrap(element, reporter, node); |
| 687 if (element == null) { | 685 if (element == null) { |
| 688 return reportAndCreateErroneousConstructorElement( | 686 return reportAndCreateErroneousConstructorElement( |
| 689 node, | 687 node, |
| 690 ConstructorResultKind.INVALID_TYPE, null, | 688 ConstructorResultKind.INVALID_TYPE, null, |
| 691 resolver.enclosingElement, name, | 689 resolver.enclosingElement, name, |
| 692 MessageKind.CANNOT_RESOLVE, | 690 MessageKind.CANNOT_RESOLVE, |
| 693 {'name': name}); | 691 {'name': name}); |
| 692 } else if (element.isAmbiguous) { |
| 693 AmbiguousElement ambiguous = element; |
| 694 return reportAndCreateErroneousConstructorElement( |
| 695 node, |
| 696 ConstructorResultKind.INVALID_TYPE, null, |
| 697 resolver.enclosingElement, name, |
| 698 ambiguous.messageKind, |
| 699 ambiguous.messageArguments, |
| 700 infos: ambiguous.computeInfos(resolver.enclosingElement, reporter)); |
| 694 } else if (element.isMalformed) { | 701 } else if (element.isMalformed) { |
| 695 return constructorResultForErroneous(node, element); | 702 return constructorResultForErroneous(node, element); |
| 696 } else if (element.isClass) { | 703 } else if (element.isClass) { |
| 697 ClassElement cls = element; | 704 ClassElement cls = element; |
| 698 cls.computeType(resolution); | 705 cls.computeType(resolution); |
| 699 return constructorResultForType(node, cls.rawType, prefix: prefix); | 706 return constructorResultForType(node, cls.rawType, prefix: prefix); |
| 700 } else if (element.isPrefix) { | 707 } else if (element.isPrefix) { |
| 701 return new ConstructorResult.forPrefix(element); | 708 return new ConstructorResult.forPrefix(element); |
| 702 } else if (element.isTypedef) { | 709 } else if (element.isTypedef) { |
| 703 TypedefElement typdef = element; | 710 TypedefElement typdef = element; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 // constructors. | 867 // constructors. |
| 861 return null; | 868 return null; |
| 862 } | 869 } |
| 863 // TODO(johnniwinther): Use [Name] for lookup. | 870 // TODO(johnniwinther): Use [Name] for lookup. |
| 864 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 871 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 865 if (constructor != null) { | 872 if (constructor != null) { |
| 866 constructor = constructor.declaration; | 873 constructor = constructor.declaration; |
| 867 } | 874 } |
| 868 return constructor; | 875 return constructor; |
| 869 } | 876 } |
| OLD | NEW |