diff options
author | Joe Onorato <joeo@android.com> | 2009-08-31 10:12:00 -0700 |
---|---|---|
committer | Joe Onorato <joeo@android.com> | 2009-08-31 10:12:00 -0700 |
commit | b72c5c2e5482cf10117b2b25f642f7616b2326c3 (patch) | |
tree | f02ba1bc29f4fe6853d9b7008eed37cdcfb96e81 /src/proguard/classfile/instruction/visitor | |
parent | a23344a828357fe4b6596f8af5fed467d72757ab (diff) | |
download | external_proguard-b72c5c2e5482cf10117b2b25f642f7616b2326c3.tar.gz external_proguard-b72c5c2e5482cf10117b2b25f642f7616b2326c3.tar.bz2 external_proguard-b72c5c2e5482cf10117b2b25f642f7616b2326c3.zip |
ProGuard 4.4android-2.1_r2.1sandroid-2.1_r2.1p2android-2.1_r2.1pandroid-2.1_r2android-2.1_r1android-2.0_r1android-2.0.1_r1
Diffstat (limited to 'src/proguard/classfile/instruction/visitor')
5 files changed, 291 insertions, 0 deletions
diff --git a/src/proguard/classfile/instruction/visitor/AllInstructionVisitor.java b/src/proguard/classfile/instruction/visitor/AllInstructionVisitor.java new file mode 100644 index 0000000..71b2cde --- /dev/null +++ b/src/proguard/classfile/instruction/visitor/AllInstructionVisitor.java @@ -0,0 +1,56 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.instruction.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.*; +import proguard.classfile.attribute.visitor.AttributeVisitor; +import proguard.classfile.util.SimplifiedVisitor; + +/** + * This AttributeVisitor lets a given InstructionVisitor visit all Instruction + * objects of the CodeAttribute objects it visits. + * + * @author Eric Lafortune + */ +public class AllInstructionVisitor +extends SimplifiedVisitor +implements AttributeVisitor +{ + private final InstructionVisitor instructionVisitor; + + + public AllInstructionVisitor(InstructionVisitor instructionVisitor) + { + this.instructionVisitor = instructionVisitor; + } + + + // Implementations for AttributeVisitor. + + public void visitAnyAttribute(Clazz clazz, Attribute attribute) {} + + + public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) + { + codeAttribute.instructionsAccept(clazz, method, instructionVisitor); + } +} diff --git a/src/proguard/classfile/instruction/visitor/InstructionCounter.java b/src/proguard/classfile/instruction/visitor/InstructionCounter.java new file mode 100644 index 0000000..1d10980 --- /dev/null +++ b/src/proguard/classfile/instruction/visitor/InstructionCounter.java @@ -0,0 +1,59 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.instruction.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.instruction.Instruction; +import proguard.classfile.util.SimplifiedVisitor; + +/** + * This InstructionVisitor counts the number of instructions that has been visited. + * + * @author Eric Lafortune + */ +public class InstructionCounter +extends SimplifiedVisitor +implements InstructionVisitor +{ + private int count; + + + /** + * Returns the number of instructions that has been visited so far. + */ + public int getCount() + { + return count; + } + + + // Implementations for InstructionVisitor. + + public void visitAnyInstruction(Clazz clazz, + Method method, + CodeAttribute codeAttribute, + int offset, + Instruction instruction) + { + count++; + } +} diff --git a/src/proguard/classfile/instruction/visitor/InstructionVisitor.java b/src/proguard/classfile/instruction/visitor/InstructionVisitor.java new file mode 100644 index 0000000..11af131 --- /dev/null +++ b/src/proguard/classfile/instruction/visitor/InstructionVisitor.java @@ -0,0 +1,42 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.instruction.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.instruction.*; + + +/** + * This interface specifies the methods for a visitor of + * <code>Instruction</code> objects. + * + * @author Eric Lafortune + */ +public interface InstructionVisitor +{ + public void visitSimpleInstruction( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction); + public void visitVariableInstruction( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction); + public void visitConstantInstruction( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction); + public void visitBranchInstruction( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction); + public void visitTableSwitchInstruction( Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction); + public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction); +} diff --git a/src/proguard/classfile/instruction/visitor/MultiInstructionVisitor.java b/src/proguard/classfile/instruction/visitor/MultiInstructionVisitor.java new file mode 100644 index 0000000..aada455 --- /dev/null +++ b/src/proguard/classfile/instruction/visitor/MultiInstructionVisitor.java @@ -0,0 +1,131 @@ +/* + * ProGuard -- shrinking, optimization, obfuscation, and preverification + * of Java bytecode. + * + * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package proguard.classfile.instruction.visitor; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.instruction.*; + + +/** + * This InstructionVisitor delegates all visits to each InstructionVisitor + * in a given list. + * + * @author Eric Lafortune + */ +public class MultiInstructionVisitor implements InstructionVisitor +{ + private static final int ARRAY_SIZE_INCREMENT = 5; + + + private InstructionVisitor[] instructionVisitors; + private int instructionVisitorCount; + + + public MultiInstructionVisitor() + { + } + + + public MultiInstructionVisitor(InstructionVisitor[] instructionVisitors) + { + this.instructionVisitors = instructionVisitors; + this.instructionVisitorCount = instructionVisitors.length; + } + + + public void addInstructionVisitor(InstructionVisitor instructionVisitor) + { + ensureArraySize(); + + instructionVisitors[instructionVisitorCount++] = instructionVisitor; + } + + + private void ensureArraySize() + { + if (instructionVisitors == null) + { + instructionVisitors = new InstructionVisitor[ARRAY_SIZE_INCREMENT]; + } + else if (instructionVisitors.length == instructionVisitorCount) + { + InstructionVisitor[] newInstructionVisitors = + new InstructionVisitor[instructionVisitorCount + + ARRAY_SIZE_INCREMENT]; + System.arraycopy(instructionVisitors, 0, + newInstructionVisitors, 0, + instructionVisitorCount); + instructionVisitors = newInstructionVisitors; + } + } + + + // Implementations for InstructionVisitor. + + public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction) + { + for (int index = 0; index < instructionVisitorCount; index++) + { + instructionVisitors[index].visitSimpleInstruction(clazz, method, codeAttribute, offset, simpleInstruction); + } + } + + public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction) + { + for (int index = 0; index < instructionVisitorCount; index++) + { + instructionVisitors[index].visitVariableInstruction(clazz, method, codeAttribute, offset, variableInstruction); + } + } + + public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) + { + for (int index = 0; index < instructionVisitorCount; index++) + { + instructionVisitors[index].visitConstantInstruction(clazz, method, codeAttribute, offset, constantInstruction); + } + } + + public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction) + { + for (int index = 0; index < instructionVisitorCount; index++) + { + instructionVisitors[index].visitBranchInstruction(clazz, method, codeAttribute, offset, branchInstruction); + } + } + + public void visitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction) + { + for (int index = 0; index < instructionVisitorCount; index++) + { + instructionVisitors[index].visitTableSwitchInstruction(clazz, method, codeAttribute, offset, tableSwitchInstruction); + } + } + + public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction) + { + for (int index = 0; index < instructionVisitorCount; index++) + { + instructionVisitors[index].visitLookUpSwitchInstruction(clazz, method, codeAttribute, offset, lookUpSwitchInstruction); + } + } +} diff --git a/src/proguard/classfile/instruction/visitor/package.html b/src/proguard/classfile/instruction/visitor/package.html new file mode 100644 index 0000000..a31a408 --- /dev/null +++ b/src/proguard/classfile/instruction/visitor/package.html @@ -0,0 +1,3 @@ +<body> +This package contains visitors for instructions. +</body> |