tint/ast: Remove scalar types from ast::*

Instead use ast::TypeName for all of these.

Bug: tint:1810
Change-Id: Ie51a69bf40648a9da73c0a1de2cd96a93d4eac76
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117892
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton 2023-02-09 23:33:24 +00:00 committed by Dawn LUCI CQ
parent eb30a0ddee
commit 6e0a51521f
65 changed files with 579 additions and 1088 deletions

View File

@ -247,7 +247,6 @@ libtint_source_set("libtint_syntax_tree_src") {
"ast/binding_attribute.h",
"ast/bitcast_expression.h",
"ast/block_statement.h",
"ast/bool.h",
"ast/bool_literal_expression.h",
"ast/break_if_statement.h",
"ast/break_statement.h",
@ -272,13 +271,10 @@ libtint_source_set("libtint_syntax_tree_src") {
"ast/expression.h",
"ast/extension.h",
"ast/external_texture.h",
"ast/f16.h",
"ast/f32.h",
"ast/float_literal_expression.h",
"ast/for_loop_statement.h",
"ast/function.h",
"ast/group_attribute.h",
"ast/i32.h",
"ast/id_attribute.h",
"ast/identifier.h",
"ast/identifier_expression.h",
@ -323,7 +319,6 @@ libtint_source_set("libtint_syntax_tree_src") {
"ast/type.h",
"ast/type_decl.h",
"ast/type_name.h",
"ast/u32.h",
"ast/unary_op.h",
"ast/unary_op_expression.h",
"ast/var.h",
@ -567,8 +562,6 @@ libtint_source_set("libtint_ast_src") {
"ast/bitcast_expression.h",
"ast/block_statement.cc",
"ast/block_statement.h",
"ast/bool.cc",
"ast/bool.h",
"ast/bool_literal_expression.cc",
"ast/bool_literal_expression.h",
"ast/break_if_statement.cc",
@ -617,10 +610,6 @@ libtint_source_set("libtint_ast_src") {
"ast/extension.h",
"ast/external_texture.cc",
"ast/external_texture.h",
"ast/f16.cc",
"ast/f16.h",
"ast/f32.cc",
"ast/f32.h",
"ast/float_literal_expression.cc",
"ast/float_literal_expression.h",
"ast/for_loop_statement.cc",
@ -629,8 +618,6 @@ libtint_source_set("libtint_ast_src") {
"ast/function.h",
"ast/group_attribute.cc",
"ast/group_attribute.h",
"ast/i32.cc",
"ast/i32.h",
"ast/id_attribute.cc",
"ast/id_attribute.h",
"ast/identifier.cc",
@ -717,8 +704,6 @@ libtint_source_set("libtint_ast_src") {
"ast/type_decl.h",
"ast/type_name.cc",
"ast/type_name.h",
"ast/u32.cc",
"ast/u32.h",
"ast/unary_op.cc",
"ast/unary_op.h",
"ast/unary_op_expression.cc",
@ -1317,7 +1302,6 @@ if (tint_build_unittests) {
"ast/bitcast_expression_test.cc",
"ast/block_statement_test.cc",
"ast/bool_literal_expression_test.cc",
"ast/bool_test.cc",
"ast/break_if_statement_test.cc",
"ast/break_statement_test.cc",
"ast/builtin_attribute_test.cc",
@ -1338,13 +1322,10 @@ if (tint_build_unittests) {
"ast/enable_test.cc",
"ast/extension_test.cc",
"ast/external_texture_test.cc",
"ast/f16_test.cc",
"ast/f32_test.cc",
"ast/float_literal_expression_test.cc",
"ast/for_loop_statement_test.cc",
"ast/function_test.cc",
"ast/group_attribute_test.cc",
"ast/i32_test.cc",
"ast/id_attribute_test.cc",
"ast/identifier_expression_test.cc",
"ast/identifier_test.cc",
@ -1380,7 +1361,6 @@ if (tint_build_unittests) {
"ast/texture_test.cc",
"ast/traverse_expressions_test.cc",
"ast/type_name_test.cc",
"ast/u32_test.cc",
"ast/unary_op_expression_test.cc",
"ast/variable_decl_statement_test.cc",
"ast/variable_test.cc",

View File

@ -102,8 +102,6 @@ list(APPEND TINT_LIB_SRCS
ast/block_statement.h
ast/bool_literal_expression.cc
ast/bool_literal_expression.h
ast/bool.cc
ast/bool.h
ast/break_if_statement.cc
ast/break_if_statement.h
ast/break_statement.cc
@ -146,10 +144,6 @@ list(APPEND TINT_LIB_SRCS
ast/expression.h
ast/external_texture.cc
ast/external_texture.h
ast/f16.cc
ast/f16.h
ast/f32.cc
ast/f32.h
ast/float_literal_expression.cc
ast/float_literal_expression.h
ast/for_loop_statement.cc
@ -158,8 +152,6 @@ list(APPEND TINT_LIB_SRCS
ast/function.h
ast/group_attribute.cc
ast/group_attribute.h
ast/i32.cc
ast/i32.h
ast/id_attribute.cc
ast/id_attribute.h
ast/identifier.cc
@ -244,8 +236,6 @@ list(APPEND TINT_LIB_SRCS
ast/type_name.h
ast/type.cc
ast/type.h
ast/u32.cc
ast/u32.h
ast/unary_op_expression.cc
ast/unary_op_expression.h
ast/unary_op.cc
@ -834,7 +824,6 @@ if(TINT_BUILD_TESTS)
ast/bitcast_expression_test.cc
ast/block_statement_test.cc
ast/bool_literal_expression_test.cc
ast/bool_test.cc
ast/break_if_statement_test.cc
ast/break_statement_test.cc
ast/builtin_attribute_test.cc
@ -855,13 +844,10 @@ if(TINT_BUILD_TESTS)
ast/discard_statement_test.cc
ast/enable_test.cc
ast/external_texture_test.cc
ast/f16_test.cc
ast/f32_test.cc
ast/float_literal_expression_test.cc
ast/for_loop_statement_test.cc
ast/function_test.cc
ast/group_attribute_test.cc
ast/i32_test.cc
ast/id_attribute_test.cc
ast/identifier_test.cc
ast/identifier_expression_test.cc
@ -896,7 +882,6 @@ if(TINT_BUILD_TESTS)
ast/texture_test.cc
ast/traverse_expressions_test.cc
ast/type_name_test.cc
ast/u32_test.cc
ast/unary_op_expression_test.cc
ast/variable_decl_statement_test.cc
ast/variable_test.cc

View File

@ -14,16 +14,12 @@
#include "src/tint/ast/alias.h"
#include "src/tint/ast/array.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/matrix.h"
#include "src/tint/ast/pointer.h"
#include "src/tint/ast/sampler.h"
#include "src/tint/ast/struct.h"
#include "src/tint/ast/test_helper.h"
#include "src/tint/ast/texture.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/vector.h"
#include "src/tint/type/access.h"
@ -33,9 +29,9 @@ namespace {
using AstAliasTest = TestHelper;
TEST_F(AstAliasTest, Create) {
auto* u32 = create<U32>();
auto* u32 = ty.u32();
auto* a = Alias("a_type", u32);
EXPECT_EQ(a->name->symbol, Symbol(1, ID()));
EXPECT_EQ(Symbols().NameFor(a->name->symbol), "a_type");
EXPECT_EQ(a->type, u32);
}

View File

@ -24,19 +24,19 @@ namespace {
using AstArrayTest = TestHelper;
TEST_F(AstArrayTest, CreateSizedArray) {
auto* u32 = create<U32>();
auto* count = Expr(3_u);
auto* arr = create<Array>(u32, count, utils::Empty);
EXPECT_EQ(arr->type, u32);
auto* arr = create<Array>(ty.u32(), count, utils::Empty);
ASSERT_TRUE(arr->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(arr->type->As<ast::TypeName>()->name->symbol), "u32");
EXPECT_EQ(arr->count, count);
EXPECT_TRUE(arr->Is<Array>());
EXPECT_FALSE(arr->IsRuntimeArray());
}
TEST_F(AstArrayTest, CreateRuntimeArray) {
auto* u32 = create<U32>();
auto* arr = create<Array>(u32, nullptr, utils::Empty);
EXPECT_EQ(arr->type, u32);
auto* arr = create<Array>(ty.u32(), nullptr, utils::Empty);
ASSERT_TRUE(arr->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(arr->type->As<ast::TypeName>()->name->symbol), "u32");
EXPECT_EQ(arr->count, nullptr);
EXPECT_TRUE(arr->Is<Array>());
EXPECT_TRUE(arr->IsRuntimeArray());
@ -51,26 +51,22 @@ TEST_F(AstArrayTest, CreateInferredTypeArray) {
}
TEST_F(AstArrayTest, FriendlyName_RuntimeSized) {
auto* i32 = create<I32>();
auto* arr = create<Array>(i32, nullptr, utils::Empty);
auto* arr = create<Array>(ty.i32(), nullptr, utils::Empty);
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32>");
}
TEST_F(AstArrayTest, FriendlyName_LiteralSized) {
auto* i32 = create<I32>();
auto* arr = create<Array>(i32, Expr(5_u), utils::Empty);
auto* arr = create<Array>(ty.i32(), Expr(5_u), utils::Empty);
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32, 5>");
}
TEST_F(AstArrayTest, FriendlyName_ConstantSized) {
auto* i32 = create<I32>();
auto* arr = create<Array>(i32, Expr("size"), utils::Empty);
auto* arr = create<Array>(ty.i32(), Expr("size"), utils::Empty);
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32, size>");
}
TEST_F(AstArrayTest, FriendlyName_WithStride) {
auto* i32 = create<I32>();
auto* arr = create<Array>(i32, Expr(5_u), utils::Vector{create<StrideAttribute>(32u)});
auto* arr = create<Array>(ty.i32(), Expr(5_u), utils::Vector{create<StrideAttribute>(32u)});
EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array<i32, 5>");
}

View File

@ -14,7 +14,6 @@
#include "src/tint/ast/atomic.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
@ -23,13 +22,14 @@ namespace {
using AstAtomicTest = TestHelper;
TEST_F(AstAtomicTest, Creation) {
auto* i32 = create<I32>();
auto* i32 = ty.i32();
auto* p = create<Atomic>(i32);
EXPECT_EQ(p->type, i32);
ASSERT_TRUE(p->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(p->type->As<ast::TypeName>()->name->symbol), "i32");
}
TEST_F(AstAtomicTest, FriendlyName) {
auto* i32 = create<I32>();
auto* i32 = ty.i32();
auto* p = create<Atomic>(i32);
EXPECT_EQ(p->FriendlyName(Symbols()), "atomic<i32>");
}

View File

@ -26,7 +26,8 @@ TEST_F(BitcastExpressionTest, Create) {
auto* expr = Expr("expr");
auto* exp = create<BitcastExpression>(ty.f32(), expr);
EXPECT_TRUE(exp->type->Is<ast::F32>());
ASSERT_TRUE(exp->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(exp->type->As<ast::TypeName>()->name->symbol), "f32");
ASSERT_EQ(exp->expr, expr);
}

View File

@ -1,38 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/bool.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::Bool);
namespace tint::ast {
Bool::Bool(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {}
Bool::Bool(Bool&&) = default;
Bool::~Bool() = default;
std::string Bool::FriendlyName(const SymbolTable&) const {
return "bool";
}
const Bool* Bool::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
return ctx->dst->create<Bool>(src);
}
} // namespace tint::ast

View File

@ -1,55 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_AST_BOOL_H_
#define SRC_TINT_AST_BOOL_H_
#include <string>
#include "src/tint/ast/type.h"
// X11 likes to #define Bool leading to confusing error messages.
// If its defined, undefine it.
#ifdef Bool
#undef Bool
#endif
namespace tint::ast {
/// A boolean type
class Bool final : public Castable<Bool, Type> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param nid the unique node identifier
/// @param src the source of this node
Bool(ProgramID pid, NodeID nid, const Source& src);
/// Move constructor
Bool(Bool&&);
~Bool() override;
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
std::string FriendlyName(const SymbolTable& symbols) const override;
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
const Bool* Clone(CloneContext* ctx) const override;
};
} // namespace tint::ast
#endif // SRC_TINT_AST_BOOL_H_

View File

@ -1,30 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/bool.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
namespace {
using AstBoolTest = TestHelper;
TEST_F(AstBoolTest, FriendlyName) {
auto* b = create<Bool>();
EXPECT_EQ(b->FriendlyName(Symbols()), "bool");
}
} // namespace
} // namespace tint::ast

View File

@ -1,38 +0,0 @@
// Copyright 2022 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/f16.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::F16);
namespace tint::ast {
F16::F16(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {}
F16::F16(F16&&) = default;
F16::~F16() = default;
std::string F16::FriendlyName(const SymbolTable&) const {
return "f16";
}
const F16* F16::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
return ctx->dst->create<F16>(src);
}
} // namespace tint::ast

View File

@ -1,49 +0,0 @@
// Copyright 2022 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_AST_F16_H_
#define SRC_TINT_AST_F16_H_
#include <string>
#include "src/tint/ast/type.h"
namespace tint::ast {
/// A float 16 type
class F16 final : public Castable<F16, Type> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param nid the unique node identifier
/// @param src the source of this node
F16(ProgramID pid, NodeID nid, const Source& src);
/// Move constructor
F16(F16&&);
~F16() override;
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
std::string FriendlyName(const SymbolTable& symbols) const override;
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
const F16* Clone(CloneContext* ctx) const override;
};
} // namespace tint::ast
#endif // SRC_TINT_AST_F16_H_

View File

@ -1,30 +0,0 @@
// Copyright 2022 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/f16.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
namespace {
using AstF16Test = TestHelper;
TEST_F(AstF16Test, FriendlyName) {
auto* f = create<F16>();
EXPECT_EQ(f->FriendlyName(Symbols()), "f16");
}
} // namespace
} // namespace tint::ast

View File

@ -1,38 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/f32.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::F32);
namespace tint::ast {
F32::F32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {}
F32::F32(F32&&) = default;
F32::~F32() = default;
std::string F32::FriendlyName(const SymbolTable&) const {
return "f32";
}
const F32* F32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
return ctx->dst->create<F32>(src);
}
} // namespace tint::ast

View File

@ -1,49 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_AST_F32_H_
#define SRC_TINT_AST_F32_H_
#include <string>
#include "src/tint/ast/type.h"
namespace tint::ast {
/// A float 32 type
class F32 final : public Castable<F32, Type> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param nid the unique node identifier
/// @param src the source of this node
F32(ProgramID pid, NodeID nid, const Source& src);
/// Move constructor
F32(F32&&);
~F32() override;
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
std::string FriendlyName(const SymbolTable& symbols) const override;
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
const F32* Clone(CloneContext* ctx) const override;
};
} // namespace tint::ast
#endif // SRC_TINT_AST_F32_H_

View File

@ -1,30 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/f32.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
namespace {
using AstF32Test = TestHelper;
TEST_F(AstF32Test, FriendlyName) {
auto* f = create<F32>();
EXPECT_EQ(f->FriendlyName(Symbols()), "f32");
}
} // namespace
} // namespace tint::ast

View File

@ -1,38 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/i32.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::I32);
namespace tint::ast {
I32::I32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {}
I32::I32(I32&&) = default;
I32::~I32() = default;
std::string I32::FriendlyName(const SymbolTable&) const {
return "i32";
}
const I32* I32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
return ctx->dst->create<I32>(src);
}
} // namespace tint::ast

View File

@ -1,49 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_AST_I32_H_
#define SRC_TINT_AST_I32_H_
#include <string>
#include "src/tint/ast/type.h"
namespace tint::ast {
/// A signed int 32 type.
class I32 final : public Castable<I32, Type> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param nid the unique node identifier
/// @param src the source of this node
I32(ProgramID pid, NodeID nid, const Source& src);
/// Move constructor
I32(I32&&);
~I32() override;
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
std::string FriendlyName(const SymbolTable& symbols) const override;
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
const I32* Clone(CloneContext* ctx) const override;
};
} // namespace tint::ast
#endif // SRC_TINT_AST_I32_H_

View File

@ -1,30 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/i32.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
namespace {
using AstI32Test = TestHelper;
TEST_F(AstI32Test, FriendlyName) {
auto* i = create<I32>();
EXPECT_EQ(i->FriendlyName(Symbols()), "i32");
}
} // namespace
} // namespace tint::ast

View File

@ -15,15 +15,11 @@
#include "src/tint/ast/matrix.h"
#include "src/tint/ast/alias.h"
#include "src/tint/ast/array.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/pointer.h"
#include "src/tint/ast/sampler.h"
#include "src/tint/ast/struct.h"
#include "src/tint/ast/test_helper.h"
#include "src/tint/ast/texture.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/vector.h"
#include "src/tint/type/access.h"
@ -33,16 +29,15 @@ namespace {
using AstMatrixTest = TestHelper;
TEST_F(AstMatrixTest, Creation) {
auto* i32 = create<I32>();
auto* m = create<Matrix>(i32, 2u, 4u);
EXPECT_EQ(m->type, i32);
auto* m = create<Matrix>(ty.i32(), 2u, 4u);
ASSERT_TRUE(m->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(m->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(m->rows, 2u);
EXPECT_EQ(m->columns, 4u);
}
TEST_F(AstMatrixTest, FriendlyName) {
auto* i32 = create<I32>();
auto* m = create<Matrix>(i32, 3u, 2u);
auto* m = create<Matrix>(ty.i32(), 3u, 2u);
EXPECT_EQ(m->FriendlyName(Symbols()), "mat2x3<i32>");
}

View File

@ -16,10 +16,7 @@
#include "src/tint/ast/alias.h"
#include "src/tint/ast/array.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/depth_texture.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/matrix.h"
#include "src/tint/ast/pointer.h"
#include "src/tint/ast/sampled_texture.h"
@ -28,7 +25,6 @@
#include "src/tint/ast/struct.h"
#include "src/tint/ast/test_helper.h"
#include "src/tint/ast/texture.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/vector.h"
#include "src/tint/type/access.h"
@ -38,29 +34,26 @@ namespace {
using AstMultisampledTextureTest = TestHelper;
TEST_F(AstMultisampledTextureTest, IsTexture) {
auto* f32 = create<F32>();
Texture* ty = create<MultisampledTexture>(type::TextureDimension::kCube, f32);
EXPECT_FALSE(ty->Is<DepthTexture>());
EXPECT_TRUE(ty->Is<MultisampledTexture>());
EXPECT_FALSE(ty->Is<SampledTexture>());
EXPECT_FALSE(ty->Is<StorageTexture>());
Texture* t = create<MultisampledTexture>(type::TextureDimension::kCube, ty.f32());
EXPECT_FALSE(t->Is<DepthTexture>());
EXPECT_TRUE(t->Is<MultisampledTexture>());
EXPECT_FALSE(t->Is<SampledTexture>());
EXPECT_FALSE(t->Is<StorageTexture>());
}
TEST_F(AstMultisampledTextureTest, Dim) {
auto* f32 = create<F32>();
auto* s = create<MultisampledTexture>(type::TextureDimension::k3d, f32);
auto* s = create<MultisampledTexture>(type::TextureDimension::k3d, ty.f32());
EXPECT_EQ(s->dim, type::TextureDimension::k3d);
}
TEST_F(AstMultisampledTextureTest, Type) {
auto* f32 = create<F32>();
auto* s = create<MultisampledTexture>(type::TextureDimension::k3d, f32);
EXPECT_EQ(s->type, f32);
auto* s = create<MultisampledTexture>(type::TextureDimension::k3d, ty.f32());
ASSERT_TRUE(s->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(s->type->As<ast::TypeName>()->name->symbol), "f32");
}
TEST_F(AstMultisampledTextureTest, FriendlyName) {
auto* f32 = create<F32>();
auto* s = create<MultisampledTexture>(type::TextureDimension::k3d, f32);
auto* s = create<MultisampledTexture>(type::TextureDimension::k3d, ty.f32());
EXPECT_EQ(s->FriendlyName(Symbols()), "texture_multisampled_3d<f32>");
}

View File

@ -14,7 +14,6 @@
#include "src/tint/ast/pointer.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
@ -23,22 +22,20 @@ namespace {
using AstPointerTest = TestHelper;
TEST_F(AstPointerTest, Creation) {
auto* i32 = create<I32>();
auto* p = create<Pointer>(i32, type::AddressSpace::kStorage, type::Access::kRead);
EXPECT_EQ(p->type, i32);
auto* p = create<Pointer>(ty.i32(), type::AddressSpace::kStorage, type::Access::kRead);
ASSERT_TRUE(p->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(p->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(p->address_space, type::AddressSpace::kStorage);
EXPECT_EQ(p->access, type::Access::kRead);
}
TEST_F(AstPointerTest, FriendlyName) {
auto* i32 = create<I32>();
auto* p = create<Pointer>(i32, type::AddressSpace::kWorkgroup, type::Access::kUndefined);
auto* p = create<Pointer>(ty.i32(), type::AddressSpace::kWorkgroup, type::Access::kUndefined);
EXPECT_EQ(p->FriendlyName(Symbols()), "ptr<workgroup, i32>");
}
TEST_F(AstPointerTest, FriendlyNameWithAccess) {
auto* i32 = create<I32>();
auto* p = create<Pointer>(i32, type::AddressSpace::kStorage, type::Access::kReadWrite);
auto* p = create<Pointer>(ty.i32(), type::AddressSpace::kStorage, type::Access::kReadWrite);
EXPECT_EQ(p->FriendlyName(Symbols()), "ptr<storage, i32, read_write>");
}

View File

@ -14,7 +14,6 @@
#include "src/tint/ast/sampled_texture.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
@ -23,28 +22,25 @@ namespace {
using AstSampledTextureTest = TestHelper;
TEST_F(AstSampledTextureTest, IsTexture) {
auto* f32 = create<F32>();
Texture* ty = create<SampledTexture>(type::TextureDimension::kCube, f32);
EXPECT_FALSE(ty->Is<DepthTexture>());
EXPECT_TRUE(ty->Is<SampledTexture>());
EXPECT_FALSE(ty->Is<StorageTexture>());
Texture* t = create<SampledTexture>(type::TextureDimension::kCube, ty.f32());
EXPECT_FALSE(t->Is<DepthTexture>());
EXPECT_TRUE(t->Is<SampledTexture>());
EXPECT_FALSE(t->Is<StorageTexture>());
}
TEST_F(AstSampledTextureTest, Dim) {
auto* f32 = create<F32>();
auto* s = create<SampledTexture>(type::TextureDimension::k3d, f32);
auto* s = create<SampledTexture>(type::TextureDimension::k3d, ty.f32());
EXPECT_EQ(s->dim, type::TextureDimension::k3d);
}
TEST_F(AstSampledTextureTest, Type) {
auto* f32 = create<F32>();
auto* s = create<SampledTexture>(type::TextureDimension::k3d, f32);
EXPECT_EQ(s->type, f32);
auto* s = create<SampledTexture>(type::TextureDimension::k3d, ty.f32());
ASSERT_TRUE(s->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(s->type->As<ast::TypeName>()->name->symbol), "f32");
}
TEST_F(AstSampledTextureTest, FriendlyName) {
auto* f32 = create<F32>();
auto* s = create<SampledTexture>(type::TextureDimension::k3d, f32);
auto* s = create<SampledTexture>(type::TextureDimension::k3d, ty.f32());
EXPECT_EQ(s->FriendlyName(Symbols()), "texture_3d<f32>");
}

View File

@ -14,9 +14,6 @@
#include "src/tint/ast/storage_texture.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/u32.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::StorageTexture);
@ -49,14 +46,14 @@ const StorageTexture* StorageTexture::Clone(CloneContext* ctx) const {
return ctx->dst->create<StorageTexture>(src, dim, format, ty, access);
}
Type* StorageTexture::SubtypeFor(type::TexelFormat format, ProgramBuilder& builder) {
const Type* StorageTexture::SubtypeFor(type::TexelFormat format, ProgramBuilder& builder) {
switch (format) {
case type::TexelFormat::kR32Uint:
case type::TexelFormat::kRgba8Uint:
case type::TexelFormat::kRg32Uint:
case type::TexelFormat::kRgba16Uint:
case type::TexelFormat::kRgba32Uint: {
return builder.create<U32>();
return builder.ty.u32();
}
case type::TexelFormat::kR32Sint:
@ -64,7 +61,7 @@ Type* StorageTexture::SubtypeFor(type::TexelFormat format, ProgramBuilder& build
case type::TexelFormat::kRg32Sint:
case type::TexelFormat::kRgba16Sint:
case type::TexelFormat::kRgba32Sint: {
return builder.create<I32>();
return builder.ty.i32();
}
case type::TexelFormat::kBgra8Unorm:
@ -74,7 +71,7 @@ Type* StorageTexture::SubtypeFor(type::TexelFormat format, ProgramBuilder& build
case type::TexelFormat::kRg32Float:
case type::TexelFormat::kRgba16Float:
case type::TexelFormat::kRgba32Float: {
return builder.create<F32>();
return builder.ty.f32();
}
case type::TexelFormat::kUndefined:

View File

@ -59,8 +59,8 @@ class StorageTexture final : public Castable<StorageTexture, Texture> {
/// @param format the storage texture image format
/// @param builder the ProgramBuilder used to build the returned type
/// @returns the storage texture subtype for the given type::TexelFormat
static Type* SubtypeFor(type::TexelFormat format, ProgramBuilder& builder);
/// @returns the storage texture subtype for the given TexelFormat
static const Type* SubtypeFor(type::TexelFormat format, ProgramBuilder& builder);
/// The image format
const type::TexelFormat format;

View File

@ -59,7 +59,9 @@ TEST_F(AstStorageTextureTest, F32) {
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE(s->As<StorageTexture>()->type->Is<F32>());
ASSERT_TRUE(s->As<StorageTexture>()->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(s->As<StorageTexture>()->type->As<ast::TypeName>()->name->symbol),
"f32");
}
TEST_F(AstStorageTextureTest, U32) {
@ -69,7 +71,9 @@ TEST_F(AstStorageTextureTest, U32) {
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE(s->As<StorageTexture>()->type->Is<U32>());
ASSERT_TRUE(s->As<StorageTexture>()->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(s->As<StorageTexture>()->type->As<ast::TypeName>()->name->symbol),
"u32");
}
TEST_F(AstStorageTextureTest, I32) {
@ -79,7 +83,9 @@ TEST_F(AstStorageTextureTest, I32) {
ASSERT_TRUE(s->Is<Texture>());
ASSERT_TRUE(s->Is<StorageTexture>());
EXPECT_TRUE(s->As<StorageTexture>()->type->Is<I32>());
ASSERT_TRUE(s->As<StorageTexture>()->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(s->As<StorageTexture>()->type->As<ast::TypeName>()->name->symbol),
"i32");
}
} // namespace

View File

@ -23,8 +23,9 @@ using StructMemberTest = TestHelper;
TEST_F(StructMemberTest, Creation) {
auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)});
EXPECT_EQ(st->name->symbol, Symbol(1, ID()));
EXPECT_TRUE(st->type->Is<ast::I32>());
EXPECT_EQ(Symbols().NameFor(st->name->symbol), "a");
ASSERT_TRUE(st->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(st->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(st->attributes.Length(), 1u);
EXPECT_TRUE(st->attributes[0]->Is<StructMemberSizeAttribute>());
EXPECT_EQ(st->source.range.begin.line, 0u);
@ -36,8 +37,9 @@ TEST_F(StructMemberTest, Creation) {
TEST_F(StructMemberTest, CreationWithSource) {
auto* st = Member(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, "a",
ty.i32());
EXPECT_EQ(st->name->symbol, Symbol(1, ID()));
EXPECT_TRUE(st->type->Is<ast::I32>());
EXPECT_EQ(Symbols().NameFor(st->name->symbol), "a");
ASSERT_TRUE(st->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(st->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(st->attributes.Length(), 0u);
EXPECT_EQ(st->source.range.begin.line, 27u);
EXPECT_EQ(st->source.range.begin.column, 4u);

View File

@ -16,15 +16,11 @@
#include "gtest/gtest-spi.h"
#include "src/tint/ast/alias.h"
#include "src/tint/ast/array.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/matrix.h"
#include "src/tint/ast/pointer.h"
#include "src/tint/ast/sampler.h"
#include "src/tint/ast/test_helper.h"
#include "src/tint/ast/texture.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/vector.h"
#include "src/tint/transform/add_block_attribute.h"

View File

@ -16,15 +16,11 @@
#include "src/tint/ast/alias.h"
#include "src/tint/ast/array.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/matrix.h"
#include "src/tint/ast/pointer.h"
#include "src/tint/ast/sampler.h"
#include "src/tint/ast/struct.h"
#include "src/tint/ast/test_helper.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/vector.h"
namespace tint::ast {

View File

@ -15,14 +15,10 @@
#include "src/tint/ast/type.h"
#include "src/tint/ast/alias.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/matrix.h"
#include "src/tint/ast/pointer.h"
#include "src/tint/ast/sampler.h"
#include "src/tint/ast/texture.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/vector.h"
#include "src/tint/symbol_table.h"

View File

@ -1,38 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/u32.h"
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::U32);
namespace tint::ast {
U32::U32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {}
U32::~U32() = default;
U32::U32(U32&&) = default;
std::string U32::FriendlyName(const SymbolTable&) const {
return "u32";
}
const U32* U32::Clone(CloneContext* ctx) const {
auto src = ctx->Clone(source);
return ctx->dst->create<U32>(src);
}
} // namespace tint::ast

View File

@ -1,49 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_AST_U32_H_
#define SRC_TINT_AST_U32_H_
#include <string>
#include "src/tint/ast/type.h"
namespace tint::ast {
/// A unsigned int 32 type.
class U32 final : public Castable<U32, Type> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param nid the unique node identifier
/// @param src the source of this node
U32(ProgramID pid, NodeID nid, const Source& src);
/// Move constructor
U32(U32&&);
~U32() override;
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
std::string FriendlyName(const SymbolTable& symbols) const override;
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
/// @param ctx the clone context
/// @return the newly cloned type
const U32* Clone(CloneContext* ctx) const override;
};
} // namespace tint::ast
#endif // SRC_TINT_AST_U32_H_

View File

@ -1,30 +0,0 @@
// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/ast/u32.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
namespace {
using AstU32Test = TestHelper;
TEST_F(AstU32Test, FriendlyName) {
auto* u = create<U32>();
EXPECT_EQ(u->FriendlyName(Symbols()), "u32");
}
} // namespace
} // namespace tint::ast

View File

@ -27,9 +27,10 @@ using VariableTest = TestHelper;
TEST_F(VariableTest, Creation) {
auto* v = Var("my_var", ty.i32(), type::AddressSpace::kFunction);
EXPECT_EQ(v->name->symbol, Symbol(1, ID()));
EXPECT_EQ(Symbols().NameFor(v->name->symbol), "my_var");
EXPECT_EQ(v->declared_address_space, type::AddressSpace::kFunction);
EXPECT_TRUE(v->type->Is<ast::I32>());
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(v->source.range.begin.line, 0u);
EXPECT_EQ(v->source.range.begin.column, 0u);
EXPECT_EQ(v->source.range.end.line, 0u);
@ -40,9 +41,10 @@ TEST_F(VariableTest, CreationWithSource) {
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i",
ty.f32(), type::AddressSpace::kPrivate, utils::Empty);
EXPECT_EQ(v->name->symbol, Symbol(1, ID()));
EXPECT_EQ(Symbols().NameFor(v->name->symbol), "i");
EXPECT_EQ(v->declared_address_space, type::AddressSpace::kPrivate);
EXPECT_TRUE(v->type->Is<ast::F32>());
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(v->source.range.begin.line, 27u);
EXPECT_EQ(v->source.range.begin.column, 4u);
EXPECT_EQ(v->source.range.end.line, 27u);
@ -53,9 +55,10 @@ TEST_F(VariableTest, CreationEmpty) {
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var",
ty.i32(), type::AddressSpace::kWorkgroup, utils::Empty);
EXPECT_EQ(v->name->symbol, Symbol(1, ID()));
EXPECT_EQ(Symbols().NameFor(v->name->symbol), "a_var");
EXPECT_EQ(v->declared_address_space, type::AddressSpace::kWorkgroup);
EXPECT_TRUE(v->type->Is<ast::I32>());
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(v->source.range.begin.line, 27u);
EXPECT_EQ(v->source.range.begin.column, 4u);
EXPECT_EQ(v->source.range.end.line, 27u);

View File

@ -14,7 +14,6 @@
#include "src/tint/ast/vector.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/test_helper.h"
namespace tint::ast {
@ -23,15 +22,14 @@ namespace {
using AstVectorTest = TestHelper;
TEST_F(AstVectorTest, Creation) {
auto* i32 = create<I32>();
auto* v = create<Vector>(i32, 2u);
EXPECT_EQ(v->type, i32);
auto* v = create<Vector>(ty.i32(), 2u);
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(v->width, 2u);
}
TEST_F(AstVectorTest, FriendlyName) {
auto* f32 = create<F32>();
auto* v = create<Vector>(f32, 3u);
auto* v = create<Vector>(ty.f32(), 3u);
EXPECT_EQ(v->FriendlyName(Symbols()), "vec3<f32>");
}

View File

@ -129,6 +129,12 @@ enum interpolation_sampling {
}
enum builtin_type {
// https://www.w3.org/TR/WGSL/#scalar-types
bool
f16
f32
i32
u32
// https://www.w3.org/TR/WGSL/#matrix-types
mat2x2f
mat2x2h

View File

@ -28,7 +28,6 @@
#include "src/tint/ast/binary_expression.h"
#include "src/tint/ast/binding_attribute.h"
#include "src/tint/ast/bitcast_expression.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/bool_literal_expression.h"
#include "src/tint/ast/break_if_statement.h"
#include "src/tint/ast/break_statement.h"
@ -49,11 +48,8 @@
#include "src/tint/ast/enable.h"
#include "src/tint/ast/extension.h"
#include "src/tint/ast/external_texture.h"
#include "src/tint/ast/f16.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/float_literal_expression.h"
#include "src/tint/ast/for_loop_statement.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/id_attribute.h"
#include "src/tint/ast/identifier.h"
#include "src/tint/ast/if_statement.h"
@ -84,7 +80,6 @@
#include "src/tint/ast/switch_statement.h"
#include "src/tint/ast/templated_identifier.h"
#include "src/tint/ast/type_name.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/unary_op_expression.h"
#include "src/tint/ast/var.h"
#include "src/tint/ast/variable_decl_statement.h"
@ -569,50 +564,40 @@ class ProgramBuilder {
/// @returns nullptr ast::Type
const ast::Type* void_() const { return nullptr; }
/// @returns a boolean type
const ast::Bool* bool_() const { return builder->create<ast::Bool>(); }
/// @returns a 'bool' typename
const ast::TypeName* bool_() const { return (*this)("bool"); }
/// @param source the Source of the node
/// @returns a boolean type
const ast::Bool* bool_(const Source& source) const {
return builder->create<ast::Bool>(source);
}
/// @returns a 'bool' typename
const ast::TypeName* bool_(const Source& source) const { return (*this)(source, "bool"); }
/// @returns a f16 type
const ast::F16* f16() const { return builder->create<ast::F16>(); }
/// @returns a 'f16' typename
const ast::TypeName* f16() const { return (*this)("f16"); }
/// @param source the Source of the node
/// @returns a f16 type
const ast::F16* f16(const Source& source) const {
return builder->create<ast::F16>(source);
}
/// @returns a 'f16' typename
const ast::TypeName* f16(const Source& source) const { return (*this)(source, "f16"); }
/// @returns a f32 type
const ast::F32* f32() const { return builder->create<ast::F32>(); }
/// @returns a 'f32' typename
const ast::TypeName* f32() const { return (*this)("f32"); }
/// @param source the Source of the node
/// @returns a f32 type
const ast::F32* f32(const Source& source) const {
return builder->create<ast::F32>(source);
}
/// @returns a 'f32' typename
const ast::TypeName* f32(const Source& source) const { return (*this)(source, "f32"); }
/// @returns a i32 type
const ast::I32* i32() const { return builder->create<ast::I32>(); }
/// @returns a 'i32' typename
const ast::TypeName* i32() const { return (*this)("i32"); }
/// @param source the Source of the node
/// @returns a i32 type
const ast::I32* i32(const Source& source) const {
return builder->create<ast::I32>(source);
}
/// @returns a 'i32' typename
const ast::TypeName* i32(const Source& source) const { return (*this)(source, "i32"); }
/// @returns a u32 type
const ast::U32* u32() const { return builder->create<ast::U32>(); }
/// @returns a 'u32' typename
const ast::TypeName* u32() const { return (*this)("u32"); }
/// @param source the Source of the node
/// @returns a u32 type
const ast::U32* u32(const Source& source) const {
return builder->create<ast::U32>(source);
}
/// @returns a 'u32' typename
const ast::TypeName* u32(const Source& source) const { return (*this)(source, "u32"); }
/// @param type vector subtype
/// @param n vector width in elements

View File

@ -64,17 +64,6 @@ TEST_F(ParserImplTest, Callable_MatPrefix) {
EXPECT_EQ(m->rows, 2u);
}
TEST_F(ParserImplTest, Callable_TypeDecl_F32) {
auto p = parser("f32");
auto t = p->callable();
ASSERT_TRUE(p->peek_is(Token::Type::kEOF));
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t.value->Is<ast::F32>());
}
TEST_F(ParserImplTest, Callable_TypeDecl_Array) {
auto p = parser("array<f32, 2>");
auto t = p->callable();
@ -87,7 +76,9 @@ TEST_F(ParserImplTest, Callable_TypeDecl_Array) {
auto* a = t.value->As<ast::Array>();
EXPECT_FALSE(a->IsRuntimeArray());
EXPECT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
auto* size = a->count->As<ast::IntLiteralExpression>();
ASSERT_NE(size, nullptr);
@ -107,7 +98,9 @@ TEST_F(ParserImplTest, Callable_TypeDecl_Array_Runtime) {
auto* a = t.value->As<ast::Array>();
EXPECT_TRUE(a->IsRuntimeArray());
EXPECT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
ASSERT_EQ(a->count, nullptr);
}
@ -123,7 +116,10 @@ TEST_F(ParserImplTest, Callable_TypeDecl_VecPrefix) {
ASSERT_TRUE(t.value->Is<ast::Vector>());
auto* v = t.value->As<ast::Vector>();
EXPECT_TRUE(v->type->Is<ast::F32>());
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(v->width, 3u);
}
@ -138,7 +134,10 @@ TEST_F(ParserImplTest, Callable_TypeDecl_MatPrefix) {
ASSERT_TRUE(t.value->Is<ast::Matrix>());
auto* m = t.value->As<ast::Matrix>();
EXPECT_TRUE(m->type->Is<ast::F32>());
ASSERT_TRUE(m->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(m->columns, 3u);
EXPECT_EQ(m->rows, 2u);
}

View File

@ -239,7 +239,11 @@ TEST_F(ParserImplTest, FunctionDecl_ReturnTypeAttributeList) {
EXPECT_EQ(f->name->symbol, p->builder().Symbols().Get("main"));
ASSERT_NE(f->return_type, nullptr);
EXPECT_TRUE(f->return_type->Is<ast::F32>());
ASSERT_TRUE(f->return_type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As<ast::TypeName>()->name->symbol),
"f32");
ASSERT_EQ(f->params.Length(), 0u);
auto& attributes = f->attributes;

View File

@ -52,7 +52,9 @@ TEST_F(ParserImplTest, FunctionHeader_AttributeReturnType) {
EXPECT_EQ(f->name, "main");
EXPECT_EQ(f->params.Length(), 0u);
EXPECT_TRUE(f->return_type->Is<ast::F32>());
ASSERT_TRUE(f->return_type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As<ast::TypeName>()->name->symbol),
"f32");
ASSERT_EQ(f->return_type_attributes.Length(), 1u);
auto* loc = f->return_type_attributes[0]->As<ast::LocationAttribute>();
@ -71,7 +73,9 @@ TEST_F(ParserImplTest, FunctionHeader_InvariantReturnType) {
EXPECT_EQ(f->name, "main");
EXPECT_EQ(f->params.Length(), 0u);
EXPECT_TRUE(f->return_type->Is<ast::F32>());
ASSERT_TRUE(f->return_type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As<ast::TypeName>()->name->symbol),
"f32");
ASSERT_EQ(f->return_type_attributes.Length(), 1u);
EXPECT_TRUE(f->return_type_attributes[0]->Is<ast::InvariantAttribute>());
}

View File

@ -44,7 +44,8 @@ TEST_F(ParserImplTest, GlobalConstDecl) {
EXPECT_EQ(c->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(c->type, nullptr);
EXPECT_TRUE(c->type->Is<ast::F32>());
ASSERT_TRUE(c->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(c->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(c->source.range.begin.line, 1u);
EXPECT_EQ(c->source.range.begin.column, 7u);
@ -120,7 +121,9 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId) {
EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(override->type, nullptr);
EXPECT_TRUE(override->type->Is<ast::F32>());
ASSERT_TRUE(override->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(override->source.range.begin.line, 1u);
EXPECT_EQ(override->source.range.begin.column, 17u);
@ -150,7 +153,9 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId_TrailingComma) {
EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(override->type, nullptr);
EXPECT_TRUE(override->type->Is<ast::F32>());
ASSERT_TRUE(override->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(override->source.range.begin.line, 1u);
EXPECT_EQ(override->source.range.begin.column, 18u);
@ -180,7 +185,9 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithoutId) {
EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(override->type, nullptr);
EXPECT_TRUE(override->type->Is<ast::F32>());
ASSERT_TRUE(override->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(override->source.range.begin.line, 1u);
EXPECT_EQ(override->source.range.begin.column, 10u);

View File

@ -30,7 +30,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutInitializer) {
ASSERT_NE(var, nullptr);
EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a"));
EXPECT_TRUE(var->type->Is<ast::F32>());
ASSERT_TRUE(var->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(var->declared_address_space, type::AddressSpace::kPrivate);
EXPECT_EQ(var->source.range.begin.line, 1u);
@ -54,7 +57,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithInitializer) {
ASSERT_NE(var, nullptr);
EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a"));
EXPECT_TRUE(var->type->Is<ast::F32>());
ASSERT_TRUE(var->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(var->declared_address_space, type::AddressSpace::kPrivate);
EXPECT_EQ(var->source.range.begin.line, 1u);
@ -80,7 +86,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute) {
EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(var->type, nullptr);
EXPECT_TRUE(var->type->Is<ast::F32>());
ASSERT_TRUE(var->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(var->declared_address_space, type::AddressSpace::kUniform);
EXPECT_EQ(var->source.range.begin.line, 1u);
@ -111,7 +120,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute_MulitpleGroups) {
EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(var->type, nullptr);
EXPECT_TRUE(var->type->Is<ast::F32>());
ASSERT_TRUE(var->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(var->declared_address_space, type::AddressSpace::kUniform);
EXPECT_EQ(var->source.range.begin.line, 1u);

View File

@ -26,7 +26,9 @@ TEST_F(ParserImplTest, ParamList_Single) {
EXPECT_EQ(e.value.Length(), 1u);
EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a"));
EXPECT_TRUE(e.value[0]->type->Is<ast::I32>());
ASSERT_TRUE(e.value[0]->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(e.value[0]->type->As<ast::TypeName>()->name->symbol),
"i32");
EXPECT_TRUE(e.value[0]->Is<ast::Parameter>());
ASSERT_EQ(e.value[0]->source.range.begin.line, 1u);
@ -44,7 +46,9 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
EXPECT_EQ(e.value.Length(), 3u);
EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a"));
EXPECT_TRUE(e.value[0]->type->Is<ast::I32>());
ASSERT_TRUE(e.value[0]->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(e.value[0]->type->As<ast::TypeName>()->name->symbol),
"i32");
EXPECT_TRUE(e.value[0]->Is<ast::Parameter>());
ASSERT_EQ(e.value[0]->source.range.begin.line, 1u);
@ -53,7 +57,9 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
ASSERT_EQ(e.value[0]->source.range.end.column, 2u);
EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("b"));
EXPECT_TRUE(e.value[1]->type->Is<ast::F32>());
ASSERT_TRUE(e.value[1]->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(e.value[1]->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_TRUE(e.value[1]->Is<ast::Parameter>());
ASSERT_EQ(e.value[1]->source.range.begin.line, 1u);
@ -63,7 +69,10 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
EXPECT_EQ(e.value[2]->name->symbol, p->builder().Symbols().Get("c"));
ASSERT_TRUE(e.value[2]->type->Is<ast::Vector>());
ASSERT_TRUE(e.value[2]->type->As<ast::Vector>()->type->Is<ast::F32>());
ASSERT_TRUE(e.value[2]->type->As<ast::Vector>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
e.value[2]->type->As<ast::Vector>()->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(e.value[2]->type->As<ast::Vector>()->width, 2u);
EXPECT_TRUE(e.value[2]->Is<ast::Parameter>());
@ -99,7 +108,10 @@ TEST_F(ParserImplTest, ParamList_Attributes) {
EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("coord"));
ASSERT_TRUE(e.value[0]->type->Is<ast::Vector>());
EXPECT_TRUE(e.value[0]->type->As<ast::Vector>()->type->Is<ast::F32>());
ASSERT_TRUE(e.value[0]->type->As<ast::Vector>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
e.value[0]->type->As<ast::Vector>()->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(e.value[0]->type->As<ast::Vector>()->width, 4u);
EXPECT_TRUE(e.value[0]->Is<ast::Parameter>());
auto attrs_0 = e.value[0]->attributes;
@ -113,7 +125,9 @@ TEST_F(ParserImplTest, ParamList_Attributes) {
ASSERT_EQ(e.value[0]->source.range.end.column, 25u);
EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("loc1"));
EXPECT_TRUE(e.value[1]->type->Is<ast::F32>());
ASSERT_TRUE(e.value[1]->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(e.value[1]->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_TRUE(e.value[1]->Is<ast::Parameter>());
auto attrs_1 = e.value[1]->attributes;
ASSERT_EQ(attrs_1.Length(), 1u);

View File

@ -238,9 +238,11 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
ASSERT_TRUE(e->Is<ast::CallExpression>());
auto* call = e->As<ast::CallExpression>();
ASSERT_TRUE(call->target.type->Is<ast::F32>());
ASSERT_EQ(call->args.Length(), 1u);
auto* type_name = As<ast::TypeName>(call->target.type);
ASSERT_NE(type_name, nullptr);
EXPECT_EQ(p->builder().Symbols().NameFor(type_name->name->symbol), "f32");
ASSERT_EQ(call->args.Length(), 1u);
ASSERT_TRUE(call->args[0]->Is<ast::IntLiteralExpression>());
}
@ -255,7 +257,10 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
ASSERT_TRUE(e->Is<ast::BitcastExpression>());
auto* c = e->As<ast::BitcastExpression>();
ASSERT_TRUE(c->type->Is<ast::F32>());
ASSERT_TRUE(c->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(c->type->As<ast::TypeName>()->name->symbol), "f32");
ASSERT_TRUE(c->expr->Is<ast::IntLiteralExpression>());
}

View File

@ -29,7 +29,8 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) {
const auto* mem = m.value[0];
EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a"));
EXPECT_TRUE(mem->type->Is<ast::I32>());
ASSERT_TRUE(mem->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(mem->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(mem->attributes.Length(), 0u);
}
@ -45,7 +46,8 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses_TrailingComma) {
const auto* mem = m.value[0];
EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a"));
EXPECT_TRUE(mem->type->Is<ast::I32>());
ASSERT_TRUE(mem->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(mem->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(mem->attributes.Length(), 0u);
}

View File

@ -28,7 +28,8 @@ TEST_F(ParserImplTest, StructMember_Parses) {
ASSERT_NE(m.value, nullptr);
EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a"));
EXPECT_TRUE(m->type->Is<ast::I32>());
ASSERT_TRUE(m->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(m->attributes.Length(), 0u);
EXPECT_EQ(m->source.range, (Source::Range{{1u, 1u}, {1u, 2u}}));
@ -46,7 +47,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithAlignAttribute) {
ASSERT_NE(m.value, nullptr);
EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a"));
EXPECT_TRUE(m->type->Is<ast::I32>());
ASSERT_TRUE(m->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(m->attributes.Length(), 1u);
EXPECT_TRUE(m->attributes[0]->Is<ast::StructMemberAlignAttribute>());
@ -71,7 +73,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithSizeAttribute) {
ASSERT_NE(m.value, nullptr);
EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a"));
EXPECT_TRUE(m->type->Is<ast::I32>());
ASSERT_TRUE(m->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(m->attributes.Length(), 1u);
ASSERT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>());
auto* s = m->attributes[0]->As<ast::StructMemberSizeAttribute>();
@ -95,7 +98,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleattributes) {
ASSERT_NE(m.value, nullptr);
EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a"));
EXPECT_TRUE(m->type->Is<ast::I32>());
ASSERT_TRUE(m->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(m->attributes.Length(), 2u);
ASSERT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>());
auto* size_attr = m->attributes[0]->As<ast::StructMemberSizeAttribute>();

View File

@ -26,7 +26,7 @@
namespace tint::reader::wgsl {
/// WGSL Parser test class
class ParserImplTest : public testing::Test, public ProgramBuilder {
class ParserImplTest : public testing::Test {
public:
/// Constructor
ParserImplTest();

View File

@ -74,9 +74,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::Texture>());
ASSERT_TRUE(t->Is<ast::SampledTexture>());
ASSERT_TRUE(t->As<ast::SampledTexture>()->type->Is<ast::F32>());
ASSERT_TRUE(t->As<ast::SampledTexture>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
t->As<ast::SampledTexture>()->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(t->As<ast::Texture>()->dim, type::TextureDimension::k1d);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}}));
}
@ -88,9 +90,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::Texture>());
ASSERT_TRUE(t->Is<ast::SampledTexture>());
ASSERT_TRUE(t->As<ast::SampledTexture>()->type->Is<ast::I32>());
ASSERT_TRUE(t->As<ast::SampledTexture>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
t->As<ast::SampledTexture>()->type->As<ast::TypeName>()->name->symbol),
"i32");
EXPECT_EQ(t->As<ast::Texture>()->dim, type::TextureDimension::k2d);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}}));
}
@ -102,9 +106,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::Texture>());
ASSERT_TRUE(t->Is<ast::SampledTexture>());
ASSERT_TRUE(t->As<ast::SampledTexture>()->type->Is<ast::U32>());
EXPECT_EQ(p->builder().Symbols().NameFor(
t->As<ast::SampledTexture>()->type->As<ast::TypeName>()->name->symbol),
"u32");
EXPECT_EQ(t->As<ast::Texture>()->dim, type::TextureDimension::k3d);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}}));
}
@ -146,9 +151,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::Texture>());
ASSERT_TRUE(t->Is<ast::MultisampledTexture>());
ASSERT_TRUE(t->As<ast::MultisampledTexture>()->type->Is<ast::I32>());
ASSERT_TRUE(t->As<ast::MultisampledTexture>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
t->As<ast::MultisampledTexture>()->type->As<ast::TypeName>()->name->symbol),
"i32");
EXPECT_EQ(t->As<ast::Texture>()->dim, type::TextureDimension::k2d);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 29u}}));
}

View File

@ -27,8 +27,9 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::Alias>());
auto* alias = t->As<ast::Alias>();
ASSERT_TRUE(alias->type->Is<ast::I32>());
ASSERT_TRUE(alias->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(alias->type->As<ast::TypeName>()->name->symbol),
"i32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 13u}}));
}
@ -62,7 +63,9 @@ TEST_F(ParserImplTest, TypeDecl_Unicode_Parses_Ident) {
ASSERT_TRUE(t.value->Is<ast::Alias>());
auto* alias = t.value->As<ast::Alias>();
EXPECT_EQ(p->builder().Symbols().NameFor(alias->name->symbol), ident);
EXPECT_TRUE(alias->type->Is<ast::I32>());
ASSERT_TRUE(alias->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(alias->type->As<ast::TypeName>()->name->symbol),
"i32");
EXPECT_EQ(alias->source.range, (Source::Range{{1u, 1u}, {1u, 37u}}));
}

View File

@ -51,7 +51,8 @@ TEST_F(ParserImplTest, TypeDecl_Bool) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::Bool>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "bool");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}}));
}
@ -62,7 +63,8 @@ TEST_F(ParserImplTest, TypeDecl_F16) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::F16>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "f16");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
}
@ -73,7 +75,8 @@ TEST_F(ParserImplTest, TypeDecl_F32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::F32>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
}
@ -84,7 +87,8 @@ TEST_F(ParserImplTest, TypeDecl_I32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::I32>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
}
@ -95,7 +99,8 @@ TEST_F(ParserImplTest, TypeDecl_U32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::U32>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "u32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
}
@ -175,7 +180,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr) {
ASSERT_TRUE(t.value->Is<ast::Pointer>());
auto* ptr = t.value->As<ast::Pointer>();
ASSERT_TRUE(ptr->type->Is<ast::F32>());
ASSERT_TRUE(ptr->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(ptr->type->As<ast::TypeName>()->name->symbol), "f32");
ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}}));
}
@ -190,7 +196,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_WithAccess) {
ASSERT_TRUE(t.value->Is<ast::Pointer>());
auto* ptr = t.value->As<ast::Pointer>();
ASSERT_TRUE(ptr->type->Is<ast::F32>());
ASSERT_TRUE(ptr->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(ptr->type->As<ast::TypeName>()->name->symbol), "f32");
ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction);
ASSERT_EQ(ptr->access, type::Access::kRead);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}}));
@ -211,7 +218,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) {
auto* vec = ptr->type->As<ast::Vector>();
ASSERT_EQ(vec->width, 2u);
ASSERT_TRUE(vec->type->Is<ast::F32>());
ASSERT_TRUE(vec->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(vec->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25}}));
}
@ -342,7 +350,9 @@ TEST_F(ParserImplTest, TypeDecl_Atomic) {
ASSERT_TRUE(t.value->Is<ast::Atomic>());
auto* atomic = t.value->As<ast::Atomic>();
ASSERT_TRUE(atomic->type->Is<ast::F32>());
ASSERT_TRUE(atomic->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(atomic->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}}));
}
@ -360,7 +370,8 @@ TEST_F(ParserImplTest, TypeDecl_Atomic_ToVec) {
auto* vec = atomic->type->As<ast::Vector>();
ASSERT_EQ(vec->width, 2u);
ASSERT_TRUE(vec->type->Is<ast::F32>());
ASSERT_TRUE(vec->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(vec->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}}));
}
@ -405,7 +416,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_AbstractIntLiteralSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}}));
@ -426,7 +438,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}}));
@ -447,7 +460,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}}));
@ -467,7 +481,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}}));
@ -487,7 +502,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_ExpressionSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
ASSERT_TRUE(a->count->Is<ast::BinaryExpression>());
@ -514,7 +530,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) {
auto* a = t.value->As<ast::Array>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::U32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "u32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}}));
}
@ -531,7 +548,10 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Vec) {
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::Vector>());
EXPECT_EQ(a->type->As<ast::Vector>()->width, 4u);
EXPECT_TRUE(a->type->As<ast::Vector>()->type->Is<ast::U32>());
ASSERT_TRUE(a->type->As<ast::Vector>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
a->type->As<ast::Vector>()->type->As<ast::TypeName>()->name->symbol),
"u32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}}));
}
@ -683,7 +703,11 @@ TEST_F(ParserImplTest, TypeDecl_Texture) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t.value->Is<ast::Texture>());
ASSERT_TRUE(t.value->Is<ast::SampledTexture>());
ASSERT_TRUE(t.value->As<ast::SampledTexture>()->type->Is<ast::F32>());
ASSERT_TRUE(t.value->As<ast::SampledTexture>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
t.value->As<ast::SampledTexture>()->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}}));
}

