From 3bfb6817df30a37deb252de364183766c57cf341 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 7 Apr 2021 08:35:31 +0000 Subject: [PATCH] semantic::Struct: Add FindMember Change-Id: Ie7b76ad8b7dbac1303ed73ba6962e584fed76238 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46628 Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: James Price --- src/semantic/sem_struct.cc | 10 ++++++++++ src/semantic/struct.h | 4 ++++ 2 files changed, 14 insertions(+) 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)]]`