From 670cd5e97ba225b5eb43fdda4ad53bf2731a35fa Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 26 May 2019 00:53:05 +0300 Subject: [PATCH] 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. --- source/programcompiler.cpp | 6 ++++++ source/programcompiler.h | 1 + 2 files changed, 7 insertions(+) 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 -- 2.45.2