View File

@ -46,7 +46,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Bool) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::Bool>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "bool");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}}));
}
@ -56,7 +57,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_F16) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::F16>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "f16");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
}
@ -66,7 +68,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_F32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::F32>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
}
@ -76,7 +79,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_I32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::I32>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "i32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
}
@ -86,7 +90,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_U32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_TRUE(t.value->Is<ast::U32>());
ASSERT_TRUE(t.value->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As<ast::TypeName>()->name->symbol), "u32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
}
@ -166,7 +171,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr) {
ASSERT_TRUE(t.value->Is<ast::Pointer>());
auto* ptr = t.value->As<ast::Pointer>();
ASSERT_TRUE(ptr->type->Is<ast::F32>());
ASSERT_TRUE(ptr->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(ptr->type->As<ast::TypeName>()->name->symbol), "f32");
ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}}));
}
@ -181,7 +187,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_WithAccess) {
ASSERT_TRUE(t.value->Is<ast::Pointer>());
auto* ptr = t.value->As<ast::Pointer>();
ASSERT_TRUE(ptr->type->Is<ast::F32>());
ASSERT_TRUE(ptr->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(ptr->type->As<ast::TypeName>()->name->symbol), "f32");
ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction);
ASSERT_EQ(ptr->access, type::Access::kRead);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}}));
@ -202,7 +209,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_ToVec) {
auto* vec = ptr->type->As<ast::Vector>();
ASSERT_EQ(vec->width, 2u);
ASSERT_TRUE(vec->type->Is<ast::F32>());
ASSERT_TRUE(vec->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(vec->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25}}));
}
@ -333,7 +341,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Atomic) {
ASSERT_TRUE(t.value->Is<ast::Atomic>());
auto* atomic = t.value->As<ast::Atomic>();
ASSERT_TRUE(atomic->type->Is<ast::F32>());
ASSERT_TRUE(atomic->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(atomic->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}}));
}
@ -351,7 +361,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Atomic_ToVec) {
auto* vec = atomic->type->As<ast::Vector>();
ASSERT_EQ(vec->width, 2u);
ASSERT_TRUE(vec->type->Is<ast::F32>());
ASSERT_TRUE(vec->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(vec->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}}));
}
@ -396,7 +407,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_AbstractIntLiteralSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}}));
@ -417,7 +429,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_SintLiteralSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}}));
@ -438,7 +451,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_UintLiteralSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}}));
@ -458,7 +472,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_ConstantSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}}));
@ -478,7 +493,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_ExpressionSize) {
auto* a = t.value->As<ast::Array>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(a->attributes.Length(), 0u);
ASSERT_TRUE(a->count->Is<ast::BinaryExpression>());
@ -505,7 +521,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_Runtime) {
auto* a = t.value->As<ast::Array>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::U32>());
ASSERT_TRUE(a->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As<ast::TypeName>()->name->symbol), "u32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}}));
}
@ -522,7 +540,10 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_Runtime_Vec) {
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::Vector>());
EXPECT_EQ(a->type->As<ast::Vector>()->width, 4u);
EXPECT_TRUE(a->type->As<ast::Vector>()->type->Is<ast::U32>());
ASSERT_TRUE(a->type->As<ast::Vector>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
a->type->As<ast::Vector>()->type->As<ast::TypeName>()->name->symbol),
"u32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}}));
}
@ -675,7 +696,10 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Texture) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t.value->Is<ast::Texture>());
ASSERT_TRUE(t.value->Is<ast::SampledTexture>());
ASSERT_TRUE(t.value->As<ast::SampledTexture>()->type->Is<ast::F32>());
ASSERT_TRUE(t.value->As<ast::SampledTexture>()->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(
t.value->As<ast::SampledTexture>()->type->As<ast::TypeName>()->name->symbol),
"f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}}));
}

