Rename 'constructed types' to 'type declarartions'

Change-Id: I0c79be17a10a542df602447e555c1344621d2dce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53803
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-06-09 14:32:14 +00:00
parent 8758f10a20
commit 950809f534
36 changed files with 141 additions and 148 deletions

View File

@ -37,7 +37,7 @@ Module::Module(ProgramID program_id,
} }
if (auto* ty = decl->As<ast::TypeDecl>()) { if (auto* ty = decl->As<ast::TypeDecl>()) {
constructed_types_.push_back(ty); type_decls_.push_back(ty);
} else if (auto* func = decl->As<Function>()) { } else if (auto* func = decl->As<Function>()) {
functions_.push_back(func); functions_.push_back(func);
} else if (auto* var = decl->As<Variable>()) { } else if (auto* var = decl->As<Variable>()) {
@ -52,7 +52,7 @@ Module::Module(ProgramID program_id,
Module::~Module() = default; Module::~Module() = default;
const ast::TypeDecl* Module::LookupType(Symbol name) const { const ast::TypeDecl* Module::LookupType(Symbol name) const {
for (auto* ty : ConstructedTypes()) { for (auto* ty : TypeDecls()) {
if (ty->name() == name) { if (ty->name() == name) {
return ty; return ty;
} }
@ -67,9 +67,9 @@ void Module::AddGlobalVariable(ast::Variable* var) {
global_declarations_.push_back(var); global_declarations_.push_back(var);
} }
void Module::AddConstructedType(ast::TypeDecl* type) { void Module::AddTypeDecl(ast::TypeDecl* type) {
TINT_ASSERT(type); TINT_ASSERT(type);
constructed_types_.push_back(type); type_decls_.push_back(type);
global_declarations_.push_back(type); global_declarations_.push_back(type);
} }
@ -93,7 +93,7 @@ void Module::Copy(CloneContext* ctx, const Module* src) {
continue; continue;
} }
if (auto* ty = decl->As<ast::TypeDecl>()) { if (auto* ty = decl->As<ast::TypeDecl>()) {
AddConstructedType(ty); AddTypeDecl(ty);
} else if (auto* func = decl->As<Function>()) { } else if (auto* func = decl->As<Function>()) {
AddFunction(func); AddFunction(func);
} else if (auto* var = decl->As<Variable>()) { } else if (auto* var = decl->As<Variable>()) {
@ -110,7 +110,7 @@ void Module::to_str(const sem::Info& sem,
make_indent(out, indent); make_indent(out, indent);
out << "Module{" << std::endl; out << "Module{" << std::endl;
indent += 2; indent += 2;
for (auto* ty : constructed_types_) { for (auto* ty : type_decls_) {
make_indent(out, indent); make_indent(out, indent);
if (auto* alias = ty->As<ast::Alias>()) { if (auto* alias = ty->As<ast::Alias>()) {
out << alias->symbol().to_str() << " -> " << alias->type()->type_name() out << alias->symbol().to_str() << " -> " << alias->type()->type_name()

View File

@ -74,17 +74,15 @@ class Module : public Castable<Module, Node> {
VariableList& GlobalVariables() { return global_variables_; } VariableList& GlobalVariables() { return global_variables_; }
/// Adds a type declaration to the Builder. /// Adds a type declaration to the Builder.
/// @param decl the constructed type declaration to add /// @param decl the type declaration to add
void AddConstructedType(ast::TypeDecl* decl); void AddTypeDecl(ast::TypeDecl* decl);
/// @returns the TypeDecl registered as a ConstructedType() /// @returns the TypeDecl registered as a TypeDecl()
/// @param name the name of the type to search for /// @param name the name of the type to search for
const ast::TypeDecl* LookupType(Symbol name) const; const ast::TypeDecl* LookupType(Symbol name) const;
/// @returns the constructed types in the translation unit /// @returns the declared types in the translation unit
const std::vector<ast::TypeDecl*>& ConstructedTypes() const { const std::vector<ast::TypeDecl*>& TypeDecls() const { return type_decls_; }
return constructed_types_;
}
/// Add a function to the Builder /// Add a function to the Builder
/// @param func the function to add /// @param func the function to add
@ -118,7 +116,7 @@ class Module : public Castable<Module, Node> {
private: private:
std::vector<ast::Node*> global_declarations_; std::vector<ast::Node*> global_declarations_;
std::vector<ast::TypeDecl*> constructed_types_; std::vector<ast::TypeDecl*> type_decls_;
FunctionList functions_; FunctionList functions_;
VariableList global_variables_; VariableList global_variables_;
}; };

View File

@ -55,11 +55,11 @@ TEST_F(ModuleTest, Assert_Null_GlobalVariable) {
"internal compiler error"); "internal compiler error");
} }
TEST_F(ModuleTest, Assert_Null_ConstructedType) { TEST_F(ModuleTest, Assert_Null_TypeDecl) {
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
{ {
ProgramBuilder builder; ProgramBuilder builder;
builder.AST().AddConstructedType(nullptr); builder.AST().AddTypeDecl(nullptr);
}, },
"internal compiler error"); "internal compiler error");
} }

View File

@ -1598,7 +1598,7 @@ class ProgramBuilder {
return create<ast::ReturnStatement>(Expr(std::forward<EXPR>(val))); return create<ast::ReturnStatement>(Expr(std::forward<EXPR>(val)));
} }
/// Creates a ast::Alias registering it with the AST().ConstructedTypes(). /// Creates a ast::Alias registering it with the AST().TypeDecls().
/// @param source the source information /// @param source the source information
/// @param name the alias name /// @param name the alias name
/// @param type the alias target type /// @param type the alias target type
@ -1606,22 +1606,22 @@ class ProgramBuilder {
template <typename NAME> template <typename NAME>
ast::Alias* Alias(const Source& source, NAME&& name, ast::Type* type) { ast::Alias* Alias(const Source& source, NAME&& name, ast::Type* type) {
auto* out = ty.alias(source, std::forward<NAME>(name), type); auto* out = ty.alias(source, std::forward<NAME>(name), type);
AST().AddConstructedType(out); AST().AddTypeDecl(out);
return out; return out;
} }
/// Creates a ast::Alias registering it with the AST().ConstructedTypes(). /// Creates a ast::Alias registering it with the AST().TypeDecls().
/// @param name the alias name /// @param name the alias name
/// @param type the alias target type /// @param type the alias target type
/// @returns the alias type /// @returns the alias type
template <typename NAME> template <typename NAME>
ast::Alias* Alias(NAME&& name, ast::Type* type) { ast::Alias* Alias(NAME&& name, ast::Type* type) {
auto* out = ty.alias(std::forward<NAME>(name), type); auto* out = ty.alias(std::forward<NAME>(name), type);
AST().AddConstructedType(out); AST().AddTypeDecl(out);
return out; return out;
} }
/// Creates a ast::Struct registering it with the AST().ConstructedTypes(). /// Creates a ast::Struct registering it with the AST().TypeDecls().
/// @param source the source information /// @param source the source information
/// @param name the struct name /// @param name the struct name
/// @param members the struct members /// @param members the struct members
@ -1635,11 +1635,11 @@ class ProgramBuilder {
auto sym = Sym(std::forward<NAME>(name)); auto sym = Sym(std::forward<NAME>(name));
auto* type = create<ast::Struct>(source, sym, std::move(members), auto* type = create<ast::Struct>(source, sym, std::move(members),
std::move(decorations)); std::move(decorations));
AST().AddConstructedType(type); AST().AddTypeDecl(type);
return type; return type;
} }
/// Creates a ast::Struct registering it with the AST().ConstructedTypes(). /// Creates a ast::Struct registering it with the AST().TypeDecls().
/// @param name the struct name /// @param name the struct name
/// @param members the struct members /// @param members the struct members
/// @param decorations the optional struct decorations /// @param decorations the optional struct decorations
@ -1651,7 +1651,7 @@ class ProgramBuilder {
auto sym = Sym(std::forward<NAME>(name)); auto sym = Sym(std::forward<NAME>(name));
auto* type = auto* type =
create<ast::Struct>(sym, std::move(members), std::move(decorations)); create<ast::Struct>(sym, std::move(members), std::move(decorations));
AST().AddConstructedType(type); AST().AddTypeDecl(type);
return type; return type;
} }

View File

@ -68,11 +68,11 @@ TEST_F(ProgramTest, Assert_NullGlobalVariable) {
"internal compiler error"); "internal compiler error");
} }
TEST_F(ProgramTest, Assert_NullConstructedType) { TEST_F(ProgramTest, Assert_NullTypeDecl) {
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
{ {
ProgramBuilder b; ProgramBuilder b;
b.AST().AddConstructedType(nullptr); b.AST().AddTypeDecl(nullptr);
}, },
"internal compiler error"); "internal compiler error");
} }

