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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 while (redirection !== null) { | 126 while (redirection !== null) { |
| 127 if (seen.contains(redirection)) { | 127 if (seen.contains(redirection)) { |
| 128 resolver.visitor.error(node, MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE); | 128 resolver.visitor.error(node, MessageKind.REDIRECTING_CONSTRUCTOR_CYCLE); |
| 129 return; | 129 return; |
| 130 } | 130 } |
| 131 seen.add(redirection); | 131 seen.add(redirection); |
| 132 redirection = resolveConstructorRedirection(redirection); | 132 redirection = resolveConstructorRedirection(redirection); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 void checkMatchingPatchParameters(FunctionElement origin, | |
| 137 Link<Element> originParameters, | |
| 138 Link<Element> patchParameters) { | |
| 139 while (!originParameters.isEmpty()) { | |
| 140 Element originParameter = originParameters.head; | |
| 141 Element patchParameter = patchParameters.head; | |
| 142 // Hack: Use unparser to test parameter equality. This only works because | |
| 143 // we are restricting patch uses and the approach cannot be used | |
|
Lasse Reichstein Nielsen
2012/10/04 07:51:21
How are we restricting it?
And isn't this incredib
Johnni Winther
2012/10/04 10:23:29
Restrictions: See the next comment.
Inefficient: Y
| |
| 144 // elsewhere. | |
| 145 String originParameterText = | |
| 146 originParameter.parseNode(compiler).toString(); | |
| 147 String patchParameterText = | |
| 148 patchParameter.parseNode(compiler).toString(); | |
| 149 if (originParameterText != patchParameterText) { | |
|
Lasse Reichstein Nielsen
2012/10/04 07:51:21
Does this require that the positional parameters h
Johnni Winther
2012/10/04 10:23:29
Yes, parameters must have the same name, and we do
| |
| 150 error(originParameter.parseNode(compiler), | |
| 151 MessageKind.PATCH_PARAMETER_MISMATCH, | |
| 152 [origin.name, originParameterText, patchParameterText]); | |
| 153 } | |
| 154 | |
| 155 originParameters = originParameters.tail; | |
| 156 patchParameters = patchParameters.tail; | |
| 157 } | |
| 158 } | |
| 159 | |
| 136 void checkMatchingPatchSignatures(FunctionElement origin, | 160 void checkMatchingPatchSignatures(FunctionElement origin, |
| 137 FunctionElement patch) { | 161 FunctionElement patch) { |
| 138 // TODO(johnniwinther): Stub. Implementation in a later CL. | 162 // TODO(johnniwinther): Show both origin and patch locations on errors. |
| 163 FunctionExpression originTree = compiler.withCurrentElement(origin, () { | |
| 164 return origin.parseNode(compiler); | |
| 165 }); | |
| 166 FunctionSignature originSignature = compiler.withCurrentElement(origin, () { | |
| 167 return origin.computeSignature(compiler); | |
| 168 }); | |
| 169 FunctionExpression patchTree = compiler.withCurrentElement(patch, () { | |
| 170 return patch.parseNode(compiler); | |
| 171 }); | |
| 172 FunctionSignature patchSignature = compiler.withCurrentElement(patch, () { | |
| 173 return patch.computeSignature(compiler); | |
| 174 }); | |
| 175 | |
|
Lasse Reichstein Nielsen
2012/10/04 07:51:21
Why is there not a == on FunctionSignature that do
Johnni Winther
2012/10/04 10:23:29
It would require the aforementioned equality on pa
| |
| 176 if (originSignature.returnType != patchSignature.returnType) { | |
| 177 Node errorNode = | |
| 178 originTree.returnType !== null ? originTree.returnType : originTree; | |
|
ahe
2012/10/04 08:34:21
I think the errorNode should be derived from patch
Johnni Winther
2012/10/04 10:23:29
Done.
| |
| 179 error(errorNode, MessageKind.PATCH_RETURN_TYPE_MISMATCH, | |
| 180 [origin.name, originSignature.returnType, patchSignature.returnType]); | |
| 181 } | |
| 182 if (originSignature.requiredParameterCount != | |
| 183 patchSignature.requiredParameterCount) { | |
| 184 error(originTree, | |
|
ahe
2012/10/04 08:34:21
patchTree
Johnni Winther
2012/10/04 10:23:29
Done.
| |
| 185 MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH, | |
| 186 [origin.name, originSignature.requiredParameterCount, | |
| 187 patchSignature.requiredParameterCount]); | |
| 188 } else { | |
| 189 checkMatchingPatchParameters(origin, | |
| 190 originSignature.requiredParameters, | |
| 191 patchSignature.requiredParameters); | |
| 192 } | |
| 193 if (originSignature.optionalParameterCount != | |
| 194 patchSignature.optionalParameterCount) { | |
| 195 error(originTree, | |
| 196 MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH, | |
| 197 [origin.name, originSignature.optionalParameterCount, | |
| 198 patchSignature.optionalParameterCount]); | |
| 199 } else { | |
| 200 checkMatchingPatchParameters(origin, | |
| 201 originSignature.optionalParameters, | |
| 202 patchSignature.optionalParameters); | |
|
Lasse Reichstein Nielsen
2012/10/04 07:51:21
Does this handle both optional positional paramete
Johnni Winther
2012/10/04 10:23:29
Yes, but a check is added to ensure that both are
| |
| 203 } | |
| 139 } | 204 } |
| 140 | 205 |
| 141 TreeElements resolveMethodElement(FunctionElement element) { | 206 TreeElements resolveMethodElement(FunctionElement element) { |
| 142 assert(invariant(element, element.isDeclaration)); | 207 assert(invariant(element, element.isDeclaration)); |
| 143 return compiler.withCurrentElement(element, () { | 208 return compiler.withCurrentElement(element, () { |
| 144 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; | 209 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; |
| 145 TreeElements elements = | 210 TreeElements elements = |
| 146 compiler.enqueuer.resolution.getCachedElements(element); | 211 compiler.enqueuer.resolution.getCachedElements(element); |
| 147 if (elements !== null) { | 212 if (elements !== null) { |
| 148 assert(isConstructor); | 213 assert(isConstructor); |
| (...skipping 2898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3047 return result; | 3112 return result; |
| 3048 } | 3113 } |
| 3049 Element lookup(SourceString name) => localLookup(name); | 3114 Element lookup(SourceString name) => localLookup(name); |
| 3050 Element lexicalLookup(SourceString name) => localLookup(name); | 3115 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3051 | 3116 |
| 3052 Element add(Element newElement) { | 3117 Element add(Element newElement) { |
| 3053 throw "Cannot add an element in a patch library scope"; | 3118 throw "Cannot add an element in a patch library scope"; |
| 3054 } | 3119 } |
| 3055 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3120 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3056 } | 3121 } |
| OLD | NEW |