Move all classes from namespace `type` to namespace `sem`

Bug: tint:724
Change-Id: I4eeabab9b00b6b28f61645bd95d326fb48609bf0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48362
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2021-04-19 22:51:23 +00:00 committed by Commit Bot service account
parent 3aa226138e
commit 3751fd2290
198 changed files with 3322 additions and 3367 deletions

View File

@ -23,7 +23,7 @@ namespace ast {
BitcastExpression::BitcastExpression(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
Expression* expr)
: Base(program_id, source), type_(type), expr_(expr) {
TINT_ASSERT(type_);

View File

@ -30,14 +30,14 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
/// @param expr the expr
BitcastExpression(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
Expression* expr);
/// Move constructor
BitcastExpression(BitcastExpression&&);
~BitcastExpression() override;
/// @returns the left side expression
type::Type* type() const { return type_; }
sem::Type* type() const { return type_; }
/// @returns the expression
Expression* expr() const { return expr_; }
@ -58,7 +58,7 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
private:
BitcastExpression(const BitcastExpression&) = delete;
type::Type* const type_;
sem::Type* const type_;
Expression* const expr_;
};

View File

@ -23,7 +23,7 @@ namespace ast {
BoolLiteral::BoolLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
bool value)
: Base(program_id, source, type), value_(value) {}

View File

@ -32,7 +32,7 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
/// @param value the bool literals value
BoolLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
bool value);
~BoolLiteral() override;

View File

@ -21,7 +21,7 @@ namespace {
using BoolLiteralTest = TestHelper;
TEST_F(BoolLiteralTest, True) {
type::Bool bool_type;
sem::Bool bool_type;
auto* b = create<BoolLiteral>(&bool_type, true);
ASSERT_TRUE(b->Is<BoolLiteral>());
ASSERT_TRUE(b->IsTrue());
@ -29,7 +29,7 @@ TEST_F(BoolLiteralTest, True) {
}
TEST_F(BoolLiteralTest, False) {
type::Bool bool_type;
sem::Bool bool_type;
auto* b = create<BoolLiteral>(&bool_type, false);
ASSERT_TRUE(b->Is<BoolLiteral>());
ASSERT_FALSE(b->IsTrue());
@ -37,7 +37,7 @@ TEST_F(BoolLiteralTest, False) {
}
TEST_F(BoolLiteralTest, Is) {
type::Bool bool_type;
sem::Bool bool_type;
ast::Literal* l = create<BoolLiteral>(&bool_type, false);
EXPECT_TRUE(l->Is<BoolLiteral>());
EXPECT_FALSE(l->Is<SintLiteral>());
@ -47,7 +47,7 @@ TEST_F(BoolLiteralTest, Is) {
}
TEST_F(BoolLiteralTest, ToStr) {
type::Bool bool_type;
sem::Bool bool_type;
auto* t = create<BoolLiteral>(&bool_type, true);
auto* f = create<BoolLiteral>(&bool_type, false);

View File

@ -25,7 +25,7 @@ namespace ast {
FloatLiteral::FloatLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
float value)
: Base(program_id, source, type), value_(value) {}

View File

@ -32,7 +32,7 @@ class FloatLiteral : public Castable<FloatLiteral, Literal> {
/// @param value the float literals value
FloatLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
float value);
~FloatLiteral() override;

View File

@ -27,7 +27,7 @@ Function::Function(ProgramID program_id,
const Source& source,
Symbol symbol,
VariableList params,
type::Type* return_type,
sem::Type* return_type,
BlockStatement* body,
DecorationList decorations,
DecorationList return_type_decorations)

View File

@ -48,7 +48,7 @@ class Function : public Castable<Function, Node> {
const Source& source,
Symbol symbol,
VariableList params,
type::Type* return_type,
sem::Type* return_type,
BlockStatement* body,
DecorationList decorations,
DecorationList return_type_decorations);
@ -76,7 +76,7 @@ class Function : public Castable<Function, Node> {
bool IsEntryPoint() const { return pipeline_stage() != PipelineStage::kNone; }
/// @returns the function return type.
type::Type* return_type() const { return return_type_; }
sem::Type* return_type() const { return return_type_; }
/// @returns the decorations attached to the function return type.
const DecorationList& return_type_decorations() const {
@ -114,7 +114,7 @@ class Function : public Castable<Function, Node> {
Symbol const symbol_;
VariableList const params_;
type::Type* const return_type_;
sem::Type* const return_type_;
BlockStatement* const body_;
DecorationList const decorations_;
DecorationList const return_type_decorations_;

View File

@ -21,7 +21,7 @@ namespace ast {
IntLiteral::IntLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
uint32_t value)
: Base(program_id, source, type), value_(value) {}

View File

@ -36,7 +36,7 @@ class IntLiteral : public Castable<IntLiteral, Literal> {
/// @param value value of the literal
IntLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
uint32_t value);
private:

File diff suppressed because it is too large Load Diff

View File

@ -182,8 +182,8 @@ struct TextureOverloadCase {
TextureOverloadCase(ValidTextureOverload,
const char*,
TextureKind,
type::SamplerKind,
type::TextureDimension,
sem::SamplerKind,
sem::TextureDimension,
TextureDataType,
const char*,
std::function<ExpressionList(ProgramBuilder*)>);
@ -191,7 +191,7 @@ struct TextureOverloadCase {
TextureOverloadCase(ValidTextureOverload,
const char*,
TextureKind,
type::TextureDimension,
sem::TextureDimension,
TextureDataType,
const char*,
std::function<ExpressionList(ProgramBuilder*)>);
@ -199,8 +199,8 @@ struct TextureOverloadCase {
TextureOverloadCase(ValidTextureOverload,
const char*,
AccessControl,
type::ImageFormat,
type::TextureDimension,
sem::ImageFormat,
sem::TextureDimension,
TextureDataType,
const char*,
std::function<ExpressionList(ProgramBuilder*)>);
@ -215,7 +215,7 @@ struct TextureOverloadCase {
/// @param builder the AST builder used for the test
/// @returns the vector component type of the texture function return value
type::Type* resultVectorComponentType(ProgramBuilder* builder) const;
sem::Type* resultVectorComponentType(ProgramBuilder* builder) const;
/// @param builder the AST builder used for the test
/// @returns a variable holding the test texture, automatically registered as
/// a global variable.
@ -233,15 +233,15 @@ struct TextureOverloadCase {
TextureKind const texture_kind;
/// The sampler kind for the sampler parameter
/// Used only when texture_kind is not kStorage
type::SamplerKind const sampler_kind = type::SamplerKind::kSampler;
sem::SamplerKind const sampler_kind = sem::SamplerKind::kSampler;
/// The access control for the storage texture
/// Used only when texture_kind is kStorage
AccessControl const access_control = AccessControl::kReadWrite;
/// The image format for the storage texture
/// Used only when texture_kind is kStorage
type::ImageFormat const image_format = type::ImageFormat::kNone;
sem::ImageFormat const image_format = sem::ImageFormat::kNone;
/// The dimensions of the texture parameter
type::TextureDimension const texture_dimension;
sem::TextureDimension const texture_dimension;
/// The data type of the texture parameter
TextureDataType const texture_data_type;
/// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc

View File

@ -19,7 +19,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Literal);
namespace tint {
namespace ast {
Literal::Literal(ProgramID program_id, const Source& source, type::Type* type)
Literal::Literal(ProgramID program_id, const Source& source, sem::Type* type)
: Base(program_id, source), type_(type) {}
Literal::~Literal() = default;

View File

@ -28,7 +28,7 @@ class Literal : public Castable<Literal, Node> {
~Literal() override;
/// @returns the type of the literal
type::Type* type() const { return type_; }
sem::Type* type() const { return type_; }
/// Writes a representation of the node to the output stream
/// @param sem the semantic info for the program
@ -50,12 +50,10 @@ class Literal : public Castable<Literal, Node> {
/// @param program_id the identifier of the program that owns this node
/// @param source the input source
/// @param type the type of the literal
explicit Literal(ProgramID program_id,
const Source& source,
type::Type* type);
explicit Literal(ProgramID program_id, const Source& source, sem::Type* type);
private:
type::Type* const type_;
sem::Type* const type_;
};
} // namespace ast

View File

@ -35,7 +35,7 @@ Module::Module(ProgramID program_id,
continue;
}
if (auto* ty = decl->As<type::Type>()) {
if (auto* ty = decl->As<sem::Type>()) {
constructed_types_.push_back(ty);
} else if (auto* func = decl->As<Function>()) {
functions_.push_back(func);
@ -62,7 +62,7 @@ void Module::Copy(CloneContext* ctx, const Module* src) {
TINT_ICE(ctx->dst->Diagnostics()) << "src global declaration was nullptr";
continue;
}
if (auto* ty = decl->As<type::Type>()) {
if (auto* ty = decl->As<sem::Type>()) {
AddConstructedType(ty);
} else if (auto* func = decl->As<Function>()) {
AddFunction(func);
@ -82,13 +82,13 @@ void Module::to_str(const sem::Info& sem,
indent += 2;
for (auto* const ty : constructed_types_) {
make_indent(out, indent);
if (auto* alias = ty->As<type::Alias>()) {
if (auto* alias = ty->As<sem::Alias>()) {
out << alias->symbol().to_str() << " -> " << alias->type()->type_name()
<< std::endl;
if (auto* str = alias->type()->As<type::StructType>()) {
if (auto* str = alias->type()->As<sem::StructType>()) {
str->impl()->to_str(sem, out, indent);
}
} else if (auto* str = ty->As<type::StructType>()) {
} else if (auto* str = ty->As<sem::StructType>()) {
out << str->symbol().to_str() << " ";
str->impl()->to_str(sem, out, indent);
}

View File

@ -67,14 +67,14 @@ class Module : public Castable<Module, Node> {
/// Adds a constructed type to the Builder.
/// The type must be an alias or a struct.
/// @param type the constructed type to add
void AddConstructedType(type::Type* type) {
void AddConstructedType(sem::Type* type) {
TINT_ASSERT(type);
constructed_types_.push_back(type);
global_declarations_.push_back(type);
}
/// @returns the constructed types in the translation unit
const std::vector<type::Type*>& ConstructedTypes() const {
const std::vector<sem::Type*>& ConstructedTypes() const {
return constructed_types_;
}
@ -115,7 +115,7 @@ class Module : public Castable<Module, Node> {
private:
std::vector<Cloneable*> global_declarations_;
std::vector<type::Type*> constructed_types_;
std::vector<sem::Type*> constructed_types_;
FunctionList functions_;
VariableList global_variables_;
};

View File

@ -128,7 +128,7 @@ let declaration_order_check_3 : i32 = 1;
for (auto* src_node : src.ASTNodes().Objects()) {
src_nodes.emplace(src_node);
}
std::unordered_set<type::Type*> src_types;
std::unordered_set<sem::Type*> src_types;
for (auto* src_type : src.Types()) {
src_types.emplace(src_type);
}

View File

@ -24,7 +24,7 @@ namespace tint {
// Forward declarations
class CloneContext;
namespace type {
namespace sem {
class Type;
}
namespace sem {

View File

@ -23,7 +23,7 @@ namespace ast {
SintLiteral::SintLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
int32_t value)
: Base(program_id, source, type, static_cast<uint32_t>(value)) {}

View File

@ -32,7 +32,7 @@ class SintLiteral : public Castable<SintLiteral, IntLiteral> {
/// @param value the signed int literals value
SintLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
int32_t value);
~SintLiteral() override;

View File

@ -45,7 +45,7 @@ TEST_F(SintLiteralTest, Name_I32) {
}
TEST_F(SintLiteralTest, Name_U32) {
type::U32 u32;
sem::U32 u32;
auto* i = create<SintLiteral>(&u32, 2);
EXPECT_EQ("__sint__u32_2", i->name());
}

View File

@ -24,7 +24,7 @@ namespace ast {
StructMember::StructMember(ProgramID program_id,
const Source& source,
const Symbol& sym,
type::Type* type,
sem::Type* type,
DecorationList decorations)
: Base(program_id, source),
symbol_(sym),

View File

@ -35,7 +35,7 @@ class StructMember : public Castable<StructMember, Node> {
StructMember(ProgramID program_id,
const Source& source,
const Symbol& sym,
type::Type* type,
sem::Type* type,
DecorationList decorations);
/// Move constructor
StructMember(StructMember&&);
@ -45,7 +45,7 @@ class StructMember : public Castable<StructMember, Node> {
/// @returns the symbol
const Symbol& symbol() const { return symbol_; }
/// @returns the type
type::Type* type() const { return type_; }
sem::Type* type() const { return type_; }
/// @returns the decorations
const DecorationList& decorations() const { return decorations_; }
@ -73,7 +73,7 @@ class StructMember : public Castable<StructMember, Node> {
StructMember(const StructMember&) = delete;
Symbol const symbol_;
type::Type* const type_;
sem::Type* const type_;
DecorationList const decorations_;
};

View File

@ -23,7 +23,7 @@ namespace ast {
TypeConstructorExpression::TypeConstructorExpression(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
ExpressionList values)
: Base(program_id, source), type_(type), values_(std::move(values)) {
TINT_ASSERT(type_);

View File

@ -33,14 +33,14 @@ class TypeConstructorExpression
/// @param values the constructor values
TypeConstructorExpression(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
ExpressionList values);
/// Move constructor
TypeConstructorExpression(TypeConstructorExpression&&);
~TypeConstructorExpression() override;
/// @returns the type
type::Type* type() const { return type_; }
sem::Type* type() const { return type_; }
/// @returns the values
const ExpressionList& values() const { return values_; }
@ -61,7 +61,7 @@ class TypeConstructorExpression
private:
TypeConstructorExpression(const TypeConstructorExpression&) = delete;
type::Type* const type_;
sem::Type* const type_;
ExpressionList const values_;
};

View File

@ -81,7 +81,7 @@ TEST_F(TypeConstructorExpressionTest, Assert_DifferentProgramID_Value) {
}
TEST_F(TypeConstructorExpressionTest, ToStr) {
type::Vector vec(ty.f32(), 3);
sem::Vector vec(ty.f32(), 3);
ExpressionList expr;
expr.push_back(Expr("expr_1"));
expr.push_back(Expr("expr_2"));

View File

@ -23,7 +23,7 @@ namespace ast {
UintLiteral::UintLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
uint32_t value)
: Base(program_id, source, type, value) {}

View File

@ -32,7 +32,7 @@ class UintLiteral : public Castable<UintLiteral, IntLiteral> {
/// @param value the uint literals value
UintLiteral(ProgramID program_id,
const Source& source,
type::Type* type,
sem::Type* type,
uint32_t value);
~UintLiteral() override;

View File

@ -27,7 +27,7 @@ Variable::Variable(ProgramID program_id,
const Source& source,
const Symbol& sym,
StorageClass declared_storage_class,
type::Type* declared_type,
sem::Type* declared_type,
bool is_const,
Expression* constructor,
DecorationList decorations)

View File

@ -103,7 +103,7 @@ class Variable : public Castable<Variable, Node> {
const Source& source,
const Symbol& sym,
StorageClass declared_storage_class,
type::Type* declared_type,
sem::Type* declared_type,
bool is_const,
Expression* constructor,
DecorationList decorations);
@ -116,7 +116,7 @@ class Variable : public Castable<Variable, Node> {
const Symbol& symbol() const { return symbol_; }
/// @returns the declared type
type::Type* declared_type() const { return declared_type_; }
sem::Type* declared_type() const { return declared_type_; }
/// @returns the declared storage class
StorageClass declared_storage_class() const {
@ -175,7 +175,7 @@ class Variable : public Castable<Variable, Node> {
Symbol const symbol_;
// The value type if a const or formal paramter, and the store type if a var
type::Type* const declared_type_;
sem::Type* const declared_type_;
bool const is_const_;
Expression* const constructor_;
DecorationList const decorations_;

View File

@ -84,7 +84,7 @@ class CloneContext {
/// Destructor
~CloneContext();
/// Clones the Node or type::Type `a` into the ProgramBuilder #dst if `a` is
/// Clones the Node or sem::Type `a` into the ProgramBuilder #dst if `a` is
/// not null. If `a` is null, then Clone() returns null. If `a` has been
/// cloned already by this CloneContext then the same cloned pointer is
/// returned.
@ -92,9 +92,9 @@ class CloneContext {
/// Clone() may use a function registered with ReplaceAll() to create a
/// transformed version of the object. See ReplaceAll() for more information.
///
/// The Node or type::Type `a` must be owned by the Program #src.
/// The Node or sem::Type `a` must be owned by the Program #src.
///
/// @param a the `Node` or `type::Type` to clone
/// @param a the `Node` or `sem::Type` to clone
/// @return the cloned node
template <typename T>
T* Clone(T* a) {
@ -144,7 +144,7 @@ class CloneContext {
return out;
}
/// Clones the Node or type::Type `a` into the ProgramBuilder #dst if `a` is
/// Clones the Node or sem::Type `a` into the ProgramBuilder #dst if `a` is
/// not null. If `a` is null, then Clone() returns null. If `a` has been
/// cloned already by this CloneContext then the same cloned pointer is
/// returned.
@ -152,9 +152,9 @@ class CloneContext {
/// Unlike Clone(), this method does not invoke or use any transformations
/// registered by ReplaceAll().
///
/// The Node or type::Type `a` must be owned by the Program #src.
/// The Node or sem::Type `a` must be owned by the Program #src.
///
/// @param a the `Node` or `type::Type` to clone
/// @param a the `Node` or `sem::Type` to clone
/// @return the cloned node
template <typename T>
T* CloneWithoutTransform(T* a) {

View File

@ -57,44 +57,44 @@ void AppendResourceBindings(std::vector<ResourceBinding>* dest,
ResourceBinding::TextureDimension
TypeTextureDimensionToResourceBindingTextureDimension(
const type::TextureDimension& type_dim) {
const sem::TextureDimension& type_dim) {
switch (type_dim) {
case type::TextureDimension::k1d:
case sem::TextureDimension::k1d:
return ResourceBinding::TextureDimension::k1d;
case type::TextureDimension::k2d:
case sem::TextureDimension::k2d:
return ResourceBinding::TextureDimension::k2d;
case type::TextureDimension::k2dArray:
case sem::TextureDimension::k2dArray:
return ResourceBinding::TextureDimension::k2dArray;
case type::TextureDimension::k3d:
case sem::TextureDimension::k3d:
return ResourceBinding::TextureDimension::k3d;
case type::TextureDimension::kCube:
case sem::TextureDimension::kCube:
return ResourceBinding::TextureDimension::kCube;
case type::TextureDimension::kCubeArray:
case sem::TextureDimension::kCubeArray:
return ResourceBinding::TextureDimension::kCubeArray;
case type::TextureDimension::kNone:
case sem::TextureDimension::kNone:
return ResourceBinding::TextureDimension::kNone;
}
return ResourceBinding::TextureDimension::kNone;
}
ResourceBinding::SampledKind BaseTypeToSampledKind(type::Type* base_type) {
ResourceBinding::SampledKind BaseTypeToSampledKind(sem::Type* base_type) {
if (!base_type) {
return ResourceBinding::SampledKind::kUnknown;
}
if (auto* at = base_type->As<type::ArrayType>()) {
if (auto* at = base_type->As<sem::ArrayType>()) {
base_type = at->type();
} else if (auto* mt = base_type->As<type::Matrix>()) {
} else if (auto* mt = base_type->As<sem::Matrix>()) {
base_type = mt->type();
} else if (auto* vt = base_type->As<type::Vector>()) {
} else if (auto* vt = base_type->As<sem::Vector>()) {
base_type = vt->type();
}
if (base_type->Is<type::F32>()) {
if (base_type->Is<sem::F32>()) {
return ResourceBinding::SampledKind::kFloat;
} else if (base_type->Is<type::U32>()) {
} else if (base_type->Is<sem::U32>()) {
return ResourceBinding::SampledKind::kUInt;
} else if (base_type->Is<type::I32>()) {
} else if (base_type->Is<sem::I32>()) {
return ResourceBinding::SampledKind::kSInt;
} else {
return ResourceBinding::SampledKind::kUnknown;
@ -102,79 +102,79 @@ ResourceBinding::SampledKind BaseTypeToSampledKind(type::Type* base_type) {
}
ResourceBinding::ImageFormat TypeImageFormatToResourceBindingImageFormat(
const type::ImageFormat& image_format) {
const sem::ImageFormat& image_format) {
switch (image_format) {
case type::ImageFormat::kR8Unorm:
case sem::ImageFormat::kR8Unorm:
return ResourceBinding::ImageFormat::kR8Unorm;
case type::ImageFormat::kR8Snorm:
case sem::ImageFormat::kR8Snorm:
return ResourceBinding::ImageFormat::kR8Snorm;
case type::ImageFormat::kR8Uint:
case sem::ImageFormat::kR8Uint:
return ResourceBinding::ImageFormat::kR8Uint;
case type::ImageFormat::kR8Sint:
case sem::ImageFormat::kR8Sint:
return ResourceBinding::ImageFormat::kR8Sint;
case type::ImageFormat::kR16Uint:
case sem::ImageFormat::kR16Uint:
return ResourceBinding::ImageFormat::kR16Uint;
case type::ImageFormat::kR16Sint:
case sem::ImageFormat::kR16Sint:
return ResourceBinding::ImageFormat::kR16Sint;
case type::ImageFormat::kR16Float:
case sem::ImageFormat::kR16Float:
return ResourceBinding::ImageFormat::kR16Float;
case type::ImageFormat::kRg8Unorm:
case sem::ImageFormat::kRg8Unorm:
return ResourceBinding::ImageFormat::kRg8Unorm;
case type::ImageFormat::kRg8Snorm:
case sem::ImageFormat::kRg8Snorm:
return ResourceBinding::ImageFormat::kRg8Snorm;
case type::ImageFormat::kRg8Uint:
case sem::ImageFormat::kRg8Uint:
return ResourceBinding::ImageFormat::kRg8Uint;
case type::ImageFormat::kRg8Sint:
case sem::ImageFormat::kRg8Sint:
return ResourceBinding::ImageFormat::kRg8Sint;
case type::ImageFormat::kR32Uint:
case sem::ImageFormat::kR32Uint:
return ResourceBinding::ImageFormat::kR32Uint;
case type::ImageFormat::kR32Sint:
case sem::ImageFormat::kR32Sint:
return ResourceBinding::ImageFormat::kR32Sint;
case type::ImageFormat::kR32Float:
case sem::ImageFormat::kR32Float:
return ResourceBinding::ImageFormat::kR32Float;
case type::ImageFormat::kRg16Uint:
case sem::ImageFormat::kRg16Uint:
return ResourceBinding::ImageFormat::kRg16Uint;
case type::ImageFormat::kRg16Sint:
case sem::ImageFormat::kRg16Sint:
return ResourceBinding::ImageFormat::kRg16Sint;
case type::ImageFormat::kRg16Float:
case sem::ImageFormat::kRg16Float:
return ResourceBinding::ImageFormat::kRg16Float;
case type::ImageFormat::kRgba8Unorm:
case sem::ImageFormat::kRgba8Unorm:
return ResourceBinding::ImageFormat::kRgba8Unorm;
case type::ImageFormat::kRgba8UnormSrgb:
case sem::ImageFormat::kRgba8UnormSrgb:
return ResourceBinding::ImageFormat::kRgba8UnormSrgb;
case type::ImageFormat::kRgba8Snorm:
case sem::ImageFormat::kRgba8Snorm:
return ResourceBinding::ImageFormat::kRgba8Snorm;
case type::ImageFormat::kRgba8Uint:
case sem::ImageFormat::kRgba8Uint:
return ResourceBinding::ImageFormat::kRgba8Uint;
case type::ImageFormat::kRgba8Sint:
case sem::ImageFormat::kRgba8Sint:
return ResourceBinding::ImageFormat::kRgba8Sint;
case type::ImageFormat::kBgra8Unorm:
case sem::ImageFormat::kBgra8Unorm:
return ResourceBinding::ImageFormat::kBgra8Unorm;
case type::ImageFormat::kBgra8UnormSrgb:
case sem::ImageFormat::kBgra8UnormSrgb:
return ResourceBinding::ImageFormat::kBgra8UnormSrgb;
case type::ImageFormat::kRgb10A2Unorm:
case sem::ImageFormat::kRgb10A2Unorm:
return ResourceBinding::ImageFormat::kRgb10A2Unorm;
case type::ImageFormat::kRg11B10Float:
case sem::ImageFormat::kRg11B10Float:
return ResourceBinding::ImageFormat::kRg11B10Float;
case type::ImageFormat::kRg32Uint:
case sem::ImageFormat::kRg32Uint:
return ResourceBinding::ImageFormat::kRg32Uint;
case type::ImageFormat::kRg32Sint:
case sem::ImageFormat::kRg32Sint:
return ResourceBinding::ImageFormat::kRg32Sint;
case type::ImageFormat::kRg32Float:
case sem::ImageFormat::kRg32Float:
return ResourceBinding::ImageFormat::kRg32Float;
case type::ImageFormat::kRgba16Uint:
case sem::ImageFormat::kRgba16Uint:
return ResourceBinding::ImageFormat::kRgba16Uint;
case type::ImageFormat::kRgba16Sint:
case sem::ImageFormat::kRgba16Sint:
return ResourceBinding::ImageFormat::kRgba16Sint;
case type::ImageFormat::kRgba16Float:
case sem::ImageFormat::kRgba16Float:
return ResourceBinding::ImageFormat::kRgba16Float;
case type::ImageFormat::kRgba32Uint:
case sem::ImageFormat::kRgba32Uint:
return ResourceBinding::ImageFormat::kRgba32Uint;
case type::ImageFormat::kRgba32Sint:
case sem::ImageFormat::kRgba32Sint:
return ResourceBinding::ImageFormat::kRgba32Sint;
case type::ImageFormat::kRgba32Float:
case sem::ImageFormat::kRgba32Float:
return ResourceBinding::ImageFormat::kRgba32Float;
case type::ImageFormat::kNone:
case sem::ImageFormat::kNone:
return ResourceBinding::ImageFormat::kNone;
}
return ResourceBinding::ImageFormat::kNone;
@ -207,7 +207,7 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
entry_point.input_variables);
}
if (!func->return_type()->Is<type::Void>()) {
if (!func->return_type()->Is<sem::Void>()) {
AddEntryPointInOutVariables("<retval>", func->return_type(),
func->return_type_decorations(),
entry_point.output_variables);
@ -386,7 +386,7 @@ std::vector<ResourceBinding> Inspector::GetUniformBufferResourceBindings(
auto binding_info = ruv.second;
auto* unwrapped_type = var->Type()->UnwrapIfNeeded();
auto* str = unwrapped_type->As<type::StructType>();
auto* str = unwrapped_type->As<sem::StructType>();
if (str == nullptr) {
continue;
}
@ -514,7 +514,7 @@ std::vector<ResourceBinding> Inspector::GetDepthTextureResourceBindings(
entry.bind_group = binding_info.group->value();
entry.binding = binding_info.binding->value();
auto* texture_type = var->Type()->UnwrapIfNeeded()->As<type::Texture>();
auto* texture_type = var->Type()->UnwrapIfNeeded()->As<sem::Texture>();
entry.dim = TypeTextureDimensionToResourceBindingTextureDimension(
texture_type->dim());
@ -541,7 +541,7 @@ ast::Function* Inspector::FindEntryPointByName(const std::string& name) {
void Inspector::AddEntryPointInOutVariables(
std::string name,
type::Type* type,
sem::Type* type,
const ast::DecorationList& decorations,
std::vector<StageVariable>& variables) const {
// Skip builtins.
@ -551,7 +551,7 @@ void Inspector::AddEntryPointInOutVariables(
auto* unwrapped_type = type->UnwrapAll();
if (auto* struct_ty = unwrapped_type->As<type::StructType>()) {
if (auto* struct_ty = unwrapped_type->As<sem::StructType>()) {
// Recurse into members.
for (auto* member : struct_ty->impl()->members()) {
AddEntryPointInOutVariables(
@ -597,7 +597,7 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
auto* var = rsv.first;
auto binding_info = rsv.second;
auto* ac_type = var->Type()->As<type::AccessControl>();
auto* ac_type = var->Type()->As<sem::AccessControl>();
if (ac_type == nullptr) {
continue;
}
@ -606,7 +606,7 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
continue;
}
auto* str = var->Type()->UnwrapIfNeeded()->As<type::StructType>();
auto* str = var->Type()->UnwrapIfNeeded()->As<sem::StructType>();
if (!str) {
continue;
}
@ -657,18 +657,18 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
entry.bind_group = binding_info.group->value();
entry.binding = binding_info.binding->value();
auto* texture_type = var->Type()->UnwrapIfNeeded()->As<type::Texture>();
auto* texture_type = var->Type()->UnwrapIfNeeded()->As<sem::Texture>();
entry.dim = TypeTextureDimensionToResourceBindingTextureDimension(
texture_type->dim());
type::Type* base_type = nullptr;
sem::Type* base_type = nullptr;
if (multisampled_only) {
base_type = texture_type->As<type::MultisampledTexture>()
base_type = texture_type->As<sem::MultisampledTexture>()
->type()
->UnwrapIfNeeded();
} else {
base_type =
texture_type->As<type::SampledTexture>()->type()->UnwrapIfNeeded();
texture_type->As<sem::SampledTexture>()->type()->UnwrapIfNeeded();
}
entry.sampled_kind = BaseTypeToSampledKind(base_type);
@ -692,7 +692,7 @@ std::vector<ResourceBinding> Inspector::GetStorageTextureResourceBindingsImpl(
auto* var = ref.first;
auto binding_info = ref.second;
auto* ac_type = var->Type()->As<type::AccessControl>();
auto* ac_type = var->Type()->As<sem::AccessControl>();
if (ac_type == nullptr) {
continue;
}
@ -709,11 +709,11 @@ std::vector<ResourceBinding> Inspector::GetStorageTextureResourceBindingsImpl(
entry.binding = binding_info.binding->value();
auto* texture_type =
var->Type()->UnwrapIfNeeded()->As<type::StorageTexture>();
var->Type()->UnwrapIfNeeded()->As<sem::StorageTexture>();
entry.dim = TypeTextureDimensionToResourceBindingTextureDimension(
texture_type->dim());
type::Type* base_type = texture_type->type()->UnwrapIfNeeded();
sem::Type* base_type = texture_type->type()->UnwrapIfNeeded();
entry.sampled_kind = BaseTypeToSampledKind(base_type);
entry.image_format = TypeImageFormatToResourceBindingImageFormat(
texture_type->image_format());

View File

@ -223,7 +223,7 @@ class Inspector {
/// @param decorations the variable decorations
/// @param variables the list to add the variables to
void AddEntryPointInOutVariables(std::string name,
type::Type* type,
sem::Type* type,
const ast::DecorationList& decorations,
std::vector<StageVariable>& variables) const;

File diff suppressed because it is too large Load Diff

View File

@ -77,7 +77,7 @@ class Matcher {
/// The map of open types. A new entry is assigned the first time an
/// OpenType is encountered. If the OpenType is encountered again, a
/// comparison is made to see if the type is consistent.
std::unordered_map<OpenType, type::Type*> open_types;
std::unordered_map<OpenType, sem::Type*> open_types;
/// The map of open numbers. A new entry is assigned the first time an
/// OpenNumber is encountered. If the OpenNumber is encountered again, a
/// comparison is made to see if the number is consistent.
@ -91,7 +91,7 @@ class Matcher {
/// Aliases are automatically unwrapped before matching.
/// Match may add to, or compare against the open types and numbers in state.
/// @returns true if the argument type is as expected.
bool Match(MatchState& state, type::Type* argument_type) const {
bool Match(MatchState& state, sem::Type* argument_type) const {
auto* unwrapped = argument_type->UnwrapAliasIfNeeded();
return MatchUnwrapped(state, unwrapped);
}
@ -110,12 +110,12 @@ class Matcher {
/// Match may add to, or compare against the open types and numbers in state.
/// @returns true if the argument type is as expected.
virtual bool MatchUnwrapped(MatchState& state,
type::Type* argument_type) const = 0;
sem::Type* argument_type) const = 0;
/// Checks `state.open_type` to see if the OpenType `t` is equal to the type
/// `ty`. If `state.open_type` does not contain an entry for `t`, then `ty`
/// is added and returns true.
bool MatchOpenType(MatchState& state, OpenType t, type::Type* ty) const {
bool MatchOpenType(MatchState& state, OpenType t, sem::Type* ty) const {
auto it = state.open_types.find(t);
if (it != state.open_types.end()) {
return it->second == ty;
@ -145,9 +145,9 @@ class Builder : public Matcher {
/// Final matched state passed to Build()
struct BuildState {
/// The type manager used to construct new types
type::Manager& ty_mgr;
sem::Manager& ty_mgr;
/// The final resolved list of open types
std::unordered_map<OpenType, type::Type*> const open_types;
std::unordered_map<OpenType, sem::Type*> const open_types;
/// The final resolved list of open numbers
std::unordered_map<OpenNumber, uint32_t> const open_numbers;
};
@ -156,7 +156,7 @@ class Builder : public Matcher {
~Builder() override = default;
/// Constructs and returns the expected type
virtual type::Type* Build(BuildState& state) const = 0;
virtual sem::Type* Build(BuildState& state) const = 0;
};
/// OpenTypeBuilder is a Matcher / Builder for an open type (T etc).
@ -166,11 +166,11 @@ class OpenTypeBuilder : public Builder {
public:
explicit OpenTypeBuilder(OpenType open_type) : open_type_(open_type) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
return MatchOpenType(state, open_type_, ty);
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
return state.open_types.at(open_type_);
}
@ -183,11 +183,11 @@ class OpenTypeBuilder : public Builder {
/// VoidBuilder is a Matcher / Builder for void types.
class VoidBuilder : public Builder {
public:
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
return ty->Is<type::Void>();
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
return ty->Is<sem::Void>();
}
type::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<type::Void>();
sem::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<sem::Void>();
}
std::string str() const override { return "void"; }
};
@ -195,11 +195,11 @@ class VoidBuilder : public Builder {
/// BoolBuilder is a Matcher / Builder for boolean types.
class BoolBuilder : public Builder {
public:
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
return ty->Is<type::Bool>();
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
return ty->Is<sem::Bool>();
}
type::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<type::Bool>();
sem::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<sem::Bool>();
}
std::string str() const override { return "bool"; }
};
@ -207,11 +207,11 @@ class BoolBuilder : public Builder {
/// F32Builder is a Matcher / Builder for f32 types.
class F32Builder : public Builder {
public:
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
return ty->Is<type::F32>();
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
return ty->Is<sem::F32>();
}
type::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<type::F32>();
sem::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<sem::F32>();
}
std::string str() const override { return "f32"; }
};
@ -219,11 +219,11 @@ class F32Builder : public Builder {
/// U32Builder is a Matcher / Builder for u32 types.
class U32Builder : public Builder {
public:
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
return ty->Is<type::U32>();
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
return ty->Is<sem::U32>();
}
type::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<type::U32>();
sem::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<sem::U32>();
}
std::string str() const override { return "u32"; }
};
@ -231,11 +231,11 @@ class U32Builder : public Builder {
/// I32Builder is a Matcher / Builder for i32 types.
class I32Builder : public Builder {
public:
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
return ty->Is<type::I32>();
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
return ty->Is<sem::I32>();
}
type::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<type::I32>();
sem::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<sem::I32>();
}
std::string str() const override { return "i32"; }
};
@ -243,8 +243,8 @@ class I32Builder : public Builder {
/// IU32Matcher is a Matcher for i32 or u32 types.
class IU32Matcher : public Matcher {
public:
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
return ty->Is<type::I32>() || ty->Is<type::U32>();
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
return ty->Is<sem::I32>() || ty->Is<sem::U32>();
}
std::string str() const override { return "i32 or u32"; }
};
@ -252,8 +252,8 @@ class IU32Matcher : public Matcher {
/// FIU32Matcher is a Matcher for f32, i32 or u32 types.
class FIU32Matcher : public Matcher {
public:
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
return ty->Is<type::F32>() || ty->Is<type::I32>() || ty->Is<type::U32>();
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
return ty->Is<sem::F32>() || ty->Is<sem::I32>() || ty->Is<sem::U32>();
}
std::string str() const override { return "f32, i32 or u32"; }
};
@ -261,7 +261,7 @@ class FIU32Matcher : public Matcher {
/// ScalarMatcher is a Matcher for f32, i32, u32 or boolean types.
class ScalarMatcher : public Matcher {
public:
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
return ty->is_scalar();
}
std::string str() const override { return "scalar"; }
@ -274,8 +274,8 @@ class OpenSizeVecBuilder : public Builder {
OpenSizeVecBuilder(OpenNumber size, Builder* element_builder)
: size_(size), element_builder_(element_builder) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* vec = ty->As<type::Vector>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* vec = ty->As<sem::Vector>()) {
if (!MatchOpenNumber(state, size_, vec->size())) {
return false;
}
@ -284,10 +284,10 @@ class OpenSizeVecBuilder : public Builder {
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto* el = element_builder_->Build(state);
auto n = state.open_numbers.at(size_);
return state.ty_mgr.Get<type::Vector>(el, n);
return state.ty_mgr.Get<sem::Vector>(el, n);
}
std::string str() const override {
@ -306,8 +306,8 @@ class VecBuilder : public Builder {
VecBuilder(uint32_t size, Builder* element_builder)
: size_(size), element_builder_(element_builder) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* vec = ty->As<type::Vector>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* vec = ty->As<sem::Vector>()) {
if (vec->size() == size_) {
return element_builder_->Match(state, vec->type());
}
@ -315,9 +315,9 @@ class VecBuilder : public Builder {
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto* el = element_builder_->Build(state);
return state.ty_mgr.Get<type::Vector>(el, size_);
return state.ty_mgr.Get<sem::Vector>(el, size_);
}
std::string str() const override {
@ -338,8 +338,8 @@ class OpenSizeMatBuilder : public Builder {
Builder* element_builder)
: columns_(columns), rows_(rows), element_builder_(element_builder) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* mat = ty->As<type::Matrix>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* mat = ty->As<sem::Matrix>()) {
if (!MatchOpenNumber(state, columns_, mat->columns())) {
return false;
}
@ -351,11 +351,11 @@ class OpenSizeMatBuilder : public Builder {
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto* el = element_builder_->Build(state);
auto columns = state.open_numbers.at(columns_);
auto rows = state.open_numbers.at(rows_);
return state.ty_mgr.Get<type::Matrix>(el, rows, columns);
return state.ty_mgr.Get<sem::Matrix>(el, rows, columns);
}
std::string str() const override {
@ -375,16 +375,16 @@ class PtrBuilder : public Builder {
explicit PtrBuilder(Builder* element_builder)
: element_builder_(element_builder) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* ptr = ty->As<type::Pointer>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* ptr = ty->As<sem::Pointer>()) {
return element_builder_->Match(state, ptr->type());
}
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto* el = element_builder_->Build(state);
return state.ty_mgr.Get<type::Pointer>(el, ast::StorageClass::kNone);
return state.ty_mgr.Get<sem::Pointer>(el, ast::StorageClass::kNone);
}
bool ExpectsPointer() const override { return true; }
@ -403,8 +403,8 @@ class ArrayBuilder : public Builder {
explicit ArrayBuilder(Builder* element_builder)
: element_builder_(element_builder) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* arr = ty->As<type::ArrayType>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* arr = ty->As<sem::ArrayType>()) {
if (arr->size() == 0) {
return element_builder_->Match(state, arr->type());
}
@ -412,9 +412,9 @@ class ArrayBuilder : public Builder {
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto* el = element_builder_->Build(state);
return state.ty_mgr.Get<type::ArrayType>(el, 0, ast::DecorationList{});
return state.ty_mgr.Get<sem::ArrayType>(el, 0, ast::DecorationList{});
}
std::string str() const override {
@ -428,12 +428,12 @@ class ArrayBuilder : public Builder {
/// SampledTextureBuilder is a Matcher / Builder for sampled texture types.
class SampledTextureBuilder : public Builder {
public:
explicit SampledTextureBuilder(type::TextureDimension dimensions,
explicit SampledTextureBuilder(sem::TextureDimension dimensions,
Builder* type_builder)
: dimensions_(dimensions), type_builder_(type_builder) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* tex = ty->As<type::SampledTexture>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* tex = ty->As<sem::SampledTexture>()) {
if (tex->dim() == dimensions_) {
return type_builder_->Match(state, tex->type());
}
@ -441,9 +441,9 @@ class SampledTextureBuilder : public Builder {
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto* type = type_builder_->Build(state);
return state.ty_mgr.Get<type::SampledTexture>(dimensions_, type);
return state.ty_mgr.Get<sem::SampledTexture>(dimensions_, type);
}
std::string str() const override {
@ -453,7 +453,7 @@ class SampledTextureBuilder : public Builder {
}
private:
type::TextureDimension const dimensions_;
sem::TextureDimension const dimensions_;
Builder* const type_builder_;
};
@ -461,12 +461,12 @@ class SampledTextureBuilder : public Builder {
/// types.
class MultisampledTextureBuilder : public Builder {
public:
explicit MultisampledTextureBuilder(type::TextureDimension dimensions,
explicit MultisampledTextureBuilder(sem::TextureDimension dimensions,
Builder* type_builder)
: dimensions_(dimensions), type_builder_(type_builder) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* tex = ty->As<type::MultisampledTexture>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* tex = ty->As<sem::MultisampledTexture>()) {
if (tex->dim() == dimensions_) {
return type_builder_->Match(state, tex->type());
}
@ -474,9 +474,9 @@ class MultisampledTextureBuilder : public Builder {
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto* type = type_builder_->Build(state);
return state.ty_mgr.Get<type::MultisampledTexture>(dimensions_, type);
return state.ty_mgr.Get<sem::MultisampledTexture>(dimensions_, type);
}
std::string str() const override {
@ -487,25 +487,25 @@ class MultisampledTextureBuilder : public Builder {
}
private:
type::TextureDimension const dimensions_;
sem::TextureDimension const dimensions_;
Builder* const type_builder_;
};
/// DepthTextureBuilder is a Matcher / Builder for depth texture types.
class DepthTextureBuilder : public Builder {
public:
explicit DepthTextureBuilder(type::TextureDimension dimensions)
explicit DepthTextureBuilder(sem::TextureDimension dimensions)
: dimensions_(dimensions) {}
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
if (auto* tex = ty->As<type::DepthTexture>()) {
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
if (auto* tex = ty->As<sem::DepthTexture>()) {
return tex->dim() == dimensions_;
}
return false;
}
type::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<type::DepthTexture>(dimensions_);
sem::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<sem::DepthTexture>(dimensions_);
}
std::string str() const override {
@ -515,7 +515,7 @@ class DepthTextureBuilder : public Builder {
}
private:
type::TextureDimension const dimensions_;
sem::TextureDimension const dimensions_;
};
/// StorageTextureBuilder is a Matcher / Builder for storage texture types of
@ -523,15 +523,15 @@ class DepthTextureBuilder : public Builder {
class StorageTextureBuilder : public Builder {
public:
explicit StorageTextureBuilder(
type::TextureDimension dimensions,
sem::TextureDimension dimensions,
OpenNumber texel_format, // a.k.a "image format"
OpenType channel_format) // a.k.a "storage subtype"
: dimensions_(dimensions),
texel_format_(texel_format),
channel_format_(channel_format) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* ac = ty->As<type::AccessControl>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* ac = ty->As<sem::AccessControl>()) {
// If we have an storage texture argument that's got an access control
// type wrapped around it, accept it. Signatures that don't include an
// access control imply any access. Example:
@ -539,7 +539,7 @@ class StorageTextureBuilder : public Builder {
ty = ac->type();
}
if (auto* tex = ty->As<type::StorageTexture>()) {
if (auto* tex = ty->As<sem::StorageTexture>()) {
if (MatchOpenNumber(state, texel_format_,
static_cast<uint32_t>(tex->image_format()))) {
if (MatchOpenType(state, channel_format_, tex->type())) {
@ -550,12 +550,12 @@ class StorageTextureBuilder : public Builder {
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto texel_format =
static_cast<type::ImageFormat>(state.open_numbers.at(texel_format_));
static_cast<sem::ImageFormat>(state.open_numbers.at(texel_format_));
auto* channel_format = state.open_types.at(channel_format_);
return state.ty_mgr.Get<type::StorageTexture>(dimensions_, texel_format,
channel_format);
return state.ty_mgr.Get<sem::StorageTexture>(dimensions_, texel_format,
channel_format);
}
std::string str() const override {
@ -565,7 +565,7 @@ class StorageTextureBuilder : public Builder {
}
private:
type::TextureDimension const dimensions_;
sem::TextureDimension const dimensions_;
OpenNumber const texel_format_;
OpenType const channel_format_;
};
@ -573,31 +573,31 @@ class StorageTextureBuilder : public Builder {
/// SamplerBuilder is a Matcher / Builder for sampler types of the given kind.
class SamplerBuilder : public Builder {
public:
explicit SamplerBuilder(type::SamplerKind kind) : kind_(kind) {}
explicit SamplerBuilder(sem::SamplerKind kind) : kind_(kind) {}
bool MatchUnwrapped(MatchState&, type::Type* ty) const override {
if (auto* sampler = ty->As<type::Sampler>()) {
bool MatchUnwrapped(MatchState&, sem::Type* ty) const override {
if (auto* sampler = ty->As<sem::Sampler>()) {
return sampler->kind() == kind_;
}
return false;
}
type::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<type::Sampler>(kind_);
sem::Type* Build(BuildState& state) const override {
return state.ty_mgr.Get<sem::Sampler>(kind_);
}
std::string str() const override {
switch (kind_) {
case type::SamplerKind::kSampler:
case sem::SamplerKind::kSampler:
return "sampler";
case type::SamplerKind::kComparisonSampler:
case sem::SamplerKind::kComparisonSampler:
return "sampler_comparison";
}
return "sampler";
}
private:
type::SamplerKind const kind_;
sem::SamplerKind const kind_;
};
/// AccessControlBuilder is a Matcher / Builder for AccessControl types
@ -607,8 +607,8 @@ class AccessControlBuilder : public Builder {
Builder* type)
: access_control_(access_control), type_(type) {}
bool MatchUnwrapped(MatchState& state, type::Type* ty) const override {
if (auto* ac = ty->As<type::AccessControl>()) {
bool MatchUnwrapped(MatchState& state, sem::Type* ty) const override {
if (auto* ac = ty->As<sem::AccessControl>()) {
if (ac->access_control() == access_control_) {
return type_->Match(state, ty);
}
@ -616,9 +616,9 @@ class AccessControlBuilder : public Builder {
return false;
}
type::Type* Build(BuildState& state) const override {
sem::Type* Build(BuildState& state) const override {
auto* ty = type_->Build(state);
return state.ty_mgr.Get<type::AccessControl>(access_control_, ty);
return state.ty_mgr.Get<sem::AccessControl>(access_control_, ty);
}
std::string str() const override {
@ -639,7 +639,7 @@ class Impl : public IntrinsicTable {
IntrinsicTable::Result Lookup(ProgramBuilder& builder,
sem::IntrinsicType type,
const std::vector<type::Type*>& args,
const std::vector<sem::Type*>& args,
const Source& source) const override;
/// Holds the information about a single overload parameter used for matching
@ -661,7 +661,7 @@ class Impl : public IntrinsicTable {
/// (positive representing a greater match), and nullptr is returned.
sem::Intrinsic* Match(ProgramBuilder& builder,
sem::IntrinsicType type,
const std::vector<type::Type*>& arg_types,
const std::vector<sem::Type*>& arg_types,
diag::List& diagnostics,
int& match_score) const;
@ -732,13 +732,13 @@ class Impl : public IntrinsicTable {
/// @returns a Matcher / Builder that matches a sampled texture with the given
/// dimensions and type
Builder* sampled_texture(type::TextureDimension dimensions, Builder* type) {
Builder* sampled_texture(sem::TextureDimension dimensions, Builder* type) {
return matcher_allocator_.Create<SampledTextureBuilder>(dimensions, type);
}
/// @returns a Matcher / Builder that matches a multisampled texture with the
/// given dimensions and type
Builder* multisampled_texture(type::TextureDimension dimensions,
Builder* multisampled_texture(sem::TextureDimension dimensions,
Builder* type) {
return matcher_allocator_.Create<MultisampledTextureBuilder>(dimensions,
type);
@ -746,13 +746,13 @@ class Impl : public IntrinsicTable {
/// @returns a Matcher / Builder that matches a depth texture with the
/// given dimensions
Builder* depth_texture(type::TextureDimension dimensions) {
Builder* depth_texture(sem::TextureDimension dimensions) {
return matcher_allocator_.Create<DepthTextureBuilder>(dimensions);
}
/// @returns a Matcher / Builder that matches a storage texture of the given
/// format with the given dimensions
Builder* storage_texture(type::TextureDimension dimensions,
Builder* storage_texture(sem::TextureDimension dimensions,
OpenNumber texel_format,
OpenType channel_format) {
return matcher_allocator_.Create<StorageTextureBuilder>(
@ -760,7 +760,7 @@ class Impl : public IntrinsicTable {
}
/// @returns a Matcher / Builder that matches a sampler type
Builder* sampler(type::SamplerKind kind) {
Builder* sampler(sem::SamplerKind kind) {
return matcher_allocator_.Create<SamplerBuilder>(kind);
}
@ -796,7 +796,7 @@ class Impl : public IntrinsicTable {
Impl::Impl() {
using I = sem::IntrinsicType;
using Dim = type::TextureDimension;
using Dim = sem::TextureDimension;
auto* void_ = &matchers_.void_; // void
auto* bool_ = &matchers_.bool_; // bool
@ -837,12 +837,12 @@ Impl::Impl() {
// I - is an alias to sem::IntrinsicType.
// I::kIsInf is shorthand for sem::IntrinsicType::kIsInf.
// bool_ - is a pointer to a pre-constructed BoolBuilder which matches and
// builds type::Bool types.
// builds sem::Bool types.
// {f32} - is the list of parameter Builders for the overload.
// Builders are a type of Matcher that can also build the the type.
// All Builders are Matchers, not all Matchers are Builders.
// f32 is a pointer to a pre-constructed F32Builder which matches and
// builds type::F32 types.
// builds sem::F32 types.
//
// This call registers the overload for the `isInf(f32) -> bool` intrinsic.
//
@ -851,8 +851,8 @@ Impl::Impl() {
//
// (1) Overload::Match() begins by attempting to match the argument types
// from left to right.
// F32Builder::Match() is called with the type::F32 argument type.
// F32Builder (only) matches the type::F32 type, so F32Builder::Match()
// F32Builder::Match() is called with the sem::F32 argument type.
// F32Builder (only) matches the sem::F32 type, so F32Builder::Match()
// returns true.
// (2) All the parameters have had their Matcher::Match() methods return
// true, there are no open-types (more about these later), so the
@ -1114,9 +1114,9 @@ Impl::Impl() {
access_control(ast::AccessControl::kWriteOnly, tex_storage_2d_array_FT);
auto* tex_storage_wo_3d_FT =
access_control(ast::AccessControl::kWriteOnly, tex_storage_3d_FT);
auto* sampler = this->sampler(type::SamplerKind::kSampler);
auto* sampler = this->sampler(sem::SamplerKind::kSampler);
auto* sampler_comparison =
this->sampler(type::SamplerKind::kComparisonSampler);
this->sampler(sem::SamplerKind::kComparisonSampler);
auto t = sem::Parameter::Usage::kTexture;
auto s = sem::Parameter::Usage::kSampler;
auto coords = sem::Parameter::Usage::kCoords;
@ -1300,7 +1300,7 @@ std::string str(const Impl::Overload& overload) {
/// types.
std::string CallSignature(ProgramBuilder& builder,
sem::IntrinsicType type,
const std::vector<type::Type*>& args) {
const std::vector<sem::Type*>& args) {
std::stringstream ss;
ss << sem::str(type) << "(";
{
@ -1320,7 +1320,7 @@ std::string CallSignature(ProgramBuilder& builder,
IntrinsicTable::Result Impl::Lookup(ProgramBuilder& builder,
sem::IntrinsicType type,
const std::vector<type::Type*>& args,
const std::vector<sem::Type*>& args,
const Source& source) const {
diag::List diagnostics;
// Candidate holds information about a mismatched overload that could be what
@ -1370,7 +1370,7 @@ IntrinsicTable::Result Impl::Lookup(ProgramBuilder& builder,
sem::Intrinsic* Impl::Overload::Match(ProgramBuilder& builder,
sem::IntrinsicType intrinsic,
const std::vector<type::Type*>& args,
const std::vector<sem::Type*>& args,
diag::List& diagnostics,
int& match_score) const {
if (type != intrinsic) {
@ -1397,7 +1397,7 @@ sem::Intrinsic* Impl::Overload::Match(ProgramBuilder& builder,
}
auto* arg_ty = args[i];
if (auto* ptr = arg_ty->As<type::Pointer>()) {
if (auto* ptr = arg_ty->As<sem::Pointer>()) {
if (!parameters[i].matcher->ExpectsPointer()) {
// Argument is a pointer, but the matcher isn't expecting one.
// Perform an implicit dereference.

View File

@ -51,7 +51,7 @@ class IntrinsicTable {
/// @return the semantic intrinsic if found, otherwise nullptr
virtual Result Lookup(ProgramBuilder& builder,
sem::IntrinsicType type,
const std::vector<type::Type*>& args,
const std::vector<sem::Type*>& args,
const Source& source) const = 0;
};

View File

@ -69,8 +69,7 @@ TEST_F(IntrinsicTableTest, MismatchU32) {
}
TEST_F(IntrinsicTableTest, MatchI32) {
auto* tex =
create<type::SampledTexture>(type::TextureDimension::k1d, ty.f32());
auto* tex = create<sem::SampledTexture>(sem::TextureDimension::k1d, ty.f32());
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, ty.i32(), ty.i32()}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@ -84,8 +83,7 @@ TEST_F(IntrinsicTableTest, MatchI32) {
}
TEST_F(IntrinsicTableTest, MismatchI32) {
auto* tex =
create<type::SampledTexture>(type::TextureDimension::k1d, ty.f32());
auto* tex = create<sem::SampledTexture>(sem::TextureDimension::k1d, ty.f32());
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, ty.f32()}, Source{});
ASSERT_EQ(result.intrinsic, nullptr);
@ -221,9 +219,8 @@ TEST_F(IntrinsicTableTest, MismatchArray) {
}
TEST_F(IntrinsicTableTest, MatchSampler) {
auto* tex =
create<type::SampledTexture>(type::TextureDimension::k2d, ty.f32());
auto* sampler = create<type::Sampler>(type::SamplerKind::kSampler);
auto* tex = create<sem::SampledTexture>(sem::TextureDimension::k2d, ty.f32());
auto* sampler = create<sem::Sampler>(sem::SamplerKind::kSampler);
auto result = table->Lookup(*this, IntrinsicType::kTextureSample,
{tex, sampler, ty.vec2<f32>()}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@ -238,8 +235,7 @@ TEST_F(IntrinsicTableTest, MatchSampler) {
}
TEST_F(IntrinsicTableTest, MismatchSampler) {
auto* tex =
create<type::SampledTexture>(type::TextureDimension::k2d, ty.f32());
auto* tex = create<sem::SampledTexture>(sem::TextureDimension::k2d, ty.f32());
auto result = table->Lookup(*this, IntrinsicType::kTextureSample,
{tex, ty.f32(), ty.vec2<f32>()}, Source{});
ASSERT_EQ(result.intrinsic, nullptr);
@ -247,8 +243,7 @@ TEST_F(IntrinsicTableTest, MismatchSampler) {
}
TEST_F(IntrinsicTableTest, MatchSampledTexture) {
auto* tex =
create<type::SampledTexture>(type::TextureDimension::k2d, ty.f32());
auto* tex = create<sem::SampledTexture>(sem::TextureDimension::k2d, ty.f32());
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, ty.vec2<i32>(), ty.i32()}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@ -263,7 +258,7 @@ TEST_F(IntrinsicTableTest, MatchSampledTexture) {
TEST_F(IntrinsicTableTest, MatchMultisampledTexture) {
auto* tex =
create<type::MultisampledTexture>(type::TextureDimension::k2d, ty.f32());
create<sem::MultisampledTexture>(sem::TextureDimension::k2d, ty.f32());
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, ty.vec2<i32>(), ty.i32()}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@ -277,7 +272,7 @@ TEST_F(IntrinsicTableTest, MatchMultisampledTexture) {
}
TEST_F(IntrinsicTableTest, MatchDepthTexture) {
auto* tex = create<type::DepthTexture>(type::TextureDimension::k2d);
auto* tex = create<sem::DepthTexture>(sem::TextureDimension::k2d);
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex, ty.vec2<i32>(), ty.i32()}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@ -291,11 +286,10 @@ TEST_F(IntrinsicTableTest, MatchDepthTexture) {
}
TEST_F(IntrinsicTableTest, MatchROStorageTexture) {
auto* tex = create<type::StorageTexture>(
type::TextureDimension::k2d, type::ImageFormat::kR16Float,
type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, Types()));
auto* tex_ac =
create<type::AccessControl>(ast::AccessControl::kReadOnly, tex);
auto* tex = create<sem::StorageTexture>(
sem::TextureDimension::k2d, sem::ImageFormat::kR16Float,
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR16Float, Types()));
auto* tex_ac = create<sem::AccessControl>(ast::AccessControl::kReadOnly, tex);
auto result = table->Lookup(*this, IntrinsicType::kTextureLoad,
{tex_ac, ty.vec2<i32>()}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
@ -309,11 +303,11 @@ TEST_F(IntrinsicTableTest, MatchROStorageTexture) {
}
TEST_F(IntrinsicTableTest, MatchWOStorageTexture) {
auto* tex = create<type::StorageTexture>(
type::TextureDimension::k2d, type::ImageFormat::kR16Float,
type::StorageTexture::SubtypeFor(type::ImageFormat::kR16Float, Types()));
auto* tex = create<sem::StorageTexture>(
sem::TextureDimension::k2d, sem::ImageFormat::kR16Float,
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kR16Float, Types()));
auto* tex_ac =
create<type::AccessControl>(ast::AccessControl::kWriteOnly, tex);
create<sem::AccessControl>(ast::AccessControl::kWriteOnly, tex);
auto result =
table->Lookup(*this, IntrinsicType::kTextureStore,
{tex_ac, ty.vec2<i32>(), ty.vec4<f32>()}, Source{});
@ -470,7 +464,7 @@ TEST_F(IntrinsicTableTest, OverloadOrderByNumberOfParameters) {
}
TEST_F(IntrinsicTableTest, OverloadOrderByMatchingParameter) {
auto* tex = create<type::DepthTexture>(type::TextureDimension::k2d);
auto* tex = create<sem::DepthTexture>(sem::TextureDimension::k2d);
auto result = table->Lookup(*this, IntrinsicType::kTextureDimensions,
{tex, ty.bool_()}, Source{});
ASSERT_EQ(

View File

@ -102,7 +102,7 @@ bool Program::IsValid() const {
return is_valid_;
}
type::Type* Program::TypeOf(const ast::Expression* expr) const {
sem::Type* Program::TypeOf(const ast::Expression* expr) const {
auto* sem = Sem().Get(expr);
return sem ? sem->Type() : nullptr;
}

View File

@ -66,7 +66,7 @@ class Program {
ProgramID ID() const { return id_; }
/// @returns a reference to the program's types
const type::Manager& Types() const {
const sem::Manager& Types() const {
AssertNotMoved();
return types_;
}
@ -129,7 +129,7 @@ class Program {
/// @param expr the AST expression
/// @return the resolved semantic type for the expression, or nullptr if the
/// expression has no resolved type.
type::Type* TypeOf(const ast::Expression* expr) const;
sem::Type* TypeOf(const ast::Expression* expr) const;
/// @param demangle whether to automatically demangle the symbols in the
/// returned string
@ -160,7 +160,7 @@ class Program {
void AssertNotMoved() const;
ProgramID id_;
type::Manager types_;
sem::Manager types_;
ASTNodeAllocator ast_nodes_;
SemNodeAllocator sem_nodes_;
ast::Module* ast_ = nullptr;

View File

@ -56,7 +56,7 @@ ProgramBuilder& ProgramBuilder::operator=(ProgramBuilder&& rhs) {
ProgramBuilder ProgramBuilder::Wrap(const Program* program) {
ProgramBuilder builder;
builder.id_ = program->ID();
builder.types_ = type::Manager::Wrap(program->Types());
builder.types_ = sem::Manager::Wrap(program->Types());
builder.ast_ = builder.create<ast::Module>(
program->AST().source(), program->AST().GlobalDeclarations());
builder.sem_ = sem::Info::Wrap(program->Sem());
@ -85,40 +85,40 @@ void ProgramBuilder::AssertNotMoved() const {
}
}
type::Type* ProgramBuilder::TypeOf(ast::Expression* expr) const {
sem::Type* ProgramBuilder::TypeOf(ast::Expression* expr) const {
auto* sem = Sem().Get(expr);
return sem ? sem->Type() : nullptr;
}
ast::ConstructorExpression* ProgramBuilder::ConstructValueFilledWith(
type::Type* type,
sem::Type* type,
int elem_value) {
auto* unwrapped_type = type->UnwrapAliasIfNeeded();
if (unwrapped_type->Is<type::Bool>()) {
if (unwrapped_type->Is<sem::Bool>()) {
return create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(type, elem_value == 0 ? false : true));
}
if (unwrapped_type->Is<type::I32>()) {
if (unwrapped_type->Is<sem::I32>()) {
return create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
type, static_cast<ProgramBuilder::i32>(elem_value)));
}
if (unwrapped_type->Is<type::U32>()) {
if (unwrapped_type->Is<sem::U32>()) {
return create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>(
type, static_cast<ProgramBuilder::u32>(elem_value)));
}
if (unwrapped_type->Is<type::F32>()) {
if (unwrapped_type->Is<sem::F32>()) {
return create<ast::ScalarConstructorExpression>(create<ast::FloatLiteral>(
type, static_cast<ProgramBuilder::f32>(elem_value)));
}
if (auto* v = unwrapped_type->As<type::Vector>()) {
if (auto* v = unwrapped_type->As<sem::Vector>()) {
ast::ExpressionList el(v->size());
for (size_t i = 0; i < el.size(); i++) {
el[i] = ConstructValueFilledWith(v->type(), elem_value);
}
return create<ast::TypeConstructorExpression>(type, std::move(el));
}
if (auto* m = unwrapped_type->As<type::Matrix>()) {
auto* col_vec_type = create<type::Vector>(m->type(), m->rows());
if (auto* m = unwrapped_type->As<sem::Matrix>()) {
auto* col_vec_type = create<sem::Vector>(m->type(), m->rows());
ast::ExpressionList el(col_vec_type->size());
for (size_t i = 0; i < el.size(); i++) {
el[i] = ConstructValueFilledWith(col_vec_type, elem_value);

View File

@ -124,13 +124,13 @@ class ProgramBuilder {
ProgramID ID() const { return id_; }
/// @returns a reference to the program's types
type::Manager& Types() {
sem::Manager& Types() {
AssertNotMoved();
return types_;
}
/// @returns a reference to the program's types
const type::Manager& Types() const {
const sem::Manager& Types() const {
AssertNotMoved();
return types_;
}
@ -287,7 +287,7 @@ class ProgramBuilder {
return sem_nodes_.Create<T>(std::forward<ARGS>(args)...);
}
/// Creates a new type::Type owned by the ProgramBuilder.
/// Creates a new sem::Type owned by the ProgramBuilder.
/// When the ProgramBuilder is destructed, owned ProgramBuilder and the
/// returned`Type` will also be destructed.
/// Types are unique (de-aliased), and so calling create() for the same `T`
@ -300,9 +300,9 @@ class ProgramBuilder {
/// @param args the arguments to pass to the type constructor
/// @returns the de-aliased type pointer
template <typename T, typename... ARGS>
traits::EnableIfIsType<T, type::Type>* create(ARGS&&... args) {
static_assert(std::is_base_of<type::Type, T>::value,
"T does not derive from type::Type");
traits::EnableIfIsType<T, sem::Type>* create(ARGS&&... args) {
static_assert(std::is_base_of<sem::Type, T>::value,
"T does not derive from sem::Type");
AssertNotMoved();
return types_.Get<T>(std::forward<ARGS>(args)...);
}
@ -324,185 +324,184 @@ class ProgramBuilder {
/// @return the tint AST type for the C type `T`.
template <typename T>
type::Type* Of() const {
sem::Type* Of() const {
return CToAST<T>::get(this);
}
/// @returns a boolean type
type::Bool* bool_() const { return builder->create<type::Bool>(); }
sem::Bool* bool_() const { return builder->create<sem::Bool>(); }
/// @returns a f32 type
type::F32* f32() const { return builder->create<type::F32>(); }
sem::F32* f32() const { return builder->create<sem::F32>(); }
/// @returns a i32 type
type::I32* i32() const { return builder->create<type::I32>(); }
sem::I32* i32() const { return builder->create<sem::I32>(); }
/// @returns a u32 type
type::U32* u32() const { return builder->create<type::U32>(); }
sem::U32* u32() const { return builder->create<sem::U32>(); }
/// @returns a void type
type::Void* void_() const { return builder->create<type::Void>(); }
sem::Void* void_() const { return builder->create<sem::Void>(); }
/// @param type vector subtype
/// @return the tint AST type for a 2-element vector of `type`.
type::Vector* vec2(type::Type* type) const {
return builder->create<type::Vector>(type, 2u);
sem::Vector* vec2(sem::Type* type) const {
return builder->create<sem::Vector>(type, 2u);
}
/// @param type vector subtype
/// @return the tint AST type for a 3-element vector of `type`.
type::Vector* vec3(type::Type* type) const {
return builder->create<type::Vector>(type, 3u);
sem::Vector* vec3(sem::Type* type) const {
return builder->create<sem::Vector>(type, 3u);
}
/// @param type vector subtype
/// @return the tint AST type for a 4-element vector of `type`.
type::Type* vec4(type::Type* type) const {
return builder->create<type::Vector>(type, 4u);
sem::Type* vec4(sem::Type* type) const {
return builder->create<sem::Vector>(type, 4u);
}
/// @return the tint AST type for a 2-element vector of the C type `T`.
template <typename T>
type::Vector* vec2() const {
sem::Vector* vec2() const {
return vec2(Of<T>());
}
/// @return the tint AST type for a 3-element vector of the C type `T`.
template <typename T>
type::Vector* vec3() const {
sem::Vector* vec3() const {
return vec3(Of<T>());
}
/// @return the tint AST type for a 4-element vector of the C type `T`.
template <typename T>
type::Type* vec4() const {
sem::Type* vec4() const {
return vec4(Of<T>());
}
/// @param type matrix subtype
/// @return the tint AST type for a 2x3 matrix of `type`.
type::Matrix* mat2x2(type::Type* type) const {
return builder->create<type::Matrix>(type, 2u, 2u);
sem::Matrix* mat2x2(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 2u, 2u);
}
/// @param type matrix subtype
/// @return the tint AST type for a 2x3 matrix of `type`.
type::Matrix* mat2x3(type::Type* type) const {
return builder->create<type::Matrix>(type, 3u, 2u);
sem::Matrix* mat2x3(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 3u, 2u);
}
/// @param type matrix subtype
/// @return the tint AST type for a 2x4 matrix of `type`.
type::Matrix* mat2x4(type::Type* type) const {
return builder->create<type::Matrix>(type, 4u, 2u);
sem::Matrix* mat2x4(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 4u, 2u);
}
/// @param type matrix subtype
/// @return the tint AST type for a 3x2 matrix of `type`.
type::Matrix* mat3x2(type::Type* type) const {
return builder->create<type::Matrix>(type, 2u, 3u);
sem::Matrix* mat3x2(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 2u, 3u);
}
/// @param type matrix subtype
/// @return the tint AST type for a 3x3 matrix of `type`.
type::Matrix* mat3x3(type::Type* type) const {
return builder->create<type::Matrix>(type, 3u, 3u);
sem::Matrix* mat3x3(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 3u, 3u);
}
/// @param type matrix subtype
/// @return the tint AST type for a 3x4 matrix of `type`.
type::Matrix* mat3x4(type::Type* type) const {
return builder->create<type::Matrix>(type, 4u, 3u);
sem::Matrix* mat3x4(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 4u, 3u);
}
/// @param type matrix subtype
/// @return the tint AST type for a 4x2 matrix of `type`.
type::Matrix* mat4x2(type::Type* type) const {
return builder->create<type::Matrix>(type, 2u, 4u);
sem::Matrix* mat4x2(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 2u, 4u);
}
/// @param type matrix subtype
/// @return the tint AST type for a 4x3 matrix of `type`.
type::Matrix* mat4x3(type::Type* type) const {
return builder->create<type::Matrix>(type, 3u, 4u);
sem::Matrix* mat4x3(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 3u, 4u);
}
/// @param type matrix subtype
/// @return the tint AST type for a 4x4 matrix of `type`.
type::Matrix* mat4x4(type::Type* type) const {
return builder->create<type::Matrix>(type, 4u, 4u);
sem::Matrix* mat4x4(sem::Type* type) const {
return builder->create<sem::Matrix>(type, 4u, 4u);
}
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x2() const {
sem::Matrix* mat2x2() const {
return mat2x2(Of<T>());
}
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x3() const {
sem::Matrix* mat2x3() const {
return mat2x3(Of<T>());
}
/// @return the tint AST type for a 2x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat2x4() const {
sem::Matrix* mat2x4() const {
return mat2x4(Of<T>());
}
/// @return the tint AST type for a 3x2 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x2() const {
sem::Matrix* mat3x2() const {
return mat3x2(Of<T>());
}
/// @return the tint AST type for a 3x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x3() const {
sem::Matrix* mat3x3() const {
return mat3x3(Of<T>());
}
/// @return the tint AST type for a 3x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat3x4() const {
sem::Matrix* mat3x4() const {
return mat3x4(Of<T>());
}
/// @return the tint AST type for a 4x2 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x2() const {
sem::Matrix* mat4x2() const {
return mat4x2(Of<T>());
}
/// @return the tint AST type for a 4x3 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x3() const {
sem::Matrix* mat4x3() const {
return mat4x3(Of<T>());
}
/// @return the tint AST type for a 4x4 matrix of the C type `T`.
template <typename T>
type::Matrix* mat4x4() const {
sem::Matrix* mat4x4() const {
return mat4x4(Of<T>());
}
/// @param subtype the array element type
/// @param n the array size. 0 represents a runtime-array.
/// @return the tint AST type for a array of size `n` of type `T`
type::ArrayType* array(type::Type* subtype, uint32_t n = 0) const {
return builder->create<type::ArrayType>(subtype, n,
ast::DecorationList{});
sem::ArrayType* array(sem::Type* subtype, uint32_t n = 0) const {
return builder->create<sem::ArrayType>(subtype, n, ast::DecorationList{});
}
/// @param subtype the array element type
/// @param n the array size. 0 represents a runtime-array.
/// @param stride the array stride.
/// @return the tint AST type for a array of size `n` of type `T`
type::ArrayType* array(type::Type* subtype,
uint32_t n,
uint32_t stride) const {
return builder->create<type::ArrayType>(
sem::ArrayType* array(sem::Type* subtype,
uint32_t n,
uint32_t stride) const {
return builder->create<sem::ArrayType>(
subtype, n,
ast::DecorationList{
builder->create<ast::StrideDecoration>(stride),
@ -511,14 +510,14 @@ class ProgramBuilder {
/// @return the tint AST type for an array of size `N` of type `T`
template <typename T, int N = 0>
type::ArrayType* array() const {
sem::ArrayType* array() const {
return array(Of<T>(), N);
}
/// @param stride the array stride
/// @return the tint AST type for an array of size `N` of type `T`
template <typename T, int N = 0>
type::ArrayType* array(uint32_t stride) const {
sem::ArrayType* array(uint32_t stride) const {
return array(Of<T>(), N, stride);
}
@ -527,33 +526,33 @@ class ProgramBuilder {
/// @param type the alias type
/// @returns the alias pointer
template <typename NAME>
type::Alias* alias(NAME&& name, type::Type* type) const {
return builder->create<type::Alias>(
builder->Sym(std::forward<NAME>(name)), type);
sem::Alias* alias(NAME&& name, sem::Type* type) const {
return builder->create<sem::Alias>(builder->Sym(std::forward<NAME>(name)),
type);
}
/// Creates an access control qualifier type
/// @param access the access control
/// @param type the inner type
/// @returns the access control qualifier type
type::AccessControl* access(ast::AccessControl access,
type::Type* type) const {
return builder->create<type::AccessControl>(access, type);
sem::AccessControl* access(ast::AccessControl access,
sem::Type* type) const {
return builder->create<sem::AccessControl>(access, type);
}
/// @return the tint AST pointer to `type` with the given ast::StorageClass
/// @param type the type of the pointer
/// @param storage_class the storage class of the pointer
type::Pointer* pointer(type::Type* type,
ast::StorageClass storage_class) const {
return builder->create<type::Pointer>(type, storage_class);
sem::Pointer* pointer(sem::Type* type,
ast::StorageClass storage_class) const {
return builder->create<sem::Pointer>(type, storage_class);
}
/// @return the tint AST pointer to type `T` with the given
/// ast::StorageClass.
/// @param storage_class the storage class of the pointer
template <typename T>
type::Pointer* pointer(ast::StorageClass storage_class) const {
sem::Pointer* pointer(ast::StorageClass storage_class) const {
return pointer(Of<T>(), storage_class);
}
@ -561,8 +560,8 @@ class ProgramBuilder {
/// @param impl the struct implementation
/// @returns a struct pointer
template <typename NAME>
type::StructType* struct_(NAME&& name, ast::Struct* impl) const {
return builder->create<type::StructType>(
sem::StructType* struct_(NAME&& name, ast::Struct* impl) const {
return builder->create<sem::StructType>(
builder->Sym(std::forward<NAME>(name)), impl);
}
@ -571,7 +570,7 @@ class ProgramBuilder {
/// contains a single static `get()` method for obtaining the corresponding
/// AST type for the C type `T`.
/// `get()` has the signature:
/// `static type::Type* get(Types* t)`
/// `static sem::Type* get(Types* t)`
template <typename T>
struct CToAST {};
@ -733,7 +732,7 @@ class ProgramBuilder {
/// @return an `ast::TypeConstructorExpression` of `type` constructed with the
/// values `args`.
template <typename... ARGS>
ast::TypeConstructorExpression* Construct(type::Type* type, ARGS&&... args) {
ast::TypeConstructorExpression* Construct(sem::Type* type, ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
type, ExprList(std::forward<ARGS>(args)...));
}
@ -746,7 +745,7 @@ class ProgramBuilder {
/// @param elem_value the initial or element value (for vec and mat) to
/// construct with
/// @return the constructor expression
ast::ConstructorExpression* ConstructValueFilledWith(type::Type* type,
ast::ConstructorExpression* ConstructValueFilledWith(sem::Type* type,
int elem_value = 0);
/// @param args the arguments for the vector constructor
@ -872,7 +871,7 @@ class ProgramBuilder {
/// @return an `ast::TypeConstructorExpression` of an array with element type
/// `subtype`, constructed with the values `args`.
template <typename... ARGS>
ast::TypeConstructorExpression* array(type::Type* subtype,
ast::TypeConstructorExpression* array(sem::Type* subtype,
uint32_t n,
ARGS&&... args) {
return create<ast::TypeConstructorExpression>(
@ -887,7 +886,7 @@ class ProgramBuilder {
/// @returns a `ast::Variable` with the given name, storage and type
template <typename NAME>
ast::Variable* Var(NAME&& name,
type::Type* type,
sem::Type* type,
ast::StorageClass storage,
ast::Expression* constructor = nullptr,
ast::DecorationList decorations = {}) {
@ -905,7 +904,7 @@ class ProgramBuilder {
template <typename NAME>
ast::Variable* Var(const Source& source,
NAME&& name,
type::Type* type,
sem::Type* type,
ast::StorageClass storage,
ast::Expression* constructor = nullptr,
ast::DecorationList decorations = {}) {
@ -920,7 +919,7 @@ class ProgramBuilder {
/// @returns a constant `ast::Variable` with the given name and type
template <typename NAME>
ast::Variable* Const(NAME&& name,
type::Type* type,
sem::Type* type,
ast::Expression* constructor = nullptr,
ast::DecorationList decorations = {}) {
return create<ast::Variable>(Sym(std::forward<NAME>(name)),
@ -937,7 +936,7 @@ class ProgramBuilder {
template <typename NAME>
ast::Variable* Const(const Source& source,
NAME&& name,
type::Type* type,
sem::Type* type,
ast::Expression* constructor = nullptr,
ast::DecorationList decorations = {}) {
return create<ast::Variable>(source, Sym(std::forward<NAME>(name)),
@ -951,7 +950,7 @@ class ProgramBuilder {
/// @returns a constant `ast::Variable` with the given name and type
template <typename NAME>
ast::Variable* Param(NAME&& name,
type::Type* type,
sem::Type* type,
ast::DecorationList decorations = {}) {
return create<ast::Variable>(Sym(std::forward<NAME>(name)),
ast::StorageClass::kNone, type, true, nullptr,
@ -966,7 +965,7 @@ class ProgramBuilder {
template <typename NAME>
ast::Variable* Param(const Source& source,
NAME&& name,
type::Type* type,
sem::Type* type,
ast::DecorationList decorations = {}) {
return create<ast::Variable>(source, Sym(std::forward<NAME>(name)),
ast::StorageClass::kNone, type, true, nullptr,
@ -1127,7 +1126,7 @@ class ProgramBuilder {
ast::Function* Func(const Source& source,
NAME&& name,
ast::VariableList params,
type::Type* type,
sem::Type* type,
ast::StatementList body,
ast::DecorationList decorations = {},
ast::DecorationList return_type_decorations = {}) {
@ -1151,7 +1150,7 @@ class ProgramBuilder {
template <typename NAME>
ast::Function* Func(NAME&& name,
ast::VariableList params,
type::Type* type,
sem::Type* type,
ast::StatementList body,
ast::DecorationList decorations = {},
ast::DecorationList return_type_decorations = {}) {
@ -1174,18 +1173,18 @@ class ProgramBuilder {
return create<ast::ReturnStatement>(Expr(std::forward<EXPR>(val)));
}
/// Creates a ast::Struct and type::StructType, registering the
/// type::StructType with the AST().ConstructedTypes().
/// Creates a ast::Struct and sem::StructType, registering the
/// sem::StructType with the AST().ConstructedTypes().
/// @param source the source information
/// @param name the struct name
/// @param members the struct members
/// @param decorations the optional struct decorations
/// @returns the struct type
template <typename NAME>
type::StructType* Structure(const Source& source,
NAME&& name,
ast::StructMemberList members,
ast::DecorationList decorations = {}) {
sem::StructType* Structure(const Source& source,
NAME&& name,
ast::StructMemberList members,
ast::DecorationList decorations = {}) {
auto* impl =
create<ast::Struct>(source, std::move(members), std::move(decorations));
auto* type = ty.struct_(Sym(std::forward<NAME>(name)), impl);
@ -1193,16 +1192,16 @@ class ProgramBuilder {
return type;
}
/// Creates a ast::Struct and type::StructType, registering the
/// type::StructType with the AST().ConstructedTypes().
/// Creates a ast::Struct and sem::StructType, registering the
/// sem::StructType with the AST().ConstructedTypes().
/// @param name the struct name
/// @param members the struct members
/// @param decorations the optional struct decorations
/// @returns the struct type
template <typename NAME>
type::StructType* Structure(NAME&& name,
ast::StructMemberList members,
ast::DecorationList decorations = {}) {
sem::StructType* Structure(NAME&& name,
ast::StructMemberList members,
ast::DecorationList decorations = {}) {
auto* impl =
create<ast::Struct>(std::move(members), std::move(decorations));
auto* type = ty.struct_(Sym(std::forward<NAME>(name)), impl);
@ -1219,7 +1218,7 @@ class ProgramBuilder {
template <typename NAME>
ast::StructMember* Member(const Source& source,
NAME&& name,
type::Type* type,
sem::Type* type,
ast::DecorationList decorations = {}) {
return create<ast::StructMember>(source, Sym(std::forward<NAME>(name)),
type, std::move(decorations));
@ -1232,7 +1231,7 @@ class ProgramBuilder {
/// @returns the struct member pointer
template <typename NAME>
ast::StructMember* Member(NAME&& name,
type::Type* type,
sem::Type* type,
ast::DecorationList decorations = {}) {
return create<ast::StructMember>(source_, Sym(std::forward<NAME>(name)),
type, std::move(decorations));
@ -1244,7 +1243,7 @@ class ProgramBuilder {
/// @param type the struct member type
/// @returns the struct member pointer
template <typename NAME>
ast::StructMember* Member(uint32_t offset, NAME&& name, type::Type* type) {
ast::StructMember* Member(uint32_t offset, NAME&& name, sem::Type* type) {
return create<ast::StructMember>(
source_, Sym(std::forward<NAME>(name)), type,
ast::DecorationList{
@ -1417,7 +1416,7 @@ class ProgramBuilder {
/// @param expr the AST expression
/// @return the resolved semantic type for the expression, or nullptr if the
/// expression has no resolved type.
type::Type* TypeOf(ast::Expression* expr) const;
sem::Type* TypeOf(ast::Expression* expr) const;
/// Wraps the ast::Literal in a statement. This is used by tests that
/// construct a partial AST and require the Resolver to reach these
@ -1465,7 +1464,7 @@ class ProgramBuilder {
private:
ProgramID id_;
type::Manager types_;
sem::Manager types_;
ASTNodeAllocator ast_nodes_;
SemNodeAllocator sem_nodes_;
ast::Module* ast_;
@ -1489,31 +1488,31 @@ class ProgramBuilder {
// Various template specializations for ProgramBuilder::TypesBuilder::CToAST.
template <>
struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::i32> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
static sem::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->i32();
}
};
template <>
struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::u32> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
static sem::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->u32();
}
};
template <>
struct ProgramBuilder::TypesBuilder::CToAST<ProgramBuilder::f32> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
static sem::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->f32();
}
};
template <>
struct ProgramBuilder::TypesBuilder::CToAST<bool> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
static sem::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->bool_();
}
};
template <>
struct ProgramBuilder::TypesBuilder::CToAST<void> {
static type::Type* get(const ProgramBuilder::TypesBuilder* t) {
static sem::Type* get(const ProgramBuilder::TypesBuilder* t) {
return t->void_();
}
};

View File

@ -100,83 +100,83 @@ ast::Builtin EnumConverter::ToBuiltin(SpvBuiltIn b) {
return ast::Builtin::kNone;
}
type::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) {
sem::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) {
if (arrayed) {
switch (dim) {
case SpvDim2D:
return type::TextureDimension::k2dArray;
return sem::TextureDimension::k2dArray;
case SpvDimCube:
return type::TextureDimension::kCubeArray;
return sem::TextureDimension::kCubeArray;
default:
break;
}
Fail() << "arrayed dimension must be 1D, 2D, or Cube. Got " << int(dim);
return type::TextureDimension::kNone;
return sem::TextureDimension::kNone;
}
// Assume non-arrayed
switch (dim) {
case SpvDim1D:
return type::TextureDimension::k1d;
return sem::TextureDimension::k1d;
case SpvDim2D:
return type::TextureDimension::k2d;
return sem::TextureDimension::k2d;
case SpvDim3D:
return type::TextureDimension::k3d;
return sem::TextureDimension::k3d;
case SpvDimCube:
return type::TextureDimension::kCube;
return sem::TextureDimension::kCube;
default:
break;
}
Fail() << "invalid dimension: " << int(dim);
return type::TextureDimension::kNone;
return sem::TextureDimension::kNone;
}
type::ImageFormat EnumConverter::ToImageFormat(SpvImageFormat fmt) {
sem::ImageFormat EnumConverter::ToImageFormat(SpvImageFormat fmt) {
switch (fmt) {
case SpvImageFormatUnknown:
return type::ImageFormat::kNone;
return sem::ImageFormat::kNone;
// 8 bit channels
case SpvImageFormatRgba8:
return type::ImageFormat::kRgba8Unorm;
return sem::ImageFormat::kRgba8Unorm;
case SpvImageFormatRgba8Snorm:
return type::ImageFormat::kRgba8Snorm;
return sem::ImageFormat::kRgba8Snorm;
case SpvImageFormatRgba8ui:
return type::ImageFormat::kRgba8Uint;
return sem::ImageFormat::kRgba8Uint;
case SpvImageFormatRgba8i:
return type::ImageFormat::kRgba8Sint;
return sem::ImageFormat::kRgba8Sint;
// 16 bit channels
case SpvImageFormatRgba16ui:
return type::ImageFormat::kRgba16Uint;
return sem::ImageFormat::kRgba16Uint;
case SpvImageFormatRgba16i:
return type::ImageFormat::kRgba16Sint;
return sem::ImageFormat::kRgba16Sint;
case SpvImageFormatRgba16f:
return type::ImageFormat::kRgba16Float;
return sem::ImageFormat::kRgba16Float;
// 32 bit channels
case SpvImageFormatR32ui:
return type::ImageFormat::kR32Uint;
return sem::ImageFormat::kR32Uint;
case SpvImageFormatR32i:
return type::ImageFormat::kR32Sint;
return sem::ImageFormat::kR32Sint;
case SpvImageFormatR32f:
return type::ImageFormat::kR32Float;
return sem::ImageFormat::kR32Float;
case SpvImageFormatRg32ui:
return type::ImageFormat::kRg32Uint;
return sem::ImageFormat::kRg32Uint;
case SpvImageFormatRg32i:
return type::ImageFormat::kRg32Sint;
return sem::ImageFormat::kRg32Sint;
case SpvImageFormatRg32f:
return type::ImageFormat::kRg32Float;
return sem::ImageFormat::kRg32Float;
case SpvImageFormatRgba32ui:
return type::ImageFormat::kRgba32Uint;
return sem::ImageFormat::kRgba32Uint;
case SpvImageFormatRgba32i:
return type::ImageFormat::kRgba32Sint;
return sem::ImageFormat::kRgba32Sint;
case SpvImageFormatRgba32f:
return type::ImageFormat::kRgba32Float;
return sem::ImageFormat::kRgba32Float;
default:
break;
}
Fail() << "invalid image format: " << int(fmt);
return type::ImageFormat::kNone;
return sem::ImageFormat::kNone;
}
} // namespace spirv

View File

@ -58,13 +58,13 @@ class EnumConverter {
/// @param dim the SPIR-V Dim value
/// @param arrayed true if the texture is arrayed
/// @returns a Tint AST texture dimension
type::TextureDimension ToDim(SpvDim dim, bool arrayed);
sem::TextureDimension ToDim(SpvDim dim, bool arrayed);
/// Converts a SPIR-V Image Format to a Tint ImageFormat
/// On failure, logs an error and returns kNone
/// @param fmt the SPIR-V format
/// @returns a Tint AST format
type::ImageFormat ToImageFormat(SpvImageFormat fmt);
sem::ImageFormat ToImageFormat(SpvImageFormat fmt);
private:
/// Registers a failure and returns a stream for log diagnostics.

View File

@ -243,7 +243,7 @@ struct DimCase {
SpvDim dim;
bool arrayed;
bool expect_success;
type::TextureDimension expected;
sem::TextureDimension expected;
};
inline std::ostream& operator<<(std::ostream& out, DimCase dc) {
out << "DimCase{ SpvDim:" << int(dc.dim) << " arrayed?:" << int(dc.arrayed)
@ -287,38 +287,37 @@ INSTANTIATE_TEST_SUITE_P(
SpvDimTest,
testing::Values(
// Non-arrayed
DimCase{SpvDim1D, false, true, type::TextureDimension::k1d},
DimCase{SpvDim2D, false, true, type::TextureDimension::k2d},
DimCase{SpvDim3D, false, true, type::TextureDimension::k3d},
DimCase{SpvDimCube, false, true, type::TextureDimension::kCube},
DimCase{SpvDim1D, false, true, sem::TextureDimension::k1d},
DimCase{SpvDim2D, false, true, sem::TextureDimension::k2d},
DimCase{SpvDim3D, false, true, sem::TextureDimension::k3d},
DimCase{SpvDimCube, false, true, sem::TextureDimension::kCube},
// Arrayed
DimCase{SpvDim2D, true, true, type::TextureDimension::k2dArray},
DimCase{SpvDimCube, true, true, type::TextureDimension::kCubeArray}));
DimCase{SpvDim2D, true, true, sem::TextureDimension::k2dArray},
DimCase{SpvDimCube, true, true, sem::TextureDimension::kCubeArray}));
INSTANTIATE_TEST_SUITE_P(
EnumConverterBad,
SpvDimTest,
testing::Values(
// Invalid SPIR-V dimensionality.
DimCase{SpvDimMax, false, false, type::TextureDimension::kNone},
DimCase{SpvDimMax, true, false, type::TextureDimension::kNone},
DimCase{SpvDimMax, false, false, sem::TextureDimension::kNone},
DimCase{SpvDimMax, true, false, sem::TextureDimension::kNone},
// Vulkan non-arrayed dimensionalities not supported by WGSL.
DimCase{SpvDimRect, false, false, type::TextureDimension::kNone},
DimCase{SpvDimBuffer, false, false, type::TextureDimension::kNone},
DimCase{SpvDimSubpassData, false, false, type::TextureDimension::kNone},
DimCase{SpvDimRect, false, false, sem::TextureDimension::kNone},
DimCase{SpvDimBuffer, false, false, sem::TextureDimension::kNone},
DimCase{SpvDimSubpassData, false, false, sem::TextureDimension::kNone},
// Arrayed dimensionalities not supported by WGSL
DimCase{SpvDim3D, true, false, type::TextureDimension::kNone},
DimCase{SpvDimRect, true, false, type::TextureDimension::kNone},
DimCase{SpvDimBuffer, true, false, type::TextureDimension::kNone},
DimCase{SpvDimSubpassData, true, false,
type::TextureDimension::kNone}));
DimCase{SpvDim3D, true, false, sem::TextureDimension::kNone},
DimCase{SpvDimRect, true, false, sem::TextureDimension::kNone},
DimCase{SpvDimBuffer, true, false, sem::TextureDimension::kNone},
DimCase{SpvDimSubpassData, true, false, sem::TextureDimension::kNone}));
// ImageFormat
struct ImageFormatCase {
SpvImageFormat format;
bool expect_success;
type::ImageFormat expected;
sem::ImageFormat expected;
};
inline std::ostream& operator<<(std::ostream& out, ImageFormatCase ifc) {
out << "ImageFormatCase{ SpvImageFormat:" << int(ifc.format)
@ -362,70 +361,68 @@ INSTANTIATE_TEST_SUITE_P(
SpvImageFormatTest,
testing::Values(
// Unknown. This is used for sampled images.
ImageFormatCase{SpvImageFormatUnknown, true, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatUnknown, true, sem::ImageFormat::kNone},
// 8 bit channels
ImageFormatCase{SpvImageFormatRgba8, true,
type::ImageFormat::kRgba8Unorm},
sem::ImageFormat::kRgba8Unorm},
ImageFormatCase{SpvImageFormatRgba8Snorm, true,
type::ImageFormat::kRgba8Snorm},
sem::ImageFormat::kRgba8Snorm},
ImageFormatCase{SpvImageFormatRgba8ui, true,
type::ImageFormat::kRgba8Uint},
sem::ImageFormat::kRgba8Uint},
ImageFormatCase{SpvImageFormatRgba8i, true,
type::ImageFormat::kRgba8Sint},
sem::ImageFormat::kRgba8Sint},
// 16 bit channels
ImageFormatCase{SpvImageFormatRgba16ui, true,
type::ImageFormat::kRgba16Uint},
sem::ImageFormat::kRgba16Uint},
ImageFormatCase{SpvImageFormatRgba16i, true,
type::ImageFormat::kRgba16Sint},
sem::ImageFormat::kRgba16Sint},
ImageFormatCase{SpvImageFormatRgba16f, true,
type::ImageFormat::kRgba16Float},
sem::ImageFormat::kRgba16Float},
// 32 bit channels
// ... 1 channel
ImageFormatCase{SpvImageFormatR32ui, true, type::ImageFormat::kR32Uint},
ImageFormatCase{SpvImageFormatR32i, true, type::ImageFormat::kR32Sint},
ImageFormatCase{SpvImageFormatR32f, true, type::ImageFormat::kR32Float},
ImageFormatCase{SpvImageFormatR32ui, true, sem::ImageFormat::kR32Uint},
ImageFormatCase{SpvImageFormatR32i, true, sem::ImageFormat::kR32Sint},
ImageFormatCase{SpvImageFormatR32f, true, sem::ImageFormat::kR32Float},
// ... 2 channels
ImageFormatCase{SpvImageFormatRg32ui, true,
type::ImageFormat::kRg32Uint},
ImageFormatCase{SpvImageFormatRg32i, true,
type::ImageFormat::kRg32Sint},
sem::ImageFormat::kRg32Uint},
ImageFormatCase{SpvImageFormatRg32i, true, sem::ImageFormat::kRg32Sint},
ImageFormatCase{SpvImageFormatRg32f, true,
type::ImageFormat::kRg32Float},
sem::ImageFormat::kRg32Float},
// ... 4 channels
ImageFormatCase{SpvImageFormatRgba32ui, true,
type::ImageFormat::kRgba32Uint},
sem::ImageFormat::kRgba32Uint},
ImageFormatCase{SpvImageFormatRgba32i, true,
type::ImageFormat::kRgba32Sint},
sem::ImageFormat::kRgba32Sint},
ImageFormatCase{SpvImageFormatRgba32f, true,
type::ImageFormat::kRgba32Float}));
sem::ImageFormat::kRgba32Float}));
INSTANTIATE_TEST_SUITE_P(
EnumConverterBad,
SpvImageFormatTest,
testing::Values(
// Scanning in order from the SPIR-V spec.
ImageFormatCase{SpvImageFormatRg16f, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16f, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR11fG11fB10f, false,
type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR16f, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRgb10A2, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR16, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR8, false, type::ImageFormat::kNone},
sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR16f, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRgb10A2, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR16, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR8, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRgba16Snorm, false,
type::ImageFormat::kNone},
sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16Snorm, false,
type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8Snorm, false,
type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16i, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8i, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR8i, false, type::ImageFormat::kNone},
sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8Snorm, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16i, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8i, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR8i, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRgb10a2ui, false,
type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16ui, false, type::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8ui, false, type::ImageFormat::kNone}));
sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16ui, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8ui, false, sem::ImageFormat::kNone}));
} // namespace
} // namespace spirv

View File

@ -724,8 +724,8 @@ FunctionEmitter::FunctionEmitter(ParserImpl* pi,
fail_stream_(pi->fail_stream()),
namer_(pi->namer()),
function_(function),
i32_(builder_.create<type::I32>()),
u32_(builder_.create<type::U32>()),
i32_(builder_.create<sem::I32>()),
u32_(builder_.create<sem::U32>()),
sample_mask_in_id(0u),
sample_mask_out_id(0u),
ep_info_(ep_info) {
@ -931,7 +931,7 @@ bool FunctionEmitter::ParseFunctionDeclaration(FunctionDeclaration* decl) {
return success();
}
type::Type* FunctionEmitter::GetVariableStoreType(
sem::Type* FunctionEmitter::GetVariableStoreType(
const spvtools::opt::Instruction& var_decl_inst) {
const auto type_id = var_decl_inst.type_id();
auto* var_ref_type = type_mgr_->GetType(type_id);
@ -2029,7 +2029,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
<< id;
return {};
case SkipReason::kPointSizeBuiltinValue: {
auto* f32 = create<type::F32>();
auto* f32 = create<sem::F32>();
return {f32,
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, f32, 1.0f))};
@ -3145,8 +3145,8 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
}
auto expr = MakeExpression(ptr_id);
// The load result type is the pointee type of its operand.
TINT_ASSERT(expr.type->Is<type::Pointer>());
expr.type = expr.type->As<type::Pointer>()->type();
TINT_ASSERT(expr.type->Is<sem::Pointer>());
expr.type = expr.type->As<sem::Pointer>()->type();
return EmitConstDefOrWriteToHoistedVar(inst, expr);
}
@ -3242,7 +3242,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
const auto opcode = inst.opcode();
type::Type* ast_type =
sem::Type* ast_type =
inst.type_id() != 0 ? parser_impl_.ConvertType(inst.type_id()) : nullptr;
auto binary_op = ConvertBinaryOp(opcode);
@ -3388,7 +3388,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
auto* func = create<ast::IdentifierExpression>(
Source{}, builder_.Symbols().Register(name));
ast::ExpressionList operands;
type::Type* first_operand_type = nullptr;
sem::Type* first_operand_type = nullptr;
// All parameters to GLSL.std.450 extended instructions are IDs.
for (uint32_t iarg = 2; iarg < inst.NumInOperands(); ++iarg) {
TypedExpression operand = MakeOperand(inst, iarg);
@ -3630,7 +3630,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
type_mgr_->FindPointerToType(pointee_type_id, storage_class);
auto* ast_pointer_type = parser_impl_.ConvertType(pointer_type_id);
TINT_ASSERT(ast_pointer_type);
TINT_ASSERT(ast_pointer_type->Is<type::Pointer>());
TINT_ASSERT(ast_pointer_type->Is<sem::Pointer>());
current_expr = TypedExpression{ast_pointer_type, next_expr};
}
return current_expr;
@ -3794,7 +3794,7 @@ ast::Expression* FunctionEmitter::MakeTrue(const Source& source) const {
}
ast::Expression* FunctionEmitter::MakeFalse(const Source& source) const {
type::Bool bool_type;
sem::Bool bool_type;
return create<ast::ScalarConstructorExpression>(
source, create<ast::BoolLiteral>(source, parser_impl_.Bool(), false));
}
@ -3815,8 +3815,8 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
// Generate an ast::TypeConstructor expression.
// Assume the literal indices are valid, and there is a valid number of them.
auto source = GetSourceForInst(inst);
type::Vector* result_type =
parser_impl_.ConvertType(inst.type_id())->As<type::Vector>();
sem::Vector* result_type =
parser_impl_.ConvertType(inst.type_id())->As<sem::Vector>();
ast::ExpressionList values;
for (uint32_t i = 2; i < inst.NumInOperands(); ++i) {
const auto index = inst.GetSingleWordInOperand(i);
@ -3907,7 +3907,7 @@ bool FunctionEmitter::RegisterLocallyDefinedValues() {
if (type) {
if (type->AsPointer()) {
if (const auto* ast_type = parser_impl_.ConvertType(inst.type_id())) {
if (auto* ptr = ast_type->As<type::Pointer>()) {
if (auto* ptr = ast_type->As<sem::Pointer>()) {
info->storage_class = ptr->storage_class();
}
}
@ -3952,21 +3952,21 @@ ast::StorageClass FunctionEmitter::GetStorageClassForPointerValue(uint32_t id) {
const auto type_id = def_use_mgr_->GetDef(id)->type_id();
if (type_id) {
auto* ast_type = parser_impl_.ConvertType(type_id);
if (ast_type && ast_type->Is<type::Pointer>()) {
return ast_type->As<type::Pointer>()->storage_class();
if (ast_type && ast_type->Is<sem::Pointer>()) {
return ast_type->As<sem::Pointer>()->storage_class();
}
}
return ast::StorageClass::kNone;
}
type::Type* FunctionEmitter::RemapStorageClass(type::Type* type,
uint32_t result_id) {
if (const auto* ast_ptr_type = type->As<type::Pointer>()) {
sem::Type* FunctionEmitter::RemapStorageClass(sem::Type* type,
uint32_t result_id) {
if (const auto* ast_ptr_type = type->As<sem::Pointer>()) {
// Remap an old-style storage buffer pointer to a new-style storage
// buffer pointer.
const auto sc = GetStorageClassForPointerValue(result_id);
if (ast_ptr_type->storage_class() != sc) {
return builder_.create<type::Pointer>(ast_ptr_type->type(), sc);
return builder_.create<sem::Pointer>(ast_ptr_type->type(), sc);
}
}
return type;
@ -4149,7 +4149,7 @@ TypedExpression FunctionEmitter::MakeNumericConversion(
return {};
}
type::Type* expr_type = nullptr;
sem::Type* expr_type = nullptr;
if ((opcode == SpvOpConvertSToF) || (opcode == SpvOpConvertUToF)) {
if (arg_expr.type->is_integer_scalar_or_vector()) {
expr_type = requested_type;
@ -4214,7 +4214,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
<< inst.PrettyPrint();
}
if (result_type->Is<type::Void>()) {
if (result_type->Is<sem::Void>()) {
return nullptr !=
AddStatement(create<ast::CallStatement>(Source{}, call_expr));
}
@ -4277,7 +4277,7 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
Source{}, builder_.Symbols().Register(name));
ast::ExpressionList params;
type::Type* first_operand_type = nullptr;
sem::Type* first_operand_type = nullptr;
for (uint32_t iarg = 0; iarg < inst.NumInOperands(); ++iarg) {
TypedExpression operand = MakeOperand(inst, iarg);
if (first_operand_type == nullptr) {
@ -4309,8 +4309,8 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
// - you can't select over pointers or pointer vectors, unless you also have
// a VariablePointers* capability, which is not allowed in by WebGPU.
auto* op_ty = operand1.type;
if (op_ty->Is<type::Vector>() || op_ty->is_float_scalar() ||
op_ty->is_integer_scalar() || op_ty->Is<type::Bool>()) {
if (op_ty->Is<sem::Vector>() || op_ty->is_float_scalar() ||
op_ty->is_integer_scalar() || op_ty->Is<sem::Bool>()) {
ast::ExpressionList params;
params.push_back(operand1.expr);
params.push_back(operand2.expr);
@ -4348,18 +4348,18 @@ const spvtools::opt::Instruction* FunctionEmitter::GetImage(
return image;
}
type::Texture* FunctionEmitter::GetImageType(
sem::Texture* FunctionEmitter::GetImageType(
const spvtools::opt::Instruction& image) {
type::Pointer* ptr_type = parser_impl_.GetTypeForHandleVar(image);
sem::Pointer* ptr_type = parser_impl_.GetTypeForHandleVar(image);
if (!parser_impl_.success()) {
Fail();
return nullptr;
}
if (!ptr_type || !ptr_type->type()->UnwrapAll()->Is<type::Texture>()) {
if (!ptr_type || !ptr_type->type()->UnwrapAll()->Is<sem::Texture>()) {
Fail() << "invalid texture type for " << image.PrettyPrint();
return nullptr;
}
return As<type::Texture>(ptr_type->type()->UnwrapAll());
return As<sem::Texture>(ptr_type->type()->UnwrapAll());
}
ast::Expression* FunctionEmitter::GetImageExpression(
@ -4409,12 +4409,12 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
}
type::Pointer* texture_ptr_type = parser_impl_.GetTypeForHandleVar(*image);
sem::Pointer* texture_ptr_type = parser_impl_.GetTypeForHandleVar(*image);
if (!texture_ptr_type) {
return Fail();
}
type::Texture* texture_type =
texture_ptr_type->type()->UnwrapAll()->As<type::Texture>();
sem::Texture* texture_type =
texture_ptr_type->type()->UnwrapAll()->As<sem::Texture>();
if (!texture_type) {
return Fail();
}
@ -4516,7 +4516,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
}
TypedExpression lod = MakeOperand(inst, arg_index);
// When sampling from a depth texture, the Lod operand must be an I32.
if (texture_type->Is<type::DepthTexture>()) {
if (texture_type->Is<sem::DepthTexture>()) {
// Convert it to a signed integer type.
lod = ToI32(lod);
}
@ -4524,8 +4524,8 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
image_operands_mask ^= SpvImageOperandsLodMask;
arg_index++;
} else if ((opcode == SpvOpImageFetch) &&
(texture_type->Is<type::SampledTexture>() ||
texture_type->Is<type::DepthTexture>())) {
(texture_type->Is<sem::SampledTexture>() ||
texture_type->Is<sem::DepthTexture>())) {
// textureLoad on sampled texture and depth texture requires an explicit
// level-of-detail parameter.
params.push_back(parser_impl_.MakeNullValue(i32_));
@ -4550,9 +4550,9 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
<< inst.PrettyPrint();
}
switch (texture_type->dim()) {
case type::TextureDimension::k2d:
case type::TextureDimension::k2dArray:
case type::TextureDimension::k3d:
case sem::TextureDimension::k2d:
case sem::TextureDimension::k2dArray:
case sem::TextureDimension::k3d:
break;
default:
return Fail() << "ConstOffset is only permitted for 2D, 2D Arrayed, "
@ -4588,7 +4588,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
// The result type, derived from the SPIR-V instruction.
auto* result_type = parser_impl_.ConvertType(inst.type_id());
auto* result_component_type = result_type;
if (auto* result_vector_type = result_type->As<type::Vector>()) {
if (auto* result_vector_type = result_type->As<sem::Vector>()) {
result_component_type = result_vector_type->type();
}
@ -4603,7 +4603,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
// dref gather vec4 ImageFetch vec4 TODO(dneto)
// Construct a 4-element vector with the result from the builtin in the
// first component.
if (texture_type->Is<type::DepthTexture>()) {
if (texture_type->Is<sem::DepthTexture>()) {
if (is_non_dref_sample || (opcode == SpvOpImageFetch)) {
value = create<ast::TypeConstructorExpression>(
Source{},
@ -4631,7 +4631,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
// or vice versa. Perform a bitcast.
value = create<ast::BitcastExpression>(Source{}, result_type, call_expr);
}
if (!expected_component_type->Is<type::F32>() &&
if (!expected_component_type->Is<sem::F32>() &&
IsSampledImageAccess(opcode)) {
// WGSL permits sampled image access only on float textures.
// Reject this case in the SPIR-V reader, at least until SPIR-V validation
@ -4675,7 +4675,7 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) {
}
exprs.push_back(
create<ast::CallExpression>(Source{}, dims_ident, dims_args));
if (type::IsTextureArray(texture_type->dim())) {
if (sem::IsTextureArray(texture_type->dim())) {
auto* layers_ident = create<ast::IdentifierExpression>(
Source{}, builder_.Symbols().Register("textureNumLayers"));
exprs.push_back(create<ast::CallExpression>(
@ -4750,14 +4750,14 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
if (!raw_coords.type) {
return {};
}
type::Texture* texture_type = GetImageType(*image);
sem::Texture* texture_type = GetImageType(*image);
if (!texture_type) {
return {};
}
type::TextureDimension dim = texture_type->dim();
sem::TextureDimension dim = texture_type->dim();
// Number of regular coordinates.
uint32_t num_axes = type::NumCoordinateAxes(dim);
bool is_arrayed = type::IsTextureArray(dim);
uint32_t num_axes = sem::NumCoordinateAxes(dim);
bool is_arrayed = sem::IsTextureArray(dim);
if ((num_axes == 0) || (num_axes > 3)) {
Fail() << "unsupported image dimensionality for "
<< texture_type->type_name() << " prompted by "
@ -4769,7 +4769,7 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
if (component_type->is_float_scalar() ||
component_type->is_integer_scalar()) {
num_coords_supplied = 1;
} else if (auto* vec_type = raw_coords.type->As<type::Vector>()) {
} else if (auto* vec_type = raw_coords.type->As<sem::Vector>()) {
component_type = vec_type->type();
num_coords_supplied = vec_type->size();
}
@ -4796,7 +4796,7 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
raw_coords]() -> ast::Expression* {
auto* swizzle_type = (num_axes == 1)
? component_type
: create<type::Vector>(component_type, num_axes);
: create<sem::Vector>(component_type, num_axes);
auto* swizzle = create<ast::MemberAccessorExpression>(
Source{}, raw_coords.expr, PrefixSwizzle(num_axes));
return ToSignedIfUnsigned({swizzle_type, swizzle}).expr;
@ -4830,8 +4830,8 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
ast::Expression* FunctionEmitter::ConvertTexelForStorage(
const spvtools::opt::Instruction& inst,
TypedExpression texel,
type::Texture* texture_type) {
auto* storage_texture_type = texture_type->As<type::StorageTexture>();
sem::Texture* texture_type) {
auto* storage_texture_type = texture_type->As<sem::StorageTexture>();
auto* src_type = texel.type;
if (!storage_texture_type) {
Fail() << "writing to other than storage texture: " << inst.PrettyPrint();
@ -4848,14 +4848,14 @@ ast::Expression* FunctionEmitter::ConvertTexelForStorage(
}
const uint32_t dest_count =
dest_type->is_scalar() ? 1 : dest_type->As<type::Vector>()->size();
dest_type->is_scalar() ? 1 : dest_type->As<sem::Vector>()->size();
if (dest_count == 3) {
Fail() << "3-channel storage textures are not supported: "
<< inst.PrettyPrint();
return nullptr;
}
const uint32_t src_count =
src_type->is_scalar() ? 1 : src_type->As<type::Vector>()->size();
src_type->is_scalar() ? 1 : src_type->As<sem::Vector>()->size();
if (src_count < dest_count) {
Fail() << "texel has too few components for storage texture: " << src_count
<< " provided but " << dest_count
@ -4925,8 +4925,8 @@ TypedExpression FunctionEmitter::ToSignedIfUnsigned(TypedExpression value) {
if (!value.type || !value.type->is_unsigned_scalar_or_vector()) {
return value;
}
if (auto* vec_type = value.type->As<type::Vector>()) {
auto* new_type = create<type::Vector>(i32_, vec_type->size());
if (auto* vec_type = value.type->As<sem::Vector>()) {
auto* new_type = create<sem::Vector>(i32_, vec_type->size());
return {new_type, create<ast::TypeConstructorExpression>(
Source{}, new_type, ast::ExpressionList{value.expr})};
}
@ -4976,10 +4976,9 @@ TypedExpression FunctionEmitter::MakeOuterProduct(
// Synthesize the result.
auto col = MakeOperand(inst, 0);
auto row = MakeOperand(inst, 1);
auto* col_ty = col.type->As<type::Vector>();
auto* row_ty = row.type->As<type::Vector>();
auto* result_ty =
parser_impl_.ConvertType(inst.type_id())->As<type::Matrix>();
auto* col_ty = col.type->As<sem::Vector>();
auto* row_ty = row.type->As<sem::Vector>();
auto* result_ty = parser_impl_.ConvertType(inst.type_id())->As<sem::Matrix>();
if (!col_ty || !col_ty || !result_ty || result_ty->type() != col_ty->type() ||
result_ty->type() != row_ty->type() ||
result_ty->columns() != row_ty->size() ||

View File

@ -512,7 +512,7 @@ class FunctionEmitter {
/// @param type the AST type
/// @param result_id the SPIR-V ID for the locally defined value
/// @returns an possibly updated type
type::Type* RemapStorageClass(type::Type* type, uint32_t result_id);
sem::Type* RemapStorageClass(sem::Type* type, uint32_t result_id);
/// Marks locally defined values when they should get a 'const'
/// definition in WGSL, or a 'var' definition at an outer scope.
@ -853,7 +853,7 @@ class FunctionEmitter {
/// Function parameters
ast::VariableList params;
/// Function return type
type::Type* return_type;
sem::Type* return_type;
/// Function decorations
ast::DecorationList decorations;
};
@ -866,7 +866,7 @@ class FunctionEmitter {
/// @returns the store type for the OpVariable instruction, or
/// null on failure.
type::Type* GetVariableStoreType(
sem::Type* GetVariableStoreType(
const spvtools::opt::Instruction& var_decl_inst);
/// Returns an expression for an instruction operand. Signedness conversion is
@ -934,7 +934,7 @@ class FunctionEmitter {
/// Get the AST texture the SPIR-V image memory object declaration.
/// @param inst the SPIR-V memory object declaration for the image.
/// @returns a texture type, or null on error
type::Texture* GetImageType(const spvtools::opt::Instruction& inst);
sem::Texture* GetImageType(const spvtools::opt::Instruction& inst);
/// Get the expression for the image operand from the first operand to the
/// given instruction.
@ -971,7 +971,7 @@ class FunctionEmitter {
ast::Expression* ConvertTexelForStorage(
const spvtools::opt::Instruction& inst,
TypedExpression texel,
type::Texture* texture_type);
sem::Texture* texture_type);
/// Returns an expression for an OpSelect, if its operands are scalars
/// or vectors. These translate directly to WGSL select. Otherwise, return
@ -1133,8 +1133,8 @@ class FunctionEmitter {
FailStream& fail_stream_;
Namer& namer_;
const spvtools::opt::Function& function_;
type::I32* const i32_; // The unique I32 type object.
type::U32* const u32_; // The unique U32 type object.
sem::I32* const i32_; // The unique I32 type object.
sem::U32* const u32_; // The unique U32 type object.
// The SPIR-V ID for the SampleMask input variable.
uint32_t sample_mask_in_id;

View File

@ -231,7 +231,7 @@ ParserImpl::ParserImpl(const std::vector<uint32_t>& spv_binary)
: Reader(),
spv_binary_(spv_binary),
fail_stream_(&success_, &errors_),
bool_type_(builder_.create<type::Bool>()),
bool_type_(builder_.create<sem::Bool>()),
namer_(fail_stream_),
enum_converter_(fail_stream_),
tools_context_(kInputEnv) {
@ -289,7 +289,7 @@ Program ParserImpl::program() {
return tint::Program(std::move(builder_));
}
type::Type* ParserImpl::ConvertType(uint32_t type_id) {
sem::Type* ParserImpl::ConvertType(uint32_t type_id) {
if (!success_) {
return nullptr;
}
@ -310,7 +310,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id) {
return nullptr;
}
auto save = [this, type_id, spirv_type](type::Type* type) {
auto save = [this, type_id, spirv_type](sem::Type* type) {
if (type != nullptr) {
id_to_type_[type_id] = type;
MaybeGenerateAlias(type_id, spirv_type);
@ -320,7 +320,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id) {
switch (spirv_type->kind()) {
case spvtools::opt::analysis::Type::kVoid:
return save(builder_.create<type::Void>());
return save(builder_.create<sem::Void>());
case spvtools::opt::analysis::Type::kBool:
return save(bool_type_);
case spvtools::opt::analysis::Type::kInteger:
@ -350,7 +350,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id) {
case spvtools::opt::analysis::Type::kImage:
// Fake it for sampler and texture types. These are handled in an
// entirely different way.
return save(builder_.create<type::Void>());
return save(builder_.create<sem::Void>());
default:
break;
}
@ -694,11 +694,11 @@ bool ParserImpl::RegisterEntryPoints() {
return success_;
}
type::Type* ParserImpl::ConvertType(
sem::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Integer* int_ty) {
if (int_ty->width() == 32) {
type::Type* signed_ty = builder_.create<type::I32>();
type::Type* unsigned_ty = builder_.create<type::U32>();
sem::Type* signed_ty = builder_.create<sem::I32>();
sem::Type* unsigned_ty = builder_.create<sem::U32>();
signed_type_for_[unsigned_ty] = signed_ty;
unsigned_type_for_[signed_ty] = unsigned_ty;
return int_ty->IsSigned() ? signed_ty : unsigned_ty;
@ -707,39 +707,39 @@ type::Type* ParserImpl::ConvertType(
return nullptr;
}
type::Type* ParserImpl::ConvertType(
sem::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Float* float_ty) {
if (float_ty->width() == 32) {
return builder_.create<type::F32>();
return builder_.create<sem::F32>();
}
Fail() << "unhandled float width: " << float_ty->width();
return nullptr;
}
type::Type* ParserImpl::ConvertType(
sem::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Vector* vec_ty) {
const auto num_elem = vec_ty->element_count();
auto* ast_elem_ty = ConvertType(type_mgr_->GetId(vec_ty->element_type()));
if (ast_elem_ty == nullptr) {
return nullptr;
}
auto* this_ty = builder_.create<type::Vector>(ast_elem_ty, num_elem);
auto* this_ty = builder_.create<sem::Vector>(ast_elem_ty, num_elem);
// Generate the opposite-signedness vector type, if this type is integral.
if (unsigned_type_for_.count(ast_elem_ty)) {
auto* other_ty = builder_.create<type::Vector>(
unsigned_type_for_[ast_elem_ty], num_elem);
auto* other_ty =
builder_.create<sem::Vector>(unsigned_type_for_[ast_elem_ty], num_elem);
signed_type_for_[other_ty] = this_ty;
unsigned_type_for_[this_ty] = other_ty;
} else if (signed_type_for_.count(ast_elem_ty)) {
auto* other_ty =
builder_.create<type::Vector>(signed_type_for_[ast_elem_ty], num_elem);
builder_.create<sem::Vector>(signed_type_for_[ast_elem_ty], num_elem);
unsigned_type_for_[other_ty] = this_ty;
signed_type_for_[this_ty] = other_ty;
}
return this_ty;
}
type::Type* ParserImpl::ConvertType(
sem::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Matrix* mat_ty) {
const auto* vec_ty = mat_ty->element_type()->AsVector();
const auto* scalar_ty = vec_ty->element_type();
@ -749,10 +749,10 @@ type::Type* ParserImpl::ConvertType(
if (ast_scalar_ty == nullptr) {
return nullptr;
}
return builder_.create<type::Matrix>(ast_scalar_ty, num_rows, num_columns);
return builder_.create<sem::Matrix>(ast_scalar_ty, num_rows, num_columns);
}
type::Type* ParserImpl::ConvertType(
sem::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::RuntimeArray* rtarr_ty) {
auto* ast_elem_ty = ConvertType(type_mgr_->GetId(rtarr_ty->element_type()));
if (ast_elem_ty == nullptr) {
@ -762,10 +762,10 @@ type::Type* ParserImpl::ConvertType(
if (!ParseArrayDecorations(rtarr_ty, &decorations)) {
return nullptr;
}
return create<type::ArrayType>(ast_elem_ty, 0, std::move(decorations));
return create<sem::ArrayType>(ast_elem_ty, 0, std::move(decorations));
}
type::Type* ParserImpl::ConvertType(
sem::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Array* arr_ty) {
const auto elem_type_id = type_mgr_->GetId(arr_ty->element_type());
auto* ast_elem_ty = ConvertType(elem_type_id);
@ -807,8 +807,8 @@ type::Type* ParserImpl::ConvertType(
if (remap_buffer_block_type_.count(elem_type_id)) {
remap_buffer_block_type_.insert(type_mgr_->GetId(arr_ty));
}
return create<type::ArrayType>(ast_elem_ty, static_cast<uint32_t>(num_elem),
std::move(decorations));
return create<sem::ArrayType>(ast_elem_ty, static_cast<uint32_t>(num_elem),
std::move(decorations));
}
bool ParserImpl::ParseArrayDecorations(
@ -840,7 +840,7 @@ bool ParserImpl::ParseArrayDecorations(
return true;
}
type::Type* ParserImpl::ConvertType(
sem::Type* ParserImpl::ConvertType(
uint32_t type_id,
const spvtools::opt::analysis::Struct* struct_ty) {
// Compute the struct decoration.
@ -947,7 +947,7 @@ type::Type* ParserImpl::ConvertType(
namer_.SuggestSanitizedName(type_id, "S");
auto name = namer_.GetName(type_id);
auto* result = builder_.create<type::StructType>(
auto* result = builder_.create<sem::StructType>(
builder_.Symbols().Register(name), ast_struct);
id_to_type_[type_id] = result;
if (num_non_writable_members == members.size()) {
@ -957,8 +957,8 @@ type::Type* ParserImpl::ConvertType(
return result;
}
type::Type* ParserImpl::ConvertType(uint32_t type_id,
const spvtools::opt::analysis::Pointer*) {
sem::Type* ParserImpl::ConvertType(uint32_t type_id,
const spvtools::opt::analysis::Pointer*) {
const auto* inst = def_use_mgr_->GetDef(type_id);
const auto pointee_type_id = inst->GetSingleWordInOperand(1);
const auto storage_class = SpvStorageClass(inst->GetSingleWordInOperand(0));
@ -987,7 +987,7 @@ type::Type* ParserImpl::ConvertType(uint32_t type_id,
ast_storage_class = ast::StorageClass::kStorage;
remap_buffer_block_type_.insert(type_id);
}
return builder_.create<type::Pointer>(ast_elem_ty, ast_storage_class);
return builder_.create<sem::Pointer>(ast_elem_ty, ast_storage_class);
}
bool ParserImpl::RegisterTypes() {
@ -1020,7 +1020,7 @@ bool ParserImpl::EmitScalarSpecConstants() {
// that is OpSpecConstantTrue, OpSpecConstantFalse, or OpSpecConstant.
for (auto& inst : module_->types_values()) {
// These will be populated for a valid scalar spec constant.
type::Type* ast_type = nullptr;
sem::Type* ast_type = nullptr;
ast::ScalarConstructorExpression* ast_expr = nullptr;
switch (inst.opcode()) {
@ -1036,17 +1036,17 @@ bool ParserImpl::EmitScalarSpecConstants() {
case SpvOpSpecConstant: {
ast_type = ConvertType(inst.type_id());
const uint32_t literal_value = inst.GetSingleWordInOperand(0);
if (ast_type->Is<type::I32>()) {
if (ast_type->Is<sem::I32>()) {
ast_expr = create<ast::ScalarConstructorExpression>(
Source{},
create<ast::SintLiteral>(Source{}, ast_type,
static_cast<int32_t>(literal_value)));
} else if (ast_type->Is<type::U32>()) {
} else if (ast_type->Is<sem::U32>()) {
ast_expr = create<ast::ScalarConstructorExpression>(
Source{},
create<ast::UintLiteral>(Source{}, ast_type,
static_cast<uint32_t>(literal_value)));
} else if (ast_type->Is<type::F32>()) {
} else if (ast_type->Is<sem::F32>()) {
float float_value;
// Copy the bits so we can read them as a float.
std::memcpy(&float_value, &literal_value, sizeof(float_value));
@ -1113,7 +1113,7 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
return;
}
const auto name = namer_.GetName(type_id);
auto* ast_alias_type = builder_.create<type::Alias>(
auto* ast_alias_type = builder_.create<sem::Alias>(
builder_.Symbols().Register(name), ast_underlying_type);
// Record this new alias as the AST type for this SPIR-V ID.
id_to_type_[type_id] = ast_alias_type;
@ -1158,7 +1158,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
if (!success_) {
return false;
}
type::Type* ast_type = nullptr;
sem::Type* ast_type = nullptr;
if (spirv_storage_class == SpvStorageClassUniformConstant) {
// These are opaque handles: samplers or textures
ast_type = GetTypeForHandleVar(var);
@ -1172,14 +1172,14 @@ bool ParserImpl::EmitModuleScopeVariables() {
"SPIR-V type with ID: "
<< var.type_id();
}
if (!ast_type->Is<type::Pointer>()) {
if (!ast_type->Is<sem::Pointer>()) {
return Fail() << "variable with ID " << var.result_id()
<< " has non-pointer type " << var.type_id();
}
}
auto* ast_store_type = ast_type->As<type::Pointer>()->type();
auto ast_storage_class = ast_type->As<type::Pointer>()->storage_class();
auto* ast_store_type = ast_type->As<sem::Pointer>()->type();
auto ast_storage_class = ast_type->As<sem::Pointer>()->storage_class();
ast::Expression* ast_constructor = nullptr;
if (var.NumInOperands() > 1) {
// SPIR-V initializers are always constants.
@ -1242,7 +1242,7 @@ const spvtools::opt::analysis::IntConstant* ParserImpl::GetArraySize(
ast::Variable* ParserImpl::MakeVariable(uint32_t id,
ast::StorageClass sc,
type::Type* type,
sem::Type* type,
bool is_const,
ast::Expression* constructor,
ast::DecorationList decorations) {
@ -1256,7 +1256,7 @@ ast::Variable* ParserImpl::MakeVariable(uint32_t id,
auto access = read_only_struct_types_.count(type)
? ast::AccessControl::kReadOnly
: ast::AccessControl::kReadWrite;
type = builder_.create<type::AccessControl>(access, type);
type = builder_.create<sem::AccessControl>(access, type);
}
for (auto& deco : GetDecorationsFor(id)) {
@ -1298,7 +1298,7 @@ ast::Variable* ParserImpl::MakeVariable(uint32_t id,
"SampleMask must be an array of 1 element.";
}
special_builtins_[id] = spv_builtin;
type = builder_.create<type::U32>();
type = builder_.create<sem::U32>();
break;
}
default:
@ -1382,25 +1382,25 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
// So canonicalization should map that way too.
// Currently "null<type>" is missing from the WGSL parser.
// See https://bugs.chromium.org/p/tint/issues/detail?id=34
if (ast_type->Is<type::U32>()) {
if (ast_type->Is<sem::U32>()) {
return {ast_type,
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::UintLiteral>(source, ast_type,
spirv_const->GetU32()))};
}
if (ast_type->Is<type::I32>()) {
if (ast_type->Is<sem::I32>()) {
return {ast_type,
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(source, ast_type,
spirv_const->GetS32()))};
}
if (ast_type->Is<type::F32>()) {
if (ast_type->Is<sem::F32>()) {
return {ast_type,
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(source, ast_type,
spirv_const->GetFloat()))};
}
if (ast_type->Is<type::Bool>()) {
if (ast_type->Is<sem::Bool>()) {
const bool value = spirv_const->AsNullConstant()
? false
: spirv_const->AsBoolConstant()->value();
@ -1444,7 +1444,7 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
return {};
}
ast::Expression* ParserImpl::MakeNullValue(type::Type* type) {
ast::Expression* ParserImpl::MakeNullValue(sem::Type* type) {
// TODO(dneto): Use the no-operands constructor syntax when it becomes
// available in Tint.
// https://github.com/gpuweb/gpuweb/issues/685
@ -1458,23 +1458,23 @@ ast::Expression* ParserImpl::MakeNullValue(type::Type* type) {
auto* original_type = type;
type = type->UnwrapIfNeeded();
if (type->Is<type::Bool>()) {
if (type->Is<sem::Bool>()) {
return create<ast::ScalarConstructorExpression>(
Source{}, create<ast::BoolLiteral>(Source{}, type, false));
}
if (type->Is<type::U32>()) {
if (type->Is<sem::U32>()) {
return create<ast::ScalarConstructorExpression>(
Source{}, create<ast::UintLiteral>(Source{}, type, 0u));
}
if (type->Is<type::I32>()) {
if (type->Is<sem::I32>()) {
return create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, type, 0));
}
if (type->Is<type::F32>()) {
if (type->Is<sem::F32>()) {
return create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, type, 0.0f));
}
if (const auto* vec_ty = type->As<type::Vector>()) {
if (const auto* vec_ty = type->As<sem::Vector>()) {
ast::ExpressionList ast_components;
for (size_t i = 0; i < vec_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(vec_ty->type()));
@ -1482,10 +1482,10 @@ ast::Expression* ParserImpl::MakeNullValue(type::Type* type) {
return create<ast::TypeConstructorExpression>(Source{}, type,
std::move(ast_components));
}
if (const auto* mat_ty = type->As<type::Matrix>()) {
if (const auto* mat_ty = type->As<sem::Matrix>()) {
// Matrix components are columns
auto* column_ty =
builder_.create<type::Vector>(mat_ty->type(), mat_ty->rows());
builder_.create<sem::Vector>(mat_ty->type(), mat_ty->rows());
ast::ExpressionList ast_components;
for (size_t i = 0; i < mat_ty->columns(); ++i) {
ast_components.emplace_back(MakeNullValue(column_ty));
@ -1493,7 +1493,7 @@ ast::Expression* ParserImpl::MakeNullValue(type::Type* type) {
return create<ast::TypeConstructorExpression>(Source{}, type,
std::move(ast_components));
}
if (auto* arr_ty = type->As<type::ArrayType>()) {
if (auto* arr_ty = type->As<sem::ArrayType>()) {
ast::ExpressionList ast_components;
for (size_t i = 0; i < arr_ty->size(); ++i) {
ast_components.emplace_back(MakeNullValue(arr_ty->type()));
@ -1501,7 +1501,7 @@ ast::Expression* ParserImpl::MakeNullValue(type::Type* type) {
return create<ast::TypeConstructorExpression>(Source{}, original_type,
std::move(ast_components));
}
if (auto* struct_ty = type->As<type::StructType>()) {
if (auto* struct_ty = type->As<sem::StructType>()) {
ast::ExpressionList ast_components;
for (auto* member : struct_ty->impl()->members()) {
ast_components.emplace_back(MakeNullValue(member->type()));
@ -1513,7 +1513,7 @@ ast::Expression* ParserImpl::MakeNullValue(type::Type* type) {
return nullptr;
}
TypedExpression ParserImpl::MakeNullExpression(type::Type* type) {
TypedExpression ParserImpl::MakeNullExpression(sem::Type* type) {
return {type, MakeNullValue(type)};
}
@ -1567,7 +1567,7 @@ TypedExpression ParserImpl::RectifyOperandSignedness(
TypedExpression ParserImpl::RectifySecondOperandSignedness(
const spvtools::opt::Instruction& inst,
type::Type* first_operand_type,
sem::Type* first_operand_type,
TypedExpression&& second_operand_expr) {
if ((first_operand_type != second_operand_expr.type) &&
AssumesSecondOperandSignednessMatchesFirstOperand(inst.opcode())) {
@ -1580,8 +1580,8 @@ TypedExpression ParserImpl::RectifySecondOperandSignedness(
return std::move(second_operand_expr);
}
type::Type* ParserImpl::ForcedResultType(const spvtools::opt::Instruction& inst,
type::Type* first_operand_type) {
sem::Type* ParserImpl::ForcedResultType(const spvtools::opt::Instruction& inst,
sem::Type* first_operand_type) {
const auto opcode = inst.opcode();
if (AssumesResultSignednessMatchesFirstOperand(opcode)) {
return first_operand_type;
@ -1596,36 +1596,34 @@ type::Type* ParserImpl::ForcedResultType(const spvtools::opt::Instruction& inst,
return nullptr;
}
type::Type* ParserImpl::GetSignedIntMatchingShape(type::Type* other) {
sem::Type* ParserImpl::GetSignedIntMatchingShape(sem::Type* other) {
if (other == nullptr) {
Fail() << "no type provided";
}
auto* i32 = builder_.create<type::I32>();
if (other->Is<type::F32>() || other->Is<type::U32>() ||
other->Is<type::I32>()) {
auto* i32 = builder_.create<sem::I32>();
if (other->Is<sem::F32>() || other->Is<sem::U32>() || other->Is<sem::I32>()) {
return i32;
}
auto* vec_ty = other->As<type::Vector>();
auto* vec_ty = other->As<sem::Vector>();
if (vec_ty) {
return builder_.create<type::Vector>(i32, vec_ty->size());
return builder_.create<sem::Vector>(i32, vec_ty->size());
}
Fail() << "required numeric scalar or vector, but got " << other->type_name();
return nullptr;
}
type::Type* ParserImpl::GetUnsignedIntMatchingShape(type::Type* other) {
sem::Type* ParserImpl::GetUnsignedIntMatchingShape(sem::Type* other) {
if (other == nullptr) {
Fail() << "no type provided";
return nullptr;
}
auto* u32 = builder_.create<type::U32>();
if (other->Is<type::F32>() || other->Is<type::U32>() ||
other->Is<type::I32>()) {
auto* u32 = builder_.create<sem::U32>();
if (other->Is<sem::F32>() || other->Is<sem::U32>() || other->Is<sem::I32>()) {
return u32;
}
auto* vec_ty = other->As<type::Vector>();
auto* vec_ty = other->As<sem::Vector>();
if (vec_ty) {
return builder_.create<type::Vector>(u32, vec_ty->size());
return builder_.create<sem::Vector>(u32, vec_ty->size());
}
Fail() << "required numeric scalar or vector, but got " << other->type_name();
return nullptr;
@ -1634,7 +1632,7 @@ type::Type* ParserImpl::GetUnsignedIntMatchingShape(type::Type* other) {
TypedExpression ParserImpl::RectifyForcedResultType(
TypedExpression expr,
const spvtools::opt::Instruction& inst,
type::Type* first_operand_type) {
sem::Type* first_operand_type) {
auto* forced_result_ty = ForcedResultType(inst, first_operand_type);
if ((forced_result_ty == nullptr) || (forced_result_ty == expr.type)) {
return expr;
@ -1813,7 +1811,7 @@ ParserImpl::GetSpirvTypeForHandleMemoryObjectDeclaration(
return raw_handle_type;
}
type::Pointer* ParserImpl::GetTypeForHandleVar(
sem::Pointer* ParserImpl::GetTypeForHandleVar(
const spvtools::opt::Instruction& var) {
auto where = handle_type_.find(&var);
if (where != handle_type_.end()) {
@ -1897,11 +1895,11 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
}
// Construct the Tint handle type.
type::Type* ast_store_type = nullptr;
sem::Type* ast_store_type = nullptr;
if (usage.IsSampler()) {
ast_store_type = builder_.create<type::Sampler>(
usage.IsComparisonSampler() ? type::SamplerKind::kComparisonSampler
: type::SamplerKind::kSampler);
ast_store_type = builder_.create<sem::Sampler>(
usage.IsComparisonSampler() ? sem::SamplerKind::kComparisonSampler
: sem::SamplerKind::kSampler);
} else if (usage.IsTexture()) {
const spvtools::opt::analysis::Image* image_type =
type_mgr_->GetType(raw_handle_type->result_id())->AsImage();
@ -1911,9 +1909,9 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
return nullptr;
}
const type::TextureDimension dim =
const sem::TextureDimension dim =
enum_converter_.ToDim(image_type->dim(), image_type->is_arrayed());
if (dim == type::TextureDimension::kNone) {
if (dim == sem::TextureDimension::kNone) {
return nullptr;
}
@ -1930,13 +1928,13 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
// OpImage variable with an OpImage*Dref* instruction. In WGSL we must
// treat that as a depth texture.
if (image_type->depth() || usage.IsDepthTexture()) {
ast_store_type = builder_.create<type::DepthTexture>(dim);
ast_store_type = builder_.create<sem::DepthTexture>(dim);
} else if (image_type->is_multisampled()) {
// Multisampled textures are never depth textures.
ast_store_type = builder_.create<type::MultisampledTexture>(
ast_store_type = builder_.create<sem::MultisampledTexture>(
dim, ast_sampled_component_type);
} else {
ast_store_type = builder_.create<type::SampledTexture>(
ast_store_type = builder_.create<sem::SampledTexture>(
dim, ast_sampled_component_type);
}
} else {
@ -1944,13 +1942,12 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
? ast::AccessControl::kReadOnly
: ast::AccessControl::kWriteOnly;
const auto format = enum_converter_.ToImageFormat(image_type->format());
if (format == type::ImageFormat::kNone) {
if (format == sem::ImageFormat::kNone) {
return nullptr;
}
auto* subtype =
type::StorageTexture::SubtypeFor(format, builder_.Types());
ast_store_type = builder_.create<type::AccessControl>(
access, builder_.create<type::StorageTexture>(dim, format, subtype));
auto* subtype = sem::StorageTexture::SubtypeFor(format, builder_.Types());
ast_store_type = builder_.create<sem::AccessControl>(
access, builder_.create<sem::StorageTexture>(dim, format, subtype));
}
} else {
Fail() << "unsupported: UniformConstant variable is not a recognized "
@ -1960,55 +1957,55 @@ type::Pointer* ParserImpl::GetTypeForHandleVar(
}
// Form the pointer type.
auto* result = builder_.create<type::Pointer>(
auto* result = builder_.create<sem::Pointer>(
ast_store_type, ast::StorageClass::kUniformConstant);
// Remember it for later.
handle_type_[&var] = result;
return result;
}
type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) {
sem::Type* ParserImpl::GetComponentTypeForFormat(sem::ImageFormat format) {
switch (format) {
case type::ImageFormat::kR8Uint:
case type::ImageFormat::kR16Uint:
case type::ImageFormat::kRg8Uint:
case type::ImageFormat::kR32Uint:
case type::ImageFormat::kRg16Uint:
case type::ImageFormat::kRgba8Uint:
case type::ImageFormat::kRg32Uint:
case type::ImageFormat::kRgba16Uint:
case type::ImageFormat::kRgba32Uint:
return builder_.create<type::U32>();
case sem::ImageFormat::kR8Uint:
case sem::ImageFormat::kR16Uint:
case sem::ImageFormat::kRg8Uint:
case sem::ImageFormat::kR32Uint:
case sem::ImageFormat::kRg16Uint:
case sem::ImageFormat::kRgba8Uint:
case sem::ImageFormat::kRg32Uint:
case sem::ImageFormat::kRgba16Uint:
case sem::ImageFormat::kRgba32Uint:
return builder_.create<sem::U32>();
case type::ImageFormat::kR8Sint:
case type::ImageFormat::kR16Sint:
case type::ImageFormat::kRg8Sint:
case type::ImageFormat::kR32Sint:
case type::ImageFormat::kRg16Sint:
case type::ImageFormat::kRgba8Sint:
case type::ImageFormat::kRg32Sint:
case type::ImageFormat::kRgba16Sint:
case type::ImageFormat::kRgba32Sint:
return builder_.create<type::I32>();
case sem::ImageFormat::kR8Sint:
case sem::ImageFormat::kR16Sint:
case sem::ImageFormat::kRg8Sint:
case sem::ImageFormat::kR32Sint:
case sem::ImageFormat::kRg16Sint:
case sem::ImageFormat::kRgba8Sint:
case sem::ImageFormat::kRg32Sint:
case sem::ImageFormat::kRgba16Sint:
case sem::ImageFormat::kRgba32Sint:
return builder_.create<sem::I32>();
case type::ImageFormat::kR8Unorm:
case type::ImageFormat::kRg8Unorm:
case type::ImageFormat::kRgba8Unorm:
case type::ImageFormat::kRgba8UnormSrgb:
case type::ImageFormat::kBgra8Unorm:
case type::ImageFormat::kBgra8UnormSrgb:
case type::ImageFormat::kRgb10A2Unorm:
case type::ImageFormat::kR8Snorm:
case type::ImageFormat::kRg8Snorm:
case type::ImageFormat::kRgba8Snorm:
case type::ImageFormat::kR16Float:
case type::ImageFormat::kR32Float:
case type::ImageFormat::kRg16Float:
case type::ImageFormat::kRg11B10Float:
case type::ImageFormat::kRg32Float:
case type::ImageFormat::kRgba16Float:
case type::ImageFormat::kRgba32Float:
return builder_.create<type::F32>();
case sem::ImageFormat::kR8Unorm:
case sem::ImageFormat::kRg8Unorm:
case sem::ImageFormat::kRgba8Unorm:
case sem::ImageFormat::kRgba8UnormSrgb:
case sem::ImageFormat::kBgra8Unorm:
case sem::ImageFormat::kBgra8UnormSrgb:
case sem::ImageFormat::kRgb10A2Unorm:
case sem::ImageFormat::kR8Snorm:
case sem::ImageFormat::kRg8Snorm:
case sem::ImageFormat::kRgba8Snorm:
case sem::ImageFormat::kR16Float:
case sem::ImageFormat::kR32Float:
case sem::ImageFormat::kRg16Float:
case sem::ImageFormat::kRg11B10Float:
case sem::ImageFormat::kRg32Float:
case sem::ImageFormat::kRgba16Float:
case sem::ImageFormat::kRgba32Float:
return builder_.create<sem::F32>();
default:
break;
}
@ -2016,56 +2013,56 @@ type::Type* ParserImpl::GetComponentTypeForFormat(type::ImageFormat format) {
return nullptr;
}
type::Type* ParserImpl::GetTexelTypeForFormat(type::ImageFormat format) {
sem::Type* ParserImpl::GetTexelTypeForFormat(sem::ImageFormat format) {
auto* component_type = GetComponentTypeForFormat(format);
if (!component_type) {
return nullptr;
}
switch (format) {
case type::ImageFormat::kR16Float:
case type::ImageFormat::kR16Sint:
case type::ImageFormat::kR16Uint:
case type::ImageFormat::kR32Float:
case type::ImageFormat::kR32Sint:
case type::ImageFormat::kR32Uint:
case type::ImageFormat::kR8Sint:
case type::ImageFormat::kR8Snorm:
case type::ImageFormat::kR8Uint:
case type::ImageFormat::kR8Unorm:
case sem::ImageFormat::kR16Float:
case sem::ImageFormat::kR16Sint:
case sem::ImageFormat::kR16Uint:
case sem::ImageFormat::kR32Float:
case sem::ImageFormat::kR32Sint:
case sem::ImageFormat::kR32Uint:
case sem::ImageFormat::kR8Sint:
case sem::ImageFormat::kR8Snorm:
case sem::ImageFormat::kR8Uint:
case sem::ImageFormat::kR8Unorm:
// One channel
return component_type;
case type::ImageFormat::kRg11B10Float:
case type::ImageFormat::kRg16Float:
case type::ImageFormat::kRg16Sint:
case type::ImageFormat::kRg16Uint:
case type::ImageFormat::kRg32Float:
case type::ImageFormat::kRg32Sint:
case type::ImageFormat::kRg32Uint:
case type::ImageFormat::kRg8Sint:
case type::ImageFormat::kRg8Snorm:
case type::ImageFormat::kRg8Uint:
case type::ImageFormat::kRg8Unorm:
case sem::ImageFormat::kRg11B10Float:
case sem::ImageFormat::kRg16Float:
case sem::ImageFormat::kRg16Sint:
case sem::ImageFormat::kRg16Uint:
case sem::ImageFormat::kRg32Float:
case sem::ImageFormat::kRg32Sint:
case sem::ImageFormat::kRg32Uint:
case sem::ImageFormat::kRg8Sint:
case sem::ImageFormat::kRg8Snorm:
case sem::ImageFormat::kRg8Uint:
case sem::ImageFormat::kRg8Unorm:
// Two channels
return builder_.create<type::Vector>(component_type, 2);
return builder_.create<sem::Vector>(component_type, 2);
case type::ImageFormat::kBgra8Unorm:
case type::ImageFormat::kBgra8UnormSrgb:
case type::ImageFormat::kRgb10A2Unorm:
case type::ImageFormat::kRgba16Float:
case type::ImageFormat::kRgba16Sint:
case type::ImageFormat::kRgba16Uint:
case type::ImageFormat::kRgba32Float:
case type::ImageFormat::kRgba32Sint:
case type::ImageFormat::kRgba32Uint:
case type::ImageFormat::kRgba8Sint:
case type::ImageFormat::kRgba8Snorm:
case type::ImageFormat::kRgba8Uint:
case type::ImageFormat::kRgba8Unorm:
case type::ImageFormat::kRgba8UnormSrgb:
case sem::ImageFormat::kBgra8Unorm:
case sem::ImageFormat::kBgra8UnormSrgb:
case sem::ImageFormat::kRgb10A2Unorm:
case sem::ImageFormat::kRgba16Float:
case sem::ImageFormat::kRgba16Sint:
case sem::ImageFormat::kRgba16Uint:
case sem::ImageFormat::kRgba32Float:
case sem::ImageFormat::kRgba32Sint:
case sem::ImageFormat::kRgba32Uint:
case sem::ImageFormat::kRgba8Sint:
case sem::ImageFormat::kRgba8Snorm:
case sem::ImageFormat::kRgba8Uint:
case sem::ImageFormat::kRgba8Unorm:
case sem::ImageFormat::kRgba8UnormSrgb:
// Four channels
return builder_.create<type::Vector>(component_type, 4);
return builder_.create<sem::Vector>(component_type, 4);
default:
break;

View File

@ -61,7 +61,7 @@ using DecorationList = std::vector<Decoration>;
/// An AST expression with its type.
struct TypedExpression {
/// The type
type::Type* type = nullptr;
sem::Type* type = nullptr;
/// The expression
ast::Expression* expr = nullptr;
};
@ -132,7 +132,7 @@ class ParserImpl : Reader {
/// after the internal representation of the module has been built.
/// @param type_id the SPIR-V ID of a type.
/// @returns a Tint type, or nullptr
type::Type* ConvertType(uint32_t type_id);
sem::Type* ConvertType(uint32_t type_id);
/// Emits an alias type declaration for the given type, if necessary, and
/// also updates the mapping of the SPIR-V type ID to the alias type.
@ -294,7 +294,7 @@ class ParserImpl : Reader {
/// in the error case
ast::Variable* MakeVariable(uint32_t id,
ast::StorageClass sc,
type::Type* type,
sem::Type* type,
bool is_const,
ast::Expression* constructor,
ast::DecorationList decorations);
@ -307,12 +307,12 @@ class ParserImpl : Reader {
/// Creates an AST expression node for the null value for the given type.
/// @param type the AST type
/// @returns a new expression
ast::Expression* MakeNullValue(type::Type* type);
ast::Expression* MakeNullValue(sem::Type* type);
/// Make a typed expression for the null value for the given type.
/// @param type the AST type
/// @returns a new typed expression
TypedExpression MakeNullExpression(type::Type* type);
TypedExpression MakeNullExpression(sem::Type* type);
/// Converts a given expression to the signedness demanded for an operand
/// of the given SPIR-V instruction, if required. If the instruction assumes
@ -337,7 +337,7 @@ class ParserImpl : Reader {
/// @returns second_operand_expr, or a cast of it
TypedExpression RectifySecondOperandSignedness(
const spvtools::opt::Instruction& inst,
type::Type* first_operand_type,
sem::Type* first_operand_type,
TypedExpression&& second_operand_expr);
/// Returns the "forced" result type for the given SPIR-V instruction.
@ -348,8 +348,8 @@ class ParserImpl : Reader {
/// @param inst the SPIR-V instruction
/// @param first_operand_type the AST type for the first operand.
/// @returns the forced AST result type, or nullptr if no forcing is required.
type::Type* ForcedResultType(const spvtools::opt::Instruction& inst,
type::Type* first_operand_type);
sem::Type* ForcedResultType(const spvtools::opt::Instruction& inst,
sem::Type* first_operand_type);
/// Returns a signed integer scalar or vector type matching the shape (scalar,
/// vector, and component bit width) of another type, which itself is a
@ -357,7 +357,7 @@ class ParserImpl : Reader {
/// requirement.
/// @param other the type whose shape must be matched
/// @returns the signed scalar or vector type
type::Type* GetSignedIntMatchingShape(type::Type* other);
sem::Type* GetSignedIntMatchingShape(sem::Type* other);
/// Returns a signed integer scalar or vector type matching the shape (scalar,
/// vector, and component bit width) of another type, which itself is a
@ -365,7 +365,7 @@ class ParserImpl : Reader {
/// requirement.
/// @param other the type whose shape must be matched
/// @returns the unsigned scalar or vector type
type::Type* GetUnsignedIntMatchingShape(type::Type* other);
sem::Type* GetUnsignedIntMatchingShape(sem::Type* other);
/// Wraps the given expression in an as-cast to the given expression's type,
/// when the underlying operation produces a forced result type different
@ -378,10 +378,10 @@ class ParserImpl : Reader {
TypedExpression RectifyForcedResultType(
TypedExpression expr,
const spvtools::opt::Instruction& inst,
type::Type* first_operand_type);
sem::Type* first_operand_type);
/// @returns the registered boolean type.
type::Type* Bool() const { return bool_type_; }
sem::Type* Bool() const { return bool_type_; }
/// Bookkeeping used for tracking the "position" builtin variable.
struct BuiltInPositionInfo {
@ -469,18 +469,18 @@ class ParserImpl : Reader {
/// @param var the OpVariable instruction
/// @returns the Tint AST type for the poiner-to-{sampler|texture} or null on
/// error
type::Pointer* GetTypeForHandleVar(const spvtools::opt::Instruction& var);
sem::Pointer* GetTypeForHandleVar(const spvtools::opt::Instruction& var);
/// Returns the channel component type corresponding to the given image
/// format.
/// @param format image texel format
/// @returns the component type, one of f32, i32, u32
type::Type* GetComponentTypeForFormat(type::ImageFormat format);
sem::Type* GetComponentTypeForFormat(sem::ImageFormat format);
/// Returns texel type corresponding to the given image format.
/// @param format image texel format
/// @returns the texel format
type::Type* GetTexelTypeForFormat(type::ImageFormat format);
sem::Type* GetTexelTypeForFormat(sem::ImageFormat format);
/// Returns the SPIR-V instruction with the given ID, or nullptr.
/// @param id the SPIR-V result ID
@ -509,20 +509,19 @@ class ParserImpl : Reader {
private:
/// Converts a specific SPIR-V type to a Tint type. Integer case
type::Type* ConvertType(const spvtools::opt::analysis::Integer* int_ty);
sem::Type* ConvertType(const spvtools::opt::analysis::Integer* int_ty);
/// Converts a specific SPIR-V type to a Tint type. Float case
type::Type* ConvertType(const spvtools::opt::analysis::Float* float_ty);
sem::Type* ConvertType(const spvtools::opt::analysis::Float* float_ty);
/// Converts a specific SPIR-V type to a Tint type. Vector case
type::Type* ConvertType(const spvtools::opt::analysis::Vector* vec_ty);
sem::Type* ConvertType(const spvtools::opt::analysis::Vector* vec_ty);
/// Converts a specific SPIR-V type to a Tint type. Matrix case
type::Type* ConvertType(const spvtools::opt::analysis::Matrix* mat_ty);
sem::Type* ConvertType(const spvtools::opt::analysis::Matrix* mat_ty);
/// Converts a specific SPIR-V type to a Tint type. RuntimeArray case
/// @param rtarr_ty the Tint type
type::Type* ConvertType(
const spvtools::opt::analysis::RuntimeArray* rtarr_ty);
sem::Type* ConvertType(const spvtools::opt::analysis::RuntimeArray* rtarr_ty);
/// Converts a specific SPIR-V type to a Tint type. Array case
/// @param arr_ty the Tint type
type::Type* ConvertType(const spvtools::opt::analysis::Array* arr_ty);
sem::Type* ConvertType(const spvtools::opt::analysis::Array* arr_ty);
/// Converts a specific SPIR-V type to a Tint type. Struct case.
/// SPIR-V allows distinct struct type definitions for two OpTypeStruct
/// that otherwise have the same set of members (and struct and member
@ -534,15 +533,15 @@ class ParserImpl : Reader {
/// not significant to the optimizer's module representation.
/// @param type_id the SPIR-V ID for the type.
/// @param struct_ty the Tint type
type::Type* ConvertType(uint32_t type_id,
const spvtools::opt::analysis::Struct* struct_ty);
sem::Type* ConvertType(uint32_t type_id,
const spvtools::opt::analysis::Struct* struct_ty);
/// Converts a specific SPIR-V type to a Tint type. Pointer case
/// The pointer to gl_PerVertex maps to nullptr, and instead is recorded
/// in member #builtin_position_.
/// @param type_id the SPIR-V ID for the type.
/// @param ptr_ty the Tint type
type::Type* ConvertType(uint32_t type_id,
const spvtools::opt::analysis::Pointer* ptr_ty);
sem::Type* ConvertType(uint32_t type_id,
const spvtools::opt::analysis::Pointer* ptr_ty);
/// Parses the array or runtime-array decorations.
/// @param spv_type the SPIR-V array or runtime-array type.
@ -573,7 +572,7 @@ class ParserImpl : Reader {
spvtools::MessageConsumer message_consumer_;
// The registered boolean type.
type::Type* bool_type_;
sem::Type* bool_type_;
// An object used to store and generate names for SPIR-V objects.
Namer namer_;
@ -609,12 +608,12 @@ class ParserImpl : Reader {
std::unordered_set<uint32_t> ignored_imports_;
// Maps a SPIR-V type ID to the corresponding Tint type.
std::unordered_map<uint32_t, type::Type*> id_to_type_;
std::unordered_map<uint32_t, sem::Type*> id_to_type_;
// Maps an unsigned type corresponding to the given signed type.
std::unordered_map<type::Type*, type::Type*> signed_type_for_;
std::unordered_map<sem::Type*, sem::Type*> signed_type_for_;
// Maps an signed type corresponding to the given unsigned type.
std::unordered_map<type::Type*, type::Type*> unsigned_type_for_;
std::unordered_map<sem::Type*, sem::Type*> unsigned_type_for_;
// Bookkeeping for the gl_Position builtin.
// In Vulkan SPIR-V, it's the 0 member of the gl_PerVertex structure.
@ -634,7 +633,7 @@ class ParserImpl : Reader {
std::unordered_set<uint32_t> remap_buffer_block_type_;
// The struct types with only read-only members.
std::unordered_set<type::Type*> read_only_struct_types_;
std::unordered_set<sem::Type*> read_only_struct_types_;
// The IDs of scalar spec constants
std::unordered_set<uint32_t> scalar_spec_constants_;
@ -659,7 +658,7 @@ class ParserImpl : Reader {
// usages implied by usages of the memory-object-declaration.
std::unordered_map<const spvtools::opt::Instruction*, Usage> handle_usage_;
// The inferred pointer type for the given handle variable.
std::unordered_map<const spvtools::opt::Instruction*, type::Pointer*>
std::unordered_map<const spvtools::opt::Instruction*, sem::Pointer*>
handle_type_;
/// Maps the SPIR-V ID of a module-scope builtin variable that should be

View File

@ -75,7 +75,7 @@ TEST_F(SpvParserTest, ConvertType_Void) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1);
EXPECT_TRUE(type->Is<type::Void>());
EXPECT_TRUE(type->Is<sem::Void>());
EXPECT_TRUE(p->error().empty());
}
@ -84,7 +84,7 @@ TEST_F(SpvParserTest, ConvertType_Bool) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(100);
EXPECT_TRUE(type->Is<type::Bool>());
EXPECT_TRUE(type->Is<sem::Bool>());
EXPECT_TRUE(p->error().empty());
}
@ -93,7 +93,7 @@ TEST_F(SpvParserTest, ConvertType_I32) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(2);
EXPECT_TRUE(type->Is<type::I32>());
EXPECT_TRUE(type->Is<sem::I32>());
EXPECT_TRUE(p->error().empty());
}
@ -102,7 +102,7 @@ TEST_F(SpvParserTest, ConvertType_U32) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::U32>());
EXPECT_TRUE(type->Is<sem::U32>());
EXPECT_TRUE(p->error().empty());
}
@ -111,7 +111,7 @@ TEST_F(SpvParserTest, ConvertType_F32) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(4);
EXPECT_TRUE(type->Is<type::F32>());
EXPECT_TRUE(type->Is<sem::F32>());
EXPECT_TRUE(p->error().empty());
}
@ -155,19 +155,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverF32) {
EXPECT_TRUE(p->BuildInternalModule());
auto* v2xf32 = p->ConvertType(20);
EXPECT_TRUE(v2xf32->Is<type::Vector>());
EXPECT_TRUE(v2xf32->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(v2xf32->As<type::Vector>()->size(), 2u);
EXPECT_TRUE(v2xf32->Is<sem::Vector>());
EXPECT_TRUE(v2xf32->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(v2xf32->As<sem::Vector>()->size(), 2u);
auto* v3xf32 = p->ConvertType(30);
EXPECT_TRUE(v3xf32->Is<type::Vector>());
EXPECT_TRUE(v3xf32->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(v3xf32->As<type::Vector>()->size(), 3u);
EXPECT_TRUE(v3xf32->Is<sem::Vector>());
EXPECT_TRUE(v3xf32->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(v3xf32->As<sem::Vector>()->size(), 3u);
auto* v4xf32 = p->ConvertType(40);
EXPECT_TRUE(v4xf32->Is<type::Vector>());
EXPECT_TRUE(v4xf32->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(v4xf32->As<type::Vector>()->size(), 4u);
EXPECT_TRUE(v4xf32->Is<sem::Vector>());
EXPECT_TRUE(v4xf32->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(v4xf32->As<sem::Vector>()->size(), 4u);
EXPECT_TRUE(p->error().empty());
}
@ -182,19 +182,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverI32) {
EXPECT_TRUE(p->BuildInternalModule());
auto* v2xi32 = p->ConvertType(20);
EXPECT_TRUE(v2xi32->Is<type::Vector>());
EXPECT_TRUE(v2xi32->As<type::Vector>()->type()->Is<type::I32>());
EXPECT_EQ(v2xi32->As<type::Vector>()->size(), 2u);
EXPECT_TRUE(v2xi32->Is<sem::Vector>());
EXPECT_TRUE(v2xi32->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(v2xi32->As<sem::Vector>()->size(), 2u);
auto* v3xi32 = p->ConvertType(30);
EXPECT_TRUE(v3xi32->Is<type::Vector>());
EXPECT_TRUE(v3xi32->As<type::Vector>()->type()->Is<type::I32>());
EXPECT_EQ(v3xi32->As<type::Vector>()->size(), 3u);
EXPECT_TRUE(v3xi32->Is<sem::Vector>());
EXPECT_TRUE(v3xi32->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(v3xi32->As<sem::Vector>()->size(), 3u);
auto* v4xi32 = p->ConvertType(40);
EXPECT_TRUE(v4xi32->Is<type::Vector>());
EXPECT_TRUE(v4xi32->As<type::Vector>()->type()->Is<type::I32>());
EXPECT_EQ(v4xi32->As<type::Vector>()->size(), 4u);
EXPECT_TRUE(v4xi32->Is<sem::Vector>());
EXPECT_TRUE(v4xi32->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(v4xi32->As<sem::Vector>()->size(), 4u);
EXPECT_TRUE(p->error().empty());
}
@ -209,19 +209,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverU32) {
EXPECT_TRUE(p->BuildInternalModule());
auto* v2xu32 = p->ConvertType(20);
EXPECT_TRUE(v2xu32->Is<type::Vector>());
EXPECT_TRUE(v2xu32->As<type::Vector>()->type()->Is<type::U32>());
EXPECT_EQ(v2xu32->As<type::Vector>()->size(), 2u);
EXPECT_TRUE(v2xu32->Is<sem::Vector>());
EXPECT_TRUE(v2xu32->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(v2xu32->As<sem::Vector>()->size(), 2u);
auto* v3xu32 = p->ConvertType(30);
EXPECT_TRUE(v3xu32->Is<type::Vector>());
EXPECT_TRUE(v3xu32->As<type::Vector>()->type()->Is<type::U32>());
EXPECT_EQ(v3xu32->As<type::Vector>()->size(), 3u);
EXPECT_TRUE(v3xu32->Is<sem::Vector>());
EXPECT_TRUE(v3xu32->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(v3xu32->As<sem::Vector>()->size(), 3u);
auto* v4xu32 = p->ConvertType(40);
EXPECT_TRUE(v4xu32->Is<type::Vector>());
EXPECT_TRUE(v4xu32->As<type::Vector>()->type()->Is<type::U32>());
EXPECT_EQ(v4xu32->As<type::Vector>()->size(), 4u);
EXPECT_TRUE(v4xu32->Is<sem::Vector>());
EXPECT_TRUE(v4xu32->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(v4xu32->As<sem::Vector>()->size(), 4u);
EXPECT_TRUE(p->error().empty());
}
@ -261,58 +261,58 @@ TEST_F(SpvParserTest, ConvertType_MatrixOverF32) {
EXPECT_TRUE(p->BuildInternalModule());
auto* m22 = p->ConvertType(22);
EXPECT_TRUE(m22->Is<type::Matrix>());
EXPECT_TRUE(m22->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m22->As<type::Matrix>()->rows(), 2u);
EXPECT_EQ(m22->As<type::Matrix>()->columns(), 2u);
EXPECT_TRUE(m22->Is<sem::Matrix>());
EXPECT_TRUE(m22->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m22->As<sem::Matrix>()->rows(), 2u);
EXPECT_EQ(m22->As<sem::Matrix>()->columns(), 2u);
auto* m23 = p->ConvertType(23);
EXPECT_TRUE(m23->Is<type::Matrix>());
EXPECT_TRUE(m23->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m23->As<type::Matrix>()->rows(), 2u);
EXPECT_EQ(m23->As<type::Matrix>()->columns(), 3u);
EXPECT_TRUE(m23->Is<sem::Matrix>());
EXPECT_TRUE(m23->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m23->As<sem::Matrix>()->rows(), 2u);
EXPECT_EQ(m23->As<sem::Matrix>()->columns(), 3u);
auto* m24 = p->ConvertType(24);
EXPECT_TRUE(m24->Is<type::Matrix>());
EXPECT_TRUE(m24->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m24->As<type::Matrix>()->rows(), 2u);
EXPECT_EQ(m24->As<type::Matrix>()->columns(), 4u);
EXPECT_TRUE(m24->Is<sem::Matrix>());
EXPECT_TRUE(m24->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m24->As<sem::Matrix>()->rows(), 2u);
EXPECT_EQ(m24->As<sem::Matrix>()->columns(), 4u);
auto* m32 = p->ConvertType(32);
EXPECT_TRUE(m32->Is<type::Matrix>());
EXPECT_TRUE(m32->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m32->As<type::Matrix>()->rows(), 3u);
EXPECT_EQ(m32->As<type::Matrix>()->columns(), 2u);
EXPECT_TRUE(m32->Is<sem::Matrix>());
EXPECT_TRUE(m32->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m32->As<sem::Matrix>()->rows(), 3u);
EXPECT_EQ(m32->As<sem::Matrix>()->columns(), 2u);
auto* m33 = p->ConvertType(33);
EXPECT_TRUE(m33->Is<type::Matrix>());
EXPECT_TRUE(m33->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m33->As<type::Matrix>()->rows(), 3u);
EXPECT_EQ(m33->As<type::Matrix>()->columns(), 3u);
EXPECT_TRUE(m33->Is<sem::Matrix>());
EXPECT_TRUE(m33->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m33->As<sem::Matrix>()->rows(), 3u);
EXPECT_EQ(m33->As<sem::Matrix>()->columns(), 3u);
auto* m34 = p->ConvertType(34);
EXPECT_TRUE(m34->Is<type::Matrix>());
EXPECT_TRUE(m34->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m34->As<type::Matrix>()->rows(), 3u);
EXPECT_EQ(m34->As<type::Matrix>()->columns(), 4u);
EXPECT_TRUE(m34->Is<sem::Matrix>());
EXPECT_TRUE(m34->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m34->As<sem::Matrix>()->rows(), 3u);
EXPECT_EQ(m34->As<sem::Matrix>()->columns(), 4u);
auto* m42 = p->ConvertType(42);
EXPECT_TRUE(m42->Is<type::Matrix>());
EXPECT_TRUE(m42->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m42->As<type::Matrix>()->rows(), 4u);
EXPECT_EQ(m42->As<type::Matrix>()->columns(), 2u);
EXPECT_TRUE(m42->Is<sem::Matrix>());
EXPECT_TRUE(m42->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m42->As<sem::Matrix>()->rows(), 4u);
EXPECT_EQ(m42->As<sem::Matrix>()->columns(), 2u);
auto* m43 = p->ConvertType(43);
EXPECT_TRUE(m43->Is<type::Matrix>());
EXPECT_TRUE(m43->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m43->As<type::Matrix>()->rows(), 4u);
EXPECT_EQ(m43->As<type::Matrix>()->columns(), 3u);
EXPECT_TRUE(m43->Is<sem::Matrix>());
EXPECT_TRUE(m43->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m43->As<sem::Matrix>()->rows(), 4u);
EXPECT_EQ(m43->As<sem::Matrix>()->columns(), 3u);
auto* m44 = p->ConvertType(44);
EXPECT_TRUE(m44->Is<type::Matrix>());
EXPECT_TRUE(m44->As<type::Matrix>()->type()->Is<type::F32>());
EXPECT_EQ(m44->As<type::Matrix>()->rows(), 4u);
EXPECT_EQ(m44->As<type::Matrix>()->columns(), 4u);
EXPECT_TRUE(m44->Is<sem::Matrix>());
EXPECT_TRUE(m44->As<sem::Matrix>()->type()->Is<sem::F32>());
EXPECT_EQ(m44->As<sem::Matrix>()->rows(), 4u);
EXPECT_EQ(m44->As<sem::Matrix>()->columns(), 4u);
EXPECT_TRUE(p->error().empty());
}
@ -326,15 +326,15 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::ArrayType>());
auto* arr_type = type->As<type::ArrayType>();
EXPECT_TRUE(type->Is<sem::ArrayType>());
auto* arr_type = type->As<sem::ArrayType>();
EXPECT_TRUE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr);
EXPECT_EQ(arr_type->size(), 0u);
EXPECT_EQ(arr_type->decorations().size(), 0u);
auto* elem_type = arr_type->type();
ASSERT_NE(elem_type, nullptr);
EXPECT_TRUE(elem_type->Is<type::U32>());
EXPECT_TRUE(elem_type->Is<sem::U32>());
EXPECT_TRUE(p->error().empty());
}
@ -361,7 +361,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray_ArrayStride_Valid) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
auto* arr_type = type->As<type::ArrayType>();
auto* arr_type = type->As<sem::ArrayType>();
EXPECT_TRUE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr);
ASSERT_EQ(arr_type->decorations().size(), 1u);
@ -409,15 +409,15 @@ TEST_F(SpvParserTest, ConvertType_Array) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::ArrayType>());
auto* arr_type = type->As<type::ArrayType>();
EXPECT_TRUE(type->Is<sem::ArrayType>());
auto* arr_type = type->As<sem::ArrayType>();
EXPECT_FALSE(arr_type->IsRuntimeArray());
ASSERT_NE(arr_type, nullptr);
EXPECT_EQ(arr_type->size(), 42u);
EXPECT_EQ(arr_type->decorations().size(), 0u);
auto* elem_type = arr_type->type();
ASSERT_NE(elem_type, nullptr);
EXPECT_TRUE(elem_type->Is<type::U32>());
EXPECT_TRUE(elem_type->Is<sem::U32>());
EXPECT_TRUE(p->error().empty());
}
@ -496,8 +496,8 @@ TEST_F(SpvParserTest, ConvertType_ArrayStride_Valid) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::ArrayType>());
auto* arr_type = type->As<type::ArrayType>();
EXPECT_TRUE(type->Is<sem::ArrayType>());
auto* arr_type = type->As<sem::ArrayType>();
ASSERT_NE(arr_type, nullptr);
ASSERT_EQ(arr_type->decorations().size(), 1u);
@ -550,10 +550,10 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::StructType>());
EXPECT_TRUE(type->Is<sem::StructType>());
Program program = p->program();
EXPECT_THAT(program.str(type->As<type::StructType>()->impl()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct{
StructMember{field0: __u32}
StructMember{field1: __f32}
}
@ -571,10 +571,10 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::StructType>());
EXPECT_TRUE(type->Is<sem::StructType>());
Program program = p->program();
EXPECT_THAT(program.str(type->As<type::StructType>()->impl()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct{
[[block]]
StructMember{field0: __u32}
}
@ -596,10 +596,10 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
auto* type = p->ConvertType(10);
ASSERT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::StructType>());
EXPECT_TRUE(type->Is<sem::StructType>());
Program program = p->program();
EXPECT_THAT(program.str(type->As<type::StructType>()->impl()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct{
StructMember{[[ offset 0 ]] field0: __f32}
StructMember{[[ offset 8 ]] field1: __vec_2__f32}
StructMember{[[ offset 16 ]] field2: __mat_2_2__f32}
@ -645,10 +645,10 @@ TEST_F(SpvParserTest, ConvertType_PointerInput) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput);
EXPECT_TRUE(p->error().empty());
}
@ -661,10 +661,10 @@ TEST_F(SpvParserTest, ConvertType_PointerOutput) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kOutput);
EXPECT_TRUE(p->error().empty());
}
@ -677,10 +677,10 @@ TEST_F(SpvParserTest, ConvertType_PointerUniform) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniform);
EXPECT_TRUE(p->error().empty());
}
@ -693,10 +693,10 @@ TEST_F(SpvParserTest, ConvertType_PointerWorkgroup) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kWorkgroup);
EXPECT_TRUE(p->error().empty());
}
@ -709,10 +709,10 @@ TEST_F(SpvParserTest, ConvertType_PointerUniformConstant) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniformConstant);
EXPECT_TRUE(p->error().empty());
}
@ -725,10 +725,10 @@ TEST_F(SpvParserTest, ConvertType_PointerStorageBuffer) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kStorage);
EXPECT_TRUE(p->error().empty());
}
@ -741,10 +741,10 @@ TEST_F(SpvParserTest, ConvertType_PointerImage) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kImage);
EXPECT_TRUE(p->error().empty());
}
@ -757,10 +757,10 @@ TEST_F(SpvParserTest, ConvertType_PointerPrivate) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kPrivate);
EXPECT_TRUE(p->error().empty());
}
@ -773,10 +773,10 @@ TEST_F(SpvParserTest, ConvertType_PointerFunction) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(3);
EXPECT_TRUE(type->Is<type::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_TRUE(ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::F32>());
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kFunction);
EXPECT_TRUE(p->error().empty());
}
@ -792,17 +792,17 @@ TEST_F(SpvParserTest, ConvertType_PointerToPointer) {
auto* type = p->ConvertType(3);
EXPECT_NE(type, nullptr);
EXPECT_TRUE(type->Is<type::Pointer>());
EXPECT_TRUE(type->Is<sem::Pointer>());
auto* ptr_ty = type->As<type::Pointer>();
auto* ptr_ty = type->As<sem::Pointer>();
EXPECT_NE(ptr_ty, nullptr);
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput);
EXPECT_TRUE(ptr_ty->type()->Is<type::Pointer>());
EXPECT_TRUE(ptr_ty->type()->Is<sem::Pointer>());
auto* ptr_ptr_ty = ptr_ty->type()->As<type::Pointer>();
auto* ptr_ptr_ty = ptr_ty->type()->As<sem::Pointer>();
EXPECT_NE(ptr_ptr_ty, nullptr);
EXPECT_EQ(ptr_ptr_ty->storage_class(), ast::StorageClass::kOutput);
EXPECT_TRUE(ptr_ptr_ty->type()->Is<type::F32>());
EXPECT_TRUE(ptr_ptr_ty->type()->Is<sem::F32>());
EXPECT_TRUE(p->error().empty());
}
@ -815,7 +815,7 @@ TEST_F(SpvParserTest, ConvertType_Sampler_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1);
EXPECT_TRUE(type->Is<type::Void>());
EXPECT_TRUE(type->Is<sem::Void>());
EXPECT_TRUE(p->error().empty());
}
@ -828,7 +828,7 @@ TEST_F(SpvParserTest, ConvertType_Image_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1);
EXPECT_TRUE(type->Is<type::Void>());
EXPECT_TRUE(type->Is<sem::Void>());
EXPECT_TRUE(p->error().empty());
}
@ -841,7 +841,7 @@ TEST_F(SpvParserTest, ConvertType_SampledImage_PretendVoid) {
EXPECT_TRUE(p->BuildInternalModule());
auto* type = p->ConvertType(1);
EXPECT_TRUE(type->Is<type::Void>());
EXPECT_TRUE(type->Is<sem::Void>());
EXPECT_TRUE(p->error().empty());
}

View File

@ -173,7 +173,7 @@ ParserImpl::FunctionHeader::FunctionHeader(const FunctionHeader&) = default;
ParserImpl::FunctionHeader::FunctionHeader(Source src,
std::string n,
ast::VariableList p,
type::Type* ret_ty,
sem::Type* ret_ty,
ast::DecorationList ret_decos)
: source(src),
name(n),
@ -243,11 +243,11 @@ Token ParserImpl::peek() {
}
void ParserImpl::register_constructed(const std::string& name,
type::Type* type) {
sem::Type* type) {
registered_constructs_[name] = type;
}
type::Type* ParserImpl::get_constructed(const std::string& name) {
sem::Type* ParserImpl::get_constructed(const std::string& name) {
if (registered_constructs_.find(name) == registered_constructs_.end()) {
return nullptr;
}
@ -507,7 +507,7 @@ Maybe<ParserImpl::VarDeclInfo> ParserImpl::variable_decl() {
// | sampled_texture_type LESS_THAN type_decl GREATER_THAN
// | multisampled_texture_type LESS_THAN type_decl GREATER_THAN
// | storage_texture_type LESS_THAN image_storage_type GREATER_THAN
Maybe<type::Type*> ParserImpl::texture_sampler_types() {
Maybe<sem::Type*> ParserImpl::texture_sampler_types() {
auto type = sampler_type();
if (type.matched)
return type;
@ -524,7 +524,7 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
if (subtype.errored)
return Failure::kErrored;
return builder_.create<type::SampledTexture>(dim.value, subtype.value);
return builder_.create<sem::SampledTexture>(dim.value, subtype.value);
}
auto ms_dim = multisampled_texture_type();
@ -535,8 +535,8 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
if (subtype.errored)
return Failure::kErrored;
return builder_.create<type::MultisampledTexture>(ms_dim.value,
subtype.value);
return builder_.create<sem::MultisampledTexture>(ms_dim.value,
subtype.value);
}
auto storage = storage_texture_type();
@ -550,9 +550,9 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
return Failure::kErrored;
auto* subtype =
type::StorageTexture::SubtypeFor(format.value, builder_.Types());
return builder_.create<type::StorageTexture>(storage.value, format.value,
subtype);
sem::StorageTexture::SubtypeFor(format.value, builder_.Types());
return builder_.create<sem::StorageTexture>(storage.value, format.value,
subtype);
}
return Failure::kNoMatch;
@ -561,13 +561,12 @@ Maybe<type::Type*> ParserImpl::texture_sampler_types() {
// sampler_type
// : SAMPLER
// | SAMPLER_COMPARISON
Maybe<type::Type*> ParserImpl::sampler_type() {
Maybe<sem::Type*> ParserImpl::sampler_type() {
if (match(Token::Type::kSampler))
return builder_.create<type::Sampler>(type::SamplerKind::kSampler);
return builder_.create<sem::Sampler>(sem::SamplerKind::kSampler);
if (match(Token::Type::kComparisonSampler))
return builder_.create<type::Sampler>(
type::SamplerKind::kComparisonSampler);
return builder_.create<sem::Sampler>(sem::SamplerKind::kComparisonSampler);
return Failure::kNoMatch;
}
@ -579,33 +578,33 @@ Maybe<type::Type*> ParserImpl::sampler_type() {
// | TEXTURE_SAMPLED_3D
// | TEXTURE_SAMPLED_CUBE
// | TEXTURE_SAMPLED_CUBE_ARRAY
Maybe<type::TextureDimension> ParserImpl::sampled_texture_type() {
Maybe<sem::TextureDimension> ParserImpl::sampled_texture_type() {
if (match(Token::Type::kTextureSampled1d))
return type::TextureDimension::k1d;
return sem::TextureDimension::k1d;
if (match(Token::Type::kTextureSampled2d))
return type::TextureDimension::k2d;
return sem::TextureDimension::k2d;
if (match(Token::Type::kTextureSampled2dArray))
return type::TextureDimension::k2dArray;
return sem::TextureDimension::k2dArray;
if (match(Token::Type::kTextureSampled3d))
return type::TextureDimension::k3d;
return sem::TextureDimension::k3d;
if (match(Token::Type::kTextureSampledCube))
return type::TextureDimension::kCube;
return sem::TextureDimension::kCube;
if (match(Token::Type::kTextureSampledCubeArray))
return type::TextureDimension::kCubeArray;
return sem::TextureDimension::kCubeArray;
return Failure::kNoMatch;
}
// multisampled_texture_type
// : TEXTURE_MULTISAMPLED_2D
Maybe<type::TextureDimension> ParserImpl::multisampled_texture_type() {
Maybe<sem::TextureDimension> ParserImpl::multisampled_texture_type() {
if (match(Token::Type::kTextureMultisampled2d))
return type::TextureDimension::k2d;
return sem::TextureDimension::k2d;
return Failure::kNoMatch;
}
@ -615,15 +614,15 @@ Maybe<type::TextureDimension> ParserImpl::multisampled_texture_type() {
// | TEXTURE_STORAGE_2D
// | TEXTURE_STORAGE_2D_ARRAY
// | TEXTURE_STORAGE_3D
Maybe<type::TextureDimension> ParserImpl::storage_texture_type() {
Maybe<sem::TextureDimension> ParserImpl::storage_texture_type() {
if (match(Token::Type::kTextureStorage1d))
return type::TextureDimension::k1d;
return sem::TextureDimension::k1d;
if (match(Token::Type::kTextureStorage2d))
return type::TextureDimension::k2d;
return sem::TextureDimension::k2d;
if (match(Token::Type::kTextureStorage2dArray))
return type::TextureDimension::k2dArray;
return sem::TextureDimension::k2dArray;
if (match(Token::Type::kTextureStorage3d))
return type::TextureDimension::k3d;
return sem::TextureDimension::k3d;
return Failure::kNoMatch;
}
@ -633,20 +632,19 @@ Maybe<type::TextureDimension> ParserImpl::storage_texture_type() {
// | TEXTURE_DEPTH_2D_ARRAY
// | TEXTURE_DEPTH_CUBE
// | TEXTURE_DEPTH_CUBE_ARRAY
Maybe<type::Type*> ParserImpl::depth_texture_type() {
Maybe<sem::Type*> ParserImpl::depth_texture_type() {
if (match(Token::Type::kTextureDepth2d))
return builder_.create<type::DepthTexture>(type::TextureDimension::k2d);
return builder_.create<sem::DepthTexture>(sem::TextureDimension::k2d);
if (match(Token::Type::kTextureDepth2dArray))
return builder_.create<type::DepthTexture>(
type::TextureDimension::k2dArray);
return builder_.create<sem::DepthTexture>(sem::TextureDimension::k2dArray);
if (match(Token::Type::kTextureDepthCube))
return builder_.create<type::DepthTexture>(type::TextureDimension::kCube);
return builder_.create<sem::DepthTexture>(sem::TextureDimension::kCube);
if (match(Token::Type::kTextureDepthCubeArray))
return builder_.create<type::DepthTexture>(
type::TextureDimension::kCubeArray);
return builder_.create<sem::DepthTexture>(
sem::TextureDimension::kCubeArray);
return Failure::kNoMatch;
}
@ -687,112 +685,112 @@ Maybe<type::Type*> ParserImpl::depth_texture_type() {
// | RGBA32UINT
// | RGBA32SINT
// | RGBA32FLOAT
Expect<type::ImageFormat> ParserImpl::expect_image_storage_type(
Expect<sem::ImageFormat> ParserImpl::expect_image_storage_type(
const std::string& use) {
if (match(Token::Type::kFormatR8Unorm))
return type::ImageFormat::kR8Unorm;
return sem::ImageFormat::kR8Unorm;
if (match(Token::Type::kFormatR8Snorm))
return type::ImageFormat::kR8Snorm;
return sem::ImageFormat::kR8Snorm;
if (match(Token::Type::kFormatR8Uint))
return type::ImageFormat::kR8Uint;
return sem::ImageFormat::kR8Uint;
if (match(Token::Type::kFormatR8Sint))
return type::ImageFormat::kR8Sint;
return sem::ImageFormat::kR8Sint;
if (match(Token::Type::kFormatR16Uint))
return type::ImageFormat::kR16Uint;
return sem::ImageFormat::kR16Uint;
if (match(Token::Type::kFormatR16Sint))
return type::ImageFormat::kR16Sint;
return sem::ImageFormat::kR16Sint;
if (match(Token::Type::kFormatR16Float))
return type::ImageFormat::kR16Float;
return sem::ImageFormat::kR16Float;
if (match(Token::Type::kFormatRg8Unorm))
return type::ImageFormat::kRg8Unorm;
return sem::ImageFormat::kRg8Unorm;
if (match(Token::Type::kFormatRg8Snorm))
return type::ImageFormat::kRg8Snorm;
return sem::ImageFormat::kRg8Snorm;
if (match(Token::Type::kFormatRg8Uint))
return type::ImageFormat::kRg8Uint;
return sem::ImageFormat::kRg8Uint;
if (match(Token::Type::kFormatRg8Sint))
return type::ImageFormat::kRg8Sint;
return sem::ImageFormat::kRg8Sint;
if (match(Token::Type::kFormatR32Uint))
return type::ImageFormat::kR32Uint;
return sem::ImageFormat::kR32Uint;
if (match(Token::Type::kFormatR32Sint))
return type::ImageFormat::kR32Sint;
return sem::ImageFormat::kR32Sint;
if (match(Token::Type::kFormatR32Float))
return type::ImageFormat::kR32Float;
return sem::ImageFormat::kR32Float;
if (match(Token::Type::kFormatRg16Uint))
return type::ImageFormat::kRg16Uint;
return sem::ImageFormat::kRg16Uint;
if (match(Token::Type::kFormatRg16Sint))
return type::ImageFormat::kRg16Sint;
return sem::ImageFormat::kRg16Sint;
if (match(Token::Type::kFormatRg16Float))
return type::ImageFormat::kRg16Float;
return sem::ImageFormat::kRg16Float;
if (match(Token::Type::kFormatRgba8Unorm))
return type::ImageFormat::kRgba8Unorm;
return sem::ImageFormat::kRgba8Unorm;
if (match(Token::Type::kFormatRgba8UnormSrgb))
return type::ImageFormat::kRgba8UnormSrgb;
return sem::ImageFormat::kRgba8UnormSrgb;
if (match(Token::Type::kFormatRgba8Snorm))
return type::ImageFormat::kRgba8Snorm;
return sem::ImageFormat::kRgba8Snorm;
if (match(Token::Type::kFormatRgba8Uint))
return type::ImageFormat::kRgba8Uint;
return sem::ImageFormat::kRgba8Uint;
if (match(Token::Type::kFormatRgba8Sint))
return type::ImageFormat::kRgba8Sint;
return sem::ImageFormat::kRgba8Sint;
if (match(Token::Type::kFormatBgra8Unorm))
return type::ImageFormat::kBgra8Unorm;
return sem::ImageFormat::kBgra8Unorm;
if (match(Token::Type::kFormatBgra8UnormSrgb))
return type::ImageFormat::kBgra8UnormSrgb;
return sem::ImageFormat::kBgra8UnormSrgb;
if (match(Token::Type::kFormatRgb10A2Unorm))
return type::ImageFormat::kRgb10A2Unorm;
return sem::ImageFormat::kRgb10A2Unorm;
if (match(Token::Type::kFormatRg11B10Float))
return type::ImageFormat::kRg11B10Float;
return sem::ImageFormat::kRg11B10Float;
if (match(Token::Type::kFormatRg32Uint))
return type::ImageFormat::kRg32Uint;
return sem::ImageFormat::kRg32Uint;
if (match(Token::Type::kFormatRg32Sint))
return type::ImageFormat::kRg32Sint;
return sem::ImageFormat::kRg32Sint;
if (match(Token::Type::kFormatRg32Float))
return type::ImageFormat::kRg32Float;
return sem::ImageFormat::kRg32Float;
if (match(Token::Type::kFormatRgba16Uint))
return type::ImageFormat::kRgba16Uint;
return sem::ImageFormat::kRgba16Uint;
if (match(Token::Type::kFormatRgba16Sint))
return type::ImageFormat::kRgba16Sint;
return sem::ImageFormat::kRgba16Sint;
if (match(Token::Type::kFormatRgba16Float))
return type::ImageFormat::kRgba16Float;
return sem::ImageFormat::kRgba16Float;
if (match(Token::Type::kFormatRgba32Uint))
return type::ImageFormat::kRgba32Uint;
return sem::ImageFormat::kRgba32Uint;
if (match(Token::Type::kFormatRgba32Sint))
return type::ImageFormat::kRgba32Sint;
return sem::ImageFormat::kRgba32Sint;
if (match(Token::Type::kFormatRgba32Float))
return type::ImageFormat::kRgba32Float;
return sem::ImageFormat::kRgba32Float;
return add_error(peek().source(), "invalid format", use);
}
@ -831,7 +829,7 @@ Expect<ParserImpl::TypedIdentifier> ParserImpl::expect_variable_ident_decl(
for (auto* deco : access_decos) {
// If we have an access control decoration then we take it and wrap our
// type up with that decoration
ty = builder_.create<type::AccessControl>(
ty = builder_.create<sem::AccessControl>(
deco->As<ast::AccessDecoration>()->value(), ty);
}
@ -871,7 +869,7 @@ Maybe<ast::StorageClass> ParserImpl::variable_storage_decoration() {
// type_alias
// : TYPE IDENT EQUAL type_decl
Maybe<type::Type*> ParserImpl::type_alias() {
Maybe<sem::Type*> ParserImpl::type_alias() {
auto t = peek();
if (!t.IsType())
return Failure::kNoMatch;
@ -893,7 +891,7 @@ Maybe<type::Type*> ParserImpl::type_alias() {
if (!type.matched)
return add_error(peek(), "invalid type alias");
auto* alias = builder_.create<type::Alias>(
auto* alias = builder_.create<sem::Alias>(
builder_.Symbols().Register(name.value), type.value);
register_constructed(name.value, alias);
@ -924,7 +922,7 @@ Maybe<type::Type*> ParserImpl::type_alias() {
// | MAT4x3 LESS_THAN type_decl GREATER_THAN
// | MAT4x4 LESS_THAN type_decl GREATER_THAN
// | texture_sampler_types
Maybe<type::Type*> ParserImpl::type_decl() {
Maybe<sem::Type*> ParserImpl::type_decl() {
auto decos = decoration_list();
if (decos.errored)
return Failure::kErrored;
@ -941,7 +939,7 @@ Maybe<type::Type*> ParserImpl::type_decl() {
return type.value;
}
Maybe<type::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
Maybe<sem::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
auto t = peek();
if (match(Token::Type::kIdentifier)) {
auto* ty = get_constructed(t.to_str());
@ -952,16 +950,16 @@ Maybe<type::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
}
if (match(Token::Type::kBool))
return builder_.create<type::Bool>();
return builder_.create<sem::Bool>();
if (match(Token::Type::kF32))
return builder_.create<type::F32>();
return builder_.create<sem::F32>();
if (match(Token::Type::kI32))
return builder_.create<type::I32>();
return builder_.create<sem::I32>();
if (match(Token::Type::kU32))
return builder_.create<type::U32>();
return builder_.create<sem::U32>();
if (t.IsVec2() || t.IsVec3() || t.IsVec4()) {
next(); // Consume the peek
@ -991,7 +989,7 @@ Maybe<type::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
return Failure::kNoMatch;
}
Expect<type::Type*> ParserImpl::expect_type(const std::string& use) {
Expect<sem::Type*> ParserImpl::expect_type(const std::string& use) {
auto type = type_decl();
if (type.errored)
return Failure::kErrored;
@ -1000,10 +998,10 @@ Expect<type::Type*> ParserImpl::expect_type(const std::string& use) {
return type.value;
}
Expect<type::Type*> ParserImpl::expect_type_decl_pointer() {
Expect<sem::Type*> ParserImpl::expect_type_decl_pointer() {
const char* use = "ptr declaration";
return expect_lt_gt_block(use, [&]() -> Expect<type::Type*> {
return expect_lt_gt_block(use, [&]() -> Expect<sem::Type*> {
auto sc = expect_storage_class(use);
if (sc.errored)
return Failure::kErrored;
@ -1015,11 +1013,11 @@ Expect<type::Type*> ParserImpl::expect_type_decl_pointer() {
if (subtype.errored)
return Failure::kErrored;
return builder_.create<type::Pointer>(subtype.value, sc.value);
return builder_.create<sem::Pointer>(subtype.value, sc.value);
});
}
Expect<type::Type*> ParserImpl::expect_type_decl_vector(Token t) {
Expect<sem::Type*> ParserImpl::expect_type_decl_vector(Token t) {
uint32_t count = 2;
if (t.IsVec3())
count = 3;
@ -1032,14 +1030,14 @@ Expect<type::Type*> ParserImpl::expect_type_decl_vector(Token t) {
if (subtype.errored)
return Failure::kErrored;
return builder_.create<type::Vector>(subtype.value, count);
return builder_.create<sem::Vector>(subtype.value, count);
}
Expect<type::Type*> ParserImpl::expect_type_decl_array(
Expect<sem::Type*> ParserImpl::expect_type_decl_array(
ast::DecorationList decos) {
const char* use = "array declaration";
return expect_lt_gt_block(use, [&]() -> Expect<type::Type*> {
return expect_lt_gt_block(use, [&]() -> Expect<sem::Type*> {
auto subtype = expect_type(use);
if (subtype.errored)
return Failure::kErrored;
@ -1052,11 +1050,11 @@ Expect<type::Type*> ParserImpl::expect_type_decl_array(
size = val.value;
}
return create<type::ArrayType>(subtype.value, size, std::move(decos));
return create<sem::ArrayType>(subtype.value, size, std::move(decos));
});
}
Expect<type::Type*> ParserImpl::expect_type_decl_matrix(Token t) {
Expect<sem::Type*> ParserImpl::expect_type_decl_matrix(Token t) {
uint32_t rows = 2;
uint32_t columns = 2;
if (t.IsMat3x2() || t.IsMat3x3() || t.IsMat3x4()) {
@ -1076,7 +1074,7 @@ Expect<type::Type*> ParserImpl::expect_type_decl_matrix(Token t) {
if (subtype.errored)
return Failure::kErrored;
return builder_.create<type::Matrix>(subtype.value, rows, columns);
return builder_.create<sem::Matrix>(subtype.value, rows, columns);
}
// storage_class
@ -1121,7 +1119,7 @@ Expect<ast::StorageClass> ParserImpl::expect_storage_class(
// struct_decl
// : struct_decoration_decl* STRUCT IDENT struct_body_decl
Maybe<type::StructType*> ParserImpl::struct_decl(ast::DecorationList& decos) {
Maybe<sem::StructType*> ParserImpl::struct_decl(ast::DecorationList& decos) {
auto t = peek();
auto source = t.source();
@ -1136,7 +1134,7 @@ Maybe<type::StructType*> ParserImpl::struct_decl(ast::DecorationList& decos) {
if (body.errored)
return Failure::kErrored;
return create<type::StructType>(
return create<sem::StructType>(
builder_.Symbols().Register(name.value),
create<ast::Struct>(source, std::move(body.value), std::move(decos)));
}
@ -1227,9 +1225,9 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
// function_type_decl
// : type_decl
// | VOID
Maybe<type::Type*> ParserImpl::function_type_decl() {
Maybe<sem::Type*> ParserImpl::function_type_decl() {
if (match(Token::Type::kVoid))
return builder_.create<type::Void>();
return builder_.create<sem::Void>();
return type_decl();
}
@ -1261,7 +1259,7 @@ Maybe<ParserImpl::FunctionHeader> ParserImpl::function_header() {
}
}
type::Type* return_type = nullptr;
sem::Type* return_type = nullptr;
ast::DecorationList return_decorations;
if (match(Token::Type::kArrow)) {
@ -1282,7 +1280,7 @@ Maybe<ParserImpl::FunctionHeader> ParserImpl::function_header() {
return_type = type.value;
}
if (return_type->Is<type::Void>()) {
if (return_type->Is<sem::Void>()) {
// crbug.com/tint/677: void has been removed from the language
deprecated(tok.source(),
"omit '-> void' for functions that do not return a value");
@ -2726,19 +2724,19 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
Maybe<ast::Literal*> ParserImpl::const_literal() {
auto t = peek();
if (match(Token::Type::kTrue)) {
auto* type = builder_.create<type::Bool>();
auto* type = builder_.create<sem::Bool>();
return create<ast::BoolLiteral>(Source{}, type, true);
}
if (match(Token::Type::kFalse)) {
auto* type = builder_.create<type::Bool>();
auto* type = builder_.create<sem::Bool>();
return create<ast::BoolLiteral>(Source{}, type, false);
}
if (match(Token::Type::kSintLiteral)) {
auto* type = builder_.create<type::I32>();
auto* type = builder_.create<sem::I32>();
return create<ast::SintLiteral>(Source{}, type, t.to_i32());
}
if (match(Token::Type::kUintLiteral)) {
auto* type = builder_.create<type::U32>();
auto* type = builder_.create<sem::U32>();
return create<ast::UintLiteral>(Source{}, type, t.to_u32());
}
if (match(Token::Type::kFloatLiteral)) {
@ -2747,7 +2745,7 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
next(); // Consume 'f'
add_error(p.source(), "float literals must not be suffixed with 'f'");
}
auto* type = builder_.create<type::F32>();
auto* type = builder_.create<sem::F32>();
return create<ast::FloatLiteral>(Source{}, type, t.to_f32());
}
return Failure::kNoMatch;

View File

@ -199,7 +199,7 @@ class ParserImpl {
/// variable_ident_decl().
struct TypedIdentifier {
/// Parsed type.
type::Type* type = nullptr;
sem::Type* type = nullptr;
/// Parsed identifier.
std::string name;
/// Source to the identifier.
@ -222,7 +222,7 @@ class ParserImpl {
FunctionHeader(Source src,
std::string n,
ast::VariableList p,
type::Type* ret_ty,
sem::Type* ret_ty,
ast::DecorationList ret_decos);
/// Destructor
~FunctionHeader();
@ -238,7 +238,7 @@ class ParserImpl {
/// Function parameters
ast::VariableList params;
/// Function return type
type::Type* return_type;
sem::Type* return_type;
/// Function return type decorations
ast::DecorationList return_type_decorations;
};
@ -252,7 +252,7 @@ class ParserImpl {
/// Variable storage class
ast::StorageClass storage_class;
/// Variable type
type::Type* type;
sem::Type* type;
};
/// Creates a new parser using the given file
@ -328,11 +328,11 @@ class ParserImpl {
/// Registers a constructed type into the parser
/// @param name the constructed name
/// @param type the constructed type
void register_constructed(const std::string& name, type::Type* type);
void register_constructed(const std::string& name, sem::Type* type);
/// Retrieves a constructed type
/// @param name The name to lookup
/// @returns the constructed type for `name` or `nullptr` if not found
type::Type* get_constructed(const std::string& name);
sem::Type* get_constructed(const std::string& name);
/// Parses the `translation_unit` grammar element
void translation_unit();
@ -362,15 +362,15 @@ class ParserImpl {
Maybe<ast::StorageClass> variable_storage_decoration();
/// Parses a `type_alias` grammar element
/// @returns the type alias or nullptr on error
Maybe<type::Type*> type_alias();
Maybe<sem::Type*> type_alias();
/// Parses a `type_decl` grammar element
/// @returns the parsed Type or nullptr if none matched.
Maybe<type::Type*> type_decl();
Maybe<sem::Type*> type_decl();
/// Parses a `type_decl` grammar element with the given pre-parsed
/// decorations.
/// @param decos the list of decorations for the type.
/// @returns the parsed Type or nullptr if none matched.
Maybe<type::Type*> type_decl(ast::DecorationList& decos);
Maybe<sem::Type*> type_decl(ast::DecorationList& decos);
/// Parses a `storage_class` grammar element, erroring on parse failure.
/// @param use a description of what was being parsed if an error was raised.
/// @returns the storage class or StorageClass::kNone if none matched
@ -379,7 +379,7 @@ class ParserImpl {
/// `struct_decoration_decl*` provided as `decos`.
/// @returns the struct type or nullptr on error
/// @param decos the list of decorations for the struct declaration.
Maybe<type::StructType*> struct_decl(ast::DecorationList& decos);
Maybe<sem::StructType*> struct_decl(ast::DecorationList& decos);
/// Parses a `struct_body_decl` grammar element, erroring on parse failure.
/// @returns the struct members
Expect<ast::StructMemberList> expect_struct_body_decl();
@ -396,31 +396,31 @@ class ParserImpl {
Maybe<ast::Function*> function_decl(ast::DecorationList& decos);
/// Parses a `texture_sampler_types` grammar element
/// @returns the parsed Type or nullptr if none matched.
Maybe<type::Type*> texture_sampler_types();
Maybe<sem::Type*> texture_sampler_types();
/// Parses a `sampler_type` grammar element
/// @returns the parsed Type or nullptr if none matched.
Maybe<type::Type*> sampler_type();
Maybe<sem::Type*> sampler_type();
/// Parses a `multisampled_texture_type` grammar element
/// @returns returns the multisample texture dimension or kNone if none
/// matched.
Maybe<type::TextureDimension> multisampled_texture_type();
Maybe<sem::TextureDimension> multisampled_texture_type();
/// Parses a `sampled_texture_type` grammar element
/// @returns returns the sample texture dimension or kNone if none matched.
Maybe<type::TextureDimension> sampled_texture_type();
Maybe<sem::TextureDimension> sampled_texture_type();
/// Parses a `storage_texture_type` grammar element
/// @returns returns the storage texture dimension.
/// Returns kNone if none matched.
Maybe<type::TextureDimension> storage_texture_type();
Maybe<sem::TextureDimension> storage_texture_type();
/// Parses a `depth_texture_type` grammar element
/// @returns the parsed Type or nullptr if none matched.
Maybe<type::Type*> depth_texture_type();
Maybe<sem::Type*> depth_texture_type();
/// Parses a `image_storage_type` grammar element
/// @param use a description of what was being parsed if an error was raised
/// @returns returns the image format or kNone if none matched.
Expect<type::ImageFormat> expect_image_storage_type(const std::string& use);
Expect<sem::ImageFormat> expect_image_storage_type(const std::string& use);
/// Parses a `function_type_decl` grammar element
/// @returns the parsed type or nullptr otherwise
Maybe<type::Type*> function_type_decl();
Maybe<sem::Type*> function_type_decl();
/// Parses a `function_header` grammar element
/// @returns the parsed function header
Maybe<FunctionHeader> function_header();
@ -784,12 +784,12 @@ class ParserImpl {
/// Used to ensure that all decorations are consumed.
bool expect_decorations_consumed(const ast::DecorationList& list);
Expect<type::Type*> expect_type_decl_pointer();
Expect<type::Type*> expect_type_decl_vector(Token t);
Expect<type::Type*> expect_type_decl_array(ast::DecorationList decos);
Expect<type::Type*> expect_type_decl_matrix(Token t);
Expect<sem::Type*> expect_type_decl_pointer();
Expect<sem::Type*> expect_type_decl_vector(Token t);
Expect<sem::Type*> expect_type_decl_array(ast::DecorationList decos);
Expect<sem::Type*> expect_type_decl_matrix(Token t);
Expect<type::Type*> expect_type(const std::string& use);
Expect<sem::Type*> expect_type(const std::string& use);
Maybe<ast::Statement*> non_block_statement();
Maybe<ast::Statement*> for_header_initializer();
@ -810,7 +810,7 @@ class ParserImpl {
uint32_t sync_depth_ = 0;
std::vector<Token::Type> sync_tokens_;
int silence_errors_ = 0;
std::unordered_map<std::string, type::Type*> registered_constructs_;
std::unordered_map<std::string, sem::Type*> registered_constructs_;
ProgramBuilder builder_;
size_t max_errors_ = 25;
};

View File

@ -28,8 +28,8 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) {
ASSERT_TRUE(e->Is<ast::TypeConstructorExpression>());
auto* t = e->As<ast::TypeConstructorExpression>();
ASSERT_TRUE(t->type()->Is<type::Vector>());
EXPECT_EQ(t->type()->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(t->type()->Is<sem::Vector>());
EXPECT_EQ(t->type()->As<sem::Vector>()->size(), 2u);
ASSERT_EQ(t->values().size(), 2u);
auto& v = t->values();

View File

@ -34,9 +34,9 @@ TEST_F(ParserImplTest, DepthTextureType_2d) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::DepthTexture>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k2d);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
EXPECT_FALSE(p->has_error());
}
@ -46,9 +46,9 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::DepthTexture>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k2dArray);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2dArray);
EXPECT_FALSE(p->has_error());
}
@ -58,9 +58,9 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::DepthTexture>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::kCube);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::kCube);
EXPECT_FALSE(p->has_error());
}
@ -70,9 +70,9 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::DepthTexture>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::kCubeArray);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::kCubeArray);
EXPECT_FALSE(p->has_error());
}

View File

@ -34,14 +34,14 @@ TEST_F(ParserImplTest, FunctionDecl) {
EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main"));
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>());
EXPECT_TRUE(f->return_type()->Is<sem::Void>());
ASSERT_EQ(f->params().size(), 2u);
EXPECT_EQ(f->params()[0]->symbol(), p->builder().Symbols().Get("a"));
EXPECT_EQ(f->params()[1]->symbol(), p->builder().Symbols().Get("b"));
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>());
EXPECT_TRUE(f->return_type()->Is<sem::Void>());
auto* body = f->body();
ASSERT_EQ(body->size(), 1u);
@ -62,10 +62,10 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main"));
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>());
EXPECT_TRUE(f->return_type()->Is<sem::Void>());
ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>());
EXPECT_TRUE(f->return_type()->Is<sem::Void>());
auto& decorations = f->decorations();
ASSERT_EQ(decorations.size(), 1u);
@ -100,10 +100,10 @@ fn main() { return; })");
EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main"));
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>());
EXPECT_TRUE(f->return_type()->Is<sem::Void>());
ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>());
EXPECT_TRUE(f->return_type()->Is<sem::Void>());
auto& decorations = f->decorations();
ASSERT_EQ(decorations.size(), 2u);
@ -145,10 +145,10 @@ fn main() { return; })");
EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main"));
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>());
EXPECT_TRUE(f->return_type()->Is<sem::Void>());
ASSERT_EQ(f->params().size(), 0u);
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>());
EXPECT_TRUE(f->return_type()->Is<sem::Void>());
auto& decos = f->decorations();
ASSERT_EQ(decos.size(), 2u);
@ -187,7 +187,7 @@ TEST_F(ParserImplTest, FunctionDecl_ReturnTypeDecorationList) {
EXPECT_EQ(f->symbol(), p->builder().Symbols().Get("main"));
ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::F32>());
EXPECT_TRUE(f->return_type()->Is<sem::F32>());
ASSERT_EQ(f->params().size(), 0u);
auto& decorations = f->decorations();

View File

@ -30,7 +30,7 @@ TEST_F(ParserImplTest, FunctionHeader) {
ASSERT_EQ(f->params.size(), 2u);
EXPECT_EQ(f->params[0]->symbol(), p->builder().Symbols().Get("a"));
EXPECT_EQ(f->params[1]->symbol(), p->builder().Symbols().Get("b"));
EXPECT_TRUE(f->return_type->Is<type::Void>());
EXPECT_TRUE(f->return_type->Is<sem::Void>());
}
TEST_F(ParserImplTest, FunctionHeader_DecoratedReturnType) {
@ -42,7 +42,7 @@ TEST_F(ParserImplTest, FunctionHeader_DecoratedReturnType) {
EXPECT_EQ(f->name, "main");
EXPECT_EQ(f->params.size(), 0u);
EXPECT_TRUE(f->return_type->Is<type::F32>());
EXPECT_TRUE(f->return_type->Is<sem::F32>());
ASSERT_EQ(f->return_type_decorations.size(), 1u);
auto* loc = f->return_type_decorations[0]->As<ast::LocationDecoration>();
ASSERT_TRUE(loc != nullptr);

View File

@ -22,7 +22,7 @@ namespace {
TEST_F(ParserImplTest, FunctionTypeDecl_Void) {
auto p = parser("void");
auto* v = p->builder().create<type::Void>();
auto* v = p->builder().create<sem::Void>();
auto e = p->function_type_decl();
EXPECT_TRUE(e.matched);
@ -34,8 +34,8 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Void) {
TEST_F(ParserImplTest, FunctionTypeDecl_Type) {
auto p = parser("vec2<f32>");
auto* f32 = p->builder().create<type::F32>();
auto* vec2 = p->builder().create<type::Vector>(f32, 2);
auto* f32 = p->builder().create<sem::F32>();
auto* vec2 = p->builder().create<sem::Vector>(f32, 2);
auto e = p->function_type_decl();
EXPECT_TRUE(e.matched);

View File

@ -34,7 +34,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) {
EXPECT_TRUE(e->is_const());
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
ASSERT_NE(e->declared_type(), nullptr);
EXPECT_TRUE(e->declared_type()->Is<type::F32>());
EXPECT_TRUE(e->declared_type()->Is<sem::F32>());
EXPECT_EQ(e->source().range.begin.line, 1u);
EXPECT_EQ(e->source().range.begin.column, 5u);
@ -115,7 +115,7 @@ TEST_F(ParserImplTest, GlobalConstantDec_ConstantId) {
EXPECT_TRUE(e->is_const());
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
ASSERT_NE(e->declared_type(), nullptr);
EXPECT_TRUE(e->declared_type()->Is<type::F32>());
EXPECT_TRUE(e->declared_type()->Is<sem::F32>());
EXPECT_EQ(e->source().range.begin.line, 1u);
EXPECT_EQ(e->source().range.begin.column, 24u);

View File

@ -84,10 +84,10 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
auto program = p->program();
ASSERT_EQ(program.AST().ConstructedTypes().size(), 1u);
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<type::Alias>());
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<sem::Alias>());
EXPECT_EQ(
program.Symbols().NameFor(
program.AST().ConstructedTypes()[0]->As<type::Alias>()->symbol()),
program.AST().ConstructedTypes()[0]->As<sem::Alias>()->symbol()),
"A");
}
@ -102,12 +102,12 @@ type B = A;)");
auto program = p->program();
ASSERT_EQ(program.AST().ConstructedTypes().size(), 2u);
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<type::StructType>());
auto* str = program.AST().ConstructedTypes()[0]->As<type::StructType>();
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<sem::StructType>());
auto* str = program.AST().ConstructedTypes()[0]->As<sem::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A"));
ASSERT_TRUE(program.AST().ConstructedTypes()[1]->Is<type::Alias>());
auto* alias = program.AST().ConstructedTypes()[1]->As<type::Alias>();
ASSERT_TRUE(program.AST().ConstructedTypes()[1]->Is<sem::Alias>());
auto* alias = program.AST().ConstructedTypes()[1]->As<sem::Alias>();
EXPECT_EQ(alias->symbol(), program.Symbols().Get("B"));
EXPECT_EQ(alias->type(), str);
}
@ -165,9 +165,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
auto* t = program.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::StructType>());
ASSERT_TRUE(t->Is<sem::StructType>());
auto* str = t->As<type::StructType>();
auto* str = t->As<sem::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 2u);
}
@ -183,16 +183,16 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
auto* t = program.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::StructType>());
ASSERT_TRUE(t->Is<sem::StructType>());
auto* str = t->As<type::StructType>();
auto* str = t->As<sem::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_FALSE(str->IsBlockDecorated());
const auto* ty = str->impl()->members()[0]->type();
ASSERT_TRUE(ty->Is<type::ArrayType>());
const auto* arr = ty->As<type::ArrayType>();
ASSERT_TRUE(ty->Is<sem::ArrayType>());
const auto* arr = ty->As<sem::ArrayType>();
ASSERT_EQ(arr->decorations().size(), 1u);
auto* stride = arr->decorations()[0];
@ -210,9 +210,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
auto* t = program.AST().ConstructedTypes()[0];
ASSERT_NE(t, nullptr);
ASSERT_TRUE(t->Is<type::StructType>());
ASSERT_TRUE(t->Is<sem::StructType>());
auto* str = t->As<type::StructType>();
auto* str = t->As<sem::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_TRUE(str->IsBlockDecorated());

View File

@ -31,7 +31,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) {
ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
EXPECT_TRUE(e->declared_type()->Is<type::F32>());
EXPECT_TRUE(e->declared_type()->Is<sem::F32>());
EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kPrivate);
EXPECT_EQ(e->source().range.begin.line, 1u);
@ -54,7 +54,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
EXPECT_TRUE(e->declared_type()->Is<type::F32>());
EXPECT_TRUE(e->declared_type()->Is<sem::F32>());
EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kPrivate);
EXPECT_EQ(e->source().range.begin.line, 1u);
@ -80,7 +80,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) {
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
ASSERT_NE(e->declared_type(), nullptr);
EXPECT_TRUE(e->declared_type()->Is<type::F32>());
EXPECT_TRUE(e->declared_type()->Is<sem::F32>());
EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kUniform);
EXPECT_EQ(e->source().range.begin.line, 1u);
@ -110,7 +110,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) {
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
ASSERT_NE(e->declared_type(), nullptr);
EXPECT_TRUE(e->declared_type()->Is<type::F32>());
EXPECT_TRUE(e->declared_type()->Is<sem::F32>());
EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kUniform);
EXPECT_EQ(e->source().range.begin.line, 1u);
@ -180,7 +180,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_SamplerImplicitStorageClass) {
ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("s"));
EXPECT_TRUE(e->declared_type()->Is<type::Sampler>());
EXPECT_TRUE(e->declared_type()->Is<sem::Sampler>());
EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kUniformConstant);
}
@ -196,7 +196,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_TextureImplicitStorageClass) {
ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("s"));
EXPECT_TRUE(e->declared_type()->UnwrapAll()->Is<type::Texture>());
EXPECT_TRUE(e->declared_type()->UnwrapAll()->Is<sem::Texture>());
EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kUniformConstant);
}
@ -210,7 +210,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_StorageClassIn_Deprecated) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
EXPECT_TRUE(e->declared_type()->Is<type::F32>());
EXPECT_TRUE(e->declared_type()->Is<sem::F32>());
EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kInput);
EXPECT_EQ(
@ -231,7 +231,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_StorageClassOut_Deprecated) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
EXPECT_TRUE(e->declared_type()->Is<type::F32>());
EXPECT_TRUE(e->declared_type()->Is<sem::F32>());
EXPECT_EQ(e->declared_storage_class(), ast::StorageClass::kOutput);
EXPECT_EQ(

View File

@ -31,7 +31,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Unorm) {
auto p = parser("r8unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR8Unorm);
EXPECT_EQ(t.value, sem::ImageFormat::kR8Unorm);
EXPECT_FALSE(p->has_error());
}
@ -39,7 +39,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Snorm) {
auto p = parser("r8snorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR8Snorm);
EXPECT_EQ(t.value, sem::ImageFormat::kR8Snorm);
EXPECT_FALSE(p->has_error());
}
@ -47,7 +47,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Uint) {
auto p = parser("r8uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR8Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kR8Uint);
EXPECT_FALSE(p->has_error());
}
@ -55,7 +55,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Sint) {
auto p = parser("r8sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR8Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kR8Sint);
EXPECT_FALSE(p->has_error());
}
@ -63,7 +63,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Uint) {
auto p = parser("r16uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR16Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kR16Uint);
EXPECT_FALSE(p->has_error());
}
@ -71,7 +71,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Sint) {
auto p = parser("r16sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR16Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kR16Sint);
EXPECT_FALSE(p->has_error());
}
@ -79,7 +79,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Float) {
auto p = parser("r16float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR16Float);
EXPECT_EQ(t.value, sem::ImageFormat::kR16Float);
EXPECT_FALSE(p->has_error());
}
@ -87,7 +87,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Unorm) {
auto p = parser("rg8unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg8Unorm);
EXPECT_EQ(t.value, sem::ImageFormat::kRg8Unorm);
EXPECT_FALSE(p->has_error());
}
@ -95,7 +95,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Snorm) {
auto p = parser("rg8snorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg8Snorm);
EXPECT_EQ(t.value, sem::ImageFormat::kRg8Snorm);
EXPECT_FALSE(p->has_error());
}
@ -103,7 +103,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Uint) {
auto p = parser("rg8uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg8Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kRg8Uint);
EXPECT_FALSE(p->has_error());
}
@ -111,7 +111,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Sint) {
auto p = parser("rg8sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg8Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kRg8Sint);
EXPECT_FALSE(p->has_error());
}
@ -119,7 +119,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Uint) {
auto p = parser("r32uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR32Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kR32Uint);
EXPECT_FALSE(p->has_error());
}
@ -127,7 +127,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Sint) {
auto p = parser("r32sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR32Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kR32Sint);
EXPECT_FALSE(p->has_error());
}
@ -135,7 +135,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Float) {
auto p = parser("r32float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kR32Float);
EXPECT_EQ(t.value, sem::ImageFormat::kR32Float);
EXPECT_FALSE(p->has_error());
}
@ -143,7 +143,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Uint) {
auto p = parser("rg16uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg16Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kRg16Uint);
EXPECT_FALSE(p->has_error());
}
@ -151,7 +151,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Sint) {
auto p = parser("rg16sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg16Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kRg16Sint);
EXPECT_FALSE(p->has_error());
}
@ -159,7 +159,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Float) {
auto p = parser("rg16float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg16Float);
EXPECT_EQ(t.value, sem::ImageFormat::kRg16Float);
EXPECT_FALSE(p->has_error());
}
@ -167,7 +167,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Unorm) {
auto p = parser("rgba8unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba8Unorm);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8Unorm);
EXPECT_FALSE(p->has_error());
}
@ -175,7 +175,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8UnormSrgb) {
auto p = parser("rgba8unorm_srgb");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba8UnormSrgb);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8UnormSrgb);
EXPECT_FALSE(p->has_error());
}
@ -183,7 +183,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Snorm) {
auto p = parser("rgba8snorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba8Snorm);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8Snorm);
EXPECT_FALSE(p->has_error());
}
@ -191,7 +191,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Uint) {
auto p = parser("rgba8uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba8Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8Uint);
EXPECT_FALSE(p->has_error());
}
@ -199,7 +199,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Sint) {
auto p = parser("rgba8sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba8Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8Sint);
EXPECT_FALSE(p->has_error());
}
@ -207,7 +207,7 @@ TEST_F(ParserImplTest, ImageStorageType_Bgra8Unorm) {
auto p = parser("bgra8unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kBgra8Unorm);
EXPECT_EQ(t.value, sem::ImageFormat::kBgra8Unorm);
EXPECT_FALSE(p->has_error());
}
@ -215,7 +215,7 @@ TEST_F(ParserImplTest, ImageStorageType_Bgra8UnormSrgb) {
auto p = parser("bgra8unorm_srgb");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kBgra8UnormSrgb);
EXPECT_EQ(t.value, sem::ImageFormat::kBgra8UnormSrgb);
EXPECT_FALSE(p->has_error());
}
@ -223,7 +223,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgb10A2Unorm) {
auto p = parser("rgb10a2unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgb10A2Unorm);
EXPECT_EQ(t.value, sem::ImageFormat::kRgb10A2Unorm);
EXPECT_FALSE(p->has_error());
}
@ -231,7 +231,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg11B10Float) {
auto p = parser("rg11b10float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg11B10Float);
EXPECT_EQ(t.value, sem::ImageFormat::kRg11B10Float);
EXPECT_FALSE(p->has_error());
}
@ -239,7 +239,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Uint) {
auto p = parser("rg32uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg32Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kRg32Uint);
EXPECT_FALSE(p->has_error());
}
@ -247,7 +247,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Sint) {
auto p = parser("rg32sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg32Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kRg32Sint);
EXPECT_FALSE(p->has_error());
}
@ -255,7 +255,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Float) {
auto p = parser("rg32float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRg32Float);
EXPECT_EQ(t.value, sem::ImageFormat::kRg32Float);
EXPECT_FALSE(p->has_error());
}
@ -263,7 +263,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Uint) {
auto p = parser("rgba16uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba16Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba16Uint);
EXPECT_FALSE(p->has_error());
}
@ -271,7 +271,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Sint) {
auto p = parser("rgba16sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba16Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba16Sint);
EXPECT_FALSE(p->has_error());
}
@ -279,7 +279,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Float) {
auto p = parser("rgba16float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba16Float);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba16Float);
EXPECT_FALSE(p->has_error());
}
@ -287,7 +287,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Uint) {
auto p = parser("rgba32uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba32Uint);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba32Uint);
EXPECT_FALSE(p->has_error());
}
@ -295,7 +295,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Sint) {
auto p = parser("rgba32sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba32Sint);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba32Sint);
EXPECT_FALSE(p->has_error());
}
@ -303,7 +303,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Float) {
auto p = parser("rgba32float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::ImageFormat::kRgba32Float);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba32Float);
EXPECT_FALSE(p->has_error());
}

View File

@ -22,7 +22,7 @@ namespace {
TEST_F(ParserImplTest, ParamList_Single) {
auto p = parser("a : i32");
auto* i32 = p->builder().create<type::I32>();
auto* i32 = p->builder().create<sem::I32>();
auto e = p->expect_param_list();
ASSERT_FALSE(p->has_error()) << p->error();
@ -42,9 +42,9 @@ TEST_F(ParserImplTest, ParamList_Single) {
TEST_F(ParserImplTest, ParamList_Multiple) {
auto p = parser("a : i32, b: f32, c: vec2<f32>");
auto* i32 = p->builder().create<type::I32>();
auto* f32 = p->builder().create<type::F32>();
auto* vec2 = p->builder().create<type::Vector>(f32, 2);
auto* i32 = p->builder().create<sem::I32>();
auto* f32 = p->builder().create<sem::F32>();
auto* vec2 = p->builder().create<sem::Vector>(f32, 2);
auto e = p->expect_param_list();
ASSERT_FALSE(p->has_error()) << p->error();
@ -100,8 +100,8 @@ TEST_F(ParserImplTest, ParamList_Decorations) {
"[[builtin(position)]] coord : vec4<f32>, "
"[[location(1)]] loc1 : f32");
auto* f32 = p->builder().create<type::F32>();
auto* vec4 = p->builder().create<type::Vector>(f32, 4);
auto* f32 = p->builder().create<sem::F32>();
auto* vec4 = p->builder().create<sem::Vector>(f32, 4);
auto e = p->expect_param_list();
ASSERT_FALSE(p->has_error()) << p->error();

View File

@ -237,7 +237,7 @@ TEST_F(ParserImplTest, PrimaryExpression_ParenExpr_InvalidExpr) {
TEST_F(ParserImplTest, PrimaryExpression_Cast) {
auto p = parser("f32(1)");
auto* f32 = p->builder().create<type::F32>();
auto* f32 = p->builder().create<sem::F32>();
auto e = p->primary_expression();
EXPECT_TRUE(e.matched);
@ -258,7 +258,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
auto p = parser("bitcast<f32>(1)");
auto* f32 = p->builder().create<type::F32>();
auto* f32 = p->builder().create<sem::F32>();
auto e = p->primary_expression();
EXPECT_TRUE(e.matched);

View File

@ -32,7 +32,7 @@ TEST_F(ParserImplTest, SampledTextureType_1d) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::k1d);
EXPECT_EQ(t.value, sem::TextureDimension::k1d);
EXPECT_FALSE(p->has_error());
}
@ -41,7 +41,7 @@ TEST_F(ParserImplTest, SampledTextureType_2d) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::k2d);
EXPECT_EQ(t.value, sem::TextureDimension::k2d);
EXPECT_FALSE(p->has_error());
}
@ -50,7 +50,7 @@ TEST_F(ParserImplTest, SampledTextureType_2dArray) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::k2dArray);
EXPECT_EQ(t.value, sem::TextureDimension::k2dArray);
EXPECT_FALSE(p->has_error());
}
@ -59,7 +59,7 @@ TEST_F(ParserImplTest, SampledTextureType_3d) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::k3d);
EXPECT_EQ(t.value, sem::TextureDimension::k3d);
EXPECT_FALSE(p->has_error());
}
@ -68,7 +68,7 @@ TEST_F(ParserImplTest, SampledTextureType_Cube) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::kCube);
EXPECT_EQ(t.value, sem::TextureDimension::kCube);
EXPECT_FALSE(p->has_error());
}
@ -77,7 +77,7 @@ TEST_F(ParserImplTest, SampledTextureType_kCubeArray) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::kCubeArray);
EXPECT_EQ(t.value, sem::TextureDimension::kCubeArray);
EXPECT_FALSE(p->has_error());
}

View File

@ -34,8 +34,8 @@ TEST_F(ParserImplTest, SamplerType_Sampler) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Sampler>());
EXPECT_FALSE(t->As<type::Sampler>()->IsComparison());
ASSERT_TRUE(t->Is<sem::Sampler>());
EXPECT_FALSE(t->As<sem::Sampler>()->IsComparison());
EXPECT_FALSE(p->has_error());
}
@ -45,8 +45,8 @@ TEST_F(ParserImplTest, SamplerType_ComparisonSampler) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Sampler>());
EXPECT_TRUE(t->As<type::Sampler>()->IsComparison());
ASSERT_TRUE(t->Is<sem::Sampler>());
EXPECT_TRUE(t->As<sem::Sampler>()->IsComparison());
EXPECT_FALSE(p->has_error());
}

View File

@ -32,7 +32,7 @@ TEST_F(ParserImplTest, StorageTextureType_1d) {
auto t = p->storage_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::k1d);
EXPECT_EQ(t.value, sem::TextureDimension::k1d);
EXPECT_FALSE(p->has_error());
}
@ -41,7 +41,7 @@ TEST_F(ParserImplTest, StorageTextureType_2d) {
auto t = p->storage_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::k2d);
EXPECT_EQ(t.value, sem::TextureDimension::k2d);
EXPECT_FALSE(p->has_error());
}
@ -50,7 +50,7 @@ TEST_F(ParserImplTest, StorageTextureType_2dArray) {
auto t = p->storage_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::k2dArray);
EXPECT_EQ(t.value, sem::TextureDimension::k2dArray);
EXPECT_FALSE(p->has_error());
}
@ -59,7 +59,7 @@ TEST_F(ParserImplTest, StorageTextureType_3d) {
auto t = p->storage_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, type::TextureDimension::k3d);
EXPECT_EQ(t.value, sem::TextureDimension::k3d);
EXPECT_FALSE(p->has_error());
}

View File

@ -23,7 +23,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) {
auto p = parser("{a : i32;}");
auto& builder = p->builder();
auto* i32 = builder.create<type::I32>();
auto* i32 = builder.create<sem::I32>();
auto m = p->expect_struct_body_decl();
ASSERT_FALSE(p->has_error());

View File

@ -38,8 +38,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_Sampler) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Sampler>());
ASSERT_FALSE(t->As<type::Sampler>()->IsComparison());
ASSERT_TRUE(t->Is<sem::Sampler>());
ASSERT_FALSE(t->As<sem::Sampler>()->IsComparison());
}
TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) {
@ -49,8 +49,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Sampler>());
ASSERT_TRUE(t->As<type::Sampler>()->IsComparison());
ASSERT_TRUE(t->Is<sem::Sampler>());
ASSERT_TRUE(t->As<sem::Sampler>()->IsComparison());
}
TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) {
@ -60,9 +60,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::DepthTexture>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k2d);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
@ -72,10 +72,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::SampledTexture>());
ASSERT_TRUE(t->As<type::SampledTexture>()->type()->Is<type::F32>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k1d);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::SampledTexture>());
ASSERT_TRUE(t->As<sem::SampledTexture>()->type()->Is<sem::F32>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k1d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
@ -85,10 +85,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::SampledTexture>());
ASSERT_TRUE(t->As<type::SampledTexture>()->type()->Is<type::I32>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k2d);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::SampledTexture>());
ASSERT_TRUE(t->As<sem::SampledTexture>()->type()->Is<sem::I32>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
@ -98,10 +98,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::SampledTexture>());
ASSERT_TRUE(t->As<type::SampledTexture>()->type()->Is<type::U32>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k3d);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::SampledTexture>());
ASSERT_TRUE(t->As<sem::SampledTexture>()->type()->Is<sem::U32>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k3d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) {
@ -151,10 +151,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) {
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::MultisampledTexture>());
ASSERT_TRUE(t->As<type::MultisampledTexture>()->type()->Is<type::I32>());
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k2d);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::MultisampledTexture>());
ASSERT_TRUE(t->As<sem::MultisampledTexture>()->type()->Is<sem::I32>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_Invalid) {
@ -205,11 +205,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::StorageTexture>());
EXPECT_EQ(t->As<type::StorageTexture>()->image_format(),
type::ImageFormat::kR8Unorm);
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k1d);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::StorageTexture>());
EXPECT_EQ(t->As<sem::StorageTexture>()->image_format(),
sem::ImageFormat::kR8Unorm);
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k1d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) {
@ -220,11 +220,11 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::StorageTexture>());
EXPECT_EQ(t->As<type::StorageTexture>()->image_format(),
type::ImageFormat::kR16Float);
EXPECT_EQ(t->As<type::Texture>()->dim(), type::TextureDimension::k2d);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::StorageTexture>());
EXPECT_EQ(t->As<sem::StorageTexture>()->image_format(),
sem::ImageFormat::kR16Float);
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) {

View File

@ -22,23 +22,23 @@ namespace {
TEST_F(ParserImplTest, TypeDecl_ParsesType) {
auto p = parser("type a = i32");
auto* i32 = p->builder().create<type::I32>();
auto* i32 = p->builder().create<sem::I32>();
auto t = p->type_alias();
EXPECT_FALSE(p->has_error());
EXPECT_FALSE(t.errored);
EXPECT_TRUE(t.matched);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Alias>());
auto* alias = t->As<type::Alias>();
ASSERT_TRUE(alias->type()->Is<type::I32>());
ASSERT_TRUE(t->Is<sem::Alias>());
auto* alias = t->As<sem::Alias>();
ASSERT_TRUE(alias->type()->Is<sem::I32>());
ASSERT_EQ(alias->type(), i32);
}
TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
auto p = parser("type a = B");
type::StructType str(p->builder().Symbols().Get("B"), {});
sem::StructType str(p->builder().Symbols().Get("B"), {});
p->register_constructed("B", &str);
auto t = p->type_alias();
@ -46,12 +46,12 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
EXPECT_FALSE(t.errored);
EXPECT_TRUE(t.matched);
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Alias>());
auto* alias = t->As<type::Alias>();
ASSERT_TRUE(t->Is<sem::Alias>());
auto* alias = t->As<sem::Alias>();
EXPECT_EQ(p->builder().Symbols().NameFor(alias->symbol()), "a");
ASSERT_TRUE(alias->type()->Is<type::StructType>());
ASSERT_TRUE(alias->type()->Is<sem::StructType>());
auto* s = alias->type()->As<type::StructType>();
auto* s = alias->type()->As<sem::StructType>();
EXPECT_EQ(s->symbol(), p->builder().Symbols().Get("B"));
EXPECT_EQ(s->symbol(), p->builder().Symbols().Get("B"));
}

View File

@ -34,9 +34,9 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
auto& builder = p->builder();
auto* int_type = builder.create<type::I32>();
auto* int_type = builder.create<sem::I32>();
auto* alias_type =
builder.create<type::Alias>(builder.Symbols().Register("A"), int_type);
builder.create<sem::Alias>(builder.Symbols().Register("A"), int_type);
p->register_constructed("A", alias_type);
@ -45,9 +45,9 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
EXPECT_EQ(t.value, alias_type);
ASSERT_TRUE(t->Is<type::Alias>());
ASSERT_TRUE(t->Is<sem::Alias>());
auto* alias = t->As<type::Alias>();
auto* alias = t->As<sem::Alias>();
EXPECT_EQ(p->builder().Symbols().NameFor(alias->symbol()), "A");
EXPECT_EQ(alias->type(), int_type);
}
@ -67,56 +67,56 @@ TEST_F(ParserImplTest, TypeDecl_Bool) {
auto p = parser("bool");
auto& builder = p->builder();
auto* bool_type = builder.create<type::Bool>();
auto* bool_type = builder.create<sem::Bool>();
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
EXPECT_EQ(t.value, bool_type);
ASSERT_TRUE(t->Is<type::Bool>());
ASSERT_TRUE(t->Is<sem::Bool>());
}
TEST_F(ParserImplTest, TypeDecl_F32) {
auto p = parser("f32");
auto& builder = p->builder();
auto* float_type = builder.create<type::F32>();
auto* float_type = builder.create<sem::F32>();
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
EXPECT_EQ(t.value, float_type);
ASSERT_TRUE(t->Is<type::F32>());
ASSERT_TRUE(t->Is<sem::F32>());
}
TEST_F(ParserImplTest, TypeDecl_I32) {
auto p = parser("i32");
auto& builder = p->builder();
auto* int_type = builder.create<type::I32>();
auto* int_type = builder.create<sem::I32>();
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
EXPECT_EQ(t.value, int_type);
ASSERT_TRUE(t->Is<type::I32>());
ASSERT_TRUE(t->Is<sem::I32>());
}
TEST_F(ParserImplTest, TypeDecl_U32) {
auto p = parser("u32");
auto& builder = p->builder();
auto* uint_type = builder.create<type::U32>();
auto* uint_type = builder.create<sem::U32>();
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
EXPECT_EQ(t.value, uint_type);
ASSERT_TRUE(t->Is<type::U32>());
ASSERT_TRUE(t->Is<sem::U32>());
}
struct VecData {
@ -138,8 +138,8 @@ TEST_P(VecTest, Parse) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
EXPECT_TRUE(t->Is<type::Vector>());
EXPECT_EQ(t->As<type::Vector>()->size(), params.count);
EXPECT_TRUE(t->Is<sem::Vector>());
EXPECT_EQ(t->As<sem::Vector>()->size(), params.count);
}
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
VecTest,
@ -226,10 +226,10 @@ TEST_F(ParserImplTest, TypeDecl_Ptr) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::Pointer>());
ASSERT_TRUE(t->Is<sem::Pointer>());
auto* ptr = t->As<type::Pointer>();
ASSERT_TRUE(ptr->type()->Is<type::F32>());
auto* ptr = t->As<sem::Pointer>();
ASSERT_TRUE(ptr->type()->Is<sem::F32>());
ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction);
}
@ -240,15 +240,15 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::Pointer>());
ASSERT_TRUE(t->Is<sem::Pointer>());
auto* ptr = t->As<type::Pointer>();
ASSERT_TRUE(ptr->type()->Is<type::Vector>());
auto* ptr = t->As<sem::Pointer>();
ASSERT_TRUE(ptr->type()->Is<sem::Vector>());
ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction);
auto* vec = ptr->type()->As<type::Vector>();
auto* vec = ptr->type()->As<sem::Vector>();
ASSERT_EQ(vec->size(), 2u);
ASSERT_TRUE(vec->type()->Is<type::F32>());
ASSERT_TRUE(vec->type()->Is<sem::F32>());
}
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingLessThan) {
@ -338,12 +338,12 @@ TEST_F(ParserImplTest, TypeDecl_Array) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::ArrayType>());
ASSERT_TRUE(t->Is<sem::ArrayType>());
auto* a = t->As<type::ArrayType>();
auto* a = t->As<sem::ArrayType>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_EQ(a->size(), 5u);
ASSERT_TRUE(a->type()->Is<type::F32>());
ASSERT_TRUE(a->type()->Is<sem::F32>());
EXPECT_EQ(a->decorations().size(), 0u);
}
@ -354,12 +354,12 @@ TEST_F(ParserImplTest, TypeDecl_Array_Stride) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::ArrayType>());
ASSERT_TRUE(t->Is<sem::ArrayType>());
auto* a = t->As<type::ArrayType>();
auto* a = t->As<sem::ArrayType>();
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_EQ(a->size(), 5u);
ASSERT_TRUE(a->type()->Is<type::F32>());
ASSERT_TRUE(a->type()->Is<sem::F32>());
ASSERT_EQ(a->decorations().size(), 1u);
auto* stride = a->decorations()[0];
@ -374,11 +374,11 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Stride) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::ArrayType>());
ASSERT_TRUE(t->Is<sem::ArrayType>());
auto* a = t->As<type::ArrayType>();
auto* a = t->As<sem::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->Is<type::F32>());
ASSERT_TRUE(a->type()->Is<sem::F32>());
ASSERT_EQ(a->decorations().size(), 1u);
auto* stride = a->decorations()[0];
@ -393,11 +393,11 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_OneBlock) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::ArrayType>());
ASSERT_TRUE(t->Is<sem::ArrayType>());
auto* a = t->As<type::ArrayType>();
auto* a = t->As<sem::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->Is<type::F32>());
ASSERT_TRUE(a->type()->Is<sem::F32>());
auto& decos = a->decorations();
ASSERT_EQ(decos.size(), 2u);
@ -414,11 +414,11 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::ArrayType>());
ASSERT_TRUE(t->Is<sem::ArrayType>());
auto* a = t->As<type::ArrayType>();
auto* a = t->As<sem::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->Is<type::F32>());
ASSERT_TRUE(a->type()->Is<sem::F32>());
auto& decos = a->decorations();
ASSERT_EQ(decos.size(), 2u);
@ -517,11 +517,11 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::ArrayType>());
ASSERT_TRUE(t->Is<sem::ArrayType>());
auto* a = t->As<type::ArrayType>();
auto* a = t->As<sem::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->Is<type::U32>());
ASSERT_TRUE(a->type()->Is<sem::U32>());
}
TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Vec) {
@ -531,9 +531,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Vec) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
ASSERT_TRUE(t->Is<type::ArrayType>());
ASSERT_TRUE(t->Is<sem::ArrayType>());
auto* a = t->As<type::ArrayType>();
auto* a = t->As<sem::ArrayType>();
ASSERT_TRUE(a->IsRuntimeArray());
ASSERT_TRUE(a->type()->is_unsigned_integer_vector());
}
@ -628,8 +628,8 @@ TEST_P(MatrixTest, Parse) {
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error());
EXPECT_TRUE(t->Is<type::Matrix>());
auto* mat = t->As<type::Matrix>();
EXPECT_TRUE(t->Is<sem::Matrix>());
auto* mat = t->As<sem::Matrix>();
EXPECT_EQ(mat->rows(), params.rows);
EXPECT_EQ(mat->columns(), params.columns);
}
@ -746,32 +746,32 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) {
auto p = parser("sampler");
auto& builder = p->builder();
auto* type = builder.create<type::Sampler>(type::SamplerKind::kSampler);
auto* type = builder.create<sem::Sampler>(sem::SamplerKind::kSampler);
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error();
EXPECT_EQ(t.value, type);
ASSERT_TRUE(t->Is<type::Sampler>());
ASSERT_FALSE(t->As<type::Sampler>()->IsComparison());
ASSERT_TRUE(t->Is<sem::Sampler>());
ASSERT_FALSE(t->As<sem::Sampler>()->IsComparison());
}
TEST_F(ParserImplTest, TypeDecl_Texture) {
auto p = parser("texture_cube<f32>");
auto& builder = p->builder();
auto* type = builder.create<type::SampledTexture>(
type::TextureDimension::kCube, ty.f32());
auto* type = builder.create<sem::SampledTexture>(sem::TextureDimension::kCube,
ty.f32());
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr);
EXPECT_EQ(t.value, type);
ASSERT_TRUE(t->Is<type::Texture>());
ASSERT_TRUE(t->Is<type::SampledTexture>());
ASSERT_TRUE(t->As<type::SampledTexture>()->type()->Is<type::F32>());
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::SampledTexture>());
ASSERT_TRUE(t->As<sem::SampledTexture>()->type()->Is<sem::F32>());
}
} // namespace

View File

@ -27,7 +27,7 @@ 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<type::F32>());
EXPECT_TRUE(v->type->Is<sem::F32>());
EXPECT_EQ(v->source.range.begin.line, 1u);
EXPECT_EQ(v->source.range.begin.column, 5u);
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, VariableDecl_WithStorageClass) {
EXPECT_FALSE(v.errored);
EXPECT_FALSE(p->has_error());
EXPECT_EQ(v->name, "my_var");
EXPECT_TRUE(v->type->Is<type::F32>());
EXPECT_TRUE(v->type->Is<sem::F32>());
EXPECT_EQ(v->storage_class, ast::StorageClass::kPrivate);
EXPECT_EQ(v->source.range.begin.line, 1u);

View File

@ -28,7 +28,7 @@ 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<type::F32>());
ASSERT_TRUE(decl->type->Is<sem::F32>());
ASSERT_EQ(decl->source.range.begin.line, 1u);
ASSERT_EQ(decl->source.range.begin.column, 1u);
@ -84,11 +84,10 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithTextureAccessDeco_Read) {
ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr);
ASSERT_TRUE(decl->type->Is<type::AccessControl>());
EXPECT_TRUE(decl->type->As<type::AccessControl>()->IsReadOnly());
ASSERT_TRUE(decl->type->As<type::AccessControl>()
->type()
->Is<type::StorageTexture>());
ASSERT_TRUE(decl->type->Is<sem::AccessControl>());
EXPECT_TRUE(decl->type->As<sem::AccessControl>()->IsReadOnly());
ASSERT_TRUE(
decl->type->As<sem::AccessControl>()->type()->Is<sem::StorageTexture>());
}
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithTextureAccessDeco_Write) {
@ -99,11 +98,10 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithTextureAccessDeco_Write) {
ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr);
ASSERT_TRUE(decl->type->Is<type::AccessControl>());
EXPECT_TRUE(decl->type->As<type::AccessControl>()->IsWriteOnly());
ASSERT_TRUE(decl->type->As<type::AccessControl>()
->type()
->Is<type::StorageTexture>());
ASSERT_TRUE(decl->type->Is<sem::AccessControl>());
EXPECT_TRUE(decl->type->As<sem::AccessControl>()->IsWriteOnly());
ASSERT_TRUE(
decl->type->As<sem::AccessControl>()->type()->Is<sem::StorageTexture>());
}
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
@ -127,8 +125,8 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr);
ASSERT_TRUE(decl->type->Is<type::AccessControl>());
EXPECT_TRUE(decl->type->As<type::AccessControl>()->IsReadOnly());
ASSERT_TRUE(decl->type->Is<sem::AccessControl>());
EXPECT_TRUE(decl->type->As<sem::AccessControl>()->IsReadOnly());
}
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
@ -152,8 +150,8 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr);
ASSERT_TRUE(decl->type->Is<type::AccessControl>());
EXPECT_TRUE(decl->type->As<type::AccessControl>()->IsReadWrite());
ASSERT_TRUE(decl->type->Is<sem::AccessControl>());
EXPECT_TRUE(decl->type->As<sem::AccessControl>()->IsReadWrite());
}
TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {

View File

@ -255,12 +255,11 @@ TEST_F(ResolverAssignmentValidationTest, AssignFromPointer_Fail) {
// var b : [[access(read)]] texture_storage_1d<rgba8unorm>;
// a = b;
auto* tex_type = create<type::StorageTexture>(
type::TextureDimension::k1d, type::ImageFormat::kRgba8Unorm,
type::StorageTexture::SubtypeFor(type::ImageFormat::kRgba8Unorm,
Types()));
auto* tex_type = create<sem::StorageTexture>(
sem::TextureDimension::k1d, sem::ImageFormat::kRgba8Unorm,
sem::StorageTexture::SubtypeFor(sem::ImageFormat::kRgba8Unorm, Types()));
auto* tex_ac =
create<type::AccessControl>(ast::AccessControl::kReadOnly, tex_type);
create<sem::AccessControl>(ast::AccessControl::kReadOnly, tex_type);
auto* var_a = Var("a", tex_ac, ast::StorageClass::kFunction);
auto* var_b = Var("b", tex_ac, ast::StorageClass::kFunction);

View File

@ -113,50 +113,50 @@ TEST_F(ResolverBuiltinsValidationTest, Frexp_Scalar) {
WrapInFunction(Decl(a), builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->Is<type::F32>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(builtin)->Is<sem::F32>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<sem::Pointer>());
}
TEST_F(ResolverBuiltinsValidationTest, Frexp_Vec2) {
auto* a = Var("a", ty.vec2<int>(), ast::StorageClass::kFunction);
auto* b = Const("b",
create<type::Pointer>(create<type::Vector>(ty.i32(), 2),
ast::StorageClass::kFunction),
create<sem::Pointer>(create<sem::Vector>(ty.i32(), 2),
ast::StorageClass::kFunction),
Expr("a"), {});
auto* builtin = Call("frexp", vec2<float>(1.0f, 1.0f), Expr("b"));
WrapInFunction(Decl(a), Decl(b), builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->is_float_vector());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<sem::Pointer>());
}
TEST_F(ResolverBuiltinsValidationTest, Frexp_Vec3) {
auto* a = Var("a", ty.vec3<int>(), ast::StorageClass::kFunction);
auto* b = Const("b",
create<type::Pointer>(create<type::Vector>(ty.i32(), 3),
ast::StorageClass::kFunction),
create<sem::Pointer>(create<sem::Vector>(ty.i32(), 3),
ast::StorageClass::kFunction),
Expr("a"), {});
auto* builtin = Call("frexp", vec3<float>(1.0f, 1.0f, 1.0f), Expr("b"));
WrapInFunction(Decl(a), Decl(b), builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->is_float_vector());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<sem::Pointer>());
}
TEST_F(ResolverBuiltinsValidationTest, Frexp_Vec4) {
auto* a = Var("a", ty.vec4<int>(), ast::StorageClass::kFunction);
auto* b = Const("b",
create<type::Pointer>(create<type::Vector>(ty.i32(), 4),
ast::StorageClass::kFunction),
create<sem::Pointer>(create<sem::Vector>(ty.i32(), 4),
ast::StorageClass::kFunction),
Expr("a"), {});
auto* builtin = Call("frexp", vec4<float>(1.0f, 1.0f, 1.0f, 1.0f), Expr("b"));
WrapInFunction(Decl(a), Decl(b), builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->is_float_vector());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<sem::Pointer>());
}
TEST_F(ResolverBuiltinsValidationTest, Modf_Scalar) {
@ -167,50 +167,50 @@ TEST_F(ResolverBuiltinsValidationTest, Modf_Scalar) {
WrapInFunction(Decl(a), Decl(b), builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->Is<type::F32>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(builtin)->Is<sem::F32>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<sem::Pointer>());
}
TEST_F(ResolverBuiltinsValidationTest, Modf_Vec2) {
auto* a = Var("a", ty.vec2<float>(), ast::StorageClass::kFunction);
auto* b = Const("b",
create<type::Pointer>(create<type::Vector>(ty.f32(), 2),
ast::StorageClass::kFunction),
create<sem::Pointer>(create<sem::Vector>(ty.f32(), 2),
ast::StorageClass::kFunction),
Expr("a"), {});
auto* builtin = Call("modf", vec2<float>(1.0f, 1.0f), Expr("b"));
WrapInFunction(Decl(a), Decl(b), builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->is_float_vector());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<sem::Pointer>());
}
TEST_F(ResolverBuiltinsValidationTest, Modf_Vec3) {
auto* a = Var("a", ty.vec3<float>(), ast::StorageClass::kFunction);
auto* b = Const("b",
create<type::Pointer>(create<type::Vector>(ty.f32(), 3),
ast::StorageClass::kFunction),
create<sem::Pointer>(create<sem::Vector>(ty.f32(), 3),
ast::StorageClass::kFunction),
Expr("a"), {});
auto* builtin = Call("modf", vec3<float>(1.0f, 1.0f, 1.0f), Expr("b"));
WrapInFunction(Decl(a), Decl(b), builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->is_float_vector());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<sem::Pointer>());
}
TEST_F(ResolverBuiltinsValidationTest, Modf_Vec4) {
auto* a = Var("a", ty.vec4<float>(), ast::StorageClass::kFunction);
auto* b = Const("b",
create<type::Pointer>(create<type::Vector>(ty.f32(), 4),
ast::StorageClass::kFunction),
create<sem::Pointer>(create<sem::Vector>(ty.f32(), 4),
ast::StorageClass::kFunction),
Expr("a"), {});
auto* builtin = Call("modf", vec4<float>(1.0f, 1.0f, 1.0f, 1.0f), Expr("b"));
WrapInFunction(Decl(a), Decl(b), builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->is_float_vector());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(builtin->params()[1])->Is<sem::Pointer>());
}
TEST_F(ResolverBuiltinsValidationTest, Cross_Float_Vec3) {
@ -309,7 +309,7 @@ TEST_P(FloatAllMatching, Scalar) {
WrapInFunction(builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->Is<type::F32>());
EXPECT_TRUE(TypeOf(builtin)->Is<sem::F32>());
}
TEST_P(FloatAllMatching, Vec2) {
@ -417,7 +417,7 @@ TEST_P(IntegerAllMatching, ScalarUnsigned) {
WrapInFunction(builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->Is<type::U32>());
EXPECT_TRUE(TypeOf(builtin)->Is<sem::U32>());
}
TEST_P(IntegerAllMatching, Vec2Unsigned) {
@ -477,7 +477,7 @@ TEST_P(IntegerAllMatching, ScalarSigned) {
WrapInFunction(builtin);
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_TRUE(TypeOf(builtin)->Is<type::I32>());
EXPECT_TRUE(TypeOf(builtin)->Is<sem::I32>());
}
TEST_P(IntegerAllMatching, Vec2Signed) {

View File

@ -127,10 +127,9 @@ TEST_P(ArrayDecorationTest, IsValid) {
auto& params = GetParam();
ast::StructMemberList members{Member(
"a",
create<type::ArrayType>(ty.f32(), 0,
ast::DecorationList{createDecoration(
Source{{12, 34}}, *this, params.kind)}))};
"a", create<sem::ArrayType>(ty.f32(), 0,
ast::DecorationList{createDecoration(
Source{{12, 34}}, *this, params.kind)}))};
auto* s = create<ast::Struct>(
members, ast::DecorationList{create<ast::StructBlockDecoration>()});
auto* s_ty = ty.struct_("mystruct", s);
@ -334,10 +333,10 @@ TEST_P(ArrayStrideTest, All) {
SCOPED_TRACE(ss.str());
auto* arr =
create<type::ArrayType>(el_ty, 4,
ast::DecorationList{
create<ast::StrideDecoration>(params.stride),
});
create<sem::ArrayType>(el_ty, 4,
ast::DecorationList{
create<ast::StrideDecoration>(params.stride),
});
Global(Source{{12, 34}}, "myarray", arr, ast::StorageClass::kInput);
@ -422,11 +421,11 @@ INSTANTIATE_TEST_SUITE_P(
Params{ty_mat4x4<f32>, (default_mat4x4.align - 1) * 7, false}));
TEST_F(ArrayStrideTest, MultipleDecorations) {
auto* arr = create<type::ArrayType>(ty.i32(), 4,
ast::DecorationList{
create<ast::StrideDecoration>(4),
create<ast::StrideDecoration>(4),
});
auto* arr = create<sem::ArrayType>(ty.i32(), 4,
ast::DecorationList{
create<ast::StrideDecoration>(4),
create<ast::StrideDecoration>(4),
});
Global(Source{{12, 34}}, "myarray", arr, ast::StorageClass::kInput);

View File

@ -61,7 +61,7 @@ TEST_P(ResolverIntrinsicDerivativeTest, Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<type::F32>());
ASSERT_TRUE(TypeOf(expr)->Is<sem::F32>());
}
TEST_P(ResolverIntrinsicDerivativeTest, Vector) {
@ -74,9 +74,9 @@ TEST_P(ResolverIntrinsicDerivativeTest, Vector) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(expr)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(expr)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 4u);
}
TEST_P(ResolverIntrinsicDerivativeTest, MissingParam) {
@ -118,7 +118,7 @@ TEST_P(ResolverIntrinsic, Test) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::Bool>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::Bool>());
}
INSTANTIATE_TEST_SUITE_P(ResolverTest,
ResolverIntrinsic,
@ -136,9 +136,9 @@ TEST_P(ResolverIntrinsicTest_FloatMethod, Vector) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::Bool>());
EXPECT_EQ(TypeOf(expr)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(expr)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_FloatMethod, Scalar) {
@ -152,7 +152,7 @@ TEST_P(ResolverIntrinsicTest_FloatMethod, Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::Bool>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::Bool>());
}
TEST_P(ResolverIntrinsicTest_FloatMethod, MissingParam) {
@ -206,9 +206,9 @@ inline std::ostream& operator<<(std::ostream& out, Texture data) {
}
struct TextureTestParams {
type::TextureDimension dim;
sem::TextureDimension dim;
Texture type = Texture::kF32;
type::ImageFormat format = type::ImageFormat::kR16Float;
sem::ImageFormat format = sem::ImageFormat::kR16Float;
};
inline std::ostream& operator<<(std::ostream& out, TextureTestParams data) {
out << data.dim << "_" << data.type;
@ -223,17 +223,17 @@ class ResolverIntrinsicTest_TextureOperation
/// @param dim dimensionality of the texture being sampled
/// @param scalar the scalar type
/// @returns a pointer to a type appropriate for the coord param
type::Type* GetCoordsType(type::TextureDimension dim, type::Type* scalar) {
sem::Type* GetCoordsType(sem::TextureDimension dim, sem::Type* scalar) {
switch (dim) {
case type::TextureDimension::k1d:
case sem::TextureDimension::k1d:
return scalar;
case type::TextureDimension::k2d:
case type::TextureDimension::k2dArray:
return create<type::Vector>(scalar, 2);
case type::TextureDimension::k3d:
case type::TextureDimension::kCube:
case type::TextureDimension::kCubeArray:
return create<type::Vector>(scalar, 3);
case sem::TextureDimension::k2d:
case sem::TextureDimension::k2dArray:
return create<sem::Vector>(scalar, 2);
case sem::TextureDimension::k3d:
case sem::TextureDimension::kCube:
case sem::TextureDimension::kCubeArray:
return create<sem::Vector>(scalar, 3);
default:
[=]() { FAIL() << "Unsupported texture dimension: " << dim; }();
}
@ -241,19 +241,19 @@ class ResolverIntrinsicTest_TextureOperation
}
void add_call_param(std::string name,
type::Type* type,
sem::Type* type,
ast::ExpressionList* call_params) {
Global(name, type, ast::StorageClass::kInput);
call_params->push_back(Expr(name));
}
type::Type* subtype(Texture type) {
sem::Type* subtype(Texture type) {
if (type == Texture::kF32) {
return create<type::F32>();
return create<sem::F32>();
}
if (type == Texture::kI32) {
return create<type::I32>();
return create<sem::I32>();
}
return create<type::U32>();
return create<sem::U32>();
}
};
@ -266,17 +266,17 @@ TEST_P(ResolverIntrinsicTest_StorageTextureOperation, TextureLoadRo) {
auto* coords_type = GetCoordsType(dim, ty.i32());
auto* subtype = type::StorageTexture::SubtypeFor(format, Types());
auto* texture_type = create<type::StorageTexture>(dim, format, subtype);
auto* subtype = sem::StorageTexture::SubtypeFor(format, Types());
auto* texture_type = create<sem::StorageTexture>(dim, format, subtype);
auto* ro_texture_type =
create<type::AccessControl>(ast::AccessControl::kReadOnly, texture_type);
create<sem::AccessControl>(ast::AccessControl::kReadOnly, texture_type);
ast::ExpressionList call_params;
add_call_param("texture", ro_texture_type, &call_params);
add_call_param("coords", coords_type, &call_params);
if (type::IsTextureArray(dim)) {
if (sem::IsTextureArray(dim)) {
add_call_param("array_index", ty.i32(), &call_params);
}
@ -286,45 +286,45 @@ TEST_P(ResolverIntrinsicTest_StorageTextureOperation, TextureLoadRo) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<type::Vector>());
ASSERT_TRUE(TypeOf(expr)->Is<sem::Vector>());
if (type == Texture::kF32) {
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::F32>());
} else if (type == Texture::kI32) {
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::I32>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::I32>());
} else {
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::U32>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::U32>());
}
EXPECT_EQ(TypeOf(expr)->As<type::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 4u);
}
INSTANTIATE_TEST_SUITE_P(
ResolverTest,
ResolverIntrinsicTest_StorageTextureOperation,
testing::Values(
TextureTestParams{type::TextureDimension::k1d, Texture::kF32,
type::ImageFormat::kR16Float},
TextureTestParams{type::TextureDimension::k1d, Texture::kI32,
type::ImageFormat::kR16Sint},
TextureTestParams{type::TextureDimension::k1d, Texture::kF32,
type::ImageFormat::kR8Unorm},
TextureTestParams{type::TextureDimension::k2d, Texture::kF32,
type::ImageFormat::kR16Float},
TextureTestParams{type::TextureDimension::k2d, Texture::kI32,
type::ImageFormat::kR16Sint},
TextureTestParams{type::TextureDimension::k2d, Texture::kF32,
type::ImageFormat::kR8Unorm},
TextureTestParams{type::TextureDimension::k2dArray, Texture::kF32,
type::ImageFormat::kR16Float},
TextureTestParams{type::TextureDimension::k2dArray, Texture::kI32,
type::ImageFormat::kR16Sint},
TextureTestParams{type::TextureDimension::k2dArray, Texture::kF32,
type::ImageFormat::kR8Unorm},
TextureTestParams{type::TextureDimension::k3d, Texture::kF32,
type::ImageFormat::kR16Float},
TextureTestParams{type::TextureDimension::k3d, Texture::kI32,
type::ImageFormat::kR16Sint},
TextureTestParams{type::TextureDimension::k3d, Texture::kF32,
type::ImageFormat::kR8Unorm}));
TextureTestParams{sem::TextureDimension::k1d, Texture::kF32,
sem::ImageFormat::kR16Float},
TextureTestParams{sem::TextureDimension::k1d, Texture::kI32,
sem::ImageFormat::kR16Sint},
TextureTestParams{sem::TextureDimension::k1d, Texture::kF32,
sem::ImageFormat::kR8Unorm},
TextureTestParams{sem::TextureDimension::k2d, Texture::kF32,
sem::ImageFormat::kR16Float},
TextureTestParams{sem::TextureDimension::k2d, Texture::kI32,
sem::ImageFormat::kR16Sint},
TextureTestParams{sem::TextureDimension::k2d, Texture::kF32,
sem::ImageFormat::kR8Unorm},
TextureTestParams{sem::TextureDimension::k2dArray, Texture::kF32,
sem::ImageFormat::kR16Float},
TextureTestParams{sem::TextureDimension::k2dArray, Texture::kI32,
sem::ImageFormat::kR16Sint},
TextureTestParams{sem::TextureDimension::k2dArray, Texture::kF32,
sem::ImageFormat::kR8Unorm},
TextureTestParams{sem::TextureDimension::k3d, Texture::kF32,
sem::ImageFormat::kR16Float},
TextureTestParams{sem::TextureDimension::k3d, Texture::kI32,
sem::ImageFormat::kR16Sint},
TextureTestParams{sem::TextureDimension::k3d, Texture::kF32,
sem::ImageFormat::kR8Unorm}));
using ResolverIntrinsicTest_SampledTextureOperation =
ResolverIntrinsicTest_TextureOperation;
@ -332,15 +332,15 @@ TEST_P(ResolverIntrinsicTest_SampledTextureOperation, TextureLoadSampled) {
auto dim = GetParam().dim;
auto type = GetParam().type;
type::Type* s = subtype(type);
sem::Type* s = subtype(type);
auto* coords_type = GetCoordsType(dim, ty.i32());
auto* texture_type = create<type::SampledTexture>(dim, s);
auto* texture_type = create<sem::SampledTexture>(dim, s);
ast::ExpressionList call_params;
add_call_param("texture", texture_type, &call_params);
add_call_param("coords", coords_type, &call_params);
if (dim == type::TextureDimension::k2dArray) {
if (dim == sem::TextureDimension::k2dArray) {
add_call_param("array_index", ty.i32(), &call_params);
}
add_call_param("level", ty.i32(), &call_params);
@ -351,24 +351,24 @@ TEST_P(ResolverIntrinsicTest_SampledTextureOperation, TextureLoadSampled) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
ASSERT_TRUE(TypeOf(expr)->Is<type::Vector>());
ASSERT_TRUE(TypeOf(expr)->Is<sem::Vector>());
if (type == Texture::kF32) {
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::F32>());
} else if (type == Texture::kI32) {
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::I32>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::I32>());
} else {
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::U32>());
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::U32>());
}
EXPECT_EQ(TypeOf(expr)->As<type::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 4u);
}
INSTANTIATE_TEST_SUITE_P(
ResolverTest,
ResolverIntrinsicTest_SampledTextureOperation,
testing::Values(TextureTestParams{type::TextureDimension::k1d},
TextureTestParams{type::TextureDimension::k2d},
TextureTestParams{type::TextureDimension::k2dArray},
TextureTestParams{type::TextureDimension::k3d}));
testing::Values(TextureTestParams{sem::TextureDimension::k1d},
TextureTestParams{sem::TextureDimension::k2d},
TextureTestParams{sem::TextureDimension::k2dArray},
TextureTestParams{sem::TextureDimension::k3d}));
TEST_F(ResolverIntrinsicTest, Dot_Vec2) {
Global("my_var", ty.vec2<f32>(), ast::StorageClass::kInput);
@ -379,7 +379,7 @@ TEST_F(ResolverIntrinsicTest, Dot_Vec2) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicTest, Dot_Vec3) {
@ -391,7 +391,7 @@ TEST_F(ResolverIntrinsicTest, Dot_Vec3) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicTest, Dot_Vec4) {
@ -403,7 +403,7 @@ TEST_F(ResolverIntrinsicTest, Dot_Vec4) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicTest, Dot_Error_Scalar) {
@ -448,9 +448,9 @@ TEST_F(ResolverIntrinsicTest, Select) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::Vector>());
EXPECT_EQ(TypeOf(expr)->As<type::Vector>()->size(), 3u);
EXPECT_TRUE(TypeOf(expr)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::Vector>());
EXPECT_EQ(TypeOf(expr)->As<sem::Vector>()->size(), 3u);
EXPECT_TRUE(TypeOf(expr)->As<sem::Vector>()->type()->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicTest, Select_Error_NoParams) {
@ -550,7 +550,7 @@ TEST_P(ResolverIntrinsicTest_Barrier, InferType) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::Void>());
EXPECT_TRUE(TypeOf(call)->Is<sem::Void>());
}
TEST_P(ResolverIntrinsicTest_Barrier, Error_TooManyParams) {
@ -585,7 +585,7 @@ TEST_P(ResolverIntrinsicTest_DataPacking, InferType) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::U32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::U32>());
}
TEST_P(ResolverIntrinsicTest_DataPacking, Error_IncorrectParamType) {
@ -657,9 +657,9 @@ TEST_P(ResolverIntrinsicTest_DataUnpacking, InferType) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
if (pack4) {
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 4u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 4u);
} else {
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 2u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 2u);
}
}
@ -696,7 +696,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam, Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_SingleParam, Error_NoParams) {
@ -771,7 +771,7 @@ TEST_F(ResolverIntrinsicDataTest, ArrayLength_Vector) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::U32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::U32>());
}
TEST_F(ResolverIntrinsicDataTest, ArrayLength_Error_ArraySized) {
@ -795,7 +795,7 @@ TEST_F(ResolverIntrinsicDataTest, Normalize_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverIntrinsicDataTest, Normalize_Error_NoParams) {
@ -818,7 +818,7 @@ TEST_F(ResolverIntrinsicDataTest, FrexpScalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicDataTest, FrexpVector) {
@ -829,8 +829,8 @@ TEST_F(ResolverIntrinsicDataTest, FrexpVector) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(call)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(call)->As<sem::Vector>()->type()->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicDataTest, Frexp_Error_FirstParamInt) {
@ -901,7 +901,7 @@ TEST_F(ResolverIntrinsicDataTest, ModfScalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicDataTest, ModfVector) {
@ -912,8 +912,8 @@ TEST_F(ResolverIntrinsicDataTest, ModfVector) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(call)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(call)->As<sem::Vector>()->type()->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicDataTest, Modf_Error_FirstParamInt) {
@ -996,7 +996,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Float_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Sint_Scalar) {
@ -1008,7 +1008,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Sint_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::I32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::I32>());
}
TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Sint_Vector) {
@ -1021,7 +1021,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Sint_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_signed_integer_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Uint_Scalar) {
@ -1033,7 +1033,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Uint_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::U32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::U32>());
}
TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Uint_Vector) {
@ -1046,7 +1046,7 @@ TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Uint_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_unsigned_integer_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_SingleParam_FloatOrInt, Error_NoParams) {
@ -1116,7 +1116,7 @@ TEST_P(ResolverIntrinsicTest_TwoParam, Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_TwoParam, Error_NoTooManyParams) {
@ -1179,7 +1179,7 @@ TEST_F(ResolverIntrinsicTest, Distance_Vector) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicTest, Cross) {
@ -1191,7 +1191,7 @@ TEST_F(ResolverIntrinsicTest, Cross) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverIntrinsicTest, Cross_Error_NoArgs) {
@ -1273,7 +1273,7 @@ TEST_F(ResolverIntrinsicTest, Normalize) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverIntrinsicTest, Normalize_NoArgs) {
@ -1313,7 +1313,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam, Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_ThreeParam, Error_NoParams) {
auto param = GetParam();
@ -1365,7 +1365,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Float_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Sint_Scalar) {
@ -1377,7 +1377,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Sint_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::I32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::I32>());
}
TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Sint_Vector) {
@ -1391,7 +1391,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Sint_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_signed_integer_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Uint_Scalar) {
@ -1403,7 +1403,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Uint_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::U32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::U32>());
}
TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Uint_Vector) {
@ -1417,7 +1417,7 @@ TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Uint_Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_unsigned_integer_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_ThreeParam_FloatOrInt, Error_NoParams) {
@ -1468,7 +1468,7 @@ TEST_P(ResolverIntrinsicTest_Int_SingleParam, Vector) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_signed_integer_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_Int_SingleParam, Error_NoParams) {
@ -1506,7 +1506,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Scalar_Signed) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::I32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::I32>());
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Scalar_Unsigned) {
@ -1518,7 +1518,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Scalar_Unsigned) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::U32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::U32>());
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Scalar_Float) {
@ -1530,7 +1530,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Scalar_Float) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Signed) {
@ -1543,7 +1543,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Signed) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_signed_integer_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Unsigned) {
@ -1556,7 +1556,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Unsigned) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_unsigned_integer_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Float) {
@ -1570,7 +1570,7 @@ TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Vector_Float) {
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->is_float_vector());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->size(), 3u);
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->size(), 3u);
}
TEST_P(ResolverIntrinsicTest_FloatOrInt_TwoParam, Error_NoParams) {
@ -1606,7 +1606,7 @@ TEST_F(ResolverIntrinsicTest, Determinant_2x2) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicTest, Determinant_3x3) {
@ -1618,7 +1618,7 @@ TEST_F(ResolverIntrinsicTest, Determinant_3x3) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicTest, Determinant_4x4) {
@ -1630,7 +1630,7 @@ TEST_F(ResolverIntrinsicTest, Determinant_4x4) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverIntrinsicTest, Determinant_NotSquare) {
@ -1933,16 +1933,16 @@ TEST_P(ResolverIntrinsicTest_Texture, Call) {
switch (param.texture_dimension) {
default:
FAIL() << "invalid texture dimensions: " << param.texture_dimension;
case type::TextureDimension::k1d:
case sem::TextureDimension::k1d:
EXPECT_EQ(TypeOf(call)->type_name(), ty.i32()->type_name());
break;
case type::TextureDimension::k2d:
case type::TextureDimension::k2dArray:
case sem::TextureDimension::k2d:
case sem::TextureDimension::k2dArray:
EXPECT_EQ(TypeOf(call)->type_name(), ty.vec2<i32>()->type_name());
break;
case type::TextureDimension::k3d:
case type::TextureDimension::kCube:
case type::TextureDimension::kCubeArray:
case sem::TextureDimension::k3d:
case sem::TextureDimension::kCube:
case sem::TextureDimension::kCubeArray:
EXPECT_EQ(TypeOf(call)->type_name(), ty.vec3<i32>()->type_name());
break;
}
@ -1960,8 +1960,8 @@ TEST_P(ResolverIntrinsicTest_Texture, Call) {
case ast::intrinsic::test::TextureKind::kMultisampled:
case ast::intrinsic::test::TextureKind::kStorage: {
auto* datatype = param.resultVectorComponentType(this);
ASSERT_TRUE(TypeOf(call)->Is<type::Vector>());
EXPECT_EQ(TypeOf(call)->As<type::Vector>()->type(), datatype);
ASSERT_TRUE(TypeOf(call)->Is<sem::Vector>());
EXPECT_EQ(TypeOf(call)->As<sem::Vector>()->type(), datatype);
break;
}
case ast::intrinsic::test::TextureKind::kDepth: {

View File

@ -89,12 +89,12 @@ TEST_F(ResolverIsHostShareable, AliasI32) {
TEST_F(ResolverIsHostShareable, AccessControlVoid) {
EXPECT_FALSE(r()->IsHostShareable(
create<type::AccessControl>(ast::AccessControl::kReadOnly, ty.void_())));
create<sem::AccessControl>(ast::AccessControl::kReadOnly, ty.void_())));
}
TEST_F(ResolverIsHostShareable, AccessControlI32) {
EXPECT_TRUE(r()->IsHostShareable(
create<type::AccessControl>(ast::AccessControl::kReadOnly, ty.i32())));
create<sem::AccessControl>(ast::AccessControl::kReadOnly, ty.i32())));
}
TEST_F(ResolverIsHostShareable, ArraySizedOfHostShareable) {

View File

@ -73,12 +73,12 @@ TEST_F(ResolverIsStorableTest, AliasI32) {
TEST_F(ResolverIsStorableTest, AccessControlVoid) {
EXPECT_FALSE(r()->IsStorable(
create<type::AccessControl>(ast::AccessControl::kReadOnly, ty.void_())));
create<sem::AccessControl>(ast::AccessControl::kReadOnly, ty.void_())));
}
TEST_F(ResolverIsStorableTest, AccessControlI32) {
EXPECT_TRUE(r()->IsStorable(
create<type::AccessControl>(ast::AccessControl::kReadOnly, ty.i32())));
create<sem::AccessControl>(ast::AccessControl::kReadOnly, ty.i32())));
}
TEST_F(ResolverIsStorableTest, ArraySizedOfStorable) {

View File

@ -117,16 +117,15 @@ bool Resolver::Resolve() {
}
// https://gpuweb.github.io/gpuweb/wgsl.html#storable-types
bool Resolver::IsStorable(type::Type* type) {
bool Resolver::IsStorable(sem::Type* type) {
type = type->UnwrapIfNeeded();
if (type->is_scalar() || type->Is<type::Vector>() ||
type->Is<type::Matrix>()) {
if (type->is_scalar() || type->Is<sem::Vector>() || type->Is<sem::Matrix>()) {
return true;
}
if (type::ArrayType* arr = type->As<type::ArrayType>()) {
if (sem::ArrayType* arr = type->As<sem::ArrayType>()) {
return IsStorable(arr->type());
}
if (type::StructType* str = type->As<type::StructType>()) {
if (sem::StructType* str = type->As<sem::StructType>()) {
for (const auto* member : str->impl()->members()) {
if (!IsStorable(member->type())) {
return false;
@ -138,21 +137,21 @@ bool Resolver::IsStorable(type::Type* type) {
}
// https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable-types
bool Resolver::IsHostShareable(type::Type* type) {
bool Resolver::IsHostShareable(sem::Type* type) {
type = type->UnwrapIfNeeded();
if (type->IsAnyOf<type::I32, type::U32, type::F32>()) {
if (type->IsAnyOf<sem::I32, sem::U32, sem::F32>()) {
return true;
}
if (auto* vec = type->As<type::Vector>()) {
if (auto* vec = type->As<sem::Vector>()) {
return IsHostShareable(vec->type());
}
if (auto* mat = type->As<type::Matrix>()) {
if (auto* mat = type->As<sem::Matrix>()) {
return IsHostShareable(mat->type());
}
if (auto* arr = type->As<type::ArrayType>()) {
if (auto* arr = type->As<sem::ArrayType>()) {
return IsHostShareable(arr->type());
}
if (auto* str = type->As<type::StructType>()) {
if (auto* str = type->As<sem::StructType>()) {
for (auto* member : str->impl()->members()) {
if (!IsHostShareable(member->type())) {
return false;
@ -163,7 +162,7 @@ bool Resolver::IsHostShareable(type::Type* type) {
return false;
}
bool Resolver::IsValidAssignment(type::Type* lhs, type::Type* rhs) {
bool Resolver::IsValidAssignment(sem::Type* lhs, sem::Type* rhs) {
// TODO(crbug.com/tint/659): This is a rough approximation, and is missing
// checks for writability of pointer storage class, access control, etc.
// This will need to be fixed after WGSL agrees the behavior of pointers /
@ -184,7 +183,7 @@ bool Resolver::ResolveInternal() {
// Process everything else in the order they appear in the module. This is
// necessary for validation of use-before-declaration.
for (auto* decl : builder_->AST().GlobalDeclarations()) {
if (auto* ty = decl->As<type::Type>()) {
if (auto* ty = decl->As<sem::Type>()) {
if (!Type(ty)) {
return false;
}
@ -209,7 +208,7 @@ bool Resolver::ResolveInternal() {
if (marked_.count(node) == 0) {
if (node->Is<ast::AccessDecoration>()) {
// These are generated by the WGSL parser, used to build
// type::AccessControls and then leaked.
// sem::AccessControls and then leaked.
// Once we introduce AST types, this should be fixed.
continue;
}
@ -222,13 +221,13 @@ bool Resolver::ResolveInternal() {
return true;
}
bool Resolver::Type(type::Type* ty) {
bool Resolver::Type(sem::Type* ty) {
ty = ty->UnwrapAliasIfNeeded();
if (auto* str = ty->As<type::StructType>()) {
if (auto* str = ty->As<sem::StructType>()) {
if (!Structure(str)) {
return false;
}
} else if (auto* arr = ty->As<type::ArrayType>()) {
} else if (auto* arr = ty->As<sem::ArrayType>()) {
if (!Array(arr, Source{})) {
return false;
}
@ -237,7 +236,7 @@ bool Resolver::Type(type::Type* ty) {
}
Resolver::VariableInfo* Resolver::Variable(ast::Variable* var,
type::Type* type /*=nullptr*/) {
sem::Type* type /*=nullptr*/) {
auto it = variable_to_info_.find(var);
if (it != variable_to_info_.end()) {
return it->second;
@ -248,7 +247,7 @@ Resolver::VariableInfo* Resolver::Variable(ast::Variable* var,
variable_to_info_.emplace(var, info);
// Resolve variable's type
if (auto* arr = info->type->As<type::ArrayType>()) {
if (auto* arr = info->type->As<sem::ArrayType>()) {
if (!Array(arr, var->source())) {
return nullptr;
}
@ -330,8 +329,8 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) {
// store type must be a host-shareable structure type with block attribute,
// satisfying the storage class constraints.
auto* access = info->type->As<type::AccessControl>();
auto* str = access ? access->type()->As<type::StructType>() : nullptr;
auto* access = info->type->As<sem::AccessControl>();
auto* str = access ? access->type()->As<sem::StructType>() : nullptr;
if (!str) {
diagnostics_.add_error(
"variables declared in the <storage> storage class must be of an "
@ -358,7 +357,7 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) {
bool Resolver::ValidateVariable(const ast::Variable* var) {
auto* type = variable_to_info_[var]->type;
if (auto* r = type->UnwrapAll()->As<type::ArrayType>()) {
if (auto* r = type->UnwrapAll()->As<sem::ArrayType>()) {
if (r->IsRuntimeArray()) {
diagnostics_.add_error(
"v-0015",
@ -390,7 +389,7 @@ bool Resolver::ValidateFunction(const ast::Function* func) {
}
}
if (!func->return_type()->Is<type::Void>()) {
if (!func->return_type()->Is<sem::Void>()) {
if (func->body()) {
if (!func->get_last_statement() ||
!func->get_last_statement()->Is<ast::ReturnStatement>()) {
@ -466,7 +465,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func) {
};
// Inner lambda that is applied to a type and all of its members.
auto validate_entry_point_decorations_inner =
[&](const ast::DecorationList& decos, type::Type* ty, Source source,
[&](const ast::DecorationList& decos, sem::Type* ty, Source source,
ParamOrRetType param_or_ret, bool is_struct_member) {
// Scan decorations for pipeline IO attributes.
// Check for overlap with attributes that have been seen previously.
@ -519,7 +518,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func) {
}
// Check that we saw a pipeline IO attribute iff we need one.
if (Canonical(ty)->Is<type::StructType>()) {
if (Canonical(ty)->Is<sem::StructType>()) {
if (pipeline_io_attribute) {
diagnostics_.add_error(
"entry point IO attributes must not be used on structure " +
@ -547,7 +546,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func) {
// Outer lambda for validating the entry point decorations for a type.
auto validate_entry_point_decorations = [&](const ast::DecorationList& decos,
type::Type* ty, Source source,
sem::Type* ty, Source source,
ParamOrRetType param_or_ret) {
// Validate the decorations for the type.
if (!validate_entry_point_decorations_inner(decos, ty, source, param_or_ret,
@ -555,12 +554,12 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func) {
return false;
}
if (auto* struct_ty = Canonical(ty)->As<type::StructType>()) {
if (auto* struct_ty = Canonical(ty)->As<sem::StructType>()) {
// Validate the decorations for each struct members, and also check for
// invalid member types.
for (auto* member : struct_ty->impl()->members()) {
auto* member_ty = Canonical(member->type());
if (member_ty->Is<type::StructType>()) {
if (member_ty->Is<sem::StructType>()) {
diagnostics_.add_error(
"entry point IO types cannot contain nested structures",
member->source());
@ -568,7 +567,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func) {
builder_->Symbols().NameFor(func->symbol()),
func->source());
return false;
} else if (auto* arr = member_ty->As<type::ArrayType>()) {
} else if (auto* arr = member_ty->As<sem::ArrayType>()) {
if (arr->IsRuntimeArray()) {
diagnostics_.add_error(
"entry point IO types cannot contain runtime sized arrays",
@ -603,7 +602,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func) {
}
}
if (!func->return_type()->Is<type::Void>()) {
if (!func->return_type()->Is<sem::Void>()) {
builtins.clear();
locations.clear();
if (!validate_entry_point_decorations(func->return_type_decorations(),
@ -646,7 +645,7 @@ bool Resolver::Function(ast::Function* func) {
return false;
}
if (auto* str = param_info->type->As<type::StructType>()) {
if (auto* str = param_info->type->As<sem::StructType>()) {
auto* info = Structure(str);
if (!info) {
return false;
@ -670,7 +669,7 @@ bool Resolver::Function(ast::Function* func) {
}
}
if (auto* str = Canonical(func->return_type())->As<type::StructType>()) {
if (auto* str = Canonical(func->return_type())->As<sem::StructType>()) {
if (!ApplyStorageClassUsageToType(ast::StorageClass::kNone, str,
func->source())) {
diagnostics_.add_note("while instantiating return type for " +
@ -945,13 +944,13 @@ bool Resolver::ArrayAccessor(ast::ArrayAccessorExpression* expr) {
auto* res = TypeOf(expr->array());
auto* parent_type = res->UnwrapAll();
type::Type* ret = nullptr;
if (auto* arr = parent_type->As<type::ArrayType>()) {
sem::Type* ret = nullptr;
if (auto* arr = parent_type->As<sem::ArrayType>()) {
ret = arr->type();
} else if (auto* vec = parent_type->As<type::Vector>()) {
} else if (auto* vec = parent_type->As<sem::Vector>()) {
ret = vec->type();
} else if (auto* mat = parent_type->As<type::Matrix>()) {
ret = builder_->create<type::Vector>(mat->type(), mat->rows());
} else if (auto* mat = parent_type->As<sem::Matrix>()) {
ret = builder_->create<sem::Vector>(mat->type(), mat->rows());
} else {
diagnostics_.add_error("invalid parent type (" + parent_type->type_name() +
") in array accessor",
@ -960,13 +959,13 @@ bool Resolver::ArrayAccessor(ast::ArrayAccessorExpression* expr) {
}
// If we're extracting from a pointer, we return a pointer.
if (auto* ptr = res->As<type::Pointer>()) {
ret = builder_->create<type::Pointer>(ret, ptr->storage_class());
} else if (auto* arr = parent_type->As<type::ArrayType>()) {
if (auto* ptr = res->As<sem::Pointer>()) {
ret = builder_->create<sem::Pointer>(ret, ptr->storage_class());
} else if (auto* arr = parent_type->As<sem::ArrayType>()) {
if (!arr->type()->is_scalar()) {
// If we extract a non-scalar from an array then we also get a pointer. We
// will generate a Function storage class variable to store this into.
ret = builder_->create<type::Pointer>(ret, ast::StorageClass::kFunction);
ret = builder_->create<sem::Pointer>(ret, ast::StorageClass::kFunction);
}
}
SetType(expr, ret);
@ -1055,7 +1054,7 @@ bool Resolver::Call(ast::CallExpression* call) {
bool Resolver::IntrinsicCall(ast::CallExpression* call,
sem::IntrinsicType intrinsic_type) {
std::vector<type::Type*> arg_tys;
std::vector<sem::Type*> arg_tys;
arg_tys.reserve(call->params().size());
for (auto* expr : call->params()) {
arg_tys.emplace_back(TypeOf(expr));
@ -1088,10 +1087,10 @@ bool Resolver::Constructor(ast::ConstructorExpression* expr) {
// Now that the argument types have been determined, make sure that they
// obey the constructor type rules laid out in
// https://gpuweb.github.io/gpuweb/wgsl.html#type-constructor-expr.
if (auto* vec_type = type_ctor->type()->As<type::Vector>()) {
if (auto* vec_type = type_ctor->type()->As<sem::Vector>()) {
return ValidateVectorConstructor(vec_type, type_ctor->values());
}
if (auto* mat_type = type_ctor->type()->As<type::Matrix>()) {
if (auto* mat_type = type_ctor->type()->As<sem::Matrix>()) {
return ValidateMatrixConstructor(mat_type, type_ctor->values());
}
// TODO(crbug.com/tint/634): Validate array constructor
@ -1104,12 +1103,12 @@ bool Resolver::Constructor(ast::ConstructorExpression* expr) {
return true;
}
bool Resolver::ValidateVectorConstructor(const type::Vector* vec_type,
bool Resolver::ValidateVectorConstructor(const sem::Vector* vec_type,
const ast::ExpressionList& values) {
type::Type* elem_type = vec_type->type()->UnwrapAll();
sem::Type* elem_type = vec_type->type()->UnwrapAll();
size_t value_cardinality_sum = 0;
for (auto* value : values) {
type::Type* value_type = TypeOf(value)->UnwrapAll();
sem::Type* value_type = TypeOf(value)->UnwrapAll();
if (value_type->is_scalar()) {
if (elem_type != value_type) {
diagnostics_.add_error(
@ -1122,8 +1121,8 @@ bool Resolver::ValidateVectorConstructor(const type::Vector* vec_type,
}
value_cardinality_sum++;
} else if (auto* value_vec = value_type->As<type::Vector>()) {
type::Type* value_elem_type = value_vec->type()->UnwrapAll();
} else if (auto* value_vec = value_type->As<sem::Vector>()) {
sem::Type* value_elem_type = value_vec->type()->UnwrapAll();
// A mismatch of vector type parameter T is only an error if multiple
// arguments are present. A single argument constructor constitutes a
// type conversion expression.
@ -1172,14 +1171,14 @@ bool Resolver::ValidateVectorConstructor(const type::Vector* vec_type,
return true;
}
bool Resolver::ValidateMatrixConstructor(const type::Matrix* matrix_type,
bool Resolver::ValidateMatrixConstructor(const sem::Matrix* matrix_type,
const ast::ExpressionList& values) {
// Zero Value expression
if (values.empty()) {
return true;
}
type::Type* elem_type = matrix_type->type()->UnwrapAll();
sem::Type* elem_type = matrix_type->type()->UnwrapAll();
if (matrix_type->columns() != values.size()) {
const Source& values_start = values[0]->source();
const Source& values_end = values[values.size() - 1]->source();
@ -1193,8 +1192,8 @@ bool Resolver::ValidateMatrixConstructor(const type::Matrix* matrix_type,
}
for (auto* value : values) {
type::Type* value_type = TypeOf(value)->UnwrapAll();
auto* value_vec = value_type->As<type::Vector>();
sem::Type* value_type = TypeOf(value)->UnwrapAll();
auto* value_vec = value_type->As<sem::Vector>();
if (!value_vec || value_vec->size() != matrix_type->rows() ||
elem_type != value_vec->type()->UnwrapAll()) {
@ -1220,11 +1219,11 @@ bool Resolver::Identifier(ast::IdentifierExpression* expr) {
// the pointer around the variable type.
if (var->declaration->is_const()) {
SetType(expr, var->type);
} else if (var->type->Is<type::Pointer>()) {
} else if (var->type->Is<sem::Pointer>()) {
SetType(expr, var->type);
} else {
SetType(expr,
builder_->create<type::Pointer>(var->type, var->storage_class));
builder_->create<sem::Pointer>(var->type, var->storage_class));
}
var->users.push_back(expr);
@ -1293,10 +1292,10 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) {
auto* res = TypeOf(expr->structure());
auto* data_type = res->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
type::Type* ret = nullptr;
sem::Type* ret = nullptr;
std::vector<uint32_t> swizzle;
if (auto* ty = data_type->As<type::StructType>()) {
if (auto* ty = data_type->As<sem::StructType>()) {
Mark(expr->member());
auto symbol = expr->member()->symbol();
auto* str = Structure(ty);
@ -1318,13 +1317,13 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) {
}
// If we're extracting from a pointer, we return a pointer.
if (auto* ptr = res->As<type::Pointer>()) {
ret = builder_->create<type::Pointer>(ret, ptr->storage_class());
if (auto* ptr = res->As<sem::Pointer>()) {
ret = builder_->create<sem::Pointer>(ret, ptr->storage_class());
}
builder_->Sem().Add(expr, builder_->create<sem::StructMemberAccess>(
expr, ret, current_statement_, member));
} else if (auto* vec = data_type->As<type::Vector>()) {
} else if (auto* vec = data_type->As<sem::Vector>()) {
Mark(expr->member());
std::string str = builder_->Symbols().NameFor(expr->member()->symbol());
auto size = str.size();
@ -1381,14 +1380,14 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) {
// A single element swizzle is just the type of the vector.
ret = vec->type();
// If we're extracting from a pointer, we return a pointer.
if (auto* ptr = res->As<type::Pointer>()) {
ret = builder_->create<type::Pointer>(ret, ptr->storage_class());
if (auto* ptr = res->As<sem::Pointer>()) {
ret = builder_->create<sem::Pointer>(ret, ptr->storage_class());
}
} else {
// The vector will have a number of components equal to the length of
// the swizzle.
ret = builder_->create<type::Vector>(vec->type(),
static_cast<uint32_t>(size));
ret = builder_->create<sem::Vector>(vec->type(),
static_cast<uint32_t>(size));
}
builder_->Sem().Add(
expr, builder_->create<sem::Swizzle>(expr, ret, current_statement_,
@ -1407,12 +1406,12 @@ bool Resolver::MemberAccessor(ast::MemberAccessorExpression* expr) {
}
bool Resolver::ValidateBinary(ast::BinaryExpression* expr) {
using Bool = type::Bool;
using F32 = type::F32;
using I32 = type::I32;
using U32 = type::U32;
using Matrix = type::Matrix;
using Vector = type::Vector;
using Bool = sem::Bool;
using F32 = sem::F32;
using I32 = sem::I32;
using U32 = sem::U32;
using Matrix = sem::Matrix;
using Vector = sem::Vector;
auto* lhs_declared_type = TypeOf(expr->lhs())->UnwrapAll();
auto* rhs_declared_type = TypeOf(expr->rhs())->UnwrapAll();
@ -1592,11 +1591,11 @@ bool Resolver::Binary(ast::BinaryExpression* expr) {
if (expr->IsLogicalAnd() || expr->IsLogicalOr() || expr->IsEqual() ||
expr->IsNotEqual() || expr->IsLessThan() || expr->IsGreaterThan() ||
expr->IsLessThanEqual() || expr->IsGreaterThanEqual()) {
auto* bool_type = builder_->create<type::Bool>();
auto* bool_type = builder_->create<sem::Bool>();
auto* param_type = TypeOf(expr->lhs())->UnwrapAll();
type::Type* result_type = bool_type;
if (auto* vec = param_type->As<type::Vector>()) {
result_type = builder_->create<type::Vector>(bool_type, vec->size());
sem::Type* result_type = bool_type;
if (auto* vec = param_type->As<sem::Vector>()) {
result_type = builder_->create<sem::Vector>(bool_type, vec->size());
}
SetType(expr, result_type);
return true;
@ -1607,20 +1606,20 @@ bool Resolver::Binary(ast::BinaryExpression* expr) {
// Note, the ordering here matters. The later checks depend on the prior
// checks having been done.
auto* lhs_mat = lhs_type->As<type::Matrix>();
auto* rhs_mat = rhs_type->As<type::Matrix>();
auto* lhs_vec = lhs_type->As<type::Vector>();
auto* rhs_vec = rhs_type->As<type::Vector>();
type::Type* result_type;
auto* lhs_mat = lhs_type->As<sem::Matrix>();
auto* rhs_mat = rhs_type->As<sem::Matrix>();
auto* lhs_vec = lhs_type->As<sem::Vector>();
auto* rhs_vec = rhs_type->As<sem::Vector>();
sem::Type* result_type;
if (lhs_mat && rhs_mat) {
result_type = builder_->create<type::Matrix>(
result_type = builder_->create<sem::Matrix>(
lhs_mat->type(), lhs_mat->rows(), rhs_mat->columns());
} else if (lhs_mat && rhs_vec) {
result_type =
builder_->create<type::Vector>(lhs_mat->type(), lhs_mat->rows());
builder_->create<sem::Vector>(lhs_mat->type(), lhs_mat->rows());
} else if (lhs_vec && rhs_mat) {
result_type =
builder_->create<type::Vector>(rhs_mat->type(), rhs_mat->columns());
builder_->create<sem::Vector>(rhs_mat->type(), rhs_mat->columns());
} else if (lhs_mat) {
// matrix * scalar
result_type = lhs_type;
@ -1665,7 +1664,7 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) {
ast::Variable* var = stmt->variable();
Mark(var);
type::Type* type = var->declared_type();
sem::Type* type = var->declared_type();
bool is_global = false;
if (variable_stack_.get(var->symbol(), nullptr, &is_global)) {
@ -1741,7 +1740,7 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) {
return true;
}
type::Type* Resolver::TypeOf(ast::Expression* expr) {
sem::Type* Resolver::TypeOf(ast::Expression* expr) {
auto it = expr_info_.find(expr);
if (it != expr_info_.end()) {
return it->second.type;
@ -1749,7 +1748,7 @@ type::Type* Resolver::TypeOf(ast::Expression* expr) {
return nullptr;
}
void Resolver::SetType(ast::Expression* expr, type::Type* type) {
void Resolver::SetType(ast::Expression* expr, sem::Type* type) {
if (expr_info_.count(expr)) {
TINT_ICE(builder_->Diagnostics())
<< "SetType() called twice for the same expression";
@ -1865,7 +1864,7 @@ void Resolver::CreateSemanticNodes() const {
}
}
bool Resolver::DefaultAlignAndSize(type::Type* ty,
bool Resolver::DefaultAlignAndSize(sem::Type* ty,
uint32_t& align,
uint32_t& size,
const Source& source) {
@ -1890,7 +1889,7 @@ bool Resolver::DefaultAlignAndSize(type::Type* ty,
align = 4;
size = 4;
return true;
} else if (auto* vec = cty->As<type::Vector>()) {
} else if (auto* vec = cty->As<sem::Vector>()) {
if (vec->size() < 2 || vec->size() > 4) {
TINT_UNREACHABLE(diagnostics_)
<< "Invalid vector size: vec" << vec->size();
@ -1899,7 +1898,7 @@ bool Resolver::DefaultAlignAndSize(type::Type* ty,
align = vector_align[vec->size()];
size = vector_size[vec->size()];
return true;
} else if (auto* mat = cty->As<type::Matrix>()) {
} else if (auto* mat = cty->As<sem::Matrix>()) {
if (mat->columns() < 2 || mat->columns() > 4 || mat->rows() < 2 ||
mat->rows() > 4) {
TINT_UNREACHABLE(diagnostics_)
@ -1909,16 +1908,16 @@ bool Resolver::DefaultAlignAndSize(type::Type* ty,
align = vector_align[mat->rows()];
size = vector_align[mat->rows()] * mat->columns();
return true;
} else if (auto* s = cty->As<type::StructType>()) {
} else if (auto* s = cty->As<sem::StructType>()) {
if (auto* si = Structure(s)) {
align = si->align;
size = si->size;
return true;
}
return false;
} else if (cty->Is<type::ArrayType>()) {
} else if (cty->Is<sem::ArrayType>()) {
if (auto* sem =
Array(ty->UnwrapAliasIfNeeded()->As<type::ArrayType>(), source)) {
Array(ty->UnwrapAliasIfNeeded()->As<sem::ArrayType>(), source)) {
align = sem->Align();
size = sem->Size();
return true;
@ -1929,7 +1928,7 @@ bool Resolver::DefaultAlignAndSize(type::Type* ty,
return false;
}
const sem::Array* Resolver::Array(type::ArrayType* arr, const Source& source) {
const sem::Array* Resolver::Array(sem::ArrayType* arr, const Source& source) {
if (auto* sem = builder_->Sem().Get(arr)) {
// Semantic info already constructed for this array type
return sem;
@ -1998,9 +1997,9 @@ const sem::Array* Resolver::Array(type::ArrayType* arr, const Source& source) {
return create_semantic(implicit_stride);
}
bool Resolver::ValidateStructure(const type::StructType* st) {
bool Resolver::ValidateStructure(const sem::StructType* st) {
for (auto* member : st->impl()->members()) {
if (auto* r = member->type()->UnwrapAll()->As<type::ArrayType>()) {
if (auto* r = member->type()->UnwrapAll()->As<sem::ArrayType>()) {
if (r->IsRuntimeArray()) {
if (member != st->impl()->members().back()) {
diagnostics_.add_error(
@ -2053,7 +2052,7 @@ bool Resolver::ValidateStructure(const type::StructType* st) {
return true;
}
Resolver::StructInfo* Resolver::Structure(type::StructType* str) {
Resolver::StructInfo* Resolver::Structure(sem::StructType* str) {
auto info_it = struct_info_.find(str);
if (info_it != struct_info_.end()) {
// StructInfo already resolved for this structure type
@ -2173,7 +2172,7 @@ Resolver::StructInfo* Resolver::Structure(type::StructType* str) {
}
bool Resolver::ValidateReturn(const ast::ReturnStatement* ret) {
type::Type* func_type = current_function_->declaration->return_type();
sem::Type* func_type = current_function_->declaration->return_type();
auto* ret_type = ret->has_value() ? TypeOf(ret->value())->UnwrapAll()
: builder_->ty.void_();
@ -2326,7 +2325,7 @@ bool Resolver::ValidateAssignment(const ast::AssignmentStatement* a) {
// lhs must be a pointer or a constant
auto* lhs_result_type = TypeOf(lhs)->UnwrapIfNeeded();
if (!lhs_result_type->Is<type::Pointer>()) {
if (!lhs_result_type->Is<sem::Pointer>()) {
// In case lhs is a constant identifier, output a nicer message as it's
// likely to be a common programmer error.
if (auto* ident = lhs->As<ast::IdentifierExpression>()) {
@ -2365,11 +2364,11 @@ bool Resolver::Assignment(ast::AssignmentStatement* a) {
}
bool Resolver::ApplyStorageClassUsageToType(ast::StorageClass sc,
type::Type* ty,
sem::Type* ty,
const Source& usage) {
ty = ty->UnwrapIfNeeded();
if (auto* str = ty->As<type::StructType>()) {
if (auto* str = ty->As<sem::StructType>()) {
auto* info = Structure(str);
if (!info) {
return false;
@ -2391,7 +2390,7 @@ bool Resolver::ApplyStorageClassUsageToType(ast::StorageClass sc,
return true;
}
if (auto* arr = ty->As<type::ArrayType>()) {
if (auto* arr = ty->As<sem::ArrayType>()) {
return ApplyStorageClassUsageToType(sc, arr->type(), usage);
}
@ -2419,20 +2418,20 @@ bool Resolver::BlockScope(const ast::BlockStatement* block,
return result;
}
std::string Resolver::VectorPretty(uint32_t size, type::Type* element_type) {
type::Vector vec_type(element_type, size);
std::string Resolver::VectorPretty(uint32_t size, sem::Type* element_type) {
sem::Vector vec_type(element_type, size);
return vec_type.FriendlyName(builder_->Symbols());
}
type::Type* Resolver::Canonical(type::Type* type) {
using AccessControl = type::AccessControl;
using Alias = type::Alias;
using Matrix = type::Matrix;
using Type = type::Type;
using Vector = type::Vector;
sem::Type* Resolver::Canonical(sem::Type* type) {
using AccessControl = sem::AccessControl;
using Alias = sem::Alias;
using Matrix = sem::Matrix;
using Type = sem::Type;
using Vector = sem::Vector;
std::function<Type*(Type*)> make_canonical;
make_canonical = [&](Type* t) -> type::Type* {
make_canonical = [&](Type* t) -> sem::Type* {
// Unwrap alias sequence
Type* ct = t;
while (auto* p = ct->As<Alias>()) {
@ -2470,7 +2469,7 @@ void Resolver::Mark(ast::Node* node) {
<< "At: " << node->source();
}
Resolver::VariableInfo::VariableInfo(ast::Variable* decl, type::Type* ctype)
Resolver::VariableInfo::VariableInfo(ast::Variable* decl, sem::Type* ctype)
: declaration(decl),
type(ctype),
storage_class(decl->declared_storage_class()) {}

View File

@ -49,9 +49,9 @@ namespace sem {
class Array;
class Statement;
} // namespace sem
namespace type {
class Struct;
} // namespace type
namespace sem {
class StructType;
} // namespace sem
namespace resolver {
@ -73,34 +73,34 @@ class Resolver {
/// @param type the given type
/// @returns true if the given type is storable
static bool IsStorable(type::Type* type);
static bool IsStorable(sem::Type* type);
/// @param type the given type
/// @returns true if the given type is host-shareable
static bool IsHostShareable(type::Type* type);
static bool IsHostShareable(sem::Type* type);
/// @param lhs the assignment store type (non-pointer)
/// @param rhs the assignment source type (non-pointer or pointer with
/// auto-deref)
/// @returns true an expression of type `rhs` can be assigned to a variable,
/// structure member or array element of type `lhs`
static bool IsValidAssignment(type::Type* lhs, type::Type* rhs);
static bool IsValidAssignment(sem::Type* lhs, sem::Type* rhs);
/// @param type the input type
/// @returns the canonical type for `type`; that is, a type with all aliases
/// removed. For example, `Canonical(alias<alias<vec3<alias<f32>>>>)` is
/// `vec3<f32>`.
type::Type* Canonical(type::Type* type);
sem::Type* Canonical(sem::Type* type);
private:
/// Structure holding semantic information about a variable.
/// Used to build the sem::Variable nodes at the end of resolving.
struct VariableInfo {
VariableInfo(ast::Variable* decl, type::Type* type);
VariableInfo(ast::Variable* decl, sem::Type* type);
~VariableInfo();
ast::Variable* const declaration;
type::Type* type;
sem::Type* type;
ast::StorageClass storage_class;
std::vector<ast::IdentifierExpression*> users;
};
@ -124,7 +124,7 @@ class Resolver {
/// Structure holding semantic information about an expression.
/// Used to build the sem::Expression nodes at the end of resolving.
struct ExpressionInfo {
type::Type* type;
sem::Type* type;
sem::Statement* statement;
};
@ -199,11 +199,11 @@ class Resolver {
/// @param params the parameters to the method call
/// @param id out parameter for the external call ID. Must not be a nullptr.
/// @returns the return type of `name` in `path` or nullptr on error.
type::Type* GetImportData(const Source& src,
const std::string& path,
const std::string& name,
const ast::ExpressionList& params,
uint32_t* id);
sem::Type* GetImportData(const Source& src,
const std::string& path,
const std::string& name,
const ast::ExpressionList& params,
uint32_t* id);
void set_referenced_from_function_if_needed(VariableInfo* var, bool local);
@ -230,7 +230,7 @@ class Resolver {
bool Statement(ast::Statement*);
bool Statements(const ast::StatementList&);
bool Switch(ast::SwitchStatement* s);
bool Type(type::Type* ty);
bool Type(sem::Type* ty);
bool UnaryOp(ast::UnaryOpExpression*);
bool VariableDeclStatement(const ast::VariableDeclStatement*);
@ -241,14 +241,14 @@ class Resolver {
bool ValidateEntryPoint(const ast::Function* func);
bool ValidateFunction(const ast::Function* func);
bool ValidateGlobalVariable(const VariableInfo* var);
bool ValidateMatrixConstructor(const type::Matrix* matrix_type,
bool ValidateMatrixConstructor(const sem::Matrix* matrix_type,
const ast::ExpressionList& values);
bool ValidateParameter(const ast::Variable* param);
bool ValidateReturn(const ast::ReturnStatement* ret);
bool ValidateStructure(const type::StructType* st);
bool ValidateStructure(const sem::StructType* st);
bool ValidateSwitch(const ast::SwitchStatement* s);
bool ValidateVariable(const ast::Variable* param);
bool ValidateVectorConstructor(const type::Vector* vec_type,
bool ValidateVectorConstructor(const sem::Vector* vec_type,
const ast::ExpressionList& values);
/// @returns the semantic information for the array `arr`, building it if it
@ -256,18 +256,18 @@ class Resolver {
/// returned.
/// @param arr the Array to get semantic information for
/// @param source the Source of the ast node with this array as its type
const sem::Array* Array(type::ArrayType* arr, const Source& source);
const sem::Array* Array(sem::ArrayType* arr, const Source& source);
/// @returns the StructInfo for the structure `str`, building it if it hasn't
/// been constructed already. If an error is raised, nullptr is returned.
StructInfo* Structure(type::StructType* str);
StructInfo* Structure(sem::StructType* str);
/// @returns the VariableInfo for the variable `var`, building it if it hasn't
/// been constructed already. If an error is raised, nullptr is returned.
/// @param var the variable to create or return the `VariableInfo` for
/// @param type optional type of `var` to use instead of
/// `var->declared_type()`. For type inference.
VariableInfo* Variable(ast::Variable* var, type::Type* type = nullptr);
VariableInfo* Variable(ast::Variable* var, sem::Type* type = nullptr);
/// Records the storage class usage for the given type, and any transient
/// dependencies of the type. Validates that the type can be used for the
@ -278,27 +278,27 @@ class Resolver {
/// given type and storage class. Used for generating sensible error messages.
/// @returns true on success, false on error
bool ApplyStorageClassUsageToType(ast::StorageClass sc,
type::Type* ty,
sem::Type* ty,
const Source& usage);
/// @param align the output default alignment in bytes for the type `ty`
/// @param size the output default size in bytes for the type `ty`
/// @param source the Source of the variable declaration of type `ty`
/// @returns true on success, false on error
bool DefaultAlignAndSize(type::Type* ty,
bool DefaultAlignAndSize(sem::Type* ty,
uint32_t& align,
uint32_t& size,
const Source& source);
/// @returns the resolved type of the ast::Expression `expr`
/// @param expr the expression
type::Type* TypeOf(ast::Expression* expr);
sem::Type* TypeOf(ast::Expression* expr);
/// Creates a sem::Expression node with the resolved type `type`, and
/// assigns this semantic node to the expression `expr`.
/// @param expr the expression
/// @param type the resolved type
void SetType(ast::Expression* expr, type::Type* type);
void SetType(ast::Expression* expr, sem::Type* type);
/// Constructs a new BlockInfo with the given type and with #current_block_ as
/// its parent, assigns this to #current_block_, and then calls `callback`.
@ -313,7 +313,7 @@ class Resolver {
/// @param size the vector dimension
/// @param element_type scalar vector sub-element type
/// @return pretty string representation
std::string VectorPretty(uint32_t size, type::Type* element_type);
std::string VectorPretty(uint32_t size, sem::Type* element_type);
/// Mark records that the given AST node has been visited, and asserts that
/// the given node has not already been seen. Diamonds in the AST are illegal.
@ -330,8 +330,8 @@ class Resolver {
std::unordered_map<const ast::Variable*, VariableInfo*> variable_to_info_;
std::unordered_map<ast::CallExpression*, FunctionCallInfo> function_calls_;
std::unordered_map<ast::Expression*, ExpressionInfo> expr_info_;
std::unordered_map<type::StructType*, StructInfo*> struct_info_;
std::unordered_map<type::Type*, type::Type*> type_to_canonical_;
std::unordered_map<sem::StructType*, StructInfo*> struct_info_;
std::unordered_map<sem::Type*, sem::Type*> type_to_canonical_;
std::unordered_set<ast::Node*> marked_;
FunctionInfo* current_function_ = nullptr;
sem::Statement* current_statement_ = nullptr;

View File

@ -67,8 +67,8 @@ TEST_F(ResolverTest, Stmt_Assign) {
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<type::F32>());
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<sem::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<sem::F32>());
EXPECT_EQ(StmtOf(lhs), assign);
EXPECT_EQ(StmtOf(rhs), assign);
}
@ -89,8 +89,8 @@ TEST_F(ResolverTest, Stmt_Case) {
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<type::F32>());
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<sem::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<sem::F32>());
EXPECT_EQ(StmtOf(lhs), assign);
EXPECT_EQ(StmtOf(rhs), assign);
EXPECT_EQ(BlockOf(assign), block);
@ -109,8 +109,8 @@ TEST_F(ResolverTest, Stmt_Block) {
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<type::F32>());
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<sem::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<sem::F32>());
EXPECT_EQ(StmtOf(lhs), assign);
EXPECT_EQ(StmtOf(rhs), assign);
EXPECT_EQ(BlockOf(lhs), block);
@ -145,11 +145,11 @@ TEST_F(ResolverTest, Stmt_If) {
ASSERT_NE(TypeOf(else_rhs), nullptr);
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(TypeOf(stmt->condition())->Is<type::Bool>());
EXPECT_TRUE(TypeOf(else_lhs)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(else_rhs)->Is<type::F32>());
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<type::F32>());
EXPECT_TRUE(TypeOf(stmt->condition())->Is<sem::Bool>());
EXPECT_TRUE(TypeOf(else_lhs)->UnwrapAll()->Is<sem::F32>());
EXPECT_TRUE(TypeOf(else_rhs)->Is<sem::F32>());
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<sem::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<sem::F32>());
EXPECT_EQ(StmtOf(lhs), assign);
EXPECT_EQ(StmtOf(rhs), assign);
EXPECT_EQ(StmtOf(cond), stmt);
@ -181,10 +181,10 @@ TEST_F(ResolverTest, Stmt_Loop) {
ASSERT_NE(TypeOf(body_rhs), nullptr);
ASSERT_NE(TypeOf(continuing_lhs), nullptr);
ASSERT_NE(TypeOf(continuing_rhs), nullptr);
EXPECT_TRUE(TypeOf(body_lhs)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(body_rhs)->Is<type::F32>());
EXPECT_TRUE(TypeOf(continuing_lhs)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(continuing_rhs)->Is<type::F32>());
EXPECT_TRUE(TypeOf(body_lhs)->UnwrapAll()->Is<sem::F32>());
EXPECT_TRUE(TypeOf(body_rhs)->Is<sem::F32>());
EXPECT_TRUE(TypeOf(continuing_lhs)->UnwrapAll()->Is<sem::F32>());
EXPECT_TRUE(TypeOf(continuing_rhs)->Is<sem::F32>());
EXPECT_EQ(BlockOf(body_lhs), body);
EXPECT_EQ(BlockOf(body_rhs), body);
EXPECT_EQ(BlockOf(continuing_lhs), continuing);
@ -200,7 +200,7 @@ TEST_F(ResolverTest, Stmt_Return) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(cond), nullptr);
EXPECT_TRUE(TypeOf(cond)->Is<type::I32>());
EXPECT_TRUE(TypeOf(cond)->Is<sem::I32>());
}
TEST_F(ResolverTest, Stmt_Return_WithoutValue) {
@ -224,9 +224,9 @@ TEST_F(ResolverTest, Stmt_Switch) {
ASSERT_NE(TypeOf(lhs), nullptr);
ASSERT_NE(TypeOf(rhs), nullptr);
EXPECT_TRUE(TypeOf(stmt->condition())->Is<type::I32>());
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<type::F32>());
EXPECT_TRUE(TypeOf(stmt->condition())->Is<sem::I32>());
EXPECT_TRUE(TypeOf(lhs)->UnwrapAll()->Is<sem::F32>());
EXPECT_TRUE(TypeOf(rhs)->Is<sem::F32>());
EXPECT_EQ(BlockOf(lhs), case_block);
EXPECT_EQ(BlockOf(rhs), case_block);
}
@ -244,7 +244,7 @@ TEST_F(ResolverTest, Stmt_Call) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::F32>());
EXPECT_EQ(StmtOf(expr), call);
}
@ -258,7 +258,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(init), nullptr);
EXPECT_TRUE(TypeOf(init)->Is<type::I32>());
EXPECT_TRUE(TypeOf(init)->Is<sem::I32>());
}
TEST_F(ResolverTest, Stmt_VariableDecl_Alias) {
@ -272,7 +272,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_Alias) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(init), nullptr);
EXPECT_TRUE(TypeOf(init)->Is<type::I32>());
EXPECT_TRUE(TypeOf(init)->Is<sem::I32>());
}
TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScope) {
@ -282,7 +282,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScope) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(init), nullptr);
EXPECT_TRUE(TypeOf(init)->Is<type::I32>());
EXPECT_TRUE(TypeOf(init)->Is<sem::I32>());
EXPECT_EQ(StmtOf(init), nullptr);
}
@ -327,13 +327,13 @@ TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(foo_i32_init), nullptr);
EXPECT_TRUE(TypeOf(foo_i32_init)->Is<type::I32>());
EXPECT_TRUE(TypeOf(foo_i32_init)->Is<sem::I32>());
ASSERT_NE(TypeOf(foo_f32_init), nullptr);
EXPECT_TRUE(TypeOf(foo_f32_init)->Is<type::F32>());
EXPECT_TRUE(TypeOf(foo_f32_init)->Is<sem::F32>());
ASSERT_NE(TypeOf(bar_i32_init), nullptr);
EXPECT_TRUE(TypeOf(bar_i32_init)->UnwrapAll()->Is<type::I32>());
EXPECT_TRUE(TypeOf(bar_i32_init)->UnwrapAll()->Is<sem::I32>());
ASSERT_NE(TypeOf(bar_f32_init), nullptr);
EXPECT_TRUE(TypeOf(bar_f32_init)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(bar_f32_init)->UnwrapAll()->Is<sem::F32>());
EXPECT_EQ(StmtOf(foo_i32_init), foo_i32_decl);
EXPECT_EQ(StmtOf(bar_i32_init), bar_i32_decl);
EXPECT_EQ(StmtOf(foo_f32_init), foo_f32_decl);
@ -379,11 +379,11 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(mod_init), nullptr);
EXPECT_TRUE(TypeOf(mod_init)->Is<type::F32>());
EXPECT_TRUE(TypeOf(mod_init)->Is<sem::F32>());
ASSERT_NE(TypeOf(fn_i32_init), nullptr);
EXPECT_TRUE(TypeOf(fn_i32_init)->Is<type::I32>());
EXPECT_TRUE(TypeOf(fn_i32_init)->Is<sem::I32>());
ASSERT_NE(TypeOf(fn_f32_init), nullptr);
EXPECT_TRUE(TypeOf(fn_f32_init)->UnwrapAll()->Is<type::F32>());
EXPECT_TRUE(TypeOf(fn_f32_init)->UnwrapAll()->Is<sem::F32>());
EXPECT_EQ(StmtOf(fn_i32_init), fn_i32_decl);
EXPECT_EQ(StmtOf(mod_init), nullptr);
EXPECT_EQ(StmtOf(fn_f32_init), fn_f32_decl);
@ -403,10 +403,10 @@ TEST_F(ResolverTest, Expr_ArrayAccessor_Array) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(acc), nullptr);
ASSERT_TRUE(TypeOf(acc)->Is<type::Pointer>());
ASSERT_TRUE(TypeOf(acc)->Is<sem::Pointer>());
auto* ptr = TypeOf(acc)->As<type::Pointer>();
EXPECT_TRUE(ptr->type()->Is<type::F32>());
auto* ptr = TypeOf(acc)->As<sem::Pointer>();
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_ArrayAccessor_Alias_Array) {
@ -420,10 +420,10 @@ TEST_F(ResolverTest, Expr_ArrayAccessor_Alias_Array) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(acc), nullptr);
ASSERT_TRUE(TypeOf(acc)->Is<type::Pointer>());
ASSERT_TRUE(TypeOf(acc)->Is<sem::Pointer>());
auto* ptr = TypeOf(acc)->As<type::Pointer>();
EXPECT_TRUE(ptr->type()->Is<type::F32>());
auto* ptr = TypeOf(acc)->As<sem::Pointer>();
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_ArrayAccessor_Array_Constant) {
@ -435,7 +435,7 @@ TEST_F(ResolverTest, Expr_ArrayAccessor_Array_Constant) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(acc), nullptr);
EXPECT_TRUE(TypeOf(acc)->Is<type::F32>()) << TypeOf(acc)->type_name();
EXPECT_TRUE(TypeOf(acc)->Is<sem::F32>()) << TypeOf(acc)->type_name();
}
TEST_F(ResolverTest, Expr_ArrayAccessor_Matrix) {
@ -447,11 +447,11 @@ TEST_F(ResolverTest, Expr_ArrayAccessor_Matrix) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(acc), nullptr);
ASSERT_TRUE(TypeOf(acc)->Is<type::Pointer>());
ASSERT_TRUE(TypeOf(acc)->Is<sem::Pointer>());
auto* ptr = TypeOf(acc)->As<type::Pointer>();
ASSERT_TRUE(ptr->type()->Is<type::Vector>());
EXPECT_EQ(ptr->type()->As<type::Vector>()->size(), 3u);
auto* ptr = TypeOf(acc)->As<sem::Pointer>();
ASSERT_TRUE(ptr->type()->Is<sem::Vector>());
EXPECT_EQ(ptr->type()->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
@ -463,10 +463,10 @@ TEST_F(ResolverTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(acc), nullptr);
ASSERT_TRUE(TypeOf(acc)->Is<type::Pointer>());
ASSERT_TRUE(TypeOf(acc)->Is<sem::Pointer>());
auto* ptr = TypeOf(acc)->As<type::Pointer>();
EXPECT_TRUE(ptr->type()->Is<type::F32>());
auto* ptr = TypeOf(acc)->As<sem::Pointer>();
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_ArrayAccessor_Vector) {
@ -478,10 +478,10 @@ TEST_F(ResolverTest, Expr_ArrayAccessor_Vector) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(acc), nullptr);
ASSERT_TRUE(TypeOf(acc)->Is<type::Pointer>());
ASSERT_TRUE(TypeOf(acc)->Is<sem::Pointer>());
auto* ptr = TypeOf(acc)->As<type::Pointer>();
EXPECT_TRUE(ptr->type()->Is<type::F32>());
auto* ptr = TypeOf(acc)->As<sem::Pointer>();
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Bitcast) {
@ -493,7 +493,7 @@ TEST_F(ResolverTest, Expr_Bitcast) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(bitcast), nullptr);
EXPECT_TRUE(TypeOf(bitcast)->Is<type::F32>());
EXPECT_TRUE(TypeOf(bitcast)->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Call) {
@ -507,7 +507,7 @@ TEST_F(ResolverTest, Expr_Call) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Call_InBinaryOp) {
@ -521,7 +521,7 @@ TEST_F(ResolverTest, Expr_Call_InBinaryOp) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Call_WithParams) {
@ -537,7 +537,7 @@ TEST_F(ResolverTest, Expr_Call_WithParams) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(param), nullptr);
EXPECT_TRUE(TypeOf(param)->Is<type::F32>());
EXPECT_TRUE(TypeOf(param)->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Call_Intrinsic) {
@ -547,7 +547,7 @@ TEST_F(ResolverTest, Expr_Call_Intrinsic) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Cast) {
@ -559,7 +559,7 @@ TEST_F(ResolverTest, Expr_Cast) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(cast), nullptr);
EXPECT_TRUE(TypeOf(cast)->Is<type::F32>());
EXPECT_TRUE(TypeOf(cast)->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Constructor_Scalar) {
@ -569,7 +569,7 @@ TEST_F(ResolverTest, Expr_Constructor_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(s), nullptr);
EXPECT_TRUE(TypeOf(s)->Is<type::F32>());
EXPECT_TRUE(TypeOf(s)->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Constructor_Type_Vec2) {
@ -579,9 +579,9 @@ TEST_F(ResolverTest, Expr_Constructor_Type_Vec2) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
}
TEST_F(ResolverTest, Expr_Constructor_Type_Vec3) {
@ -591,9 +591,9 @@ TEST_F(ResolverTest, Expr_Constructor_Type_Vec3) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverTest, Expr_Constructor_Type_Vec4) {
@ -603,9 +603,9 @@ TEST_F(ResolverTest, Expr_Constructor_Type_Vec4) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverTest, Expr_Identifier_GlobalVariable) {
@ -617,8 +617,8 @@ TEST_F(ResolverTest, Expr_Identifier_GlobalVariable) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(ident), nullptr);
EXPECT_TRUE(TypeOf(ident)->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(ident)->As<type::Pointer>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(ident)->Is<sem::Pointer>());
EXPECT_TRUE(TypeOf(ident)->As<sem::Pointer>()->type()->Is<sem::F32>());
EXPECT_TRUE(CheckVarUsers(my_var, {ident}));
ASSERT_NE(VarOf(ident), nullptr);
EXPECT_EQ(VarOf(ident)->Declaration(), my_var);
@ -633,7 +633,7 @@ TEST_F(ResolverTest, Expr_Identifier_GlobalConstant) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(ident), nullptr);
EXPECT_TRUE(TypeOf(ident)->Is<type::F32>());
EXPECT_TRUE(TypeOf(ident)->Is<sem::F32>());
EXPECT_TRUE(CheckVarUsers(my_var, {ident}));
ASSERT_NE(VarOf(ident), nullptr);
EXPECT_EQ(VarOf(ident)->Declaration(), my_var);
@ -654,7 +654,7 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(my_var_a), nullptr);
EXPECT_TRUE(TypeOf(my_var_a)->Is<type::F32>());
EXPECT_TRUE(TypeOf(my_var_a)->Is<sem::F32>());
EXPECT_EQ(StmtOf(my_var_a), decl);
EXPECT_TRUE(CheckVarUsers(var, {my_var_a}));
ASSERT_NE(VarOf(my_var_a), nullptr);
@ -678,12 +678,12 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(my_var_a), nullptr);
EXPECT_TRUE(TypeOf(my_var_a)->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(my_var_a)->As<type::Pointer>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(my_var_a)->Is<sem::Pointer>());
EXPECT_TRUE(TypeOf(my_var_a)->As<sem::Pointer>()->type()->Is<sem::F32>());
EXPECT_EQ(StmtOf(my_var_a), assign);
ASSERT_NE(TypeOf(my_var_b), nullptr);
EXPECT_TRUE(TypeOf(my_var_b)->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(my_var_b)->As<type::Pointer>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(my_var_b)->Is<sem::Pointer>());
EXPECT_TRUE(TypeOf(my_var_b)->As<sem::Pointer>()->type()->Is<sem::F32>());
EXPECT_EQ(StmtOf(my_var_b), assign);
EXPECT_TRUE(CheckVarUsers(var, {my_var_a, my_var_b}));
ASSERT_NE(VarOf(my_var_a), nullptr);
@ -709,12 +709,12 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(my_var_a), nullptr);
EXPECT_TRUE(TypeOf(my_var_a)->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(my_var_a)->As<type::Pointer>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(my_var_a)->Is<sem::Pointer>());
EXPECT_TRUE(TypeOf(my_var_a)->As<sem::Pointer>()->type()->Is<sem::F32>());
EXPECT_EQ(StmtOf(my_var_a), assign);
ASSERT_NE(TypeOf(my_var_b), nullptr);
EXPECT_TRUE(TypeOf(my_var_b)->Is<type::Pointer>());
EXPECT_TRUE(TypeOf(my_var_b)->As<type::Pointer>()->type()->Is<type::F32>());
EXPECT_TRUE(TypeOf(my_var_b)->Is<sem::Pointer>());
EXPECT_TRUE(TypeOf(my_var_b)->As<sem::Pointer>()->type()->Is<sem::F32>());
EXPECT_EQ(StmtOf(my_var_b), assign);
}
@ -728,7 +728,7 @@ TEST_F(ResolverTest, Expr_Call_Function) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(call), nullptr);
EXPECT_TRUE(TypeOf(call)->Is<type::F32>());
EXPECT_TRUE(TypeOf(call)->Is<sem::F32>());
}
TEST_F(ResolverTest, Expr_Identifier_Unknown) {
@ -902,10 +902,10 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(mem), nullptr);
ASSERT_TRUE(TypeOf(mem)->Is<type::Pointer>());
ASSERT_TRUE(TypeOf(mem)->Is<sem::Pointer>());
auto* ptr = TypeOf(mem)->As<type::Pointer>();
EXPECT_TRUE(ptr->type()->Is<type::F32>());
auto* ptr = TypeOf(mem)->As<sem::Pointer>();
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
ASSERT_TRUE(Sem().Get(mem)->Is<sem::StructMemberAccess>());
EXPECT_EQ(Sem()
.Get(mem)
@ -932,10 +932,10 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(mem), nullptr);
ASSERT_TRUE(TypeOf(mem)->Is<type::Pointer>());
ASSERT_TRUE(TypeOf(mem)->Is<sem::Pointer>());
auto* ptr = TypeOf(mem)->As<type::Pointer>();
EXPECT_TRUE(ptr->type()->Is<type::F32>());
auto* ptr = TypeOf(mem)->As<sem::Pointer>();
EXPECT_TRUE(ptr->type()->Is<sem::F32>());
ASSERT_TRUE(Sem().Get(mem)->Is<sem::StructMemberAccess>());
}
@ -948,9 +948,9 @@ TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(mem), nullptr);
ASSERT_TRUE(TypeOf(mem)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(mem)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(mem)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(mem)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(mem)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(mem)->As<sem::Vector>()->size(), 4u);
ASSERT_TRUE(Sem().Get(mem)->Is<sem::Swizzle>());
EXPECT_THAT(Sem().Get(mem)->As<sem::Swizzle>()->Indices(),
ElementsAre(0, 2, 1, 3));
@ -965,10 +965,10 @@ TEST_F(ResolverTest, Expr_MemberAccessor_VectorSwizzle_SingleElement) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(mem), nullptr);
ASSERT_TRUE(TypeOf(mem)->Is<type::Pointer>());
ASSERT_TRUE(TypeOf(mem)->Is<sem::Pointer>());
auto* ptr = TypeOf(mem)->As<type::Pointer>();
ASSERT_TRUE(ptr->type()->Is<type::F32>());
auto* ptr = TypeOf(mem)->As<sem::Pointer>();
ASSERT_TRUE(ptr->type()->Is<sem::F32>());
ASSERT_TRUE(Sem().Get(mem)->Is<sem::Swizzle>());
EXPECT_THAT(Sem().Get(mem)->As<sem::Swizzle>()->Indices(), ElementsAre(2));
}
@ -1004,7 +1004,7 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
ast::DecorationList{});
auto* stB = ty.struct_("B", strctB);
type::Vector vecB(stB, 3);
sem::Vector vecB(stB, 3);
auto* strctA = create<ast::Struct>(
ast::StructMemberList{Member("mem", &vecB)}, ast::DecorationList{});
@ -1019,9 +1019,9 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(mem), nullptr);
ASSERT_TRUE(TypeOf(mem)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(mem)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(mem)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(mem)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(mem)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(mem)->As<sem::Vector>()->size(), 2u);
ASSERT_TRUE(Sem().Get(mem)->Is<sem::Swizzle>());
}
@ -1041,7 +1041,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(expr), nullptr);
EXPECT_TRUE(TypeOf(expr)->Is<type::F32>());
EXPECT_TRUE(TypeOf(expr)->Is<sem::F32>());
}
namespace ExprBinaryTest {
@ -1247,17 +1247,17 @@ TEST_P(Expr_Binary_Test_WithAlias_Valid, All) {
<< rhs_type->FriendlyName(Symbols());
// For vectors and matrices, wrap the sub type in an alias
auto make_alias = [this](type::Type* type) -> type::Type* {
type::Type* result;
if (auto* v = type->As<type::Vector>()) {
result = create<type::Vector>(
create<type::Alias>(Symbols().New(), v->type()), v->size());
} else if (auto* m = type->As<type::Matrix>()) {
auto make_alias = [this](sem::Type* type) -> sem::Type* {
sem::Type* result;
if (auto* v = type->As<sem::Vector>()) {
result = create<sem::Vector>(
create<sem::Alias>(Symbols().New(), v->type()), v->size());
} else if (auto* m = type->As<sem::Matrix>()) {
result =
create<type::Matrix>(create<type::Alias>(Symbols().New(), m->type()),
m->rows(), m->columns());
create<sem::Matrix>(create<sem::Alias>(Symbols().New(), m->type()),
m->rows(), m->columns());
} else {
result = create<type::Alias>(Symbols().New(), type);
result = create<sem::Alias>(Symbols().New(), type);
}
return result;
};
@ -1358,20 +1358,20 @@ TEST_P(Expr_Binary_Test_Invalid_VectorMatrixMultiply, All) {
uint32_t mat_rows = std::get<2>(GetParam());
uint32_t mat_cols = std::get<3>(GetParam());
type::Type* lhs_type;
type::Type* rhs_type;
type::Type* result_type;
sem::Type* lhs_type;
sem::Type* rhs_type;
sem::Type* result_type;
bool is_valid_expr;
if (vec_by_mat) {
lhs_type = create<type::Vector>(ty.f32(), vec_size);
rhs_type = create<type::Matrix>(ty.f32(), mat_rows, mat_cols);
result_type = create<type::Vector>(ty.f32(), mat_cols);
lhs_type = create<sem::Vector>(ty.f32(), vec_size);
rhs_type = create<sem::Matrix>(ty.f32(), mat_rows, mat_cols);
result_type = create<sem::Vector>(ty.f32(), mat_cols);
is_valid_expr = vec_size == mat_rows;
} else {
lhs_type = create<type::Matrix>(ty.f32(), mat_rows, mat_cols);
rhs_type = create<type::Vector>(ty.f32(), vec_size);
result_type = create<type::Vector>(ty.f32(), mat_rows);
lhs_type = create<sem::Matrix>(ty.f32(), mat_rows, mat_cols);
rhs_type = create<sem::Vector>(ty.f32(), vec_size);
result_type = create<sem::Vector>(ty.f32(), mat_rows);
is_valid_expr = vec_size == mat_cols;
}
@ -1410,10 +1410,9 @@ TEST_P(Expr_Binary_Test_Invalid_MatrixMatrixMultiply, All) {
uint32_t rhs_mat_rows = std::get<2>(GetParam());
uint32_t rhs_mat_cols = std::get<3>(GetParam());
auto* lhs_type = create<type::Matrix>(ty.f32(), lhs_mat_rows, lhs_mat_cols);
auto* rhs_type = create<type::Matrix>(ty.f32(), rhs_mat_rows, rhs_mat_cols);
auto* result_type =
create<type::Matrix>(ty.f32(), lhs_mat_rows, rhs_mat_cols);
auto* lhs_type = create<sem::Matrix>(ty.f32(), lhs_mat_rows, lhs_mat_cols);
auto* rhs_type = create<sem::Matrix>(ty.f32(), rhs_mat_rows, rhs_mat_cols);
auto* result_type = create<sem::Matrix>(ty.f32(), lhs_mat_rows, rhs_mat_cols);
Global("lhs", lhs_type, ast::StorageClass::kInput);
Global("rhs", rhs_type, ast::StorageClass::kInput);
@ -1455,9 +1454,9 @@ TEST_P(UnaryOpExpressionTest, Expr_UnaryOp) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(der), nullptr);
ASSERT_TRUE(TypeOf(der)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(der)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(der)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(der)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(der)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(der)->As<sem::Vector>()->size(), 4u);
}
INSTANTIATE_TEST_SUITE_P(ResolverTest,
UnaryOpExpressionTest,

View File

@ -105,96 +105,96 @@ template <typename T>
class ResolverTestWithParam : public TestHelper,
public testing::TestWithParam<T> {};
inline type::Type* ty_bool_(const ProgramBuilder::TypesBuilder& ty) {
inline sem::Type* ty_bool_(const ProgramBuilder::TypesBuilder& ty) {
return ty.bool_();
}
inline type::Type* ty_i32(const ProgramBuilder::TypesBuilder& ty) {
inline sem::Type* ty_i32(const ProgramBuilder::TypesBuilder& ty) {
return ty.i32();
}
inline type::Type* ty_u32(const ProgramBuilder::TypesBuilder& ty) {
inline sem::Type* ty_u32(const ProgramBuilder::TypesBuilder& ty) {
return ty.u32();
}
inline type::Type* ty_f32(const ProgramBuilder::TypesBuilder& ty) {
inline sem::Type* ty_f32(const ProgramBuilder::TypesBuilder& ty) {
return ty.f32();
}
using create_type_func_ptr =
type::Type* (*)(const ProgramBuilder::TypesBuilder& ty);
sem::Type* (*)(const ProgramBuilder::TypesBuilder& ty);
template <typename T>
type::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) {
return ty.vec2<T>();
}
template <create_type_func_ptr create_type>
type::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) {
auto* type = create_type(ty);
return ty.vec2(type);
}
template <typename T>
type::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) {
return ty.vec3<T>();
}
template <create_type_func_ptr create_type>
type::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) {
auto* type = create_type(ty);
return ty.vec3(type);
}
template <typename T>
type::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) {
return ty.vec4<T>();
}
template <create_type_func_ptr create_type>
type::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) {
auto* type = create_type(ty);
return ty.vec4(type);
}
template <typename T>
type::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat2x2<T>();
}
template <create_type_func_ptr create_type>
type::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) {
auto* type = create_type(ty);
return ty.mat2x2(type);
}
template <typename T>
type::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat3x3<T>();
}
template <create_type_func_ptr create_type>
type::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) {
auto* type = create_type(ty);
return ty.mat3x3(type);
}
template <typename T>
type::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) {
return ty.mat4x4<T>();
}
template <create_type_func_ptr create_type>
type::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) {
auto* type = create_type(ty);
return ty.mat4x4(type);
}
template <create_type_func_ptr create_type>
type::Type* ty_alias(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_alias(const ProgramBuilder::TypesBuilder& ty) {
auto* type = create_type(ty);
return ty.alias("alias_" + type->type_name(), type);
}
template <create_type_func_ptr create_type>
type::Type* ty_access(const ProgramBuilder::TypesBuilder& ty) {
sem::Type* ty_access(const ProgramBuilder::TypesBuilder& ty) {
auto* type = create_type(ty);
return ty.access(ast::AccessControl::kReadOnly, type);
}

View File

@ -19,11 +19,11 @@ namespace resolver {
namespace {
/// @return the element type of `type` for vec and mat, otherwise `type` itself
type::Type* ElementTypeOf(type::Type* type) {
if (auto* v = type->As<type::Vector>()) {
sem::Type* ElementTypeOf(sem::Type* type) {
if (auto* v = type->As<sem::Vector>()) {
return v->type();
}
if (auto* m = type->As<type::Matrix>()) {
if (auto* m = type->As<sem::Matrix>()) {
return m->type();
}
return type;

View File

@ -912,9 +912,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec2_Success_ZeroValue) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec2F32_Success_Scalar) {
@ -924,9 +924,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec2F32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec2U32_Success_Scalar) {
@ -936,9 +936,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec2U32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::U32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec2I32_Success_Scalar) {
@ -948,9 +948,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec2I32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::I32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec2Bool_Success_Scalar) {
@ -960,9 +960,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec2Bool_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::Bool>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec2_Success_Identity) {
@ -972,9 +972,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec2_Success_Identity) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
}
TEST_F(ResolverValidationTest,
@ -985,9 +985,9 @@ TEST_F(ResolverValidationTest,
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 2u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 2u);
}
TEST_F(ResolverValidationTest,
@ -1174,9 +1174,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec3_Success_ZeroValue) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec3F32_Success_Scalar) {
@ -1186,9 +1186,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec3F32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec3U32_Success_Scalar) {
@ -1198,9 +1198,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec3U32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::U32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec3I32_Success_Scalar) {
@ -1210,9 +1210,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec3I32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::I32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec3Bool_Success_Scalar) {
@ -1222,9 +1222,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec3Bool_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::Bool>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec3_Success_Vec2AndScalar) {
@ -1234,9 +1234,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec3_Success_Vec2AndScalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec3_Success_ScalarAndVec2) {
@ -1246,9 +1246,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec3_Success_ScalarAndVec2) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec3_Success_Identity) {
@ -1258,9 +1258,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec3_Success_Identity) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest,
@ -1271,9 +1271,9 @@ TEST_F(ResolverValidationTest,
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 3u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 3u);
}
TEST_F(ResolverValidationTest,
@ -1528,9 +1528,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_ZeroValue) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4F32_Success_Scalar) {
@ -1540,9 +1540,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4F32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4U32_Success_Scalar) {
@ -1552,9 +1552,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4U32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::U32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::U32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4I32_Success_Scalar) {
@ -1564,9 +1564,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4I32_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::I32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::I32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4Bool_Success_Scalar) {
@ -1576,9 +1576,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4Bool_Success_Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::Bool>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::Bool>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_Vec2ScalarScalar) {
@ -1588,9 +1588,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_Vec2ScalarScalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_ScalarVec2Scalar) {
@ -1600,9 +1600,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_ScalarVec2Scalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_ScalarScalarVec2) {
@ -1612,9 +1612,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_ScalarScalarVec2) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_Vec2AndVec2) {
@ -1624,9 +1624,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_Vec2AndVec2) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_Vec3AndScalar) {
@ -1636,9 +1636,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_Vec3AndScalar) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_ScalarAndVec3) {
@ -1648,9 +1648,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_ScalarAndVec3) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_Identity) {
@ -1660,9 +1660,9 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vec4_Success_Identity) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest,
@ -1673,9 +1673,9 @@ TEST_F(ResolverValidationTest,
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest,
@ -1700,9 +1700,9 @@ TEST_F(ResolverValidationTest,
EXPECT_TRUE(r()->Resolve()) << r()->error();
ASSERT_NE(TypeOf(tc), nullptr);
ASSERT_TRUE(TypeOf(tc)->Is<type::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<type::Vector>()->type()->Is<type::F32>());
EXPECT_EQ(TypeOf(tc)->As<type::Vector>()->size(), 4u);
ASSERT_TRUE(TypeOf(tc)->Is<sem::Vector>());
EXPECT_TRUE(TypeOf(tc)->As<sem::Vector>()->type()->Is<sem::F32>());
EXPECT_EQ(TypeOf(tc)->As<sem::Vector>()->size(), 4u);
}
TEST_F(ResolverValidationTest, Expr_Constructor_Vector_Alias_Argument_Error) {
@ -1731,7 +1731,7 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vector_Alias_Argument_Success) {
TEST_F(ResolverValidationTest, Expr_Constructor_Vector_ElementTypeAlias_Error) {
auto* f32_alias = ty.alias("Float32", ty.f32());
auto* vec_type = create<type::Vector>(f32_alias, 2);
auto* vec_type = create<sem::Vector>(f32_alias, 2);
// vec2<Float32>(1.0f, 1u)
auto* tc = create<ast::TypeConstructorExpression>(
@ -1749,7 +1749,7 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vector_ElementTypeAlias_Error) {
TEST_F(ResolverValidationTest,
Expr_Constructor_Vector_ElementTypeAlias_Success) {
auto* f32_alias = ty.alias("Float32", ty.f32());
auto* vec_type = create<type::Vector>(f32_alias, 2);
auto* vec_type = create<sem::Vector>(f32_alias, 2);
// vec2<Float32>(1.0f, 1.0f)
auto* tc = create<ast::TypeConstructorExpression>(Source{{12, 34}}, vec_type,
@ -1762,7 +1762,7 @@ TEST_F(ResolverValidationTest,
TEST_F(ResolverValidationTest,
Expr_Constructor_Vector_ArgumentElementTypeAlias_Error) {
auto* f32_alias = ty.alias("Float32", ty.f32());
auto* vec_type = create<type::Vector>(f32_alias, 2);
auto* vec_type = create<sem::Vector>(f32_alias, 2);
// vec3<u32>(vec<Float32>(), 1.0f)
auto* tc = vec3<u32>(create<ast::TypeConstructorExpression>(
@ -1779,7 +1779,7 @@ TEST_F(ResolverValidationTest,
TEST_F(ResolverValidationTest,
Expr_Constructor_Vector_ArgumentElementTypeAlias_Success) {
auto* f32_alias = ty.alias("Float32", ty.f32());
auto* vec_type = create<type::Vector>(f32_alias, 2);
auto* vec_type = create<sem::Vector>(f32_alias, 2);
// vec3<f32>(vec<Float32>(), 1.0f)
auto* tc = vec3<f32>(create<ast::TypeConstructorExpression>(
@ -1811,8 +1811,8 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_Error_TooFewArguments) {
// matNxM<f32>(vecM<f32>(), ...); with N - 1 arguments
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<type::Vector>(ty.f32(), param.rows);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<sem::Vector>(ty.f32(), param.rows);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns - 1; i++) {
@ -1835,8 +1835,8 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_Error_TooManyArguments) {
// matNxM<f32>(vecM<f32>(), ...); with N + 1 arguments
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<type::Vector>(ty.f32(), param.rows);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<sem::Vector>(ty.f32(), param.rows);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns + 1; i++) {
@ -1859,7 +1859,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_Error_InvalidArgumentType) {
// matNxM<f32>(1.0, 1.0, ...); N arguments
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) {
@ -1888,9 +1888,9 @@ TEST_P(MatrixConstructorTest,
return;
}
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* valid_vec_type = create<type::Vector>(ty.f32(), param.rows);
auto* invalid_vec_type = create<type::Vector>(ty.f32(), param.rows - 1);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* valid_vec_type = create<sem::Vector>(ty.f32(), param.rows);
auto* invalid_vec_type = create<sem::Vector>(ty.f32(), param.rows - 1);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns - 1; i++) {
@ -1924,9 +1924,9 @@ TEST_P(MatrixConstructorTest,
return;
}
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* valid_vec_type = create<type::Vector>(ty.f32(), param.rows);
auto* invalid_vec_type = create<type::Vector>(ty.f32(), param.rows + 1);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* valid_vec_type = create<sem::Vector>(ty.f32(), param.rows);
auto* invalid_vec_type = create<sem::Vector>(ty.f32(), param.rows + 1);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns - 1; i++) {
@ -1954,8 +1954,8 @@ TEST_P(MatrixConstructorTest,
// matNxM<f32>(vecM<u32>(), ...); with N arguments
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<type::Vector>(ty.u32(), param.rows);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<sem::Vector>(ty.u32(), param.rows);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) {
@ -1978,7 +1978,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ZeroValue_Success) {
// matNxM<f32>();
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* tc = create<ast::TypeConstructorExpression>(Source{{12, 40}},
matrix_type, ExprList());
WrapInFunction(tc);
@ -1990,8 +1990,8 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_WithArguments_Success) {
// matNxM<f32>(vecM<f32>(), ...); with N arguments
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<type::Vector>(ty.f32(), param.rows);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<sem::Vector>(ty.f32(), param.rows);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) {
@ -2011,9 +2011,8 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Error) {
const auto param = GetParam();
auto* f32_alias = ty.alias("Float32", ty.f32());
auto* matrix_type =
create<type::Matrix>(f32_alias, param.rows, param.columns);
auto* vec_type = create<type::Vector>(ty.u32(), param.rows);
auto* matrix_type = create<sem::Matrix>(f32_alias, param.rows, param.columns);
auto* vec_type = create<sem::Vector>(ty.u32(), param.rows);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) {
@ -2037,9 +2036,8 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Success) {
const auto param = GetParam();
auto* f32_alias = ty.alias("Float32", ty.f32());
auto* matrix_type =
create<type::Matrix>(f32_alias, param.rows, param.columns);
auto* vec_type = create<type::Vector>(ty.f32(), param.rows);
auto* matrix_type = create<sem::Matrix>(f32_alias, param.rows, param.columns);
auto* vec_type = create<sem::Vector>(ty.f32(), param.rows);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) {
@ -2069,8 +2067,8 @@ TEST_F(ResolverValidationTest, Expr_MatrixConstructor_ArgumentTypeAlias_Error) {
TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentTypeAlias_Success) {
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<type::Vector>(ty.f32(), param.rows);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* vec_type = create<sem::Vector>(ty.f32(), param.rows);
auto* vec_alias = ty.alias("VectorFloat2", vec_type);
ast::ExpressionList args;
@ -2088,9 +2086,9 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentTypeAlias_Success) {
TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentElementTypeAlias_Error) {
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* f32_alias = ty.alias("UnsignedInt", ty.u32());
auto* vec_type = create<type::Vector>(f32_alias, param.rows);
auto* vec_type = create<sem::Vector>(f32_alias, param.rows);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) {
@ -2112,9 +2110,9 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentElementTypeAlias_Error) {
TEST_P(MatrixConstructorTest,
Expr_Constructor_ArgumentElementTypeAlias_Success) {
const auto param = GetParam();
auto* matrix_type = create<type::Matrix>(ty.f32(), param.rows, param.columns);
auto* matrix_type = create<sem::Matrix>(ty.f32(), param.rows, param.columns);
auto* f32_alias = ty.alias("Float32", ty.f32());
auto* vec_type = create<type::Vector>(f32_alias, param.rows);
auto* vec_type = create<sem::Vector>(f32_alias, param.rows);
ast::ExpressionList args;
for (uint32_t i = 1; i <= param.columns; i++) {

View File

@ -19,7 +19,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::Array);
namespace tint {
namespace sem {
Array::Array(type::ArrayType* type,
Array::Array(sem::ArrayType* type,
uint32_t align,
uint32_t size,
uint32_t stride)

View File

@ -21,12 +21,9 @@
namespace tint {
// Forward declarations
namespace type {
class ArrayType;
} // namespace type
namespace sem {
// Forward declarations
class ArrayType;
/// Array holds the semantic information for Array nodes.
class Array : public Castable<Array, Node> {
@ -37,10 +34,10 @@ class Array : public Castable<Array, Node> {
/// @param size the byte size of the structure
/// @param stride the number of bytes from the start of one element of the
/// array to the start of the next element
Array(type::ArrayType* type, uint32_t align, uint32_t size, uint32_t stride);
Array(sem::ArrayType* type, uint32_t align, uint32_t size, uint32_t stride);
/// @return the resolved type of the Array
type::ArrayType* Type() const { return type_; }
sem::ArrayType* Type() const { return type_; }
/// @returns the byte alignment of the array
/// @note this may differ from the alignment of a structure member of this
@ -57,7 +54,7 @@ class Array : public Castable<Array, Node> {
uint32_t Stride() const { return stride_; }
private:
type::ArrayType* const type_;
sem::ArrayType* const type_;
uint32_t const align_;
uint32_t const size_;
uint32_t const stride_;

View File

@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::CallTarget);
namespace tint {
namespace sem {
CallTarget::CallTarget(type::Type* return_type, const ParameterList& parameters)
CallTarget::CallTarget(sem::Type* return_type, const ParameterList& parameters)
: return_type_(return_type), parameters_(parameters) {}
CallTarget::~CallTarget() = default;

View File

@ -23,9 +23,9 @@
namespace tint {
// Forward declarations
namespace type {
namespace sem {
class Type;
} // namespace type
} // namespace sem
namespace sem {
@ -50,7 +50,7 @@ struct Parameter {
};
/// Parameter type
type::Type* const type;
sem::Type* const type;
/// Parameter usage
Usage const usage = Usage::kNone;
};
@ -80,10 +80,10 @@ class CallTarget : public Castable<CallTarget, Node> {
/// Constructor
/// @param return_type the return type of the call target
/// @param parameters the parameters for the call target
CallTarget(type::Type* return_type, const ParameterList& parameters);
CallTarget(sem::Type* return_type, const ParameterList& parameters);
/// @return the return type of the call target
type::Type* ReturnType() const { return return_type_; }
sem::Type* ReturnType() const { return return_type_; }
/// Destructor
~CallTarget() override;
@ -92,7 +92,7 @@ class CallTarget : public Castable<CallTarget, Node> {
const ParameterList& Parameters() const { return parameters_; }
private:
type::Type* const return_type_;
sem::Type* const return_type_;
ParameterList const parameters_;
};

View File

@ -20,7 +20,7 @@ namespace tint {
namespace sem {
Expression::Expression(ast::Expression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement)
: declaration_(declaration),
type_(type->UnwrapIfNeeded()),

View File

@ -19,16 +19,10 @@
#include "src/sem/node.h"
namespace tint {
namespace sem {
// Forward declarations
namespace sem {
class Statement;
} // namespace sem
namespace type {
class Type;
} // namespace type
namespace sem {
/// Expression holds the semantic information for expression nodes.
class Expression : public Castable<Expression, Node> {
@ -38,11 +32,11 @@ class Expression : public Castable<Expression, Node> {
/// @param type the resolved type of the expression
/// @param statement the statement that owns this expression
Expression(ast::Expression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement);
/// @return the resolved type of the expression
type::Type* Type() const { return type_; }
sem::Type* Type() const { return type_; }
/// @return the statement that owns this expression
Statement* Stmt() const { return statement_; }
@ -52,7 +46,7 @@ class Expression : public Castable<Expression, Node> {
private:
ast::Expression* declaration_;
type::Type* const type_;
sem::Type* const type_;
Statement* const statement_;
};

View File

@ -117,12 +117,12 @@ Function::ReferencedBuiltinVariables() const {
}
Function::VariableBindings Function::ReferencedSamplerVariables() const {
return ReferencedSamplerVariablesImpl(type::SamplerKind::kSampler);
return ReferencedSamplerVariablesImpl(sem::SamplerKind::kSampler);
}
Function::VariableBindings Function::ReferencedComparisonSamplerVariables()
const {
return ReferencedSamplerVariablesImpl(type::SamplerKind::kComparisonSampler);
return ReferencedSamplerVariablesImpl(sem::SamplerKind::kComparisonSampler);
}
Function::VariableBindings Function::ReferencedSampledTextureVariables() const {
@ -140,7 +140,7 @@ Function::VariableBindings Function::ReferencedStorageTextureVariables() const {
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type =
var->Declaration()->declared_type()->UnwrapIfNeeded();
auto* storage_texture = unwrapped_type->As<type::StorageTexture>();
auto* storage_texture = unwrapped_type->As<sem::StorageTexture>();
if (storage_texture == nullptr) {
continue;
}
@ -158,7 +158,7 @@ Function::VariableBindings Function::ReferencedDepthTextureVariables() const {
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type =
var->Declaration()->declared_type()->UnwrapIfNeeded();
auto* storage_texture = unwrapped_type->As<type::DepthTexture>();
auto* storage_texture = unwrapped_type->As<sem::DepthTexture>();
if (storage_texture == nullptr) {
continue;
}
@ -180,13 +180,13 @@ bool Function::HasAncestorEntryPoint(Symbol symbol) const {
}
Function::VariableBindings Function::ReferencedSamplerVariablesImpl(
type::SamplerKind kind) const {
sem::SamplerKind kind) const {
VariableBindings ret;
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type =
var->Declaration()->declared_type()->UnwrapIfNeeded();
auto* sampler = unwrapped_type->As<type::Sampler>();
auto* sampler = unwrapped_type->As<sem::Sampler>();
if (sampler == nullptr || sampler->kind() != kind) {
continue;
}
@ -205,13 +205,13 @@ Function::VariableBindings Function::ReferencedSampledTextureVariablesImpl(
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type =
var->Declaration()->declared_type()->UnwrapIfNeeded();
auto* texture = unwrapped_type->As<type::Texture>();
auto* texture = unwrapped_type->As<sem::Texture>();
if (texture == nullptr) {
continue;
}
auto is_multisampled = texture->Is<type::MultisampledTexture>();
auto is_sampled = texture->Is<type::SampledTexture>();
auto is_multisampled = texture->Is<sem::MultisampledTexture>();
auto is_sampled = texture->Is<sem::SampledTexture>();
if ((multisampled && !is_multisampled) || (!multisampled && !is_sampled)) {
continue;

View File

@ -142,7 +142,7 @@ class Function : public Castable<Function, CallTarget> {
bool HasAncestorEntryPoint(Symbol sym) const;
private:
VariableBindings ReferencedSamplerVariablesImpl(type::SamplerKind kind) const;
VariableBindings ReferencedSamplerVariablesImpl(sem::SamplerKind kind) const;
VariableBindings ReferencedSampledTextureVariablesImpl(
bool multisampled) const;

View File

@ -195,7 +195,7 @@ bool IsBarrierIntrinsic(IntrinsicType i) {
}
Intrinsic::Intrinsic(IntrinsicType type,
type::Type* return_type,
sem::Type* return_type,
const ParameterList& parameters)
: Base(return_type, parameters), type_(type) {}

View File

@ -174,7 +174,7 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
/// @param return_type the return type for the intrinsic call
/// @param parameters the parameters for the intrinsic overload
Intrinsic(IntrinsicType type,
type::Type* return_type,
sem::Type* return_type,
const ParameterList& parameters);
/// Destructor

View File

@ -26,7 +26,7 @@ namespace sem {
MemberAccessorExpression::MemberAccessorExpression(
ast::MemberAccessorExpression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement)
: Base(declaration, type, statement) {}
@ -34,7 +34,7 @@ MemberAccessorExpression::~MemberAccessorExpression() = default;
StructMemberAccess::StructMemberAccess(
ast::MemberAccessorExpression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement,
const StructMember* member)
: Base(declaration, type, statement), member_(member) {}
@ -42,7 +42,7 @@ StructMemberAccess::StructMemberAccess(
StructMemberAccess::~StructMemberAccess() = default;
Swizzle::Swizzle(ast::MemberAccessorExpression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement,
std::vector<uint32_t> indices)
: Base(declaration, type, statement), indices_(std::move(indices)) {}

View File

@ -42,7 +42,7 @@ class MemberAccessorExpression
/// @param type the resolved type of the expression
/// @param statement the statement that owns this expression
MemberAccessorExpression(ast::MemberAccessorExpression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement);
/// Destructor
@ -61,7 +61,7 @@ class StructMemberAccess
/// @param statement the statement that owns this expression
/// @param member the structure member
StructMemberAccess(ast::MemberAccessorExpression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement,
const StructMember* member);
@ -85,7 +85,7 @@ class Swizzle : public Castable<Swizzle, MemberAccessorExpression> {
/// @param statement the statement that
/// @param indices the swizzle indices
Swizzle(ast::MemberAccessorExpression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement,
std::vector<uint32_t> indices);

View File

@ -23,7 +23,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::StructMember);
namespace tint {
namespace sem {
Struct::Struct(type::StructType* type,
Struct::Struct(sem::StructType* type,
StructMemberList members,
uint32_t align,
uint32_t size,

View File

@ -30,12 +30,11 @@ namespace tint {
namespace ast {
class StructMember;
} // namespace ast
namespace type {
class StructType;
} // namespace type
namespace sem {
// Forward declarations
class StructType;
class StructMember;
/// A vector of StructMember pointers.
@ -63,7 +62,7 @@ class Struct : public Castable<Struct, Node> {
/// alignment padding
/// @param storage_class_usage a set of all the storage class usages
/// @param pipeline_stage_uses a set of all the pipeline stage uses
Struct(type::StructType* type,
Struct(sem::StructType* type,
StructMemberList members,
uint32_t align,
uint32_t size,
@ -75,7 +74,7 @@ class Struct : public Castable<Struct, Node> {
~Struct() override;
/// @returns the structure type
type::StructType* Type() const { return type_; }
sem::StructType* Type() const { return type_; }
/// @returns the members of the structure
const StructMemberList& Members() const { return members_; }
@ -128,7 +127,7 @@ class Struct : public Castable<Struct, Node> {
}
private:
type::StructType* const type_;
sem::StructType* const type_;
StructMemberList const members_;
uint32_t const align_;
uint32_t const size_;

View File

@ -29,21 +29,18 @@ class Statement;
class StructMember;
class Variable;
} // namespace ast
namespace type {
class ArrayType;
class StructType;
} // namespace type
namespace sem {
// Forward declarations
class Array;
class ArrayType;
class Call;
class Expression;
class Function;
class MemberAccessorExpression;
class Statement;
class Struct;
class StructType;
class StructMember;
class Variable;
@ -53,13 +50,13 @@ class Variable;
/// rules will be used to infer the return type based on the argument type.
struct TypeMappings {
//! @cond Doxygen_Suppress
Array* operator()(type::ArrayType*);
Array* operator()(sem::ArrayType*);
Call* operator()(ast::CallExpression*);
Expression* operator()(ast::Expression*);
Function* operator()(ast::Function*);
MemberAccessorExpression* operator()(ast::MemberAccessorExpression*);
Statement* operator()(ast::Statement*);
Struct* operator()(type::StructType*);
Struct* operator()(sem::StructType*);
StructMember* operator()(ast::StructMember*);
Variable* operator()(ast::Variable*);
//! @endcond

View File

@ -24,18 +24,18 @@ namespace tint {
namespace sem {
Variable::Variable(const ast::Variable* declaration,
type::Type* type,
sem::Type* type,
ast::StorageClass storage_class)
: declaration_(declaration), type_(type), storage_class_(storage_class) {}
Variable::~Variable() = default;
type::Type* Variable::DeclaredType() const {
sem::Type* Variable::DeclaredType() const {
return declaration_->declared_type();
}
VariableUser::VariableUser(ast::IdentifierExpression* declaration,
type::Type* type,
sem::Type* type,
Statement* statement,
sem::Variable* variable)
: Base(declaration, type, statement), variable_(variable) {}

Some files were not shown because too many files have changed in this diff Show More