| 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 |
| 9 Feature; |
| 8 import '../compiler.dart' show | 10 import '../compiler.dart' show |
| 9 Compiler; | 11 Compiler; |
| 10 import '../constants/constructors.dart' show | 12 import '../constants/constructors.dart' show |
| 11 GenerativeConstantConstructor, | 13 GenerativeConstantConstructor, |
| 12 RedirectingGenerativeConstantConstructor; | 14 RedirectingGenerativeConstantConstructor; |
| 13 import '../constants/expressions.dart'; | 15 import '../constants/expressions.dart'; |
| 14 import '../dart_types.dart'; | 16 import '../dart_types.dart'; |
| 15 import '../elements/elements.dart'; | 17 import '../elements/elements.dart'; |
| 16 import '../elements/modelx.dart' show | 18 import '../elements/modelx.dart' show |
| 17 ConstructorElementX, | 19 ConstructorElementX, |
| 18 ErroneousConstructorElementX, | 20 ErroneousConstructorElementX, |
| 19 ErroneousElementX, | 21 ErroneousElementX, |
| 20 ErroneousFieldElementX, | 22 ErroneousFieldElementX, |
| 21 FieldElementX, | 23 FieldElementX, |
| 22 InitializingFormalElementX, | 24 InitializingFormalElementX, |
| 23 ParameterElementX; | 25 ParameterElementX; |
| 24 import '../tree/tree.dart'; | 26 import '../tree/tree.dart'; |
| 25 import '../util/util.dart' show | 27 import '../util/util.dart' show |
| 26 Link; | 28 Link; |
| 27 import '../universe/call_structure.dart' show | 29 import '../universe/call_structure.dart' show |
| 28 CallStructure; | 30 CallStructure; |
| 29 import '../universe/selector.dart' show | |
| 30 Selector; | |
| 31 import '../universe/use.dart' show | 31 import '../universe/use.dart' show |
| 32 StaticUse; | 32 StaticUse; |
| 33 | 33 |
| 34 import 'members.dart' show | 34 import 'members.dart' show |
| 35 lookupInScope, | 35 lookupInScope, |
| 36 ResolverVisitor; | 36 ResolverVisitor; |
| 37 import 'registry.dart' show | 37 import 'registry.dart' show |
| 38 ResolutionRegistry; | 38 ResolutionRegistry; |
| 39 import 'resolution_common.dart' show | 39 import 'resolution_common.dart' show |
| 40 CommonResolverVisitor; | 40 CommonResolverVisitor; |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 if (missingConstructor) { | 489 if (missingConstructor) { |
| 490 registry.registerThrowNoSuchMethod(); | 490 registry.registerFeature(Feature.THROW_NO_SUCH_METHOD); |
| 491 } else { | 491 } else { |
| 492 registry.registerThrowRuntimeError(); | 492 registry.registerFeature(Feature.THROW_RUNTIME_ERROR); |
| 493 } | 493 } |
| 494 if (isError || inConstContext) { | 494 if (isError || inConstContext) { |
| 495 reporter.reportErrorMessage( | 495 reporter.reportErrorMessage( |
| 496 diagnosticNode, kind, arguments); | 496 diagnosticNode, kind, arguments); |
| 497 } else { | 497 } else { |
| 498 reporter.reportWarningMessage( | 498 reporter.reportWarningMessage( |
| 499 diagnosticNode, kind, arguments); | 499 diagnosticNode, kind, arguments); |
| 500 } | 500 } |
| 501 ErroneousElement error = new ErroneousConstructorElementX( | 501 ErroneousElement error = new ErroneousConstructorElementX( |
| 502 kind, arguments, name, enclosing); | 502 kind, arguments, name, enclosing); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 527 } else if (inConstContext && !constructor.isConst) { | 527 } else if (inConstContext && !constructor.isConst) { |
| 528 reporter.reportErrorMessage( | 528 reporter.reportErrorMessage( |
| 529 diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 529 diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 530 return new ConstructorResult( | 530 return new ConstructorResult( |
| 531 ConstructorResultKind.NON_CONSTANT, constructor, type); | 531 ConstructorResultKind.NON_CONSTANT, constructor, type); |
| 532 } else { | 532 } else { |
| 533 if (constructor.isGenerativeConstructor) { | 533 if (constructor.isGenerativeConstructor) { |
| 534 if (cls.isAbstract) { | 534 if (cls.isAbstract) { |
| 535 reporter.reportWarningMessage( | 535 reporter.reportWarningMessage( |
| 536 diagnosticNode, MessageKind.ABSTRACT_CLASS_INSTANTIATION); | 536 diagnosticNode, MessageKind.ABSTRACT_CLASS_INSTANTIATION); |
| 537 registry.registerAbstractClassInstantiation(); | 537 registry.registerFeature(Feature.ABSTRACT_CLASS_INSTANTIATION); |
| 538 return new ConstructorResult( | 538 return new ConstructorResult( |
| 539 ConstructorResultKind.ABSTRACT, constructor, type); | 539 ConstructorResultKind.ABSTRACT, constructor, type); |
| 540 } else { | 540 } else { |
| 541 return new ConstructorResult( | 541 return new ConstructorResult( |
| 542 ConstructorResultKind.GENERATIVE, constructor, type); | 542 ConstructorResultKind.GENERATIVE, constructor, type); |
| 543 } | 543 } |
| 544 } else { | 544 } else { |
| 545 assert(invariant(diagnosticNode, constructor.isFactoryConstructor, | 545 assert(invariant(diagnosticNode, constructor.isFactoryConstructor, |
| 546 message: "Unexpected constructor $constructor.")); | 546 message: "Unexpected constructor $constructor.")); |
| 547 return new ConstructorResult( | 547 return new ConstructorResult( |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 } | 690 } |
| 691 } | 691 } |
| 692 | 692 |
| 693 ConstructorResult constructorResultForErroneous( | 693 ConstructorResult constructorResultForErroneous( |
| 694 Node node, Element error) { | 694 Node node, Element error) { |
| 695 if (error is! ErroneousElementX) { | 695 if (error is! ErroneousElementX) { |
| 696 // Parser error. The error has already been reported. | 696 // Parser error. The error has already been reported. |
| 697 error = new ErroneousConstructorElementX( | 697 error = new ErroneousConstructorElementX( |
| 698 MessageKind.NOT_A_TYPE, {'node': node}, | 698 MessageKind.NOT_A_TYPE, {'node': node}, |
| 699 error.name, error); | 699 error.name, error); |
| 700 registry.registerThrowRuntimeError(); | 700 registry.registerFeature(Feature.THROW_RUNTIME_ERROR); |
| 701 } | 701 } |
| 702 return new ConstructorResult( | 702 return new ConstructorResult( |
| 703 ConstructorResultKind.INVALID_TYPE, | 703 ConstructorResultKind.INVALID_TYPE, |
| 704 error, | 704 error, |
| 705 new MalformedType(error, null)); | 705 new MalformedType(error, null)); |
| 706 } | 706 } |
| 707 | 707 |
| 708 ConstructorResult constructorResultForType( | 708 ConstructorResult constructorResultForType( |
| 709 Node node, | 709 Node node, |
| 710 DartType type) { | 710 DartType type) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 // constructors. | 786 // constructors. |
| 787 return null; | 787 return null; |
| 788 } | 788 } |
| 789 // TODO(johnniwinther): Use [Name] for lookup. | 789 // TODO(johnniwinther): Use [Name] for lookup. |
| 790 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 790 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 791 if (constructor != null) { | 791 if (constructor != null) { |
| 792 constructor = constructor.declaration; | 792 constructor = constructor.declaration; |
| 793 } | 793 } |
| 794 return constructor; | 794 return constructor; |
| 795 } | 795 } |
| OLD | NEW |