From: Mikko Rasa Date: Fri, 26 Feb 2021 18:26:27 +0000 (+0200) Subject: Mostly cosmetic tweaks X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=7f29c6d2a4eee36538d7ccf24980e749592e2444 Mostly cosmetic tweaks --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 1ebb87c5..3f63dd8a 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -14,7 +14,7 @@ InlineableFunctionLocator::InlineableFunctionLocator(): void InlineableFunctionLocator::visit(FunctionCall &call) { FunctionDeclaration *def = call.declaration; - if(def && def->definition!=def) + if(def) def = def->definition; if(def) @@ -95,7 +95,7 @@ void FunctionInliner::visit(FunctionCall &call) visit_and_inline(*i); FunctionDeclaration *def = call.declaration; - if(def && def->definition!=def) + if(def) def = def->definition; if(def && inlineable.count(def)) @@ -259,7 +259,7 @@ void UnusedVariableRemover::visit(VariableReference &var) if(var.declaration && !assignment_target) { VariableInfo &var_info = variables.back()[var.declaration]; - var_info.assignments.clear(); + clear_assignments(var_info, false); var_info.referenced = true; } } @@ -441,7 +441,7 @@ void UnusedVariableRemover::visit(Iteration &iter) BlockVariableMap &block_variables = variables.back(); for(BlockVariableMap::iterator i=block_variables.begin(); i!=block_variables.end(); ++i) if(!i->second.local && i->second.referenced) - i->second.assignments.clear(); + clear_assignments(i->second, false); merge_down_variables(); } diff --git a/source/glsl/syntax.cpp b/source/glsl/syntax.cpp index bda0dd1d..7f2efdce 100644 --- a/source/glsl/syntax.cpp +++ b/source/glsl/syntax.cpp @@ -181,15 +181,15 @@ void Assignment::visit(NodeVisitor &visitor) FunctionCall::FunctionCall(): - declaration(0), - constructor(false) + constructor(false), + declaration(0) { } FunctionCall::FunctionCall(const FunctionCall &other): name(other.name), - declaration(0), constructor(other.constructor), - arguments(other.arguments) + arguments(other.arguments), + declaration(0) { } void FunctionCall::visit(NodeVisitor &visitor) @@ -241,25 +241,25 @@ void StructDeclaration::visit(NodeVisitor &visitor) VariableDeclaration::VariableDeclaration(): constant(false), - type_declaration(0), array(false), + type_declaration(0), linked_declaration(0) { } VariableDeclaration::VariableDeclaration(const VariableDeclaration &other): + layout(other.layout), constant(other.constant), sampling(other.sampling), interpolation(other.interpolation), interface(other.interface), precision(other.precision), type(other.type), - type_declaration(0), name(other.name), array(other.array), array_size(other.array_size), init_expression(other.init_expression), - linked_declaration(0), - layout(other.layout) + type_declaration(0), + linked_declaration(0) { } VariableDeclaration::~VariableDeclaration() @@ -310,8 +310,8 @@ FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other): return_type(other.return_type), name(other.name), parameters(other.parameters), - definition(other.definition==&other ? this : 0), - body(other.body) + body(other.body), + definition(other.definition==&other ? this : 0) { } void FunctionDeclaration::visit(NodeVisitor &visitor) diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index 49699f2e..55f47402 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -108,6 +108,7 @@ struct Block: Node { NodeList body; bool use_braces; + std::map variables; Block *parent; @@ -142,6 +143,7 @@ struct ParenthesizedExpression: Expression struct VariableReference: Expression { std::string name; + VariableDeclaration *declaration; VariableReference(); @@ -154,6 +156,7 @@ struct VariableReference: Expression struct InterfaceBlockReference: Expression { std::string name; + InterfaceBlock *declaration; InterfaceBlockReference(); @@ -167,6 +170,7 @@ struct MemberAccess: Expression { NodePtr left; std::string member; + VariableDeclaration *declaration; MemberAccess(); @@ -202,6 +206,7 @@ struct BinaryExpression: Expression struct Assignment: BinaryExpression { bool self_referencing; + VariableDeclaration *target_declaration; Assignment(); @@ -214,10 +219,11 @@ struct Assignment: BinaryExpression struct FunctionCall: Expression { std::string name; - FunctionDeclaration *declaration; bool constructor; NodeArray arguments; + FunctionDeclaration *declaration; + FunctionCall(); FunctionCall(const FunctionCall &); @@ -287,19 +293,20 @@ struct StructDeclaration: Statement struct VariableDeclaration: Statement { + NodePtr layout; bool constant; std::string sampling; std::string interpolation; std::string interface; std::string precision; std::string type; - StructDeclaration *type_declaration; std::string name; bool array; NodePtr array_size; NodePtr init_expression; + + StructDeclaration *type_declaration; VariableDeclaration *linked_declaration; - NodePtr layout; VariableDeclaration(); VariableDeclaration(const VariableDeclaration &); @@ -316,6 +323,7 @@ struct InterfaceBlock: Statement Block members; std::string instance_name; bool array; + InterfaceBlock *linked_block; InterfaceBlock(); @@ -331,9 +339,10 @@ struct FunctionDeclaration: Statement std::string return_type; std::string name; NodeArray parameters; - FunctionDeclaration *definition; Block body; + FunctionDeclaration *definition; + FunctionDeclaration(); FunctionDeclaration(const FunctionDeclaration &);