1 21 package proguard.classfile.editor; 22 23 import proguard.classfile.util.*; 24 import proguard.classfile.attribute.visitor.*; 25 import proguard.classfile.attribute.*; 26 import proguard.classfile.instruction.visitor.InstructionVisitor; 27 import proguard.classfile.instruction.*; 28 import proguard.classfile.*; 29 30 36 public class VariableSizeUpdater 37 extends SimplifiedVisitor 38 implements AttributeVisitor, 39 InstructionVisitor 40 { 41 private static final boolean DEBUG = false; 43 46 47 48 50 public void visitAnyAttribute(Clazz clazz, Attribute attribute) {} 51 52 53 public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) 54 { 55 59 codeAttribute.u2maxLocals = ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz)); 61 62 if ((method.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) == 0) 64 { 65 codeAttribute.u2maxLocals++; 66 } 67 68 if (DEBUG) 69 { 70 System.out.println("VariableSizeUpdater: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)); 71 System.out.println("Max locals: "+codeAttribute.u2maxLocals+" <- parameters"); 72 } 73 74 codeAttribute.instructionsAccept(clazz, method, this); 76 } 77 78 79 81 public void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) {} 82 83 84 public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction) 85 { 86 int variableSize = variableInstruction.variableIndex + 1; 87 if (variableInstruction.isCategory2()) 88 { 89 variableSize++; 90 } 91 92 if (codeAttribute.u2maxLocals < variableSize) 93 { 94 codeAttribute.u2maxLocals = variableSize; 95 96 if (DEBUG) 97 { 98 System.out.println("Max locals: "+codeAttribute.u2maxLocals+" <- "+variableInstruction.toString(offset)); 99 } 100 } 101 } 102 } 103 | Popular Tags |