visitor.visit_end_full_expression (condition);
}
- bool always_true (Expression condition) {
- unowned BooleanLiteral? literal = condition as BooleanLiteral;
- return (literal != null && literal.value);
- }
-
public override void replace_expression (Expression old_node, Expression new_node) {
if (condition == old_node) {
condition = new_node;
// convert to simple loop
// do not generate variable and if block if condition is always true
- if (always_true (condition)) {
+ if (condition.is_always_true ()) {
var loop = new Loop (body, source_reference);
unowned Block parent_block = (Block) parent_node;
return true;
}
+ /**
+ * Check whether this expression is always true.
+ */
+ public bool is_always_true () {
+ unowned BooleanLiteral? literal = this as BooleanLiteral;
+ return (literal != null && literal.value);
+ }
+
+ /**
+ * Check whether this expression is always false.
+ */
+ public bool is_always_false () {
+ unowned BooleanLiteral? literal = this as BooleanLiteral;
+ return (literal != null && !literal.value);
+ }
+
public Statement? parent_statement {
get {
unowned Expression? expr = parent_node as Expression;
}
}
- bool always_true (Expression condition) {
- unowned BooleanLiteral? literal = condition as BooleanLiteral;
- return (literal != null && literal.value);
- }
-
- bool always_false (Expression condition) {
- unowned BooleanLiteral? literal = condition as BooleanLiteral;
- return (literal != null && !literal.value);
- }
-
public override void visit_if_statement (IfStatement stmt) {
if (unreachable (stmt)) {
return;
// true block
var last_block = current_block;
- if (always_false (stmt.condition)) {
+ if (stmt.condition.is_always_false ()) {
mark_unreachable ();
} else {
current_block = new BasicBlock ();
// false block
var last_true_block = current_block;
- if (always_true (stmt.condition)) {
+ if (stmt.condition.is_always_true ()) {
mark_unreachable ();
} else {
current_block = new BasicBlock ();
}
}
- bool always_true (Expression condition) {
- unowned BooleanLiteral? literal = condition as BooleanLiteral;
- return (literal != null && literal.value);
- }
-
- bool always_false (Expression condition) {
- unowned BooleanLiteral? literal = condition as BooleanLiteral;
- return (literal != null && !literal.value);
- }
-
public override bool check (CodeContext context) {
if (checked) {
return !error;
}
// do not generate if block if condition is always true
- if (condition == null || always_true (condition)) {
- } else if (always_false (condition)) {
+ if (condition == null || condition.is_always_true ()) {
+ } else if (condition.is_always_false ()) {
// do not generate if block if condition is always false
body.insert_statement (0, new BreakStatement (condition.source_reference));
} else {
body.accept (visitor);
}
- bool always_true (Expression condition) {
- unowned BooleanLiteral? literal = condition as BooleanLiteral;
- return (literal != null && literal.value);
- }
-
- bool always_false (Expression condition) {
- unowned BooleanLiteral? literal = condition as BooleanLiteral;
- return (literal != null && !literal.value);
- }
-
public override void replace_expression (Expression old_node, Expression new_node) {
if (condition == old_node) {
condition = new_node;
// convert to simple loop
- if (always_true (condition)) {
+ if (condition.is_always_true ()) {
// do not generate if block if condition is always true
- } else if (always_false (condition)) {
+ } else if (condition.is_always_false ()) {
// do not generate if block if condition is always false
body.insert_statement (0, new BreakStatement (condition.source_reference));
} else {