| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 abstract class TreeElements { | 5 abstract class TreeElements { |
| 6 Element operator[](Node node); | 6 Element operator[](Node node); |
| 7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
| 8 DartType getType(TypeAnnotation annotation); | 8 DartType getType(TypeAnnotation annotation); |
| 9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
| 10 } | 10 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // A synthetic constructor does not have a node. | 82 // A synthetic constructor does not have a node. |
| 83 if (node === null) return null; | 83 if (node === null) return null; |
| 84 if (node.initializers === null) return null; | 84 if (node.initializers === null) return null; |
| 85 Link<Node> initializers = node.initializers.nodes; | 85 Link<Node> initializers = node.initializers.nodes; |
| 86 if (!initializers.isEmpty() && | 86 if (!initializers.isEmpty() && |
| 87 Initializers.isConstructorRedirect(initializers.head)) { | 87 Initializers.isConstructorRedirect(initializers.head)) { |
| 88 final ClassElement classElement = constructor.getEnclosingClass(); | 88 final ClassElement classElement = constructor.getEnclosingClass(); |
| 89 final SourceString constructorName = | 89 final SourceString constructorName = |
| 90 getConstructorName(initializers.head); | 90 getConstructorName(initializers.head); |
| 91 final SourceString className = classElement.name; | 91 final SourceString className = classElement.name; |
| 92 return classElement.lookupConstructor(className, constructorName); | 92 return classElement.lookupConstructor(constructor.getLibrary(), |
| 93 className, |
| 94 constructorName); |
| 93 } | 95 } |
| 94 return null; | 96 return null; |
| 95 } | 97 } |
| 96 | 98 |
| 97 void resolveRedirectingConstructor(InitializerResolver resolver, | 99 void resolveRedirectingConstructor(InitializerResolver resolver, |
| 98 Node node, | 100 Node node, |
| 99 FunctionElement constructor, | 101 FunctionElement constructor, |
| 100 FunctionElement redirection) { | 102 FunctionElement redirection) { |
| 101 Set<FunctionElement> seen = new Set<FunctionElement>(); | 103 Set<FunctionElement> seen = new Set<FunctionElement>(); |
| 102 seen.add(constructor); | 104 seen.add(constructor); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // of the interface. | 180 // of the interface. |
| 179 SourceString name; | 181 SourceString name; |
| 180 if (defaultClass.implementsInterface(intrface)) { | 182 if (defaultClass.implementsInterface(intrface)) { |
| 181 // TODO(ahe): Don't use string replacement here. | 183 // TODO(ahe): Don't use string replacement here. |
| 182 name = new SourceString(constructor.name.slowToString().replaceFirst( | 184 name = new SourceString(constructor.name.slowToString().replaceFirst( |
| 183 intrface.name.slowToString(), | 185 intrface.name.slowToString(), |
| 184 defaultClass.name.slowToString())); | 186 defaultClass.name.slowToString())); |
| 185 } else { | 187 } else { |
| 186 name = constructor.name; | 188 name = constructor.name; |
| 187 } | 189 } |
| 188 constructor.defaultImplementation = defaultClass.lookupConstructor(name); | 190 constructor.defaultImplementation = |
| 191 defaultClass.lookupConstructor(defaultClass.getLibrary(), |
| 192 name); |
| 189 | 193 |
| 190 if (constructor.defaultImplementation === null) { | 194 if (constructor.defaultImplementation === null) { |
| 191 // We failed to find a constructor named either | 195 // We failed to find a constructor named either |
| 192 // "MyInterface.name" or "MyClass.name". | 196 // "MyInterface.name" or "MyClass.name". |
| 193 error(node, | 197 error(node, |
| 194 MessageKind.CANNOT_FIND_CONSTRUCTOR2, | 198 MessageKind.CANNOT_FIND_CONSTRUCTOR2, |
| 195 [name, defaultClass.name]); | 199 [name, defaultClass.name]); |
| 196 } | 200 } |
| 197 } | 201 } |
| 198 | 202 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 if (lookupTarget === visitor.compiler.objectClass) { | 589 if (lookupTarget === visitor.compiler.objectClass) { |
| 586 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); | 590 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); |
| 587 } else { | 591 } else { |
| 588 lookupTarget = lookupTarget.supertype.element; | 592 lookupTarget = lookupTarget.supertype.element; |
| 589 } | 593 } |
| 590 } | 594 } |
| 591 | 595 |
| 592 // Lookup constructor and try to match it to the selector. | 596 // Lookup constructor and try to match it to the selector. |
| 593 ResolverTask resolver = visitor.compiler.resolver; | 597 ResolverTask resolver = visitor.compiler.resolver; |
| 594 final SourceString className = lookupTarget.name; | 598 final SourceString className = lookupTarget.name; |
| 595 result = lookupTarget.lookupConstructor(className, constructorName); | 599 result = |
| 600 lookupTarget.lookupConstructor(constructor.getLibrary(), |
| 601 className, |
| 602 constructorName); |
| 596 if (result === null || !result.isGenerativeConstructor()) { | 603 if (result === null || !result.isGenerativeConstructor()) { |
| 597 String classNameString = className.slowToString(); | 604 String classNameString = className.slowToString(); |
| 598 String constructorNameString = constructorName.slowToString(); | 605 String constructorNameString = constructorName.slowToString(); |
| 599 String name = (constructorName === const SourceString('')) | 606 String name = (constructorName === const SourceString('')) |
| 600 ? classNameString | 607 ? classNameString |
| 601 : "$classNameString.$constructorNameString"; | 608 : "$classNameString.$constructorNameString"; |
| 602 MessageKind kind = isImplicitSuperCall | 609 MessageKind kind = isImplicitSuperCall |
| 603 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT | 610 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT |
| 604 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; | 611 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; |
| 605 error(diagnosticNode, kind, [name]); | 612 error(diagnosticNode, kind, [name]); |
| (...skipping 1983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2589 compiler.reportWarning(diagnosticNode, warning); | 2596 compiler.reportWarning(diagnosticNode, warning); |
| 2590 return new ErroneousFunctionElement(warning.message, targetName, | 2597 return new ErroneousFunctionElement(warning.message, targetName, |
| 2591 enclosing); | 2598 enclosing); |
| 2592 } | 2599 } |
| 2593 } | 2600 } |
| 2594 | 2601 |
| 2595 FunctionElement lookupConstructor(ClassElement cls, | 2602 FunctionElement lookupConstructor(ClassElement cls, |
| 2596 Node diagnosticNode, | 2603 Node diagnosticNode, |
| 2597 SourceString constructorName) { | 2604 SourceString constructorName) { |
| 2598 cls.ensureResolved(compiler); | 2605 cls.ensureResolved(compiler); |
| 2599 Element result = cls.lookupConstructor(cls.name, constructorName); | 2606 Element result = |
| 2607 cls.lookupConstructor(resolver.enclosingElement.getLibrary(), |
| 2608 cls.name, |
| 2609 constructorName); |
| 2600 if (result === null) { | 2610 if (result === null) { |
| 2601 String fullConstructorName = cls.name.slowToString(); | 2611 String fullConstructorName = cls.name.slowToString(); |
| 2602 if (constructorName !== const SourceString('')) { | 2612 if (constructorName !== const SourceString('')) { |
| 2603 fullConstructorName = '$fullConstructorName' | 2613 fullConstructorName = '$fullConstructorName' |
| 2604 '.${constructorName.slowToString()}'; | 2614 '.${constructorName.slowToString()}'; |
| 2605 } | 2615 } |
| 2606 return failOrReturnErroneousElement(cls, diagnosticNode, | 2616 return failOrReturnErroneousElement(cls, diagnosticNode, |
| 2607 new SourceString(fullConstructorName), | 2617 new SourceString(fullConstructorName), |
| 2608 MessageKind.CANNOT_FIND_CONSTRUCTOR, | 2618 MessageKind.CANNOT_FIND_CONSTRUCTOR, |
| 2609 [fullConstructorName]); | 2619 [fullConstructorName]); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2817 | 2827 |
| 2818 Element localLookup(SourceString name) => library.find(name); | 2828 Element localLookup(SourceString name) => library.find(name); |
| 2819 Element lookup(SourceString name) => localLookup(name); | 2829 Element lookup(SourceString name) => localLookup(name); |
| 2820 Element lexicalLookup(SourceString name) => localLookup(name); | 2830 Element lexicalLookup(SourceString name) => localLookup(name); |
| 2821 | 2831 |
| 2822 Element add(Element newElement) { | 2832 Element add(Element newElement) { |
| 2823 throw "Cannot add an element in the top scope"; | 2833 throw "Cannot add an element in the top scope"; |
| 2824 } | 2834 } |
| 2825 String toString() => '$element'; | 2835 String toString() => '$element'; |
| 2826 } | 2836 } |
| OLD | NEW |