View File

@ -24,7 +24,9 @@ TEST_F(ParserImplTest, VariableDecl_Parses) {
EXPECT_FALSE(v.errored);
EXPECT_EQ(v->name, "my_var");
EXPECT_NE(v->type, nullptr);
EXPECT_TRUE(v->type->Is<ast::F32>());
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 11u}}));
EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 14u}, {1u, 17u}}));
@ -43,7 +45,9 @@ TEST_F(ParserImplTest, VariableDecl_Unicode_Parses) {
EXPECT_FALSE(v.errored);
EXPECT_EQ(v->name, ident);
EXPECT_NE(v->type, nullptr);
EXPECT_TRUE(v->type->Is<ast::F32>());
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 48u}}));
EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 51u}, {1u, 54u}}));
@ -79,7 +83,10 @@ TEST_F(ParserImplTest, VariableDecl_WithAddressSpace) {
EXPECT_FALSE(v.errored);
EXPECT_FALSE(p->has_error());
EXPECT_EQ(v->name, "my_var");
EXPECT_TRUE(v->type->Is<ast::F32>());
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(v->address_space, type::AddressSpace::kPrivate);
EXPECT_EQ(v->source.range.begin.line, 1u);
@ -95,7 +102,10 @@ TEST_F(ParserImplTest, VariableDecl_WithPushConstant) {
EXPECT_FALSE(v.errored);
EXPECT_FALSE(p->has_error());
EXPECT_EQ(v->name, "my_var");
EXPECT_TRUE(v->type->Is<ast::F32>());
ASSERT_TRUE(v->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(v->address_space, type::AddressSpace::kPushConstant);
}

View File

@ -24,7 +24,8 @@ TEST_F(ParserImplTest, VariableIdentDecl_Parses) {
ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr);
ASSERT_TRUE(decl->type->Is<ast::F32>());
ASSERT_TRUE(decl->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(decl->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}}));
EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}}));
@ -37,7 +38,8 @@ TEST_F(ParserImplTest, VariableIdentDecl_Parses_AllowInferredType) {
ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr);
ASSERT_TRUE(decl->type->Is<ast::F32>());
ASSERT_TRUE(decl->type->Is<ast::TypeName>());
EXPECT_EQ(p->builder().Symbols().NameFor(decl->type->As<ast::TypeName>()->name->symbol), "f32");
EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}}));
EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}}));

