예제 #1
0
  protected void checkReturn(Stmt.Return ret) {
    JavaMethod method = (JavaMethod) getEnclosingScope(JavaMethod.class);

    if (method instanceof JavaConstructor) {
      return; // could do better than this.
    }

    Type retType = method.returnType().attribute(Type.class);

    if (ret.expr() != null) {
      checkExpression(ret.expr());

      Type ret_t = ret.expr().attribute(Type.class);
      try {
        if (ret_t.equals(new Type.Void())) {
          syntax_error("cannot return a value from method whose result type is void", ret);
        } else if (!types.subtype(retType, ret_t, loader)) {
          syntax_error("required return type " + retType + ",  found type " + ret_t, ret);
        }

      } catch (ClassNotFoundException ex) {
        syntax_error(ex.getMessage(), ret);
      }
    } else if (!(retType instanceof Type.Void)) {
      syntax_error("missing return value", ret);
    }
  }
예제 #2
0
  protected void checkMethod(JavaMethod d) {
    enclosingScopes.push(d);

    checkStatement(d.body());

    enclosingScopes.pop();
  }