Esempio n. 1
0
  public void atKeyword(Keyword k) throws CompileError {
    arrayDim = 0;
    int token = k.get();
    switch (token) {
      case TRUE:
        bytecode.addIconst(1);
        exprType = BOOLEAN;
        break;
      case FALSE:
        bytecode.addIconst(0);
        exprType = BOOLEAN;
        break;
      case NULL:
        bytecode.addOpcode(ACONST_NULL);
        exprType = NULL;
        break;
      case THIS:
      case SUPER:
        if (inStaticMethod)
          throw new CompileError("not-available: " + (token == THIS ? "this" : "super"));

        bytecode.addAload(0);
        exprType = CLASS;
        if (token == THIS) className = getThisName();
        else className = getSuperName();
        break;
      default:
        fatal();
    }
  }
Esempio n. 2
0
  public void atMethodDecl(MethodDecl method) throws CompileError {
    ASTList mods = method.getModifiers();
    setMaxLocals(1);
    while (mods != null) {
      Keyword k = (Keyword) mods.head();
      mods = mods.tail();
      if (k.get() == STATIC) {
        setMaxLocals(0);
        inStaticMethod = true;
      }
    }

    ASTList params = method.getParams();
    while (params != null) {
      atDeclarator((Declarator) params.head());
      params = params.tail();
    }

    Stmnt s = method.getBody();
    atMethodBody(s, method.isConstructor(), method.getReturn().getType() == VOID);
  }