Author: tcurdt
Date: Fri Apr 6 10:41:12 2007
New Revision: 526235
URL: http://svn.apache.org/viewvc?view=revrev=526235
Log:
http://issues.apache.org/bugzilla/show_bug.cgi?id=40577
Modified:
jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java
jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
Modified:
jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java
URL:
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java?view=diffrev=526235r1=526234r2=526235
==
---
jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java
(original)
+++
jakarta/bcel/trunk/src/main/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java
Fri Apr 6 10:41:12 2007
@@ -23,13 +23,17 @@
import java.util.List;
import java.util.Random;
import java.util.Vector;
+
import org.apache.bcel.Constants;
import org.apache.bcel.Repository;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.GETFIELD;
import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InvokeInstruction;
import org.apache.bcel.generic.JsrInstruction;
+import org.apache.bcel.generic.LoadInstruction;
import org.apache.bcel.generic.MethodGen;
import org.apache.bcel.generic.ObjectType;
import org.apache.bcel.generic.RET;
@@ -40,6 +44,7 @@
import org.apache.bcel.verifier.VerificationResult;
import org.apache.bcel.verifier.Verifier;
import org.apache.bcel.verifier.exc.AssertionViolatedException;
+import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
import org.apache.bcel.verifier.exc.VerifierConstraintViolatedException;
/**
@@ -126,7 +131,7 @@
* The proof of termination is about the existence of a
* fix point of frame merging.
*/
- private void circulationPump(ControlFlowGraph cfg, InstructionContext
start, Frame vanillaFrame, InstConstraintVisitor icv, ExecutionVisitor ev){
+ private void circulationPump(MethodGen m,ControlFlowGraph cfg,
InstructionContext start, Frame vanillaFrame, InstConstraintVisitor icv,
ExecutionVisitor ev){
final Random random = new Random();
InstructionContextQueue icq = new InstructionContextQueue();
@@ -246,6 +251,44 @@
this.addMessage(Warning:
ReturnInstruction '+ic+' may leave method with an uninitialized object on the
operand stack '+os+'.);
}
}
+//see JVM $4.8.2
+//TODO implement all based on stack
+Type returnedType = null;
+if( ih.getPrev().getInstruction() instanceof InvokeInstruction
)
+{
+returnedType =
((InvokeInstruction)ih.getPrev().getInstruction()).getType(m.getConstantPool());
+}
+if( ih.getPrev().getInstruction() instanceof LoadInstruction )
+{
+int index =
((LoadInstruction)ih.getPrev().getInstruction()).getIndex();
+returnedType = lvs.get(index);
+}
+if( ih.getPrev().getInstruction() instanceof GETFIELD )
+{
+returnedType =
((GETFIELD)ih.getPrev().getInstruction()).getType(m.getConstantPool());
+}
+if( returnedType != null )
+{
+if( returnedType instanceof ObjectType )
+{
+try
+{
+if(
!((ObjectType)returnedType).isAssignmentCompatibleWith(m.getReturnType()) )
+{
+throw new
StructuralCodeConstraintException(Returned type +returnedType+ does not
match Method's return type +m.getReturnType());
+}
+}
+catch (ClassNotFoundException e)
+{
+//dont know what do do now, so raise
RuntimeException
+throw new RuntimeException(e);
+}
+}
+else if( !returnedType.equals(m.getReturnType()) )
+{
+throw new StructuralCodeConstraintException(Returned
type +returnedType+ does not match Method's return type +m.getReturnType());
+}
+}
}
}while ((ih = ih.getNext()) != null);
@@ -321,7 +364,7 @@