Chromium Code Reviews| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 // A synthetic constructor does not have a node. | 98 // A synthetic constructor does not have a node. |
| 99 if (node === null) return null; | 99 if (node === null) return null; |
| 100 if (node.initializers === null) return null; | 100 if (node.initializers === null) return null; |
| 101 Link<Node> initializers = node.initializers.nodes; | 101 Link<Node> initializers = node.initializers.nodes; |
| 102 if (!initializers.isEmpty() && | 102 if (!initializers.isEmpty() && |
| 103 Initializers.isConstructorRedirect(initializers.head)) { | 103 Initializers.isConstructorRedirect(initializers.head)) { |
| 104 final ClassElement classElement = constructor.getEnclosingClass(); | 104 final ClassElement classElement = constructor.getEnclosingClass(); |
| 105 final SourceString constructorName = | 105 final SourceString constructorName = |
| 106 getConstructorName(initializers.head); | 106 getConstructorName(initializers.head); |
| 107 final SourceString className = classElement.name; | 107 final SourceString className = classElement.name; |
| 108 return classElement.lookupConstructor(className, constructorName); | 108 |
| 109 return classElement.lookupConstructor( | |
| 110 new Selector.callConstructor(className, | |
| 111 constructorName, | |
| 112 constructor.getLibrary())); | |
|
kasperl
2012/09/24 05:52:38
I'm a bit worried about getting the library from v
aam-me
2012/09/25 04:15:18
Having helper function in the resolver (ResolverVi
| |
| 109 } | 113 } |
| 110 return null; | 114 return null; |
| 111 } | 115 } |
| 112 | 116 |
| 113 void resolveRedirectingConstructor(InitializerResolver resolver, | 117 void resolveRedirectingConstructor(InitializerResolver resolver, |
| 114 Node node, | 118 Node node, |
| 115 FunctionElement constructor, | 119 FunctionElement constructor, |
| 116 FunctionElement redirection) { | 120 FunctionElement redirection) { |
| 117 Set<FunctionElement> seen = new Set<FunctionElement>(); | 121 Set<FunctionElement> seen = new Set<FunctionElement>(); |
| 118 seen.add(constructor); | 122 seen.add(constructor); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // of the interface. | 199 // of the interface. |
| 196 SourceString name; | 200 SourceString name; |
| 197 if (defaultClass.implementsInterface(intrface)) { | 201 if (defaultClass.implementsInterface(intrface)) { |
| 198 // TODO(ahe): Don't use string replacement here. | 202 // TODO(ahe): Don't use string replacement here. |
| 199 name = new SourceString(constructor.name.slowToString().replaceFirst( | 203 name = new SourceString(constructor.name.slowToString().replaceFirst( |
| 200 intrface.name.slowToString(), | 204 intrface.name.slowToString(), |
| 201 defaultClass.name.slowToString())); | 205 defaultClass.name.slowToString())); |
| 202 } else { | 206 } else { |
| 203 name = constructor.name; | 207 name = constructor.name; |
| 204 } | 208 } |
| 205 constructor.defaultImplementation = defaultClass.lookupConstructor(name); | 209 constructor.defaultImplementation = defaultClass.lookupConstructor( |
| 210 new Selector.callDefaultConstructor(name, | |
| 211 defaultClass.getLibrary())); | |
| 206 | 212 |
| 207 if (constructor.defaultImplementation === null) { | 213 if (constructor.defaultImplementation === null) { |
| 208 // We failed to find a constructor named either | 214 // We failed to find a constructor named either |
| 209 // "MyInterface.name" or "MyClass.name". | 215 // "MyInterface.name" or "MyClass.name". |
| 210 error(node, | 216 error(node, |
| 211 MessageKind.CANNOT_FIND_CONSTRUCTOR2, | 217 MessageKind.CANNOT_FIND_CONSTRUCTOR2, |
| 212 [name, defaultClass.name]); | 218 [name, defaultClass.name]); |
| 213 } | 219 } |
| 214 } | 220 } |
| 215 | 221 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 if (lookupTarget === visitor.compiler.objectClass) { | 608 if (lookupTarget === visitor.compiler.objectClass) { |
| 603 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); | 609 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); |
| 604 } else { | 610 } else { |
| 605 lookupTarget = lookupTarget.supertype.element; | 611 lookupTarget = lookupTarget.supertype.element; |
| 606 } | 612 } |
| 607 } | 613 } |
| 608 | 614 |
| 609 // Lookup constructor and try to match it to the selector. | 615 // Lookup constructor and try to match it to the selector. |
| 610 ResolverTask resolver = visitor.compiler.resolver; | 616 ResolverTask resolver = visitor.compiler.resolver; |
| 611 final SourceString className = lookupTarget.name; | 617 final SourceString className = lookupTarget.name; |
| 612 result = lookupTarget.lookupConstructor(className, constructorName); | 618 Selector lookupSelector = |
| 619 new Selector.callConstructor(className, | |
|
kasperl
2012/09/24 05:52:38
4 space indent.
| |
| 620 constructorName, | |
| 621 constructor.getLibrary()); | |
| 622 result = lookupTarget.lookupConstructor(lookupSelector); | |
| 613 if (result === null || !result.isGenerativeConstructor()) { | 623 if (result === null || !result.isGenerativeConstructor()) { |
| 614 String classNameString = className.slowToString(); | |
| 615 String constructorNameString = constructorName.slowToString(); | |
| 616 String name = (constructorName === const SourceString('')) | |
| 617 ? classNameString | |
| 618 : "$classNameString.$constructorNameString"; | |
| 619 MessageKind kind = isImplicitSuperCall | 624 MessageKind kind = isImplicitSuperCall |
| 620 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT | 625 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT |
| 621 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; | 626 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; |
| 622 error(diagnosticNode, kind, [name]); | 627 error(diagnosticNode, kind, [lookupSelector.name]); |
| 623 } else { | 628 } else { |
| 624 if (!selector.applies(result, visitor.compiler)) { | 629 if (!selector.applies(result, visitor.compiler)) { |
| 625 MessageKind kind = isImplicitSuperCall | 630 MessageKind kind = isImplicitSuperCall |
| 626 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT | 631 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT |
| 627 : MessageKind.NO_MATCHING_CONSTRUCTOR; | 632 : MessageKind.NO_MATCHING_CONSTRUCTOR; |
| 628 error(diagnosticNode, kind); | 633 error(diagnosticNode, kind); |
| 629 } | 634 } |
| 630 } | 635 } |
| 631 return result; | 636 return result; |
| 632 } | 637 } |
| (...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2640 return new ErroneousFunctionElement(kind, arguments, targetName, | 2645 return new ErroneousFunctionElement(kind, arguments, targetName, |
| 2641 enclosing); | 2646 enclosing); |
| 2642 } | 2647 } |
| 2643 } | 2648 } |
| 2644 | 2649 |
| 2645 // TODO(ngeoffray): method named lookup should not report errors. | 2650 // TODO(ngeoffray): method named lookup should not report errors. |
| 2646 FunctionElement lookupConstructor(ClassElement cls, | 2651 FunctionElement lookupConstructor(ClassElement cls, |
| 2647 Node diagnosticNode, | 2652 Node diagnosticNode, |
| 2648 SourceString constructorName) { | 2653 SourceString constructorName) { |
| 2649 cls.ensureResolved(compiler); | 2654 cls.ensureResolved(compiler); |
| 2650 Element result = cls.lookupConstructor(cls.name, constructorName); | 2655 Selector selector = |
| 2656 new Selector.callConstructor(cls.name, | |
| 2657 constructorName, | |
| 2658 resolver.enclosingElement.getLibrary()); | |
| 2659 Element result = cls.lookupConstructor(selector); | |
| 2651 if (result === null) { | 2660 if (result === null) { |
| 2652 String fullConstructorName = cls.name.slowToString(); | |
| 2653 if (constructorName !== const SourceString('')) { | |
| 2654 fullConstructorName = '$fullConstructorName' | |
| 2655 '.${constructorName.slowToString()}'; | |
| 2656 } | |
| 2657 return failOrReturnErroneousElement(cls, diagnosticNode, | 2661 return failOrReturnErroneousElement(cls, diagnosticNode, |
| 2658 new SourceString(fullConstructorName), | 2662 selector.name, |
|
kasperl
2012/09/24 05:52:38
So there are two places where you need the full na
| |
| 2659 MessageKind.CANNOT_FIND_CONSTRUCTOR, | 2663 MessageKind.CANNOT_FIND_CONSTRUCTOR, |
| 2660 [fullConstructorName]); | 2664 [selector.name.slowToString()]); |
| 2661 } else if (inConstContext && | 2665 } else if (inConstContext && |
| 2662 (result.modifiers == null || !result.modifiers.isConst())) { | 2666 (result.modifiers == null || !result.modifiers.isConst())) { |
| 2663 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 2667 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 2664 } | 2668 } |
| 2665 return result; | 2669 return result; |
| 2666 } | 2670 } |
| 2667 | 2671 |
| 2668 visitNewExpression(NewExpression node) { | 2672 visitNewExpression(NewExpression node) { |
| 2669 Node selector = node.send.selector; | 2673 Node selector = node.send.selector; |
| 2670 Element e = visit(selector); | 2674 Element e = visit(selector); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2871 | 2875 |
| 2872 Element localLookup(SourceString name) => library.find(name); | 2876 Element localLookup(SourceString name) => library.find(name); |
| 2873 Element lookup(SourceString name) => localLookup(name); | 2877 Element lookup(SourceString name) => localLookup(name); |
| 2874 Element lexicalLookup(SourceString name) => localLookup(name); | 2878 Element lexicalLookup(SourceString name) => localLookup(name); |
| 2875 | 2879 |
| 2876 Element add(Element newElement) { | 2880 Element add(Element newElement) { |
| 2877 throw "Cannot add an element in the top scope"; | 2881 throw "Cannot add an element in the top scope"; |
| 2878 } | 2882 } |
| 2879 String toString() => '$element'; | 2883 String toString() => '$element'; |
| 2880 } | 2884 } |
| OLD | NEW |