diff --git a/src/semantic/sem_struct.cc b/src/semantic/sem_struct.cc index 78c272a093..d715863734 100644 --- a/src/semantic/sem_struct.cc +++ b/src/semantic/sem_struct.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/ast/struct_member.h" #include "src/semantic/struct.h" TINT_INSTANTIATE_TYPEINFO(tint::semantic::Struct); @@ -37,6 +38,15 @@ Struct::Struct(type::Struct* type, Struct::~Struct() = default; +const StructMember* Struct::FindMember(Symbol name) const { + for (auto* member : members_) { + if (member->Declaration()->symbol() == name) { + return member; + } + } + return nullptr; +} + StructMember::StructMember(ast::StructMember* declaration, uint32_t offset, uint32_t align, diff --git a/src/semantic/struct.h b/src/semantic/struct.h index 3cd16964a3..4400f64626 100644 --- a/src/semantic/struct.h +++ b/src/semantic/struct.h @@ -79,6 +79,10 @@ class Struct : public Castable { /// @returns the members of the structure const StructMemberList& Members() const { return members_; } + /// @param name the member name to look for + /// @returns the member with the given name, or nullptr if it was not found. + const StructMember* FindMember(Symbol name) const; + /// @returns the byte alignment of the structure /// @note this may differ from the alignment of a structure member of this /// structure type, if the member is annotated with the `[[align(n)]]`