This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push: new c9d593ea Use camel case names c9d593ea is described below commit c9d593eaf3cb4c673403cf475315ee79f7cd18dc Author: Gary David Gregory (Code signing key) <ggreg...@apache.org> AuthorDate: Sun Nov 6 14:08:23 2022 -0500 Use camel case names --- .../org/apache/bcel/generic/ConstantPoolGen.java | 8 +-- .../structurals/InstConstraintVisitor.java | 82 +++++++++++----------- .../bcel/verifier/structurals/Subroutines.java | 46 ++++++------ .../verifier/tests/TestArrayAccess02Creator.java | 38 +++++----- .../bcel/verifier/tests/TestReturn03Creator.java | 24 +++---- 5 files changed, 99 insertions(+), 99 deletions(-) diff --git a/src/main/java/org/apache/bcel/generic/ConstantPoolGen.java b/src/main/java/org/apache/bcel/generic/ConstantPoolGen.java index 0622364c..e47ca57b 100644 --- a/src/main/java/org/apache/bcel/generic/ConstantPoolGen.java +++ b/src/main/java/org/apache/bcel/generic/ConstantPoolGen.java @@ -130,12 +130,12 @@ public class ConstantPoolGen { } } else if (c instanceof ConstantNameAndType) { final ConstantNameAndType n = (ConstantNameAndType) c; - final ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()]; - final ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()]; + final ConstantUtf8 u8NameIdx = (ConstantUtf8) constants[n.getNameIndex()]; + final ConstantUtf8 u8SigIdx = (ConstantUtf8) constants[n.getSignatureIndex()]; - sb.append(u8.getBytes()); + sb.append(u8NameIdx.getBytes()); sb.append(NAT_DELIM); - sb.append(u8_2.getBytes()); + sb.append(u8SigIdx.getBytes()); final String key = sb.toString(); sb.delete(0, sb.length()); diff --git a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java index e4a174b1..485ce6b4 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java @@ -78,34 +78,6 @@ public class InstConstraintVisitor extends EmptyVisitor { public InstConstraintVisitor() { } - /***************************************************************/ - /* MISC */ - /***************************************************************/ - /** - * Ensures the general preconditions of an instruction that accesses the stack. This method is here because BCEL has no - * such superinterface for the stack accessing instructions; and there are funny unexpected exceptions in the semantices - * of the superinterfaces and superclasses provided. E.g. SWAP is a StackConsumer, but DUP_X1 is not a StackProducer. - * Therefore, this method is called by all StackProducer, StackConsumer, and StackInstruction instances via their - * visitXXX() method. Unfortunately, as the superclasses and superinterfaces overlap, some instructions cause this - * method to be called two or three times. [TODO: Fix this.] - * - * @see #visitStackConsumer(StackConsumer o) - * @see #visitStackProducer(StackProducer o) - * @see #visitStackInstruction(StackInstruction o) - */ - private void _visitStackAccessor(final Instruction o) { - final int consume = o.consumeStack(cpg); // Stack values are always consumed first; then produced. - if (consume > stack().slotsUsed()) { - constraintViolated(o, "Cannot consume " + consume + " stack slots: only " + stack().slotsUsed() + " slot(s) left on stack!\nStack:\n" + stack()); - } - - final int produce = o.produceStack(cpg) - o.consumeStack(cpg); // Stack values are always consumed first; then produced. - if (produce + stack().slotsUsed() > stack().maxStack()) { - constraintViolated(o, "Cannot produce " + produce + " stack slots: only " + (stack().maxStack() - stack().slotsUsed()) - + " free stack slot(s) left.\nStack:\n" + stack()); - } - } - /** * Assures arrayref is of ArrayType or NULL; returns true if and only if arrayref is non-NULL. * @@ -207,12 +179,6 @@ public class InstConstraintVisitor extends EmptyVisitor { return frame.getStack(); } - /***************************************************************/ - /* "generic"visitXXXX methods where XXXX is an interface */ - /* therefore, we don't know the order of visiting; but we know */ - /* these methods are called before the visitYYYY methods below */ - /***************************************************************/ - /** Assures value is of type INT. */ private void valueOfInt(final Instruction o, final Type value) { if (!value.equals(Type.INT)) { @@ -220,6 +186,12 @@ public class InstConstraintVisitor extends EmptyVisitor { } } + /***************************************************************/ + /* "generic"visitXXXX methods where XXXX is an interface */ + /* therefore, we don't know the order of visiting; but we know */ + /* these methods are called before the visitYYYY methods below */ + /***************************************************************/ + /** * Ensures the specific preconditions of the said instruction. */ @@ -377,10 +349,6 @@ public class InstConstraintVisitor extends EmptyVisitor { } } - /***************************************************************/ - /* "special"visitXXXX methods for one type of instruction each */ - /***************************************************************/ - /** * Ensures the specific preconditions of the said instruction. */ @@ -399,6 +367,10 @@ public class InstConstraintVisitor extends EmptyVisitor { } } + /***************************************************************/ + /* "special"visitXXXX methods for one type of instruction each */ + /***************************************************************/ + /** * Ensures the specific preconditions of the said instruction. */ @@ -2648,12 +2620,40 @@ public class InstConstraintVisitor extends EmptyVisitor { // nothing to do here. Generic visitXXX() methods did the trick before. } + /***************************************************************/ + /* MISC */ + /***************************************************************/ + /** + * Ensures the general preconditions of an instruction that accesses the stack. This method is here because BCEL has no + * such superinterface for the stack accessing instructions; and there are funny unexpected exceptions in the semantices + * of the superinterfaces and superclasses provided. E.g. SWAP is a StackConsumer, but DUP_X1 is not a StackProducer. + * Therefore, this method is called by all StackProducer, StackConsumer, and StackInstruction instances via their + * visitXXX() method. Unfortunately, as the superclasses and superinterfaces overlap, some instructions cause this + * method to be called two or three times. [TODO: Fix this.] + * + * @see #visitStackConsumer(StackConsumer o) + * @see #visitStackProducer(StackProducer o) + * @see #visitStackInstruction(StackInstruction o) + */ + private void visitStackAccessor(final Instruction o) { + final int consume = o.consumeStack(cpg); // Stack values are always consumed first; then produced. + if (consume > stack().slotsUsed()) { + constraintViolated(o, "Cannot consume " + consume + " stack slots: only " + stack().slotsUsed() + " slot(s) left on stack!\nStack:\n" + stack()); + } + + final int produce = o.produceStack(cpg) - o.consumeStack(cpg); // Stack values are always consumed first; then produced. + if (produce + stack().slotsUsed() > stack().maxStack()) { + constraintViolated(o, "Cannot produce " + produce + " stack slots: only " + (stack().maxStack() - stack().slotsUsed()) + + " free stack slot(s) left.\nStack:\n" + stack()); + } + } + /** * Ensures the general preconditions of a StackConsumer instance. */ @Override public void visitStackConsumer(final StackConsumer o) { - _visitStackAccessor((Instruction) o); + visitStackAccessor((Instruction) o); } /** @@ -2661,7 +2661,7 @@ public class InstConstraintVisitor extends EmptyVisitor { */ @Override public void visitStackInstruction(final StackInstruction o) { - _visitStackAccessor(o); + visitStackAccessor(o); } /** @@ -2669,7 +2669,7 @@ public class InstConstraintVisitor extends EmptyVisitor { */ @Override public void visitStackProducer(final StackProducer o) { - _visitStackAccessor((Instruction) o); + visitStackAccessor((Instruction) o); } /** diff --git a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java index 30113f0e..56711fe4 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java @@ -98,23 +98,6 @@ public class Subroutines { public SubroutineImpl() { } - /** - * A recursive helper method for getRecursivelyAccessedLocalsIndices(). - * - * @see #getRecursivelyAccessedLocalsIndices() - */ - private void _getRecursivelyAccessedLocalsIndicesHelper(final Set<Integer> set, final Subroutine[] subs) { - for (final Subroutine sub : subs) { - final int[] lvs = sub.getAccessedLocalsIndices(); - for (final int lv : lvs) { - set.add(Integer.valueOf(lv)); - } - if (sub.subSubs().length != 0) { - _getRecursivelyAccessedLocalsIndicesHelper(set, sub.subSubs()); - } - } - } - /** * Adds a new JSR or JSR_W that has this subroutine as its target. */ @@ -236,7 +219,7 @@ public class Subroutines { for (final int lv : lvs) { s.add(Integer.valueOf(lv)); } - _getRecursivelyAccessedLocalsIndicesHelper(s, this.subSubs()); + getRecursivelyAccessedLocalsIndicesHelper(s, this.subSubs()); final int[] ret = new int[s.size()]; int j = -1; for (final Integer index : s) { @@ -246,6 +229,23 @@ public class Subroutines { return ret; } + /** + * A recursive helper method for getRecursivelyAccessedLocalsIndices(). + * + * @see #getRecursivelyAccessedLocalsIndices() + */ + private void getRecursivelyAccessedLocalsIndicesHelper(final Set<Integer> set, final Subroutine[] subs) { + for (final Subroutine sub : subs) { + final int[] lvs = sub.getAccessedLocalsIndices(); + for (final int lv : lvs) { + set.add(Integer.valueOf(lv)); + } + if (sub.subSubs().length != 0) { + getRecursivelyAccessedLocalsIndicesHelper(set, sub.subSubs()); + } + } + } + /** * Sets the leaving RET instruction. Must be invoked after all instructions are added. Must not be invoked for top-level * 'subroutine'. @@ -519,16 +519,16 @@ public class Subroutines { // Now make sure no instruction of a Subroutine is protected by exception handling code // as is mandated by JustIces notion of subroutines. for (final CodeExceptionGen handler : handlers) { - InstructionHandle _protected = handler.getStartPC(); - while (_protected != handler.getEndPC().getNext()) { + InstructionHandle protectedIh = handler.getStartPC(); + while (protectedIh != handler.getEndPC().getNext()) { // Note the inclusive/inclusive notation of "generic API" exception handlers! for (final Subroutine sub : subroutines.values()) { - if (sub != subroutines.get(all[0]) && sub.contains(_protected)) { - throw new StructuralCodeConstraintException("Subroutine instruction '" + _protected + "' is protected by an exception handler, '" + if (sub != subroutines.get(all[0]) && sub.contains(protectedIh)) { + throw new StructuralCodeConstraintException("Subroutine instruction '" + protectedIh + "' is protected by an exception handler, '" + handler + "'. This is forbidden by the JustIce verifier due to its clear definition of subroutines."); } } - _protected = _protected.getNext(); + protectedIh = protectedIh.getNext(); } } } diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java index 5ea1b20c..7f42ec50 100644 --- a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java +++ b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java @@ -34,66 +34,66 @@ import org.apache.bcel.generic.PUSH; import org.apache.bcel.generic.Type; public class TestArrayAccess02Creator extends TestCreator { - private final InstructionFactory _factory; - private final ConstantPoolGen _cp; - private final ClassGen _cg; + private final InstructionFactory instructionFactory; + private final ConstantPoolGen constantPoolGen; + private final ClassGen classGen; public TestArrayAccess02Creator() { - _cg = new ClassGen(TEST_PACKAGE + ".TestArrayAccess02", "java.lang.Object", "TestArrayAccess02.java", Const.ACC_PUBLIC | Const.ACC_SUPER, + classGen = new ClassGen(TEST_PACKAGE + ".TestArrayAccess02", "java.lang.Object", "TestArrayAccess02.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {}); - _cp = _cg.getConstantPool(); - _factory = new InstructionFactory(_cg, _cp); + constantPoolGen = classGen.getConstantPool(); + instructionFactory = new InstructionFactory(classGen, constantPoolGen); } @Override public void create(final OutputStream out) throws IOException { createMethod_0(); createMethod_1(); - _cg.getJavaClass().dump(out); + classGen.getJavaClass().dump(out); } private void createMethod_0() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "<init>", TEST_PACKAGE + ".TestArrayAccess02", il, - _cp); + constantPoolGen); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); assertNotNull(ih_0); // TODO why is this not used - il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); + il.append(instructionFactory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); - _cg.addMethod(method.getMethod()); + classGen.addMethod(method.getMethod()); il.dispose(); } private void createMethod_1() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.VOID, Type.NO_ARGS, new String[] {}, "test", - TEST_PACKAGE + ".TestArrayAccess02", il, _cp); + TEST_PACKAGE + ".TestArrayAccess02", il, constantPoolGen); - final InstructionHandle ih_0 = il.append(new PUSH(_cp, 1)); + final InstructionHandle ih_0 = il.append(new PUSH(constantPoolGen, 1)); assertNotNull(ih_0); // TODO why is this not used - il.append(_factory.createNewArray(new ObjectType(TEST_PACKAGE + ".TestArrayAccess02"), (short) 1)); + il.append(instructionFactory.createNewArray(new ObjectType(TEST_PACKAGE + ".TestArrayAccess02"), (short) 1)); il.append(InstructionFactory.createStore(Type.OBJECT, 0)); - final InstructionHandle ih_5 = il.append(new PUSH(_cp, 1)); + final InstructionHandle ih_5 = il.append(new PUSH(constantPoolGen, 1)); assertNotNull(ih_5); // TODO why is this not used - il.append(_factory.createNewArray(Type.STRING, (short) 1)); + il.append(instructionFactory.createNewArray(Type.STRING, (short) 1)); il.append(InstructionFactory.createStore(Type.OBJECT, 1)); final InstructionHandle ih_10 = il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); assertNotNull(ih_10); // TODO why is this not used - il.append(new PUSH(_cp, 0)); - il.append(_factory.createNew(TEST_PACKAGE + ".TestArrayAccess02")); + il.append(new PUSH(constantPoolGen, 0)); + il.append(instructionFactory.createNew(TEST_PACKAGE + ".TestArrayAccess02")); il.append(InstructionConst.DUP); - il.append(_factory.createInvoke(TEST_PACKAGE + ".TestArrayAccess02", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); + il.append(instructionFactory.createInvoke(TEST_PACKAGE + ".TestArrayAccess02", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); il.append(InstructionConst.AASTORE); final InstructionHandle ih_20 = il.append(InstructionFactory.createReturn(Type.VOID)); assertNotNull(ih_20); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); - _cg.addMethod(method.getMethod()); + classGen.addMethod(method.getMethod()); il.dispose(); } } diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java index d753226d..097f859e 100644 --- a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java +++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java @@ -32,17 +32,17 @@ import org.apache.bcel.generic.MethodGen; import org.apache.bcel.generic.Type; public abstract class TestReturn03Creator extends TestCreator { - private final InstructionFactory _factory; - private final ConstantPoolGen _cp; - private final ClassGen _cg; + private final InstructionFactory instructionFactory; + private final ConstantPoolGen constantPoolGen; + private final ClassGen classGen; private final Type returnType; private final String genClassSuffix; protected TestReturn03Creator(final Type returnType, final String genClassSuffix) { - _cg = new ClassGen(TEST_PACKAGE + ".TestReturn03" + genClassSuffix, "java.lang.Object", "TestReturn03.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {}); + classGen = new ClassGen(TEST_PACKAGE + ".TestReturn03" + genClassSuffix, "java.lang.Object", "TestReturn03.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {}); - _cp = _cg.getConstantPool(); - _factory = new InstructionFactory(_cg, _cp); + constantPoolGen = classGen.getConstantPool(); + instructionFactory = new InstructionFactory(classGen, constantPoolGen); this.returnType = returnType; this.genClassSuffix = genClassSuffix; } @@ -51,35 +51,35 @@ public abstract class TestReturn03Creator extends TestCreator { public void create(final OutputStream out) throws IOException { createMethod_0(); createMethod_1(); - _cg.getJavaClass().dump(out); + classGen.getJavaClass().dump(out); } private void createMethod_0() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "<init>", TEST_PACKAGE + ".TestReturn03", il, _cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "<init>", TEST_PACKAGE + ".TestReturn03", il, constantPoolGen); final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); assertNotNull(ih_0); // TODO why is this not used - il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); + il.append(instructionFactory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID)); assertNotNull(ih_4); // TODO why is this not used method.setMaxStack(); method.setMaxLocals(); - _cg.addMethod(method.getMethod()); + classGen.addMethod(method.getMethod()); il.dispose(); } private void createMethod_1() { final InstructionList il = new InstructionList(); final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.INT, Type.NO_ARGS, new String[] {}, "test3", - TEST_PACKAGE + ".TestReturn03" + genClassSuffix, il, _cp); + TEST_PACKAGE + ".TestReturn03" + genClassSuffix, il, constantPoolGen); final InstructionHandle ih_0 = il.append(InstructionConst.ACONST_NULL); assertNotNull(ih_0); // TODO why is this not used il.append(InstructionFactory.createReturn(returnType)); method.setMaxStack(); method.setMaxLocals(); - _cg.addMethod(method.getMethod()); + classGen.addMethod(method.getMethod()); il.dispose(); } }