Make ast::StructMember accept typ::Type

A minimal change to get a feel for what updating AST types to accept
typ::Type (for now) looks like.

Bug: tint:724
Change-Id: I33b33eb6af90e3629f76716a421f952f5a4bc11d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48841
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Antonio Maiorano 2021-04-23 08:35:13 +00:00 committed by Commit Bot service account
parent 05abdf5096
commit 0b9ea91fcf
4 changed files with 19 additions and 7 deletions

View File

@ -24,13 +24,13 @@ namespace ast {
StructMember::StructMember(ProgramID program_id, StructMember::StructMember(ProgramID program_id,
const Source& source, const Source& source,
const Symbol& sym, const Symbol& sym,
sem::Type* type, typ::Type type,
DecorationList decorations) DecorationList decorations)
: Base(program_id, source), : Base(program_id, source),
symbol_(sym), symbol_(sym),
type_(type), type_(type),
decorations_(std::move(decorations)) { decorations_(std::move(decorations)) {
TINT_ASSERT(type); TINT_ASSERT(type.sem);
TINT_ASSERT(symbol_.IsValid()); TINT_ASSERT(symbol_.IsValid());
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id);
for (auto* deco : decorations_) { for (auto* deco : decorations_) {
@ -59,7 +59,7 @@ StructMember* StructMember::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering // Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source()); auto src = ctx->Clone(source());
auto sym = ctx->Clone(symbol_); auto sym = ctx->Clone(symbol_);
auto* ty = ctx->Clone(type_); auto ty = ctx->Clone(type_);
auto decos = ctx->Clone(decorations_); auto decos = ctx->Clone(decorations_);
return ctx->dst->create<StructMember>(src, sym, ty, decos); return ctx->dst->create<StructMember>(src, sym, ty, decos);
} }

View File

@ -19,6 +19,7 @@
#include <vector> #include <vector>
#include "src/ast/decoration.h" #include "src/ast/decoration.h"
#include "src/typepair.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -35,7 +36,7 @@ class StructMember : public Castable<StructMember, Node> {
StructMember(ProgramID program_id, StructMember(ProgramID program_id,
const Source& source, const Source& source,
const Symbol& sym, const Symbol& sym,
sem::Type* type, typ::Type type,
DecorationList decorations); DecorationList decorations);
/// Move constructor /// Move constructor
StructMember(StructMember&&); StructMember(StructMember&&);
@ -44,8 +45,9 @@ class StructMember : public Castable<StructMember, Node> {
/// @returns the symbol /// @returns the symbol
const Symbol& symbol() const { return symbol_; } const Symbol& symbol() const { return symbol_; }
/// @returns the type /// @returns the type
sem::Type* type() const { return type_; } typ::Type type() const { return type_; }
/// @returns the decorations /// @returns the decorations
const DecorationList& decorations() const { return decorations_; } const DecorationList& decorations() const { return decorations_; }
@ -73,7 +75,7 @@ class StructMember : public Castable<StructMember, Node> {
StructMember(const StructMember&) = delete; StructMember(const StructMember&) = delete;
Symbol const symbol_; Symbol const symbol_;
sem::Type* const type_; typ::Type const type_;
DecorationList const decorations_; DecorationList const decorations_;
}; };

View File

@ -25,6 +25,7 @@
#include "src/debug.h" #include "src/debug.h"
#include "src/symbol.h" #include "src/symbol.h"
#include "src/traits.h" #include "src/traits.h"
#include "src/typepair.h"
namespace tint { namespace tint {
@ -179,6 +180,15 @@ class CloneContext {
return CheckedCast<T>(c); return CheckedCast<T>(c);
} }
/// Clones the type pair
/// @param tp the type pair to clone
/// @return the cloned type pair
template <typename AST, typename SEM>
typ::TypePair<AST, SEM> Clone(const typ::TypePair<AST, SEM>& tp) {
return {Clone(const_cast<ast::Type*>(tp.ast)),
Clone(const_cast<sem::Type*>(tp.sem))};
}
/// Clones the Source `s` into #dst /// Clones the Source `s` into #dst
/// TODO(bclayton) - Currently this 'clone' is a shallow copy. If/when /// 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 /// `Source.File`s are owned by the Program this should make a copy of the

View File

@ -190,7 +190,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_FALSE(str->IsBlockDecorated()); EXPECT_FALSE(str->IsBlockDecorated());
const auto* ty = str->impl()->members()[0]->type(); const auto ty = str->impl()->members()[0]->type();
ASSERT_TRUE(ty->Is<sem::ArrayType>()); ASSERT_TRUE(ty->Is<sem::ArrayType>());
const auto* arr = ty->As<sem::ArrayType>(); const auto* arr = ty->As<sem::ArrayType>();