View File

@ -1044,7 +1044,7 @@ bool FunctionEmitter::EmitEntryPointAsWrapper() {
// Create and register the result type. // Create and register the result type.
auto* str = create<ast::Struct>(Source{}, return_struct_sym, return_members, auto* str = create<ast::Struct>(Source{}, return_struct_sym, return_members,
ast::DecorationList{}); ast::DecorationList{});
parser_impl_.AddConstructedType(return_struct_sym, str); parser_impl_.AddTypeDecl(return_struct_sym, str);
return_type = builder_.ty.Of(str); return_type = builder_.ty.Of(str);
// Add the return-value statement. // Add the return-value statement.

View File

@ -1033,14 +1033,14 @@ const Type* ParserImpl::ConvertType(
if (num_non_writable_members == members.size()) { if (num_non_writable_members == members.size()) {
read_only_struct_types_.insert(ast_struct->name()); read_only_struct_types_.insert(ast_struct->name());
} }
AddConstructedType(sym, ast_struct); AddTypeDecl(sym, ast_struct);
return ty_.Struct(sym, std::move(ast_member_types)); return ty_.Struct(sym, std::move(ast_member_types));
} }
void ParserImpl::AddConstructedType(Symbol name, ast::TypeDecl* decl) { void ParserImpl::AddTypeDecl(Symbol name, ast::TypeDecl* decl) {
auto iter = constructed_types_.insert(name); auto iter = declared_types_.insert(name);
if (iter.second) { if (iter.second) {
builder_.AST().AddConstructedType(decl); builder_.AST().AddTypeDecl(decl);
} }
} }
@ -1220,7 +1220,7 @@ const Type* ParserImpl::MaybeGenerateAlias(
builder_.ty.alias(sym, ast_underlying_type->Build(builder_)); builder_.ty.alias(sym, ast_underlying_type->Build(builder_));
// Record this new alias as the AST type for this SPIR-V ID. // Record this new alias as the AST type for this SPIR-V ID.
AddConstructedType(sym, ast_alias_type); AddTypeDecl(sym, ast_alias_type);
return ty_.Alias(sym, ast_underlying_type); return ty_.Alias(sym, ast_underlying_type);
} }

View File

