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

@ -839,6 +839,8 @@ libtint_source_set("libtint_type_src") {
"type/atomic.h",
"type/bool.cc",
"type/bool.h",
"type/builtin.cc",
"type/builtin.h",
"type/clone_context.h",
"type/depth_multisampled_texture.cc",
"type/depth_multisampled_texture.h",
@ -870,8 +872,6 @@ libtint_source_set("libtint_type_src") {
"type/sampler.h",
"type/sampler_kind.cc",
"type/sampler_kind.h",
"type/short_name.cc",
"type/short_name.h",
"type/storage_texture.cc",
"type/storage_texture.h",
"type/struct.cc",
@ -1511,6 +1511,7 @@ if (tint_build_unittests) {
"type/array_test.cc",
"type/atomic_test.cc",
"type/bool_test.cc",
"type/builtin_test.cc",
"type/depth_multisampled_texture_test.cc",
"type/depth_texture_test.cc",
"type/external_texture_test.cc",
@ -1524,7 +1525,6 @@ if (tint_build_unittests) {
"type/reference_test.cc",
"type/sampled_texture_test.cc",
"type/sampler_test.cc",
"type/short_name_test.cc",
"type/storage_texture_test.cc",
"type/struct_test.cc",
"type/texel_format_test.cc",

View File

@ -591,7 +591,7 @@ tint_generated(sem/builtin_type)
tint_generated(sem/parameter_usage)
tint_generated(type/access BENCH TEST)
tint_generated(type/address_space BENCH TEST)
tint_generated(type/short_name BENCH TEST)
tint_generated(type/builtin BENCH TEST)
tint_generated(type/texel_format BENCH TEST)
if(UNIX)

View File

@ -128,7 +128,7 @@ enum interpolation_sampling {
sample
}
enum short_name {
enum builtin_type {
// https://www.w3.org/TR/WGSL/#matrix-types
mat2x2f
mat2x2h

View File

@ -73,7 +73,7 @@
#include "src/tint/scope_stack.h"
#include "src/tint/sem/builtin.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/short_name.h"
#include "src/tint/type/builtin.h"
#include "src/tint/utils/block_allocator.h"
#include "src/tint/utils/compiler_macros.h"
#include "src/tint/utils/defer.h"
@ -494,7 +494,7 @@ class DependencyScanner {
bool IsBuiltin(Symbol name) const {
auto s = symbols_.NameFor(name);
if (sem::ParseBuiltinType(s) != sem::BuiltinType::kNone ||
type::ParseShortName(s) != type::ShortName::kUndefined) {
type::ParseBuiltin(s) != type::Builtin::kUndefined) {
return true;
}
return false;

View File

@ -116,9 +116,9 @@ TEST_F(ResolverF16ExtensionTest, F16LiteralUsedWithoutExtension) {
EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled");
}
using ResolverF16ExtensionShortNameTest = ResolverTestWithParam<const char*>;
using ResolverF16ExtensionBuiltinTypeAliasTest = ResolverTestWithParam<const char*>;
TEST_P(ResolverF16ExtensionShortNameTest, Vec2hTypeUsedWithExtension) {
TEST_P(ResolverF16ExtensionBuiltinTypeAliasTest, Vec2hTypeUsedWithExtension) {
// enable f16;
// var<private> v : vec2h;
Enable(ast::Extension::kF16);
@ -128,7 +128,7 @@ TEST_P(ResolverF16ExtensionShortNameTest, Vec2hTypeUsedWithExtension) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
}
TEST_P(ResolverF16ExtensionShortNameTest, Vec2hTypeUsedWithoutExtension) {
TEST_P(ResolverF16ExtensionBuiltinTypeAliasTest, Vec2hTypeUsedWithoutExtension) {
// var<private> v : vec2h;
GlobalVar("v", ty(Source{{12, 34}}, GetParam()), type::AddressSpace::kPrivate);
@ -136,8 +136,8 @@ TEST_P(ResolverF16ExtensionShortNameTest, Vec2hTypeUsedWithoutExtension) {
EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled");
}
INSTANTIATE_TEST_SUITE_P(ResolverF16ExtensionShortNameTest,
ResolverF16ExtensionShortNameTest,
INSTANTIATE_TEST_SUITE_P(ResolverF16ExtensionBuiltinTypeAliasTest,
ResolverF16ExtensionBuiltinTypeAliasTest,
testing::Values("mat2x2h",
"mat2x3h",
"mat2x4h",

View File

@ -74,6 +74,7 @@
#include "src/tint/type/abstract_int.h"
#include "src/tint/type/array.h"
#include "src/tint/type/atomic.h"
#include "src/tint/type/builtin.h"
#include "src/tint/type/depth_multisampled_texture.h"
#include "src/tint/type/depth_texture.h"
#include "src/tint/type/multisampled_texture.h"
@ -81,7 +82,6 @@
#include "src/tint/type/reference.h"
#include "src/tint/type/sampled_texture.h"
#include "src/tint/type/sampler.h"
#include "src/tint/type/short_name.h"
#include "src/tint/type/storage_texture.h"
#include "src/tint/utils/compiler_macros.h"
#include "src/tint/utils/defer.h"
@ -336,7 +336,7 @@ type::Type* Resolver::Type(const ast::Type* ty) {
AddError("cannot use builtin '" + name + "' as type", ty->source);
return nullptr;
}
return ShortName(t->name->symbol, t->source);
return BuiltinType(t->name->symbol, t->source);
}
return Switch(
resolved, //
@ -2332,7 +2332,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
builtin_type != sem::BuiltinType::kNone) {
return BuiltinCall(expr, builtin_type, args);
}
if (auto* alias = ShortName(ident->symbol, ident->source)) {
if (auto* alias = BuiltinType(ident->symbol, ident->source)) {
return ty_init_or_conv(alias);
}
return nullptr;
@ -2436,87 +2436,87 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr,
return call;
}
type::Type* Resolver::ShortName(Symbol sym, const Source& source) const {
type::Type* Resolver::BuiltinType(Symbol sym, const Source& source) const {
auto name = builder_->Symbols().NameFor(sym);
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); };
switch (type::ParseShortName(name)) {
case type::ShortName::kMat2X2F:
switch (type::ParseBuiltin(name)) {
case type::Builtin::kMat2X2F:
return b.create<type::Matrix>(vec_f32(2u), 2u);
case type::ShortName::kMat2X3F:
case type::Builtin::kMat2X3F:
return b.create<type::Matrix>(vec_f32(3u), 2u);
case type::ShortName::kMat2X4F:
case type::Builtin::kMat2X4F:
return b.create<type::Matrix>(vec_f32(4u), 2u);
case type::ShortName::kMat3X2F:
case type::Builtin::kMat3X2F:
return b.create<type::Matrix>(vec_f32(2u), 3u);
case type::ShortName::kMat3X3F:
case type::Builtin::kMat3X3F:
return b.create<type::Matrix>(vec_f32(3u), 3u);
case type::ShortName::kMat3X4F:
case type::Builtin::kMat3X4F:
return b.create<type::Matrix>(vec_f32(4u), 3u);
case type::ShortName::kMat4X2F:
case type::Builtin::kMat4X2F:
return b.create<type::Matrix>(vec_f32(2u), 4u);
case type::ShortName::kMat4X3F:
case type::Builtin::kMat4X3F:
return b.create<type::Matrix>(vec_f32(3u), 4u);
case type::ShortName::kMat4X4F:
case type::Builtin::kMat4X4F:
return b.create<type::Matrix>(vec_f32(4u), 4u);
case type::ShortName::kMat2X2H:
case type::Builtin::kMat2X2H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(2u), 2u)
: nullptr;
case type::ShortName::kMat2X3H:
case type::Builtin::kMat2X3H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(3u), 2u)
: nullptr;
case type::ShortName::kMat2X4H:
case type::Builtin::kMat2X4H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(4u), 2u)
: nullptr;
case type::ShortName::kMat3X2H:
case type::Builtin::kMat3X2H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(2u), 3u)
: nullptr;
case type::ShortName::kMat3X3H:
case type::Builtin::kMat3X3H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(3u), 3u)
: nullptr;
case type::ShortName::kMat3X4H:
case type::Builtin::kMat3X4H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(4u), 3u)
: nullptr;
case type::ShortName::kMat4X2H:
case type::Builtin::kMat4X2H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(2u), 4u)
: nullptr;
case type::ShortName::kMat4X3H:
case type::Builtin::kMat4X3H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(3u), 4u)
: nullptr;
case type::ShortName::kMat4X4H:
case type::Builtin::kMat4X4H:
return validator_.CheckF16Enabled(source) ? b.create<type::Matrix>(vec_f16(4u), 4u)
: nullptr;
case type::ShortName::kVec2F:
case type::Builtin::kVec2F:
return vec_f32(2u);
case type::ShortName::kVec3F:
case type::Builtin::kVec3F:
return vec_f32(3u);
case type::ShortName::kVec4F:
case type::Builtin::kVec4F:
return vec_f32(4u);
case type::ShortName::kVec2H:
case type::Builtin::kVec2H:
return validator_.CheckF16Enabled(source) ? vec_f16(2u) : nullptr;
case type::ShortName::kVec3H:
case type::Builtin::kVec3H:
return validator_.CheckF16Enabled(source) ? vec_f16(3u) : nullptr;
case type::ShortName::kVec4H:
case type::Builtin::kVec4H:
return validator_.CheckF16Enabled(source) ? vec_f16(4u) : nullptr;
case type::ShortName::kVec2I:
case type::Builtin::kVec2I:
return b.create<type::Vector>(b.create<type::I32>(), 2u);
case type::ShortName::kVec3I:
case type::Builtin::kVec3I:
return b.create<type::Vector>(b.create<type::I32>(), 3u);
case type::ShortName::kVec4I:
case type::Builtin::kVec4I:
return b.create<type::Vector>(b.create<type::I32>(), 4u);
case type::ShortName::kVec2U:
case type::Builtin::kVec2U:
return b.create<type::Vector>(b.create<type::U32>(), 2u);
case type::ShortName::kVec3U:
case type::Builtin::kVec3U:
return b.create<type::Vector>(b.create<type::U32>(), 3u);
case type::ShortName::kVec4U:
case type::Builtin::kVec4U:
return b.create<type::Vector>(b.create<type::U32>(), 4u);
case type::ShortName::kUndefined:
case type::Builtin::kUndefined:
break;
}
TINT_ICE(Resolver, diagnostics_) << source << " unhandled type short name '" << name << "'";
TINT_ICE(Resolver, diagnostics_) << source << " unhandled builtin type '" << name << "'";
return nullptr;
}
@ -2764,7 +2764,7 @@ sem::ValueExpression* Resolver::Identifier(const ast::IdentifierExpression* expr
}
if (sem_.ResolvedSymbol<type::Type>(expr) ||
type::ParseShortName(builder_->Symbols().NameFor(symbol)) != type::ShortName::kUndefined) {
type::ParseBuiltin(builder_->Symbols().NameFor(symbol)) != type::Builtin::kUndefined) {
AddError("missing '(' for type initializer or cast", expr->source.End());
return nullptr;
}

View File

@ -431,9 +431,9 @@ class Resolver {
/// @returns true if the symbol is the name of a builtin function.
bool IsBuiltin(Symbol) const;
/// @returns the type short-name alias for the symbol @p symbol at @p source
/// @note: Will raise an ICE if @p symbol is not a short-name type.
type::Type* ShortName(Symbol symbol, const Source& source) const;
/// @returns the builtin type for the symbol @p symbol at @p source
/// @note: Will raise an ICE if @p symbol is not a builtin type.
type::Type* BuiltinType(Symbol symbol, const Source& source) const;
// ArrayInitializerSig represents a unique array initializer signature.
// It is a tuple of the array type, number of arguments provided and earliest evaluation stage.

View File

@ -181,7 +181,7 @@ TEST_F(ResolverValidationTest, Expr_DontCall_Type) {
EXPECT_EQ(r()->error(), "12:34 error: missing '(' for type initializer or cast");
}
TEST_F(ResolverValidationTest, Expr_DontCall_ShortName) {
TEST_F(ResolverValidationTest, Expr_DontCall_BuiltinType) {
WrapInFunction(Expr(Source{{12, 34}}, "vec3f"));
EXPECT_FALSE(r()->Resolve());

View File

@ -1,16 +1,45 @@
{{- (Globals).Put "enum_override_names" Map -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- define "OverrideEnumName" -}}
{{- /* Overrides the C++ name for a sem.Enum. */ -}}
{{- /* Arguments: */ -}}
{{- /* * 'Enum' the sem::Enum */ -}}
{{- /* * 'Name' the new C++ name for enum */ -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- $enum_override_names := (Globals).Get "enum_override_names" -}}
{{- $enum_override_names.Put $.Enum $.Name -}}
{{- end -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- define "EnumName" -}}
{{- /* Prints the C++ name for the given sem.Enum argument. */ -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- $enum_override_names := (Globals).Get "enum_override_names" -}}
{{- $override := $enum_override_names.Get $ -}}
{{ if $override -}}
{{ $override -}}
{{ else -}}
{{ PascalCase $.Name}}
{{- end -}}
{{- end -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- define "EnumCase" -}}
{{- /* Prints the 'Enum::kEntry' name for the provided sem.EnumEntry */ -}}
{{- /* argument. */ -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{PascalCase $.Enum.Name}}::k{{PascalCase $.Name}}
{{- Eval "EnumName" $.Enum}}::k{{PascalCase $.Name}}
{{- end -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- define "DeclareEnum" -}}
{{- /* Declares the 'enum class' for the provided sem.Enum argument. */ -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- $enum := PascalCase $.Name -}}
{{- $enum := Eval "EnumName" $ -}}
enum class {{$enum}} {
kUndefined,
{{- range $entry := $.Entries }}
@ -44,7 +73,7 @@ constexpr const char* k{{$enum}}Strings[] = {
{{- /* Implements the 'ParseEnum' function for the provided sem.Enum */ -}}
{{- /* argument. */ -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- $enum := PascalCase $.Name -}}
{{- $enum := Eval "EnumName" $ -}}
/// Parse{{$enum}} parses a {{$enum}} from a string.
/// @param str the string to parse
/// @returns the parsed enum, or {{$enum}}::kUndefined if the string could not be parsed.
@ -64,7 +93,7 @@ constexpr const char* k{{$enum}}Strings[] = {
{{- /* Implements the std::ostream 'operator<<()' function to print the */ -}}
{{- /* provided sem.Enum. */ -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- $enum := PascalCase $.Name -}}
{{- $enum := Eval "EnumName" $ -}}
std::ostream& operator<<(std::ostream& out, {{$enum}} value) {
switch (value) {
case {{$enum}}::kUndefined:
@ -84,7 +113,7 @@ std::ostream& operator<<(std::ostream& out, {{$enum}} value) {
{{- /* Implements unit tests for parsing and printing the provided */ -}}
{{- /* sem.Enum argument. */ -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- $enum := PascalCase $.Name -}}
{{- $enum := Eval "EnumName" $ -}}
namespace parse_print_tests {
struct Case {
@ -142,7 +171,7 @@ INSTANTIATE_TEST_SUITE_P(ValidCases, {{$enum}}PrintTest, testing::ValuesIn(kVali
{{- /* Implements a micro-benchmark for parsing the provided sem.Enum */ -}}
{{- /* argument. */ -}}
{{- /* ------------------------------------------------------------------ */ -}}
{{- $enum := PascalCase $.Name -}}
{{- $enum := Eval "EnumName" $ -}}
void {{$enum}}Parser(::benchmark::State& state) {
std::array kStrings{
{{- $exclude := $.NameSet -}}

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

View File

@ -15,175 +15,175 @@
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/short_name.cc.tmpl
// src/tint/type/builtin.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/short_name.h"
#include "src/tint/type/builtin.h"
namespace tint::type {
/// ParseShortName parses a ShortName from a string.
/// ParseBuiltin parses a Builtin from a string.
/// @param str the string to parse
/// @returns the parsed enum, or ShortName::kUndefined if the string could not be parsed.
ShortName ParseShortName(std::string_view str) {
/// @returns the parsed enum, or Builtin::kUndefined if the string could not be parsed.
Builtin ParseBuiltin(std::string_view str) {
if (str == "mat2x2f") {
return ShortName::kMat2X2F;
return Builtin::kMat2X2F;
}
if (str == "mat2x2h") {
return ShortName::kMat2X2H;
return Builtin::kMat2X2H;
}
if (str == "mat2x3f") {
return ShortName::kMat2X3F;
return Builtin::kMat2X3F;
}
if (str == "mat2x3h") {
return ShortName::kMat2X3H;
return Builtin::kMat2X3H;
}
if (str == "mat2x4f") {
return ShortName::kMat2X4F;
return Builtin::kMat2X4F;
}
if (str == "mat2x4h") {
return ShortName::kMat2X4H;
return Builtin::kMat2X4H;
}
if (str == "mat3x2f") {
return ShortName::kMat3X2F;
return Builtin::kMat3X2F;
}
if (str == "mat3x2h") {
return ShortName::kMat3X2H;
return Builtin::kMat3X2H;
}
if (str == "mat3x3f") {
return ShortName::kMat3X3F;
return Builtin::kMat3X3F;
}
if (str == "mat3x3h") {
return ShortName::kMat3X3H;
return Builtin::kMat3X3H;
}
if (str == "mat3x4f") {
return ShortName::kMat3X4F;
return Builtin::kMat3X4F;
}
if (str == "mat3x4h") {
return ShortName::kMat3X4H;
return Builtin::kMat3X4H;
}
if (str == "mat4x2f") {
return ShortName::kMat4X2F;
return Builtin::kMat4X2F;
}
if (str == "mat4x2h") {
return ShortName::kMat4X2H;
return Builtin::kMat4X2H;
}
if (str == "mat4x3f") {
return ShortName::kMat4X3F;
return Builtin::kMat4X3F;
}
if (str == "mat4x3h") {
return ShortName::kMat4X3H;
return Builtin::kMat4X3H;
}
if (str == "mat4x4f") {
return ShortName::kMat4X4F;
return Builtin::kMat4X4F;
}
if (str == "mat4x4h") {
return ShortName::kMat4X4H;
return Builtin::kMat4X4H;
}
if (str == "vec2f") {
return ShortName::kVec2F;
return Builtin::kVec2F;
}
if (str == "vec2h") {
return ShortName::kVec2H;
return Builtin::kVec2H;
}
if (str == "vec2i") {
return ShortName::kVec2I;
return Builtin::kVec2I;
}
if (str == "vec2u") {
return ShortName::kVec2U;
return Builtin::kVec2U;
}
if (str == "vec3f") {
return ShortName::kVec3F;
return Builtin::kVec3F;
}
if (str == "vec3h") {
return ShortName::kVec3H;
return Builtin::kVec3H;
}
if (str == "vec3i") {
return ShortName::kVec3I;
return Builtin::kVec3I;
}
if (str == "vec3u") {
return ShortName::kVec3U;
return Builtin::kVec3U;
}
if (str == "vec4f") {
return ShortName::kVec4F;
return Builtin::kVec4F;
}
if (str == "vec4h") {
return ShortName::kVec4H;
return Builtin::kVec4H;
}
if (str == "vec4i") {
return ShortName::kVec4I;
return Builtin::kVec4I;
}
if (str == "vec4u") {
return ShortName::kVec4U;
return Builtin::kVec4U;
}
return ShortName::kUndefined;
return Builtin::kUndefined;
}
std::ostream& operator<<(std::ostream& out, ShortName value) {
std::ostream& operator<<(std::ostream& out, Builtin value) {
switch (value) {
case ShortName::kUndefined:
case Builtin::kUndefined:
return out << "undefined";
case ShortName::kMat2X2F:
case Builtin::kMat2X2F:
return out << "mat2x2f";
case ShortName::kMat2X2H:
case Builtin::kMat2X2H:
return out << "mat2x2h";
case ShortName::kMat2X3F:
case Builtin::kMat2X3F:
return out << "mat2x3f";
case ShortName::kMat2X3H:
case Builtin::kMat2X3H:
return out << "mat2x3h";
case ShortName::kMat2X4F:
case Builtin::kMat2X4F:
return out << "mat2x4f";
case ShortName::kMat2X4H:
case Builtin::kMat2X4H:
return out << "mat2x4h";
case ShortName::kMat3X2F:
case Builtin::kMat3X2F:
return out << "mat3x2f";
case ShortName::kMat3X2H:
case Builtin::kMat3X2H:
return out << "mat3x2h";
case ShortName::kMat3X3F:
case Builtin::kMat3X3F:
return out << "mat3x3f";
case ShortName::kMat3X3H:
case Builtin::kMat3X3H:
return out << "mat3x3h";
case ShortName::kMat3X4F:
case Builtin::kMat3X4F:
return out << "mat3x4f";
case ShortName::kMat3X4H:
case Builtin::kMat3X4H:
return out << "mat3x4h";
case ShortName::kMat4X2F:
case Builtin::kMat4X2F:
return out << "mat4x2f";
case ShortName::kMat4X2H:
case Builtin::kMat4X2H:
return out << "mat4x2h";
case ShortName::kMat4X3F:
case Builtin::kMat4X3F:
return out << "mat4x3f";
case ShortName::kMat4X3H:
case Builtin::kMat4X3H:
return out << "mat4x3h";
case ShortName::kMat4X4F:
case Builtin::kMat4X4F:
return out << "mat4x4f";
case ShortName::kMat4X4H:
case Builtin::kMat4X4H:
return out << "mat4x4h";
case ShortName::kVec2F:
case Builtin::kVec2F:
return out << "vec2f";
case ShortName::kVec2H:
case Builtin::kVec2H:
return out << "vec2h";
case ShortName::kVec2I:
case Builtin::kVec2I:
return out << "vec2i";
case ShortName::kVec2U:
case Builtin::kVec2U:
return out << "vec2u";
case ShortName::kVec3F:
case Builtin::kVec3F:
return out << "vec3f";
case ShortName::kVec3H:
case Builtin::kVec3H:
return out << "vec3h";
case ShortName::kVec3I:
case Builtin::kVec3I:
return out << "vec3i";
case ShortName::kVec3U:
case Builtin::kVec3U:
return out << "vec3u";
case ShortName::kVec4F:
case Builtin::kVec4F:
return out << "vec4f";
case ShortName::kVec4H:
case Builtin::kVec4H:
return out << "vec4h";
case ShortName::kVec4I:
case Builtin::kVec4I:
return out << "vec4i";
case ShortName::kVec4U:
case Builtin::kVec4U:
return out << "vec4u";
}
return out << "<unknown>";

View File

@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate short_name.cc
Template file for use with tools/src/cmd/gen to generate builtin.cc
To update the generated file, run:
./tools/run gen
@ -12,9 +12,10 @@ See:
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "short_name") -}}
{{- $enum := (Sem.Enum "builtin_type") -}}
{{- Eval "OverrideEnumName" "Enum" $enum "Name" "Builtin" -}}
#include "src/tint/type/short_name.h"
#include "src/tint/type/builtin.h"
namespace tint::type {

View File

@ -15,20 +15,20 @@
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/short_name.h.tmpl
// src/tint/type/builtin.h.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_TINT_TYPE_SHORT_NAME_H_
#define SRC_TINT_TYPE_SHORT_NAME_H_
#ifndef SRC_TINT_TYPE_BUILTIN_H_
#define SRC_TINT_TYPE_BUILTIN_H_
#include <ostream>
namespace tint::type {
/// An enumerator of builtin type aliases.
enum class ShortName {
/// An enumerator of builtin types.
enum class Builtin {
kUndefined,
kMat2X2F,
kMat2X2H,
@ -63,16 +63,16 @@ enum class ShortName {
};
/// @param out the std::ostream to write to
/// @param value the ShortName
/// @param value the Builtin
/// @returns `out` so calls can be chained
std::ostream& operator<<(std::ostream& out, ShortName value);
std::ostream& operator<<(std::ostream& out, Builtin value);
/// ParseShortName parses a ShortName from a string.
/// ParseBuiltin parses a Builtin from a string.
/// @param str the string to parse
/// @returns the parsed enum, or ShortName::kUndefined if the string could not be parsed.
ShortName ParseShortName(std::string_view str);
/// @returns the parsed enum, or Builtin::kUndefined if the string could not be parsed.
Builtin ParseBuiltin(std::string_view str);
constexpr const char* kShortNameStrings[] = {
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",
@ -81,4 +81,4 @@ constexpr const char* kShortNameStrings[] = {
} // namespace tint::type
#endif // SRC_TINT_TYPE_SHORT_NAME_H_
#endif // SRC_TINT_TYPE_BUILTIN_H_

View File

@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate short_name.h
Template file for use with tools/src/cmd/gen to generate builtin.h
To update the generated file, run:
./tools/run gen
@ -12,18 +12,19 @@ See:
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "short_name") -}}
{{- $enum := (Sem.Enum "builtin_type") -}}
{{- Eval "OverrideEnumName" "Enum" $enum "Name" "Builtin" -}}
#ifndef SRC_TINT_TYPE_SHORT_NAME_H_
#define SRC_TINT_TYPE_SHORT_NAME_H_
#ifndef SRC_TINT_TYPE_BUILTIN_H_
#define SRC_TINT_TYPE_BUILTIN_H_
#include <ostream>
namespace tint::type {
/// An enumerator of builtin type aliases.
/// An enumerator of builtin types.
{{ Eval "DeclareEnum" $enum}}
} // namespace tint::type
#endif // SRC_TINT_TYPE_SHORT_NAME_H_
#endif // SRC_TINT_TYPE_BUILTIN_H_

View File

@ -15,12 +15,12 @@
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/short_name_bench.cc.tmpl
// src/tint/type/builtin_bench.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/short_name.h"
#include "src/tint/type/builtin.h"
#include <array>
@ -29,7 +29,7 @@
namespace tint::type {
namespace {
void ShortNameParser(::benchmark::State& state) {
void BuiltinParser(::benchmark::State& state) {
std::array kStrings{
"at2x2cc", "l23f", "matVx2f", "mat2x2f", "mat212f", "mqtJx2f",
"mat2x27ll", "ppqqt22HH", "macv", "bt2xGh", "mat2x2h", "mat2iivh",
@ -69,13 +69,13 @@ void ShortNameParser(::benchmark::State& state) {
};
for (auto _ : state) {
for (auto& str : kStrings) {
auto result = ParseShortName(str);
auto result = ParseBuiltin(str);
benchmark::DoNotOptimize(result);
}
}
}
BENCHMARK(ShortNameParser);
BENCHMARK(BuiltinParser);
} // namespace
} // namespace tint::type

View File

@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate short_name_bench.cc
Template file for use with tools/src/cmd/gen to generate builtin_bench.cc
To update the generated file, run:
./tools/run gen
@ -12,9 +12,10 @@ See:
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "short_name") -}}
{{- $enum := (Sem.Enum "builtin_type") -}}
{{- Eval "OverrideEnumName" "Enum" $enum "Name" "Builtin" -}}
#include "src/tint/type/short_name.h"
#include "src/tint/type/builtin.h"
#include <array>

View File

@ -0,0 +1,130 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/builtin_test.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/builtin.h"
#include <string>
#include "gtest/gtest.h"
#include "src/tint/utils/string.h"
namespace tint::type {
namespace {
namespace parse_print_tests {
struct Case {
const char* string;
Builtin value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
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},
};
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},
{"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},
};
using BuiltinParseTest = testing::TestWithParam<Case>;
TEST_P(BuiltinParseTest, Parse) {
const char* string = GetParam().string;
Builtin expect = GetParam().value;
EXPECT_EQ(expect, ParseBuiltin(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, BuiltinParseTest, testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases, BuiltinParseTest, testing::ValuesIn(kInvalidCases));
using BuiltinPrintTest = testing::TestWithParam<Case>;
TEST_P(BuiltinPrintTest, Print) {
Builtin value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, BuiltinPrintTest, testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace
} // namespace tint::type

View File

@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate short_name_test.cc
Template file for use with tools/src/cmd/gen to generate builtin_test.cc
To update the generated file, run:
./tools/run gen
@ -12,9 +12,10 @@ See:
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "short_name") -}}
{{- $enum := (Sem.Enum "builtin_type") -}}
{{- Eval "OverrideEnumName" "Enum" $enum "Name" "Builtin" -}}
#include "src/tint/type/short_name.h"
#include "src/tint/type/builtin.h"
#include <string>

View File

@ -1,135 +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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/type/short_name_test.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/type/short_name.h"
#include <string>
#include "gtest/gtest.h"
#include "src/tint/utils/string.h"
namespace tint::type {
namespace {
namespace parse_print_tests {
struct Case {
const char* string;
ShortName value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"mat2x2f", ShortName::kMat2X2F}, {"mat2x2h", ShortName::kMat2X2H},
{"mat2x3f", ShortName::kMat2X3F}, {"mat2x3h", ShortName::kMat2X3H},
{"mat2x4f", ShortName::kMat2X4F}, {"mat2x4h", ShortName::kMat2X4H},
{"mat3x2f", ShortName::kMat3X2F}, {"mat3x2h", ShortName::kMat3X2H},
{"mat3x3f", ShortName::kMat3X3F}, {"mat3x3h", ShortName::kMat3X3H},
{"mat3x4f", ShortName::kMat3X4F}, {"mat3x4h", ShortName::kMat3X4H},
{"mat4x2f", ShortName::kMat4X2F}, {"mat4x2h", ShortName::kMat4X2H},
{"mat4x3f", ShortName::kMat4X3F}, {"mat4x3h", ShortName::kMat4X3H},
{"mat4x4f", ShortName::kMat4X4F}, {"mat4x4h", ShortName::kMat4X4H},
{"vec2f", ShortName::kVec2F}, {"vec2h", ShortName::kVec2H},
{"vec2i", ShortName::kVec2I}, {"vec2u", ShortName::kVec2U},
{"vec3f", ShortName::kVec3F}, {"vec3h", ShortName::kVec3H},
{"vec3i", ShortName::kVec3I}, {"vec3u", ShortName::kVec3U},
{"vec4f", ShortName::kVec4F}, {"vec4h", ShortName::kVec4H},
{"vec4i", ShortName::kVec4I}, {"vec4u", ShortName::kVec4U},
};
static constexpr Case kInvalidCases[] = {
{"at2x2cc", ShortName::kUndefined}, {"l23f", ShortName::kUndefined},
{"matVx2f", ShortName::kUndefined}, {"mat212h", ShortName::kUndefined},
{"mqtJx2h", ShortName::kUndefined}, {"mat2x27ll", ShortName::kUndefined},
{"ppqqt23HH", ShortName::kUndefined}, {"macv", ShortName::kUndefined},
{"bt2xGf", ShortName::kUndefined}, {"mat2iivh", ShortName::kUndefined},
{"8WWt2x3h", ShortName::kUndefined}, {"mxx2x3h", ShortName::kUndefined},
{"mX2x4gg", ShortName::kUndefined}, {"a2xXf", ShortName::kUndefined},
{"mat234f", ShortName::kUndefined}, {"Eat2x4h", ShortName::kUndefined},
{"mPTT2x4h", ShortName::kUndefined}, {"mat2xdxx", ShortName::kUndefined},
{"m44t3x2f", ShortName::kUndefined}, {"maSS3xVVf", ShortName::kUndefined},
{"RatR22f", ShortName::kUndefined}, {"mF3x9h", ShortName::kUndefined},
{"matx2h", ShortName::kUndefined}, {"VOORRH2h", ShortName::kUndefined},
{"ma3xyf", ShortName::kUndefined}, {"llnarr3773f", ShortName::kUndefined},
{"mat34300", ShortName::kUndefined}, {"a3ooh", ShortName::kUndefined},
{"zz3x3h", ShortName::kUndefined}, {"miitppx1", ShortName::kUndefined},
{"mat3xXXf", ShortName::kUndefined}, {"9II5ann3x4f", ShortName::kUndefined},
{"mataSSrHHYf", ShortName::kUndefined}, {"makkh", ShortName::kUndefined},
{"jatgRx", ShortName::kUndefined}, {"mb3x4", ShortName::kUndefined},
{"mat4xjf", ShortName::kUndefined}, {"at4x2f", ShortName::kUndefined},
{"q4x2f", ShortName::kUndefined}, {"matNN2h", ShortName::kUndefined},
{"at42vv", ShortName::kUndefined}, {"QQt4x2h", ShortName::kUndefined},
{"maffxr", ShortName::kUndefined}, {"mat4xjf", ShortName::kUndefined},
{"mNNw4x38", ShortName::kUndefined}, {"matx3h", ShortName::kUndefined},
{"mrrt4x3h", ShortName::kUndefined}, {"Gat4x3h", ShortName::kUndefined},
{"mat4x4FF", ShortName::kUndefined}, {"at4f", ShortName::kUndefined},
{"marrx4f", ShortName::kUndefined}, {"t4x4h", ShortName::kUndefined},
{"Da4xJJh", ShortName::kUndefined}, {"ma84", ShortName::kUndefined},
{"e2k", ShortName::kUndefined}, {"vecf", ShortName::kUndefined},
{"Jecf", ShortName::kUndefined}, {"ec2h", ShortName::kUndefined},
{"_KKttcH", ShortName::kUndefined}, {"vexxh", ShortName::kUndefined},
{"__qcF", ShortName::kUndefined}, {"vc2qq", ShortName::kUndefined},
{"33e62i", ShortName::kUndefined}, {"6QQott2u", ShortName::kUndefined},
{"v6c2u", ShortName::kUndefined}, {"zzc2O6", ShortName::kUndefined},
{"vyyc3f", ShortName::kUndefined}, {"vcZZ", ShortName::kUndefined},
{"ecWq4f", ShortName::kUndefined}, {"vOO3h", ShortName::kUndefined},
{"oYe3", ShortName::kUndefined}, {"v3", ShortName::kUndefined},
{"Fe3i", ShortName::kUndefined}, {"vwci", ShortName::kUndefined},
{"vefi", ShortName::kUndefined}, {"KKeq3u", ShortName::kUndefined},
{"vFmm3u", ShortName::kUndefined}, {"vecu", ShortName::kUndefined},
{"qc4f", ShortName::kUndefined}, {"vecbb", ShortName::kUndefined},
{"iic4", ShortName::kUndefined}, {"vqOOh", ShortName::kUndefined},
{"vevvTTh", ShortName::kUndefined}, {"veFF4h", ShortName::kUndefined},
{"00PfQ", ShortName::kUndefined}, {"vec4P", ShortName::kUndefined},
{"vec77s", ShortName::kUndefined}, {"vecbbCu", ShortName::kUndefined},
{"vecXXu", ShortName::kUndefined}, {"CCOOec4", ShortName::kUndefined},
};
using ShortNameParseTest = testing::TestWithParam<Case>;
TEST_P(ShortNameParseTest, Parse) {
const char* string = GetParam().string;
ShortName expect = GetParam().value;
EXPECT_EQ(expect, ParseShortName(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, ShortNameParseTest, testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases, ShortNameParseTest, testing::ValuesIn(kInvalidCases));
using ShortNamePrintTest = testing::TestWithParam<Case>;
TEST_P(ShortNamePrintTest, Print) {
ShortName value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, ShortNamePrintTest, testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace
} // namespace tint::type

View File

@ -40,10 +40,13 @@ func Run(tmpl string, w io.Writer, funcs Functions) error {
template: template.New("<template>"),
}
globals := newMap()
// Add a bunch of generic useful functions
g.funcs = Functions{
"Contains": strings.Contains,
"Eval": g.eval,
"Globals": func() Map { return globals },
"HasPrefix": strings.HasPrefix,
"HasSuffix": strings.HasSuffix,
"Import": g.importTmpl,
@ -128,9 +131,13 @@ func (g *generator) importTmpl(path string) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to open '%v': %w", path, err)
}
if err := g.bindAndParse(g.template.New(""), string(data)); err != nil {
t := g.template.New("")
if err := g.bindAndParse(t, string(data)); err != nil {
return "", fmt.Errorf("failed to parse '%v': %w", path, err)
}
if err := t.Execute(ioutil.Discard, nil); err != nil {
return "", fmt.Errorf("failed to execute '%v': %w", path, err)
}
return "", nil
}