|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.multijava.util.Utils
org.jmlspecs.jmlrac.TransUtils
org.jmlspecs.jmlrac.WrapperMethod
A class for generating wrapper methods. A wrapper method is a method that wraps a method with assertion check methods such as pre and postcondition check methods. The original method is renamed and called by the wrapper method inside the wrap. Wrapper methods are generated for only concrete methods; no wrapper methods are generated for abstract methods.
| Field Summary | |
protected StringBuffer |
args
arguments to pre/orig, post, or xpost method calls |
private boolean |
hasReturn
true if the target method has return type. |
protected String |
ident
name of the target method. |
protected boolean |
isHelper
true if the target method is a helper. |
protected boolean |
isStatic
true if the target method is a static method. |
protected JmlMethodDeclaration |
methodDecl
target method to be wrapped. |
protected StringBuffer |
postArgs
arguments to pre/orig, post, or xpost method calls |
protected CType |
returnType
return type of the target method. |
protected String |
typeName
type name whose methods are to be wrapped. |
protected StringBuffer |
xpostArgs
arguments to pre/orig, post, or xpost method calls |
| Fields inherited from class org.jmlspecs.jmlrac.TransUtils |
typeDecl |
| Fields inherited from class org.multijava.util.Utils |
DBG_LEVEL_HIGH, DBG_LEVEL_LOW, DBG_LEVEL_NO |
| Fields inherited from interface org.jmlspecs.jmlrac.RacConstants |
MN_CHECK_HC, MN_CHECK_INV, MN_CHECK_POST, MN_CHECK_PRE, MN_CHECK_XPOST, MN_EVAL_OLD, MN_GHOST, MN_INIT, MN_INTERNAL, MN_MODEL, MN_MODEL_PUBLIC, MN_RESTORE_FROM, MN_SAVE_TO, MN_SPEC, MN_SPEC_PUBLIC, TN_JMLCHECKABLE, TN_JMLSURROGATE, TN_JMLUNIT_TEST_POSTFIX, TN_JMLUNIT_TESTDATA_POSTFIX, TN_JMLVALUE, TN_SURROGATE, VN_ASSERTION, VN_CATCH_VAR, VN_CLASS_INIT, VN_CONSTRUCTED, VN_DELEGEE, VN_ERROR_SET, VN_EXCEPTION, VN_FREE_VAR, VN_INIT, VN_OLD_VAR, VN_POST_VAR, VN_PRE_VAR, VN_PRECOND, VN_RAC_COMPILED, VN_RAC_LEVEL, VN_RESULT, VN_STACK_VAR, VN_XRESULT |
| Constructor Summary | |
WrapperMethod(String typeName,
JmlMethodDeclaration mdecl)
Construct a new instance. |
|
| Method Summary | |
protected void |
buildArguments()
Builds arguments to various assertion check methods such as pre- and postcondition check methods. |
protected JBlock |
buildWrapperBody()
Returns code for the body of the wrapper method being created. |
protected String |
callOriginalMethod()
Returns code for invoking the original method. |
protected String |
checkConstraint()
Returns code for checking history constraint. |
protected String |
checkPostcondition()
Returns code for checking normal postcondition. |
protected String |
checkPostInvariant()
Returns code for checking invariant in the post-state. |
protected String |
checkPrecondition()
Returns code for checking precondition. |
protected String |
checkPreInvariant()
Returns code for checking invariant in the pre-state. |
protected String |
checkXPostcondition()
Returns code for checking exceptional postcondition. |
protected String |
constraintCallArg()
Returns, in the string form, the argument for calling a constraint check method. |
protected String |
evalOldInConstraint()
Returns code for evaluating old expressions in constraints. |
JMethodDeclarationType |
generate()
Returns a wrapper method. |
protected String |
identification(String state)
Returns a string that identifies the method being translated. |
protected String |
isActive(String type)
Returns a string representation of the condition that tests if the given type of assertion is active. |
protected String |
mandatoryReturn()
Returns a mandatory return statement. |
protected String |
nocheckDuringInit()
Returns code for bypassing assertion checks during the class and instance initialization. |
protected String |
optionalReturn()
Returns an optional return statement. |
protected String |
racMethodName(String type)
Returns the name of runtime assertion checker method for the given type. |
protected String |
resultVarDecl()
Returns code for declaring result variable. |
protected String |
wrap(String type,
String comment,
String stmt)
Returns the given statement, stmt, wrapped in
assertion check demarcation. |
protected String |
wrap2(String type,
String comment,
String stmt)
Returns the given statement, stmt, wrapped in
assertion check demarcation. |
protected String |
wrap3(String type,
String comment,
String stmt)
Returns the given statement, stmt, wrapped in
assertion check demarcation. |
| Methods inherited from class org.multijava.util.Utils |
assertTrue, assertTrue, combineArrays, escapeString, escapeString, fail, fail, getFilePath, hasFlag, hasOtherFlags, parsePathParts, relativePathTo, splitQualifiedName, splitQualifiedName, stripJavaModifiers, stripNonJavaModifiers, stripPrivateModifier, unescapeString, vectorToArray, vectorToIntArray |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected final String typeName
protected final JmlMethodDeclaration methodDecl
protected invariant methodDecl != null;
protected final boolean isHelper
protected invariant isHelper == methodDecl.isHelper();
protected final boolean isStatic
protected invariant isStatic == methodDecl.isStatic();
private final boolean hasReturn
private invariant hasReturn == (returnType != null && !returnType.isVoid());
protected final CType returnType
private invariant returnType == methodDecl.returnType();
protected final String ident
private invariant ident == methodDecl.ident();
protected StringBuffer args
protected StringBuffer postArgs
protected StringBuffer xpostArgs
| Constructor Detail |
public WrapperMethod(String typeName,
JmlMethodDeclaration mdecl)
requires typeName != null && mdecl != null && mdecl.body() != null;
mdecl - method to be wrapped; must not be abstract.| Method Detail |
public JMethodDeclarationType generate()
T m(T1 x1, ..., Tn xn) {
checkPre$m(x1, ..., xn);
checkInv();
T r = init_T;
boolean ok = true;
try {
r = orig$m(x1, ..., xn);
checkPost$m(x1, ..., xn, r);
}
catch (JMLEntryPreconditionError e) {
ok = false;
throw new JMLInternalPreconditionError(e);
}
catch (JMLExitPostconditionError e) {
ok = false;
throw new JMLInternalPostconditionError(e);
}
catch (JMLAssertionError e) {
ok = false;
throw e;
}
catch (Throwable e) {
try {
checkXPost$m(x1, ..., xn, r, e);
}
catch (JMLAssertionError e1) {
ok = false;
throw e1;
}
}
finally {
if (ok) {
checkInv();
checkConstraint();
}
}
}
old String n = methodDecl.ident(); modifies methodDecl.*; assignable args, postArgs, xpostArgs; ensures methodDecl.ident().equals(MN_INTERNAL + n) && \fresh(\result);
protected JBlock buildWrapperBody()
generate().
ensures \result != null;
generate()protected String nocheckDuringInit()
if (!VN_CLASS_INIT [|| !VN_INIT] [|| !VN_CONSTRUCTED()]) {
[return] m(x1, ..., xn);
[return;]
}
protected String checkPreInvariant()
// check static invariant
if (JMLChecker.isActive(JMLChecker.INVARIANT)) {
JMLChecker.enter();
checkInv$static();
JMLChecker.exit();
}
// check instance invariant
if (JMLChecker.isActive(JMLChecker.INVARIANT)) {
JMLChecker.enter();
checkInv$instance$T();
JMLChecker.exit();
}
where T is the name of type being translated. The
code for checking instance invariant is generated only if the
target method is an instance method.
requires isHelper; ensures \fresh(\result) && "".equals(\result); also requires !isHelper; ensures \fresh(\result) && \result.length() > 0 && (* \result is of the above form of code *);
protected String checkPostInvariant()
// check static invariant
if (JMLChecker.isActive(JMLChecker.INVARIANT)) {
JMLChecker.enter();
checkInv$static();
JMLChecker.exit();
}
// check instance invariant
if (JMLChecker.isActive(JMLChecker.INVARIANT)) {
JMLChecker.enter();
checkInv$instance$T();
JMLChecker.exit();
}
where T is the name of type being translated. The
code for checking instance invariant is generated only if the
target method is an instance method.
requires isHelper; ensures \fresh(\result) && "".equals(\result); also requires !isHelper; ensures \fresh(\result) && \result.length() > 0 && (* \result is of the above form of code *);
protected String evalOldInConstraint()
// eval old exprs in static constraint
if (JMLChecker.isActive(JMLChecker.CONSTRAINT)) {
JMLChecker.enter();
evalOldExprInHC$satic();
JMLChecker.exit();
}
// eval old exprs in non-static constraint
if (JMLChecker.isActive(JMLChecker.CONSTRAINT)) {
JMLChecker.enter();
evalOldExprInHC$instance$T();
JMLChecker.exit();
}
where T is the name of type being translated. The
code for instance constraints is generated only if the
target method is an instance method.
protected String checkConstraint()
// check static constraint
if (JMLChecker.isActive(JMLChecker.CONSTRAINT)) {
JMLChecker.enter();
checkHC$static();
JMLChecker.exit();
}
// check instance constraint
if (JMLChecker.isActive(JMLChecker.CONSTRAINT)) {
JMLChecker.enter();
checkHC$instance$T();
JMLChecker.exit();
}
where T is the name of type being translated. The
code for checking instance constraint is generated only if the
target method is an instance method.
protected String constraintCallArg()
protected void buildArguments()
args to "(x1,...,xn)",
postArgs to "(x1,...,xn,VN_RESULT)", and
xpostArgs to "(x1,...,xn,VN_XRESULT)".
assignable args, postArgs, xpostArgs; ensures args != null && postArgs != null && xpostArgs != null;
protected String callOriginalMethod()
[ VN_RESULT = ] internal$m(x1,...,xn);.
protected String resultVarDecl()
T VN_RESULT = init_value_of_T;,
where T is the return type.
protected String checkPrecondition()
// check precondition
if (JMLChecker.isActive(JMLChecker.PRECONDITION)) {
JMLChecker.enter();
checkPre$m$T(x1,...,xn);
JMLChecker.exit();
}
where m is the name of method being translated and
T is the name of the owning type.
protected String checkPostcondition()
// check normal postcondition
if (JMLChecker.isActive(JMLChecker.POSTCONDITION)) {
JMLChecker.enter();
checkPost$m$T(x1,...,xn,r);
JMLChecker.exit();
}
where m is the name of method being translated and
T is the name of the owning type.
protected String checkXPostcondition()
// check exceptional postcondition
if (JMLChecker.isActive(JMLChecker.POSTCONDITION)) {
JMLChecker.enter();
checkXPost$m$T(x1,...,xn,r,e);
JMLChecker.exit();
}
where m is the name of method being translated and
T is the name of the owning type.
protected String mandatoryReturn()
return statement. I.e,
return [ VN_RESULT ];. The optional result
variable is generated only if the method being translated has a
non-void return type.
protected String optionalReturn()
return statement. I.e,
[ return VN_RESULT ; ]. If the method being
translated has a void return type, the result is an empty
string.
protected String wrap(String type,
String comment,
String stmt)
stmt, wrapped in
assertion check demarcation. The returned code has the
following structure.
// comment
if (JMLChecker.isActive(JMLChecker.type)) {
JMLChecker.enter();
stmt;
JMLChecker.exit();
}
type - assertion type, e.g., PRECONDITION, etc.comment - header commentstmt - statement to be wrapped
protected String wrap2(String type,
String comment,
String stmt)
stmt, wrapped in
assertion check demarcation. The whole code is indented two
tabs. The returned code has the following structure.
// comment
if (JMLChecker.isActive(JMLChecker.type)) {
JMLChecker.enter();
stmt;
JMLChecker.exit();
}
type - assertion type, e.g., PRECONDITION, etc.comment - header commentstmt - statement to be wrapped
protected String wrap3(String type,
String comment,
String stmt)
stmt, wrapped in
assertion check demarcation. The whole code is indented three
tabs. The returned code has the following structure.
// comment
if (JMLChecker.isActive(JMLChecker.type)) {
JMLChecker.enter();
stmt;
JMLChecker.exit();
}
type - assertion type, e.g., PRECONDITION, etc.comment - header commentstmt - statement to be wrappedprotected String isActive(String type)
ensures \result.equals("JMLChecker.isActive(JMLChecker." + type +")");
protected String identification(String state)
protected String racMethodName(String type)
requires (* type is MN_CHECK_PRE, MN_CHECK_POST, MN_CHECK_XPOST, etc.*); ensures \result.equals(type + ident + "$" + typeName);
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||