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>
This commit is contained in:
parent
f23696ddda
commit
3bfb6817df
|
@ -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,
|
||||
|
|
|
@ -79,6 +79,10 @@ class Struct : public Castable<Struct, Node> {
|
|||
/// @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)]]`
|
||||
|
|
Loading…
Reference in New Issue