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

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

Issue 10908238: Only allow 'void' as a return type. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 | « lib/compiler/implementation/compiler.dart ('k') | 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 204 }
205 205
206 TreeElements resolveParameter(Element element) { 206 TreeElements resolveParameter(Element element) {
207 Node tree = element.parseNode(compiler); 207 Node tree = element.parseNode(compiler);
208 ResolverVisitor visitor = 208 ResolverVisitor visitor =
209 new ResolverVisitor(compiler, element.enclosingElement); 209 new ResolverVisitor(compiler, element.enclosingElement);
210 initializerDo(tree, visitor.visit); 210 initializerDo(tree, visitor.visit);
211 return visitor.mapping; 211 return visitor.mapping;
212 } 212 }
213 213
214 DartType resolveTypeAnnotation(Element element, TypeAnnotation annotation) { 214 DartType resolveTypeAnnotationHelper(Element element,
215 TypeAnnotation annotation) {
215 if (annotation === null) return compiler.types.dynamicType; 216 if (annotation === null) return compiler.types.dynamicType;
216 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 217 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
217 DartType result = visitor.resolveTypeAnnotation(annotation); 218 DartType result = visitor.resolveTypeAnnotation(annotation);
218 if (result === null) { 219 if (result === null) {
219 // TODO(karklose): warning. 220 // TODO(karklose): warning.
220 return compiler.types.dynamicType; 221 return compiler.types.dynamicType;
221 } 222 }
222 return result; 223 return result;
223 } 224 }
224 225
226 DartType resolveTypeAnnotation(Element element, TypeAnnotation annotation) {
ahe 2012/09/13 11:49:37 I think this method could call resolveReturnType.
ngeoffray 2012/09/13 11:56:56 Done.
227 DartType type = resolveTypeAnnotationHelper(element, annotation);
228 if (type == compiler.types.voidType) {
229 error(annotation, MessageKind.VOID_NOT_ALLOWED);
230 }
231 return type;
232 }
233
234 DartType resolveReturnType(Element element,
235 TypeAnnotation annotation) {
236 return resolveTypeAnnotationHelper(element, annotation);
237 }
238
225 /** 239 /**
226 * Load and resolve the supertypes of [cls]. 240 * Load and resolve the supertypes of [cls].
227 * 241 *
228 * Warning: do not call this method directly. It should only be 242 * Warning: do not call this method directly. It should only be
229 * called by [resolveClass] and [ClassSupertypeResolver]. 243 * called by [resolveClass] and [ClassSupertypeResolver].
230 */ 244 */
231 void loadSupertypes(ClassElement cls, Node from) { 245 void loadSupertypes(ClassElement cls, Node from) {
232 compiler.withCurrentElement(cls, () => measure(() { 246 compiler.withCurrentElement(cls, () => measure(() {
233 if (cls.supertypeLoadState == STATE_DONE) return; 247 if (cls.supertypeLoadState == STATE_DONE) return;
234 if (cls.supertypeLoadState == STATE_STARTED) { 248 if (cls.supertypeLoadState == STATE_STARTED) {
(...skipping 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 } 2379 }
2366 currentDefinitions = node; 2380 currentDefinitions = node;
2367 Element element = definition.accept(this); 2381 Element element = definition.accept(this);
2368 currentDefinitions = null; 2382 currentDefinitions = null;
2369 return element; 2383 return element;
2370 } 2384 }
2371 2385
2372 Element visitIdentifier(Identifier node) { 2386 Element visitIdentifier(Identifier node) {
2373 Element variables = new VariableListElement.node(currentDefinitions, 2387 Element variables = new VariableListElement.node(currentDefinitions,
2374 ElementKind.VARIABLE_LIST, enclosingElement); 2388 ElementKind.VARIABLE_LIST, enclosingElement);
2389 // Ensure a parameter is not typed 'void'.
2390 variables.computeType(compiler);
2375 return new VariableElement(node.source, variables, 2391 return new VariableElement(node.source, variables,
2376 ElementKind.PARAMETER, enclosingElement, node: node); 2392 ElementKind.PARAMETER, enclosingElement, node: node);
2377 } 2393 }
2378 2394
2379 SourceString getParameterName(Send node) { 2395 SourceString getParameterName(Send node) {
2380 var identifier = node.selector.asIdentifier(); 2396 var identifier = node.selector.asIdentifier();
2381 if (identifier !== null) { 2397 if (identifier !== null) {
2382 // Normal parameter: [:Type name:]. 2398 // Normal parameter: [:Type name:].
2383 return identifier.source; 2399 return identifier.source;
2384 } else { 2400 } else {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2484 MessageKind.EXTRA_FORMALS.error([]), 2500 MessageKind.EXTRA_FORMALS.error([]),
2485 api.Diagnostic.WARNING); 2501 api.Diagnostic.WARNING);
2486 } 2502 }
2487 } 2503 }
2488 } 2504 }
2489 LinkBuilder<Element> parametersBuilder = 2505 LinkBuilder<Element> parametersBuilder =
2490 visitor.analyzeNodes(formalParameters.nodes); 2506 visitor.analyzeNodes(formalParameters.nodes);
2491 requiredParameterCount = parametersBuilder.length; 2507 requiredParameterCount = parametersBuilder.length;
2492 parameters = parametersBuilder.toLink(); 2508 parameters = parametersBuilder.toLink();
2493 } 2509 }
2494 DartType returnType = compiler.resolveTypeAnnotation(element, returnNode); 2510 DartType returnType = compiler.resolveReturnType(element, returnNode);
2495 return new FunctionSignature(parameters, 2511 return new FunctionSignature(parameters,
2496 visitor.optionalParameters, 2512 visitor.optionalParameters,
2497 requiredParameterCount, 2513 requiredParameterCount,
2498 visitor.optionalParameterCount, 2514 visitor.optionalParameterCount,
2499 visitor.optionalParametersAreNamed, 2515 visitor.optionalParametersAreNamed,
2500 returnType); 2516 returnType);
2501 } 2517 }
2502 2518
2503 // TODO(ahe): This is temporary. 2519 // TODO(ahe): This is temporary.
2504 void resolveExpression(Node node) { 2520 void resolveExpression(Node node) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 2779
2764 Element localLookup(SourceString name) => library.find(name); 2780 Element localLookup(SourceString name) => library.find(name);
2765 Element lookup(SourceString name) => localLookup(name); 2781 Element lookup(SourceString name) => localLookup(name);
2766 Element lexicalLookup(SourceString name) => localLookup(name); 2782 Element lexicalLookup(SourceString name) => localLookup(name);
2767 2783
2768 Element add(Element newElement) { 2784 Element add(Element newElement) {
2769 throw "Cannot add an element in the top scope"; 2785 throw "Cannot add an element in the top scope";
2770 } 2786 }
2771 String toString() => '$element'; 2787 String toString() => '$element';
2772 } 2788 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698