}
methodVisitor.visitCode();
}
+
+ public LocalVariable getThis(TypeDesc type) {
+ return new LocalVariable(0, type);
+ }
public void loadConstant(boolean value) {
if(value)
public void invokeInterface(String className, String methodName,
TypeDesc ret, TypeDesc[] params) {
checkClassName(className);
+ checkParameters(params);
methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, className, methodName,
MethodDesc.forArguments(ret, params).getDescriptor(), true);
}
public void invokeVirtual(String className, String methodName,
TypeDesc ret, TypeDesc[] params) {
checkClassName(className);
+ checkParameters(params);
methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, methodName,
MethodDesc.forArguments(ret, params).getDescriptor(), false);
}
public void invokeConstructor(String className, TypeDesc[] params) {
checkClassName(className);
+ checkParameters(params);
methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "<init>",
MethodDesc.forArguments(TypeDesc.VOID, params).getDescriptor(), false);
}
public void invokeStatic(String className, String methodName, TypeDesc ret,
TypeDesc[] params) {
checkClassName(className);
+ checkParameters(params);
methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, className, methodName,
MethodDesc.forArguments(ret, params).getDescriptor(), false);
}
public void newObject(TypeDesc type) {
methodVisitor.visitTypeInsn(Opcodes.NEW, getClassName(type));
}
+
+ public void newObject(String type) {
+ methodVisitor.visitTypeInsn(Opcodes.NEW, type);
+ }
public void newObject(TypeDesc type, int dimensions) {
methodVisitor.visitMultiANewArrayInsn(type.getDescriptor(), dimensions);
public static String getClassName(Class<?> clazz) {
return clazz.getName().replace('.', '/');
}
+
+ public void switch_(int[] values, Label[] labels, Label defaultLabel) {
+ int lo = values[0];
+ int hi = values[values.length-1];
+ long table_space_cost = 4 + ((long) hi - lo + 1); // words
+ long table_time_cost = 3; // comparisons
+ long lookup_space_cost = 3 + 2 * (long) values.length;
+ long lookup_time_cost = values.length;
+ if(values.length > 0 &&
+ table_space_cost + 3 * table_time_cost <=
+ lookup_space_cost + 3 * lookup_time_cost) {
+ Label[] table = new Label[hi - lo + 1];
+ for(int i=0,j=0;i<table.length;++i) {
+ int id = lo+i;
+ if(values[j] == id) {
+ table[i] = labels[j];
+ ++j;
+ }
+ else
+ table[i] = defaultLabel;
+ }
+ methodVisitor.visitTableSwitchInsn(lo, hi, defaultLabel, table);
+ }
+ else
+ methodVisitor.visitLookupSwitchInsn(defaultLabel, values, labels);
+ }
+
+ private static void checkParameters(TypeDesc[] params) {
+ for(TypeDesc param : params)
+ if(param.equals(TypeDesc.VOID))
+ throw new IllegalArgumentException();
+ }
}