]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/generate.cpp
Refactor the interface of SL::Compiler
[libs/gl.git] / source / glsl / generate.cpp
index 55687924ffc1703bfb05fb0dd560f4aff255d885..f3c57a2f0f9190352860bc5f7bc22ff634433123 100644 (file)
@@ -78,13 +78,12 @@ VariableResolver::VariableResolver():
        self_referencing(false)
 { }
 
-void VariableResolver::apply(Stage &s)
+void VariableResolver::apply(Stage &stage)
 {
-       SetForScope<Stage *> set(stage, &s);
-       Stage *builtins = get_builtins(stage->type);
+       Stage *builtins = get_builtins(stage.type);
        if(builtins)
                blocks.push_back(&builtins->content);
-       stage->content.visit(*this);
+       visit(stage.content);
        if(builtins)
                blocks.pop_back();
 }
@@ -240,14 +239,15 @@ void FunctionResolver::visit(FunctionDeclaration &func)
 
 
 InterfaceGenerator::InterfaceGenerator():
+       stage(0),
        scope_level(0)
 { }
 
-string InterfaceGenerator::get_out_prefix(StageType type)
+string InterfaceGenerator::get_out_prefix(Stage::Type type)
 {
-       if(type==VERTEX)
+       if(type==Stage::VERTEX)
                return "_vs_out_";
-       else if(type==GEOMETRY)
+       else if(type==Stage::GEOMETRY)
                return "_gs_out_";
        else
                return string();
@@ -259,7 +259,7 @@ void InterfaceGenerator::apply(Stage &s)
        if(stage->previous)
                in_prefix = get_out_prefix(stage->previous->type);
        out_prefix = get_out_prefix(stage->type);
-       stage->content.visit(*this);
+       visit(s.content);
 }
 
 void InterfaceGenerator::visit(Block &block)
@@ -301,7 +301,7 @@ bool InterfaceGenerator::generate_interface(VariableDeclaration &var, const stri
        iface_var->type = var.type;
        iface_var->type_declaration = var.type_declaration;
        iface_var->name = name;
-       if(stage->type==GEOMETRY)
+       if(stage->type==Stage::GEOMETRY)
                iface_var->array = ((var.array && var.interface!="in") || iface=="in");
        else
                iface_var->array = var.array;
@@ -411,7 +411,7 @@ void InterfaceGenerator::visit(Passthrough &pass)
                }
        }
 
-       if(stage->type==GEOMETRY)
+       if(stage->type==Stage::GEOMETRY)
        {
                VariableReference *ref = new VariableReference;
                ref->name = "gl_in";
@@ -471,7 +471,7 @@ void DeclarationReorderer::visit(Block &block)
 {
        SetForScope<unsigned> set(scope_level, scope_level+1);
        if(scope_level>1)
-               return StageVisitor::visit(block);
+               return TraversingVisitor::visit(block);
 
        NodeList<Statement>::iterator struct_insert_point = block.body.end();
        NodeList<Statement>::iterator variable_insert_point = block.body.end();
@@ -547,7 +547,7 @@ void DeclarationReorderer::visit(Block &block)
 
 void DeclarationReorderer::visit(VariableDeclaration &var)
 {
-       StageVisitor::visit(var);
+       TraversingVisitor::visit(var);
        kind = VARIABLE;
 }