View File

@ -23,7 +23,6 @@
#include "src/tint/ast/assignment_statement.h"
#include "src/tint/ast/atomic.h"
#include "src/tint/ast/block_statement.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/break_if_statement.h"
#include "src/tint/ast/break_statement.h"
#include "src/tint/ast/call_statement.h"
@ -35,10 +34,7 @@
#include "src/tint/ast/diagnostic_attribute.h"
#include "src/tint/ast/discard_statement.h"
#include "src/tint/ast/external_texture.h"
#include "src/tint/ast/f16.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/for_loop_statement.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/id_attribute.h"
#include "src/tint/ast/identifier.h"
#include "src/tint/ast/if_statement.h"
@ -66,7 +62,6 @@
#include "src/tint/ast/templated_identifier.h"
#include "src/tint/ast/traverse_expressions.h"
#include "src/tint/ast/type_name.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/var.h"
#include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/ast/vector.h"
@ -407,10 +402,12 @@ class DependencyScanner {
[&](const ast::MultisampledTexture* tex) { //
TraverseType(tex->type);
},
[&](const ast::StorageTexture* tex) { //
TraverseType(tex->type);
},
[&](Default) {
if (!ty->IsAnyOf<ast::Bool, ast::I32, ast::U32, ast::F16, ast::F32,
ast::DepthTexture, ast::DepthMultisampledTexture,
ast::StorageTexture, ast::ExternalTexture, ast::Sampler>()) {
if (!ty->IsAnyOf<ast::DepthTexture, ast::DepthMultisampledTexture,
ast::ExternalTexture, ast::Sampler>()) {
UnhandledNode(diagnostics_, ty);
}
});

View File

@ -1264,11 +1264,13 @@ TEST_P(ResolverDependencyGraphResolveToBuiltinType, Resolve) {
TEST_P(ResolverDependencyGraphResolveToBuiltinType, ShadowedByGlobalVar) {
const auto use = std::get<0>(GetParam());
const auto name = std::get<1>(GetParam());
const std::string name = std::get<1>(GetParam());
const auto symbol = Symbols().New(name);
auto* decl =
GlobalVar(symbol, name == "i32" ? ty.u32() : ty.i32(), type::AddressSpace::kPrivate);
SymbolTestHelper helper(this);
auto* decl = helper.Add(SymbolDeclKind::GlobalVar, symbol);
auto* ident = helper.Add(use, symbol);
helper.Build();
@ -1279,11 +1281,14 @@ TEST_P(ResolverDependencyGraphResolveToBuiltinType, ShadowedByGlobalVar) {
TEST_P(ResolverDependencyGraphResolveToBuiltinType, ShadowedByStruct) {
const auto use = std::get<0>(GetParam());
const auto name = std::get<1>(GetParam());
const std::string name = std::get<1>(GetParam());
const auto symbol = Symbols().New(name);
auto* decl = Structure(symbol, utils::Vector{
Member("m", name == "i32" ? ty.u32() : ty.i32()),
});
SymbolTestHelper helper(this);
auto* decl = helper.Add(SymbolDeclKind::Struct, symbol);
auto* ident = helper.Add(use, symbol);
helper.Build();
@ -1734,7 +1739,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) {
GlobalVar(Sym(), ty.external_texture());
GlobalVar(Sym(), ty.multisampled_texture(type::TextureDimension::k2d, T));
GlobalVar(Sym(), ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Float,
type::Access::kRead)); //
type::Access::kRead));
GlobalVar(Sym(), ty.sampler(type::SamplerKind::kSampler));
GlobalVar(Sym(), ty.i32(), utils::Vector{Binding(V), Group(V)});

View File

@ -227,13 +227,6 @@ type::Type* Resolver::Type(const ast::Type* ty) {
Mark(ty);
auto* s = Switch(
ty, //
[&](const ast::Bool*) { return builder_->create<type::Bool>(); },
[&](const ast::I32*) { return builder_->create<type::I32>(); },
[&](const ast::U32*) { return builder_->create<type::U32>(); },
[&](const ast::F16* t) -> type::F16* {
return validator_.CheckF16Enabled(t->source) ? builder_->create<type::F16>() : nullptr;
},
[&](const ast::F32*) { return builder_->create<type::F32>(); },
[&](const ast::Vector* t) -> type::Vector* {
if (!t->type) {
AddError("missing vector element type", t->source.End());
@ -2447,88 +2440,91 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr,
type::Type* Resolver::BuiltinType(type::Builtin builtin_ty, const ast::Identifier* ident) const {
auto& b = *builder_;
auto vec_f32 = [&](uint32_t n) { return b.create<type::Vector>(b.create<type::F32>(), n); };
auto vec_f16 = [&](uint32_t n) { return b.create<type::Vector>(b.create<type::F16>(), n); };
auto f32 = [&] { return b.create<type::F32>(); };
auto i32 = [&] { return b.create<type::I32>(); };
auto u32 = [&] { return b.create<type::U32>(); };
auto f16 = [&] {
return validator_.CheckF16Enabled(ident->source) ? b.create<type::F16>() : nullptr;
};
auto vec = [&](type::Type* el, uint32_t n) {
return el ? b.create<type::Vector>(el, n) : nullptr;
};
auto mat = [&](type::Type* el, uint32_t num_columns, uint32_t num_rows) {
return el ? b.create<type::Matrix>(vec(el, num_rows), num_columns) : nullptr;
};
switch (builtin_ty) {
case type::Builtin::kBool:
return b.create<type::Bool>();
case type::Builtin::kI32:
return i32();
case type::Builtin::kU32:
return u32();
case type::Builtin::kF16:
return f16();
case type::Builtin::kF32:
return b.create<type::F32>();
case type::Builtin::kMat2X2F:
return b.create<type::Matrix>(vec_f32(2u), 2u);
return mat(f32(), 2u, 2u);
case type::Builtin::kMat2X3F:
return b.create<type::Matrix>(vec_f32(3u), 2u);
return mat(f32(), 2u, 3u);
case type::Builtin::kMat2X4F:
return b.create<type::Matrix>(vec_f32(4u), 2u);
return mat(f32(), 2u, 4u);
case type::Builtin::kMat3X2F:
return b.create<type::Matrix>(vec_f32(2u), 3u);
return mat(f32(), 3u, 2u);
case type::Builtin::kMat3X3F:
return b.create<type::Matrix>(vec_f32(3u), 3u);
return mat(f32(), 3u, 3u);
case type::Builtin::kMat3X4F:
return b.create<type::Matrix>(vec_f32(4u), 3u);
return mat(f32(), 3u, 4u);
case type::Builtin::kMat4X2F:
return b.create<type::Matrix>(vec_f32(2u), 4u);
return mat(f32(), 4u, 2u);
case type::Builtin::kMat4X3F:
return b.create<type::Matrix>(vec_f32(3u), 4u);
return mat(f32(), 4u, 3u);
case type::Builtin::kMat4X4F:
return b.create<type::Matrix>(vec_f32(4u), 4u);
return mat(f32(), 4u, 4u);
case type::Builtin::kMat2X2H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(2u), 2u)
: nullptr;
return mat(f16(), 2u, 2u);
case type::Builtin::kMat2X3H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(3u), 2u)
: nullptr;
return mat(f16(), 2u, 3u);
case type::Builtin::kMat2X4H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(4u), 2u)
: nullptr;
return mat(f16(), 2u, 4u);
case type::Builtin::kMat3X2H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(2u), 3u)
: nullptr;
return mat(f16(), 3u, 2u);
case type::Builtin::kMat3X3H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(3u), 3u)
: nullptr;
return mat(f16(), 3u, 3u);
case type::Builtin::kMat3X4H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(4u), 3u)
: nullptr;
return mat(f16(), 3u, 4u);
case type::Builtin::kMat4X2H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(2u), 4u)
: nullptr;
return mat(f16(), 4u, 2u);
case type::Builtin::kMat4X3H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(3u), 4u)
: nullptr;
return mat(f16(), 4u, 3u);
case type::Builtin::kMat4X4H:
return validator_.CheckF16Enabled(ident->source)
? b.create<type::Matrix>(vec_f16(4u), 4u)
: nullptr;
return mat(f16(), 4u, 4u);
case type::Builtin::kVec2F:
return vec_f32(2u);
return vec(f32(), 2u);
case type::Builtin::kVec3F:
return vec_f32(3u);
return vec(f32(), 3u);
case type::Builtin::kVec4F:
return vec_f32(4u);
return vec(f32(), 4u);
case type::Builtin::kVec2H:
return validator_.CheckF16Enabled(ident->source) ? vec_f16(2u) : nullptr;
return vec(f16(), 2u);
case type::Builtin::kVec3H:
return validator_.CheckF16Enabled(ident->source) ? vec_f16(3u) : nullptr;
return vec(f16(), 3u);
case type::Builtin::kVec4H:
return validator_.CheckF16Enabled(ident->source) ? vec_f16(4u) : nullptr;
return vec(f16(), 4u);
case type::Builtin::kVec2I:
return b.create<type::Vector>(b.create<type::I32>(), 2u);
return vec(i32(), 2u);
case type::Builtin::kVec3I:
return b.create<type::Vector>(b.create<type::I32>(), 3u);
return vec(i32(), 3u);
case type::Builtin::kVec4I:
return b.create<type::Vector>(b.create<type::I32>(), 4u);
return vec(i32(), 4u);
case type::Builtin::kVec2U:
return b.create<type::Vector>(b.create<type::U32>(), 2u);
return vec(u32(), 2u);
case type::Builtin::kVec3U:
return b.create<type::Vector>(b.create<type::U32>(), 3u);
return vec(u32(), 3u);
case type::Builtin::kVec4U:
return b.create<type::Vector>(b.create<type::U32>(), 4u);
return vec(u32(), 4u);
case type::Builtin::kUndefined:
break;
}

