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

Side by Side Diff: frog/gen.dart

Issue 8534001: Adds typechecking of return values (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** 5 /**
6 * Top level generator object for writing code and keeping track of 6 * Top level generator object for writing code and keeping track of
7 * dependencies. 7 * dependencies.
8 * 8 *
9 * Should have two compilation models, but only one implemented so far. 9 * Should have two compilation models, but only one implemented so far.
10 * 10 *
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 meth.generator.writeDefinition(writer, null); 1096 meth.generator.writeDefinition(writer, null);
1097 return false; 1097 return false;
1098 } 1098 }
1099 1099
1100 /** 1100 /**
1101 * Returns true indicating that normal control-flow is interrupted by 1101 * Returns true indicating that normal control-flow is interrupted by
1102 * this statement. (This could be a return, break, throw, or continue.) 1102 * this statement. (This could be a return, break, throw, or continue.)
1103 */ 1103 */
1104 bool visitReturnStatement(ReturnStatement node) { 1104 bool visitReturnStatement(ReturnStatement node) {
1105 if (node.value == null) { 1105 if (node.value == null) {
1106 // This is essentially "return null".
1107 // It can't issue a warning because every type is nullable.
jimhug 2011/11/11 15:02:02 Isn't there a TODO here to fix the language <smile
1106 writer.writeln('return;'); 1108 writer.writeln('return;');
1107 } else { 1109 } else {
1108 if (method.isConstructor) { 1110 if (method.isConstructor) {
1109 world.error('return of value not allowed from constructor', node.span); 1111 world.error('return of value not allowed from constructor', node.span);
1110 } 1112 }
1111 writer.writeln('return ${visitValue(node.value).code};'); 1113 var value = visitTypedValue(node.value, method.returnType);
jimhug 2011/11/11 15:02:02 I love the fact that this is essentially your enti
1114 writer.writeln('return ${value.code};');
1112 } 1115 }
1113 return true; 1116 return true;
1114 } 1117 }
1115 1118
1116 bool visitThrowStatement(ThrowStatement node) { 1119 bool visitThrowStatement(ThrowStatement node) {
1117 // Dart allows throwing anything, just like JS 1120 // Dart allows throwing anything, just like JS
1118 if (node.value != null) { 1121 if (node.value != null) {
1119 var value = visitValue(node.value); 1122 var value = visitValue(node.value);
1120 // Ensure that we generate a toString() method for things that we throw 1123 // Ensure that we generate a toString() method for things that we throw
1121 value.invoke(this, 'toString', node, Arguments.EMPTY); 1124 value.invoke(this, 'toString', node, Arguments.EMPTY);
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 } 2233 }
2231 for (int i = bareCount; i < length; i++) { 2234 for (int i = bareCount; i < length; i++) {
2232 var name = getName(i); 2235 var name = getName(i);
2233 if (name == null) name = '\$$i'; 2236 if (name == null) name = '\$$i';
2234 // TODO(jimhug): Need source locations. 2237 // TODO(jimhug): Need source locations.
2235 result.add(new Value(world.varType, name, null, false, /*needsTemp:*/false )); 2238 result.add(new Value(world.varType, name, null, false, /*needsTemp:*/false ));
2236 } 2239 }
2237 return new Arguments(nodes, result); 2240 return new Arguments(nodes, result);
2238 } 2241 }
2239 } 2242 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698