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 Resolution; | 8 import '../common/resolution.dart' show Resolution; |
9 import '../constants/constructors.dart' | 9 import '../constants/constructors.dart' |
10 show | 10 show |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 reporter.reportWarningMessage( | 561 reporter.reportWarningMessage( |
562 diagnosticNode, MessageKind.ABSTRACT_CLASS_INSTANTIATION); | 562 diagnosticNode, MessageKind.ABSTRACT_CLASS_INSTANTIATION); |
563 registry.registerFeature(Feature.ABSTRACT_CLASS_INSTANTIATION); | 563 registry.registerFeature(Feature.ABSTRACT_CLASS_INSTANTIATION); |
564 return new ConstructorResult( | 564 return new ConstructorResult( |
565 ConstructorResultKind.ABSTRACT, prefix, constructor, type); | 565 ConstructorResultKind.ABSTRACT, prefix, constructor, type); |
566 } else { | 566 } else { |
567 return new ConstructorResult( | 567 return new ConstructorResult( |
568 ConstructorResultKind.GENERATIVE, prefix, constructor, type); | 568 ConstructorResultKind.GENERATIVE, prefix, constructor, type); |
569 } | 569 } |
570 } else { | 570 } else { |
571 assert(invariant(diagnosticNode, constructor.isFactoryConstructor, | 571 assert(constructor.isFactoryConstructor, |
572 message: "Unexpected constructor $constructor.")); | 572 failedAt(diagnosticNode, "Unexpected constructor $constructor.")); |
573 return new ConstructorResult( | 573 return new ConstructorResult( |
574 ConstructorResultKind.FACTORY, prefix, constructor, type); | 574 ConstructorResultKind.FACTORY, prefix, constructor, type); |
575 } | 575 } |
576 } | 576 } |
577 } | 577 } |
578 | 578 |
579 ConstructorResult visitNewExpression(NewExpression node) { | 579 ConstructorResult visitNewExpression(NewExpression node) { |
580 Node selector = node.send.selector; | 580 Node selector = node.send.selector; |
581 ConstructorResult result = visit(selector); | 581 ConstructorResult result = visit(selector); |
582 assert(invariant(selector, result != null, | 582 assert(result != null, |
583 message: 'No result returned for $selector.')); | 583 failedAt(selector, 'No result returned for $selector.')); |
584 return finishConstructorReference(result, node.send.selector, node); | 584 return finishConstructorReference(result, node.send.selector, node); |
585 } | 585 } |
586 | 586 |
587 /// Finishes resolution of a constructor reference and records the | 587 /// Finishes resolution of a constructor reference and records the |
588 /// type of the constructed instance on [expression]. | 588 /// type of the constructed instance on [expression]. |
589 ConstructorResult finishConstructorReference( | 589 ConstructorResult finishConstructorReference( |
590 ConstructorResult result, Node diagnosticNode, Node expression) { | 590 ConstructorResult result, Node diagnosticNode, Node expression) { |
591 assert(invariant(diagnosticNode, result != null, | 591 assert(result != null, |
592 message: 'No result returned for $diagnosticNode.')); | 592 failedAt(diagnosticNode, 'No result returned for $diagnosticNode.')); |
593 | 593 |
594 if (result.kind != null) { | 594 if (result.kind != null) { |
595 resolver.registry.setType(expression, result.type); | 595 resolver.registry.setType(expression, result.type); |
596 return result; | 596 return result; |
597 } | 597 } |
598 | 598 |
599 // Find the unnamed constructor if the reference resolved to a | 599 // Find the unnamed constructor if the reference resolved to a |
600 // class. | 600 // class. |
601 if (result.type != null) { | 601 if (result.type != null) { |
602 // The unnamed constructor may not exist, so [e] may become unresolved. | 602 // The unnamed constructor may not exist, so [e] may become unresolved. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 Element element = lookupInScope(reporter, send, resolver.scope, name); | 635 Element element = lookupInScope(reporter, send, resolver.scope, name); |
636 if (element != null && element.isPrefix) { | 636 if (element != null && element.isPrefix) { |
637 prefix = element; | 637 prefix = element; |
638 } | 638 } |
639 } | 639 } |
640 return constructorResultForType(node, type, prefix: prefix); | 640 return constructorResultForType(node, type, prefix: prefix); |
641 } | 641 } |
642 | 642 |
643 ConstructorResult visitSend(Send node) { | 643 ConstructorResult visitSend(Send node) { |
644 ConstructorResult receiver = visit(node.receiver); | 644 ConstructorResult receiver = visit(node.receiver); |
645 assert(invariant(node.receiver, receiver != null, | 645 assert(receiver != null, |
646 message: 'No result returned for $node.receiver.')); | 646 failedAt(node.receiver, 'No result returned for $node.receiver.')); |
647 if (receiver.kind != null) { | 647 if (receiver.kind != null) { |
648 assert(invariant(node, receiver.element.isMalformed, | 648 assert(receiver.element.isMalformed, |
649 message: "Unexpected prefix result: $receiver.")); | 649 failedAt(node, "Unexpected prefix result: $receiver.")); |
650 // We have already found an error. | 650 // We have already found an error. |
651 return receiver; | 651 return receiver; |
652 } | 652 } |
653 | 653 |
654 Identifier name = node.selector.asIdentifier(); | 654 Identifier name = node.selector.asIdentifier(); |
655 if (name == null) { | 655 if (name == null) { |
656 reporter.internalError(node.selector, 'unexpected node'); | 656 reporter.internalError(node.selector, 'unexpected node'); |
657 } | 657 } |
658 | 658 |
659 if (receiver.type != null) { | 659 if (receiver.type != null) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 // constructors. | 886 // constructors. |
887 return null; | 887 return null; |
888 } | 888 } |
889 // TODO(johnniwinther): Use [Name] for lookup. | 889 // TODO(johnniwinther): Use [Name] for lookup. |
890 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 890 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
891 if (constructor != null) { | 891 if (constructor != null) { |
892 constructor = constructor.declaration; | 892 constructor = constructor.declaration; |
893 } | 893 } |
894 return constructor; | 894 return constructor; |
895 } | 895 } |
OLD | NEW |