]> git.tdb.fi Git - libs/gl.git/commitdiff
Store the index of the member in MemberAccess
authorMikko Rasa <tdb@tdb.fi>
Sun, 4 Apr 2021 08:32:31 +0000 (11:32 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 4 Apr 2021 08:32:50 +0000 (11:32 +0300)
source/glsl/resolve.cpp
source/glsl/syntax.cpp
source/glsl/syntax.h

index 05aead3c5fa369f55529c02c05c34fe7a6997dba..02f224d66b4453d2469a2638e0ab0453d2cd6c4a 100644 (file)
@@ -279,21 +279,18 @@ void VariableResolver::visit(MemberAccess &memacc)
        TraversingVisitor::visit(memacc);
 
        VariableDeclaration *declaration = 0;
+       int index = -1;
        if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(memacc.left->type))
        {
                map<string, VariableDeclaration *>::iterator i = strct->members.variables.find(memacc.member);
                if(i!=strct->members.variables.end())
                {
                        declaration = i->second;
+                       for(NodeList<Statement>::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<Statement>::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<BasicTypeDeclaration *>(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)
index d0273909d68db900e0d95e79c08f1d2cf9f140cd..c54a82979081cc03e3a2c4bbb66e55cb9b2aa934 100644 (file)
@@ -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)
index b4d1b3869ae9395c90a5a424fa939ac17fada381..66fed6e83f058d83b476d777a45cb43947703c72 100644 (file)
@@ -187,6 +187,7 @@ struct MemberAccess: Expression
        std::string member;
 
        VariableDeclaration *declaration;
+       int index;
 
        MemberAccess();
        MemberAccess(const MemberAccess &);