| OLD | NEW |
| 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 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 meth.generator.writeDefinition(writer, null); | 1093 meth.generator.writeDefinition(writer, null); |
| 1094 return false; | 1094 return false; |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 /** | 1097 /** |
| 1098 * Returns true indicating that normal control-flow is interrupted by | 1098 * Returns true indicating that normal control-flow is interrupted by |
| 1099 * this statement. (This could be a return, break, throw, or continue.) | 1099 * this statement. (This could be a return, break, throw, or continue.) |
| 1100 */ | 1100 */ |
| 1101 bool visitReturnStatement(ReturnStatement node) { | 1101 bool visitReturnStatement(ReturnStatement node) { |
| 1102 if (node.value == null) { | 1102 if (node.value == null) { |
| 1103 // This is essentially "return null". |
| 1104 // It can't issue a warning because every type is nullable. |
| 1103 writer.writeln('return;'); | 1105 writer.writeln('return;'); |
| 1104 } else { | 1106 } else { |
| 1105 if (method.isConstructor) { | 1107 if (method.isConstructor) { |
| 1106 world.error('return of value not allowed from constructor', node.span); | 1108 world.error('return of value not allowed from constructor', node.span); |
| 1107 } | 1109 } |
| 1108 writer.writeln('return ${visitValue(node.value).code};'); | 1110 var value = visitTypedValue(node.value, method.returnType); |
| 1111 writer.writeln('return ${value.code};'); |
| 1109 } | 1112 } |
| 1110 return true; | 1113 return true; |
| 1111 } | 1114 } |
| 1112 | 1115 |
| 1113 bool visitThrowStatement(ThrowStatement node) { | 1116 bool visitThrowStatement(ThrowStatement node) { |
| 1114 // Dart allows throwing anything, just like JS | 1117 // Dart allows throwing anything, just like JS |
| 1115 if (node.value != null) { | 1118 if (node.value != null) { |
| 1116 var value = visitValue(node.value); | 1119 var value = visitValue(node.value); |
| 1117 // Ensure that we generate a toString() method for things that we throw | 1120 // Ensure that we generate a toString() method for things that we throw |
| 1118 value.invoke(this, 'toString', node, Arguments.EMPTY); | 1121 value.invoke(this, 'toString', node, Arguments.EMPTY); |
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2227 } | 2230 } |
| 2228 for (int i = bareCount; i < length; i++) { | 2231 for (int i = bareCount; i < length; i++) { |
| 2229 var name = getName(i); | 2232 var name = getName(i); |
| 2230 if (name == null) name = '\$$i'; | 2233 if (name == null) name = '\$$i'; |
| 2231 // TODO(jimhug): Need source locations. | 2234 // TODO(jimhug): Need source locations. |
| 2232 result.add(new Value(world.varType, name, null, false, /*needsTemp:*/false
)); | 2235 result.add(new Value(world.varType, name, null, false, /*needsTemp:*/false
)); |
| 2233 } | 2236 } |
| 2234 return new Arguments(nodes, result); | 2237 return new Arguments(nodes, result); |
| 2235 } | 2238 } |
| 2236 } | 2239 } |
| OLD | NEW |