Allow removing the initialization statement of a for loop
authorMikko Rasa <tdb@tdb.fi>
Sat, 25 May 2019 21:53:05 +0000 (00:53 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 May 2019 21:53:05 +0000 (00:53 +0300)
Previously the compiler would recognize it as unused but couldn't remove
it, leading it to repeat the optimizer endlessly.

source/programcompiler.cpp
source/programcompiler.h

index 88ec6e59d88054480457be91cd0da9e14f201f02..2bf57c6ad8fe4788ad9417b0f73123eb2351a0b2 100644 (file)
@@ -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 &)
 {
index 461fac9a2e649b1fb3f2597da5ebed6759b218ff..1258bde00ce0cbc8b9f45326377e9fe7524d7af7 100644 (file)
@@ -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