| 226 | return funcName; |
| 227 | } |
| 228 | public String translate(TypeInfo result) { |
| 229 | StringBuilder code = new StringBuilder("public static "); |
| 230 | TypeInfo returnType = funcType.returnType; |
| 231 | code.append(javaType(returnType)).append(' '); |
| 232 | code.append(METHOD).append("(chap11.ArrayEnv ").append(ENV); |
| 233 | for (int i = 0; i < funcType.parameterTypes.length; i++) { |
| 234 | code.append(',').append(javaType(funcType.parameterTypes[i])) |
| 235 | .append(' ').append(LOCAL).append(i); |
| 236 | } |
| 237 | code.append("){\n"); |
| 238 | code.append(javaType(returnType)).append(' ').append(RESULT) |
| 239 | .append(";\n"); |
| 240 | for (int i = funcType.parameterTypes.length; i < size; i++) { |
| 241 | TypeInfo t = bodyEnv.get(0, i); |
| 242 | code.append(javaType(t)).append(' ').append(LOCAL).append(i); |
| 243 | if (t.type() == TypeInfo.INT) |
| 244 | code.append("=0;\n"); |
| 245 | else |
| 246 | code.append("=null;\n"); |
| 247 | } |
| 248 | code.append(((ASTreeEx)revise(body())).translate(returnType)); |
| 249 | code.append("return ").append(RESULT).append(";}"); |
| 250 | return code.toString(); |
| 251 | } |
| 252 | protected String javaType(TypeInfo t) { |
| 253 | if (t.type() == TypeInfo.INT) |
| 254 | return "int"; |