/* valaforstatement.vala
*
- * Copyright (C) 2006-2009 Jürg Billeter
+ * Copyright (C) 2006-2010 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
return (literal != null && literal.value);
}
+ bool always_false (Expression condition) {
+ var literal = condition as BooleanLiteral;
+ return (literal != null && !literal.value);
+ }
+
public override bool check (SemanticAnalyzer analyzer) {
// convert to simple loop
}
// do not generate if block if condition is always true
- if (condition != null && !always_true (condition)) {
+ if (condition == null || always_true (condition)) {
+ } else if (always_false (condition)) {
+ // do not generate if block if condition is always false
+ body.insert_statement (0, new BreakStatement (condition.source_reference));
+ } else {
// condition
var if_condition = new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, condition, condition.source_reference);
var true_block = new Block (condition.source_reference);