From: Mikko Rasa Date: Sat, 25 May 2019 21:53:05 +0000 (+0300) Subject: Allow removing the initialization statement of a for loop X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=670cd5e97ba225b5eb43fdda4ad53bf2731a35fa;p=libs%2Fgl.git Allow removing the initialization statement of a for loop Previously the compiler would recognize it as unused but couldn't remove it, leading it to repeat the optimizer endlessly. --- diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 88ec6e59..2bf57c6a 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -1658,6 +1658,12 @@ void ProgramCompiler::NodeRemover::visit(VariableDeclaration &var) var.init_expression = 0; } +void ProgramCompiler::NodeRemover::visit(Iteration &iter) +{ + if(to_remove.count(iter.init_statement.get())) + iter.init_statement = 0; +} + void ProgramCompiler::PrecisionRemover::visit(Precision &) { diff --git a/source/programcompiler.h b/source/programcompiler.h index 461fac9a..1258bde0 100644 --- a/source/programcompiler.h +++ b/source/programcompiler.h @@ -324,6 +324,7 @@ private: using Visitor::visit; virtual void visit(ProgramSyntax::Block &); virtual void visit(ProgramSyntax::VariableDeclaration &); + virtual void visit(ProgramSyntax::Iteration &); }; struct PrecisionRemover: BlockModifier