|
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.TransInterface
A class for translating JML interface declarations. The translation
produces an inner class in the interface, called a surrogate
class. The surrogate class takes the responsibility of
checking assertions of the interface and thus defines all the
assertion check methods for the interface. This class supports the
Template Method Pattern laid out by the abstract
superclass TransType.
| Field Summary | |
private RacNode |
hcMethod
History constraint check methods for the current interface. |
private JmlInterfaceDeclaration |
interfaceDecl
Target interface to be translated. |
private RacNode |
invMethod
Invariant check methods for the current interface. |
private List |
newFields
New field declarations to be added to the surrogate class. |
private List |
newMethods
New mehtod declarations to be added to the surrogate class. |
private static TokenReference |
NO_REF
Null token reference. |
| 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 |
| Constructor Summary | |
TransInterface(JmlInterfaceDeclaration interfaceDecl)
Construct a TransInterface object. |
|
| Method Summary | |
protected void |
addNewMethod(JmlMethodDeclaration mdecl)
Adds a new method declaration, mdecl, to
the surrogate class to be generated in the finalization step of
this translation. |
protected JmlMethodDeclaration |
assertionInheritanceMethod()
Returns a method declaration implementing dynamic inheritance using the Java's reflection facility. |
private JmlMethodDeclaration |
concreteMethod(CMethod mdecl)
Returns a concrete (delegation) method that implements the abstract method declaration, mdecl. |
private RacNode |
concreteMethods()
Returns concrete method declarations, often called delegation methods, that implements the abstract methods declared in the interface (and its super-interfaces). |
private JmlMethodDeclaration |
defaultModelFieldAccessor(CField field)
Returns a default accessor method for a model field, field. |
protected void |
finalizeTranslation()
Finalizes the translation of this interface. |
private void |
genSurrogateClass(RacNode newFdecls,
RacNode newMdecls)
Generates a surrogate class for the interface declaration being translated. |
protected JmlMethodDeclaration |
ghostFieldAccessors(JmlFieldDeclaration fdecl)
Returns a pair of ghost field accessor methods (getter and setter) for the given ghost field declaration. |
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. |
private JmlMethodDeclaration |
specPublicMethodAccessor(JmlMethodDeclaration mdecl)
Returns an access method for the given spec_public (or spec_protected) method declaration, mdecl. |
protected String |
surrogatePlaceHolders(RacNode newFdecls,
RacNode newMdecls,
RacNode mdecls)
Returns a place holder string ($0... |
protected Object[] |
surrogatePlaceValues(RacNode newFdecls,
RacNode newMdecls,
RacNode mdecls)
Returns an array of objects representing actual values for the place holder. |
protected void |
translateConstraint()
Translates constraint clauses of this interface declaration. |
protected JmlFieldDeclaration |
translateField(JmlFieldDeclaration fieldDecl)
Translates the given JML field declaration, fieldDecl, by specially handling final, model, model,
spec_public, and spec_protected fields. |
protected void |
translateInvariant()
Translates invariant clauses of this interface 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, dynamicInvocationMethod, findTypeWithRepresentsFor, forNameMethod, ident, initFlags, isAccessorGenerated, isInterface, postTranslationChangesForSpecTestFile, setAccessorGenerated, translate, translateBody, 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 JmlInterfaceDeclaration interfaceDecl
private invariant interfaceDecl == (JmlInterfaceDeclaration)typeDecl;
private List newMethods
private List newFields
private RacNode invMethod
private RacNode hcMethod
private static final TokenReference NO_REF
| Constructor Detail |
public TransInterface(JmlInterfaceDeclaration interfaceDecl)
TransInterface object.
interfaceDecl - target interface declaration to be translated| Method Detail |
protected void translateInvariant()
also modifies invMethod;
protected void translateConstraint()
also modifies hcMethod;
protected JmlFieldDeclaration translateField(JmlFieldDeclaration fieldDecl)
fieldDecl, by specially handling final, model, model,
spec_public, and spec_protected fields.
If this is a model field and has no accessor method generated yet
(i.e., by represents clauses), generates the following
form of default model accessor method:
[[... model T m ...;]] ==
protected T m() {
throw new JMLNonExecutableException();
}
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 code is added to the surrogate class.
also requires fieldDecl != null; modifies modelMethods, interfaceDecl, newMethods;
translateField in class TransType#translateRepresents(JmlRepresentsDecl[]),
ghostFieldAccessors(JmlFieldDeclaration),
#modelMethodsprotected 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).
also requires mdecl != null; modifies newMethods, newFields;
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();
protected void finalizeTranslation()
also modifies interfaceDecl, newMethods;
finalizeTranslation in class TransType
private void genSurrogateClass(RacNode newFdecls,
RacNode newMdecls)
public class JmlSurrogate implements I, JMLSurrogate {
public JmlSurrogate(JMLCheckeble self) {
super(self);
}
public T1 m1(...) {
try {
return self.m1(...);
}
catch (java.lang.Throwable e) {
throw new java.lang.RuntimeException();
}
}
...
public Tn mn(...) {
...
}
private JMLCheckable self;
}
where I is the name of the interface being
translated. The interface JMLSurrogate defines properties that
all surrogate classes have to implement, and the interface
JMLCheckable defines properties for implementing classes. Both
interfaces together define the minimal protocol for the
surrogate class and the implementing class to communicate with
each other for dynamic delegation.
modifies interfaceDecl;
newFdecls - field declarations to be added to the
surrogate class. It may be null.newMdecls - method declarations (e.g., assertion check
methods) to be added to the surrogate class. It may be null.
protected String surrogatePlaceHolders(RacNode newFdecls,
RacNode newMdecls,
RacNode mdecls)
surrogatePlaceValues(RacNode, RacNode, RacNode)
protected Object[] surrogatePlaceValues(RacNode newFdecls,
RacNode newMdecls,
RacNode mdecls)
surrogatePlaceHolders(RacNode, RacNode, RacNode)private RacNode concreteMethods()
concreteMethod for
the general structure of the delegation method.
concreteMethod(CMethod),
genSurrogateClass(RacNode, RacNode)private JmlMethodDeclaration concreteMethod(CMethod mdecl)
mdecl. The returned
method delegates calls to the corresponding method in the
implementing class. The general structure of the delegation
method is as follows.
public T1 m1(...) {
try {
return self.m1(...);
}
catch (java.lang.Throwable e) {
throw new java.lang.RuntimeException();
}
}
Since delegation methods are called only for evaluating
interface assertions, all exceptions are caught and re-thrown
as RuntimeException.
concreteMethod(CMethod),
requires mdecl != null;
ensures \result != null;
private JmlMethodDeclaration defaultModelFieldAccessor(CField field)
field. A default model field access method performs
a dynamic call to the corresponding model field access method of
the implementing class and has the following form:
public [static] T model$n() {
String cn = self.getClass().getName();
Object obj = rac$invoke(cn, self, "model$n", null, null);
return unwrapObject(T, obj);
}
protected JmlMethodDeclaration ghostFieldAccessors(JmlFieldDeclaration fdecl)
MN_GHOST + ident + "$" + className,
where the constant MN_GHOST is usually "ghost$"
and ident is the name of the ghost field. The
accessor methods has the following general structure:
public [static] T ghost$v$C() {
return v;
}
public [static] void ghost$v$C(T x) {
v = x;
}
This method also generates a private field for storing ghost
values and possibly an initializer block too.
private [static] T v;
[static] {
v = initializer;
}
This method is overwritten here to combine code for accessors
and the new private field declaration and return it as a single
object. In the overwritten method, the new field declaration is
piggybacked in the given field declaration for later
pretty-printing (see RacPrettyPrinter.visitJmlFieldDeclaration).
ghostFieldAccessors in class TransTypeTransType.ghostFieldAccessors(JmlFieldDeclaration)protected void addNewMethod(JmlMethodDeclaration mdecl)
mdecl, to
the surrogate class to be generated in the finalization step of
this translation.
protected String receiver(String clsName,
String clazz,
String receiver)
dynamicInvocationMethod to define a
subclass-specific dynamic invocation method.
also ensures \result.equals(TN_JMLSURROGATE + ".getReceiver(" + clazz + ", " + receiver + ")");
TransType.dynamicInvocationMethod()protected JmlMethodDeclaration assertionInheritanceMethod()
ensures \result != null;
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||