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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 return resolveParameter(element); | 82 return resolveParameter(element); |
| 83 } | 83 } |
| 84 | 84 |
| 85 compiler.unimplemented("resolve($element)", | 85 compiler.unimplemented("resolve($element)", |
| 86 node: element.parseNode(compiler)); | 86 node: element.parseNode(compiler)); |
| 87 }); | 87 }); |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool isNamedConstructor(Send node) => node.receiver !== null; | 90 bool isNamedConstructor(Send node) => node.receiver !== null; |
| 91 | 91 |
| 92 SourceString getConstructorName(Send node) { | 92 SourceString getConstructorName(Send node, SourceString className) { |
|
kasperl
2012/10/15 07:26:38
Maybe this helper could give you the selector inst
aam-me
2012/10/15 12:07:52
Done.
| |
| 93 return node.selector.asIdentifier().source; | 93 if (!isNamedConstructor(node)) { |
| 94 return const SourceString(""); | |
| 95 } else { | |
| 96 SourceString constructorName = node.selector.asIdentifier().source; | |
| 97 if (constructorName.slowToString() != className.slowToString()) { | |
| 98 return constructorName; | |
| 99 } else { | |
| 100 return const SourceString(""); | |
| 101 } | |
| 102 } | |
| 94 } | 103 } |
| 95 | 104 |
| 96 String constructorNameForDiagnostics(SourceString className, | 105 String constructorNameForDiagnostics(SourceString className, |
| 97 SourceString constructorName) { | 106 SourceString constructorName) { |
| 98 String classNameString = className.slowToString(); | 107 String classNameString = className.slowToString(); |
| 99 String constructorNameString = constructorName.slowToString(); | 108 String constructorNameString = constructorName.slowToString(); |
| 100 return (constructorName === const SourceString('')) | 109 return (constructorName === const SourceString('')) |
| 101 ? classNameString | 110 ? classNameString |
| 102 : "$classNameString.$constructorNameString"; | 111 : "$classNameString.$constructorNameString"; |
| 103 } | 112 } |
| 104 | 113 |
| 105 FunctionElement resolveConstructorRedirection(InitializerResolver resolver, | 114 FunctionElement resolveConstructorRedirection(InitializerResolver resolver, |
| 106 FunctionElement constructor) { | 115 FunctionElement constructor) { |
| 107 if (constructor.isPatched) { | 116 if (constructor.isPatched) { |
| 108 checkMatchingPatchSignatures(constructor, constructor.patch); | 117 checkMatchingPatchSignatures(constructor, constructor.patch); |
| 109 constructor = constructor.patch; | 118 constructor = constructor.patch; |
| 110 } | 119 } |
| 111 FunctionExpression node = constructor.parseNode(compiler); | 120 FunctionExpression node = constructor.parseNode(compiler); |
| 112 | 121 |
| 113 // A synthetic constructor does not have a node. | 122 // A synthetic constructor does not have a node. |
| 114 if (node === null) return null; | 123 if (node === null) return null; |
| 115 if (node.initializers === null) return null; | 124 if (node.initializers === null) return null; |
| 116 Link<Node> initializers = node.initializers.nodes; | 125 Link<Node> initializers = node.initializers.nodes; |
| 117 if (!initializers.isEmpty() && | 126 if (!initializers.isEmpty() && |
| 118 Initializers.isConstructorRedirect(initializers.head)) { | 127 Initializers.isConstructorRedirect(initializers.head)) { |
| 119 final ClassElement classElement = constructor.getEnclosingClass(); | 128 final ClassElement classElement = constructor.getEnclosingClass(); |
| 129 SourceString constructorName = getConstructorName(initializers.head, class Element.name); | |
|
kasperl
2012/10/15 07:26:38
Long line.
aam-me
2012/10/15 12:07:52
Done.
| |
| 120 Selector selector; | 130 Selector selector; |
| 121 if (isNamedConstructor(initializers.head)) { | 131 if (constructorName != const SourceString("")) { |
| 122 SourceString constructorName = getConstructorName(initializers.head); | |
| 123 selector = new Selector.callConstructor( | 132 selector = new Selector.callConstructor( |
| 124 constructorName, | 133 constructorName, |
| 125 resolver.visitor.enclosingElement.getLibrary()); | 134 resolver.visitor.enclosingElement.getLibrary()); |
| 126 } else { | 135 } else { |
| 127 selector = new Selector.callDefaultConstructor( | 136 selector = new Selector.callDefaultConstructor( |
| 128 resolver.visitor.enclosingElement.getLibrary()); | 137 resolver.visitor.enclosingElement.getLibrary()); |
| 129 } | 138 } |
| 130 return classElement.lookupConstructor(selector); | 139 return classElement.lookupConstructor(selector); |
| 131 } | 140 } |
| 132 return null; | 141 return null; |
| 133 } | 142 } |
| 134 | 143 |
| 135 void resolveRedirectingConstructor(InitializerResolver resolver, | 144 void resolveRedirectingConstructor(InitializerResolver resolver, |
| 136 Node node, | 145 Node node, |
| 137 FunctionElement constructor, | 146 FunctionElement constructor, |
| 138 FunctionElement redirection) { | 147 FunctionElement redirection) { |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 visitor.resolveArguments(call.argumentsNode); | 747 visitor.resolveArguments(call.argumentsNode); |
| 739 }); | 748 }); |
| 740 Selector selector = visitor.mapping.getSelector(call); | 749 Selector selector = visitor.mapping.getSelector(call); |
| 741 bool isSuperCall = Initializers.isSuperConstructorCall(call); | 750 bool isSuperCall = Initializers.isSuperConstructorCall(call); |
| 742 | 751 |
| 743 ClassElement lookupTarget = getSuperOrThisLookupTarget(constructor, | 752 ClassElement lookupTarget = getSuperOrThisLookupTarget(constructor, |
| 744 isSuperCall, | 753 isSuperCall, |
| 745 call); | 754 call); |
| 746 final SourceString className = lookupTarget.name; | 755 final SourceString className = lookupTarget.name; |
| 747 | 756 |
| 748 SourceString constructorName; | 757 SourceString constructorName = resolver.getConstructorName(call, className); |
| 749 Selector lookupSelector; | 758 Selector lookupSelector; |
| 750 if (resolver.isNamedConstructor(call)) { | 759 if (constructorName != const SourceString('')) { |
| 751 constructorName = resolver.getConstructorName(call); | |
| 752 lookupSelector = new Selector.callConstructor( | 760 lookupSelector = new Selector.callConstructor( |
| 753 constructorName, | 761 constructorName, |
| 754 visitor.enclosingElement.getLibrary()); | 762 visitor.enclosingElement.getLibrary()); |
| 755 } else { | 763 } else { |
| 756 constructorName = const SourceString(''); | |
| 757 lookupSelector = new Selector.callDefaultConstructor( | 764 lookupSelector = new Selector.callDefaultConstructor( |
| 758 visitor.enclosingElement.getLibrary()); | 765 visitor.enclosingElement.getLibrary()); |
| 759 } | 766 } |
| 760 | 767 |
| 761 FunctionElement lookedupConstructor = | 768 FunctionElement lookedupConstructor = |
| 762 lookupTarget.lookupConstructor(lookupSelector); | 769 lookupTarget.lookupConstructor(lookupSelector); |
| 763 | 770 |
| 764 final bool isImplicitSuperCall = false; | 771 final bool isImplicitSuperCall = false; |
| 765 verifyThatConstructorMatchesCall(lookedupConstructor, | 772 verifyThatConstructorMatchesCall(lookedupConstructor, |
| 766 selector, | 773 selector, |
| 767 isImplicitSuperCall, | 774 isImplicitSuperCall, |
| 768 call, | 775 call, |
| 769 constructorName, | 776 constructorName, |
|
kasperl
2012/10/15 07:26:38
Isn't the constructor name always in lookupSelecto
aam-me
2012/10/15 12:07:52
Done.
| |
| 770 className); | 777 className); |
| 771 | 778 |
| 772 visitor.useElement(call, lookedupConstructor); | 779 visitor.useElement(call, lookedupConstructor); |
| 773 visitor.world.registerStaticUse(lookedupConstructor); | 780 visitor.world.registerStaticUse(lookedupConstructor); |
| 774 return lookedupConstructor; | 781 return lookedupConstructor; |
| 775 } | 782 } |
| 776 | 783 |
| 777 void resolveImplicitSuperConstructorSend(FunctionElement constructor, | 784 void resolveImplicitSuperConstructorSend(FunctionElement constructor, |
| 778 FunctionExpression functionNode) { | 785 FunctionExpression functionNode) { |
| 779 // If the class has a super resolve the implicit super call. | 786 // If the class has a super resolve the implicit super call. |
| (...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3227 return result; | 3234 return result; |
| 3228 } | 3235 } |
| 3229 Element lookup(SourceString name) => localLookup(name); | 3236 Element lookup(SourceString name) => localLookup(name); |
| 3230 Element lexicalLookup(SourceString name) => localLookup(name); | 3237 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3231 | 3238 |
| 3232 Element add(Element newElement) { | 3239 Element add(Element newElement) { |
| 3233 throw "Cannot add an element in a patch library scope"; | 3240 throw "Cannot add an element in a patch library scope"; |
| 3234 } | 3241 } |
| 3235 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3242 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3236 } | 3243 } |
| OLD | NEW |