private CompoundInstruction createInstructionPush(Element inst) throws IllegalXMLVMException { String t = inst.getAttributeValue("type"); Type type = parseTypeString(t); String value = inst.getAttributeValue("value"); if (type == Type.STRING) return new PUSH(constantPoolGen, value); else if (type == Type.INT) return new PUSH(constantPoolGen, Integer.parseInt(value)); else if (type == Type.FLOAT) return new PUSH(constantPoolGen, Float.parseFloat(value)); else if (type == Type.DOUBLE) return new PUSH(constantPoolGen, Double.parseDouble(value)); else if (type == Type.LONG) return new PUSH(constantPoolGen, Long.parseLong(value)); else throw new IllegalXMLVMException(inst.getName() + " with bad type '" + t + "'"); }
public void storeLocal(int pc, int slot) { boolean isupval = pi.isUpvalueAssign(pc, slot); int index = findSlotIndex( slot, isupval ); if (isupval) { boolean isupcreate = pi.isUpvalueCreate(pc, slot); if ( isupcreate ) { append(factory.createInvoke(classname, "newupe", TYPE_LOCALUPVALUE, ARG_TYPES_NONE, Constants.INVOKESTATIC)); append(InstructionConstants.DUP); append(new ASTORE(index)); } else { append(new ALOAD(index)); } append(InstructionConstants.SWAP); append(new PUSH(cp, 0)); append(InstructionConstants.SWAP); append(InstructionConstants.AASTORE); } else { append(new ASTORE(index)); } }
private String createLuaStringField(LuaString value) { String name = PREFIX_CONSTANT+constants.size(); FieldGen fg = new FieldGen(Constants.ACC_STATIC | Constants.ACC_FINAL, TYPE_LUAVALUE, name, cp); cg.addField(fg.getField()); LuaString ls = value.checkstring(); if ( ls.isValidUtf8() ) { init.append(new PUSH(cp, value.tojstring())); init.append(factory.createInvoke(STR_LUASTRING, "valueOf", TYPE_LUASTRING, ARG_TYPES_STRING, Constants.INVOKESTATIC)); } else { char[] c = new char[ls.m_length]; for ( int j=0; j<ls.m_length; j++ ) c[j] = (char) (0xff & (int) (ls.m_bytes[ls.m_offset+j])); init.append(new PUSH(cp, new String(c))); init.append(factory.createInvoke(STR_STRING, "toCharArray", TYPE_CHARARRAY, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); init.append(factory.createInvoke(STR_LUASTRING, "valueOf", TYPE_LUASTRING, ARG_TYPES_CHARARRAY, Constants.INVOKESTATIC)); } init.append(factory.createPutStatic(classname, name, TYPE_LUAVALUE)); return name; }
protected void addFindMethod(ParsedMethod m) { GeneratedMethod gm = new GeneratedMethod(m); InstructionList il = gm.start(); writeMethodPreamble(gm, il); il.append(new PUSH(_cp, (ObjectType) gm.getReturnType())); m.getArguments()[0].pushAsObject(il); il.append(_factory.createInvoke(EM_TYPE, "find", Type.OBJECT, new Type[] { Type.CLASS, Type.OBJECT }, Constants.INVOKEINTERFACE)); il.append(_factory.createCheckCast(((ReferenceType) gm.getReturnType()))); il.append(InstructionFactory.createReturn(gm.getReturnType())); gm.done(); }
protected void processMethodAnnotations(ParsedMethod m, InstructionList il) { MaxResults mr = m.getMethod().getAnnotation(MaxResults.class); if (mr != null) { if (mr.value() < 0) { throw new IllegalArgumentException( "MaxResults without a value on " + m.getMethod()); } il.append(new PUSH(_cp, mr.value())); il.append(_factory.createInvoke(TQ_CLASS, "setMaxResults", new ObjectType(TQ_CLASS), new Type[] { Type.INT }, Constants.INVOKEINTERFACE)); } FirstResult fr = m.getMethod().getAnnotation(FirstResult.class); if (fr != null && fr.value() > -1) { il.append(new PUSH(_cp, fr.value())); il.append(_factory.createInvoke(TQ_CLASS, "setFirstResult", new ObjectType(TQ_CLASS), new Type[] { Type.INT }, Constants.INVOKEINTERFACE)); } }
public void generateReadArrayCode(InstructionList il, InstructionFactory factory, ConstantPoolGen cp, int dim, int[] maxIndex) { for (int i = 0; i < dim; i++) il.append(new PUSH(cp, maxIndex[i])); il.append((Instruction) factory.createNewArray(type, (short) dim)); il.append(InstructionFactory.DUP_X1); if (dim == 1) il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, arrayArgType, INVOKEINTERFACE)); else il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readMultiArray", Type.VOID, objectArrayArgType, INVOKEINTERFACE)); }
/** * Inject common exception catch blocks */ public void injectCommonExceptionCatchBlock(InstructionList il, MethodGen method, int variableIndex) { il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.RuntimeException")))); BranchInstruction b1 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null); il.append(b1); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createCheckCast(new ObjectType("java.lang.RuntimeException"))); il.append(InstructionConstants.ATHROW); InstructionHandle ih1 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(new INSTANCEOF(constantsPool.addClass(new ObjectType("java.lang.Error")))); BranchInstruction b2 = InstructionFactory.createBranchInstruction(Constants.IFEQ, null); il.append(b2); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createCheckCast(new ObjectType("java.lang.Error"))); il.append(InstructionConstants.ATHROW); InstructionHandle ih2 = il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createInvoke("java.lang.Throwable", "printStackTrace", Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createNew("org.codehaus.jremoting.client.InvocationException")); il.append(InstructionConstants.DUP); il.append(factory.createNew("java.lang.StringBuffer")); il.append(InstructionConstants.DUP); il.append(new PUSH(constantsPool, "Should never get here: ")); il.append(factory.createInvoke("java.lang.StringBuffer", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL)); il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(factory.createInvoke("java.lang.Throwable", "getMessage", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.lang.StringBuffer", "append", Type.STRINGBUFFER, new Type[]{Type.STRING}, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.lang.StringBuffer", "toString", Type.STRING, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); il.append(factory.createInvoke("org.codehaus.jremoting.client.InvocationException", "<init>", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKESPECIAL)); il.append(InstructionConstants.ATHROW); b1.setTarget(ih1); b2.setTarget(ih2); }
/** * Translate code to call the BasisLibrary.unallowed_extensionF(String) * method. */ private void translateUnallowedExtension(ConstantPoolGen cpg, InstructionList il) { int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unallowed_extension_functionF", "(Ljava/lang/String;)V"); il.append(new PUSH(cpg, _fname.toString())); il.append(new INVOKESTATIC(index)); }
public void initializeSlots() { int slot = 0; createUpvalues(-1, 0, p.maxstacksize); if ( superclassType == SUPERTYPE_VARARGS ) { for ( slot=0; slot<p.numparams; slot++ ) { if ( pi.isInitialValueUsed(slot) ) { append(new ALOAD(1)); append(new PUSH(cp, slot+1)); append(factory.createInvoke(STR_VARARGS, "arg", TYPE_LUAVALUE, ARG_TYPES_INT, Constants.INVOKEVIRTUAL)); storeLocal(-1, slot); } } append(new ALOAD(1)); append(new PUSH(cp, 1 + p.numparams)); append(factory.createInvoke(STR_VARARGS, "subargs", TYPE_VARARGS, ARG_TYPES_INT, Constants.INVOKEVIRTUAL)); append(new ASTORE(1)); } else { // fixed arg function between 0 and 3 arguments for ( slot=0; slot<p.numparams; slot++ ) { this.plainSlotVars.put( Integer.valueOf(slot), Integer.valueOf(1+slot) ); if ( pi.isUpvalueCreate(-1, slot) ) { append(new ALOAD(1+slot)); storeLocal(-1, slot); } } } // nil parameters // TODO: remove this for lua 5.2, not needed for ( ; slot<p.maxstacksize; slot++ ) { if ( pi.isInitialValueUsed(slot) ) { loadNil(); storeLocal(-1, slot); } } }
public void loadLocal(int pc, int slot) { boolean isupval = pi.isUpvalueRefer(pc, slot); int index = findSlotIndex( slot, isupval ); append(new ALOAD(index)); if (isupval) { append(new PUSH(cp, 0)); append(InstructionConstants.AALOAD); } }
public void loadUpvalue(int upindex) { boolean isrw = pi.isReadWriteUpvalue( pi.upvals[upindex] ); append(InstructionConstants.THIS); if ( isrw ) { append(factory.createFieldAccess(classname, upvalueName(upindex), TYPE_LOCALUPVALUE, Constants.GETFIELD)); append(new PUSH(cp,0)); append(InstructionConstants.AALOAD); } else { append(factory.createFieldAccess(classname, upvalueName(upindex), TYPE_LUAVALUE, Constants.GETFIELD)); } }
public void storeUpvalue(int pc, int upindex, int slot) { boolean isrw = pi.isReadWriteUpvalue( pi.upvals[upindex] ); append(InstructionConstants.THIS); if ( isrw ) { append(factory.createFieldAccess(classname, upvalueName(upindex), TYPE_LOCALUPVALUE, Constants.GETFIELD)); append(new PUSH(cp,0)); loadLocal(pc, slot); append(InstructionConstants.AASTORE); } else { loadLocal(pc, slot); append(factory.createFieldAccess(classname, upvalueName(upindex), TYPE_LUAVALUE, Constants.PUTFIELD)); } }
public void arg(int argindex) { if ( argindex == 1 ) { append(factory.createInvoke(STR_VARARGS, "arg1", TYPE_LUAVALUE, ARG_TYPES_NONE, Constants.INVOKEVIRTUAL)); } else { append(new PUSH(cp, argindex)); append(factory.createInvoke(STR_VARARGS, "arg", TYPE_LUAVALUE, ARG_TYPES_INT, Constants.INVOKEVIRTUAL)); } }
public void loadArrayArgs(int pc, int firstslot, int nargs) { append(new PUSH(cp, nargs)); append(new ANEWARRAY(cp.addClass(STR_LUAVALUE))); for ( int i=0; i<nargs; i++ ) { append(InstructionConstants.DUP); append(new PUSH(cp, i)); loadLocal(pc, firstslot++); append(new AASTORE()); } }
private String createLuaIntegerField(int value) { String name = PREFIX_CONSTANT+constants.size(); FieldGen fg = new FieldGen(Constants.ACC_STATIC | Constants.ACC_FINAL, TYPE_LUAVALUE, name, cp); cg.addField(fg.getField()); init.append(new PUSH(cp, value)); init.append(factory.createInvoke(STR_LUAVALUE, "valueOf", TYPE_LUAINTEGER, ARG_TYPES_INT, Constants.INVOKESTATIC)); init.append(factory.createPutStatic(classname, name, TYPE_LUAVALUE)); return name; }
private String createLuaDoubleField(double value) { String name = PREFIX_CONSTANT+constants.size(); FieldGen fg = new FieldGen(Constants.ACC_STATIC | Constants.ACC_FINAL, TYPE_LUAVALUE, name, cp); cg.addField(fg.getField()); init.append(new PUSH(cp, value)); init.append(factory.createInvoke(STR_LUAVALUE, "valueOf", TYPE_LUANUMBER, ARG_TYPES_DOUBLE, Constants.INVOKESTATIC)); init.append(factory.createPutStatic(classname, name, TYPE_LUAVALUE)); return name; }
public void setlistStack(int pc, int a0, int index0, int nvals) { for ( int i=0; i<nvals; i++ ) { dup(); append(new PUSH(cp, index0+i)); loadLocal( pc, a0+i ); append(factory.createInvoke(STR_LUAVALUE, "rawset", Type.VOID, ARG_TYPES_INT_LUAVALUE, Constants.INVOKEVIRTUAL)); } }
static byte[] bcelHelloWorld() { ClassGen cg = new ClassGen("HelloWorld", "java/lang/Object", "HelloWorld.java", Constants.ACC_PUBLIC, null); cg.addEmptyConstructor(Constants.ACC_PUBLIC); ConstantPoolGen cp = cg.getConstantPool(); org.apache.bcel.generic.InstructionList il = new org.apache.bcel.generic.InstructionList(); org.apache.bcel.generic.InstructionFactory factory = new org.apache.bcel.generic.InstructionFactory( cg); MethodGen mg = new MethodGen(Constants.ACC_STATIC | Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.VOID, new org.apache.bcel.generic.Type[] { new ArrayType( org.apache.bcel.generic.Type.STRING, 1) }, null, "main", "HelloWorld", il, cp); il.append(factory.createGetStatic("java/lang/System", "out", printStreamT)); il.append(new PUSH(cp, "Hello world!")); il.append(factory .createInvoke( "java.io.PrintStream", "println", org.apache.bcel.generic.Type.VOID, new org.apache.bcel.generic.Type[] { org.apache.bcel.generic.Type.STRING }, Constants.INVOKESPECIAL)); mg.setMaxStack(); cg.addMethod(mg.getMethod()); return cg.getJavaClass().getBytes(); }
static byte[] aspectjBcelHelloWorld() { org.aspectj.apache.bcel.generic.ClassGen cg = new org.aspectj.apache.bcel.generic.ClassGen( "HelloWorld", "java/lang/Object", "HelloWorld.java", Constants.ACC_PUBLIC, null); cg.addEmptyConstructor(Constants.ACC_PUBLIC); org.aspectj.apache.bcel.generic.ConstantPoolGen cp = cg .getConstantPool(); org.aspectj.apache.bcel.generic.InstructionList il = new org.aspectj.apache.bcel.generic.InstructionList(); org.aspectj.apache.bcel.generic.InstructionFactory factory = new org.aspectj.apache.bcel.generic.InstructionFactory( cg); org.aspectj.apache.bcel.generic.MethodGen mg = new org.aspectj.apache.bcel.generic.MethodGen( Constants.ACC_STATIC | Constants.ACC_PUBLIC, org.aspectj.apache.bcel.generic.Type.VOID, new org.aspectj.apache.bcel.generic.Type[] { new org.aspectj.apache.bcel.generic.ArrayType( org.aspectj.apache.bcel.generic.Type.STRING, 1) }, null, "main", "HelloWorld", il, cp); il.append(factory.createGetStatic("java/lang/System", "out", printStreamAT)); il.append(new org.aspectj.apache.bcel.generic.PUSH(cp, "Hello world!")); il.append(factory .createInvoke( "java.io.PrintStream", "println", org.aspectj.apache.bcel.generic.Type.VOID, new org.aspectj.apache.bcel.generic.Type[] { org.aspectj.apache.bcel.generic.Type.STRING }, Constants.INVOKESPECIAL)); mg.setMaxStack(); cg.addMethod(mg.getMethod()); return cg.getJavaClass().getBytes(); }
static byte[] bcelHelloWorld() { ClassGen cg = new ClassGen("HelloWorld", "java/lang/Object", "HelloWorld.java", Constants.ACC_PUBLIC, null); cg.addEmptyConstructor(Constants.ACC_PUBLIC); ConstantPoolGen cp = cg.getConstantPool(); org.apache.bcel.generic.InstructionList il = new org.apache.bcel.generic.InstructionList(); org.apache.bcel.generic.InstructionFactory factory = new org.apache.bcel.generic.InstructionFactory(cg); MethodGen mg = new MethodGen(Constants.ACC_STATIC | Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.VOID, new org.apache.bcel.generic.Type[] { new ArrayType(org.apache.bcel.generic.Type.STRING, 1) }, null, "main", "HelloWorld", il, cp); il.append(factory.createGetStatic("java/lang/System", "out", printStreamT)); il.append(new PUSH(cp, "Hello world!")); il.append(factory.createInvoke("java.io.PrintStream", "println", org.apache.bcel.generic.Type.VOID, new org.apache.bcel.generic.Type[] { org.apache.bcel.generic.Type.STRING }, Constants.INVOKESPECIAL)); mg.setMaxStack(); cg.addMethod(mg.getMethod()); return cg.getJavaClass().getBytes(); }
static byte[] aspectjBcelHelloWorld() { org.aspectj.apache.bcel.generic.ClassGen cg = new org.aspectj.apache.bcel.generic.ClassGen("HelloWorld", "java/lang/Object", "HelloWorld.java", Constants.ACC_PUBLIC, null); cg.addEmptyConstructor(Constants.ACC_PUBLIC); org.aspectj.apache.bcel.generic.ConstantPoolGen cp = cg.getConstantPool(); org.aspectj.apache.bcel.generic.InstructionList il = new org.aspectj.apache.bcel.generic.InstructionList(); org.aspectj.apache.bcel.generic.InstructionFactory factory = new org.aspectj.apache.bcel.generic.InstructionFactory(cg); org.aspectj.apache.bcel.generic.MethodGen mg = new org.aspectj.apache.bcel.generic.MethodGen(Constants.ACC_STATIC | Constants.ACC_PUBLIC, org.aspectj.apache.bcel.generic.Type.VOID, new org.aspectj.apache.bcel.generic.Type[] { new org.aspectj.apache.bcel.generic.ArrayType(org.aspectj.apache.bcel.generic.Type.STRING, 1) }, null, "main", "HelloWorld", il, cp); il.append(factory.createGetStatic("java/lang/System", "out", printStreamAT)); il.append(new org.aspectj.apache.bcel.generic.PUSH(cp, "Hello world!")); il.append(factory.createInvoke("java.io.PrintStream", "println", org.aspectj.apache.bcel.generic.Type.VOID, new org.aspectj.apache.bcel.generic.Type[] { org.aspectj.apache.bcel.generic.Type.STRING }, Constants.INVOKESPECIAL)); mg.setMaxStack(); cg.addMethod(mg.getMethod()); return cg.getJavaClass().getBytes(); }
private void generateStreamer(RootClass k, ConstantPoolGen cp, InstructionList il, InstructionFactory factory, String className) { if (k.getClassName().equals("TObject") && optimize) return; RootMember[] members = k.getMembers(); int multiplier = 1; for (int i = 0; i < members.length; i++) { BasicMember member = (BasicMember) members[i]; if (optimize && ((i + 1) < members.length) && (member.getArrayDim() == 0) && member.getJavaType().equals(((BasicMember) members[i + 1]).getJavaType())) { multiplier++; } else { Type type = member.getJavaType(); Type arrayType = new ArrayType(type, 1); il.append(InstructionConstants.ALOAD_0); il.append(InstructionConstants.ALOAD_1); il.append(InstructionConstants.ILOAD_2); //length if (multiplier > 1) { il.append(new PUSH(cp, multiplier)); il.append(InstructionConstants.IMUL); } String varCounter = member.getVarCounter(); if (varCounter == null) { for (int j = 0; j < member.getArrayDim(); j++) il.append(new PUSH(cp, member.getMaxIndex(j))); il.append((Instruction) factory.createNewArray(((BasicRootClass) member.getType()).getJavaType(), (short) (member.getArrayDim() + 1))); il.append(InstructionConstants.DUP_X1); if (member.getArrayDim() == 0) { if (type instanceof ObjectType) { il.append(new PUSH(cp,member.getType().getClassName())); il.append(factory.createInvoke("org.dianahep.root4j.core.IOUtils", "readFixedArray", Type.VOID, new Type[] { RootType.ROOTINPUT, new ArrayType(Type.OBJECT, 1), RootType.STRING }, INVOKESTATIC)); } else { il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readFixedArray", Type.VOID, new Type[] { arrayType }, INVOKEINTERFACE)); } } else { il.append(factory.createInvoke("org.dianahep.root4j.core.RootInput", "readMultiArray", Type.VOID, new Type[] { new ArrayType(Type.OBJECT, 1) }, INVOKEINTERFACE)); } } else { il.append((Instruction) factory.createNewArray(type, (short)1)); il.append(InstructionConstants.DUP_X1); il.append(InstructionConstants.ALOAD_0); il.append(factory.createFieldAccess(className, varCounter, RootType.INTARRAY, Constants.GETFIELD)); il.append(factory.createInvoke("org.dianahep.root4j.core.IOUtils", "readVariableMultiArray", Type.VOID, new Type[] { RootType.ROOTINPUT,arrayType,RootType.INTARRAY }, INVOKESTATIC)); } il.append(factory.createPutField(className, member.getName(), arrayType)); multiplier = 1; } } }
private static void generateMethods(RootClass k, ConstantPoolGen cp, InstructionList il, InstructionFactory factory, ClassGen cg, String className, Class implementedInterface) { RootMember[] members = k.getMembers(); for (int i = 0; i < members.length; i++) { Type type = ((BasicMember) members[i]).getJavaType(); Type returnType = type; try { if (implementedInterface != null) returnType = Type.getType(implementedInterface.getMethod(nameMangler.mangleMember(members[i].getName()),(Class[]) null).getReturnType()); if (!returnType.equals(type) && debugRoot) { System.err.println("Warning: Interface type mismatch "+implementedInterface.getName()+"."+nameMangler.mangleMember(members[i].getName())+" "+returnType+" "+type); } } catch (NoSuchMethodException x) { } if (cg.containsMethod(nameMangler.mangleMember(members[i].getName()), "()" + returnType.getSignature()) == null) { MethodGen mg = new MethodGen(ACC_PUBLIC, returnType, null, null, nameMangler.mangleMember(members[i].getName()), null, il, cp); if (members[i].getType() == null) // Dummy object { il.append(new PUSH(cp, "<<Unreadable>>")); } else { il.append(InstructionConstants.ALOAD_0); il.append(factory.createGetField(className, members[i].getName(), type)); } if (!returnType.equals(type) && !(returnType == Type.INT && (type == Type.BYTE || type == Type.CHAR || type == Type.SHORT))) il.append(factory.createCast(type,returnType)); il.append(InstructionFactory.createReturn(returnType)); mg.setMaxStack(); mg.setMaxLocals(); cg.addMethod(mg.getMethod()); il.dispose(); } } }
/** * Create interface method's args. * * @param numberOfArguments the number of arguments. * @param il an instruction list * @param variableIndex a varible index. * @param paramTypes parameter types * @param generatedClassName the generated class name. */ private void createInterfaceMethodArgs(int numberOfArguments, InstructionList il, int variableIndex, Class[] paramTypes, String generatedClassName) { Type previousType = null; int loadIndex = 0; for (int i = 0; i < numberOfArguments; i++) { // assigning the obj ref's il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex - 1)); il.append(new PUSH(constantsPool, i)); String className = paramTypes[i].getName(); //adjust for any previous wider datatype (double/long) if (previousType != null && (previousType == Type.DOUBLE || previousType == Type.LONG)) { ++loadIndex; } if (paramTypes[i].isPrimitive()) { il.append(factory.createNew(getJavaWrapperClass(className))); il.append(InstructionConstants.DUP); il.append(InstructionFactory.createLoad(getBCELPrimitiveType(className), ++loadIndex)); il.append(factory.createInvoke(getJavaWrapperClass(className), "<init>", Type.VOID, new Type[]{getBCELPrimitiveType(className)}, Constants.INVOKESPECIAL)); il.append(InstructionConstants.AASTORE); } else { //create the static fields for enabling .class calls String encodedFieldName; if (paramTypes[i].isArray()) { int index = className.lastIndexOf('['); if (className.charAt(index + 1) == 'L') { encodedFieldName = "array$" + className.substring(1 + index, className.length() - 1).replace('.', '$'); } else { encodedFieldName = "array$" + className.substring(1 + index, className.length()); } } else { encodedFieldName = "class$" + className.replace('.', '$'); } addField(encodedFieldName); // ******** TODO assign the obj reference il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex - 1)); il.append(new PUSH(constantsPool, i)); il.append(InstructionFactory.createLoad(Type.OBJECT, ++loadIndex)); il.append(InstructionConstants.AASTORE); // *********TODO assign the class ref's il.append(InstructionFactory.createLoad(Type.OBJECT, variableIndex)); il.append(new PUSH(constantsPool, i)); il.append(factory.createFieldAccess(generatedClassName, encodedFieldName, new ObjectType("java.lang.Class"), Constants.GETSTATIC)); BranchInstruction ifnull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null); il.append(ifnull); il.append(factory.createFieldAccess(generatedClassName, encodedFieldName, new ObjectType("java.lang.Class"), Constants.GETSTATIC)); BranchInstruction goHeadToStoreRef = InstructionFactory.createBranchInstruction(Constants.GOTO, null); il.append(goHeadToStoreRef); InstructionHandle ifnullStartHere = il.append(new PUSH(constantsPool, className)); ifnull.setTarget(ifnullStartHere); il.append(factory.createInvoke(generatedClassName, "class$", new ObjectType("java.lang.Class"), new Type[]{Type.STRING}, Constants.INVOKESTATIC)); il.append(InstructionConstants.DUP); il.append(factory.createFieldAccess(generatedClassName, encodedFieldName, new ObjectType("java.lang.Class"), Constants.PUTSTATIC)); InstructionHandle storeClassRef = il.append(InstructionConstants.AASTORE); goHeadToStoreRef.setTarget(storeClassRef); } previousType = getBCELPrimitiveType(className); } }
/** * @param il the instruction list * @param msg the message */ protected void createTestMethod(InstructionList il, String msg) { il.append(factory.createFieldAccess("java.lang.System", "out", new ObjectType("java.io.PrintStream"), Constants.GETSTATIC)); il.append(new PUSH(constantsPool, msg)); il.append(factory.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[]{Type.STRING}, Constants.INVOKEVIRTUAL)); }
public void newTable( int b, int c ) { append(new PUSH(cp, b)); append(new PUSH(cp, c)); append(factory.createInvoke(STR_LUAVALUE, "tableOf", TYPE_LUATABLE, ARG_TYPES_INT_INT, Constants.INVOKESTATIC)); }
public void subargs(int firstarg) { append(new PUSH(cp, firstarg)); append(factory.createInvoke(STR_VARARGS, "subargs", TYPE_VARARGS, ARG_TYPES_INT, Constants.INVOKEVIRTUAL)); }