semantic::Struct: Add FindMember
Change-Id: Ie7b76ad8b7dbac1303ed73ba6962e584fed76238
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46628
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/semantic/sem_struct.cc b/src/semantic/sem_struct.cc
index 78c272a..d715863 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() = 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 3cd1696..4400f64 100644
--- a/src/semantic/struct.h
+++ b/src/semantic/struct.h
@@ -79,6 +79,10 @@
/// @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)]]`