|
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.TransConstraint
A class for translating JML (history) constraints. A history constraint is translated into a couple of constraint check methods, one for static (class) constraints and the other for non-static (instance) constraints. The translation also produce a couple of old expression evaluation methods, one for static constraints and the other for both static and non-static constraints. The latter is supposed to be called by non-static methods. The old expression evaluation methods, if called in the pre-state, evaluate old expressions appearing in the constraints and store the results to newly introduced private fields, called old expression fields. An old expression field is a temporary location to hold the value of an old expression (evaluated in the pre-state). The constraint check methods use the old variable in place of the original old expression. The client of this class is responsible for (1) adding constraint check methods and old expression evaluation methods to the host type declaration containing the target constraint clauses, (2) declaring appropriate old expression fields to the host type declaration, and (3) making calls to the old expression evaluation methods in the appropriate pre-state (e.g., in the wrapper method).
ConstraintMethod| Field Summary | |
private List |
oldExprsInstance
The set of (translated) old expressions appearing in the non-static constraints. |
private List |
oldExprsStatic
The set of (translated) old expressions appearing in the static constraints. |
private List |
restoreMethods
The names of restore methods generated so far. |
private List |
stackVarsInstance
The set of private stack field names used to save and restore old expression values appearing in non-static constraint clauses. |
private List |
stackVarsStatic
The set of private stack field names used to save and restore old expression values appearing in static constraint clauses. |
private JmlTypeDeclaration |
typeDecl
The host type declaration containing the target constraint clause to be translated by this translator. |
private VarGenerator |
varGen
The variable generator to be used in the translation. |
| Fields inherited from class org.jmlspecs.jmlrac.TransUtils |
|
| 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 | |
TransConstraint(JmlTypeDeclaration typeDecl,
VarGenerator varGen)
Constructs a TransConstraint object. |
|
| Method Summary | |
private RacNode |
constraintMethod(boolean forStatic,
int cnt,
JExpression pred,
JmlMethodName[] names)
Returns a constraint check method that checks the given predicate, pred as a hisotry constraint. |
private RacNode |
constraintMethod(JmlConstraint constraint,
int cnt)
Returns a constraint check method for the given hisotry constraint, constraint. |
private RacNode |
constraintMethod(JmlConstraint[] constraints,
boolean forStatic)
Returns a static or an instance constraint check method for the given history constraints, constraints. |
private String |
evalSuperHC(VarGenerator varGen,
boolean forStatic,
CClass clazz)
Return code that evaluates the old expressions of the given supertype, clazz, by making an appropriate call to
its old expression evaluation method. |
private RacNode |
genStackMethods(boolean forStatic,
String stackVar,
List oldExprs)
Returns a private stack field declaration with a pair of push and pop methods. |
private static boolean |
isCheckable(JmlConstraint cons)
Returns true if the given constraint clause is checkable. |
PreValueVars.Entry[] |
oldExprFields(boolean forStatic)
Returns field declarations for the old expressions appearing in the constraint clause. |
private RacNode |
oldMethod(List exprs,
boolean forStatic)
Returns an old-expression evaluation method for the given old expressions, exprs. |
RacNode |
translate(JmlConstraint[] constraints)
Translates the given history constraints, constraints, and returns the translation result. |
| 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 |
private final JmlTypeDeclaration typeDecl
private final VarGenerator varGen
private List oldExprsStatic
RacNode),
which, if executed, evaluate the old expression and store the
result into a freshly introduced field, called an old
expression field. The name of the old expression field is
given by the name field of the class
RacNode in the form of
"T n;\n", where T is the type and
n is the field name.
public invariant (\forall Object o; oldExprsStatic.contains(o); o instanceof RacNode);
TransPostcondition.visitJmlPreExpression(JmlPreExpression),
TransPostcondition.visitJmlOldExpression(JmlOldExpression)private List oldExprsInstance
RacNode),
which, if executed, evaluate the old expression and store the
result into a freshly introduced field, called an old
expression field. The name of the old expression field is
given by the name field of the class
RacNode in the form of
"T n;\n", where T is the type and
n is the field name.
public invariant (\forall Object o; oldExprsInstance.contains(o); o instanceof RacNode);
TransPostcondition.visitJmlPreExpression(JmlPreExpression),
TransPostcondition.visitJmlOldExpression(JmlOldExpression)private List stackVarsStatic
private invariant (\forall Object o; stackVarsStatic.contains(o); o instanceof String);
private List stackVarsInstance
private invariant (\forall Object o; stackVarsInstance.contains(o); o instanceof String);
private List restoreMethods
private invariant (\forall Object o; restoreMethods.contains(o); o instanceof String);
| Constructor Detail |
public TransConstraint(JmlTypeDeclaration typeDecl,
VarGenerator varGen)
TransConstraint object.
requires typeDecl != null && varGen != null;
typeDecl - host type declaration containing the target
constraint clause to be translatedvarGen - variable generator to be used for the translation| Method Detail |
public PreValueVars.Entry[] oldExprFields(boolean forStatic)
[static] T n;\n", where
T is the type and n is the field
name. Note that the old expression evaluation methods, returned
by the method translate, if called, evaluate old
expressions and initialize the declared fields.
These fields are called old expression fields.
This method must be called after the translation.
ensures \result != null;
forStatic - true for static old expressions;
false for instance old expressions.translate(JmlConstraint[]),
oldExprsStatic,
oldExprsInstance,
PreValueVars.Entrypublic RacNode translate(JmlConstraint[] constraints)
constraints, and returns the translation result.
This method translates the given history constraints and
produces a couple of new field declarations and several new
methods:
ConstraintMethod).ConstraintMethod).The old expression evaluation methods, if called, evaluate the old expressions appearing in the constraints and store the results into newly introduced fields, called old expression fields. The old expression fields are used instead of the original old expressions by the constraint check methods. The generated methods are concatenated and returned as the translation result.
The stack variables and their access methods are used to correctly pass, in the presence recursive method calls, old expression values evaluated in the pre=state to the constraint check methods executed in the post-state.
requires constraints != null; assignable oldExprsStatic, oldExprsInstance; assignable stackVarsStatic, stackVarsInstance, restoreMethods; ensures \result != null;
constraints - history constraints to be translatedoldExprFields(boolean)
private RacNode constraintMethod(JmlConstraint[] constraints,
boolean forStatic)
constraints. As a
side-effect, this method also translates and accumulates into
private fields old expressions appearing in the constraints for
future use.
requires constraints != null; assignable oldExprsStatic, oldExprsInstance; assignable stackVarsStatic, stackVarsInstance, restoreMethods; ensures \result != null;
constraints - history constraints to be translatedforStatic - type of constraints to be translated
(static or non-static)
RacNode representing a
constraint check method.oldExprsStatic,
oldExprsInstance
private RacNode constraintMethod(JmlConstraint constraint,
int cnt)
constraint. The parameter
cnt is used as a suffix for the name of generated
check method. As a side-effect, this method also translates and
accumulates into private fields all the old expressions
appearing in the given constraint.
requires constraint != null; assignable oldExprsStatic, oldExprsInstance; assignable stackVarsStatic, stackVarsInstance; ensures \result != null;
constraint - history constraint to be translated
RacNode representing a
constraint check method.oldExprsStatic,
oldExprsInstance,
stackVarsStatic,
stackVarsInstance
private RacNode constraintMethod(boolean forStatic,
int cnt,
JExpression pred,
JmlMethodName[] names)
pred as a hisotry constraint. If the
parameter forStatic is true, the given predicate
is regarded as a static constraint; otherwise, it is regared as
a non-static constraint. The parameter cnt is
used as a suffix for the name of generated check method. As a
side-effect, this method also translates and accumulates into
private fields all the old expressions appearing in the given
constraint.
assignable oldExprsStatic, oldExprsInstance; assignable stackVarsStatic, stackVarsInstance; ensures \result != null;
RacNode representing a
constraint check method.oldExprsStatic,
oldExprsInstance,
stackVarsStatic,
stackVarsInstance,
restoreMethodsprivate static boolean isCheckable(JmlConstraint cons)
private RacNode oldMethod(List exprs,
boolean forStatic)
exprs. The resulting method, if
called, evaluates old expressions given by exprs
and stores the results into the so-called old expression
fields.
requires exprs != null && (\forall Object o; exprs.contains(o); o instanceof RacNode); ensures \result != null;
exprs - a list of (translated) old expressions
(RacNode)forStatic - type of constraint (static or non-static)
RacNode representing an old
expression evaluation method.oldExprsStatic,
oldExprsInstance
private String evalSuperHC(VarGenerator varGen,
boolean forStatic,
CClass clazz)
clazz, by making an appropriate call to
its old expression evaluation method.
#reflectiveCall(CClass)
private RacNode genStackMethods(boolean forStatic,
String stackVar,
List oldExprs)
private [static] Stack var = new Stack();
private [static] void saveTo$var() {
Object val[] = new Object[n];
val[1] = preVar1;
...
val[n] = preVarn;
var.push(val);
}
private [static] void restoreFrom$var() {
Object val[] = (Object[]) var.pop();
preVar1 = val[1];
...
preVarn = val[n];
}
requires (\forall Object o; oldExprs.contains(o); o instanceof PreValueVars.Entry); assignable \nothing;
forStatic - true if the stack and methods should be staticstackVar - name of the stack field to be declaredoldExprs - fields to store into and restore from the stack
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||