diff --git a/src/ast/struct_member.cc b/src/ast/struct_member.cc index d9b895cc1b..7fc2fa250b 100644 --- a/src/ast/struct_member.cc +++ b/src/ast/struct_member.cc @@ -24,13 +24,13 @@ namespace ast { StructMember::StructMember(ProgramID program_id, const Source& source, const Symbol& sym, - sem::Type* type, + typ::Type type, DecorationList decorations) : Base(program_id, source), symbol_(sym), type_(type), decorations_(std::move(decorations)) { - TINT_ASSERT(type); + TINT_ASSERT(type.sem); TINT_ASSERT(symbol_.IsValid()); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id); for (auto* deco : decorations_) { @@ -59,7 +59,7 @@ StructMember* StructMember::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source()); auto sym = ctx->Clone(symbol_); - auto* ty = ctx->Clone(type_); + auto ty = ctx->Clone(type_); auto decos = ctx->Clone(decorations_); return ctx->dst->create(src, sym, ty, decos); } diff --git a/src/ast/struct_member.h b/src/ast/struct_member.h index 246aa2fc69..cd8408d0f4 100644 --- a/src/ast/struct_member.h +++ b/src/ast/struct_member.h @@ -19,6 +19,7 @@ #include #include "src/ast/decoration.h" +#include "src/typepair.h" namespace tint { namespace ast { @@ -35,7 +36,7 @@ class StructMember : public Castable { StructMember(ProgramID program_id, const Source& source, const Symbol& sym, - sem::Type* type, + typ::Type type, DecorationList decorations); /// Move constructor StructMember(StructMember&&); @@ -44,8 +45,9 @@ class StructMember : public Castable { /// @returns the symbol const Symbol& symbol() const { return symbol_; } + /// @returns the type - sem::Type* type() const { return type_; } + typ::Type type() const { return type_; } /// @returns the decorations const DecorationList& decorations() const { return decorations_; } @@ -73,7 +75,7 @@ class StructMember : public Castable { StructMember(const StructMember&) = delete; Symbol const symbol_; - sem::Type* const type_; + typ::Type const type_; DecorationList const decorations_; }; diff --git a/src/clone_context.h b/src/clone_context.h index ec562f38f2..080c27b25b 100644 --- a/src/clone_context.h +++ b/src/clone_context.h @@ -25,6 +25,7 @@ #include "src/debug.h" #include "src/symbol.h" #include "src/traits.h" +#include "src/typepair.h" namespace tint { @@ -179,6 +180,15 @@ class CloneContext { return CheckedCast(c); } + /// Clones the type pair + /// @param tp the type pair to clone + /// @return the cloned type pair + template + typ::TypePair Clone(const typ::TypePair& tp) { + return {Clone(const_cast(tp.ast)), + Clone(const_cast(tp.sem))}; + } + /// Clones the Source `s` into #dst /// TODO(bclayton) - Currently this 'clone' is a shallow copy. If/when /// `Source.File`s are owned by the Program this should make a copy of the diff --git a/src/reader/wgsl/parser_impl_global_decl_test.cc b/src/reader/wgsl/parser_impl_global_decl_test.cc index 551605e372..79fddcbb96 100644 --- a/src/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_decl_test.cc @@ -190,7 +190,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) { EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_FALSE(str->IsBlockDecorated()); - const auto* ty = str->impl()->members()[0]->type(); + const auto ty = str->impl()->members()[0]->type(); ASSERT_TRUE(ty->Is()); const auto* arr = ty->As();