View File

@ -143,7 +143,7 @@ struct CombineSamplers::State {
const type::Type* texture_type = texture->Type()->UnwrapRef();
const type::DepthTexture* depth = texture_type->As<type::DepthTexture>();
if (depth && !sampler) {
return ctx.dst->create<ast::SampledTexture>(depth->dim(), ctx.dst->create<ast::F32>());
return ctx.dst->create<ast::SampledTexture>(depth->dim(), ctx.dst->ty.f32());
} else {
return CreateASTTypeFor(ctx, texture_type);
}

View File

@ -78,19 +78,19 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type
return nullptr;
}
if (ty->Is<type::I32>()) {
return ctx.dst->create<ast::I32>();
return ctx.dst->ty.i32();
}
if (ty->Is<type::U32>()) {
return ctx.dst->create<ast::U32>();
return ctx.dst->ty.u32();
}
if (ty->Is<type::F16>()) {
return ctx.dst->create<ast::F16>();
return ctx.dst->ty.f16();
}
if (ty->Is<type::F32>()) {
return ctx.dst->create<ast::F32>();
return ctx.dst->ty.f32();
}
if (ty->Is<type::Bool>()) {
return ctx.dst->create<ast::Bool>();
return ctx.dst->ty.bool_();
}
if (auto* m = ty->As<type::Matrix>()) {
auto* el = CreateASTTypeFor(ctx, m->type());

View File

@ -12,9 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/transform/transform.h"
#include <string>
#include "src/tint/clone_context.h"
#include "src/tint/program_builder.h"
#include "src/tint/transform/transform.h"
#include "gtest/gtest.h"
@ -37,14 +39,21 @@ struct CreateASTTypeForTest : public testing::Test, public Transform {
return CreateASTTypeFor(ctx, sem_type);
}
std::string TypeNameOf(const ast::Type* ty) const {
if (auto* type_name = ty->As<ast::TypeName>()) {
return ast_type_builder.Symbols().NameFor(type_name->name->symbol);
}
return "<not-a-typename>";
}
ProgramBuilder ast_type_builder;
};
TEST_F(CreateASTTypeForTest, Basic) {
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::I32>(); })->Is<ast::I32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::U32>(); })->Is<ast::U32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::F32>(); })->Is<ast::F32>());
EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create<type::Bool>(); })->Is<ast::Bool>());
EXPECT_EQ(TypeNameOf(create([](ProgramBuilder& b) { return b.create<type::I32>(); })), "i32");
EXPECT_EQ(TypeNameOf(create([](ProgramBuilder& b) { return b.create<type::U32>(); })), "u32");
EXPECT_EQ(TypeNameOf(create([](ProgramBuilder& b) { return b.create<type::F32>(); })), "f32");
EXPECT_EQ(TypeNameOf(create([](ProgramBuilder& b) { return b.create<type::Bool>(); })), "bool");
EXPECT_EQ(create([](ProgramBuilder& b) { return b.create<type::Void>(); }), nullptr);
}
@ -54,7 +63,7 @@ TEST_F(CreateASTTypeForTest, Matrix) {
return b.create<type::Matrix>(column_type, 3u);
});
ASSERT_TRUE(mat->Is<ast::Matrix>());
ASSERT_TRUE(mat->As<ast::Matrix>()->type->Is<ast::F32>());
EXPECT_EQ(TypeNameOf(mat->As<ast::Matrix>()->type), "f32");
ASSERT_EQ(mat->As<ast::Matrix>()->columns, 3u);
ASSERT_EQ(mat->As<ast::Matrix>()->rows, 2u);
}
@ -63,7 +72,7 @@ TEST_F(CreateASTTypeForTest, Vector) {
auto* vec =
create([](ProgramBuilder& b) { return b.create<type::Vector>(b.create<type::F32>(), 2u); });
ASSERT_TRUE(vec->Is<ast::Vector>());
ASSERT_TRUE(vec->As<ast::Vector>()->type->Is<ast::F32>());
EXPECT_EQ(TypeNameOf(vec->As<ast::Vector>()->type), "f32");
ASSERT_EQ(vec->As<ast::Vector>()->width, 2u);
}
@ -73,7 +82,7 @@ TEST_F(CreateASTTypeForTest, ArrayImplicitStride) {
4u, 4u, 32u, 32u);
});
ASSERT_TRUE(arr->Is<ast::Array>());
ASSERT_TRUE(arr->As<ast::Array>()->type->Is<ast::F32>());
EXPECT_EQ(TypeNameOf(arr->As<ast::Array>()->type), "f32");
ASSERT_EQ(arr->As<ast::Array>()->attributes.Length(), 0u);
auto* size = arr->As<ast::Array>()->count->As<ast::IntLiteralExpression>();
@ -87,7 +96,7 @@ TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) {
4u, 4u, 64u, 32u);
});
ASSERT_TRUE(arr->Is<ast::Array>());
ASSERT_TRUE(arr->As<ast::Array>()->type->Is<ast::F32>());
EXPECT_EQ(TypeNameOf(arr->As<ast::Array>()->type), "f32");
ASSERT_EQ(arr->As<ast::Array>()->attributes.Length(), 1u);
ASSERT_TRUE(arr->As<ast::Array>()->attributes[0]->Is<ast::StrideAttribute>());
ASSERT_EQ(arr->As<ast::Array>()->attributes[0]->As<ast::StrideAttribute>()->stride, 64u);

