ACCESSCONSTRUCTOR added.

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1185 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
jochen 25 years ago
parent e00cff956c
commit 43a2e1ccfa
  1. 66
      jode/jode/jvm/SyntheticAnalyzer.java.in

@ -43,6 +43,7 @@ public class SyntheticAnalyzer implements Opcodes {
public final static int ACCESSGETSTATIC = 5; public final static int ACCESSGETSTATIC = 5;
public final static int ACCESSPUTSTATIC = 6; public final static int ACCESSPUTSTATIC = 6;
public final static int ACCESSSTATICMETHOD = 7; public final static int ACCESSSTATICMETHOD = 7;
public final static int ACCESSCONSTRUCTOR = 8;
int kind = UNKNOWN; int kind = UNKNOWN;
Reference reference; Reference reference;
@ -58,6 +59,9 @@ public class SyntheticAnalyzer implements Opcodes {
if (!checkName || method.getName().startsWith("access$")) if (!checkName || method.getName().startsWith("access$"))
if (checkAccess()) if (checkAccess())
return; return;
if (method.getName().equals("<init>"))
if (checkConstructorAccess())
return;
} }
public int getKind() { public int getKind() {
@ -151,8 +155,6 @@ public class SyntheticAnalyzer implements Opcodes {
if (instr.getOpcode() < opc_ireturn if (instr.getOpcode() < opc_ireturn
|| instr.getOpcode() > opc_areturn) || instr.getOpcode() > opc_areturn)
return false; return false;
if (iter.hasNext())
return false;
/* For valid bytecode the type matches automatically */ /* For valid bytecode the type matches automatically */
reference = ref; reference = ref;
kind = ACCESSGETSTATIC; kind = ACCESSGETSTATIC;
@ -184,8 +186,6 @@ public class SyntheticAnalyzer implements Opcodes {
instr = (Instruction) iter.next(); instr = (Instruction) iter.next();
if (instr.getOpcode() != opc_return) if (instr.getOpcode() != opc_return)
return false; return false;
if (iter.hasNext())
return false;
reference = ref; reference = ref;
kind = ACCESSPUTSTATIC; kind = ACCESSPUTSTATIC;
return true; return true;
@ -212,8 +212,6 @@ public class SyntheticAnalyzer implements Opcodes {
|| instr.getOpcode() > opc_areturn) || instr.getOpcode() > opc_areturn)
return false; return false;
} }
if (iter.hasNext())
return false;
/* For valid bytecode the types matches automatically */ /* For valid bytecode the types matches automatically */
reference = ref; reference = ref;
@ -255,8 +253,6 @@ public class SyntheticAnalyzer implements Opcodes {
if (instr.getOpcode() < opc_ireturn if (instr.getOpcode() < opc_ireturn
|| instr.getOpcode() > opc_areturn) || instr.getOpcode() > opc_areturn)
return false; return false;
if (iter.hasNext())
return false;
/* For valid bytecode the type matches automatically */ /* For valid bytecode the type matches automatically */
reference = ref; reference = ref;
kind = ACCESSGETFIELD; kind = ACCESSGETFIELD;
@ -287,8 +283,6 @@ public class SyntheticAnalyzer implements Opcodes {
instr = (Instruction) iter.next(); instr = (Instruction) iter.next();
if (instr.getOpcode() != opc_return) if (instr.getOpcode() != opc_return)
return false; return false;
if (iter.hasNext())
return false;
reference = ref; reference = ref;
kind = ACCESSPUTFIELD; kind = ACCESSPUTFIELD;
return true; return true;
@ -314,8 +308,6 @@ public class SyntheticAnalyzer implements Opcodes {
|| instr.getOpcode() > opc_areturn) || instr.getOpcode() > opc_areturn)
return false; return false;
} }
if (iter.hasNext())
return false;
/* For valid bytecode the types matches automatically */ /* For valid bytecode the types matches automatically */
reference = ref; reference = ref;
@ -324,4 +316,54 @@ public class SyntheticAnalyzer implements Opcodes {
} }
return false; return false;
} }
public boolean checkConstructorAccess() {
ClassInfo clazzInfo = method.getClazzInfo();
BytecodeInfo bytecode = method.getBytecode();
Handler[] excHandlers = bytecode.getExceptionHandlers();
if (excHandlers != null && excHandlers.length != 0)
return false;
Iterator iter = bytecode.getInstructions().iterator();
Instruction instr = (Instruction) iter.next();
if (instr.getOpcode() != opc_aload || instr.getLocalSlot() != 0)
return false;
instr = (Instruction) iter.next();
// slot begins with 2. Slot 1 contains a dummy value, that
// is used so that the constructor has a different type signature.
int params = 0, slot = 2;
while (instr.getOpcode() >= opc_iload
&& instr.getOpcode() <= opc_aload
&& instr.getLocalSlot() == slot) {
params++;
slot += (instr.getOpcode() == opc_lload
|| instr.getOpcode() == opc_dload) ? 2 : 1;
instr = (Instruction) iter.next();
} }
if (instr.getOpcode() == opc_invokespecial) {
Reference ref = instr.getReference();
String refClazz = ref.getClazz().substring(1);
if (!(refClazz.substring(0, refClazz.length()-1)
.equals(clazzInfo.getName().replace('.','/'))))
return false;
MethodInfo refMethod
= clazzInfo.findMethod(ref.getName(), ref.getType());
MethodType refType = Type.tMethod(ref.getType());
if ((refMethod.getModifiers() & modifierMask) != Modifier.PRIVATE
|| !refMethod.getName().equals("<init>")
|| refType.getParameterTypes().length != params)
return false;
instr = (Instruction) iter.next();
if (instr.getOpcode() != opc_return)
return false;
/* For valid bytecode the types matches automatically */
reference = ref;
kind = ACCESSCONSTRUCTOR;
return true;
}
return false;
}
}

Loading…
Cancel
Save