@ -190,10 +190,10 @@ class ParserImpl : Reader {
const spvtools::opt::analysis::Type* type, const spvtools::opt::analysis::Type* type,
const Type* ast_type); const Type* ast_type);
/// Adds `type` as a constructed type if it hasn't been added yet. /// Adds `decl` as a declared type if it hasn't been added yet.
/// @param name the type's unique name /// @param name the type's unique name
/// @param decl the type declaration to add /// @param decl the type declaration to add
void AddConstructedType(Symbol name, ast::TypeDecl* decl); void AddTypeDecl(Symbol name, ast::TypeDecl* decl);
/// @returns the fail stream object /// @returns the fail stream object
FailStream& fail_stream() { return fail_stream_; } FailStream& fail_stream() { return fail_stream_; }
@ -760,9 +760,9 @@ class ParserImpl : Reader {
std::unordered_map<const spvtools::opt::Instruction*, const Pointer*> std::unordered_map<const spvtools::opt::Instruction*, const Pointer*>
handle_type_; handle_type_;
// Set of symbols of constructed types that have been added, used to avoid // Set of symbols of declared type that have been added, used to avoid
// adding duplicates. // adding duplicates.
std::unordered_set<Symbol> constructed_types_; std::unordered_set<Symbol> declared_types_;
/// Maps the SPIR-V ID of a module-scope builtin variable that should be /// Maps the SPIR-V ID of a module-scope builtin variable that should be
/// ignored or type-converted, to its builtin kind. /// ignored or type-converted, to its builtin kind.

View File

@ -312,16 +312,16 @@ Token ParserImpl::last_token() const {
return last_token_; return last_token_;
} }
void ParserImpl::register_constructed(const std::string& name, void ParserImpl::register_type(const std::string& name,
const ast::TypeDecl* type_decl) { const ast::TypeDecl* type_decl) {
registered_constructs_[name] = type_decl; registered_types_[name] = type_decl;
} }
const ast::TypeDecl* ParserImpl::get_constructed(const std::string& name) { const ast::TypeDecl* ParserImpl::get_type(const std::string& name) {
if (registered_constructs_.find(name) == registered_constructs_.end()) { if (registered_types_.find(name) == registered_types_.end()) {
return nullptr; return nullptr;
} }
return registered_constructs_[name]; return registered_types_[name];
} }
bool ParserImpl::Parse() { bool ParserImpl::Parse() {
@ -397,7 +397,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("type alias", Token::Type::kSemicolon)) if (!expect("type alias", Token::Type::kSemicolon))
return Failure::kErrored; return Failure::kErrored;
builder_.AST().AddConstructedType(const_cast<ast::Alias*>(ta.value)); builder_.AST().AddTypeDecl(const_cast<ast::Alias*>(ta.value));
return true; return true;
} }
@ -409,9 +409,8 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("struct declaration", Token::Type::kSemicolon)) if (!expect("struct declaration", Token::Type::kSemicolon))
return Failure::kErrored; return Failure::kErrored;
register_constructed(builder_.Symbols().NameFor(str.value->name()), register_type(builder_.Symbols().NameFor(str.value->name()), str.value);
str.value); builder_.AST().AddTypeDecl(str.value);
builder_.AST().AddConstructedType(str.value);
return true; return true;
} }
@ -1032,7 +1031,7 @@ Maybe<ast::Alias*> ParserImpl::type_alias() {
auto* alias = builder_.ty.alias(make_source_range_from(t.source()), auto* alias = builder_.ty.alias(make_source_range_from(t.source()),
name.value, type.value); name.value, type.value);
register_constructed(name.value, alias); register_type(name.value, alias);
return alias; return alias;
} }
@ -1082,9 +1081,9 @@ Maybe<ast::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
Source source; Source source;
if (match(Token::Type::kIdentifier, &source)) { if (match(Token::Type::kIdentifier, &source)) {
// TODO(crbug.com/tint/697): Remove // TODO(crbug.com/tint/697): Remove
auto* ty = get_constructed(t.to_str()); auto* ty = get_type(t.to_str());
if (ty == nullptr) if (ty == nullptr)
return add_error(t, "unknown constructed type '" + t.to_str() + "'"); return add_error(t, "unknown type '" + t.to_str() + "'");
return builder_.create<ast::TypeName>( return builder_.create<ast::TypeName>(
source, builder_.Symbols().Register(t.to_str())); source, builder_.Symbols().Register(t.to_str()));
@ -2242,7 +2241,7 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
return create<ast::BitcastExpression>(source, type.value, params.value); return create<ast::BitcastExpression>(source, type.value, params.value);
} }
if (t.IsIdentifier() && !get_constructed(t.to_str())) { if (t.IsIdentifier() && !get_type(t.to_str())) {
next(); next();
auto* ident = create<ast::IdentifierExpression>( auto* ident = create<ast::IdentifierExpression>(

View File

@ -378,17 +378,16 @@ class ParserImpl {
/// @param source the source to associate the error with /// @param source the source to associate the error with
/// @param msg the warning message /// @param msg the warning message
void deprecated(const Source& source, const std::string& msg); void deprecated(const Source& source, const std::string& msg);
/// Registers a constructed type into the parser /// Registers a declared type into the parser
/// TODO(crbug.com/tint/724): Remove /// TODO(crbug.com/tint/724): Remove
/// @param name the constructed name /// @param name the type name
/// @param type_decl the constructed type declaration /// @param type_decl the type declaration
void register_constructed(const std::string& name, void register_type(const std::string& name, const ast::TypeDecl* type_decl);
const ast::TypeDecl* type_decl); /// Retrieves a declared type
/// Retrieves a constructed type
/// TODO(crbug.com/tint/724): Remove /// TODO(crbug.com/tint/724): Remove
/// @param name The name to lookup /// @param name The name to lookup
/// @returns the constructed type for `name` or `nullptr` if not found /// @returns the declared type for `name` or `nullptr` if not found
const ast::TypeDecl* get_constructed(const std::string& name); const ast::TypeDecl* get_type(const std::string& name);
/// Parses the `translation_unit` grammar element /// Parses the `translation_unit` grammar element
void translation_unit(); void translation_unit();
@ -882,7 +881,7 @@ class ParserImpl {
uint32_t sync_depth_ = 0; uint32_t sync_depth_ = 0;
std::vector<Token::Type> sync_tokens_; std::vector<Token::Type> sync_tokens_;
int silence_errors_ = 0; int silence_errors_ = 0;
std::unordered_map<std::string, const ast::TypeDecl*> registered_constructs_; std::unordered_map<std::string, const ast::TypeDecl*> registered_types_;
ProgramBuilder builder_; ProgramBuilder builder_;
size_t max_errors_ = 25; size_t max_errors_ = 25;
}; };

View File

@ -134,7 +134,7 @@ TEST_F(ParserImplTest, ConstExpr_ConstLiteral_Invalid) {
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_TRUE(e.errored); ASSERT_TRUE(e.errored);
ASSERT_EQ(e.value, nullptr); ASSERT_EQ(e.value, nullptr);
EXPECT_EQ(p->error(), "1:1: unknown constructed type 'invalid'"); EXPECT_EQ(p->error(), "1:1: unknown type 'invalid'");
} }
TEST_F(ParserImplTest, ConstExpr_Recursion) { TEST_F(ParserImplTest, ConstExpr_Recursion) {

View File

@ -420,7 +420,7 @@ TEST_F(ParserImplErrorTest, FunctionMissingOpenLine) {
var a : f32 = bar[0]; var a : f32 = bar[0];
return; return;
})", })",
"test.wgsl:2:17 error: unknown constructed type 'bar'\n" "test.wgsl:2:17 error: unknown type 'bar'\n"
" var a : f32 = bar[0];\n" " var a : f32 = bar[0];\n"
" ^^^\n" " ^^^\n"
"\n" "\n"
@ -733,7 +733,7 @@ TEST_F(ParserImplErrorTest, GlobalDeclTypeAliasMissingSemicolon) {
TEST_F(ParserImplErrorTest, GlobalDeclTypeInvalid) { TEST_F(ParserImplErrorTest, GlobalDeclTypeInvalid) {
EXPECT("var x : fish;", EXPECT("var x : fish;",
"test.wgsl:1:9 error: unknown constructed type 'fish'\n" "test.wgsl:1:9 error: unknown type 'fish'\n"
"var x : fish;\n" "var x : fish;\n"
" ^^^^\n"); " ^^^^\n");
} }

View File

@ -112,7 +112,7 @@ TEST_F(ParserImplTest, FunctionHeader_InvalidReturnType) {
EXPECT_FALSE(f.matched); EXPECT_FALSE(f.matched);
EXPECT_TRUE(f.errored); EXPECT_TRUE(f.errored);
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:14: unknown constructed type 'invalid'"); EXPECT_EQ(p->error(), "1:14: unknown type 'invalid'");
} }
TEST_F(ParserImplTest, FunctionHeader_MissingReturnType) { TEST_F(ParserImplTest, FunctionHeader_MissingReturnType) {

View File

@ -85,7 +85,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl_InvalidVariable) {
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);
EXPECT_FALSE(e.matched); EXPECT_FALSE(e.matched);
EXPECT_EQ(e.value, nullptr); EXPECT_EQ(e.value, nullptr);
EXPECT_EQ(p->error(), "1:9: unknown constructed type 'invalid'"); EXPECT_EQ(p->error(), "1:9: unknown type 'invalid'");
} }
TEST_F(ParserImplTest, GlobalConstantDecl_InvalidExpression) { TEST_F(ParserImplTest, GlobalConstantDecl_InvalidExpression) {

View File

@ -48,7 +48,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Invalid) {
auto p = parser("var<private> a : vec2<invalid>;"); auto p = parser("var<private> a : vec2<invalid>;");
p->expect_global_decl(); p->expect_global_decl();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:23: unknown constructed type 'invalid'"); EXPECT_EQ(p->error(), "1:23: unknown type 'invalid'");
} }
TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_MissingSemicolon) { TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_MissingSemicolon) {
@ -90,12 +90,11 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto program = p->program(); auto program = p->program();
ASSERT_EQ(program.AST().ConstructedTypes().size(), 1u); ASSERT_EQ(program.AST().TypeDecls().size(), 1u);
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<ast::Alias>()); ASSERT_TRUE(program.AST().TypeDecls()[0]->Is<ast::Alias>());
EXPECT_EQ( EXPECT_EQ(program.Symbols().NameFor(
program.Symbols().NameFor( program.AST().TypeDecls()[0]->As<ast::Alias>()->symbol()),
program.AST().ConstructedTypes()[0]->As<ast::Alias>()->symbol()), "A");
"A");
} }
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) { TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) {
@ -108,13 +107,13 @@ type B = A;)");
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto program = p->program(); auto program = p->program();
ASSERT_EQ(program.AST().ConstructedTypes().size(), 2u); ASSERT_EQ(program.AST().TypeDecls().size(), 2u);
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<ast::Struct>()); ASSERT_TRUE(program.AST().TypeDecls()[0]->Is<ast::Struct>());
auto* str = program.AST().ConstructedTypes()[0]->As<ast::Struct>(); auto* str = program.AST().TypeDecls()[0]->As<ast::Struct>();
EXPECT_EQ(str->name(), program.Symbols().Get("A")); EXPECT_EQ(str->name(), program.Symbols().Get("A"));
ASSERT_TRUE(program.AST().ConstructedTypes()[1]->Is<ast::Alias>()); ASSERT_TRUE(program.AST().TypeDecls()[1]->Is<ast::Alias>());
auto* alias = program.AST().ConstructedTypes()[1]->As<ast::Alias>(); auto* alias = program.AST().TypeDecls()[1]->As<ast::Alias>();
EXPECT_EQ(alias->symbol(), program.Symbols().Get("B")); EXPECT_EQ(alias->symbol(), program.Symbols().Get("B"));
auto* tn = alias->type()->As<ast::TypeName>(); auto* tn = alias->type()->As<ast::TypeName>();
EXPECT_NE(tn, nullptr); EXPECT_NE(tn, nullptr);
@ -125,7 +124,7 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias_Invalid) {
auto p = parser("type A = invalid;"); auto p = parser("type A = invalid;");
p->expect_global_decl(); p->expect_global_decl();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:10: unknown constructed type 'invalid'"); EXPECT_EQ(p->error(), "1:10: unknown type 'invalid'");
} }
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_MissingSemicolon) { TEST_F(ParserImplTest, GlobalDecl_TypeAlias_MissingSemicolon) {
@ -170,9 +169,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto program = p->program(); auto program = p->program();
ASSERT_EQ(program.AST().ConstructedTypes().size(), 1u); ASSERT_EQ(program.AST().TypeDecls().size(), 1u);
auto* t = program.AST().ConstructedTypes()[0]; auto* t = program.AST().TypeDecls()[0];
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<ast::Struct>()); ASSERT_TRUE(t->Is<ast::Struct>());
@ -188,9 +187,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto program = p->program(); auto program = p->program();
ASSERT_EQ(program.AST().ConstructedTypes().size(), 1u); ASSERT_EQ(program.AST().TypeDecls().size(), 1u);
auto* t = program.AST().ConstructedTypes()[0]; auto* t = program.AST().TypeDecls()[0];
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<ast::Struct>()); ASSERT_TRUE(t->Is<ast::Struct>());
@ -215,9 +214,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
auto program = p->program(); auto program = p->program();
ASSERT_EQ(program.AST().ConstructedTypes().size(), 1u); ASSERT_EQ(program.AST().TypeDecls().size(), 1u);
auto* t = program.AST().ConstructedTypes()[0]; auto* t = program.AST().TypeDecls()[0];
ASSERT_NE(t, nullptr); ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<ast::Struct>()); ASSERT_TRUE(t->Is<ast::Struct>());

