|
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.TransType
org.jmlspecs.jmlrac.TransClass
A class for translating JML class declarations. The translation
produces a set of assertion check methods for the class and any
necessary fields, e.g., to hold old values. This class implements
the Template Method Pattern layed out by the abstract
superclass TransType.
| Field Summary | |
private JmlClassDeclaration |
classDecl
Target class declaration to be translated. |
private boolean |
surrogateCacheNeeded
True if a cache for interface surrogates need be generated for the current class being translated. |
| Fields inherited from class org.jmlspecs.jmlrac.TransType |
dynamicInvocationMethodNeeded, genSpecTestFile, genWrapperClass, modelMethods, specInheritanceMethodNeeded, typeDecl, varGen |
| 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 |
| Fields inherited from interface org.multijava.mjc.Constants |
ACC_PURE, AMID_JAVA_MATH, AMID_MAX, AMID_SAFE_MATH, CMP_VERSION, JAV_ASSERTION_ERROR, JAV_CLASS, JAV_CLASSLOADER, JAV_CLASSNOTFOUND_EXCEPTION, JAV_CLONE, JAV_CLONEABLE, JAV_CONSTRUCTOR, JAV_ERROR, JAV_EXCEPTION, JAV_INIT, JAV_LENGTH, JAV_NAME_SEPARATOR, JAV_NOCLASSDEFFOUND_ERROR, JAV_OBJECT, JAV_OUTER_THIS, JAV_RMJ_RUNTIME_EXCEPTION, JAV_RUNTIME, JAV_RUNTIME_EXCEPTION, JAV_SERIALIZABLE, JAV_STATIC_INIT, JAV_STRING, JAV_STRINGBUFFER, JAV_SUPER, JAV_THIS, JAV_THROWABLE, MJ_ANCHOR, OPE_BAND, OPE_BNOT, OPE_BOR, OPE_BSR, OPE_BXOR, OPE_EQ, OPE_GE, OPE_GT, OPE_LAND, OPE_LE, OPE_LNOT, OPE_LOR, OPE_LT, OPE_MINUS, OPE_NE, OPE_PERCENT, OPE_PLUS, OPE_POSTDEC, OPE_POSTINC, OPE_PREDEC, OPE_PREINC, OPE_SIMPLE, OPE_SL, OPE_SLASH, OPE_SR, OPE_STAR, TID_ARRAY, TID_BOOLEAN, TID_BYTE, TID_CHAR, TID_CLASS, TID_DOUBLE, TID_FLOAT, TID_INT, TID_LONG, TID_MAX, TID_SHORT, TID_VOID, UNIV_ARRAY_TMP, UNIV_TMP |
| Constructor Summary | |
TransClass(JmlClassDeclaration classDecl)
Constructs a TransClass object. |
|
| Method Summary | |
protected void |
addNewMethod(JmlMethodDeclaration mdecl)
Adds a new method declaration, mdecl, to the
instrumented class. |
protected JmlMethodDeclaration |
assertionInheritanceMethod()
Returns a method declaration implementing dynamic inheritance using the Java's reflection facility. |
protected JmlMethodDeclaration |
constructionStatusAccessor()
Returns declarations of a private instance field and a protected access method for storing and accessing the status of an instance construction. |
protected TransMethod |
createMethodTranslator(JmlMethodDeclaration mdecl)
Creates a method translator for the given method declaration. |
private JmlConstructorDeclaration |
defaultConstructor()
Returns a default constructor for the target class declaration. |
private JmlMethodDeclaration |
defaultModelFieldAccessor(CField field)
Returns a default accessor method for a model field. |
protected JmlMethodDeclaration |
dynamicInvocationMethod()
Returns a method declaration that makes a dynamic call to the given method using the Java's reflection facility. |
protected void |
finalizeTranslation()
Performs a finialization of translation, e.g., generation of spec inheritance mechanism. |
private boolean |
generateAccessorsForInterfaceModelFields()
Generates access methods for all the model fields inherited from the interfaces of this class. |
private JFieldDeclarationType[] |
interfaceModelFields()
Returns all model fields inherited from the interfaces of this class, but excluding those also inherited from the superclass chain. |
private JmlMethodDeclaration |
modelFieldDelegationMethod(CField field,
JmlTypeDeclaration tdecl)
Returns a model field delegation method for model field, field, whose represents clause
is found in type tdecl. |
protected String |
receiver(String clsName,
String clazz,
String receiver)
Returns a string form of code that, if executed, returns the receiver of for a dynamic call. |
protected JmlMethodDeclaration |
specPublicAccessor(CField field)
Returns a default access method for a spec_public field. |
private JmlMethodDeclaration |
specPublicConstructorAccessor(JmlConstructorDeclaration mdecl)
Returns an access method for the given spec_public (or spec_protected) constructor declaration. |
private JmlMethodDeclaration |
specPublicMethodAccessor(JmlMethodDeclaration mdecl)
Returns an access method for the given spec_public (or spec_protected) method declaration, mdecl. |
protected JmlMethodDeclaration |
staticInvariantCheckInitializer()
Returns a static initializer that checks whether static invariants are established by the initialization of this class. |
protected JmlMethodDeclaration |
surrogateCacheDeclaration()
Returns a field declaration for an interface surroagte cache with a cache lookup method and a cache update method. |
private Set |
toSet(JFieldDeclarationType[] fdecls)
Returns a set containing elements from the given array. |
protected void |
translateBody(ArrayList inners,
ArrayList methods,
JPhylum[] fieldsAndInits)
Translates a class body of the target class declaration. |
protected void |
translateConstraint()
Translates constraint clauses of the target class. |
protected JmlFieldDeclaration |
translateField(JmlFieldDeclaration fieldDecl)
Translates a JML field declaration, fieldDecl, e.g.,
handling final, model, spec_public, and spec_protected. |
protected void |
translateInvariant()
Translates invariant clauses of this class declaration. |
protected void |
translateMethod(JmlMethodDeclaration mdecl)
Translates a JML method declaration. |
protected void |
translateModelMethod(JmlMethodDeclaration mdecl)
Translates the given model method (or constructor), mdecl. ! |
| Methods inherited from class org.jmlspecs.jmlrac.TransType |
dynamicCallNeeded, findTypeWithRepresentsFor, forNameMethod, ghostFieldAccessors, ident, initFlags, isAccessorGenerated, isInterface, postTranslationChangesForSpecTestFile, setAccessorGenerated, translate, translateForSpecTestFile, translateRepresents |
| 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 JmlClassDeclaration classDecl
private invariant classDecl == (JmlClassDeclaration)typeDecl;
private boolean surrogateCacheNeeded
private invariant dynamicInvocationMethodNeeded ==> surrogateCacheNeeded;
dynamicInvocationMethod(),
surrogateCacheDeclaration()| Constructor Detail |
public TransClass(JmlClassDeclaration classDecl)
TransClass object.
classDecl - target class declaration to be translated| Method Detail |
protected JmlFieldDeclaration translateField(JmlFieldDeclaration fieldDecl)
fieldDecl, e.g.,
handling final, model, spec_public, and spec_protected.
If this is a model field and it has no accessor method generated by
represents clauses, generate the following form of
default model accessor method:
[[... model T m ...;]] ==
protected T m() {
throw new JMLNonExecutableException();
}
The generated method declaration is added to the current class,
classDecl and its name is added to the field
modelMethods.
If the given declaration is a ghost field declaration, generates a pair of ghost field accessor methods (getter and setter), a private field for storing ghost values, and possibly an initialization block. The generated code has the following structure:
private [static] T v;
[static] {
v = initializer;
}
public [static] T ghost$v$C() {
return v;
}
public [static] void ghost$v$C(T x) {
v = x;
}
The generated accessors are added to the current class
declaration, and the new field declaration (with its
initialization block) is stored into the input field
declaration for later pretty-printing in the proper order.
also requires fieldDecl != null; modifies modelMethods, classDecl.*;
translateField in class TransType#translateRepresents(JmlRepresentsDecl[]),
#modelMethodsprotected void translateInvariant()
also modifies classDecl.*;
protected void translateConstraint()
also assignable classDecl.*;
TransConstraint
protected void translateBody(ArrayList inners,
ArrayList methods,
JPhylum[] fieldsAndInits)
translateBody in class TransTypeinners - inner classesmethods - mthod declarationsfieldsAndInits - field declarations
also requires inners != null && methods != null && fieldsAndInits != null;
protected void translateMethod(JmlMethodDeclaration mdecl)
PreconditionMethod).
PostconditionMethod and
ExceptionalPostconditionMethod).
WappersMethod).
The translation also generate several new instance fields to store temporally values used by the assertion checking methods. There are three kinds of variables that are generated and declared as instance fields.
Similarly, translation of JML constructor declaration also produces
four new methods, and the original constructor becomes a wrapper
method (refer to the class TransConstructor).
protected TransMethod createMethodTranslator(JmlMethodDeclaration mdecl)
protected void translateModelMethod(JmlMethodDeclaration mdecl)
mdecl. !FIXME!describe translation rules.
translateModelMethod in class TransTypeprivate JmlMethodDeclaration specPublicMethodAccessor(JmlMethodDeclaration mdecl)
mdecl. The
returned method has the following code structure.
public [static] T specPublic$m(x1, ..., xn) {
[return] m(x1, ..., xn);
}
requires mdecl.isSpecPublic() || mdecl.isSpecPublic();
private JmlMethodDeclaration specPublicConstructorAccessor(JmlConstructorDeclaration mdecl)
public static T specPublic$$init$(x1, ..., xn) {
return new T(x1, ..., xn);
}
where T is the name of type currently being
translated.
requires mdecl.isSpecPublic() || mdecl.isSpecPublic();
protected void finalizeTranslation()
finalizeTranslation in class TransTypeprotected JmlMethodDeclaration staticInvariantCheckInitializer()
protected JmlMethodDeclaration constructionStatusAccessor()
private boolean generateAccessorsForInterfaceModelFields()
defaultModelFieldAccessor(CField),
modelFieldDelegationMethod(CField, JmlTypeDeclaration)private JFieldDeclarationType[] interfaceModelFields()
private Set toSet(JFieldDeclarationType[] fdecls)
private JmlMethodDeclaration defaultModelFieldAccessor(CField field)
public [static] T model$n() {
throw new JMLNonExecutableException();
}
private JmlMethodDeclaration modelFieldDelegationMethod(CField field,
JmlTypeDeclaration tdecl)
field, whose represents clause
is found in type tdecl.
The returned method has the following form:
public [static] T model$n() {
Object obj = dynamic_delegation_to_accessor_method_in_tdecl();
return unwrapped_obj;
}
protected JmlMethodDeclaration specPublicAccessor(CField field)
spec_public field.
The returned method has the following form:
public [static] T spec$n() {
return x;
}
where x is the name of the given field.
protected void addNewMethod(JmlMethodDeclaration mdecl)
mdecl, to the
instrumented class.
private JmlConstructorDeclaration defaultConstructor()
protected JmlMethodDeclaration assertionInheritanceMethod()
ensures \result != null;
protected JmlMethodDeclaration surrogateCacheDeclaration()
JmlMethodDeclaration so
that it can be added to the current type declaration by using
addMember method.
protected JmlMethodDeclaration dynamicInvocationMethod()
dynamicInvocationMethod in class TransType
protected String receiver(String clsName,
String clazz,
String receiver)
dynamicInvocationMethod to define a
subclass-specific dynamic invocation method.
also ensures \result.equals("rac$receiver(" +clsName+ ", " +receiver+ ")");
TransType.dynamicInvocationMethod()
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||