]> git.tdb.fi Git - libs/gl.git/commitdiff
Make DumpTree able to dump arbitrary nodes
authorMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 12:43:02 +0000 (15:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 12:44:13 +0000 (15:44 +0300)
Remove that ability from Formatter since it makes assumptions about the
state of the nodes, like certain references existing.

source/glsl/debug.cpp
source/glsl/debug.h
source/glsl/output.h

index 2f243dc73dc0d25518ce341597749f4255f45d8a..c02d914720a35707d2e40d167d31f0538f7ec901 100644 (file)
@@ -11,7 +11,7 @@ namespace SL {
 std::string DumpTree::apply(Stage &stage)
 {
        formatted = format("Stage: %s\n", Stage::get_stage_name(stage.type));
-       tree.push_back(BRANCH);
+       begin_sub();
        append(format("Version: %d.%02d", stage.required_features.glsl_version.major, stage.required_features.glsl_version.minor));
 
        for(std::map<string, TypeDeclaration *>::const_iterator i=stage.types.begin(); i!=stage.types.end(); ++i)
@@ -78,7 +78,8 @@ void DumpTree::append_subtree(Node &node)
 
 void DumpTree::begin_sub()
 {
-       tree.back() = (tree.back()==BRANCH_LAST ? EMPTY : STRAIGHT);
+       if(!tree.empty())
+               tree.back() = (tree.back()==BRANCH_LAST ? EMPTY : STRAIGHT);
        tree.push_back(BRANCH);
 }
 
@@ -90,7 +91,7 @@ void DumpTree::last_branch()
 void DumpTree::end_sub()
 {
        tree.pop_back();
-       if(tree.back()==STRAIGHT)
+       if(!tree.empty() && tree.back()==STRAIGHT)
                tree.back() = BRANCH;
 }
 
index da888198414f8a7d891a7884a5ddbedd45d7b4cd..c3e9c701075b87974a7e5101ad635bf0bf8e5d8b 100644 (file)
@@ -38,6 +38,7 @@ private:
 
 public:
        std::string apply(Stage &);
+       std::string apply(Node &n) { n.visit(*this); return formatted; }
 
 private:
        void append(const std::string &);
index 1e59a445ebdd1f16eead08246ac98196b3a286ca..09cdf0714fb735103ba1cbedac9e2e53239d97fe 100644 (file)
@@ -26,7 +26,6 @@ public:
        Formatter();
 
        std::string apply(Stage &);
-       std::string apply(Node &n) { n.visit(*this); return formatted; }
 
 private:
        void append(const std::string &);