|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.jmlspecs.jmlrac.qexpr.TransQuantifiedExpression
An abstract class for translating JML quantified expressions into Java source code. The translation rules for the JML universal/existential quantified expressions are defined as follows.
[[(\forall T x; P; Q), r]] =
Collection c = null;
[[S, c]] // S is the qset of P ==> Q
r = c != null;
if (r) {
Iterator iter = c.iterator();
for (r && iter.hasNext()) {
T x = iter.next();
[[P ==> Q, r]]
}
}
[[(\exists T x; P; Q), r]] =
Collection c = null;
[[S, c]] // S is the qset of P && Q
r = c == null;
if (!r) {
Iterator iter = c.iterator();
for (!r && iter.hasNext()) {
T x = iter.next();
[[P && Q, r]]
}
}
The translation rules for other quantifiers are defined in a
similar way.
TransExpression.visitJmlSpecQuantifiedExpression(
JmlSpecQuantifiedExpression)| Field Summary | |
private RacContext |
context
Current translation context. |
private JmlSpecQuantifiedExpression |
quantiExp
quantified expression to be translated. |
private String |
resultVar
variable name to store the value of quantified expression in the translated code. |
private AbstractExpressionTranslator |
transExp
translator for translating subexpressions |
private VarGenerator |
varGen
variable generator for generating unique local variables. |
| Constructor Summary | |
TransQuantifiedExpression(VarGenerator varGen,
RacContext context,
JmlSpecQuantifiedExpression expr,
String resultVar,
AbstractExpressionTranslator transExp)
Constructs a new instance. |
|
| Method Summary | |
RacNode |
generateLoop(RacNode node)
Tanslates a JML quantified expression into Java source code that, if executed, evaluates the given statement, node for each combination of bound variables of
the quantified expression. |
private RacNode |
nonExecutableQuantifiedExpression()
Translates a non-executable quantified expression. |
RacNode |
translate()
Translates a JML quantified expression into Java source code and return the translated code. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private VarGenerator varGen
private RacContext context
private JmlSpecQuantifiedExpression quantiExp
private String resultVar
private AbstractExpressionTranslator transExp
| Constructor Detail |
public TransQuantifiedExpression(VarGenerator varGen,
RacContext context,
JmlSpecQuantifiedExpression expr,
String resultVar,
AbstractExpressionTranslator transExp)
varGen - variable generator to be used during translation to
generate unique local variables.expr - quantified expression to be translated.resultVar - variable name to have the value of quantified
expression in the translated code.transExp - translator to use for translating subexpressions of
the quantified expression.| Method Detail |
public RacNode translate()
TransQuantifiedExpression for the format of the generated
code.
if - the quantified expression is not executable.
public RacNode generateLoop(RacNode node)
throws NonExecutableQuantifierException
node for each combination of bound variables of
the quantified expression. For example, given a quantified expression
(\forall int i;
i >= 0 && i < this.v.length;
this.v[i] >= \old(this.v[i]))
this method generates the following code:
int i = 0;
int l = this.v.length;
while (i < l) {
[[code for argument node]]
i = i + 1;
}
where l is a unique local variable generated by
the runtime assertion checker compiler.
This method is used in translating old expressions contained in
quantified expressions.
if - the quantified expression is not executable.
NonExecutableQuantifierExceptionTransPostcondition.visitJmlOldExpression(JmlOldExpression),
TransPostcondition#oldExpressionInQuantifiers(JmlOldExpression)private RacNode nonExecutableQuantifiedExpression()
resultVar = true/false;, if the contextual
translation is enabled. Otherwise, it is translated into the
following code:
if (true) {
throw new JMLNonExecutableException();
}
A non-boolean typed quantified expression is also translated
into the above if statement.
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||