]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.cpp
Make function dependency collection its own visitor class
[libs/gl.git] / source / glsl / optimize.cpp
index 43f94e8d4da10422be8a8047c238d9c61b9b6a9a..d7558ebde6c095b240943d4b317840425b46282a 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/raii.h>
 #include <msp/strings/format.h>
 #include "optimize.h"
+#include "reflect.h"
 
 using namespace std;
 
@@ -119,17 +120,13 @@ void InlineableFunctionLocator::visit(Return &ret)
 
 InlineContentInjector::InlineContentInjector():
        source_func(0),
-       pass(DEPENDS)
+       pass(REFERENCED)
 { }
 
 const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &target_func, Block &tgt_blk, const NodeList<Statement>::iterator &ins_pt, FunctionCall &call)
 {
        source_func = call.declaration->definition;
 
-       // Collect all declarations the inlined function depends on.
-       pass = DEPENDS;
-       source_func->visit(*this);
-
        /* Populate referenced_names from the target function so we can rename
        variables from the inlined function that would conflict. */
        pass = REFERENCED;
@@ -187,7 +184,7 @@ const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &ta
 
        tgt_blk.body.splice(ins_pt, staging_block.body);
 
-       NodeReorderer().apply(stage, target_func, dependencies);
+       NodeReorderer().apply(stage, target_func, DependencyCollector().apply(*source_func));
 
        return r_result_name;
 }
@@ -200,31 +197,19 @@ void InlineContentInjector::visit(VariableReference &var)
                if(i!=staging_block.variables.end())
                        var.name = i->second->name;
        }
-       else if(pass==DEPENDS && var.declaration)
-       {
-               dependencies.insert(var.declaration);
-               var.declaration->visit(*this);
-       }
        else if(pass==REFERENCED)
                referenced_names.insert(var.name);
 }
 
 void InlineContentInjector::visit(InterfaceBlockReference &iface)
 {
-       if(pass==DEPENDS && iface.declaration)
-       {
-               dependencies.insert(iface.declaration);
-               iface.declaration->visit(*this);
-       }
-       else if(pass==REFERENCED)
+       if(pass==REFERENCED)
                referenced_names.insert(iface.name);
 }
 
 void InlineContentInjector::visit(FunctionCall &call)
 {
-       if(pass==DEPENDS && call.declaration)
-               dependencies.insert(call.declaration);
-       else if(pass==REFERENCED)
+       if(pass==REFERENCED)
                referenced_names.insert(call.name);
        TraversingVisitor::visit(call);
 }
@@ -249,11 +234,6 @@ void InlineContentInjector::visit(VariableDeclaration &var)
                        }
                }
        }
-       else if(pass==DEPENDS && var.type_declaration)
-       {
-               dependencies.insert(var.type_declaration);
-               var.type_declaration->visit(*this);
-       }
        else if(pass==REFERENCED)
                referenced_names.insert(var.type);
 }