ProgramCompiler::ExpressionEvaluator::ExpressionEvaluator():
variable_values(0),
+ const_only(false),
result(0.0f),
result_valid(false)
{ }
-ProgramCompiler::ExpressionEvaluator::ExpressionEvaluator(const ValueMap &v):
- variable_values(&v),
+ProgramCompiler::ExpressionEvaluator::ExpressionEvaluator(const ValueMap *v, bool c):
+ variable_values(v),
+ const_only(c),
result(0.0f),
result_valid(false)
{ }
{
if(!var.declaration)
return;
+ if(const_only && !var.declaration->constant)
+ return;
if(variable_values)
{
ProgramCompiler::ConstantConditionEliminator::ConstantConditionEliminator():
- scope_level(0)
+ scope_level(0),
+ in_loop(false)
{ }
void ProgramCompiler::ConstantConditionEliminator::visit(Block &block)
void ProgramCompiler::ConstantConditionEliminator::visit(Conditional &cond)
{
- ExpressionEvaluator eval(variable_values);
+ ExpressionEvaluator eval(&variable_values, in_loop);
cond.condition->visit(eval);
if(eval.result_valid)
flatten_block(eval.result ? cond.body : cond.else_body);
void ProgramCompiler::ConstantConditionEliminator::visit(Iteration &iter)
{
+ // XXX Should this not visit init_statement first?
if(iter.condition)
{
- ExpressionEvaluator eval;
+ ExpressionEvaluator eval(0, in_loop);
iter.condition->visit(eval);
if(eval.result_valid && !eval.result)
{
}
}
+ SetFlag set_loop(in_loop);
TraversingVisitor::visit(iter);
}
typedef std::map<ProgramSyntax::VariableDeclaration *, ProgramSyntax::Expression *> ValueMap;
const ValueMap *variable_values;
+ bool const_only;
float result;
bool result_valid;
ExpressionEvaluator();
- ExpressionEvaluator(const ValueMap &);
+ ExpressionEvaluator(const ValueMap *, bool);
using ProgramSyntax::NodeVisitor::visit;
virtual void visit(ProgramSyntax::Literal &);
struct ConstantConditionEliminator: BlockModifier
{
unsigned scope_level;
+ bool in_loop;
ExpressionEvaluator::ValueMap variable_values;
ConstantConditionEliminator();