From: Mikko Rasa Date: Mon, 15 Feb 2021 16:04:53 +0000 (+0200) Subject: Adjust member access of the various visitors in the GLSL compiler X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0ca367ce305ae6f2025739b3b199a7f75d4132db;p=libs%2Fgl.git Adjust member access of the various visitors in the GLSL compiler Most of them don't work properly if given some random node to start with. --- diff --git a/source/glsl/compatibility.cpp b/source/glsl/compatibility.cpp index 398a7bd3..1ada7b7c 100644 --- a/source/glsl/compatibility.cpp +++ b/source/glsl/compatibility.cpp @@ -91,6 +91,12 @@ LegacyConverter::LegacyConverter(const Version &v): frag_out(0) { } +void LegacyConverter::apply(Stage &s) +{ + SetForScope set_stage(stage, &s); + visit(s.content); +} + bool LegacyConverter::check_version(const Version &feature_version) const { if(target_version set_stage(stage, &s); - visit(s.content); -} - bool LegacyConverter::supports_unified_interface_syntax() const { if(target_api==OPENGL_ES2) diff --git a/source/glsl/compatibility.h b/source/glsl/compatibility.h index 732f3477..fdbd3d07 100644 --- a/source/glsl/compatibility.h +++ b/source/glsl/compatibility.h @@ -8,7 +8,7 @@ namespace Msp { namespace GL { namespace SL { -class DefaultPrecisionGenerator: public BlockModifier +class DefaultPrecisionGenerator: private BlockModifier { private: Stage::Type stage_type; @@ -20,23 +20,25 @@ public: void apply(Stage &); - using BlockModifier::visit; +private: virtual void visit(Block &); virtual void visit(Precision &); virtual void visit(VariableDeclaration &); + using BlockModifier::visit; }; -class PrecisionRemover: public BlockModifier +class PrecisionRemover: private BlockModifier { public: void apply(Stage &s) { visit(s.content); } - using BlockModifier::visit; +private: virtual void visit(Precision &); virtual void visit(VariableDeclaration &); + using BlockModifier::visit; }; -class LegacyConverter: public BlockModifier +class LegacyConverter: private BlockModifier { private: Stage *stage; @@ -49,13 +51,11 @@ public: LegacyConverter(); LegacyConverter(const Version &); + virtual void apply(Stage &); + private: bool check_version(const Version &) const; bool check_extension(const Extension &) const; -public: - using BlockModifier::visit; - virtual void apply(Stage &); -private: bool supports_unified_interface_syntax() const; virtual void visit(VariableReference &); virtual void visit(Assignment &); @@ -67,6 +67,7 @@ private: virtual void visit(VariableDeclaration &); bool supports_interface_blocks(const std::string &) const; virtual void visit(InterfaceBlock &); + using BlockModifier::visit; }; } // namespace SL diff --git a/source/glsl/generate.h b/source/glsl/generate.h index 90cf2722..0c2a0ad8 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -11,7 +11,7 @@ namespace Msp { namespace GL { namespace SL { -class DeclarationCombiner: public BlockModifier +class DeclarationCombiner: private BlockModifier { private: bool toplevel; @@ -23,13 +23,14 @@ public: void apply(Stage &s) { visit(s.content); } - using BlockModifier::visit; +private: virtual void visit(Block &); virtual void visit(FunctionDeclaration &); virtual void visit(VariableDeclaration &); + using BlockModifier::visit; }; -class VariableResolver: public TraversingVisitor +class VariableResolver: private TraversingVisitor { private: std::vector blocks; @@ -45,7 +46,7 @@ public: void apply(Stage &); - using TraversingVisitor::visit; +private: virtual void visit(Block &); virtual void visit(VariableReference &); virtual void visit(MemberAccess &); @@ -54,9 +55,10 @@ public: virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); + using TraversingVisitor::visit; }; -class FunctionResolver: public TraversingVisitor +class FunctionResolver: private TraversingVisitor { private: std::map > functions; @@ -64,12 +66,13 @@ private: public: void apply(Stage &s) { visit(s.content); } - using TraversingVisitor::visit; +private: virtual void visit(FunctionCall &); virtual void visit(FunctionDeclaration &); + using TraversingVisitor::visit; }; -class InterfaceGenerator: public BlockModifier +class InterfaceGenerator: private BlockModifier { private: Stage *stage; @@ -83,18 +86,19 @@ public: void apply(Stage &); +private: static std::string get_out_prefix(Stage::Type); - using BlockModifier::visit; - virtual void visit(Block &); std::string change_prefix(const std::string &, const std::string &) const; + virtual void visit(Block &); bool generate_interface(VariableDeclaration &, const std::string &, const std::string &); ExpressionStatement &insert_assignment(const std::string &, Expression *); virtual void visit(VariableReference &); virtual void visit(VariableDeclaration &); virtual void visit(Passthrough &); + using BlockModifier::visit; }; -class DeclarationReorderer: public TraversingVisitor +class DeclarationReorderer: private TraversingVisitor { private: enum DeclarationKind @@ -116,7 +120,7 @@ public: void apply(Stage &s) { visit(s.content); } - using TraversingVisitor::visit; +private: virtual void visit(Block &); virtual void visit(FunctionCall &); virtual void visit(InterfaceLayout &) { kind = LAYOUT; } @@ -124,6 +128,7 @@ public: virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &) { kind = VARIABLE; } virtual void visit(FunctionDeclaration &); + using TraversingVisitor::visit; }; } // namespace SL diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 2e28d48a..cfebf0f7 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -10,7 +10,7 @@ namespace Msp { namespace GL { namespace SL { -class InlineableFunctionLocator: public TraversingVisitor +class InlineableFunctionLocator: private TraversingVisitor { private: std::map refcounts; @@ -22,12 +22,13 @@ public: const std::set &apply(Stage &s) { visit(s.content); return inlineable; } - using TraversingVisitor::visit; +private: virtual void visit(FunctionCall &); virtual void visit(FunctionDeclaration &); + using TraversingVisitor::visit; }; -class FunctionInliner: public TraversingVisitor +class FunctionInliner: private TraversingVisitor { private: std::set inlineable; @@ -42,8 +43,7 @@ public: private: void visit_and_inline(RefPtr &); -public: - using TraversingVisitor::visit; + virtual void visit(Block &); virtual void visit(UnaryExpression &); virtual void visit(BinaryExpression &); @@ -51,9 +51,10 @@ public: virtual void visit(FunctionCall &); virtual void visit(VariableDeclaration &); virtual void visit(Return &); + using TraversingVisitor::visit; }; -class ConstantConditionEliminator: public BlockModifier +class ConstantConditionEliminator: private BlockModifier { private: unsigned scope_level; @@ -65,16 +66,17 @@ public: void apply(Stage &s) { visit(s.content); } - using BlockModifier::visit; +private: virtual void visit(Block &); virtual void visit(UnaryExpression &); virtual void visit(Assignment &); virtual void visit(VariableDeclaration &); virtual void visit(Conditional &); virtual void visit(Iteration &); + using BlockModifier::visit; }; -class UnusedVariableLocator: public TraversingVisitor +class UnusedVariableLocator: private TraversingVisitor { private: struct VariableInfo @@ -103,28 +105,25 @@ public: const std::set &apply(Stage &); - using TraversingVisitor::visit; +private: virtual void visit(VariableReference &); virtual void visit(MemberAccess &); virtual void visit(BinaryExpression &); virtual void visit(Assignment &); -private: void record_assignment(VariableDeclaration &, Node &, bool); void clear_assignments(VariableInfo &, bool); -public: virtual void visit(ExpressionStatement &); virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &); -private: void merge_down_variables(); -public: virtual void visit(Conditional &); virtual void visit(Iteration &); + using TraversingVisitor::visit; }; -class UnusedFunctionLocator: public TraversingVisitor +class UnusedFunctionLocator: private TraversingVisitor { private: std::set unused_nodes; @@ -133,9 +132,10 @@ private: public: const std::set &apply(Stage &s) { visit(s.content); return unused_nodes; } - using TraversingVisitor::visit; +private: virtual void visit(FunctionCall &); virtual void visit(FunctionDeclaration &); + using TraversingVisitor::visit; }; } // namespace SL diff --git a/source/glsl/output.h b/source/glsl/output.h index 06bb5fd1..5b034202 100644 --- a/source/glsl/output.h +++ b/source/glsl/output.h @@ -8,7 +8,7 @@ namespace Msp { namespace GL { namespace SL { -class Formatter: public TraversingVisitor +class Formatter: private TraversingVisitor { private: Stage *stage; @@ -28,8 +28,7 @@ private: void append(const std::string &); void append(char); void set_source(unsigned, unsigned); -public: - using TraversingVisitor::visit; + virtual void visit(Block &); virtual void visit(Literal &); virtual void visit(ParenthesizedExpression &); @@ -52,6 +51,7 @@ public: virtual void visit(Iteration &); virtual void visit(Return &); virtual void visit(Jump &); + using TraversingVisitor::visit; }; } // namespace SL