]> git.tdb.fi Git - libs/gl.git/commitdiff
Rename members of visitors to indicate which are "return values"
authorMikko Rasa <tdb@tdb.fi>
Wed, 3 Mar 2021 12:59:19 +0000 (14:59 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 3 Mar 2021 16:50:12 +0000 (18:50 +0200)
source/glsl/compatibility.cpp
source/glsl/compatibility.h
source/glsl/evaluate.cpp
source/glsl/evaluate.h
source/glsl/generate.cpp
source/glsl/generate.h
source/glsl/optimize.cpp
source/glsl/optimize.h

index 128902f3b9f473bb9df87559d40a231c139ac55e..9ed0d20c82c8b2a0ecc109c9db4adb55fff5040b 100644 (file)
@@ -150,12 +150,12 @@ void LegacyConverter::visit(VariableReference &var)
        {
                var.name = "gl_FragColor";
                var.declaration = 0;
-               type = "vec4";
+               r_type = "vec4";
        }
        else if(var.declaration)
-               type = var.declaration->type;
+               r_type = var.declaration->type;
        else
-               type = string();
+               r_type.clear();
 }
 
 void LegacyConverter::visit(Assignment &assign)
@@ -178,12 +178,12 @@ void LegacyConverter::visit(FunctionCall &call)
        if(call.name=="texture")
        {
                string sampler_type;
-               type = string();
+               r_type.clear();
                NodeArray<Expression>::iterator i = call.arguments.begin();
                if(i!=call.arguments.end())
                {
                        (*i)->visit(*this);
-                       sampler_type = type;
+                       sampler_type = r_type;
 
                        for(; i!=call.arguments.end(); ++i)
                                (*i)->visit(*this);
index ad6c7cbe9c875f3a63c7cdb69c682f2f7f7a0aa3..c30dce8c2f3c7728188a6dcc1e7c671c08a405d5 100644 (file)
@@ -50,7 +50,7 @@ class LegacyConverter: private TraversingVisitor
 private:
        Stage *stage;
        Features features;
-       std::string type;
+       std::string r_type;
        VariableDeclaration *frag_out;
        NodeList<Statement>::iterator uniform_insert_point;
        std::set<Node *> nodes_to_remove;
index 915b2a6fe2cce1a6f8dcc4cd275029f1225ba6a2..f290002b61a14c0fefb15b92398a821c7ec7f529 100644 (file)
@@ -7,25 +7,25 @@ namespace SL {
 
 ExpressionEvaluator::ExpressionEvaluator():
        variable_values(0),
-       result(0.0f),
-       result_valid(false)
+       r_result(0.0f),
+       r_result_valid(false)
 { }
 
 ExpressionEvaluator::ExpressionEvaluator(const ValueMap &v):
        variable_values(&v),
-       result(0.0f),
-       result_valid(false)
+       r_result(0.0f),
+       r_result_valid(false)
 { }
 
 void ExpressionEvaluator::visit(Literal &literal)
 {
        if(literal.token=="true")
-               result = 1.0f;
+               r_result = 1.0f;
        else if(literal.token=="false")
-               result = 0.0f;
+               r_result = 0.0f;
        else
-               result = lexical_cast<float>(literal.token);
-       result_valid = true;
+               r_result = lexical_cast<float>(literal.token);
+       r_result_valid = true;
 }
 
 void ExpressionEvaluator::visit(ParenthesizedExpression &parexp)
@@ -50,49 +50,49 @@ void ExpressionEvaluator::visit(VariableReference &var)
 
 void ExpressionEvaluator::visit(UnaryExpression &unary)
 {
-       result_valid = false;
+       r_result_valid = false;
        unary.expression->visit(*this);
-       if(!result_valid)
+       if(!r_result_valid)
                return;
 
        if(unary.oper->token[0]=='!')
-               result = !result;
+               r_result = !r_result;
        else
-               result_valid = false;
+               r_result_valid = false;
 }
 
 void ExpressionEvaluator::visit(BinaryExpression &binary)
 {
-       result_valid = false;
+       r_result_valid = false;
        binary.left->visit(*this);
-       if(!result_valid)
+       if(!r_result_valid)
                return;
 
-       float left_result = result;
-       result_valid = false;
+       float left_result = r_result;
+       r_result_valid = false;
        binary.right->visit(*this);
-       if(!result_valid)
+       if(!r_result_valid)
                return;
 
        std::string oper = binary.oper->token;
        if(oper=="<")
-               result = (left_result<result);
+               r_result = (left_result<r_result);
        else if(oper=="<=")
-               result = (left_result<=result);
+               r_result = (left_result<=r_result);
        else if(oper==">")
-               result = (left_result>result);
+               r_result = (left_result>r_result);
        else if(oper==">=")
-               result = (left_result>=result);
+               r_result = (left_result>=r_result);
        else if(oper=="==")
-               result = (left_result==result);
+               r_result = (left_result==r_result);
        else if(oper=="!=")
-               result = (left_result!=result);
+               r_result = (left_result!=r_result);
        else if(oper=="&&")
-               result = (left_result && result);
+               r_result = (left_result && r_result);
        else if(oper=="||")
-               result = (left_result || result);
+               r_result = (left_result || r_result);
        else
-               result_valid = false;
+               r_result_valid = false;
 }
 
 } // namespace SL
index 2c80a6cba24fd90881e85062400a052f63335a7a..f3d3755ff62b602ead868278aa3ad8c0e17141a1 100644 (file)
@@ -16,15 +16,15 @@ public:
 
 private:
        const ValueMap *variable_values;
-       float result;
-       bool result_valid;
+       float r_result;
+       bool r_result_valid;
 
 public:
        ExpressionEvaluator();
        ExpressionEvaluator(const ValueMap &);
 
-       float get_result() const { return result; }
-       bool is_result_valid() const { return result_valid; }
+       float get_result() const { return r_result; }
+       bool is_result_valid() const { return r_result_valid; }
 
        using NodeVisitor::visit;
        virtual void visit(Literal &);
index 6b336f3179de690b2967cd85fe5da0cafff130ab..38eda220cee20533db6936e1b79d0831c01aefff 100644 (file)
@@ -116,10 +116,10 @@ void BlockHierarchyResolver::enter(Block &block)
 
 VariableResolver::VariableResolver():
        stage(0),
-       members(0),
+       r_members(0),
        record_target(false),
-       assignment_target(0),
-       self_referencing(false)
+       r_assignment_target(0),
+       r_self_referencing(false)
 { }
 
 void VariableResolver::apply(Stage &s)
@@ -138,7 +138,7 @@ void VariableResolver::enter(Block &block)
 void VariableResolver::visit(VariableReference &var)
 {
        var.declaration = 0;
-       members = 0;
+       r_members = 0;
        for(Block *block=current_block; (!var.declaration && block); block=block->parent)
        {
                map<string, VariableDeclaration *>::iterator i = block->variables.find(var.name);
@@ -149,7 +149,7 @@ void VariableResolver::visit(VariableReference &var)
        if(var.declaration)
        {
                if(var.declaration->type_declaration)
-                       members = &var.declaration->type_declaration->members.variables;
+                       r_members = &var.declaration->type_declaration->members.variables;
        }
        else
        {
@@ -157,10 +157,10 @@ void VariableResolver::visit(VariableReference &var)
                map<string, InterfaceBlock *>::const_iterator i = blocks.find(var.name);
                if(i!=blocks.end() && i->second->instance_name==var.name)
                {
-                       iface_ref = new InterfaceBlockReference;
-                       iface_ref->name = var.name;
-                       iface_ref->declaration = i->second;
-                       members = &i->second->members.variables;
+                       r_iface_ref = new InterfaceBlockReference;
+                       r_iface_ref->name = var.name;
+                       r_iface_ref->declaration = i->second;
+                       r_members = &i->second->members.variables;
                }
                else
                {
@@ -176,16 +176,16 @@ void VariableResolver::visit(VariableReference &var)
 
        if(record_target)
        {
-               if(assignment_target)
+               if(r_assignment_target)
                {
                        record_target = false;
-                       assignment_target = 0;
+                       r_assignment_target = 0;
                }
                else
-                       assignment_target = var.declaration;
+                       r_assignment_target = var.declaration;
        }
-       else if(var.declaration && var.declaration==assignment_target)
-               self_referencing = true;
+       else if(var.declaration && var.declaration==r_assignment_target)
+               r_self_referencing = true;
 }
 
 void VariableResolver::visit(InterfaceBlockReference &iface)
@@ -197,7 +197,7 @@ void VariableResolver::visit(InterfaceBlockReference &iface)
                if(i!=stage->interface_blocks.end())
                {
                        iface.declaration = i->second;
-                       members = &i->second->members.variables;
+                       r_members = &i->second->members.variables;
                        break;
                }
        }
@@ -205,26 +205,26 @@ void VariableResolver::visit(InterfaceBlockReference &iface)
 
 void VariableResolver::visit(MemberAccess &memacc)
 {
-       members = 0;
-       iface_ref = 0;
+       r_members = 0;
+       r_iface_ref = 0;
        memacc.left->visit(*this);
 
-       if(iface_ref)
-               memacc.left = iface_ref;
-       iface_ref = 0;
+       if(r_iface_ref)
+               memacc.left = r_iface_ref;
+       r_iface_ref = 0;
 
        memacc.declaration = 0;
-       if(members)
+       if(r_members)
        {
-               map<string, VariableDeclaration *>::iterator i = members->find(memacc.member);
-               if(i!=members->end())
+               map<string, VariableDeclaration *>::iterator i = r_members->find(memacc.member);
+               if(i!=r_members->end())
                {
                        memacc.declaration = i->second;
                        if(i->second->type_declaration)
-                               members = &i->second->type_declaration->members.variables;
+                               r_members = &i->second->type_declaration->members.variables;
                }
                else
-                       members = 0;
+                       r_members = 0;
        }
 }
 
@@ -236,17 +236,17 @@ void VariableResolver::visit(BinaryExpression &binary)
                        SetForScope<bool> set(record_target, false);
                        binary.right->visit(*this);
                }
-               members = 0;
-               iface_ref = 0;
+               r_members = 0;
+               r_iface_ref = 0;
                binary.left->visit(*this);
-               if(iface_ref)
-                       binary.left = iface_ref;
-               iface_ref = 0;
+               if(r_iface_ref)
+                       binary.left = r_iface_ref;
+               r_iface_ref = 0;
        }
        else
        {
                TraversingVisitor::visit(binary);
-               members = 0;
+               r_members = 0;
        }
 }
 
@@ -254,15 +254,15 @@ void VariableResolver::visit(Assignment &assign)
 {
        {
                SetFlag set(record_target);
-               assignment_target = 0;
+               r_assignment_target = 0;
                assign.left->visit(*this);
        }
 
-       self_referencing = false;
+       r_self_referencing = false;
        assign.right->visit(*this);
 
-       assign.self_referencing = (self_referencing || assign.oper->token[0]!='=');
-       assign.target_declaration = assignment_target;
+       assign.self_referencing = (r_self_referencing || assign.oper->token[0]!='=');
+       assign.target_declaration = r_assignment_target;
 }
 
 void VariableResolver::visit(StructDeclaration &strct)
index 48fc742342bdf042aa32bdbd5686e61e1e43bbe0..bcb70c04c6da49c0df7dc294d37d38139bbd8fda 100644 (file)
@@ -61,12 +61,12 @@ class VariableResolver: private TraversingVisitor
 {
 private:
        Stage *stage;
-       std::map<std::string, VariableDeclaration *> *members;
-       RefPtr<InterfaceBlockReference> iface_ref;
+       std::map<std::string, VariableDeclaration *> *r_members;
+       RefPtr<InterfaceBlockReference> r_iface_ref;
        std::string block_interface;
        bool record_target;
-       VariableDeclaration *assignment_target;
-       bool self_referencing;
+       VariableDeclaration *r_assignment_target;
+       bool r_self_referencing;
 
 public:
        VariableResolver();
index b7236feb6fafb4f7e0495b3b6e8260329f91b29b..8a9992a2dba88a054dfeed5f5f681ba012946147 100644 (file)
@@ -74,19 +74,19 @@ const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &ta
        source_func = &src;
        for(NodeList<Statement>::iterator i=src.body.body.begin(); i!=src.body.body.end(); ++i)
        {
-               inlined_statement = 0;
+               r_inlined_statement = 0;
                (*i)->visit(*this);
-               if(!inlined_statement)
-                       inlined_statement = (*i)->clone();
+               if(!r_inlined_statement)
+                       r_inlined_statement = (*i)->clone();
 
                SetFlag set_remap(remap_names);
-               inlined_statement->visit(*this);
-               tgtb.body.insert(ins_pt, inlined_statement);
+               r_inlined_statement->visit(*this);
+               tgtb.body.insert(ins_pt, r_inlined_statement);
        }
 
        NodeReorderer().apply(stage, target_func, dependencies);
 
-       return result_name;
+       return r_result_name;
 }
 
 string InlineContentInjector::create_unused_name(const string &base, bool always_prefix)
@@ -151,7 +151,7 @@ void InlineContentInjector::visit(VariableDeclaration &var)
        {
                RefPtr<VariableDeclaration> inlined_var = var.clone();
                inlined_var->name = create_unused_name(var.name, false);
-               inlined_statement = inlined_var;
+               r_inlined_statement = inlined_var;
 
                variable_map[var.name] = inlined_var.get();
        }
@@ -163,40 +163,40 @@ void InlineContentInjector::visit(Return &ret)
 
        if(ret.expression)
        {
-               result_name = create_unused_name("return", true);
+               r_result_name = create_unused_name("return", true);
                RefPtr<VariableDeclaration> var = new VariableDeclaration;
                var->source = ret.source;
                var->line = ret.line;
                var->type = source_func->return_type;
-               var->name = result_name;
+               var->name = r_result_name;
                var->init_expression = ret.expression->clone();
-               inlined_statement = var;
+               r_inlined_statement = var;
        }
 }
 
 
 FunctionInliner::FunctionInliner():
        current_function(0),
