| 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 import '../compiler.dart' show | 6 import '../compiler.dart' show |
| 7 Compiler; | 7 Compiler; |
| 8 import '../constants/constructors.dart' show | 8 import '../constants/constructors.dart' show |
| 9 GenerativeConstantConstructor, | 9 GenerativeConstantConstructor, |
| 10 RedirectingGenerativeConstantConstructor; | 10 RedirectingGenerativeConstantConstructor; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 ]); | 85 ]); |
| 86 isValidAsConstant = false; | 86 isValidAsConstant = false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void checkForDuplicateInitializers(FieldElementX field, Node init) { | 89 void checkForDuplicateInitializers(FieldElementX field, Node init) { |
| 90 // [field] can be null if it could not be resolved. | 90 // [field] can be null if it could not be resolved. |
| 91 if (field == null) return; | 91 if (field == null) return; |
| 92 if (initialized.containsKey(field)) { | 92 if (initialized.containsKey(field)) { |
| 93 reportDuplicateInitializerError(field, init, initialized[field]); | 93 reportDuplicateInitializerError(field, init, initialized[field]); |
| 94 } else if (field.isFinal) { | 94 } else if (field.isFinal) { |
| 95 field.parseNode(visitor.compiler); | 95 field.parseNode(visitor.resolution.parsing); |
| 96 Expression initializer = field.initializer; | 96 Expression initializer = field.initializer; |
| 97 if (initializer != null) { | 97 if (initializer != null) { |
| 98 reportDuplicateInitializerError(field, init, initializer); | 98 reportDuplicateInitializerError(field, init, initializer); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 initialized[field] = init; | 101 initialized[field] = init; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void resolveFieldInitializer(SendSet init) { | 104 void resolveFieldInitializer(SendSet init) { |
| 105 // init is of the form [this.]field = value. | 105 // init is of the form [this.]field = value. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 String fullConstructorName = Elements.constructorNameForDiagnostics( | 261 String fullConstructorName = Elements.constructorNameForDiagnostics( |
| 262 className, | 262 className, |
| 263 constructorSelector.name); | 263 constructorSelector.name); |
| 264 MessageKind kind = isImplicitSuperCall | 264 MessageKind kind = isImplicitSuperCall |
| 265 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT | 265 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT |
| 266 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; | 266 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; |
| 267 listener.reportErrorMessage( | 267 listener.reportErrorMessage( |
| 268 diagnosticNode, kind, {'constructorName': fullConstructorName}); | 268 diagnosticNode, kind, {'constructorName': fullConstructorName}); |
| 269 isValidAsConstant = false; | 269 isValidAsConstant = false; |
| 270 } else { | 270 } else { |
| 271 lookedupConstructor.computeType(visitor.compiler); | 271 lookedupConstructor.computeType(visitor.resolution); |
| 272 if (!call.signatureApplies(lookedupConstructor.functionSignature)) { | 272 if (!call.signatureApplies(lookedupConstructor.functionSignature)) { |
| 273 MessageKind kind = isImplicitSuperCall | 273 MessageKind kind = isImplicitSuperCall |
| 274 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT | 274 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT |
| 275 : MessageKind.NO_MATCHING_CONSTRUCTOR; | 275 : MessageKind.NO_MATCHING_CONSTRUCTOR; |
| 276 listener.reportErrorMessage(diagnosticNode, kind); | 276 listener.reportErrorMessage(diagnosticNode, kind); |
| 277 isValidAsConstant = false; | 277 isValidAsConstant = false; |
| 278 } else if (constructor.isConst | 278 } else if (constructor.isConst |
| 279 && !lookedupConstructor.isConst) { | 279 && !lookedupConstructor.isConst) { |
| 280 MessageKind kind = isImplicitSuperCall | 280 MessageKind kind = isImplicitSuperCall |
| 281 ? MessageKind.CONST_CALLS_NON_CONST_FOR_IMPLICIT | 281 ? MessageKind.CONST_CALLS_NON_CONST_FOR_IMPLICIT |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 type = new MalformedType(error, null); | 474 type = new MalformedType(error, null); |
| 475 } | 475 } |
| 476 return new ConstructorResult(resultKind, error, type); | 476 return new ConstructorResult(resultKind, error, type); |
| 477 } | 477 } |
| 478 | 478 |
| 479 ConstructorResult resolveConstructor( | 479 ConstructorResult resolveConstructor( |
| 480 InterfaceType type, | 480 InterfaceType type, |
| 481 Node diagnosticNode, | 481 Node diagnosticNode, |
| 482 String constructorName) { | 482 String constructorName) { |
| 483 ClassElement cls = type.element; | 483 ClassElement cls = type.element; |
| 484 cls.ensureResolved(compiler); | 484 cls.ensureResolved(resolution); |
| 485 ConstructorElement constructor = findConstructor( | 485 ConstructorElement constructor = findConstructor( |
| 486 resolver.enclosingElement.library, cls, constructorName); | 486 resolver.enclosingElement.library, cls, constructorName); |
| 487 if (constructor == null) { | 487 if (constructor == null) { |
| 488 String fullConstructorName = | 488 String fullConstructorName = |
| 489 Elements.constructorNameForDiagnostics(cls.name, constructorName); | 489 Elements.constructorNameForDiagnostics(cls.name, constructorName); |
| 490 return reportAndCreateErroneousConstructorElement( | 490 return reportAndCreateErroneousConstructorElement( |
| 491 diagnosticNode, | 491 diagnosticNode, |
| 492 ConstructorResultKind.UNRESOLVED_CONSTRUCTOR, type, | 492 ConstructorResultKind.UNRESOLVED_CONSTRUCTOR, type, |
| 493 cls, constructorName, | 493 cls, constructorName, |
| 494 MessageKind.CANNOT_FIND_CONSTRUCTOR, | 494 MessageKind.CANNOT_FIND_CONSTRUCTOR, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 return reportAndCreateErroneousConstructorElement( | 634 return reportAndCreateErroneousConstructorElement( |
| 635 node, | 635 node, |
| 636 ConstructorResultKind.INVALID_TYPE, null, | 636 ConstructorResultKind.INVALID_TYPE, null, |
| 637 resolver.enclosingElement, name, | 637 resolver.enclosingElement, name, |
| 638 MessageKind.CANNOT_RESOLVE, | 638 MessageKind.CANNOT_RESOLVE, |
| 639 {'name': name}); | 639 {'name': name}); |
| 640 } else if (element.isErroneous) { | 640 } else if (element.isErroneous) { |
| 641 return constructorResultForErroneous(node, element); | 641 return constructorResultForErroneous(node, element); |
| 642 } else if (element.isClass) { | 642 } else if (element.isClass) { |
| 643 ClassElement cls = element; | 643 ClassElement cls = element; |
| 644 cls.computeType(compiler); | 644 cls.computeType(resolution); |
| 645 return constructorResultForType(node, cls.rawType); | 645 return constructorResultForType(node, cls.rawType); |
| 646 } else if (element.isPrefix) { | 646 } else if (element.isPrefix) { |
| 647 return new ConstructorResult.forElement(element); | 647 return new ConstructorResult.forElement(element); |
| 648 } else if (element.isTypedef) { | 648 } else if (element.isTypedef) { |
| 649 TypedefElement typdef = element; | 649 TypedefElement typdef = element; |
| 650 typdef.ensureResolved(compiler); | 650 typdef.ensureResolved(resolution); |
| 651 return constructorResultForType(node, typdef.rawType); | 651 return constructorResultForType(node, typdef.rawType); |
| 652 } else if (element.isTypeVariable) { | 652 } else if (element.isTypeVariable) { |
| 653 TypeVariableElement typeVariableElement = element; | 653 TypeVariableElement typeVariableElement = element; |
| 654 return constructorResultForType(node, typeVariableElement.type); | 654 return constructorResultForType(node, typeVariableElement.type); |
| 655 } else { | 655 } else { |
| 656 return reportAndCreateErroneousConstructorElement( | 656 return reportAndCreateErroneousConstructorElement( |
| 657 node, | 657 node, |
| 658 ConstructorResultKind.INVALID_TYPE, null, | 658 ConstructorResultKind.INVALID_TYPE, null, |
| 659 resolver.enclosingElement, name, | 659 resolver.enclosingElement, name, |
| 660 MessageKind.NOT_A_TYPE, {'node': name}); | 660 MessageKind.NOT_A_TYPE, {'node': name}); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 // constructors. | 757 // constructors. |
| 758 return null; | 758 return null; |
| 759 } | 759 } |
| 760 // TODO(johnniwinther): Use [Name] for lookup. | 760 // TODO(johnniwinther): Use [Name] for lookup. |
| 761 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 761 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 762 if (constructor != null) { | 762 if (constructor != null) { |
| 763 constructor = constructor.declaration; | 763 constructor = constructor.declaration; |
| 764 } | 764 } |
| 765 return constructor; | 765 return constructor; |
| 766 } | 766 } |
| OLD | NEW |