tint/type: Rename ShortName to type::Builtin

These will include the builtin language types.

Bug: tint:1810
Change-Id: I695a9ee833e1035eb1d17913d709038ae4c561d8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118502
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2023-02-07 13:35:58 +00:00
committed by Dawn LUCI CQ
parent a5ea0a1450
commit ad73301856
21 changed files with 353 additions and 318 deletions

View File

@@ -24,7 +24,7 @@
#include "src/tint/sem/type_conversion.h"
#include "src/tint/sem/type_initializer.h"
#include "src/tint/text/unicode.h"
#include "src/tint/type/short_name.h"
#include "src/tint/type/builtin.h"
TINT_INSTANTIATE_TYPEINFO(tint::transform::Renamer);
TINT_INSTANTIATE_TYPEINFO(tint::transform::Renamer::Data);
@@ -1266,9 +1266,9 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
auto is_type_short_name = [&](const Symbol& symbol) {
auto name = src->Symbols().NameFor(symbol);
if (type::ParseShortName(name) != type::ShortName::kUndefined) {
// Identifier *looks* like a builtin short-name, but check the using actually
// shadowing a short-name with a type alias.
if (type::ParseBuiltin(name) != type::Builtin::kUndefined) {
// Identifier *looks* like a builtin type, but check that the builtin type isn't being
// shadowed with a user declared type.
for (auto* decl : src->AST().TypeDecls()) {
if (decl->name == symbol) {
return false;

View File

@@ -18,7 +18,7 @@
#include "gmock/gmock.h"
#include "src/tint/transform/test_helper.h"
#include "src/tint/type/short_name.h"
#include "src/tint/type/builtin.h"
namespace tint::transform {
namespace {
@@ -1500,7 +1500,7 @@ INSTANTIATE_TEST_SUITE_P(
// "while" // WGSL reserved keyword
kUnicodeIdentifier));
const char* ExpandShortName(std::string_view name) {
const char* ExpandBuiltinType(std::string_view name) {
if (name == "mat2x2f") {
return "mat2x2<f32>";
}
@@ -1591,16 +1591,16 @@ const char* ExpandShortName(std::string_view name) {
if (name == "vec4u") {
return "vec4<u32>";
}
ADD_FAILURE() << "unhandled type short-name: " << name;
ADD_FAILURE() << "unhandled type: " << name;
return "<invalid>";
}
using RenamerTypeShortNamesTest = TransformTestWithParam<const char*>;
using RenamerTypeBuiltinTypesTest = TransformTestWithParam<const char*>;
TEST_P(RenamerTypeShortNamesTest, PreserveTypeUsage) {
TEST_P(RenamerTypeBuiltinTypesTest, PreserveTypeUsage) {
auto expand = [&](const char* source) {
auto out = utils::ReplaceAll(source, "$name", GetParam());
out = utils::ReplaceAll(out, "$type", ExpandShortName(GetParam()));
out = utils::ReplaceAll(out, "$type", ExpandBuiltinType(GetParam()));
return out;
};
@@ -1638,10 +1638,10 @@ struct tint_symbol_5 {
EXPECT_EQ(expect, str(got));
}
TEST_P(RenamerTypeShortNamesTest, PreserveTypeInitializer) {
TEST_P(RenamerTypeBuiltinTypesTest, PreserveTypeInitializer) {
auto expand = [&](const char* source) {
auto out = utils::ReplaceAll(source, "$name", GetParam());
out = utils::ReplaceAll(out, "$type", ExpandShortName(GetParam()));
out = utils::ReplaceAll(out, "$type", ExpandBuiltinType(GetParam()));
return out;
};
@@ -1668,10 +1668,10 @@ fn tint_symbol() {
EXPECT_EQ(expect, str(got));
}
TEST_P(RenamerTypeShortNamesTest, PreserveTypeConversion) {
TEST_P(RenamerTypeBuiltinTypesTest, PreserveTypeConversion) {
auto expand = [&](const char* source) {
auto out = utils::ReplaceAll(source, "$name", GetParam());
out = utils::ReplaceAll(out, "$type", ExpandShortName(GetParam()));
out = utils::ReplaceAll(out, "$type", ExpandBuiltinType(GetParam()));
return out;
};
@@ -1698,10 +1698,10 @@ fn tint_symbol() {
EXPECT_EQ(expect, str(got));
}
TEST_P(RenamerTypeShortNamesTest, RenameShadowedByAlias) {
TEST_P(RenamerTypeBuiltinTypesTest, RenameShadowedByAlias) {
auto expand = [&](const char* source) {
auto out = utils::ReplaceAll(source, "$name", GetParam());
out = utils::ReplaceAll(out, "$type", ExpandShortName(GetParam()));
out = utils::ReplaceAll(out, "$type", ExpandBuiltinType(GetParam()));
return out;
};
@@ -1728,10 +1728,10 @@ fn tint_symbol_1() {
EXPECT_EQ(expect, str(got));
}
TEST_P(RenamerTypeShortNamesTest, RenameShadowedByStruct) {
TEST_P(RenamerTypeBuiltinTypesTest, RenameShadowedByStruct) {
auto expand = [&](const char* source) {
auto out = utils::ReplaceAll(source, "$name", GetParam());
out = utils::ReplaceAll(out, "$type", ExpandShortName(GetParam()));
out = utils::ReplaceAll(out, "$type", ExpandBuiltinType(GetParam()));
return out;
};
@@ -1764,9 +1764,9 @@ fn tint_symbol_2() {
EXPECT_EQ(expect, str(got));
}
INSTANTIATE_TEST_SUITE_P(RenamerTypeShortNamesTest,
RenamerTypeShortNamesTest,
testing::ValuesIn(type::kShortNameStrings));
INSTANTIATE_TEST_SUITE_P(RenamerTypeBuiltinTypesTest,
RenamerTypeBuiltinTypesTest,
testing::ValuesIn(type::kBuiltinStrings));
} // namespace
} // namespace tint::transform