View File

@ -300,7 +300,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast_InvalidType) {
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);
EXPECT_EQ(e.value, nullptr); EXPECT_EQ(e.value, nullptr);
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:9: unknown constructed type 'invalid'"); EXPECT_EQ(p->error(), "1:9: unknown type 'invalid'");
} }
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingLeftParen) { TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingLeftParen) {

View File

@ -152,7 +152,7 @@ TEST_F(ParserImplTest, StructDecl_InvalidStructBody) {
EXPECT_EQ(s.value, nullptr); EXPECT_EQ(s.value, nullptr);
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:16: unknown constructed type 'B'"); EXPECT_EQ(p->error(), "1:16: unknown type 'B'");
} }
TEST_F(ParserImplTest, StructDecl_InvalidDecorationDecl) { TEST_F(ParserImplTest, StructDecl_InvalidDecorationDecl) {

View File

@ -202,7 +202,7 @@ TEST_F(ParserImplTest, StructMember_InvalidVariable) {
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_TRUE(m.errored); ASSERT_TRUE(m.errored);
ASSERT_EQ(m.value, nullptr); ASSERT_EQ(m.value, nullptr);
EXPECT_EQ(p->error(), "1:17: unknown constructed type 'B'"); EXPECT_EQ(p->error(), "1:17: unknown type 'B'");
} }
TEST_F(ParserImplTest, StructMember_MissingSemicolon) { TEST_F(ParserImplTest, StructMember_MissingSemicolon) {

View File

@ -54,15 +54,15 @@ fn main() -> { // missing return type
TEST_F(ParserImplTest, GetRegisteredType) { TEST_F(ParserImplTest, GetRegisteredType) {
auto p = parser(""); auto p = parser("");
auto* alias = create<ast::Alias>(Sym("my_alias"), ty.i32()); auto* alias = create<ast::Alias>(Sym("my_alias"), ty.i32());
p->register_constructed("my_alias", alias); p->register_type("my_alias", alias);
auto* got = p->get_constructed("my_alias"); auto* got = p->get_type("my_alias");
EXPECT_EQ(got, alias); EXPECT_EQ(got, alias);
} }
TEST_F(ParserImplTest, GetUnregisteredType) { TEST_F(ParserImplTest, GetUnregisteredType) {
auto p = parser(""); auto p = parser("");
auto* alias = p->get_constructed("my_alias"); auto* alias = p->get_type("my_alias");
ASSERT_EQ(alias, nullptr); ASSERT_EQ(alias, nullptr);
} }

View File

@ -126,7 +126,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) {
EXPECT_EQ(t.value, nullptr); EXPECT_EQ(t.value, nullptr);
EXPECT_FALSE(t.matched); EXPECT_FALSE(t.matched);
EXPECT_TRUE(t.errored); EXPECT_TRUE(t.errored);
EXPECT_EQ(p->error(), "1:12: unknown constructed type 'abc'"); EXPECT_EQ(p->error(), "1:12: unknown type 'abc'");
} }
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingType) { TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingType) {
@ -185,7 +185,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_Invalid) {
EXPECT_EQ(t.value, nullptr); EXPECT_EQ(t.value, nullptr);
EXPECT_FALSE(t.matched); EXPECT_FALSE(t.matched);
EXPECT_TRUE(t.errored); EXPECT_TRUE(t.errored);
EXPECT_EQ(p->error(), "1:25: unknown constructed type 'abc'"); EXPECT_EQ(p->error(), "1:25: unknown type 'abc'");
} }
TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_MissingType) { TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_MissingType) {

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
auto p = parser("type a = B"); auto p = parser("type a = B");
auto* str = p->builder().Structure(p->builder().Symbols().Register("B"), {}); auto* str = p->builder().Structure(p->builder().Symbols().Register("B"), {});
p->register_constructed("B", str); p->register_type("B", str);
auto t = p->type_alias(); auto t = p->type_alias();
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
@ -89,7 +89,7 @@ TEST_F(ParserImplTest, TypeDecl_InvalidType) {
EXPECT_FALSE(t.matched); EXPECT_FALSE(t.matched);
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_EQ(t.value, nullptr); EXPECT_EQ(t.value, nullptr);
EXPECT_EQ(p->error(), "1:10: unknown constructed type 'B'"); EXPECT_EQ(p->error(), "1:10: unknown type 'B'");
} }
} // namespace } // namespace

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
auto& builder = p->builder(); auto& builder = p->builder();
auto* alias_type = builder.ty.alias("A", builder.ty.i32()); auto* alias_type = builder.ty.alias("A", builder.ty.i32());
p->register_constructed("A", alias_type); p->register_type("A", alias_type);
auto t = p->type_decl(); auto t = p->type_decl();
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
@ -58,7 +58,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier_NotFound) {
EXPECT_FALSE(t.matched); EXPECT_FALSE(t.matched);
ASSERT_EQ(t.value, nullptr); ASSERT_EQ(t.value, nullptr);
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:1: unknown constructed type 'B'"); EXPECT_EQ(p->error(), "1:1: unknown type 'B'");
} }
TEST_F(ParserImplTest, TypeDecl_Bool) { TEST_F(ParserImplTest, TypeDecl_Bool) {
@ -182,7 +182,7 @@ TEST_P(VecBadType, Handles_Unknown_Type) {
EXPECT_FALSE(t.matched); EXPECT_FALSE(t.matched);
ASSERT_EQ(t.value, nullptr); ASSERT_EQ(t.value, nullptr);
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(p->error(), "1:6: unknown constructed type 'unknown'"); ASSERT_EQ(p->error(), "1:6: unknown type 'unknown'");
} }
INSTANTIATE_TEST_SUITE_P(ParserImplTest, INSTANTIATE_TEST_SUITE_P(ParserImplTest,
VecBadType, VecBadType,
@ -365,7 +365,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_BadType) {
EXPECT_FALSE(t.matched); EXPECT_FALSE(t.matched);
ASSERT_EQ(t.value, nullptr); ASSERT_EQ(t.value, nullptr);
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(p->error(), "1:15: unknown constructed type 'unknown'"); ASSERT_EQ(p->error(), "1:15: unknown type 'unknown'");
} }
TEST_F(ParserImplTest, TypeDecl_Ptr_BadAccess) { TEST_F(ParserImplTest, TypeDecl_Ptr_BadAccess) {
@ -599,7 +599,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_BadType) {
EXPECT_FALSE(t.matched); EXPECT_FALSE(t.matched);
ASSERT_EQ(t.value, nullptr); ASSERT_EQ(t.value, nullptr);
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(p->error(), "1:7: unknown constructed type 'unknown'"); ASSERT_EQ(p->error(), "1:7: unknown type 'unknown'");
} }
TEST_F(ParserImplTest, TypeDecl_Array_ZeroSize) { TEST_F(ParserImplTest, TypeDecl_Array_ZeroSize) {
@ -761,7 +761,7 @@ TEST_P(MatrixBadType, Handles_Unknown_Type) {
EXPECT_FALSE(t.matched); EXPECT_FALSE(t.matched);
ASSERT_EQ(t.value, nullptr); ASSERT_EQ(t.value, nullptr);
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(p->error(), "1:8: unknown constructed type 'unknown'"); ASSERT_EQ(p->error(), "1:8: unknown type 'unknown'");
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
ParserImplTest, ParserImplTest,

View File

@ -81,7 +81,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_InvalidType) {
auto decl = p->expect_variable_ident_decl("test"); auto decl = p->expect_variable_ident_decl("test");
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_TRUE(decl.errored); ASSERT_TRUE(decl.errored);
ASSERT_EQ(p->error(), "1:10: unknown constructed type 'invalid'"); ASSERT_EQ(p->error(), "1:10: unknown type 'invalid'");
} }
// TODO(crbug.com/tint/846): Remove // TODO(crbug.com/tint/846): Remove
@ -134,7 +134,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read_DEPRECATED) {
auto* s = Structure(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
p->register_constructed("S", s); p->register_type("S", s);
auto res = p->expect_global_decl(); auto res = p->expect_global_decl();
ASSERT_FALSE(res.errored) << p->error(); ASSERT_FALSE(res.errored) << p->error();
@ -166,7 +166,7 @@ TEST_F(ParserImplTest,
auto* s = Structure(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
p->register_constructed("S", s); p->register_type("S", s);
auto res = p->expect_global_decl(); auto res = p->expect_global_decl();
ASSERT_FALSE(res.errored) << p->error(); ASSERT_FALSE(res.errored) << p->error();
@ -197,7 +197,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail_DEPRECATED) {
auto* s = Structure(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
p->register_constructed("S", s); p->register_type("S", s);
auto decl = p->expect_variable_ident_decl("test"); auto decl = p->expect_variable_ident_decl("test");
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
@ -220,7 +220,7 @@ TEST_F(ParserImplTest,
auto* s = Structure(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
p->register_constructed("S", s); p->register_type("S", s);
auto decl = p->expect_variable_ident_decl("test"); auto decl = p->expect_variable_ident_decl("test");
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
@ -259,7 +259,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) {
auto* s = Structure(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
p->register_constructed("S", s); p->register_type("S", s);
auto decl = p->expect_variable_ident_decl("test"); auto decl = p->expect_variable_ident_decl("test");
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());

View File

@ -65,7 +65,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) {
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);
EXPECT_EQ(e.value, nullptr); EXPECT_EQ(e.value, nullptr);
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:9: unknown constructed type 'invalid'"); EXPECT_EQ(p->error(), "1:9: unknown type 'invalid'");
} }
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ConstructorInvalid) { TEST_F(ParserImplTest, VariableStmt_VariableDecl_ConstructorInvalid) {
@ -160,7 +160,7 @@ TEST_F(ParserImplTest, VariableStmt_Let_InvalidVarIdent) {
EXPECT_TRUE(e.errored); EXPECT_TRUE(e.errored);
EXPECT_EQ(e.value, nullptr); EXPECT_EQ(e.value, nullptr);
EXPECT_TRUE(p->has_error()); EXPECT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:9: unknown constructed type 'invalid'"); EXPECT_EQ(p->error(), "1:9: unknown type 'invalid'");
} }
TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) { TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) {

View File

@ -351,7 +351,7 @@ struct DataType<alias<T, ID>> {
auto name = b.Symbols().Register("alias_" + std::to_string(ID)); auto name = b.Symbols().Register("alias_" + std::to_string(ID));
if (!b.AST().LookupType(name)) { if (!b.AST().LookupType(name)) {
auto* type = DataType<T>::AST(b); auto* type = DataType<T>::AST(b);
b.AST().AddConstructedType(b.ty.alias(name, type)); b.AST().AddTypeDecl(b.ty.alias(name, type));
} }
return b.create<ast::TypeName>(name); return b.create<ast::TypeName>(name);
} }

View File

@ -75,7 +75,7 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap& data) {
// Strip entry point IO decorations from struct declarations. // Strip entry point IO decorations from struct declarations.
// TODO(jrprice): This code is duplicated with the SPIR-V transform. // TODO(jrprice): This code is duplicated with the SPIR-V transform.
for (auto* ty : ctx.src->AST().ConstructedTypes()) { for (auto* ty : ctx.src->AST().TypeDecls()) {
if (auto* struct_ty = ty->As<ast::Struct>()) { if (auto* struct_ty = ty->As<ast::Struct>()) {
// Build new list of struct members without entry point IO decorations. // Build new list of struct members without entry point IO decorations.
ast::StructMemberList new_struct_members; ast::StructMemberList new_struct_members;

View File

@ -331,8 +331,8 @@ void InsertGlobal(CloneContext& ctx,
} }
} }
/// @returns the unwrapped, user-declared constructed type of ty. /// @returns the unwrapped, user-declared type of ty.
const ast::TypeDecl* ConstructedTypeOf(const sem::Type* ty) { const ast::TypeDecl* TypeDeclOf(const sem::Type* ty) {
while (true) { while (true) {
if (auto* ref = ty->As<sem::Reference>()) { if (auto* ref = ty->As<sem::Reference>()) {
ty = ref->StoreType(); ty = ref->StoreType();
@ -341,7 +341,7 @@ const ast::TypeDecl* ConstructedTypeOf(const sem::Type* ty) {
if (auto* str = ty->As<sem::Struct>()) { if (auto* str = ty->As<sem::Struct>()) {
return str->Declaration(); return str->Declaration();
} }
// Not a constructed type // Not a declared type
return nullptr; return nullptr;
} }
} }
@ -762,7 +762,7 @@ Output DecomposeStorageAccess::Run(const Program* in, const DataMap&) {
auto* offset = access.offset->Build(ctx); auto* offset = access.offset->Build(ctx);
auto* buf_ty = access.var->Type()->UnwrapRef(); auto* buf_ty = access.var->Type()->UnwrapRef();
auto* el_ty = access.type->UnwrapRef(); auto* el_ty = access.type->UnwrapRef();
auto* insert_after = ConstructedTypeOf(access.var->Type()); auto* insert_after = TypeDeclOf(access.var->Type());
Symbol func = state.LoadFunc(ctx, insert_after, buf_ty, el_ty, Symbol func = state.LoadFunc(ctx, insert_after, buf_ty, el_ty,
access.var->As<sem::VariableUser>()); access.var->As<sem::VariableUser>());
@ -778,7 +778,7 @@ Output DecomposeStorageAccess::Run(const Program* in, const DataMap&) {
auto* buf_ty = store.target.var->Type()->UnwrapRef(); auto* buf_ty = store.target.var->Type()->UnwrapRef();
auto* el_ty = store.target.type->UnwrapRef(); auto* el_ty = store.target.type->UnwrapRef();
auto* value = store.assignment->rhs(); auto* value = store.assignment->rhs();
auto* insert_after = ConstructedTypeOf(store.target.var->Type()); auto* insert_after = TypeDeclOf(store.target.var->Type());
Symbol func = state.StoreFunc(ctx, insert_after, buf_ty, el_ty, Symbol func = state.StoreFunc(ctx, insert_after, buf_ty, el_ty,
store.target.var->As<sem::VariableUser>()); store.target.var->As<sem::VariableUser>());

View File

@ -71,7 +71,7 @@ Output SingleEntryPoint::Run(const Program* in, const DataMap& data) {
for (auto* decl : in->AST().GlobalDeclarations()) { for (auto* decl : in->AST().GlobalDeclarations()) {
if (auto* ty = decl->As<ast::TypeDecl>()) { if (auto* ty = decl->As<ast::TypeDecl>()) {
// TODO(jrprice): Strip unused types. // TODO(jrprice): Strip unused types.
out.AST().AddConstructedType(ctx.Clone(ty)); out.AST().AddTypeDecl(ctx.Clone(ty));
} else if (auto* var = decl->As<ast::Variable>()) { } else if (auto* var = decl->As<ast::Variable>()) {
if (var->is_const() || referenced_vars.count(var)) { if (var->is_const() || referenced_vars.count(var)) {
out.AST().AddGlobalVariable(ctx.Clone(var)); out.AST().AddGlobalVariable(ctx.Clone(var));

View File

@ -127,7 +127,7 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
// ``` // ```
// Strip entry point IO decorations from struct declarations. // Strip entry point IO decorations from struct declarations.
for (auto* ty : ctx.src->AST().ConstructedTypes()) { for (auto* ty : ctx.src->AST().TypeDecls()) {
if (auto* struct_ty = ty->As<ast::Struct>()) { if (auto* struct_ty = ty->As<ast::Struct>()) {
// Build new list of struct members without entry point IO decorations. // Build new list of struct members without entry point IO decorations.
ast::StructMemberList new_struct_members; ast::StructMemberList new_struct_members;

View File

@ -120,15 +120,15 @@ bool GeneratorImpl::Generate(std::ostream& out) {
register_global(global); register_global(global);
} }
for (auto* const ty : builder_.AST().ConstructedTypes()) { for (auto* const ty : builder_.AST().TypeDecls()) {
if (ty->Is<ast::Alias>()) { if (ty->Is<ast::Alias>()) {
continue; continue;
} }
if (!EmitConstructedType(out, TypeOf(ty))) { if (!EmitTypeDecl(out, TypeOf(ty))) {
return false; return false;
} }
} }
if (!builder_.AST().ConstructedTypes().empty()) { if (!builder_.AST().TypeDecls().empty()) {
out << std::endl; out << std::endl;
} }
@ -204,8 +204,7 @@ std::string GeneratorImpl::current_ep_var_name(VarType type) {
return name; return name;
} }
bool GeneratorImpl::EmitConstructedType(std::ostream& out, bool GeneratorImpl::EmitTypeDecl(std::ostream& out, const sem::Type* ty) {
const sem::Type* ty) {
make_indent(out); make_indent(out);
if (auto* str = ty->As<sem::Struct>()) { if (auto* str = ty->As<sem::Struct>()) {
@ -214,8 +213,7 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
return false; return false;
} }
} else { } else {
TINT_UNREACHABLE(diagnostics_) TINT_UNREACHABLE(diagnostics_) << "declared type: " << ty->TypeInfo().name;
<< "constructed type: " << ty->TypeInfo().name;
return false; return false;
} }

View File

@ -57,11 +57,11 @@ class GeneratorImpl : public TextGenerator {
/// @returns true on successful generation; false otherwise /// @returns true on successful generation; false otherwise
bool Generate(std::ostream& out); bool Generate(std::ostream& out);
/// Handles generating a constructed type /// Handles generating a declared type
/// @param out the output stream /// @param out the output stream
/// @param ty the constructed type to generate /// @param ty the declared type to generate
/// @returns true if the constructed type was emitted /// @returns true if the declared type was emitted
bool EmitConstructedType(std::ostream& out, const sem::Type* ty); bool EmitTypeDecl(std::ostream& out, const sem::Type* ty);
/// Handles an array accessor expression /// Handles an array accessor expression
/// @param pre the preamble for the expression stream /// @param pre the preamble for the expression stream
/// @param out the output of the expression stream /// @param out the output of the expression stream

View File

@ -87,9 +87,9 @@ bool GeneratorImpl::Generate() {
global_variables_.set(global->symbol(), sem); global_variables_.set(global->symbol(), sem);
} }
for (auto* const type_decl : program_->AST().ConstructedTypes()) { for (auto* const type_decl : program_->AST().TypeDecls()) {
if (!type_decl->Is<ast::Alias>()) { if (!type_decl->Is<ast::Alias>()) {
if (!EmitConstructedType(TypeOf(type_decl))) { if (!EmitTypeDecl(TypeOf(type_decl))) {
return false; return false;
} }
} }
@ -105,7 +105,7 @@ bool GeneratorImpl::Generate() {
} }
} }
if (!program_->AST().ConstructedTypes().empty() || array_wrappers_.size()) { if (!program_->AST().TypeDecls().empty() || array_wrappers_.size()) {
out_ << std::endl; out_ << std::endl;
} }
@ -160,7 +160,7 @@ bool GeneratorImpl::Generate() {
return true; return true;
} }
bool GeneratorImpl::EmitConstructedType(const sem::Type* ty) { bool GeneratorImpl::EmitTypeDecl(const sem::Type* ty) {
make_indent(); make_indent();
if (auto* str = ty->As<sem::Struct>()) { if (auto* str = ty->As<sem::Struct>()) {
@ -2011,7 +2011,7 @@ bool GeneratorImpl::EmitType(const sem::Type* type, const std::string& name) {
out_ << "sampler"; out_ << "sampler";
} else if (auto* str = type->As<sem::Struct>()) { } else if (auto* str = type->As<sem::Struct>()) {
// The struct type emits as just the name. The declaration would be emitted // The struct type emits as just the name. The declaration would be emitted
// as part of emitting the constructed types. // as part of emitting the declared types.
out_ << program_->Symbols().NameFor(str->Declaration()->name()); out_ << program_->Symbols().NameFor(str->Declaration()->name());
} else if (auto* tex = type->As<sem::Texture>()) { } else if (auto* tex = type->As<sem::Texture>()) {
if (tex->Is<sem::DepthTexture>()) { if (tex->Is<sem::DepthTexture>()) {

View File

@ -61,10 +61,10 @@ class GeneratorImpl : public TextGenerator {
/// @returns true on successful generation; false otherwise /// @returns true on successful generation; false otherwise
bool Generate(); bool Generate();
/// Handles generating a constructed /// Handles generating a declared type
/// @param ty the constructed type to generate /// @param ty the declared type to generate
/// @returns true if the constructed type was emitted /// @returns true if the declared type was emitted
bool EmitConstructedType(const sem::Type* ty); bool EmitTypeDecl(const sem::Type* ty);
/// Handles an array accessor expression /// Handles an array accessor expression
/// @param expr the expression to emit /// @param expr the expression to emit
/// @returns true if the array accessor was emitted /// @returns true if the array accessor was emitted

View File

@ -67,7 +67,7 @@ bool GeneratorImpl::Generate() {
// Generate global declarations in the order they appear in the module. // Generate global declarations in the order they appear in the module.
for (auto* decl : program_->AST().GlobalDeclarations()) { for (auto* decl : program_->AST().GlobalDeclarations()) {
if (auto* td = decl->As<ast::TypeDecl>()) { if (auto* td = decl->As<ast::TypeDecl>()) {
if (!EmitConstructedType(td)) { if (!EmitTypeDecl(td)) {
return false; return false;
} }
} else if (auto* func = decl->As<ast::Function>()) { } else if (auto* func = decl->As<ast::Function>()) {
@ -91,7 +91,7 @@ bool GeneratorImpl::Generate() {
return true; return true;
} }
bool GeneratorImpl::EmitConstructedType(const ast::TypeDecl* ty) { bool GeneratorImpl::EmitTypeDecl(const ast::TypeDecl* ty) {
make_indent(); make_indent();
if (auto* alias = ty->As<ast::Alias>()) { if (auto* alias = ty->As<ast::Alias>()) {
@ -105,7 +105,7 @@ bool GeneratorImpl::EmitConstructedType(const ast::TypeDecl* ty) {
return false; return false;
} }
} else { } else {
diagnostics_.add_error("unknown constructed type: " + diagnostics_.add_error("unknown declared type: " +
std::string(ty->TypeInfo().name)); std::string(ty->TypeInfo().name));
return false; return false;
} }

View File

@ -54,10 +54,10 @@ class GeneratorImpl : public TextGenerator {
/// @returns true on successful generation; false otherwise /// @returns true on successful generation; false otherwise
bool Generate(); bool Generate();
/// Handles generating a constructed type /// Handles generating a declared type
/// @param ty the constructed to generate /// @param ty the declared type to generate
/// @returns true if the constructed was emitted /// @returns true if the declared type was emitted
bool EmitConstructedType(const ast::TypeDecl* ty); bool EmitTypeDecl(const ast::TypeDecl* ty);
/// Handles an array accessor expression /// Handles an array accessor expression
/// @param expr the expression to emit /// @param expr the expression to emit
/// @returns true if the array accessor was emitted /// @returns true if the array accessor was emitted

View File

@ -26,12 +26,12 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_F32) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitConstructedType(alias)) << gen.error(); ASSERT_TRUE(gen.EmitTypeDecl(alias)) << gen.error();
EXPECT_EQ(gen.result(), R"(type a = f32; EXPECT_EQ(gen.result(), R"(type a = f32;
)"); )");
} }
TEST_F(WgslGeneratorImplTest, EmitConstructedType_Struct) { TEST_F(WgslGeneratorImplTest, EmitTypeDecl_Struct) {
auto* s = Structure("A", { auto* s = Structure("A", {
Member("a", ty.f32()), Member("a", ty.f32()),
Member("b", ty.i32()), Member("b", ty.i32()),
@ -41,8 +41,8 @@ TEST_F(WgslGeneratorImplTest, EmitConstructedType_Struct) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitConstructedType(s)) << gen.error(); ASSERT_TRUE(gen.EmitTypeDecl(s)) << gen.error();
ASSERT_TRUE(gen.EmitConstructedType(alias)) << gen.error(); ASSERT_TRUE(gen.EmitTypeDecl(alias)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct A { EXPECT_EQ(gen.result(), R"(struct A {
a : f32; a : f32;
b : i32; b : i32;
@ -61,7 +61,7 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_ToStruct) {
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.EmitConstructedType(alias)) << gen.error(); ASSERT_TRUE(gen.EmitTypeDecl(alias)) << gen.error();
EXPECT_EQ(gen.result(), R"(type B = A; EXPECT_EQ(gen.result(), R"(type B = A;
)"); )");
} }