|
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.TransMethod
A class for translating JML annotated Java methods into RAC-enabled methods. The translation produces new methods and fields that must be added to the target class, and also renames the original method.
A non_null annotation to a formal parameter is
interpreted as a part of preconditions. That is, a
non_null annotation to a formal parameter, say
x, has the same effect as conjoining the predicate
x != null to the precondition of the method.
| Nested Class Summary | |
protected static class |
TransMethod.GeneralSpecCase
A concrete wrapper class to JmlGeneralSpecCase for
conjoining multiple specification clauses in a specification
case. |
protected static class |
TransMethod.SpecCase
An abstract superclass for conjoining multiple specification clauses, such as requires and ensures
clauses, in a specification case. |
protected static class |
TransMethod.SpecCaseCollector
A class for collecting all specification cases from a desugared method specification. |
| Field Summary | |
protected JmlMethodSpecification |
desugaredSpec
desugared specification of the target method to be translated |
protected boolean |
genSpecTestFile
True if we are generating a test wrapper for a spec file (and we do not have the original source). |
protected JmlMethodDeclaration |
methodDecl
target method to be transformed. |
protected List |
newFields
newly created fields (as the result of translation) that need be added to the target class, e.g., old and precondition variables |
protected List |
newMethods
newly created methods (as the result of translation) that need be added to the target class |
private String |
stackVar
|
protected JmlTypeDeclaration |
typeDecl
Target type declaration whose methods are to be translated. |
protected VarGenerator |
varGen
for generating fresh variables needed in the generated Java code |
| 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 | |
TransMethod(JmlTypeDeclaration typeDecl,
VarGenerator varGen)
Constructs a new TransMethod object. |
|
| Method Summary | |
protected TransPostcondition |
createPostconditionTranslator(VarGenerator postVarGen,
RacContext ctx,
VarGenerator preVarGen,
boolean isStatic,
JExpression pred,
String var)
Creates an appropriate postcondition translator. |
protected PreValueVars |
genAssertionMethods()
Generates pre/postcondition check methods. |
protected JStatement[] |
genDelegatedMethod()
Generates a method body for a non-abstract method that does not have an implementation; it is used to generate test fixtures for specification files in the absence of .java implementations. |
protected void |
genStackMethod(PreValueVars vars)
Generates a private stack field declaration and a pair of push and pop methods. |
protected void |
genWrapperMethod()
Renames the original method and generate a wrapper method that calls the original method wrapped with pre and postcondition checking. |
boolean |
hasNewFields()
Returns true if any new field declarations has been generated as the result of translation. |
boolean |
hasNewMethods()
Returns true if any new method declarations has been generated as the result of translation. |
private boolean |
methodHasRealExplicitSpecs()
|
protected String |
methodName()
Returns the name of the targe method declaration being translated. |
private boolean |
methodReturnTypeHasExplicitNullityModifiers()
|
List |
newFields()
Returns a list of new field declarations created by this translation, which need be added to the target class or interface. |
List |
newMethods()
Returns a list of new method declaratons created by this transformation, and need be added to the target class or instance. |
private boolean |
paramsHaveExplicitNullityModifiers()
|
void |
perform(JmlMethodDeclaration methodDecl)
Peforms translation leaving the results in appropriate instance variables. |
protected JExpression |
postNonNullAnnotation()
Returns an expression conjoinable to the normal postcondition, that checks the non_null annotation of the method
declaration. |
protected JExpression |
preNonNullAnnotations()
Composes the (implicit or explicit) non_null annotations of formal
parameters, if any, into a JML expression and return it. |
private JExpression |
preNonNullAnnotationsDefaultToTrueExpr()
|
protected List |
translateForAllVarDecl(JmlSpecVarDecl varDecl,
VarGenerator varGen)
Translates the given forall variable declarations. |
protected List |
translateLetVarDecl(JmlSpecVarDecl varDecl,
VarGenerator varGen)
Translates the given old variable declarations. |
protected RacNode |
translateSignalsClause(VarGenerator varGen,
VarGenerator oldVarGen,
JmlSignalsClause sigClause,
String preVar,
RacNode stmt,
List oldExprs)
Translates the given signals clause. |
protected List |
translateSpecVarDecls(JmlSpecVarDecl[] varDecls,
VarGenerator varGen)
Translates specification variable declarations. |
| 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 boolean genSpecTestFile
protected final JmlTypeDeclaration typeDecl
protected invariant typeDecl != null;
protected JmlMethodDeclaration methodDecl
protected invariant methodDecl != null ==> typeDecl.methods().contains(methodDecl);
protected List newFields
protected List newMethods
protected JmlMethodSpecification desugaredSpec
protected VarGenerator varGen
private String stackVar
| Constructor Detail |
public TransMethod(JmlTypeDeclaration typeDecl,
VarGenerator varGen)
TransMethod object.
typeDecl - target type declaration whose methods are to be
translated.varGen - variable name generator
requires typeDecl != null && varGen != null;
| Method Detail |
public boolean hasNewFields()
ensures \result == newFields.size() > 0;
public boolean hasNewMethods()
ensures \result == newMethods.size() > 0;
public List newFields()
ensures \result != null && (\forall Object o; \result.contains(o); (o instanceof String) && (* o has the form: "[static] T v = init;\n" *));
public List newMethods()
ensures \result != null && (\forall Object o; \result.contains(o); (o instanceof JmlMethodDeclaration));
public void perform(JmlMethodDeclaration methodDecl)
methodDecl - method to translate
requires methodDecl != null && typeDecl.methods().contains(methodDecl); assignable newMethods, newFields, this.methodDecl, desugaredSpec; assignable stackVar;
protected PreValueVars genAssertionMethods()
newMethods and
newFields respectively. Returned is the set of
(generated) private fields that need to be saved before, and
restored after the execution of the method body, due to
the possiblity of recursive method calls.
requires (* desugaredSpec has desugared method spec *); //assignable newMethods, newFields, stackVar; ensures \result != null;
protected TransPostcondition createPostconditionTranslator(VarGenerator postVarGen,
RacContext ctx,
VarGenerator preVarGen,
boolean isStatic,
JExpression pred,
String var)
protected List translateSpecVarDecls(JmlSpecVarDecl[] varDecls,
VarGenerator varGen)
requires varDecls != null && varGen != null; ensures \fresh(\result) && (\forall Object o; \result.contains(o); o instanceof RacNode);
varDecls - declarations to be translatedvarGen - variable generator for fresh variable names
RacNodes, representing translated
initializers with the corresponding new field
declarations. The field declarations are
piggybacked in the name fields of nodes.JMLRacValue
protected List translateLetVarDecl(JmlSpecVarDecl varDecl,
VarGenerator varGen)
requires varDecl != null && varGen != null; ensures \fresh(\result) && (\forall Object o; \result.contains(o); o instanceof RacNode);
varDecl - declaration to be translatedvarGen - variable generator for fresh variable names
RacNodes representing translated
code with the new instance field declarations.
The field declarations are piggybacked in the
name fields of RacNode.JMLRacValue
protected List translateForAllVarDecl(JmlSpecVarDecl varDecl,
VarGenerator varGen)
requires varDecl != null && varGen != null; ensures \fresh(\result) && (\forall Object o; \result.contains(o); o instanceof RacNode);
varDecl - declaration to be translatedvarGen - variable generator for fresh variable names
RacNodes representing translated
code with the corresponding instance field declarations.
The field declarations are piggybacked in the
name fields of RacNode.JMLRacValue
protected RacNode translateSignalsClause(VarGenerator varGen,
VarGenerator oldVarGen,
JmlSignalsClause sigClause,
String preVar,
RacNode stmt,
List oldExprs)
signals clause. The overall
translation rule for exceptional postconditions is roughly
defined as follows.
[[signals (Ei ei) Pi]] =
if (e instanceof Ei) {
Ei ei = (Ei) e;
boolean vi = false;
[[Pi, vi]]
b = b && vi;
}
check(b);
if (e instanceof java.lang.RuntimeException)
throw (java.lang.RuntimeException) e;
else if (e instanceof java.lang.Error)
throw (java.lang.Error) e;
if (e instanceof CEi)
throw (CEi) e;
where the variable e refers to actual exceptions thrown
and b conjoins the results of evaluating all exceptional
predicates. Both variables are defined in the body of exceptional
postcondition checking method. If the exceptional postcondition
is satisfied, the original exception is rethrown at the end;
CEi denotes a checked exception that is listed in the
method declaration.
This method method produces the first if statement
(of the translation rule) corresponding to the given
signals clause. The method accumulates the generated
if statement by appending it to the argument
stmt. The accumulated if statements is
is returned as the result. The method also accumulates the translated
old expressions appearing in the given signals clause
to the argument oldExprs. For the translation, the
method uses the variable generator varGen to generate
fresh variables and the variable generator oldVarGen
for fresh old variables.
varGen - variable generator for fresh variablesoldVarGen - variable generator for old variablessigClause - the signals clause to translatepreVar - precondition variablestmt - accumlated result of signals clauses translationoldExprs - old expressions accumulated so far
requires varGen != null && oldVarGen != null && sigClause != null
&& preVar != null && oldExprs != null;
modifies oldExprs.theList;
ensures \result != null;
protected void genWrapperMethod()
T m(T1 x1, ..., Tn xn) {
checkPre$m(x1, ..., xn);
T r = init_T;
try {
r = orig$m(x1, ..., xn);
}
catch (Exception e) {
checkExcept$m(x1, ..., xn, e);
}
checkPost$m(x1, ..., xn, r);
}
protected JStatement[] genDelegatedMethod()
protected void genStackMethod(PreValueVars vars)
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];
}
private boolean methodReturnTypeHasExplicitNullityModifiers()
private boolean paramsHaveExplicitNullityModifiers()
private JExpression preNonNullAnnotationsDefaultToTrueExpr()
protected JExpression preNonNullAnnotations()
non_null annotations of formal
parameters, if any, into a JML expression and return it.
If all parameters are nullable then,
the method returns null.
ensures (* \result may be null *);
protected JExpression postNonNullAnnotation()
non_null annotation of the method
declaration. If the method declaration is nullable then
null is returned.
private boolean methodHasRealExplicitSpecs()
protected String methodName()
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||