int compile(Bytecode code) throws CannotCompileException { code.addIconst(param); return 1; }
@Override int compile(Bytecode code) throws CannotCompileException { code.addIconst(param); return 1; }
/** * Appends NEWARRAY for primitive types. * * @param atype <code>T_BOOLEAN</code>, <code>T_CHAR</code>, ... * @see Opcode */ public void addNewarray(int atype, int length) { addIconst(length); addOpcode(NEWARRAY); add(atype); }
int compileIfStatic(CtClass type, String name, Bytecode code, Javac drv) throws CannotCompileException { code.addIconst(value); code.addPutstatic(Bytecode.THIS, name, Descriptor.of(type)); return 1; // stack size }
/** * Appends MULTINEWARRAY. * * @param clazz the array type. * @param dimensions the sizes of all dimensions. * @return the length of <code>dimensions</code>. */ public int addMultiNewarray(CtClass clazz, int[] dimensions) { int len = dimensions.length; for (int i = 0; i < len; ++i) addIconst(dimensions[i]); growStack(len); return addMultiNewarray(clazz, len); }
protected final int compileStringParameter(Bytecode code) throws CannotCompileException { int nparam = stringParams.length; code.addIconst(nparam); code.addAnewarray(javaLangString); for (int j = 0; j < nparam; ++j) { code.add(Bytecode.DUP); // dup code.addIconst(j); // iconst_<j> code.addLdc(stringParams[j]); // ldc ... code.add(Bytecode.AASTORE); // aastore } return 4; }
private static void makeParameterList(Bytecode code, Class[] params) { int regno = 1; int n = params.length; code.addIconst(n); code.addAnewarray("java/lang/Object"); for (int i = 0; i < n; i++) { code.addOpcode(Opcode.DUP); code.addIconst(i); Class type = params[i]; if (type.isPrimitive()) regno = makeWrapper(code, type, regno); else { code.addAload(regno); regno++; } code.addOpcode(Opcode.AASTORE); } }
/** * Appends NEWARRAY for primitive types. * * @param atype <code>T_BOOLEAN</code>, <code>T_CHAR</code>, ... * @see Opcode */ public void addNewarray(int atype, int length) { addIconst(length); addOpcode(NEWARRAY); add(atype); }
@Override int compileIfStatic(CtClass type, String name, Bytecode code, Javac drv) throws CannotCompileException { code.addIconst(value); code.addPutstatic(Bytecode.THIS, name, Descriptor.of(type)); return 1; // stack size }
int compile(CtClass type, String name, Bytecode code, CtClass[] parameters, Javac drv) throws CannotCompileException { code.addAload(0); code.addIconst(value); code.addPutfield(Bytecode.THIS, name, Descriptor.of(type)); return 2; // stack size }
/** * Appends ICONST and ANEWARRAY. * * @param clazz the elememnt type. * @param length the array length. */ public void addAnewarray(CtClass clazz, int length) { addIconst(length); addOpcode(ANEWARRAY); addIndex(constPool.addClassInfo(clazz)); }
public void atIntConst(IntConst i) throws CompileError { arrayDim = 0; long value = i.get(); int type = i.getType(); if (type == IntConstant || type == CharConstant) { exprType = (type == IntConstant ? INT : CHAR); bytecode.addIconst((int)value); } else { exprType = LONG; bytecode.addLconst(value); } }
protected final int compileStringParameter(Bytecode code) throws CannotCompileException { int nparam = stringParams.length; code.addIconst(nparam); code.addAnewarray(javaLangString); for (int j = 0; j < nparam; ++j) { code.add(Bytecode.DUP); // dup code.addIconst(j); // iconst_<j> code.addLdc(stringParams[j]); // ldc ... code.add(Bytecode.AASTORE); // aastore } return 4; }
/** * Appends MULTINEWARRAY. * * @param clazz the array type. * @param dimensions the sizes of all dimensions. * @return the length of <code>dimensions</code>. */ public int addMultiNewarray(CtClass clazz, int[] dimensions) { int len = dimensions.length; for (int i = 0; i < len; ++i) addIconst(dimensions[i]); growStack(len); return addMultiNewarray(clazz, len); }
/** * Appends ICONST and ANEWARRAY. * * @param clazz the elememnt type. * @param length the array length. */ public void addAnewarray(CtClass clazz, int length) { addIconst(length); addOpcode(ANEWARRAY); addIndex(constPool.addClassInfo(clazz)); }
@Override int compile(CtClass type, String name, Bytecode code, CtClass[] parameters, Javac drv) throws CannotCompileException { code.addAload(0); code.addIconst(value); code.addPutfield(Bytecode.THIS, name, Descriptor.of(type)); return 2; // stack size }
@Override public void atIntConst(IntConst i) throws CompileError { arrayDim = 0; long value = i.get(); int type = i.getType(); if (type == IntConstant || type == CharConstant) { exprType = (type == IntConstant ? INT : CHAR); bytecode.addIconst((int)value); } else { exprType = LONG; bytecode.addLconst(value); } }
/** * @param thisMethod might be null. */ private static void callFind2Methods(Bytecode code, String superMethod, String thisMethod, int index, String desc, int classVar, int arrayVar) { String findClass = RuntimeSupport.class.getName(); String findDesc = "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/reflect/Method;)V"; code.addAload(classVar); code.addLdc(superMethod); if (thisMethod == null) code.addOpcode(Opcode.ACONST_NULL); else code.addLdc(thisMethod); code.addIconst(index); code.addLdc(desc); code.addAload(arrayVar); code.addInvokestatic(findClass, "find2Methods", findDesc); }
protected void atAssignParamList(CtClass[] params, Bytecode code) throws CompileError { if (params == null) return; int varNo = indexOfParam1(); int n = params.length; for (int i = 0; i < n; ++i) { code.addOpcode(DUP); code.addIconst(i); code.addOpcode(AALOAD); compileUnwrapValue(params[i], code); code.addStore(varNo, params[i]); varNo += is2word(exprType, arrayDim) ? 2 : 1; } }
protected void atPlusPlusCore(int dup_code, boolean doDup, int token, boolean isPost, Expr expr) throws CompileError { int t = exprType; if (doDup && isPost) bytecode.addOpcode(dup_code); if (t == INT || t == BYTE || t == CHAR || t == SHORT) { bytecode.addIconst(1); bytecode.addOpcode(token == PLUSPLUS ? IADD : ISUB); exprType = INT; } else if (t == LONG) { bytecode.addLconst((long)1); bytecode.addOpcode(token == PLUSPLUS ? LADD : LSUB); } else if (t == FLOAT) { bytecode.addFconst(1.0f); bytecode.addOpcode(token == PLUSPLUS ? FADD : FSUB); } else if (t == DOUBLE) { bytecode.addDconst(1.0); bytecode.addOpcode(token == PLUSPLUS ? DADD : DSUB); } else badType(expr); if (doDup && !isPost) bytecode.addOpcode(dup_code); }