Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 11052012: Patch signatures checked in resolver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Check moved. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 != 0 &&
198 patchSignature.optionalParameterCount != 0) {
199 if (originSignature.optionalParametersAreNamed !=
200 patchSignature.optionalParametersAreNamed) {
201 compiler.withCurrentElement(patch, () {
202 error(patchTree,
203 MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH,
204 [origin.name]);
205 });
206 }
207 }
208 if (originSignature.optionalParameterCount !=
209 patchSignature.optionalParameterCount) {
210 compiler.withCurrentElement(patch, () {
211 error(patchTree,
212 MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH,
213 [origin.name, originSignature.optionalParameterCount,
214 patchSignature.optionalParameterCount]);
215 });
216 } else {
217 checkMatchingPatchParameters(origin,
218 originSignature.optionalParameters,
219 patchSignature.optionalParameters);
220 }
139 } 221 }
140 222
141 TreeElements resolveMethodElement(FunctionElement element) { 223 TreeElements resolveMethodElement(FunctionElement element) {
142 assert(invariant(element, element.isDeclaration)); 224 assert(invariant(element, element.isDeclaration));
143 return compiler.withCurrentElement(element, () { 225 return compiler.withCurrentElement(element, () {
144 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; 226 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR;
145 TreeElements elements = 227 TreeElements elements =
146 compiler.enqueuer.resolution.getCachedElements(element); 228 compiler.enqueuer.resolution.getCachedElements(element);
147 if (elements !== null) { 229 if (elements !== null) {
148 assert(isConstructor); 230 assert(isConstructor);
(...skipping 2906 matching lines...) Expand 10 before | Expand all | Expand 10 after
3055 return result; 3137 return result;
3056 } 3138 }
3057 Element lookup(SourceString name) => localLookup(name); 3139 Element lookup(SourceString name) => localLookup(name);
3058 Element lexicalLookup(SourceString name) => localLookup(name); 3140 Element lexicalLookup(SourceString name) => localLookup(name);
3059 3141
3060 Element add(Element newElement) { 3142 Element add(Element newElement) {
3061 throw "Cannot add an element in a patch library scope"; 3143 throw "Cannot add an element in a patch library scope";
3062 } 3144 }
3063 String toString() => 'PatchLibraryScope($origin,$patch)'; 3145 String toString() => 'PatchLibraryScope($origin,$patch)';
3064 } 3146 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698