| 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 '../compiler.dart' show | 8 import '../compiler.dart' show |
| 9 Compiler; | 9 Compiler; |
| 10 import '../constants/constructors.dart' show | 10 import '../constants/constructors.dart' show |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 return result; | 539 return result; |
| 540 } | 540 } |
| 541 | 541 |
| 542 // Find the unnamed constructor if the reference resolved to a | 542 // Find the unnamed constructor if the reference resolved to a |
| 543 // class. | 543 // class. |
| 544 if (result.type != null) { | 544 if (result.type != null) { |
| 545 // The unnamed constructor may not exist, so [e] may become unresolved. | 545 // The unnamed constructor may not exist, so [e] may become unresolved. |
| 546 result = resolveConstructor(result.type, diagnosticNode, ''); | 546 result = resolveConstructor(result.type, diagnosticNode, ''); |
| 547 } else { | 547 } else { |
| 548 Element element = result.element; | 548 Element element = result.element; |
| 549 if (element.isErroneous) { | 549 if (element.isMalformed) { |
| 550 result = constructorResultForErroneous(diagnosticNode, element); | 550 result = constructorResultForErroneous(diagnosticNode, element); |
| 551 } else { | 551 } else { |
| 552 result = reportAndCreateErroneousConstructorElement( | 552 result = reportAndCreateErroneousConstructorElement( |
| 553 diagnosticNode, | 553 diagnosticNode, |
| 554 ConstructorResultKind.INVALID_TYPE, null, | 554 ConstructorResultKind.INVALID_TYPE, null, |
| 555 element, element.name, | 555 element, element.name, |
| 556 MessageKind.NOT_A_TYPE, {'node': diagnosticNode}); | 556 MessageKind.NOT_A_TYPE, {'node': diagnosticNode}); |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 resolver.registry.setType(expression, result.type); | 559 resolver.registry.setType(expression, result.type); |
| 560 return result; | 560 return result; |
| 561 } | 561 } |
| 562 | 562 |
| 563 ConstructorResult visitTypeAnnotation(TypeAnnotation node) { | 563 ConstructorResult visitTypeAnnotation(TypeAnnotation node) { |
| 564 // This is not really resolving a type-annotation, but the name of the | 564 // This is not really resolving a type-annotation, but the name of the |
| 565 // constructor. Therefore we allow deferred types. | 565 // constructor. Therefore we allow deferred types. |
| 566 DartType type = resolver.resolveTypeAnnotation( | 566 DartType type = resolver.resolveTypeAnnotation( |
| 567 node, | 567 node, |
| 568 malformedIsError: inConstContext, | 568 malformedIsError: inConstContext, |
| 569 deferredIsMalformed: false); | 569 deferredIsMalformed: false); |
| 570 registry.registerRequiredType(type, resolver.enclosingElement); | 570 registry.registerRequiredType(type, resolver.enclosingElement); |
| 571 return constructorResultForType(node, type); | 571 return constructorResultForType(node, type); |
| 572 } | 572 } |
| 573 | 573 |
| 574 ConstructorResult visitSend(Send node) { | 574 ConstructorResult visitSend(Send node) { |
| 575 ConstructorResult receiver = visit(node.receiver); | 575 ConstructorResult receiver = visit(node.receiver); |
| 576 assert(invariant(node.receiver, receiver != null, | 576 assert(invariant(node.receiver, receiver != null, |
| 577 message: 'No result returned for $node.receiver.')); | 577 message: 'No result returned for $node.receiver.')); |
| 578 if (receiver.kind != null) { | 578 if (receiver.kind != null) { |
| 579 assert(invariant(node, receiver.element.isErroneous, | 579 assert(invariant(node, receiver.element.isMalformed, |
| 580 message: "Unexpected prefix result: $receiver.")); | 580 message: "Unexpected prefix result: $receiver.")); |
| 581 // We have already found an error. | 581 // We have already found an error. |
| 582 return receiver; | 582 return receiver; |
| 583 } | 583 } |
| 584 | 584 |
| 585 Identifier name = node.selector.asIdentifier(); | 585 Identifier name = node.selector.asIdentifier(); |
| 586 if (name == null) { | 586 if (name == null) { |
| 587 reporter.internalError(node.selector, 'unexpected node'); | 587 reporter.internalError(node.selector, 'unexpected node'); |
| 588 } | 588 } |
| 589 | 589 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 ConstructorResult constructorResultForElement( | 627 ConstructorResult constructorResultForElement( |
| 628 Node node, String name, Element element) { | 628 Node node, String name, Element element) { |
| 629 element = Elements.unwrap(element, reporter, node); | 629 element = Elements.unwrap(element, reporter, node); |
| 630 if (element == null) { | 630 if (element == null) { |
| 631 return reportAndCreateErroneousConstructorElement( | 631 return reportAndCreateErroneousConstructorElement( |
| 632 node, | 632 node, |
| 633 ConstructorResultKind.INVALID_TYPE, null, | 633 ConstructorResultKind.INVALID_TYPE, null, |
| 634 resolver.enclosingElement, name, | 634 resolver.enclosingElement, name, |
| 635 MessageKind.CANNOT_RESOLVE, | 635 MessageKind.CANNOT_RESOLVE, |
| 636 {'name': name}); | 636 {'name': name}); |
| 637 } else if (element.isErroneous) { | 637 } else if (element.isMalformed) { |
| 638 return constructorResultForErroneous(node, element); | 638 return constructorResultForErroneous(node, element); |
| 639 } else if (element.isClass) { | 639 } else if (element.isClass) { |
| 640 ClassElement cls = element; | 640 ClassElement cls = element; |
| 641 cls.computeType(resolution); | 641 cls.computeType(resolution); |
| 642 return constructorResultForType(node, cls.rawType); | 642 return constructorResultForType(node, cls.rawType); |
| 643 } else if (element.isPrefix) { | 643 } else if (element.isPrefix) { |
| 644 return new ConstructorResult.forElement(element); | 644 return new ConstructorResult.forElement(element); |
| 645 } else if (element.isTypedef) { | 645 } else if (element.isTypedef) { |
| 646 TypedefElement typdef = element; | 646 TypedefElement typdef = element; |
| 647 typdef.ensureResolved(resolution); | 647 typdef.ensureResolved(resolution); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 // constructors. | 754 // constructors. |
| 755 return null; | 755 return null; |
| 756 } | 756 } |
| 757 // TODO(johnniwinther): Use [Name] for lookup. | 757 // TODO(johnniwinther): Use [Name] for lookup. |
| 758 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 758 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 759 if (constructor != null) { | 759 if (constructor != null) { |
| 760 constructor = constructor.declaration; | 760 constructor = constructor.declaration; |
| 761 } | 761 } |
| 762 return constructor; | 762 return constructor; |
| 763 } | 763 } |
| OLD | NEW |