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 | |
| 144 // elsewhere. | |
| 145 String originParameterText = | |
| 146 originParameter.parseNode(compiler).toString(); | |
| 147 String patchParameterText = | |
| 148 patchParameter.parseNode(compiler).toString(); | |
| 149 if (originParameterText != patchParameterText) { | |
| 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 | |
| 176 if (originSignature.returnType != patchSignature.returnType) { | |
| 177 compiler.withCurrentElement(patch, () { | |
| 178 Node errorNode = | |
| 179 patchTree.returnType !== null ? patchTree.returnType : patchTree; | |
| 180 error(errorNode, MessageKind.PATCH_RETURN_TYPE_MISMATCH, [origin.name, | |
| 181 originSignature.returnType, patchSignature.returnType]); | |
| 182 }); | |
| 183 } | |
| 184 if (originSignature.requiredParameterCount != | |
| 185 patchSignature.requiredParameterCount) { | |
| 186 compiler.withCurrentElement(patch, () { | |
| 187 error(patchTree, | |
| 188 MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH, | |
| 189 [origin.name, originSignature.requiredParameterCount, | |
| 190 patchSignature.requiredParameterCount]); | |
| 191 }); | |
| 192 } else { | |
| 193 checkMatchingPatchParameters(origin, | |
| 194 originSignature.requiredParameters, | |
| 195 patchSignature.requiredParameters); | |
| 196 } | |
| 197 if (originSignature.optionalParameterCount != | |
| 198 patchSignature.optionalParameterCount) { | |
| 199 compiler.withCurrentElement(patch, () { | |
| 200 error(patchTree, | |
| 201 MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH, | |
| 202 [origin.name, originSignature.optionalParameterCount, | |
| 203 patchSignature.optionalParameterCount]); | |
| 204 }); | |
| 205 } else { | |
| 206 checkMatchingPatchParameters(origin, | |
| 207 originSignature.optionalParameters, | |
| 208 patchSignature.optionalParameters); | |
| 209 | |
| 210 if (originSignature.optionalParametersAreNamed != | |
| 211 patchSignature.optionalParametersAreNamed) { | |
|
Lasse Reichstein Nielsen
2012/10/04 11:01:49
Check this before comparing the actual parameters,
Johnni Winther
2012/10/05 11:43:22
Done.
| |
| 212 compiler.withCurrentElement(patch, () { | |
| 213 error(patchTree, | |
| 214 MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH, | |
| 215 [origin.name]); | |
| 216 }); | |
| 217 } | |
| 218 } | |
| 139 } | 219 } |
| 140 | 220 |
| 141 TreeElements resolveMethodElement(FunctionElement element) { | 221 TreeElements resolveMethodElement(FunctionElement element) { |
| 142 assert(invariant(element, element.isDeclaration)); | 222 assert(invariant(element, element.isDeclaration)); |
| 143 return compiler.withCurrentElement(element, () { | 223 return compiler.withCurrentElement(element, () { |
| 144 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; | 224 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; |
| 145 TreeElements elements = | 225 TreeElements elements = |
| 146 compiler.enqueuer.resolution.getCachedElements(element); | 226 compiler.enqueuer.resolution.getCachedElements(element); |
| 147 if (elements !== null) { | 227 if (elements !== null) { |
| 148 assert(isConstructor); | 228 assert(isConstructor); |
| (...skipping 2906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3055 return result; | 3135 return result; |
| 3056 } | 3136 } |
| 3057 Element lookup(SourceString name) => localLookup(name); | 3137 Element lookup(SourceString name) => localLookup(name); |
| 3058 Element lexicalLookup(SourceString name) => localLookup(name); | 3138 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3059 | 3139 |
| 3060 Element add(Element newElement) { | 3140 Element add(Element newElement) { |
| 3061 throw "Cannot add an element in a patch library scope"; | 3141 throw "Cannot add an element in a patch library scope"; |
| 3062 } | 3142 } |
| 3063 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3143 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3064 } | 3144 } |
| OLD | NEW |