aboutsummaryrefslogtreecommitdiffstats
path: root/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2024-03-15 13:41:59 +0100
committerAlexander Kriegisch <Alexander@Kriegisch.name>2024-03-15 19:27:30 +0100
commit17795394ff051ddfe02d717f6df327e63835a270 (patch)
tree3c618e5c1800356dc77ff92041481b2cab028cc7 /bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util
parent9df260e17a040b03cdb9b8451e022f6d88eb83d5 (diff)
downloadaspectj-17795394ff051ddfe02d717f6df327e63835a270.tar.gz
aspectj-17795394ff051ddfe02d717f6df327e63835a270.zip
Remove bcel-builder/verifier-src
It looks as if the source code is never built and never used either. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util')
-rw-r--r--bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java366
-rw-r--r--bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELifier.java341
-rw-r--r--bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/InstructionFinder.java440
3 files changed, 0 insertions, 1147 deletions
diff --git a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java
deleted file mode 100644
index 0b7912bc0..000000000
--- a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java
+++ /dev/null
@@ -1,366 +0,0 @@
-package org.aspectj.apache.bcel.verifier.util;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.Utility;
-import org.aspectj.apache.bcel.generic.BranchHandle;
-import org.aspectj.apache.bcel.generic.CodeExceptionGen;
-import org.aspectj.apache.bcel.generic.FieldInstruction;
-import org.aspectj.apache.bcel.generic.IINC;
-import org.aspectj.apache.bcel.generic.Instruction;
-import org.aspectj.apache.bcel.generic.InstructionBranch;
-import org.aspectj.apache.bcel.generic.InstructionByte;
-import org.aspectj.apache.bcel.generic.InstructionCP;
-import org.aspectj.apache.bcel.generic.InstructionConstants;
-import org.aspectj.apache.bcel.generic.InstructionHandle;
-import org.aspectj.apache.bcel.generic.InstructionSelect;
-import org.aspectj.apache.bcel.generic.InvokeInstruction;
-import org.aspectj.apache.bcel.generic.MULTIANEWARRAY;
-import org.aspectj.apache.bcel.generic.MethodGen;
-import org.aspectj.apache.bcel.generic.ObjectType;
-import org.aspectj.apache.bcel.generic.RET;
-import org.aspectj.apache.bcel.generic.Type;
-import org.aspectj.apache.bcel.verifier.InstructionWalker;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (https://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache BCEL" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache BCEL", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <https://www.apache.org/>.
- */
-
-/**
- * Factory creates il.append() statements, and sets instruction targets. A helper class for BCELifier.
- *
- * @see BCELifier
- * @version $Id: BCELFactory.java,v 1.6 2009/09/14 20:29:10 aclement Exp $
- * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
- */
-class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor {
- private final MethodGen _mg;
- private final PrintWriter _out;
- private final ConstantPool _cp;
-
- BCELFactory(MethodGen mg, PrintWriter out) {
- _mg = mg;
- _cp = mg.getConstantPool();
- _out = out;
- }
-
- private final HashMap<Instruction, InstructionHandle> branch_map = new HashMap<Instruction, InstructionHandle>(); // Map<Instruction,
- // InstructionHandle>
-
- public void start() {
- if (!_mg.isAbstract() && !_mg.isNative()) {
- for (InstructionHandle ih = _mg.getInstructionList().getStart(); ih != null; ih = ih.getNext()) {
- Instruction i = ih.getInstruction();
-
- if (i instanceof InstructionBranch) {
- branch_map.put(i, ih); // memorize container
- }
-
- if (ih.hasTargeters()) {
- if (i instanceof InstructionBranch) {
- _out.println(" InstructionHandle ih_" + ih.getPosition() + ";");
- } else {
- _out.print(" InstructionHandle ih_" + ih.getPosition() + " = ");
- }
- } else {
- _out.print(" ");
- }
-
- if (!visitInstruction(i)) {
- InstructionWalker.accept(i, this);
- }
- }
-
- updateBranchTargets();
- updateExceptionHandlers();
- }
- }
-
- private boolean visitInstruction(Instruction i) {
- short opcode = i.getOpcode();
-
- if (InstructionConstants.INSTRUCTIONS[opcode] != null && !i.isConstantInstruction() && !i.isReturnInstruction()) { // Handled
- // below
- _out.println("il.append(InstructionConstants." + i.getName().toUpperCase() + ");");
- return true;
- }
-
- return false;
- }
-
- public void visitLocalVariableInstruction(Instruction i) {
- short opcode = i.getOpcode();
- Type type = i.getType(_cp);
-
- if (opcode == Constants.IINC) {
- _out.println("il.append(new IINC(" + i.getIndex() + ", " + ((IINC) i).getIncrement() + "));");
- } else {
- String kind = opcode < Constants.ISTORE ? "Load" : "Store";
- _out.println("il.append(_factory.create" + kind + "(" + BCELifier.printType(type) + ", " + i.getIndex() + "));");
- }
- }
-
- @Override
- public void visitArrayInstruction(Instruction i) {
- short opcode = i.getOpcode();
- Type type = i.getType(_cp);
- String kind = opcode < Constants.IASTORE ? "Load" : "Store";
-
- _out.println("il.append(_factory.createArray" + kind + "(" + BCELifier.printType(type) + "));");
- }
-
- public void visitFieldInstruction(FieldInstruction i) {
- short opcode = i.getOpcode();
-
- String class_name = i.getClassName(_cp);
- String field_name = i.getFieldName(_cp);
- Type type = i.getFieldType(_cp);
-
- _out.println("il.append(_factory.createFieldAccess(\"" + class_name + "\", \"" + field_name + "\", "
- + BCELifier.printType(type) + ", " + "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() + "));");
- }
-
- @Override
- public void visitInvokeInstruction(InvokeInstruction i) {
- short opcode = i.getOpcode();
- String class_name = i.getClassName(_cp);
- String method_name = i.getMethodName(_cp);
- Type type = i.getReturnType(_cp);
- Type[] arg_types = i.getArgumentTypes(_cp);
-
- _out.println("il.append(_factory.createInvoke(\"" + class_name + "\", \"" + method_name + "\", "
- + BCELifier.printType(type) + ", " + BCELifier.printArgumentTypes(arg_types) + ", " + "Constants."
- + Constants.OPCODE_NAMES[opcode].toUpperCase() + "));");
- }
-
- @Override
- public void visitAllocationInstruction(Instruction i) {
- Type type;
-
- if (i.isConstantPoolInstruction()) {
- type = ((InstructionCP) i).getType(_cp);
- } else {
- type = ((InstructionByte) i).getType();
- }
-
- short opcode = i.getOpcode();
- int dim = 1;
-
- switch (opcode) {
- case Constants.NEW:
- _out.println("il.append(_factory.createNew(\"" + ((ObjectType) type).getClassName() + "\"));");
- break;
-
- case Constants.MULTIANEWARRAY:
- dim = ((MULTIANEWARRAY) i).getDimensions();
- case Constants.ANEWARRAY:
- case Constants.NEWARRAY:
- _out.println("il.append(_factory.createNewArray(" + BCELifier.printType(type) + ", (short) " + dim + "));");
- break;
-
- default:
- throw new RuntimeException("Oops: " + opcode);
- }
- }
-
- private void createConstant(Object value) {
- String embed = value.toString();
-
- if (value instanceof String) {
- embed = '"' + Utility.convertString(value.toString()) + '"';
- } else if (value instanceof Character) {
- embed = "(char)0x" + Integer.toHexString(((Character) value).charValue());
- }
-
- _out.println("il.append(new PUSH(_cp, " + embed + "));");
- }
-
- @Override
- public void visitLDC(Instruction i) {
- createConstant(i.getValue(_cp));
- }
-
- @Override
- public void visitLDC2_W(Instruction i) {
- createConstant(i.getValue(_cp));
- }
-
- @Override
- public void visitConstantPushInstruction(Instruction i) {
- createConstant(i.getValue());
- }
-
- @Override
- public void visitINSTANCEOF(Instruction i) {
- Type type = i.getType(_cp);
-
- _out.println("il.append(new INSTANCEOF(_cp.addClass(" + BCELifier.printType(type) + ")));");
- }
-
- @Override
- public void visitCHECKCAST(Instruction i) {
- Type type = i.getType(_cp);
-
- _out.println("il.append(_factory.createCheckCast(" + BCELifier.printType(type) + "));");
- }
-
- @Override
- public void visitReturnInstruction(Instruction i) {
- Type type = i.getType(_cp);
-
- _out.println("il.append(_factory.createReturn(" + BCELifier.printType(type) + "));");
- }
-
- // Memorize BranchInstructions that need an update
- private final ArrayList<InstructionBranch> branches = new ArrayList<InstructionBranch>();
-
- @Override
- public void visitBranchInstruction(InstructionBranch bi) {
- BranchHandle bh = (BranchHandle) branch_map.get(bi);
- int pos = bh.getPosition();
- String name = bi.getName() + "_" + pos;
-
- if (bi instanceof InstructionSelect) {
- InstructionSelect s = (InstructionSelect) bi;
- branches.add(bi);
-
- StringBuffer args = new StringBuffer("new int[] { ");
- int[] matchs = s.getMatchs();
-
- for (int i = 0; i < matchs.length; i++) {
- args.append(matchs[i]);
-
- if (i < matchs.length - 1) {
- args.append(", ");
- }
- }
-
- args.append(" }");
-
- _out.print(" Select " + name + " = new " + bi.getName().toUpperCase() + "(" + args + ", new InstructionHandle[] { ");
-
- for (int i = 0; i < matchs.length; i++) {
- _out.print("null");
-
- if (i < matchs.length - 1) {
- _out.print(", ");
- }
- }
-
- _out.println(");");
- } else {
- int t_pos = bh.getTarget().getPosition();
- String target;
-
- if (pos > t_pos) {
- target = "ih_" + t_pos;
- } else {
- branches.add(bi);
- target = "null";
- }
-
- _out.println(" BranchInstruction " + name + " = _factory.createBranchInstruction(" + "Constants."
- + bi.getName().toUpperCase() + ", " + target + ");");
- }
-
- if (bh.hasTargeters()) {
- _out.println(" ih_" + pos + " = il.append(" + name + ");");
- } else {
- _out.println(" il.append(" + name + ");");
- }
- }
-
- @Override
- public void visitRET(RET i) {
- _out.println("il.append(new RET(" + i.getIndex() + ")));");
- }
-
- private void updateBranchTargets() {
- for (Iterator<InstructionBranch> i = branches.iterator(); i.hasNext();) {
- InstructionBranch bi = i.next();
- BranchHandle bh = (BranchHandle) branch_map.get(bi);
- int pos = bh.getPosition();
- String name = bi.getName() + "_" + pos;
- int t_pos = bh.getTarget().getPosition();
-
- _out.println(" " + name + ".setTarget(ih_" + t_pos + ");");
-
- if (bi instanceof InstructionSelect) {
- InstructionHandle[] ihs = ((InstructionSelect) bi).getTargets();
-
- for (int j = 0; j < ihs.length; j++) {
- t_pos = ihs[j].getPosition();
-
- _out.println(" " + name + ".setTarget(" + j + ", ih_" + t_pos + ");");
- }
- }
- }
- }
-
- private void updateExceptionHandlers() {
- CodeExceptionGen[] handlers = _mg.getExceptionHandlers();
-
- for (int i = 0; i < handlers.length; i++) {
- CodeExceptionGen h = handlers[i];
- String type = h.getCatchType() == null ? "null" : BCELifier.printType(h.getCatchType());
-
- _out.println(" method.addExceptionHandler(" + "ih_" + h.getStartPC().getPosition() + ", " + "ih_"
- + h.getEndPC().getPosition() + ", " + "ih_" + h.getHandlerPC().getPosition() + ", " + type + ");");
- }
- }
-}
diff --git a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELifier.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELifier.java
deleted file mode 100644
index 0e2eddb00..000000000
--- a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELifier.java
+++ /dev/null
@@ -1,341 +0,0 @@
-package org.aspectj.apache.bcel.verifier.util;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (https://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache BCEL" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache BCEL", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <https://www.apache.org/>.
- */
-import java.io.OutputStream;
-import java.io.PrintWriter;
-
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.Repository;
-import org.aspectj.apache.bcel.classfile.ClassParser;
-import org.aspectj.apache.bcel.classfile.ConstantValue;
-import org.aspectj.apache.bcel.classfile.Field;
-import org.aspectj.apache.bcel.classfile.JavaClass;
-import org.aspectj.apache.bcel.classfile.Method;
-import org.aspectj.apache.bcel.classfile.Utility;
-import org.aspectj.apache.bcel.generic.ArrayType;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.generic.MethodGen;
-import org.aspectj.apache.bcel.generic.Type;
-
-/**
- * This class takes a given JavaClass object and converts it to a
- * Java program that creates that very class using BCEL. This
- * gives new users of BCEL a useful example showing how things
- * are done with BCEL. It does not cover all features of BCEL,
- * but tries to mimic hand-written code as close as possible.
- *
- * @version $Id: BCELifier.java,v 1.2 2008/05/28 23:53:04 aclement Exp $
- * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
- */
-public class BCELifier extends org.aspectj.apache.bcel.verifier.EmptyClassVisitor {
- private JavaClass _clazz;
- private PrintWriter _out;
- private ConstantPool _cp;
-
- /** @param clazz Java class to "decompile"
- * @param out where to output Java program
- */
- public BCELifier(JavaClass clazz, OutputStream out) {
- _clazz = clazz;
- _out = new PrintWriter(out);
- _cp = new ConstantPool(_clazz.getConstantPool().getConstantPool());
- }
-
- /** Start Java code generation
- */
- public void start() {
- visitJavaClass(_clazz);
- _out.flush();
- }
-
- public void visitJavaClass(JavaClass clazz) {
- String class_name = clazz.getClassName();
- String super_name = clazz.getSuperclassName();
- String package_name = clazz.getPackageName();
- String inter = BCELifier.printArray(clazz.getInterfaceNames(),
- false, true);
- if(!"".equals(package_name)) {
- class_name = class_name.substring(package_name.length() + 1);
- _out.println("package " + package_name + ";\n");
- }
-
- _out.println("import org.aspectj.apache.bcel.generic.*;");
- _out.println("import org.aspectj.apache.bcel.classfile.*;");
- _out.println("import org.aspectj.apache.bcel.*;");
- _out.println("import java.io.*;\n");
-
- _out.println("public class " + class_name + "Creator implements Constants {");
- _out.println(" private InstructionFactory _factory;");
- _out.println(" private ConstantPoolGen _cp;");
- _out.println(" private ClassGen _cg;\n");
-
- _out.println(" public " + class_name + "Creator() {");
- _out.println(" _cg = new ClassGen(\"" +
- (("".equals(package_name))? class_name :
- package_name + "." + class_name) +
- "\", \"" + super_name + "\", " +
- "\"" + clazz.getSourceFileName() + "\", " +
- printFlags(clazz.getModifiers(), true) + ", " +
- "new String[] { " + inter + " });\n");
-
- _out.println(" _cp = _cg.getConstantPool();");
- _out.println(" _factory = new InstructionFactory(_cg, _cp);");
- _out.println(" }\n");
-
- printCreate();
-
- Field[] fields = clazz.getFields();
-
- if(fields.length > 0) {
- _out.println(" private void createFields() {");
- _out.println(" FieldGen field;");
-
- for(int i=0; i < fields.length; i++) {
- fields[i].accept(this);
- }
-
- _out.println(" }\n");
- }
-
- Method[] methods = clazz.getMethods();
-
- for(int i=0; i < methods.length; i++) {
- _out.println(" private void createMethod_" + i + "() {");
-
- methods[i].accept(this);
- _out.println(" }\n");
- }
-
- printMain();
- _out.println("}");
- }
-
- private void printCreate() {
- _out.println(" public void create(OutputStream out) throws IOException {");
-
- Field[] fields = _clazz.getFields();
- if(fields.length > 0) {
- _out.println(" createFields();");
- }
-
- Method[] methods = _clazz.getMethods();
- for(int i=0; i < methods.length; i++) {
- _out.println(" createMethod_" + i + "();");
- }
-
- _out.println(" _cg.getJavaClass().dump(out);");
-
- _out.println(" }\n");
- }
-
- private void printMain() {
- String class_name = _clazz.getClassName();
-
- _out.println(" public static void main(String[] args) throws Exception {");
- _out.println(" " + class_name + "Creator creator = new " +
- class_name + "Creator();");
- _out.println(" creator.create(new FileOutputStream(\"" + class_name +
- ".class\"));");
- _out.println(" }");
- }
-
- public void visitField(Field field) {
- _out.println("\n field = new FieldGen(" +
- printFlags(field.getModifiers()) +
- ", " + printType(field.getSignature()) + ", \"" +
- field.getName() + "\", _cp);");
-
- ConstantValue cv = field.getConstantValue();
-
- if(cv != null) {
- String value = cv.toString();
- _out.println(" field.setInitValue(" + value + ")");
- }
-
- _out.println(" _cg.addField(field.getField());");
- }
-
- public void visitMethod(Method method) {
- MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp);
-
- Type result_type = mg.getReturnType();
- Type[] arg_types = mg.getArgumentTypes();
-
- _out.println(" InstructionList il = new InstructionList();");
- _out.println(" MethodGen method = new MethodGen(" +
- printFlags(method.getModifiers()) +
- ", " + printType(result_type) +
- ", " + printArgumentTypes(arg_types) + ", " +
- "new String[] { " +
- BCELifier.printArray(mg.getArgumentNames(), false, true) +
- " }, \"" + method.getName() + "\", \"" +
- _clazz.getClassName() + "\", il, _cp);\n");
-
- BCELFactory factory = new BCELFactory(mg, _out);
- factory.start();
-
- _out.println(" method.setMaxStack();");
- _out.println(" method.setMaxLocals();");
- _out.println(" _cg.addMethod(method.getMethod());");
- _out.println(" il.dispose();");
- }
-
- public static final String printArray(Object[] obj, boolean braces,
- boolean quote) {
- if(obj == null)
- return null;
-
- StringBuffer buf = new StringBuffer();
- if(braces)
- buf.append('{');
-
- for(int i=0; i < obj.length; i++) {
- if(obj[i] != null) {
- buf.append((quote? "\"" : "") + obj[i].toString() + (quote? "\"" : ""));
- } else {
- buf.append("null");
- }
-
- if(i < obj.length - 1) {
- buf.append(", ");
- }
- }
-
- if(braces)
- buf.append('}');
-
- return buf.toString();
- }
-
-static String printFlags(int flags) {
- return printFlags(flags, false);
- }
-
- static String printFlags(int flags, boolean for_class) {
- if(flags == 0)
- return "0";
-
- StringBuffer buf = new StringBuffer();
- for(int i=0, pow=1; i <= Constants.MAX_ACC_FLAG; i++) {
- if((flags & pow) != 0) {
- if((pow == Constants.ACC_SYNCHRONIZED) && for_class)
- buf.append("ACC_SUPER | ");
- else
- buf.append("ACC_" + Constants.ACCESS_NAMES[i].toUpperCase() + " | ");
- }
-
- pow <<= 1;
- }
-
- String str = buf.toString();
- return str.substring(0, str.length() - 3);
- }
-
- static String printArgumentTypes(Type[] arg_types) {
- if(arg_types.length == 0)
- return "Type.NO_ARGS";
-
- StringBuffer args = new StringBuffer();
-
- for(int i=0; i < arg_types.length; i++) {
- args.append(printType(arg_types[i]));
-
- if(i < arg_types.length - 1)
- args.append(", ");
- }
-
- return "new Type[] { " + args.toString() + " }";
- }
-
- static String printType(Type type) {
- return printType(type.getSignature());
- }
-
- static String printType(String signature) {
- Type type = Type.getType(signature);
- byte t = type.getType();
-
- if(t <= Constants.T_VOID) {
- return "Type." + Constants.TYPE_NAMES[t].toUpperCase();
- } else if(type.toString().equals("java.lang.String")) {
- return "Type.STRING";
- } else if(type.toString().equals("java.lang.Object")) {
- return "Type.OBJECT";
- } else if(type.toString().equals("java.lang.StringBuffer")) {
- return "Type.STRINGBUFFER";
- } else if(type instanceof ArrayType) {
- ArrayType at = (ArrayType)type;
-
- return "new ArrayType(" + printType(at.getBasicType()) +
- ", " + at.getDimensions() + ")";
- } else {
- return "new ObjectType(\"" + Utility.signatureToString(signature, false) +
- "\")";
- }
- }
-
- /** Default main method
- */
- public static void main(String[] argv) throws Exception {
- JavaClass java_class;
- String name = argv[0];
-
- if((java_class = Repository.lookupClass(name)) == null)
- java_class = new ClassParser(name).parse(); // May throw IOException
-
- BCELifier bcelifier = new BCELifier(java_class, System.out);
- bcelifier.start();
- }
-}
diff --git a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/InstructionFinder.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/InstructionFinder.java
deleted file mode 100644
index a695ac9db..000000000
--- a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/InstructionFinder.java
+++ /dev/null
@@ -1,440 +0,0 @@
-package org.aspectj.apache.bcel.verifier.util;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (https://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache BCEL" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache BCEL", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <https://www.apache.org/>.
- */
-
-import java.util.*;
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.generic.*;
-import org.apache.regexp.*;
-
-/**
- * InstructionFinder is a tool to search for given instructions patterns,
- * i.e., match sequences of instructions in an instruction list via
- * regular expressions. This can be used, e.g., in order to implement
- * a peep hole optimizer that looks for code patterns and replaces
- * them with faster equivalents.
- *
- * <p>This class internally uses the <a href="https://jakarta.apache.org/regexp/">
- * Regexp</a> package to search for regular expressions.
- *
- * A typical application would look like this:
-<pre>
- InstructionFinder f = new InstructionFinder(il);
- String pat = "IfInstruction ICONST_0 GOTO ICONST_1 NOP (IFEQ|IFNE)";
-
- for(Iterator i = f.search(pat, constraint); i.hasNext(); ) {
- InstructionHandle[] match = (InstructionHandle[])i.next();
- ...
- il.delete(match[1], match[5]);
- ...
- }
-</pre>
- * @version $Id: InstructionFinder.java,v 1.4 2009/09/09 19:56:20 aclement Exp $
- * @author <A HREF="https://www.berlin.de/~markus.dahm/">M. Dahm</A>
- * @see Instruction
- * @see InstructionList
- */
-public class InstructionFinder {
- private static final int OFFSET = 32767; // char + OFFSET is outside of LATIN-1
- private static final int NO_OPCODES = 256; // Potential number, some are not used
-
- private static final HashMap<String, String> map = new HashMap<String, String>(); // Map<String,Pattern>
-
- private InstructionList il;
- private String il_string; // instruction list as string
- private InstructionHandle[] handles; // map instruction list to array
-
- /**
- * @param il instruction list to search for given patterns
- */
- public InstructionFinder(InstructionList il) {
- this.il = il;
- reread();
- }
-
- /**
- * Reread the instruction list, e.g., after you've altered the list upon a match.
- */
- public final void reread() {
- int size = il.getLength();
- char[] buf = new char[size]; // Create a string with length equal to il length
- handles = il.getInstructionHandles();
-
- // Map opcodes to characters
- for(int i=0; i < size; i++)
- buf[i] = makeChar(handles[i].getInstruction().getOpcode());
-
- il_string = new String(buf);
- }
-
- /**
- * Map symbolic instruction names like "getfield" to a single character.
- *
- * @param pattern instruction pattern in lower case
- * @return encoded string for a pattern such as "BranchInstruction".
- */
- private static final String mapName(String pattern) {
- String result = map.get(pattern);
-
- if(result != null)
- return result;
-
- for(short i=0; i < NO_OPCODES; i++)
- if(pattern.equals(Constants.OPCODE_NAMES[i]))
- return "" + makeChar(i);
-
- throw new RuntimeException("Instruction unknown: " + pattern);
- }
-
- /**
- * Replace symbolic names of instructions with the appropiate character and remove
- * all white space from string. Meta characters such as +, * are ignored.
- *
- * @param pattern The pattern to compile
- * @return translated regular expression string
- */
- private static final String compilePattern(String pattern) {
- String lower = pattern.toLowerCase();
- StringBuffer buf = new StringBuffer();
- int size = pattern.length();
-
- for(int i=0; i < size; i++) {
- char ch = lower.charAt(i);
-
- if(Character.isLetterOrDigit(ch)) {
- StringBuffer name = new StringBuffer();
-
- while((Character.isLetterOrDigit(ch) || ch == '_') && i < size) {
- name.append(ch);
-
- if(++i < size)
- ch = lower.charAt(i);
- else
- break;
- }
-
- i--;
-
- buf.append(mapName(name.toString()));
- } else if(!Character.isWhitespace(ch))
- buf.append(ch);
- }
-
- return buf.toString();
- }
-
- /**
- * @return the matched piece of code as an array of instruction (handles)
- */
- private InstructionHandle[] getMatch(int matched_from, int match_length) {
- InstructionHandle[] match = new InstructionHandle[match_length];
- System.arraycopy(handles, matched_from, match, 0, match_length);
-
- return match;
- }
-
- /**
- * Search for the given pattern in the instruction list. You can search for any valid
- * opcode via its symbolic name, e.g. "istore". You can also use a super class or
- * an interface name to match a whole set of instructions, e.g. "BranchInstruction" or
- * "LoadInstruction". "istore" is also an alias for all "istore_x" instructions. Additional
- * aliases are "if" for "ifxx", "if_icmp" for "if_icmpxx", "if_acmp" for "if_acmpxx".
- *
- * Consecutive instruction names must be separated by white space which will be removed
- * during the compilation of the pattern.
- *
- * For the rest the usual pattern matching rules for regular expressions apply.<P>
- * Example pattern:
- * <pre>
- search("BranchInstruction NOP ((IfInstruction|GOTO)+ ISTORE Instruction)*");
- * </pre>
- *
- * <p>If you alter the instruction list upon a match such that other
- * matching areas are affected, you should call reread() to update
- * the finder and call search() again, because the matches are cached.
- *
- * @param pattern the instruction pattern to search for, where case is ignored
- * @param from where to start the search in the instruction list
- * @param constraint optional CodeConstraint to check the found code pattern for
- * user-defined constraints
- * @return iterator of matches where e.nextElement() returns an array of instruction handles
- * describing the matched area
- */
- public final Iterator<InstructionHandle[]> search(String pattern, InstructionHandle from,
- CodeConstraint constraint)
- {
- String search = compilePattern(pattern);
- int start = -1;
-
- for(int i=0; i < handles.length; i++) {
- if(handles[i] == from) {
- start = i; // Where to start search from (index)
- break;
- }
- }
-
- if(start == -1)
- throw new ClassGenException("Instruction handle " + from +
- " not found in instruction list.");
- try {
- RE regex = new RE(search);
- ArrayList<InstructionHandle[]> matches = new ArrayList<InstructionHandle[]>();
-
- while(start < il_string.length() && regex.match(il_string, start)) {
- int startExpr = regex.getParenStart(0);
- int endExpr = regex.getParenEnd(0);
- int lenExpr = regex.getParenLength(0);
-
- InstructionHandle[] match = getMatch(startExpr, lenExpr);
-
- if((constraint == null) || constraint.checkCode(match))
- matches.add(match);
- start = endExpr;
- }
-
- return matches.iterator();
- } catch(RESyntaxException e) {
- System.err.println(e);
- }
-
- return null;
- }
-
- /**
- * Start search beginning from the start of the given instruction list.
- *
- * @param pattern the instruction pattern to search for, where case is ignored
- * @return iterator of matches where e.nextElement()
- * returns an array of instruction handles describing the matched
- * area
- */
- public final Iterator<InstructionHandle[]> search(String pattern) {
- return search(pattern, il.getStart(), null);
- }
-
- /**
- * Start search beginning from `from'.
- *
- * @param pattern the instruction pattern to search for, where case is ignored
- * @param from where to start the search in the instruction list
- * @return iterator of matches where e.nextElement() returns an array of instruction handles
- * describing the matched area
- */
- public final Iterator<InstructionHandle[]> search(String pattern, InstructionHandle from) {
- return search(pattern, from, null);
- }
-
- /**
- * Start search beginning from the start of the given instruction list.
- * Check found matches with the constraint object.
- *
- * @param pattern the instruction pattern to search for, case is ignored
- * @param constraint constraints to be checked on matching code
- * @return instruction handle or `null' if the match failed
- */
- public final Iterator<InstructionHandle[]> search(String pattern, CodeConstraint constraint) {
- return search(pattern, il.getStart(), constraint);
- }
-
- /**
- * Convert opcode number to char.
- */
- private static final char makeChar(short opcode) {
- return (char)(opcode + OFFSET);
- }
-
- /**
- * @return the inquired instruction list
- */
- public final InstructionList getInstructionList() { return il; }
-
- /**
- * Code patterns found may be checked using an additional
- * user-defined constraint object whether they really match the needed criterion.
- * I.e., check constraints that can not expressed with regular expressions.
- *
- */
- public interface CodeConstraint {
- /**
- * @param match array of instructions matching the requested pattern
- * @return true if the matched area is really useful
- */
- public boolean checkCode(InstructionHandle[] match);
- }
-
- // Initialize pattern map
-
- static {
- map.put("arithmeticinstruction", "(irem|lrem|iand|ior|ineg|isub|lneg|fneg|fmul|ldiv|fadd|lxor|frem|idiv|land|ixor|ishr|fsub|lshl|fdiv|iadd|lor|dmul|lsub|ishl|imul|lmul|lushr|dneg|iushr|lshr|ddiv|drem|dadd|ladd|dsub)");
- map.put("invokeinstruction", "(invokevirtual|invokeinterface|invokestatic|invokespecial)");
- map.put("arrayinstruction", "(baload|aastore|saload|caload|fastore|lastore|iaload|castore|iastore|aaload|bastore|sastore|faload|laload|daload|dastore)");
- map.put("gotoinstruction", "(goto|goto_w)");
- map.put("conversioninstruction", "(d2l|l2d|i2s|d2i|l2i|i2b|l2f|d2f|f2i|i2d|i2l|f2d|i2c|f2l|i2f)");
- map.put("localvariableinstruction", "(fstore|iinc|lload|dstore|dload|iload|aload|astore|istore|fload|lstore)");
- map.put("loadinstruction", "(fload|dload|lload|iload|aload)");
- map.put("fieldinstruction", "(getfield|putstatic|getstatic|putfield)");
- map.put("cpinstruction", "(ldc2_w|invokeinterface|multianewarray|putstatic|instanceof|getstatic|checkcast|getfield|invokespecial|ldc_w|invokestatic|invokevirtual|putfield|ldc|new|anewarray)");
- map.put("stackinstruction", "(dup2|swap|dup2_x2|pop|pop2|dup|dup2_x1|dup_x2|dup_x1)");
- map.put("branchinstruction", "(ifle|if_acmpne|if_icmpeq|if_acmpeq|ifnonnull|goto_w|iflt|ifnull|if_icmpne|tableswitch|if_icmple|ifeq|if_icmplt|jsr_w|if_icmpgt|ifgt|jsr|goto|ifne|ifge|lookupswitch|if_icmpge)");
- map.put("returninstruction", "(lreturn|ireturn|freturn|dreturn|areturn|return)");
- map.put("storeinstruction", "(istore|fstore|dstore|astore|lstore)");
- map.put("select", "(tableswitch|lookupswitch)");
- map.put("ifinstruction", "(ifeq|ifgt|if_icmpne|if_icmpeq|ifge|ifnull|ifne|if_icmple|if_icmpge|if_acmpeq|if_icmplt|if_acmpne|ifnonnull|iflt|if_icmpgt|ifle)");
- map.put("jsrinstruction", "(jsr|jsr_w)");
- map.put("variablelengthinstruction", "(tableswitch|jsr|goto|lookupswitch)");
- map.put("unconditionalbranch", "(goto|jsr|jsr_w|athrow|goto_w)");
- map.put("constantpushinstruction", "(dconst|bipush|sipush|fconst|iconst|lconst)");
- map.put("typedinstruction", "(imul|lsub|aload|fload|lor|new|aaload|fcmpg|iand|iaload|lrem|idiv|d2l|isub|dcmpg|dastore|ret|f2d|f2i|drem|iinc|i2c|checkcast|frem|lreturn|astore|lushr|daload|dneg|fastore|istore|lshl|ldiv|lstore|areturn|ishr|ldc_w|invokeinterface|aastore|lxor|ishl|l2d|i2f|return|faload|sipush|iushr|caload|instanceof|invokespecial|putfield|fmul|ireturn|laload|d2f|lneg|ixor|i2l|fdiv|lastore|multianewarray|i2b|getstatic|i2d|putstatic|fcmpl|saload|ladd|irem|dload|jsr_w|dconst|dcmpl|fsub|freturn|ldc|aconst_null|castore|lmul|ldc2_w|dadd|iconst|f2l|ddiv|dstore|land|jsr|anewarray|dmul|bipush|dsub|sastore|d2i|i2s|lshr|iadd|l2i|lload|bastore|fstore|fneg|iload|fadd|baload|fconst|ior|ineg|dreturn|l2f|lconst|getfield|invokevirtual|invokestatic|iastore)");
- map.put("popinstruction", "(fstore|dstore|pop|pop2|astore|putstatic|istore|lstore)");
- map.put("allocationinstruction", "(multianewarray|new|anewarray|newarray)");
- map.put("indexedinstruction", "(lload|lstore|fload|ldc2_w|invokeinterface|multianewarray|astore|dload|putstatic|instanceof|getstatic|checkcast|getfield|invokespecial|dstore|istore|iinc|ldc_w|ret|fstore|invokestatic|iload|putfield|invokevirtual|ldc|new|aload|anewarray)");
- map.put("pushinstruction", "(dup|lload|dup2|bipush|fload|ldc2_w|sipush|lconst|fconst|dload|getstatic|ldc_w|aconst_null|dconst|iload|ldc|iconst|aload)");
- map.put("stackproducer", "(imul|lsub|aload|fload|lor|new|aaload|fcmpg|iand|iaload|lrem|idiv|d2l|isub|dcmpg|dup|f2d|f2i|drem|i2c|checkcast|frem|lushr|daload|dneg|lshl|ldiv|ishr|ldc_w|invokeinterface|lxor|ishl|l2d|i2f|faload|sipush|iushr|caload|instanceof|invokespecial|fmul|laload|d2f|lneg|ixor|i2l|fdiv|getstatic|i2b|swap|i2d|dup2|fcmpl|saload|ladd|irem|dload|jsr_w|dconst|dcmpl|fsub|ldc|arraylength|aconst_null|tableswitch|lmul|ldc2_w|iconst|dadd|f2l|ddiv|land|jsr|anewarray|dmul|bipush|dsub|d2i|newarray|i2s|lshr|iadd|lload|l2i|fneg|iload|fadd|baload|fconst|lookupswitch|ior|ineg|lconst|l2f|getfield|invokevirtual|invokestatic)");
- map.put("stackconsumer", "(imul|lsub|lor|iflt|fcmpg|if_icmpgt|iand|ifeq|if_icmplt|lrem|ifnonnull|idiv|d2l|isub|dcmpg|dastore|if_icmpeq|f2d|f2i|drem|i2c|checkcast|frem|lreturn|astore|lushr|pop2|monitorexit|dneg|fastore|istore|lshl|ldiv|lstore|areturn|if_icmpge|ishr|monitorenter|invokeinterface|aastore|lxor|ishl|l2d|i2f|return|iushr|instanceof|invokespecial|fmul|ireturn|d2f|lneg|ixor|pop|i2l|ifnull|fdiv|lastore|i2b|if_acmpeq|ifge|swap|i2d|putstatic|fcmpl|ladd|irem|dcmpl|fsub|freturn|ifgt|castore|lmul|dadd|f2l|ddiv|dstore|land|if_icmpne|if_acmpne|dmul|dsub|sastore|ifle|d2i|i2s|lshr|iadd|l2i|bastore|fstore|fneg|fadd|ior|ineg|ifne|dreturn|l2f|if_icmple|getfield|invokevirtual|invokestatic|iastore)");
- map.put("exceptionthrower", "(irem|lrem|laload|putstatic|baload|dastore|areturn|getstatic|ldiv|anewarray|iastore|castore|idiv|saload|lastore|fastore|putfield|lreturn|caload|getfield|return|aastore|freturn|newarray|instanceof|multianewarray|athrow|faload|iaload|aaload|dreturn|monitorenter|checkcast|bastore|arraylength|new|invokevirtual|sastore|ldc_w|ireturn|invokespecial|monitorexit|invokeinterface|ldc|invokestatic|daload)");
- map.put("loadclass", "(multianewarray|invokeinterface|instanceof|invokespecial|putfield|checkcast|putstatic|invokevirtual|new|getstatic|invokestatic|getfield|anewarray)");
- map.put("instructiontargeter", "(ifle|if_acmpne|if_icmpeq|if_acmpeq|ifnonnull|goto_w|iflt|ifnull|if_icmpne|tableswitch|if_icmple|ifeq|if_icmplt|jsr_w|if_icmpgt|ifgt|jsr|goto|ifne|ifge|lookupswitch|if_icmpge)");
-
- // Some aliases
- map.put("if_icmp", "(if_icmpne|if_icmpeq|if_icmple|if_icmpge|if_icmplt|if_icmpgt)");
- map.put("if_acmp", "(if_acmpeq|if_acmpne)");
- map.put("if", "(ifeq|ifne|iflt|ifge|ifgt|ifle)");
-
- // Precompile some aliases first
- map.put("iconst", precompile(Constants.ICONST_0, Constants.ICONST_5, Constants.ICONST_M1));
- map.put("lconst", new String(new char[] { '(', makeChar(Constants.LCONST_0), '|',
- makeChar(Constants.LCONST_1), ')' }));
- map.put("dconst", new String(new char[] { '(', makeChar(Constants.DCONST_0), '|',
- makeChar(Constants.DCONST_1), ')' }));
- map.put("fconst", new String(new char[] { '(', makeChar(Constants.FCONST_0), '|',
- makeChar(Constants.FCONST_1), ')' }));
-
- map.put("iload", precompile(Constants.ILOAD_0, Constants.ILOAD_3, Constants.ILOAD));
- map.put("dload", precompile(Constants.DLOAD_0, Constants.DLOAD_3, Constants.DLOAD));
- map.put("fload", precompile(Constants.FLOAD_0, Constants.FLOAD_3, Constants.FLOAD));
- map.put("aload", precompile(Constants.ALOAD_0, Constants.ALOAD_3, Constants.ALOAD));
-
- map.put("istore", precompile(Constants.ISTORE_0, Constants.ISTORE_3, Constants.ISTORE));
- map.put("dstore", precompile(Constants.DSTORE_0, Constants.DSTORE_3, Constants.DSTORE));
- map.put("fstore", precompile(Constants.FSTORE_0, Constants.FSTORE_3, Constants.FSTORE));
- map.put("astore", precompile(Constants.ASTORE_0, Constants.ASTORE_3, Constants.ASTORE));
-
- // Compile strings
-
- for(Iterator<String> i = map.keySet().iterator(); i.hasNext(); ) {
- String key = i.next();
- String value = map.get(key);
-
- char ch = value.charAt(1); // Omit already precompiled patterns
- if(ch < OFFSET) {
- map.put(key, compilePattern(value)); // precompile all patterns
- }
- }
-
- // Add instruction alias to match anything
-
- StringBuffer buf = new StringBuffer("(");
-
- for(short i=0; i < NO_OPCODES; i++) {
- if(Constants.iLen[i] != Constants.UNDEFINED_LENGTH) { // Not an invalid opcode
- buf.append(makeChar(i));
-
- if(i < NO_OPCODES - 1)
- buf.append('|');
- }
- }
- buf.append(')');
-
- map.put("instruction", buf.toString());
- }
-
- private static String precompile(short from, short to, short extra) {
- StringBuffer buf = new StringBuffer("(");
-
- for(short i=from; i <= to; i++) {
- buf.append(makeChar(i));
- buf.append('|');
- }
-
- buf.append(makeChar(extra));
- buf.append(")");
- return buf.toString();
- }
-
-// /*
-// * Internal debugging routines.
-// */
-// private static final String pattern2string(String pattern) {
-// return pattern2string(pattern, true);
-// }
-//
-// private static final String pattern2string(String pattern, boolean make_string) {
-// StringBuffer buf = new StringBuffer();
-//
-// for(int i=0; i < pattern.length(); i++) {
-// char ch = pattern.charAt(i);
-//
-// if(ch >= OFFSET) {
-// if(make_string)
-// buf.append(Constants.OPCODE_NAMES[ch - OFFSET]);
-// else
-// buf.append((int)(ch - OFFSET));
-// } else
-// buf.append(ch);
-// }
-//
-// return buf.toString();
-// }
-}