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 8267a869 Refactor common code
8267a869 is described below
commit 8267a869a9e6316f24b94c90ec3e732ff7a5c0c8
Author: Gary David Gregory (Code signing key) <[email protected]>
AuthorDate: Sat Oct 29 11:28:33 2022 -0400
Refactor common code
---
.../structurals/InstConstraintVisitor.java | 48 ++++------------------
1 file changed, 7 insertions(+), 41 deletions(-)
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 c0c29617..e4a174b1 100644
---
a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
+++
b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
@@ -1709,7 +1709,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
}
}
- private Type visitInvokeInternals(final InvokeInstruction o) throws
ClassNotFoundException {
+ private int visitInvokeInternals(final InvokeInstruction o) throws
ClassNotFoundException {
final Type t = o.getType(cpg);
if (t instanceof ObjectType) {
final String name = ((ObjectType) t).getClassName();
@@ -1745,8 +1745,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
}
}
}
-
- return stack().peek(nargs);
+ return nargs;
}
/**
@@ -1766,7 +1765,8 @@ public class InstConstraintVisitor extends EmptyVisitor {
// the o.getClassType(cpg) type has passed pass 2; see
visitLoadClass(o).
- Type objref = visitInvokeInternals(o);
+ final int nargs = visitInvokeInternals(o);
+ Type objref = stack().peek(nargs);
if (objref == Type.NULL) {
return;
}
@@ -1811,42 +1811,7 @@ public class InstConstraintVisitor extends EmptyVisitor {
public void visitINVOKESTATIC(final INVOKESTATIC o) {
try {
// Method is not native, otherwise pass 3 would not happen.
-
- final Type t = o.getType(cpg);
- if (t instanceof ObjectType) {
- final String name = ((ObjectType) t).getClassName();
- final Verifier v = VerifierFactory.getVerifier(name);
- final VerificationResult vr = v.doPass2();
- if (vr.getStatus() != VerificationResult.VERIFIED_OK) {
- constraintViolated(o, "Class '" + name + "' is referenced,
but cannot be loaded and resolved: '" + vr + "'.");
- }
- }
-
- final Type[] argtypes = o.getArgumentTypes(cpg);
- final int nargs = argtypes.length;
-
- for (int i = nargs - 1; i >= 0; i--) {
- final Type fromStack = stack().peek(nargs - 1 - i); // 0 to
nargs-1
- Type fromDesc = argtypes[i];
- if (fromDesc == Type.BOOLEAN || fromDesc == Type.BYTE ||
fromDesc == Type.CHAR || fromDesc == Type.SHORT) {
- fromDesc = Type.INT;
- }
- if (!fromStack.equals(fromDesc)) {
- if (fromStack instanceof ReferenceType && fromDesc
instanceof ReferenceType) {
- final ReferenceType rFromStack = (ReferenceType)
fromStack;
- final ReferenceType rFromDesc = (ReferenceType)
fromDesc;
- // TODO: This check can possibly only be done using
Staerk-et-al's "set of object types"
- // instead of a "wider cast object type" created
during verification.
- if (!rFromStack.isAssignmentCompatibleWith(rFromDesc))
{
- constraintViolated(o,
- "Expecting a '" + fromDesc + "' but found a '"
+ fromStack + "' on the stack (which is not assignment compatible).");
- }
- referenceTypeIsInitialized(o, rFromStack);
- } else {
- constraintViolated(o, "Expecting a '" + fromDesc + "'
but found a '" + fromStack + "' on the stack.");
- }
- }
- }
+ visitInvokeInternals(o);
} catch (final ClassNotFoundException e) {
// FIXME: maybe not the best way to handle this
throw new AssertionViolatedException("Missing class: " + e, e);
@@ -1861,7 +1826,8 @@ public class InstConstraintVisitor extends EmptyVisitor {
try {
// the o.getClassType(cpg) type has passed pass 2; see
visitLoadClass(o).
- Type objref = visitInvokeInternals(o);
+ final int nargs = visitInvokeInternals(o);
+ Type objref = stack().peek(nargs);
if (objref == Type.NULL) {
return;
}