]> git.tdb.fi Git - libs/gl.git/commitdiff
Store functions definitions in Stage
authorMikko Rasa <tdb@tdb.fi>
Sun, 28 Feb 2021 11:19:25 +0000 (13:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 28 Feb 2021 19:41:54 +0000 (21:41 +0200)
source/glsl/debug.cpp
source/glsl/generate.cpp
source/glsl/generate.h
source/glsl/syntax.h
source/glsl/visitor.cpp
source/glsl/visitor.h

index c29a60ceab724c6b19069538d38aa3ad144b7d29..b913f5b493a2b2ad550d5f83903abe74ab68affb 100644 (file)
@@ -27,6 +27,9 @@ const std::string &DumpTree::apply(Stage &stage)
                        append(text);
                }
 
+       for(std::map<string, FunctionDeclaration *>::const_iterator i=stage.functions.begin(); i!=stage.functions.end(); ++i)
+               append(format("Function: %%%d %s", get_label(*i->second), i->first));
+
        last_branch();
        stage.content.visit(*this);
        return formatted;
index 13b62aa32296a3d6c93c851827387205c08bfed1..ff863824055ae76ef51cc9fdd08521b2b3548aa2 100644 (file)
@@ -309,28 +309,42 @@ void VariableResolver::visit(InterfaceBlock &iface)
 }
 
 
+void FunctionResolver::apply(Stage &s)
+{
+       stage = &s;
+       s.content.visit(*this);
+}
+
 void FunctionResolver::visit(FunctionCall &call)
 {
-       map<string, vector<FunctionDeclaration *> >::iterator i = functions.find(call.name);
-       if(i!=functions.end())
-               call.declaration = i->second.back();
+       map<string, FunctionDeclaration *>::iterator i = stage->functions.find(call.name);
+       if(i!=stage->functions.end())
+               call.declaration = i->second;
 
        TraversingVisitor::visit(call);
 }
 
 void FunctionResolver::visit(FunctionDeclaration &func)
 {
-       vector<FunctionDeclaration *> &decls = functions[func.name];
+       FunctionDeclaration *&stage_decl = stage->functions[func.name];
+       vector<FunctionDeclaration *> &decls = declarations[func.name];
        if(func.definition==&func)
        {
+               stage_decl = &func;
+
                for(vector<FunctionDeclaration *>::iterator i=decls.begin(); i!=decls.end(); ++i)
                {
                        (*i)->definition = func.definition;
                        (*i)->body.body.clear();
                }
        }
-       else if(!decls.empty() && decls.back()->definition)
-               func.definition = decls.back()->definition;
+       else
+       {
+               if(!stage_decl)
+                       stage_decl = &func;
+
+               func.definition = stage_decl->definition;
+       }
        decls.push_back(&func);
 
        TraversingVisitor::visit(func);
index dc90b6eb5d36dc9b363ff0acbd01ba364c3f6a00..4359a09fdc59d7d772d19be09f02714dfba0e225 100644 (file)
@@ -93,7 +93,7 @@ class FunctionResolver: private TraversingVisitor
 {
 private:
        Stage *stage;
-       std::map<std::string, std::vector<FunctionDeclaration *> > functions;
+       std::map<std::string, std::vector<FunctionDeclaration *> > declarations;
 
 public:
        void apply(Stage &);
index 55f47402f514538b959a459a07b3532e2a0d5efd..70ea50d106f774c2c8be8974cb3140fbf0421d39 100644 (file)
@@ -410,6 +410,7 @@ struct Stage
        Block content;
        std::map<std::string, StructDeclaration *> types;
        std::map<std::string, InterfaceBlock *> interface_blocks;
+       std::map<std::string, FunctionDeclaration *> functions;
        std::map<std::string, unsigned> locations;
        Features required_features;
 
index fd25bf342a7ea588525be88079166453474c4e8e..d8b1813959f17e4535ea1ea8c60001c22a36d76f 100644 (file)
@@ -186,6 +186,13 @@ void NodeRemover::visit(InterfaceBlock &iface)
        TraversingVisitor::visit(iface);
 }
 
+void NodeRemover::visit(FunctionDeclaration &func)
+{
+       if(to_remove->count(&func))
+               remove_from_map(stage->functions, func.name+func.signature, func);
+       TraversingVisitor::visit(func);
+}
+
 void NodeRemover::visit(Iteration &iter)
 {
        if(to_remove->count(iter.init_statement.get()))
index 4e48a1a11f112205ec10feedf2017d6c7099ddd1..83b310f62ebadbcef621a9b8d1aa65eb571e59c1 100644 (file)
@@ -106,6 +106,7 @@ private:
        virtual void visit(StructDeclaration &);
        virtual void visit(VariableDeclaration &);
        virtual void visit(InterfaceBlock &);
+       virtual void visit(FunctionDeclaration &);
        virtual void visit(Iteration &);
 };