-       any_inlined(false)
+       r_any_inlined(false)
 { }
 
 bool FunctionInliner::apply(Stage &s)
 {
        stage = &s;
        inlineable = InlineableFunctionLocator().apply(s);
-       any_inlined = false;
+       r_any_inlined = false;
        s.content.visit(*this);
-       return any_inlined;
+       return r_any_inlined;
 }
 
 void FunctionInliner::visit_and_inline(RefPtr<Expression> &ptr)
 {
-       inline_result = 0;
+       r_inline_result = 0;
        ptr->visit(*this);
-       if(inline_result)
+       if(r_inline_result)
        {
-               ptr = inline_result;
-               any_inlined = true;
+               ptr = r_inline_result;
+               r_any_inlined = true;
        }
 }
 
@@ -214,20 +214,20 @@ void FunctionInliner::visit(Block &block)
 void FunctionInliner::visit(UnaryExpression &unary)
 {
        visit_and_inline(unary.expression);
-       inline_result = 0;
+       r_inline_result = 0;
 }
 
 void FunctionInliner::visit(BinaryExpression &binary)
 {
        visit_and_inline(binary.left);
        visit_and_inline(binary.right);
-       inline_result = 0;
+       r_inline_result = 0;
 }
 
 void FunctionInliner::visit(MemberAccess &memacc)
 {
        visit_and_inline(memacc.left);
-       inline_result = 0;
+       r_inline_result = 0;
 }
 
 void FunctionInliner::visit(FunctionCall &call)
