From 03d9003072e85c934f5624329fb4a34db8763db2 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 4 Apr 2021 11:32:31 +0300 Subject: [PATCH] Store the index of the member in MemberAccess --- source/glsl/resolve.cpp | 12 +++++------- source/glsl/syntax.cpp | 6 ++++-- source/glsl/syntax.h | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/source/glsl/resolve.cpp b/source/glsl/resolve.cpp index 05aead3c..02f224d6 100644 --- a/source/glsl/resolve.cpp +++ b/source/glsl/resolve.cpp @@ -279,21 +279,18 @@ void VariableResolver::visit(MemberAccess &memacc) TraversingVisitor::visit(memacc); VariableDeclaration *declaration = 0; + int index = -1; if(StructDeclaration *strct = dynamic_cast(memacc.left->type)) { map::iterator i = strct->members.variables.find(memacc.member); if(i!=strct->members.variables.end()) { declaration = i->second; + for(NodeList::const_iterator j=strct->members.body.begin(); (j!=strct->members.body.end() && j->get()!=i->second); ++j) + ++index; if(record_target) - { - unsigned index = 0; - for(NodeList::const_iterator j=strct->members.body.begin(); (j!=strct->members.body.end() && j->get()!=i->second); ++j) - ++index; - add_to_chain(Assignment::Target::MEMBER, index); - } } } else if(BasicTypeDeclaration *basic = dynamic_cast(memacc.left->type)) @@ -324,8 +321,9 @@ void VariableResolver::visit(MemberAccess &memacc) } } - r_any_resolved |= (declaration!=memacc.declaration); + r_any_resolved |= (declaration!=memacc.declaration || index!=memacc.index); memacc.declaration = declaration; + memacc.index = index; } void VariableResolver::visit(Swizzle &swizzle) diff --git a/source/glsl/syntax.cpp b/source/glsl/syntax.cpp index d0273909..c54a8297 100644 --- a/source/glsl/syntax.cpp +++ b/source/glsl/syntax.cpp @@ -138,14 +138,16 @@ void InterfaceBlockReference::visit(NodeVisitor &visitor) MemberAccess::MemberAccess(): - declaration(0) + declaration(0), + index(-1) { } MemberAccess::MemberAccess(const MemberAccess &other): Expression(other), left(other.left), member(other.member), - declaration(0) + declaration(0), + index(-1) { } void MemberAccess::visit(NodeVisitor &visitor) diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index b4d1b386..66fed6e8 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -187,6 +187,7 @@ struct MemberAccess: Expression std::string member; VariableDeclaration *declaration; + int index; MemberAccess(); MemberAccess(const MemberAccess &); -- 2.45.2