java.lang.Object
edu.ucsb.ccs.jcontractor.transformation.Transformation
edu.ucsb.ccs.jcontractor.transformation.ContractTransformation
edu.ucsb.ccs.jcontractor.transformation.ReplaceReturnInstructionsTransformation
- public class ReplaceReturnInstructionsTransformation
- extends ContractTransformation
A transformation to replace all the return statements in a
non-contract methods with a jump to the end of the method, so that
exit condition checking code may be appended to the instruction
list. The transformation is only neccessary when an exit condition
needs to be checked, so it only modifies methods for which either
the postcondition or the exit invariant is checkable.
The transformation also saves the method's return value to a
local variable, and makes the index of this variable available to
subsequent transformations (AppendReturnTransformation, in
particular, needs it). The index is saved in the shared data table
as an Integer, under the key SHARED_INFO_RESULT_INDEX_KEY +
methodName + methodSignature
. Nothing is stored if the
return type is void.
Here's an example of some bytecode processed by this
transformation:
Before: After:
----------- --------------
0: iload_0 0: iload_0
1: ifeq #4 1: ifeq #4
2: iconst_0 2: iconst_0
3: return 3: goto #6
4: iconst_1 4: iconst_1
5: return 5: goto #6
6: nop
- Version:
- $Id: ReplaceReturnInstructionsTransformation.java,v 1.8 2002/07/14 07:58:03 parkera Exp $
Methods inherited from class edu.ucsb.ccs.jcontractor.transformation.ContractTransformation |
append, canCheckEntryInvariant, canCheckExitInvariant_Precondition, canCheckExitInvariant, canCheckPostcondition, canCheckPrecondition, canHaveInheritedContract_Precondition, canHaveInheritedContract, canHaveInvariant_Precondition, canHaveInvariant, canHavePostcondition_Precondition, canHavePostcondition, canHavePrecondition_Precondition, canHavePrecondition, canReferenceOld_Precondition, canReferenceOld, contractsCheckable_Precondition, contractsCheckable, createLoadArguments_Postcondition, createLoadArguments_Precondition, createLoadArguments, entryInvariantCheckable_Precondition, findMethod, findMethod, findMethodIndex, getContractClassName_Postcondition, getContractClassName_Postcondition, getContractClassName_Precondition, getContractClassName_Precondition, getContractClassName, getContractClassName, getInvariantMethodName_Postcondition, getInvariantMethodName_Precondition, getInvariantMethodName, getInvariantMethodSignature_Postcondition, getInvariantMethodSignature_Precondition, getInvariantMethodSignature, getPostconditionMethodName_Postcondition, getPostconditionMethodName_Precondition, getPostconditionMethodName, getPostconditionMethodSignature_Postcondition, getPostconditionMethodSignature_Precondition, getPostconditionMethodSignature, getPreconditionMethodName_Postcondition, getPreconditionMethodName_Precondition, getPreconditionMethodName, getPreconditionMethodSignature_Postcondition, getPreconditionMethodSignature_Precondition, getPreconditionMethodSignature, hasExternalContract, hasInterfaceContract, hasSuperClassContract, isContractClass_Postcondition, isContractClass_Precondition, isContractClass, isContractMethod_Postcondition, isContractMethod_Precondition, isContractMethod, isInvariantMethod_Precondition, isInvariantMethod, isPostconditionMethod_Postcondition, isPostconditionMethod, isPreconditionMethod_Precondition, isPreconditionMethod, postconditionCheckable_Precondition, preconditionCheckable_Precondition, prepend, prependToConstructor_Precondition, prependToConstructor, replaceInstruction, replaceInstruction, replaceReturnInstructions_Precondition, replaceReturnInstructions |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SHARED_INFO_RESULT_INDEX_KEY
public static final java.lang.String SHARED_INFO_RESULT_INDEX_KEY
- Constant for the key with which the result index is saved in the
shared data.
- See Also:
- Constant Field Values
ReplaceReturnInstructionsTransformation
public ReplaceReturnInstructionsTransformation()
acceptClass
public boolean acceptClass()
- Determine if the current class should be processed. All classes
in which contracts are checkable are processed.
- Specified by:
acceptClass
in class Transformation
transformMethod
public void transformMethod(org.apache.bcel.generic.MethodGen mg)
- Replace all the return statements in the method with code a jump
the end of the method. Only methods with exit conditions need to
be transformed, so only methods for which either the
postcondition or exit invariant is checkable are processed.
- Specified by:
transformMethod
in class Transformation
saveResult
protected void saveResult(org.apache.bcel.generic.MethodGen mg)
- Save the result of the method to a local variable named
"$result", and save the index of this new variable in the shared
info table. The index is saved as an Integer, under the key
SHARED_INFO_RESULT_INDEX_KEY + mg.getName() +
mg.getSignature()
. No value will be stored if the mehod's
return type is void.
saveResult_Postcondition
protected boolean saveResult_Postcondition(org.apache.bcel.generic.MethodGen mg,
java.lang.Void RESULT)
transformClass
public void transformClass()
- Does nothing. This transformation operates only on methods.
- Specified by:
transformClass
in class Transformation