@@ -249,14 +249,14 @@ void FunctionInliner::visit(FunctionCall &call)
 
                RefPtr<VariableReference> ref = new VariableReference;
                ref->name = result_name;
-               inline_result = ref;
+               r_inline_result = ref;
 
                /* Inlined variables need to be resolved before this function can be
                inlined further. */
                inlineable.erase(current_function);
        }
        else
-               inline_result = 0;
+               r_inline_result = 0;
 }
 
 void FunctionInliner::visit(ExpressionStatement &expr)
@@ -268,7 +268,7 @@ void FunctionInliner::visit(VariableDeclaration &var)
 {
        if(var.init_expression)
                visit_and_inline(var.init_expression);
-       inline_result = 0;
+       r_inline_result = 0;
 }
 
 void FunctionInliner::visit(FunctionDeclaration &func)
@@ -406,10 +406,10 @@ UnusedVariableRemover::VariableInfo::VariableInfo():
 
 UnusedVariableRemover::UnusedVariableRemover():
        aggregate(0),
-       assignment(0),
+       r_assignment(0),
        assignment_target(false),
-       assign_to_subscript(false),
-       side_effects(false)
+       r_assign_to_subscript(false),
+       r_side_effects(false)
 { }
 
 bool UnusedVariableRemover::apply(Stage &stage)
