From: Mikko Rasa Date: Wed, 3 Mar 2021 12:59:19 +0000 (+0200) Subject: Rename members of visitors to indicate which are "return values" X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8173340a7737e32cb25b21b67049102bd1526beb;p=libs%2Fgl.git Rename members of visitors to indicate which are "return values" --- diff --git a/source/glsl/compatibility.cpp b/source/glsl/compatibility.cpp index 128902f3..9ed0d20c 100644 --- a/source/glsl/compatibility.cpp +++ b/source/glsl/compatibility.cpp @@ -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::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); diff --git a/source/glsl/compatibility.h b/source/glsl/compatibility.h index ad6c7cbe..c30dce8c 100644 --- a/source/glsl/compatibility.h +++ b/source/glsl/compatibility.h @@ -50,7 +50,7 @@ class LegacyConverter: private TraversingVisitor private: Stage *stage; Features features; - std::string type; + std::string r_type; VariableDeclaration *frag_out; NodeList::iterator uniform_insert_point; std::set nodes_to_remove; diff --git a/source/glsl/evaluate.cpp b/source/glsl/evaluate.cpp index 915b2a6f..f290002b 100644 --- a/source/glsl/evaluate.cpp +++ b/source/glsl/evaluate.cpp @@ -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(literal.token); - result_valid = true; + r_result = lexical_cast(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 = (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 diff --git a/source/glsl/evaluate.h b/source/glsl/evaluate.h index 2c80a6cb..f3d3755f 100644 --- a/source/glsl/evaluate.h +++ b/source/glsl/evaluate.h @@ -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 &); diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 6b336f31..38eda220 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -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::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::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::iterator i = members->find(memacc.member); - if(i!=members->end()) + map::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 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) diff --git a/source/glsl/generate.h b/source/glsl/generate.h index 48fc7423..bcb70c04 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -61,12 +61,12 @@ class VariableResolver: private TraversingVisitor { private: Stage *stage; - std::map *members; - RefPtr iface_ref; + std::map *r_members; + RefPtr 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(); diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index b7236feb..8a9992a2 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -74,19 +74,19 @@ const string &InlineContentInjector::apply(Stage &stage, FunctionDeclaration &ta source_func = &src; for(NodeList::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 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 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 &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 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 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 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); } diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index e74e6e0e..373e0199 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -45,9 +45,9 @@ private: std::map variable_map; bool remap_names; bool deps_only; - RefPtr inlined_statement; + RefPtr r_inlined_statement; std::set dependencies; - std::string result_name; + std::string r_result_name; public: InlineContentInjector(); @@ -74,8 +74,8 @@ private: std::set inlineable; FunctionDeclaration *current_function; NodeList::iterator insert_point; - RefPtr inline_result; - bool any_inlined; + RefPtr r_inline_result; + bool r_any_inlined; public: FunctionInliner(); @@ -143,10 +143,10 @@ private: std::map aggregates; Node *aggregate; std::vector 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();