View File

@ -28,6 +28,18 @@ namespace tint::type {
/// @param str the string to parse
/// @returns the parsed enum, or Builtin::kUndefined if the string could not be parsed.
Builtin ParseBuiltin(std::string_view str) {
if (str == "bool") {
return Builtin::kBool;
}
if (str == "f16") {
return Builtin::kF16;
}
if (str == "f32") {
return Builtin::kF32;
}
if (str == "i32") {
return Builtin::kI32;
}
if (str == "mat2x2f") {
return Builtin::kMat2X2F;
}
@ -82,6 +94,9 @@ Builtin ParseBuiltin(std::string_view str) {
if (str == "mat4x4h") {
return Builtin::kMat4X4H;
}
if (str == "u32") {
return Builtin::kU32;
}
if (str == "vec2f") {
return Builtin::kVec2F;
}
@ -125,6 +140,14 @@ std::ostream& operator<<(std::ostream& out, Builtin value) {
switch (value) {
case Builtin::kUndefined:
return out << "undefined";
case Builtin::kBool:
return out << "bool";
case Builtin::kF16:
return out << "f16";
case Builtin::kF32:
return out << "f32";
case Builtin::kI32:
return out << "i32";
case Builtin::kMat2X2F:
return out << "mat2x2f";
case Builtin::kMat2X2H:
@ -161,6 +184,8 @@ std::ostream& operator<<(std::ostream& out, Builtin value) {
return out << "mat4x4f";
case Builtin::kMat4X4H:
return out << "mat4x4h";
case Builtin::kU32:
return out << "u32";
case Builtin::kVec2F:
return out << "vec2f";
case Builtin::kVec2H:

View File

@ -30,6 +30,10 @@ namespace tint::type {
/// An enumerator of builtin types.
enum class Builtin {
kUndefined,
kBool,
kF16,
kF32,
kI32,
kMat2X2F,
kMat2X2H,
kMat2X3F,
@ -48,6 +52,7 @@ enum class Builtin {
kMat4X3H,
kMat4X4F,
kMat4X4H,
kU32,
kVec2F,
kVec2H,
kVec2I,
@ -73,10 +78,11 @@ std::ostream& operator<<(std::ostream& out, Builtin value);
Builtin ParseBuiltin(std::string_view str);
constexpr const char* kBuiltinStrings[] = {
"mat2x2f", "mat2x2h", "mat2x3f", "mat2x3h", "mat2x4f", "mat2x4h", "mat3x2f", "mat3x2h",
"mat3x3f", "mat3x3h", "mat3x4f", "mat3x4h", "mat4x2f", "mat4x2h", "mat4x3f", "mat4x3h",
"mat4x4f", "mat4x4h", "vec2f", "vec2h", "vec2i", "vec2u", "vec3f", "vec3h",
"vec3i", "vec3u", "vec4f", "vec4h", "vec4i", "vec4u",
"bool", "f16", "f32", "i32", "mat2x2f", "mat2x2h", "mat2x3f",
"mat2x3h", "mat2x4f", "mat2x4h", "mat3x2f", "mat3x2h", "mat3x3f", "mat3x3h",
"mat3x4f", "mat3x4h", "mat4x2f", "mat4x2h", "mat4x3f", "mat4x3h", "mat4x4f",
"mat4x4h", "u32", "vec2f", "vec2h", "vec2i", "vec2u", "vec3f",
"vec3h", "vec3i", "vec3u", "vec4f", "vec4h", "vec4i", "vec4u",
};
} // namespace tint::type

View File

@ -31,41 +31,47 @@ namespace {
void BuiltinParser(::benchmark::State& state) {
std::array kStrings{
"at2x2cc", "l23f", "matVx2f", "mat2x2f", "mat212f", "mqtJx2f",
"mat2x27ll", "ppqqt22HH", "macv", "bt2xGh", "mat2x2h", "mat2iivh",
"8WWt2x2h", "mxx2x2h", "mX2x3gg", "a2xXf", "mat233f", "mat2x3f",
"Eat2x3f", "mPTT2x3f", "mat2xdxx", "m44t2x3h", "maSS2xVVh", "RatR22h",
"mat2x3h", "mF2x9h", "matx3h", "VOORRH3h", "ma2xyf", "llnarr2774f",
"mat24400", "mat2x4f", "a2oof", "zz2x4f", "miitppx1", "mat2xXXh",
"9II5ann2x4h", "mataSSrHHYh", "mat2x4h", "makkh", "jatgRx", "mb2x4",
"mat3xjf", "at3x2f", "q3x2f", "mat3x2f", "matNN2f", "at32vv",
"QQt3x2f", "maffxr", "mat3xjh", "mNNw3x28", "mat3x2h", "matx2h",
"mrrt3x2h", "Gat3x2h", "mat3x3FF", "at3f", "marrx3f", "mat3x3f",
"t3x3f", "Da3xJJf", "ma83", "m11k3", "matx3h", "maJx3h",
"mat3x3h", "mat3c3h", "mat3x3O", "KK_atvvtt3h", "xx83x4f", "__qatF4",
"matqx4f", "mat3x4f", "33atOx4f", "mtt63x9oQQ", "ma3x66f", "mtOxzz66",
"mat3yy4h", "ZaHH4Z", "mat3x4h", "4WWt3q4h", "mOO3x4h", "oatY4h",
"matx", "ma4xFf", "at4x2w", "mat4x2f", "fGtxKf", "matqKx2f",
"matmmxFf", "at4x2h", "mt4x2q", "mat4xbb", "mat4x2h", "mi4x2h",
"maOO4xq", "matTvvx2h", "maFF4x3f", "Pa00xQf", "mPt4x3f", "mat4x3f",
"ma774xss", "RRCbb4x3f", "mXXt4x3f", "qaCC4xOOh", "ma4s3L", "mXt4x3h",
"mat4x3h", "mat43h", "qa4O3", "mat4x22h", "myzz40XX", "matVViP",
"mannC4f", "mat4x4f", "atx4AHHq", "mat4x4", "fatK4f", "ltgg4h",
"mat4xh", "NTTtcx4h", "mat4x4h", "ma7ppl4h", "mNNt4xg", "uub4XX4h",
"vec2", "882K", "vq9f", "vec2f", "vec211", "22ciif",
"ec77f", "NN22h", "vVVc2h", "WW11w2h", "vec2h", "vcwwh",
"vDc2h", "vecK", "f11r2PP", "ve2i", "vec2YY", "vec2i",
"vkktHH", "rrec2i", "vWWssi", "veYu", "eq2f", "u22ec2u",
"vec2u", "c2u", "vec2", "vYyc27E", "veMof", "ve3MM",
"55ec3f", "vec3f", "N3f", "ve33f", "3ec3f", "mecI",
"vrnK3h", "v3", "vec3h", "ILLch", "ecf", "UecRY",
"vechi", "qeIIu", "Hec3i", "vec3i", "eQQvv", "e66i",
"7Wc3", "ve055DD", "IIec3u", "vec3", "vec3u", "rec3",
"lec3u", "GeJ3u", "ey4f", "vc4f", "IIeBB4f", "vec4f",
"TTec338", "veUUSS4nnd", "vZx5CC", "kkec4q", "v005ih", "vnIIc4h",
"vec4h", "cceW", "cKK", "vec66h", "vePPK", "vexxi",
"qec4i", "vec4i", "veSyMMr", "v4u", "ec", "5eFF4u",
"rrecz44", "vWW", "vec4u", "XJecCZZ", "vePP4", "vec4c",
"ccol", "3", "bVol", "bool", "1ool", "bqoJ",
"bllo77", "fppqH", "", "Gb", "f16", "f1vi",
"f8WW", "fxx", "fgg", "X", "332", "f32",
"fE2", "fPTT", "dxx2", "4432", "iSVV2", "RR2",
"i32", "92", "i3", "VOR2", "ma2xyf", "llnarr2772f",
"mat24200", "mat2x2f", "a2oof", "zz2x2f", "miitppx1", "mat2xXXh",
"9II5ann2x2h", "mataSSrHHYh", "mat2x2h", "makkh", "jatgRx", "mb2x2",
"mat2xjf", "at2x3f", "q2x3f", "mat2x3f", "matNN3f", "at23vv",
"QQt2x3f", "maffxr", "mat2xjh", "mNNw2x38", "mat2x3h", "matx3h",
"mrrt2x3h", "Gat2x3h", "mat2x4FF", "at2f", "marrx4f", "mat2x4f",
"t2x4f", "Da2xJJf", "ma84", "m11k4", "matx4h", "maJx4h",
"mat2x4h", "mat2c4h", "mat2x4O", "KK_atvvtt4h", "xx83x2f", "__qatF2",
"matqx2f", "mat3x2f", "33atOx2f", "mtt63x9oQQ", "ma3x66f", "mtOxzz66",
"mat3yy2h", "ZaHH2Z", "mat3x2h", "4WWt3q2h", "mOO3x2h", "oatY2h",
"matx", "ma3xFf", "at3x3w", "mat3x3f", "fGtxKf", "matqKx3f",
"matmmxFf", "at3x3h", "mt3x3q", "mat3xbb", "mat3x3h", "mi3x3h",
"maOO3xq", "matTvvx3h", "maFF3x4f", "Pa00xQf", "mPt3x4f", "mat3x4f",
"ma773xss", "RRCbb3x4f", "mXXt3x4f", "qaCC3xOOh", "ma3s4L", "mXt3x4h",
"mat3x4h", "mat34h", "qa3O4", "mat3x22h", "myzz40XX", "matVViP",
"mannC2f", "mat4x2f", "atx2AHHq", "mat4x2", "fatK2f", "ltgg2h",
"mat4xh", "NTTtcx4h", "mat4x2h", "ma7ppl2h", "mNNt4xg", "uub4XX2h",
"matx3f", "Qt883f", "mt9q3f", "mat4x3f", "m11t4x3f", "22at4iif",
"at4x377", "m2t4xNh", "mVVt4x3h", "FaWW4w11h", "mat4x3h", "mawwx3h",
"Dat4x3h", "mt4x3K", "mat41PPhf", "mat44f", "mYYt4x4f", "mat4x4f",
"mttHH4kk", "mat4rr4f", "WWas4x4f", "Yt4x4h", "mt4qfh", "mav224xuh",
"mat4x4h", "t4x4h", "YYat4h", "may4x4EYY", "Mo2", "uMM",
"u552", "u32", "N", "333", "u33", "mecI",
"vrnK2f", "v2", "vec2f", "ILLcf", "ecf", "UecRY",
"vechh", "qeIIu", "Hec2h", "vec2h", "eQQvv", "e66h",
"7Wc2", "ve055DD", "IIec2i", "vec2", "vec2i", "rec2",
"lec2i", "GeJ2i", "ey2u", "vc2u", "IIeBB2u", "vec2u",
"TTec338", "veUUSS2nnd", "vZx5CC", "kkec3q", "v005if", "vnIIc3f",
"vec3f", "cceW", "cKK", "vec66f", "vePPK", "vexxh",
"qec3h", "vec3h", "veSyMMr", "v3u", "ec", "5eFF3i",
"rrecz44", "vWW", "vec3i", "XJecCZZ", "vePP3", "vec3c",
"ve6ll3u", "vcyy99", "Jec3KK", "vec3u", "_ex3", "Ky3",
"zek3u", "veKSf", "vc4f", "ec4VV", "vec4f", "IAAc4f",
"jbR", "veY4", "ec4h", "vc911", "mmcch", "vec4h",
"vJJch", "lDDcUfC", "vec4g", "CCe", "ec4i", "vIc__i",
"vec4i", "ePPtt", "v3dc4i", "vcyyi", "u4", "v03nnu",
"Cuuecnv", "vec4u", "vX4ll", "vocppu", "vwwc4",
};
for (auto _ : state) {
for (auto& str : kStrings) {

View File

@ -43,64 +43,74 @@ inline std::ostream& operator<<(std::ostream& out, Case c) {
}
static constexpr Case kValidCases[] = {
{"mat2x2f", Builtin::kMat2X2F}, {"mat2x2h", Builtin::kMat2X2H}, {"mat2x3f", Builtin::kMat2X3F},
{"mat2x3h", Builtin::kMat2X3H}, {"mat2x4f", Builtin::kMat2X4F}, {"mat2x4h", Builtin::kMat2X4H},
{"mat3x2f", Builtin::kMat3X2F}, {"mat3x2h", Builtin::kMat3X2H}, {"mat3x3f", Builtin::kMat3X3F},
{"mat3x3h", Builtin::kMat3X3H}, {"mat3x4f", Builtin::kMat3X4F}, {"mat3x4h", Builtin::kMat3X4H},
{"mat4x2f", Builtin::kMat4X2F}, {"mat4x2h", Builtin::kMat4X2H}, {"mat4x3f", Builtin::kMat4X3F},
{"mat4x3h", Builtin::kMat4X3H}, {"mat4x4f", Builtin::kMat4X4F}, {"mat4x4h", Builtin::kMat4X4H},
{"vec2f", Builtin::kVec2F}, {"vec2h", Builtin::kVec2H}, {"vec2i", Builtin::kVec2I},
{"vec2u", Builtin::kVec2U}, {"vec3f", Builtin::kVec3F}, {"vec3h", Builtin::kVec3H},
{"vec3i", Builtin::kVec3I}, {"vec3u", Builtin::kVec3U}, {"vec4f", Builtin::kVec4F},
{"vec4h", Builtin::kVec4H}, {"vec4i", Builtin::kVec4I}, {"vec4u", Builtin::kVec4U},
{"bool", Builtin::kBool}, {"f16", Builtin::kF16}, {"f32", Builtin::kF32},
{"i32", Builtin::kI32}, {"mat2x2f", Builtin::kMat2X2F}, {"mat2x2h", Builtin::kMat2X2H},
{"mat2x3f", Builtin::kMat2X3F}, {"mat2x3h", Builtin::kMat2X3H}, {"mat2x4f", Builtin::kMat2X4F},
{"mat2x4h", Builtin::kMat2X4H}, {"mat3x2f", Builtin::kMat3X2F}, {"mat3x2h", Builtin::kMat3X2H},
{"mat3x3f", Builtin::kMat3X3F}, {"mat3x3h", Builtin::kMat3X3H}, {"mat3x4f", Builtin::kMat3X4F},
{"mat3x4h", Builtin::kMat3X4H}, {"mat4x2f", Builtin::kMat4X2F}, {"mat4x2h", Builtin::kMat4X2H},
{"mat4x3f", Builtin::kMat4X3F}, {"mat4x3h", Builtin::kMat4X3H}, {"mat4x4f", Builtin::kMat4X4F},
{"mat4x4h", Builtin::kMat4X4H}, {"u32", Builtin::kU32}, {"vec2f", Builtin::kVec2F},
{"vec2h", Builtin::kVec2H}, {"vec2i", Builtin::kVec2I}, {"vec2u", Builtin::kVec2U},
{"vec3f", Builtin::kVec3F}, {"vec3h", Builtin::kVec3H}, {"vec3i", Builtin::kVec3I},
{"vec3u", Builtin::kVec3U}, {"vec4f", Builtin::kVec4F}, {"vec4h", Builtin::kVec4H},
{"vec4i", Builtin::kVec4I}, {"vec4u", Builtin::kVec4U},
};
static constexpr Case kInvalidCases[] = {
{"at2x2cc", Builtin::kUndefined}, {"l23f", Builtin::kUndefined},
{"matVx2f", Builtin::kUndefined}, {"mat212h", Builtin::kUndefined},
{"mqtJx2h", Builtin::kUndefined}, {"mat2x27ll", Builtin::kUndefined},
{"ppqqt23HH", Builtin::kUndefined}, {"macv", Builtin::kUndefined},
{"bt2xGf", Builtin::kUndefined}, {"mat2iivh", Builtin::kUndefined},
{"8WWt2x3h", Builtin::kUndefined}, {"mxx2x3h", Builtin::kUndefined},
{"mX2x4gg", Builtin::kUndefined}, {"a2xXf", Builtin::kUndefined},
{"mat234f", Builtin::kUndefined}, {"Eat2x4h", Builtin::kUndefined},
{"mPTT2x4h", Builtin::kUndefined}, {"mat2xdxx", Builtin::kUndefined},
{"m44t3x2f", Builtin::kUndefined}, {"maSS3xVVf", Builtin::kUndefined},
{"RatR22f", Builtin::kUndefined}, {"mF3x9h", Builtin::kUndefined},
{"matx2h", Builtin::kUndefined}, {"VOORRH2h", Builtin::kUndefined},
{"ma3xyf", Builtin::kUndefined}, {"llnarr3773f", Builtin::kUndefined},
{"mat34300", Builtin::kUndefined}, {"a3ooh", Builtin::kUndefined},
{"zz3x3h", Builtin::kUndefined}, {"miitppx1", Builtin::kUndefined},
{"mat3xXXf", Builtin::kUndefined}, {"9II5ann3x4f", Builtin::kUndefined},
{"ccol", Builtin::kUndefined}, {"3", Builtin::kUndefined},
{"bVol", Builtin::kUndefined}, {"116", Builtin::kUndefined},
{"qJ6", Builtin::kUndefined}, {"f17ll", Builtin::kUndefined},
{"fppqH", Builtin::kUndefined}, {"", Builtin::kUndefined},
{"Gb", Builtin::kUndefined}, {"i3vi", Builtin::kUndefined},
{"i8WW", Builtin::kUndefined}, {"ixx", Builtin::kUndefined},
{"mX2x2gg", Builtin::kUndefined}, {"a2xXf", Builtin::kUndefined},
{"mat232f", Builtin::kUndefined}, {"Eat2x2h", Builtin::kUndefined},
{"mPTT2x2h", Builtin::kUndefined}, {"mat2xdxx", Builtin::kUndefined},
{"m44t2x3f", Builtin::kUndefined}, {"maSS2xVVf", Builtin::kUndefined},
{"RatR22f", Builtin::kUndefined}, {"mF2x9h", Builtin::kUndefined},
{"matx3h", Builtin::kUndefined}, {"VOORRH3h", Builtin::kUndefined},
{"ma2xyf", Builtin::kUndefined}, {"llnarr2774f", Builtin::kUndefined},
{"mat24400", Builtin::kUndefined}, {"a2ooh", Builtin::kUndefined},
{"zz2x4h", Builtin::kUndefined}, {"miitppx1", Builtin::kUndefined},
{"mat3xXXf", Builtin::kUndefined}, {"9II5ann3x2f", Builtin::kUndefined},
{"mataSSrHHYf", Builtin::kUndefined}, {"makkh", Builtin::kUndefined},
{"jatgRx", Builtin::kUndefined}, {"mb3x4", Builtin::kUndefined},
{"mat4xjf", Builtin::kUndefined}, {"at4x2f", Builtin::kUndefined},
{"q4x2f", Builtin::kUndefined}, {"matNN2h", Builtin::kUndefined},
{"at42vv", Builtin::kUndefined}, {"QQt4x2h", Builtin::kUndefined},
{"maffxr", Builtin::kUndefined}, {"mat4xjf", Builtin::kUndefined},
{"mNNw4x38", Builtin::kUndefined}, {"matx3h", Builtin::kUndefined},
{"mrrt4x3h", Builtin::kUndefined}, {"Gat4x3h", Builtin::kUndefined},
{"mat4x4FF", Builtin::kUndefined}, {"at4f", Builtin::kUndefined},
{"marrx4f", Builtin::kUndefined}, {"t4x4h", Builtin::kUndefined},
{"Da4xJJh", Builtin::kUndefined}, {"ma84", Builtin::kUndefined},
{"e2k", Builtin::kUndefined}, {"vecf", Builtin::kUndefined},
{"Jecf", Builtin::kUndefined}, {"ec2h", Builtin::kUndefined},
{"_KKttcH", Builtin::kUndefined}, {"vexxh", Builtin::kUndefined},
{"__qcF", Builtin::kUndefined}, {"vc2qq", Builtin::kUndefined},
{"33e62i", Builtin::kUndefined}, {"6QQott2u", Builtin::kUndefined},
{"v6c2u", Builtin::kUndefined}, {"zzc2O6", Builtin::kUndefined},
{"vyyc3f", Builtin::kUndefined}, {"vcZZ", Builtin::kUndefined},
{"ecWq4f", Builtin::kUndefined}, {"vOO3h", Builtin::kUndefined},
{"oYe3", Builtin::kUndefined}, {"v3", Builtin::kUndefined},
{"Fe3i", Builtin::kUndefined}, {"vwci", Builtin::kUndefined},
{"vefi", Builtin::kUndefined}, {"KKeq3u", Builtin::kUndefined},
{"vFmm3u", Builtin::kUndefined}, {"vecu", Builtin::kUndefined},
{"qc4f", Builtin::kUndefined}, {"vecbb", Builtin::kUndefined},
{"iic4", Builtin::kUndefined}, {"vqOOh", Builtin::kUndefined},
{"vevvTTh", Builtin::kUndefined}, {"veFF4h", Builtin::kUndefined},
{"00PfQ", Builtin::kUndefined}, {"vec4P", Builtin::kUndefined},
{"vec77s", Builtin::kUndefined}, {"vecbbCu", Builtin::kUndefined},
{"vecXXu", Builtin::kUndefined}, {"CCOOec4", Builtin::kUndefined},
{"jatgRx", Builtin::kUndefined}, {"mb3x2", Builtin::kUndefined},
{"mat3xjf", Builtin::kUndefined}, {"at3x3f", Builtin::kUndefined},
{"q3x3f", Builtin::kUndefined}, {"matNN3h", Builtin::kUndefined},
{"at33vv", Builtin::kUndefined}, {"QQt3x3h", Builtin::kUndefined},
{"maffxr", Builtin::kUndefined}, {"mat3xjf", Builtin::kUndefined},
{"mNNw3x48", Builtin::kUndefined}, {"matx4h", Builtin::kUndefined},
{"mrrt3x4h", Builtin::kUndefined}, {"Gat3x4h", Builtin::kUndefined},
{"mat4x2FF", Builtin::kUndefined}, {"at4f", Builtin::kUndefined},
{"marrx2f", Builtin::kUndefined}, {"t4x2h", Builtin::kUndefined},
{"Da4xJJh", Builtin::kUndefined}, {"ma82", Builtin::kUndefined},
{"m11k3", Builtin::kUndefined}, {"matx3f", Builtin::kUndefined},
{"maJx3f", Builtin::kUndefined}, {"mat4c3h", Builtin::kUndefined},
{"mat4x3O", Builtin::kUndefined}, {"KK_atvvtt3h", Builtin::kUndefined},
{"xx84x4f", Builtin::kUndefined}, {"__qatF4", Builtin::kUndefined},
{"matqx4f", Builtin::kUndefined}, {"33atOx4h", Builtin::kUndefined},
{"mtt64x9oQQ", Builtin::kUndefined}, {"ma4x66h", Builtin::kUndefined},
{"zzO6", Builtin::kUndefined}, {"uyy2", Builtin::kUndefined},
{"HZ", Builtin::kUndefined}, {"ecWq4f", Builtin::kUndefined},
{"vOO2f", Builtin::kUndefined}, {"oYe2", Builtin::kUndefined},
{"v2", Builtin::kUndefined}, {"Fe2h", Builtin::kUndefined},
{"vwch", Builtin::kUndefined}, {"vefi", Builtin::kUndefined},
{"KKeq2i", Builtin::kUndefined}, {"vFmm2i", Builtin::kUndefined},
{"vecu", Builtin::kUndefined}, {"qc2u", Builtin::kUndefined},
{"vecbb", Builtin::kUndefined}, {"iic3", Builtin::kUndefined},
{"vqOOf", Builtin::kUndefined}, {"vevvTTf", Builtin::kUndefined},
{"veFF3h", Builtin::kUndefined}, {"00PfQ", Builtin::kUndefined},
{"vec3P", Builtin::kUndefined}, {"vec77s", Builtin::kUndefined},
{"vecbbCi", Builtin::kUndefined}, {"vecXXi", Builtin::kUndefined},
{"CCOOec3", Builtin::kUndefined}, {"vs3u", Builtin::kUndefined},
{"Xec3u", Builtin::kUndefined}, {"ve4f", Builtin::kUndefined},
{"qq4", Builtin::kUndefined}, {"vec422", Builtin::kUndefined},
{"vezzXy", Builtin::kUndefined}, {"ieVVP", Builtin::kUndefined},
{"venCh", Builtin::kUndefined}, {"vHc4Aq", Builtin::kUndefined},
{"ve4i", Builtin::kUndefined}, {"vefK", Builtin::kUndefined},
{"vgg4", Builtin::kUndefined}, {"vecu", Builtin::kUndefined},
{"4TNc4u", Builtin::kUndefined},
};
using BuiltinParseTest = testing::TestWithParam<Case>;

View File

@ -86,19 +86,17 @@ const sem::Call* AppendVector(ProgramBuilder* b,
packed_el_sem_ty = vector_ty;
}
const ast::Type* packed_el_ast_ty = nullptr;
if (packed_el_sem_ty->Is<type::I32>()) {
packed_el_ast_ty = b->create<ast::I32>();
} else if (packed_el_sem_ty->Is<type::U32>()) {
packed_el_ast_ty = b->create<ast::U32>();
} else if (packed_el_sem_ty->Is<type::F32>()) {
packed_el_ast_ty = b->create<ast::F32>();
} else if (packed_el_sem_ty->Is<type::Bool>()) {
packed_el_ast_ty = b->create<ast::Bool>();
} else {
TINT_UNREACHABLE(Writer, b->Diagnostics())
<< "unsupported vector element type: " << packed_el_sem_ty->TypeInfo().name;
}
const ast::Type* packed_el_ast_ty = Switch(
packed_el_sem_ty, //
[&](const type::I32*) { return b->ty.i32(); },
[&](const type::U32*) { return b->ty.u32(); },
[&](const type::F32*) { return b->ty.f32(); },
[&](const type::Bool*) { return b->ty.bool_(); },
[&](Default) {
TINT_UNREACHABLE(Writer, b->Diagnostics())
<< "unsupported vector element type: " << packed_el_sem_ty->TypeInfo().name;
return nullptr;
});
auto* statement = vector_sem->Stmt();

View File

@ -86,7 +86,9 @@ TEST_F(AppendVectorTest, Vec2i32_u32) {
EXPECT_EQ(vec_123->args[1], scalar_2);
auto* u32_to_i32 = vec_123->args[2]->As<ast::CallExpression>();
ASSERT_NE(u32_to_i32, nullptr);
EXPECT_TRUE(u32_to_i32->target.type->Is<ast::I32>());
ASSERT_TRUE(u32_to_i32->target.type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(u32_to_i32->target.type->As<ast::TypeName>()->name->symbol), "i32");
ASSERT_EQ(u32_to_i32->args.Length(), 1u);
EXPECT_EQ(u32_to_i32->args[0], scalar_3);
@ -132,13 +134,18 @@ TEST_F(AppendVectorTest, Vec2i32FromVec2u32_u32) {
ASSERT_NE(v2u32_to_v2i32, nullptr);
ASSERT_TRUE(v2u32_to_v2i32->target.type->Is<ast::Vector>());
EXPECT_EQ(v2u32_to_v2i32->target.type->As<ast::Vector>()->width, 2u);
EXPECT_TRUE(v2u32_to_v2i32->target.type->As<ast::Vector>()->type->Is<ast::I32>());
ASSERT_TRUE(v2u32_to_v2i32->target.type->As<ast::Vector>()->type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(v2u32_to_v2i32->target.type->As<ast::Vector>()
->type->As<ast::TypeName>()
->name->symbol),
"i32");
EXPECT_EQ(v2u32_to_v2i32->args.Length(), 1u);
EXPECT_EQ(v2u32_to_v2i32->args[0], uvec_12);
auto* u32_to_i32 = vec_123->args[1]->As<ast::CallExpression>();
ASSERT_NE(u32_to_i32, nullptr);
EXPECT_TRUE(u32_to_i32->target.type->Is<ast::I32>());
ASSERT_TRUE(u32_to_i32->target.type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(u32_to_i32->target.type->As<ast::TypeName>()->name->symbol), "i32");
ASSERT_EQ(u32_to_i32->args.Length(), 1u);
EXPECT_EQ(u32_to_i32->args[0], scalar_3);
@ -180,7 +187,8 @@ TEST_F(AppendVectorTest, Vec2i32_f32) {
EXPECT_EQ(vec_123->args[1], scalar_2);
auto* f32_to_i32 = vec_123->args[2]->As<ast::CallExpression>();
ASSERT_NE(f32_to_i32, nullptr);
EXPECT_TRUE(f32_to_i32->target.type->Is<ast::I32>());
ASSERT_TRUE(f32_to_i32->target.type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(f32_to_i32->target.type->As<ast::TypeName>()->name->symbol), "i32");
ASSERT_EQ(f32_to_i32->args.Length(), 1u);
EXPECT_EQ(f32_to_i32->args[0], scalar_3);
@ -381,7 +389,8 @@ TEST_F(AppendVectorTest, Vec2i32Var_f32Var) {
EXPECT_EQ(vec_123->args[0], vec_12);
auto* f32_to_i32 = vec_123->args[1]->As<ast::CallExpression>();
ASSERT_NE(f32_to_i32, nullptr);
EXPECT_TRUE(f32_to_i32->target.type->Is<ast::I32>());
ASSERT_TRUE(f32_to_i32->target.type->Is<ast::TypeName>());
EXPECT_EQ(Symbols().NameFor(f32_to_i32->target.type->As<ast::TypeName>()->name->symbol), "i32");
ASSERT_EQ(f32_to_i32->args.Length(), 1u);
EXPECT_EQ(f32_to_i32->args[0], scalar_3);

View File

@ -19,14 +19,11 @@
#include "src/tint/ast/alias.h"
#include "src/tint/ast/array.h"
#include "src/tint/ast/atomic.h"
#include "src/tint/ast/bool.h"
#include "src/tint/ast/bool_literal_expression.h"
#include "src/tint/ast/call_statement.h"
#include "src/tint/ast/depth_texture.h"
#include "src/tint/ast/external_texture.h"
#include "src/tint/ast/f32.h"
#include "src/tint/ast/float_literal_expression.h"
#include "src/tint/ast/i32.h"
#include "src/tint/ast/id_attribute.h"
#include "src/tint/ast/internal_attribute.h"
#include "src/tint/ast/interpolate_attribute.h"
@ -43,7 +40,6 @@
#include "src/tint/ast/struct_member_offset_attribute.h"
#include "src/tint/ast/struct_member_size_attribute.h"
#include "src/tint/ast/type_name.h"
#include "src/tint/ast/u32.h"
#include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/ast/vector.h"
#include "src/tint/ast/workgroup_attribute.h"
@ -423,22 +419,6 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) {
}
return true;
},
[&](const ast::Bool*) {
out << "bool";
return true;
},
[&](const ast::F32*) {
out << "f32";
return true;
},
[&](const ast::F16*) {
out << "f16";
return true;
},
[&](const ast::I32*) {
out << "i32";
return true;
},
[&](const ast::Matrix* mat) {
out << "mat" << mat->columns << "x" << mat->rows;
if (auto* el_ty = mat->type) {
@ -574,10 +554,6 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) {
return true;
});
},
[&](const ast::U32*) {
out << "u32";
return true;
},
[&](const ast::Vector* vec) {
out << "vec" << vec->width;
if (auto* el_ty = vec->type) {