@@ -463,7 +463,7 @@ void UnusedVariableRemover::visit(UnaryExpression &unary)
 {
        TraversingVisitor::visit(unary);
        if(unary.oper->token[1]=='+' || unary.oper->token[1]=='-')
-               side_effects = true;
+               r_side_effects = true;
 }
 
 void UnusedVariableRemover::visit(BinaryExpression &binary)
@@ -471,7 +471,7 @@ void UnusedVariableRemover::visit(BinaryExpression &binary)
        if(binary.oper->token[0]=='[')
        {
                if(assignment_target)
-                       assign_to_subscript = true;
+                       r_assign_to_subscript = true;
                binary.left->visit(*this);
                SetForScope<bool> set(assignment_target, false);
                binary.right->visit(*this);
@@ -483,19 +483,19 @@ void UnusedVariableRemover::visit(BinaryExpression &binary)
 void UnusedVariableRemover::visit(Assignment &assign)
 {
        {
-               assign_to_subscript = false;
+               r_assign_to_subscript = false;
                SetForScope<bool> set(assignment_target, !assign.self_referencing);
                assign.left->visit(*this);
        }
        assign.right->visit(*this);
-       assignment = &assign;
-       side_effects = true;
+       r_assignment = &assign;
+       r_side_effects = true;
 }
 
 void UnusedVariableRemover::visit(FunctionCall &call)
 {
        TraversingVisitor::visit(call);
-       side_effects = true;
+       r_side_effects = true;
 }
 
 void UnusedVariableRemover::record_assignment(VariableDeclaration &var, Node &node, bool chained)
@@ -519,12 +519,12 @@ void UnusedVariableRemover::clear_assignments(VariableInfo &var_info, bool mark_
 
 void UnusedVariableRemover::visit(ExpressionStatement &expr)
 {
-       assignment = 0;
-       side_effects = false;
+       r_assignment = 0;
+       r_side_effects = false;
        TraversingVisitor::visit(expr);
-       if(assignment && assignment->target_declaration)
-               record_assignment(*assignment->target_declaration, expr, (assignment->self_referencing || assign_to_subscript));
-       if(!side_effects)
+       if(r_assignment && r_assignment->target_declaration)
+               record_assignment(*r_assignment->target_declaration, expr, (r_assignment->self_referencing || r_assign_to_subscript));
+       if(!r_side_effects)
                unused_nodes.insert(&expr);
 }
 
index e74e6e0e812b3a3cdaf2f1b5286960fdc87487b2..373e0199dd316cad4e3390f3e66cd1473aa7f8db 100644 (file)
@@ -45,9 +45,9 @@ private:
        std::map<std::string, VariableDeclaration *> variable_map;
        bool remap_names;
        bool deps_only;
-       RefPtr<Statement> inlined_statement;
+       RefPtr<Statement> r_inlined_statement;
        std::set<Node *> dependencies;
-       std::string result_name;
+       std::string r_result_name;
 
 public:
        InlineContentInjector();
@@ -74,8 +74,8 @@ private:
        std::set<FunctionDeclaration *> inlineable;
        FunctionDeclaration *current_function;
        NodeList<Statement>::iterator insert_point;
-       RefPtr<Expression> inline_result;
-       bool any_inlined;
+       RefPtr<Expression> r_inline_result;
+       bool r_any_inlined;
 
 public:
        FunctionInliner();
@@ -143,10 +143,10 @@ private:
        std::map<VariableDeclaration *, Node *> aggregates;
        Node *aggregate;
        std::vector<BlockVariableMap> variables;
-       Assignment *assignment;
+       Assignment *r_assignment;
        bool assignment_target;
-       bool assign_to_subscript;
-       bool side_effects;
+       bool r_assign_to_subscript;
+       bool r_side_effects;
 
 public:
        UnusedVariableRemover();