int index = iterator.u16bitAt(pos + 1); Javac jc = new Javac(thisClass); ClassPool cp = thisClass.getClassPool(); CodeAttribute ca = iterator.get(); jc.recordParams(javaLangObject, params, true, paramVar, withinStatic()); int retVar = jc.recordReturnType(retType, true); jc.recordProceed(new ProceedForInstanceof(index)); jc.recordType(getType()); Bytecode bytecode = jc.getBytecode(); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); jc.compileStmnt(statement); bytecode.addLoad(retVar, retType);
throws CannotCompileException Javac compiler = new Javac(declaring); try { if (delegateMethod != null) compiler.recordProceed(delegateObj, delegateMethod); CtMember obj = compiler.compile(src); if (obj instanceof CtMethod) return (CtMethod)obj;
cc.checkModify(); try { Javac jv = new Javac(cc); if (delegateMethod != null) jv.recordProceed(delegateObj, delegateMethod); Bytecode b = jv.compileBody(this, src); methodInfo.setCodeAttribute(b.toCodeAttribute()); methodInfo.setAccessFlags(methodInfo.getAccessFlags()
/** * Compiles an exression. <code>recordParams()</code> must be * called before invoking this method. * * <p>Local variables are not accessible * within the compiled source text. Fields and method parameters * ($0, $1, ..) are available if <code>recordParams()</code> * have been invoked. */ public void compileExpr(String src) throws CompileError { ASTree e = parseExpr(src, stable); compileExpr(e); }
/** * Compiles the given source code and creates a constructor. * The source code must include not only the constructor body * but the whole declaration. * * @param src the source text. * @param declaring the class to which the created constructor is added. */ public static CtConstructor make(String src, CtClass declaring) throws CannotCompileException { Javac compiler = new Javac(declaring); try { CtMember obj = compiler.compile(src); if (obj instanceof CtConstructor) { // a stack map table has been already created. return (CtConstructor)obj; } } catch (CompileError e) { throw new CannotCompileException(e); } throw new CannotCompileException("not a constructor"); }
throw new CannotCompileException("not method invocation"); Javac jc = new Javac(thisClass); ClassPool cp = thisClass.getClassPool(); CodeAttribute ca = iterator.get(); CtClass retType = Descriptor.getReturnType(signature, cp); int paramVar = ca.getMaxLocals(); jc.recordParams(classname, params, true, paramVar, withinStatic()); int retVar = jc.recordReturnType(retType, true); if (c == INVOKESTATIC) jc.recordStaticProceed(classname, methodname); else if (c == INVOKESPECIAL) jc.recordSpecialProceed(Javac.param0Name, classname, methodname, signature, index); else jc.recordProceed(Javac.param0Name, methodname); Bytecode bytecode = jc.getBytecode(); storeStack(params, c == INVOKESTATIC, paramVar, bytecode); jc.recordLocalVariables(ca, pos); jc.compileStmnt(statement); if (retType != CtClass.voidType) bytecode.addLoad(retVar, retType);
Javac jv = new Javac(cc); try { int nvars = jv.recordParams(getParameterTypes(), Modifier.isStatic(getModifiers())); jv.recordParamNames(ca, nvars); jv.recordLocalVariables(ca, 0); jv.recordType(getReturnType0()); jv.compileStmnt(src); Bytecode b = jv.getBytecode(); int stack = b.getMaxStack(); int locals = b.getMaxLocals();
Javac jv = new Javac(thisClass); Bytecode b = jv.getBytecode(); b.setStackDepth(1); b.setMaxLocals(ca.getMaxLocals()); int var = jv.recordVariable(type, EXCEPTION_NAME); jv.recordReturnType(type, false); b.addAstore(var); jv.compileStmnt(src); b.addAload(var);
cc.checkModify(); CodeIterator iterator = ca.iterator(); Javac jv = new Javac(cc); try { jv.recordLocalVariables(ca, index); jv.recordParams(getParameterTypes(), Modifier.isStatic(getModifiers())); jv.setMaxLocals(ca.getMaxLocals()); jv.compileStmnt(src); Bytecode b = jv.getBytecode(); int locals = b.getMaxLocals(); int stack = b.getMaxStack();
recordParams(method.getParameterTypes(), Modifier.isStatic(mod)); rtype = CtClass.voidType; recordReturnType(rtype, false); boolean isVoid = rtype == CtClass.voidType; makeDefaultBody(bytecode, rtype); else { Parser p = new Parser(new Lex(src));
Bytecode b = new Bytecode(cp, ca.getMaxStack(), ca.getMaxLocals()); b.setStackDepth(1); Javac jv = new Javac(b, cc); try { jv.recordParams(getParameterTypes(), Modifier.isStatic(getModifiers())); int var = jv.recordVariable(exceptionType, exceptionName); b.addAstore(var); jv.compileStmnt(src);
try { if (mem instanceof FieldDecl) return compileField((FieldDecl)mem); else { CtBehavior cb = compileMethod(p, (MethodDecl)mem); CtClass decl = cb.getDeclaringClass(); cb.getMethodInfo2()
ca.getMaxStack(), ca.getMaxLocals()); b.setStackDepth(ca.getMaxStack()); Javac jv = new Javac(b, cc); try { jv.recordParams(getParameterTypes(), false); jv.compileStmnt(src); ca.setMaxStack(b.getMaxStack()); ca.setMaxLocals(b.getMaxLocals());
void compileExpr(Javac drv) throws CompileError { drv.compileExpr(expression); }
private int makeFieldInitializer(Bytecode code, CtClass[] parameters) throws CannotCompileException, NotFoundException { int stacksize = 0; Javac jv = new Javac(code, this); try { jv.recordParams(parameters, false); } catch (CompileError e) { throw new CannotCompileException(e); } for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) { CtField f = fi.field; if (!Modifier.isStatic(f.getModifiers())) { int s = fi.init.compile(f.getType(), f.getName(), code, parameters, jv); if (stacksize < s) stacksize = s; } } return stacksize; }
int getConstantValue(ConstPool cp, CtClass type) { try { ASTree t = Javac.parseExpr(expression, new SymbolTable()); return getConstantValue2(cp, type, t); } catch (CompileError e) { return 0; } } }
private int insertAfterAdvice(Bytecode code, Javac jv, String src, ConstPool cp, CtClass rtype, int varNo) throws CompileError { int pc = code.currentPc(); if (rtype == CtClass.voidType) { code.addOpcode(Opcode.ACONST_NULL); code.addAstore(varNo); jv.compileStmnt(src); code.addOpcode(Opcode.RETURN); if (code.getMaxLocals() < 1) code.setMaxLocals(1); } else { code.addStore(varNo, rtype); jv.compileStmnt(src); code.addLoad(varNo, rtype); if (rtype.isPrimitive()) code.addOpcode(((CtPrimitiveType)rtype).getReturnOp()); else code.addOpcode(Opcode.ARETURN); } return code.currentPc() - pc; }
private void modifyClassConstructor(ClassFile cf) throws CannotCompileException, NotFoundException { if (fieldInitializers == null) return; Bytecode code = new Bytecode(cf.getConstPool(), 0, 0); Javac jv = new Javac(code, this); int stacksize = 0; boolean doInit = false; for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) { CtField f = fi.field; if (Modifier.isStatic(f.getModifiers())) { doInit = true; int s = fi.init.compileIfStatic(f.getType(), f.getName(), code, jv); if (stacksize < s) stacksize = s; } } if (doInit) // need an initializer for static fileds. modifyClassConstructor(cf, code, stacksize, 0); }
throw new CannotCompileException("not method invocation"); Javac jc = new Javac(thisClass); ClassPool cp = thisClass.getClassPool(); CodeAttribute ca = iterator.get(); CtClass retType = Descriptor.getReturnType(signature, cp); int paramVar = ca.getMaxLocals(); jc.recordParams(classname, params, true, paramVar, withinStatic()); int retVar = jc.recordReturnType(retType, true); if (c == INVOKESTATIC) jc.recordStaticProceed(classname, methodname); else if (c == INVOKESPECIAL) jc.recordSpecialProceed(Javac.param0Name, classname, methodname, signature, index); else jc.recordProceed(Javac.param0Name, methodname); Bytecode bytecode = jc.getBytecode(); storeStack(params, c == INVOKESTATIC, paramVar, bytecode); jc.recordLocalVariables(ca, pos); jc.compileStmnt(statement); if (retType != CtClass.voidType) bytecode.addLoad(retVar, retType);
Javac jv = new Javac(cc); try { int nvars = jv.recordParams(getParameterTypes(), Modifier.isStatic(getModifiers())); jv.recordParamNames(ca, nvars); jv.recordLocalVariables(ca, 0); jv.recordType(getReturnType0()); jv.compileStmnt(src); Bytecode b = jv.getBytecode(); int stack = b.getMaxStack(); int locals = b.getMaxLocals();