From 05597fbb3671dfed4776bc5223958c85e780345e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 20 Feb 2021 20:10:30 +0200 Subject: [PATCH] Tweaks to visitor classes in the GLSL compiler --- source/glsl/compatibility.cpp | 4 ++-- source/glsl/generate.cpp | 2 +- source/glsl/optimize.cpp | 6 +++--- source/glsl/output.cpp | 2 +- source/glsl/visitor.cpp | 2 +- source/glsl/visitor.h | 6 ++++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/source/glsl/compatibility.cpp b/source/glsl/compatibility.cpp index f12a46e3..692db972 100644 --- a/source/glsl/compatibility.cpp +++ b/source/glsl/compatibility.cpp @@ -20,7 +20,7 @@ DefaultPrecisionGenerator::DefaultPrecisionGenerator(): void DefaultPrecisionGenerator::apply(Stage &stage) { - SetForScope set_stage(stage_type, stage.type); + stage_type = stage.type; visit(stage.content); } @@ -87,7 +87,7 @@ LegacyConverter::LegacyConverter(): void LegacyConverter::apply(Stage &s) { - SetForScope set_stage(stage, &s); + stage = &s; visit(s.content); } diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index f3c57a2f..379a6871 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -255,7 +255,7 @@ string InterfaceGenerator::get_out_prefix(Stage::Type type) void InterfaceGenerator::apply(Stage &s) { - SetForScope set(stage, &s); + stage = &s; if(stage->previous) in_prefix = get_out_prefix(stage->previous->type); out_prefix = get_out_prefix(stage->type); diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 5813e2d9..dfb17b26 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -213,14 +213,14 @@ UnusedVariableLocator::UnusedVariableLocator(): global_scope(true) { } -const set &UnusedVariableLocator::apply(Stage &s) +const set &UnusedVariableRemover::apply(Stage &stage) { variables.push_back(BlockVariableMap()); - visit(s.content); + visit(stage.content); BlockVariableMap &global_variables = variables.back(); for(BlockVariableMap::iterator i=global_variables.begin(); i!=global_variables.end(); ++i) { - if(i->first->interface=="out" && (s.type==Stage::FRAGMENT || i->first->linked_declaration || !i->first->name.compare(0, 3, "gl_"))) + if(i->first->interface=="out" && (stage.type==Stage::FRAGMENT || i->first->linked_declaration || !i->first->name.compare(0, 3, "gl_"))) continue; if(!i->second.referenced) { diff --git a/source/glsl/output.cpp b/source/glsl/output.cpp index 6e88fd1f..973ff832 100644 --- a/source/glsl/output.cpp +++ b/source/glsl/output.cpp @@ -18,7 +18,7 @@ Formatter::Formatter(): const string &Formatter::apply(Stage &s) { - SetForScope set_stage(stage, &s); + stage = &s; GLApi api = get_gl_api(); const Version &ver = s.required_version; diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index 717acad1..91e75b70 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -153,7 +153,7 @@ NodeRemover::NodeRemover(const set &r): void NodeRemover::apply(Stage &s) { - SetForScope set_stage(stage, &s); + stage = &s; visit(s.content); } diff --git a/source/glsl/visitor.h b/source/glsl/visitor.h index e1c45b5c..756584c2 100644 --- a/source/glsl/visitor.h +++ b/source/glsl/visitor.h @@ -83,7 +83,7 @@ public: }; template -class NodeGatherer: public TraversingVisitor +class NodeGatherer: private TraversingVisitor { private: std::vector nodes; @@ -91,11 +91,12 @@ private: public: const std::vector &apply(Stage &s) { visit(s.content); return nodes; } +private: using TraversingVisitor::visit; virtual void visit(T &n) { nodes.push_back(&n); } }; -class NodeRemover: public TraversingVisitor +class NodeRemover: private TraversingVisitor { private: Stage *stage; @@ -106,6 +107,7 @@ public: void apply(Stage &); +private: using TraversingVisitor::visit; virtual void visit(Block &); virtual void visit(VariableDeclaration &); -- 2.45.2