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

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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 resolveTypeAnnotation(Element element, TypeAnnotation annotation) {
215 DartType type = resolveReturnType(element, annotation);
216 if (type == compiler.types.voidType) {
217 error(annotation, MessageKind.VOID_NOT_ALLOWED);
218 }
219 return type;
220 }
221
222 DartType resolveReturnType(Element element, TypeAnnotation annotation) {
215 if (annotation === null) return compiler.types.dynamicType; 223 if (annotation === null) return compiler.types.dynamicType;
216 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 224 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
217 DartType result = visitor.resolveTypeAnnotation(annotation); 225 DartType result = visitor.resolveTypeAnnotation(annotation);
218 if (result === null) { 226 if (result === null) {
219 // TODO(karklose): warning. 227 // TODO(karklose): warning.
220 return compiler.types.dynamicType; 228 return compiler.types.dynamicType;
221 } 229 }
222 return result; 230 return result;
223 } 231 }
224 232
(...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 } 2373 }
2366 currentDefinitions = node; 2374 currentDefinitions = node;
2367 Element element = definition.accept(this); 2375 Element element = definition.accept(this);
2368 currentDefinitions = null; 2376 currentDefinitions = null;
2369 return element; 2377 return element;
2370 } 2378 }
2371 2379
2372 Element visitIdentifier(Identifier node) { 2380 Element visitIdentifier(Identifier node) {
2373 Element variables = new VariableListElement.node(currentDefinitions, 2381 Element variables = new VariableListElement.node(currentDefinitions,
2374 ElementKind.VARIABLE_LIST, enclosingElement); 2382 ElementKind.VARIABLE_LIST, enclosingElement);
2383 // Ensure a parameter is not typed 'void'.
2384 variables.computeType(compiler);
2375 return new VariableElement(node.source, variables, 2385 return new VariableElement(node.source, variables,
2376 ElementKind.PARAMETER, enclosingElement, node: node); 2386 ElementKind.PARAMETER, enclosingElement, node: node);
2377 } 2387 }
2378 2388
2379 SourceString getParameterName(Send node) { 2389 SourceString getParameterName(Send node) {
2380 var identifier = node.selector.asIdentifier(); 2390 var identifier = node.selector.asIdentifier();
2381 if (identifier !== null) { 2391 if (identifier !== null) {
2382 // Normal parameter: [:Type name:]. 2392 // Normal parameter: [:Type name:].
2383 return identifier.source; 2393 return identifier.source;
2384 } else { 2394 } else {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2484 MessageKind.EXTRA_FORMALS.error([]), 2494 MessageKind.EXTRA_FORMALS.error([]),
2485 api.Diagnostic.WARNING); 2495 api.Diagnostic.WARNING);
2486 } 2496 }
2487 } 2497 }
2488 } 2498 }
2489 LinkBuilder<Element> parametersBuilder = 2499 LinkBuilder<Element> parametersBuilder =
2490 visitor.analyzeNodes(formalParameters.nodes); 2500 visitor.analyzeNodes(formalParameters.nodes);
2491 requiredParameterCount = parametersBuilder.length; 2501 requiredParameterCount = parametersBuilder.length;
2492 parameters = parametersBuilder.toLink(); 2502 parameters = parametersBuilder.toLink();
2493 } 2503 }
2494 DartType returnType = compiler.resolveTypeAnnotation(element, returnNode); 2504 DartType returnType = compiler.resolveReturnType(element, returnNode);
2495 return new FunctionSignature(parameters, 2505 return new FunctionSignature(parameters,
2496 visitor.optionalParameters, 2506 visitor.optionalParameters,
2497 requiredParameterCount, 2507 requiredParameterCount,
2498 visitor.optionalParameterCount, 2508 visitor.optionalParameterCount,
2499 visitor.optionalParametersAreNamed, 2509 visitor.optionalParametersAreNamed,
2500 returnType); 2510 returnType);
2501 } 2511 }
2502 2512
2503 // TODO(ahe): This is temporary. 2513 // TODO(ahe): This is temporary.
2504 void resolveExpression(Node node) { 2514 void resolveExpression(Node node) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 2773
2764 Element localLookup(SourceString name) => library.find(name); 2774 Element localLookup(SourceString name) => library.find(name);
2765 Element lookup(SourceString name) => localLookup(name); 2775 Element lookup(SourceString name) => localLookup(name);
2766 Element lexicalLookup(SourceString name) => localLookup(name); 2776 Element lexicalLookup(SourceString name) => localLookup(name);
2767 2777
2768 Element add(Element newElement) { 2778 Element add(Element newElement) {
2769 throw "Cannot add an element in the top scope"; 2779 throw "Cannot add an element in the top scope";
2770 } 2780 }
2771 String toString() => '$element'; 2781 String toString() => '$element';
2772 } 2782 }
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