cvs commit: jakarta-bcel/src/java/org/apache/bcel/verifier/structurals InstConstraintVisitor.java

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
enver       2003/12/18 10:58:24

  Modified:    src/java/org/apache/bcel/verifier/structurals
                        InstConstraintVisitor.java
  Log:
  RETURN must only be used in VOID methods.
  
  Revision  Changes    Path
  1.8       +16 -10    jakarta-bcel/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java
  
  Index: InstConstraintVisitor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- InstConstraintVisitor.java	20 Aug 2003 13:31:14 -0000	1.7
  +++ InstConstraintVisitor.java	18 Dec 2003 18:58:24 -0000	1.8
  @@ -418,8 +418,21 @@
   	 * Assures the generic preconditions of a ReturnInstruction instance.
   	 */
   	public void visitReturnInstruction(ReturnInstruction o){
  -		if (o instanceof RETURN){
  -			return;
  +		Type method_type = mg.getType();
  +		if (method_type == Type.BOOLEAN ||
  +			method_type == Type.BYTE ||
  +			method_type == Type.SHORT ||
  +			method_type == Type.CHAR){
  +		        method_type = Type.INT;
  +			}
  +
  +        if (o instanceof RETURN){
  +            if (method_type != Type.VOID){
  +                constraintViolated(o, "RETURN instruction in non-void method.");
  +            }
  +            else{
  +			    return;
  +            }
   		}
   		if (o instanceof ARETURN){
   			if (stack().peek() == Type.NULL){
  @@ -439,13 +452,6 @@
   			}
   		}
   		else{
  -			Type method_type = mg.getType();
  -			if (method_type == Type.BOOLEAN ||
  -					method_type == Type.BYTE ||
  -					method_type == Type.SHORT ||
  -					method_type == Type.CHAR){
  -				method_type = Type.INT;
  -			}
   			if (! ( method_type.equals( stack().peek() ))){
   				constraintViolated(o, "Current method has return type of '"+mg.getType()+"' expecting a '"+method_type+"' on top of the stack. But stack top is a '"+stack().peek()+"'.");
   			}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.