From 4e3c03e2b60f9d6a9b8ed69b7150eb91e2db2e34 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 5 Apr 2021 15:43:02 +0300 Subject: [PATCH] Make DumpTree able to dump arbitrary nodes Remove that ability from Formatter since it makes assumptions about the state of the nodes, like certain references existing. --- source/glsl/debug.cpp | 7 ++++--- source/glsl/debug.h | 1 + source/glsl/output.h | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/glsl/debug.cpp b/source/glsl/debug.cpp index 2f243dc7..c02d9147 100644 --- a/source/glsl/debug.cpp +++ b/source/glsl/debug.cpp @@ -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::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; } diff --git a/source/glsl/debug.h b/source/glsl/debug.h index da888198..c3e9c701 100644 --- a/source/glsl/debug.h +++ b/source/glsl/debug.h @@ -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 &); diff --git a/source/glsl/output.h b/source/glsl/output.h index 1e59a445..09cdf071 100644 --- a/source/glsl/output.h +++ b/source/glsl/output.h @@ -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 &); -- 2.43.0