aboutsummaryrefslogtreecommitdiffstats
path: root/src/proguard/classfile/instruction/visitor
diff options
context:
space:
mode:
Diffstat (limited to 'src/proguard/classfile/instruction/visitor')
-rw-r--r--src/proguard/classfile/instruction/visitor/AllInstructionVisitor.java56
-rw-r--r--src/proguard/classfile/instruction/visitor/InstructionCounter.java59
-rw-r--r--src/proguard/classfile/instruction/visitor/InstructionVisitor.java42
-rw-r--r--src/proguard/classfile/instruction/visitor/MultiInstructionVisitor.java131
-rw-r--r--src/proguard/classfile/instruction/visitor/package.html3
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>