|
Has a generalization of the conventional meaning -- evaluates the first
expression (the condition) to a boolean. If it's true, evaluates
the second expression (the consequent). If it's last, evaluates
the third expression (the alternative). The value of the if expression
as a whole is the value of the consequent or alternative -- whichever
was executed.
|
"if" "(" eExpr ")" "{"
eExpr
"}" "else" "{"
eExpr
"}"
|
|
<!ELEMENT ifExpr (%eExpr;, %eExpr;, %eExpr;)>
|
|
If the condition doesn't define any variables used in the then-part,
and if the ifExpr as a whole is not used in a value-context (ie,
it is used in a for-effects-only context), then it translates
directly to the corresponding Java.
If it's used in a value-context, then a result variable is declared
ahead of time, and both branches assign to it.
If the condition does define variables used in the then-part,
XXX
|
|
if (getChar() =~ c ? (c != EOF)) {
println(c)
}
|
|
if (getChar.run() =~ c :any ? __equalizer.sameEver(c, EOF).not()) {
println.run(c)
} else {
null
}
|
|
<ifExpr>
<matchBindExpr>
<callExpr>
<Noun>getChar</Noun>
<Verb>run</Verb>
</callExpr>
<suchThatPattern>
<finalPattern>
<Noun>c</Noun>
<Noun>any</Noun>
</finalPattern>
<callExpr>
<callExpr>
<Noun>E</Noun>
<Noun>c</Noun>
<Verb>same</Verb>
<Noun>EOF</Noun>
</callExpr>
<Verb>not</Verb>
</callExpr>
</suchThatPattern>
</matchBindPattern>
<callExpr>
<Noun>println</Noun>
<Verb>run</Verb>
<Noun>c</Noun>
</callExpr>
<Noun>null</Noun>
</ifExpr>
|
|
Object result_7;
boolean result_6 = false;
Object c_tmp = Ref.broken(...);
fail_6: {
Object c = E.call(getChar, "run");
if (! E.toBoolean(E.call(E.same(c, EOF), "not"))) {
break fail_6;
}
//commit
result_6 = true;
c_tmp = c;
}
if (result_6) {
Object c = c_tmp;
result7 = E.call(println, "run", c);
} else {
result_7 = null;
}
|
There is one scope box containing both condition and consequent. There is
another scope box containing only the alternative. This means that both
condition and alternative see (have in scope) the same variable definition
visible to the if expression as a whole, but that the consequent sees the
variables defined in the condition. None of the variables defined in the
if expression are visible in the succeeding scope of the if expression. |
|