tint/ast: Remove unnecessary ast:: prefixes
These uses are already in the ast namespace, so do not need the extra qualification. Change-Id: I5e66048c9485c55b72e61ffa5b85b17ba1c780d0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120761 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
parent
4a88a3287e
commit
5662f79b24
|
@ -127,11 +127,11 @@ class BinaryExpression final : public Castable<BinaryExpression, Expression> {
|
||||||
/// @returns true if the op is an arithmetic operation
|
/// @returns true if the op is an arithmetic operation
|
||||||
inline bool IsArithmetic(BinaryOp op) {
|
inline bool IsArithmetic(BinaryOp op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kAdd:
|
case BinaryOp::kAdd:
|
||||||
case ast::BinaryOp::kSubtract:
|
case BinaryOp::kSubtract:
|
||||||
case ast::BinaryOp::kMultiply:
|
case BinaryOp::kMultiply:
|
||||||
case ast::BinaryOp::kDivide:
|
case BinaryOp::kDivide:
|
||||||
case ast::BinaryOp::kModulo:
|
case BinaryOp::kModulo:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -142,12 +142,12 @@ inline bool IsArithmetic(BinaryOp op) {
|
||||||
/// @returns true if the op is a comparison operation
|
/// @returns true if the op is a comparison operation
|
||||||
inline bool IsComparison(BinaryOp op) {
|
inline bool IsComparison(BinaryOp op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kEqual:
|
case BinaryOp::kEqual:
|
||||||
case ast::BinaryOp::kNotEqual:
|
case BinaryOp::kNotEqual:
|
||||||
case ast::BinaryOp::kLessThan:
|
case BinaryOp::kLessThan:
|
||||||
case ast::BinaryOp::kLessThanEqual:
|
case BinaryOp::kLessThanEqual:
|
||||||
case ast::BinaryOp::kGreaterThan:
|
case BinaryOp::kGreaterThan:
|
||||||
case ast::BinaryOp::kGreaterThanEqual:
|
case BinaryOp::kGreaterThanEqual:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -158,9 +158,9 @@ inline bool IsComparison(BinaryOp op) {
|
||||||
/// @returns true if the op is a bitwise operation
|
/// @returns true if the op is a bitwise operation
|
||||||
inline bool IsBitwise(BinaryOp op) {
|
inline bool IsBitwise(BinaryOp op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kAnd:
|
case BinaryOp::kAnd:
|
||||||
case ast::BinaryOp::kOr:
|
case BinaryOp::kOr:
|
||||||
case ast::BinaryOp::kXor:
|
case BinaryOp::kXor:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -171,8 +171,8 @@ inline bool IsBitwise(BinaryOp op) {
|
||||||
/// @returns true if the op is a bit shift operation
|
/// @returns true if the op is a bit shift operation
|
||||||
inline bool IsBitshift(BinaryOp op) {
|
inline bool IsBitshift(BinaryOp op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kShiftLeft:
|
case BinaryOp::kShiftLeft:
|
||||||
case ast::BinaryOp::kShiftRight:
|
case BinaryOp::kShiftRight:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -181,8 +181,8 @@ inline bool IsBitshift(BinaryOp op) {
|
||||||
|
|
||||||
inline bool BinaryExpression::IsLogical() const {
|
inline bool BinaryExpression::IsLogical() const {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case ast::BinaryOp::kLogicalAnd:
|
case BinaryOp::kLogicalAnd:
|
||||||
case ast::BinaryOp::kLogicalOr:
|
case BinaryOp::kLogicalOr:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace tint::ast {
|
||||||
BindingAttribute::BindingAttribute(ProgramID pid,
|
BindingAttribute::BindingAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* exp)
|
const Expression* exp)
|
||||||
: Base(pid, nid, src), expr(exp) {}
|
: Base(pid, nid, src), expr(exp) {}
|
||||||
|
|
||||||
BindingAttribute::~BindingAttribute() = default;
|
BindingAttribute::~BindingAttribute() = default;
|
||||||
|
|
|
@ -30,7 +30,7 @@ class BindingAttribute final : public Castable<BindingAttribute, Attribute> {
|
||||||
/// @param nid the unique node identifier
|
/// @param nid the unique node identifier
|
||||||
/// @param src the source of this node
|
/// @param src the source of this node
|
||||||
/// @param expr the binding expression
|
/// @param expr the binding expression
|
||||||
BindingAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* expr);
|
BindingAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* expr);
|
||||||
~BindingAttribute() override;
|
~BindingAttribute() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
|
@ -43,7 +43,7 @@ class BindingAttribute final : public Castable<BindingAttribute, Attribute> {
|
||||||
const BindingAttribute* Clone(CloneContext* ctx) const override;
|
const BindingAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// the binding expression
|
/// the binding expression
|
||||||
const ast::Expression* const expr;
|
const Expression* const expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -63,8 +63,7 @@ TEST_F(BlockStatementTest, Assert_Null_Statement) {
|
||||||
EXPECT_FATAL_FAILURE(
|
EXPECT_FATAL_FAILURE(
|
||||||
{
|
{
|
||||||
ProgramBuilder b;
|
ProgramBuilder b;
|
||||||
b.create<BlockStatement>(utils::Vector<const ast::Statement*, 1>{nullptr},
|
b.create<BlockStatement>(utils::Vector<const Statement*, 1>{nullptr}, utils::Empty);
|
||||||
utils::Empty);
|
|
||||||
},
|
},
|
||||||
"internal compiler error");
|
"internal compiler error");
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,13 +128,13 @@ std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::Type TextureOverloadCase::BuildResultVectorComponentType(ProgramBuilder* b) const {
|
Type TextureOverloadCase::BuildResultVectorComponentType(ProgramBuilder* b) const {
|
||||||
switch (texture_data_type) {
|
switch (texture_data_type) {
|
||||||
case ast::builtin::test::TextureDataType::kF32:
|
case builtin::test::TextureDataType::kF32:
|
||||||
return b->ty.f32();
|
return b->ty.f32();
|
||||||
case ast::builtin::test::TextureDataType::kU32:
|
case builtin::test::TextureDataType::kU32:
|
||||||
return b->ty.u32();
|
return b->ty.u32();
|
||||||
case ast::builtin::test::TextureDataType::kI32:
|
case builtin::test::TextureDataType::kI32:
|
||||||
return b->ty.i32();
|
return b->ty.i32();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,31 +142,31 @@ ast::Type TextureOverloadCase::BuildResultVectorComponentType(ProgramBuilder* b)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b) const {
|
const Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b) const {
|
||||||
utils::Vector attrs{
|
utils::Vector attrs{
|
||||||
b->Group(0_u),
|
b->Group(0_u),
|
||||||
b->Binding(0_a),
|
b->Binding(0_a),
|
||||||
};
|
};
|
||||||
switch (texture_kind) {
|
switch (texture_kind) {
|
||||||
case ast::builtin::test::TextureKind::kRegular:
|
case builtin::test::TextureKind::kRegular:
|
||||||
return b->GlobalVar(
|
return b->GlobalVar(
|
||||||
kTextureName,
|
kTextureName,
|
||||||
b->ty.sampled_texture(texture_dimension, BuildResultVectorComponentType(b)), attrs);
|
b->ty.sampled_texture(texture_dimension, BuildResultVectorComponentType(b)), attrs);
|
||||||
|
|
||||||
case ast::builtin::test::TextureKind::kDepth:
|
case builtin::test::TextureKind::kDepth:
|
||||||
return b->GlobalVar(kTextureName, b->ty.depth_texture(texture_dimension), attrs);
|
return b->GlobalVar(kTextureName, b->ty.depth_texture(texture_dimension), attrs);
|
||||||
|
|
||||||
case ast::builtin::test::TextureKind::kDepthMultisampled:
|
case builtin::test::TextureKind::kDepthMultisampled:
|
||||||
return b->GlobalVar(kTextureName, b->ty.depth_multisampled_texture(texture_dimension),
|
return b->GlobalVar(kTextureName, b->ty.depth_multisampled_texture(texture_dimension),
|
||||||
attrs);
|
attrs);
|
||||||
|
|
||||||
case ast::builtin::test::TextureKind::kMultisampled:
|
case builtin::test::TextureKind::kMultisampled:
|
||||||
return b->GlobalVar(
|
return b->GlobalVar(
|
||||||
kTextureName,
|
kTextureName,
|
||||||
b->ty.multisampled_texture(texture_dimension, BuildResultVectorComponentType(b)),
|
b->ty.multisampled_texture(texture_dimension, BuildResultVectorComponentType(b)),
|
||||||
attrs);
|
attrs);
|
||||||
|
|
||||||
case ast::builtin::test::TextureKind::kStorage: {
|
case builtin::test::TextureKind::kStorage: {
|
||||||
auto st = b->ty.storage_texture(texture_dimension, texel_format, access);
|
auto st = b->ty.storage_texture(texture_dimension, texel_format, access);
|
||||||
return b->GlobalVar(kTextureName, st, attrs);
|
return b->GlobalVar(kTextureName, st, attrs);
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ast::Variable* TextureOverloadCase::BuildSamplerVariable(ProgramBuilder* b) const {
|
const Variable* TextureOverloadCase::BuildSamplerVariable(ProgramBuilder* b) const {
|
||||||
utils::Vector attrs = {b->Group(0_a), b->Binding(1_a)};
|
utils::Vector attrs = {b->Group(0_a), b->Binding(1_a)};
|
||||||
return b->GlobalVar(kSamplerName, b->ty.sampler(sampler_kind), attrs);
|
return b->GlobalVar(kSamplerName, b->ty.sampler(sampler_kind), attrs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,8 +185,8 @@ bool ReturnsVoid(ValidTextureOverload texture_overload);
|
||||||
|
|
||||||
/// Describes a texture builtin overload
|
/// Describes a texture builtin overload
|
||||||
struct TextureOverloadCase {
|
struct TextureOverloadCase {
|
||||||
/// Args is a list of ast::Expression used as arguments to the texture overload case.
|
/// Args is a list of Expression used as arguments to the texture overload case.
|
||||||
using Args = utils::Vector<const ast::Expression*, 8>;
|
using Args = utils::Vector<const Expression*, 8>;
|
||||||
|
|
||||||
/// Constructor for textureSample...() functions
|
/// Constructor for textureSample...() functions
|
||||||
TextureOverloadCase(ValidTextureOverload,
|
TextureOverloadCase(ValidTextureOverload,
|
||||||
|
@ -225,15 +225,15 @@ struct TextureOverloadCase {
|
||||||
|
|
||||||
/// @param builder the AST builder used for the test
|
/// @param builder the AST builder used for the test
|
||||||
/// @returns the vector component type of the texture function return value
|
/// @returns the vector component type of the texture function return value
|
||||||
ast::Type BuildResultVectorComponentType(ProgramBuilder* builder) const;
|
Type BuildResultVectorComponentType(ProgramBuilder* builder) const;
|
||||||
/// @param builder the AST builder used for the test
|
/// @param builder the AST builder used for the test
|
||||||
/// @returns a variable holding the test texture, automatically registered as
|
/// @returns a variable holding the test texture, automatically registered as
|
||||||
/// a global variable.
|
/// a global variable.
|
||||||
const ast::Variable* BuildTextureVariable(ProgramBuilder* builder) const;
|
const Variable* BuildTextureVariable(ProgramBuilder* builder) const;
|
||||||
/// @param builder the AST builder used for the test
|
/// @param builder the AST builder used for the test
|
||||||
/// @returns a Variable holding the test sampler, automatically registered as
|
/// @returns a Variable holding the test sampler, automatically registered as
|
||||||
/// a global variable.
|
/// a global variable.
|
||||||
const ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
|
const Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
|
||||||
|
|
||||||
/// The enumerator for this overload
|
/// The enumerator for this overload
|
||||||
const ValidTextureOverload overload;
|
const ValidTextureOverload overload;
|
||||||
|
|
|
@ -22,7 +22,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CaseSelector);
|
||||||
|
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
|
|
||||||
CaseSelector::CaseSelector(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* e)
|
CaseSelector::CaseSelector(ProgramID pid, NodeID nid, const Source& src, const Expression* e)
|
||||||
: Base(pid, nid, src), expr(e) {}
|
: Base(pid, nid, src), expr(e) {}
|
||||||
|
|
||||||
CaseSelector::CaseSelector(CaseSelector&&) = default;
|
CaseSelector::CaseSelector(CaseSelector&&) = default;
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace tint::ast {
|
||||||
DiagnosticAttribute::DiagnosticAttribute(ProgramID pid,
|
DiagnosticAttribute::DiagnosticAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
ast::DiagnosticControl&& dc)
|
DiagnosticControl&& dc)
|
||||||
: Base(pid, nid, src), control(std::move(dc)) {}
|
: Base(pid, nid, src), control(std::move(dc)) {}
|
||||||
|
|
||||||
DiagnosticAttribute::~DiagnosticAttribute() = default;
|
DiagnosticAttribute::~DiagnosticAttribute() = default;
|
||||||
|
|
|
@ -30,7 +30,7 @@ class DiagnosticAttribute final : public Castable<DiagnosticAttribute, Attribute
|
||||||
/// @param nid the unique node identifier
|
/// @param nid the unique node identifier
|
||||||
/// @param src the source of this node
|
/// @param src the source of this node
|
||||||
/// @param dc the diagnostic control
|
/// @param dc the diagnostic control
|
||||||
DiagnosticAttribute(ProgramID pid, NodeID nid, const Source& src, ast::DiagnosticControl&& dc);
|
DiagnosticAttribute(ProgramID pid, NodeID nid, const Source& src, DiagnosticControl&& dc);
|
||||||
~DiagnosticAttribute() override;
|
~DiagnosticAttribute() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
|
@ -42,7 +42,7 @@ class DiagnosticAttribute final : public Castable<DiagnosticAttribute, Attribute
|
||||||
const DiagnosticAttribute* Clone(CloneContext* ctx) const override;
|
const DiagnosticAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The diagnostic control.
|
/// The diagnostic control.
|
||||||
const ast::DiagnosticControl control;
|
const DiagnosticControl control;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -28,8 +28,8 @@ TEST_F(DiagnosticControlTest, Assert_RuleNotTemplated) {
|
||||||
EXPECT_FATAL_FAILURE(
|
EXPECT_FATAL_FAILURE(
|
||||||
{
|
{
|
||||||
ProgramBuilder b;
|
ProgramBuilder b;
|
||||||
ast::DiagnosticControl control(builtin::DiagnosticSeverity::kWarning,
|
DiagnosticControl control(builtin::DiagnosticSeverity::kWarning,
|
||||||
b.Ident("name", "a", "b", "c"));
|
b.Ident("name", "a", "b", "c"));
|
||||||
},
|
},
|
||||||
"internal compiler error");
|
"internal compiler error");
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,14 @@ namespace {
|
||||||
using DiagnosticDirectiveTest = TestHelper;
|
using DiagnosticDirectiveTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(DiagnosticDirectiveTest, Creation) {
|
TEST_F(DiagnosticDirectiveTest, Creation) {
|
||||||
auto* name = Ident("foo");
|
auto* diag = DiagnosticDirective(Source{{{10, 5}, {10, 15}}},
|
||||||
DiagnosticControl control(builtin::DiagnosticSeverity::kWarning, name);
|
builtin::DiagnosticSeverity::kWarning, "foo");
|
||||||
auto* diag = create<ast::DiagnosticDirective>(Source{{{10, 5}, {10, 15}}}, std::move(control));
|
|
||||||
EXPECT_EQ(diag->source.range.begin.line, 10u);
|
EXPECT_EQ(diag->source.range.begin.line, 10u);
|
||||||
EXPECT_EQ(diag->source.range.begin.column, 5u);
|
EXPECT_EQ(diag->source.range.begin.column, 5u);
|
||||||
EXPECT_EQ(diag->source.range.end.line, 10u);
|
EXPECT_EQ(diag->source.range.end.line, 10u);
|
||||||
EXPECT_EQ(diag->source.range.end.column, 15u);
|
EXPECT_EQ(diag->source.range.end.column, 15u);
|
||||||
EXPECT_EQ(diag->control.severity, builtin::DiagnosticSeverity::kWarning);
|
EXPECT_EQ(diag->control.severity, builtin::DiagnosticSeverity::kWarning);
|
||||||
EXPECT_EQ(diag->control.rule_name, name);
|
CheckIdentifier(Symbols(), diag->control.rule_name, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace {
|
||||||
using EnableTest = TestHelper;
|
using EnableTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(EnableTest, Creation) {
|
TEST_F(EnableTest, Creation) {
|
||||||
auto* ext = create<ast::Enable>(Source{{{20, 2}, {20, 5}}}, builtin::Extension::kF16);
|
auto* ext = Enable(Source{{{20, 2}, {20, 5}}}, builtin::Extension::kF16);
|
||||||
EXPECT_EQ(ext->source.range.begin.line, 20u);
|
EXPECT_EQ(ext->source.range.begin.line, 20u);
|
||||||
EXPECT_EQ(ext->source.range.begin.column, 2u);
|
EXPECT_EQ(ext->source.range.begin.column, 2u);
|
||||||
EXPECT_EQ(ext->source.range.end.line, 20u);
|
EXPECT_EQ(ext->source.range.end.line, 20u);
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Function final : public Castable<Function, Node> {
|
||||||
ast::PipelineStage PipelineStage() const;
|
ast::PipelineStage PipelineStage() const;
|
||||||
|
|
||||||
/// @returns true if this function is an entry point
|
/// @returns true if this function is an entry point
|
||||||
bool IsEntryPoint() const { return PipelineStage() != PipelineStage::kNone; }
|
bool IsEntryPoint() const { return PipelineStage() != ast::PipelineStage::kNone; }
|
||||||
|
|
||||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||||
/// `ctx`.
|
/// `ctx`.
|
||||||
|
@ -111,12 +111,12 @@ class FunctionList : public utils::Vector<const Function*, 8> {
|
||||||
/// @param sym the function symbol to search for
|
/// @param sym the function symbol to search for
|
||||||
/// @param stage the pipeline stage
|
/// @param stage the pipeline stage
|
||||||
/// @returns the associated function or nullptr if none exists
|
/// @returns the associated function or nullptr if none exists
|
||||||
const Function* Find(Symbol sym, PipelineStage stage) const;
|
const Function* Find(Symbol sym, ast::PipelineStage stage) const;
|
||||||
|
|
||||||
/// @param stage the pipeline stage
|
/// @param stage the pipeline stage
|
||||||
/// @returns true if the Builder contains an entrypoint function with
|
/// @returns true if the Builder contains an entrypoint function with
|
||||||
/// the given stage
|
/// the given stage
|
||||||
bool HasStage(PipelineStage stage) const;
|
bool HasStage(ast::PipelineStage stage) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -65,23 +65,23 @@ TEST_F(FunctionTest, Creation_Body_Vector) {
|
||||||
auto* f = Func("func", utils::Empty, ty.void_(), utils::Vector{Discard(), Return()});
|
auto* f = Func("func", utils::Empty, ty.void_(), utils::Vector{Discard(), Return()});
|
||||||
ASSERT_NE(f->body, nullptr);
|
ASSERT_NE(f->body, nullptr);
|
||||||
ASSERT_EQ(f->body->statements.Length(), 2u);
|
ASSERT_EQ(f->body->statements.Length(), 2u);
|
||||||
EXPECT_TRUE(f->body->statements[0]->Is<ast::DiscardStatement>());
|
EXPECT_TRUE(f->body->statements[0]->Is<DiscardStatement>());
|
||||||
EXPECT_TRUE(f->body->statements[1]->Is<ast::ReturnStatement>());
|
EXPECT_TRUE(f->body->statements[1]->Is<ReturnStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FunctionTest, Creation_Body_Block) {
|
TEST_F(FunctionTest, Creation_Body_Block) {
|
||||||
auto* f = Func("func", utils::Empty, ty.void_(), Block(Discard(), Return()));
|
auto* f = Func("func", utils::Empty, ty.void_(), Block(Discard(), Return()));
|
||||||
ASSERT_NE(f->body, nullptr);
|
ASSERT_NE(f->body, nullptr);
|
||||||
ASSERT_EQ(f->body->statements.Length(), 2u);
|
ASSERT_EQ(f->body->statements.Length(), 2u);
|
||||||
EXPECT_TRUE(f->body->statements[0]->Is<ast::DiscardStatement>());
|
EXPECT_TRUE(f->body->statements[0]->Is<DiscardStatement>());
|
||||||
EXPECT_TRUE(f->body->statements[1]->Is<ast::ReturnStatement>());
|
EXPECT_TRUE(f->body->statements[1]->Is<ReturnStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FunctionTest, Creation_Body_Stmt) {
|
TEST_F(FunctionTest, Creation_Body_Stmt) {
|
||||||
auto* f = Func("func", utils::Empty, ty.void_(), Return());
|
auto* f = Func("func", utils::Empty, ty.void_(), Return());
|
||||||
ASSERT_NE(f->body, nullptr);
|
ASSERT_NE(f->body, nullptr);
|
||||||
ASSERT_EQ(f->body->statements.Length(), 1u);
|
ASSERT_EQ(f->body->statements.Length(), 1u);
|
||||||
EXPECT_TRUE(f->body->statements[0]->Is<ast::ReturnStatement>());
|
EXPECT_TRUE(f->body->statements[0]->Is<ReturnStatement>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FunctionTest, Creation_Body_Nullptr) {
|
TEST_F(FunctionTest, Creation_Body_Nullptr) {
|
||||||
|
@ -117,7 +117,7 @@ TEST_F(FunctionTest, Assert_TemplatedName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FunctionTest, Assert_NullParam) {
|
TEST_F(FunctionTest, Assert_NullParam) {
|
||||||
using ParamList = utils::Vector<const ast::Parameter*, 2>;
|
using ParamList = utils::Vector<const Parameter*, 2>;
|
||||||
EXPECT_FATAL_FAILURE(
|
EXPECT_FATAL_FAILURE(
|
||||||
{
|
{
|
||||||
ProgramBuilder b;
|
ProgramBuilder b;
|
||||||
|
|
|
@ -22,10 +22,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupAttribute);
|
||||||
|
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
|
|
||||||
GroupAttribute::GroupAttribute(ProgramID pid,
|
GroupAttribute::GroupAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* exp)
|
||||||
NodeID nid,
|
|
||||||
const Source& src,
|
|
||||||
const ast::Expression* exp)
|
|
||||||
: Base(pid, nid, src), expr(exp) {}
|
: Base(pid, nid, src), expr(exp) {}
|
||||||
|
|
||||||
GroupAttribute::~GroupAttribute() = default;
|
GroupAttribute::~GroupAttribute() = default;
|
||||||
|
|
|
@ -30,7 +30,7 @@ class GroupAttribute final : public Castable<GroupAttribute, Attribute> {
|
||||||
/// @param nid the unique node identifier
|
/// @param nid the unique node identifier
|
||||||
/// @param src the source of this node
|
/// @param src the source of this node
|
||||||
/// @param expr the group expression
|
/// @param expr the group expression
|
||||||
GroupAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* expr);
|
GroupAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* expr);
|
||||||
~GroupAttribute() override;
|
~GroupAttribute() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
|
@ -43,7 +43,7 @@ class GroupAttribute final : public Castable<GroupAttribute, Attribute> {
|
||||||
const GroupAttribute* Clone(CloneContext* ctx) const override;
|
const GroupAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The group expression
|
/// The group expression
|
||||||
const ast::Expression* const expr;
|
const Expression* const expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -22,7 +22,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IdAttribute);
|
||||||
|
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
|
|
||||||
IdAttribute::IdAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* exp)
|
IdAttribute::IdAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* exp)
|
||||||
: Base(pid, nid, src), expr(exp) {}
|
: Base(pid, nid, src), expr(exp) {}
|
||||||
|
|
||||||
IdAttribute::~IdAttribute() = default;
|
IdAttribute::~IdAttribute() = default;
|
||||||
|
|
|
@ -30,7 +30,7 @@ class IdAttribute final : public Castable<IdAttribute, Attribute> {
|
||||||
/// @param nid the unique node identifier
|
/// @param nid the unique node identifier
|
||||||
/// @param src the source of this node
|
/// @param src the source of this node
|
||||||
/// @param expr the numeric id expression
|
/// @param expr the numeric id expression
|
||||||
IdAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* expr);
|
IdAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* expr);
|
||||||
~IdAttribute() override;
|
~IdAttribute() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
|
@ -43,7 +43,7 @@ class IdAttribute final : public Castable<IdAttribute, Attribute> {
|
||||||
const IdAttribute* Clone(CloneContext* ctx) const override;
|
const IdAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The id expression
|
/// The id expression
|
||||||
const ast::Expression* const expr;
|
const Expression* const expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -24,7 +24,7 @@ using IdAttributeTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(IdAttributeTest, Creation) {
|
TEST_F(IdAttributeTest, Creation) {
|
||||||
auto* d = Id(12_a);
|
auto* d = Id(12_a);
|
||||||
EXPECT_TRUE(d->expr->Is<ast::IntLiteralExpression>());
|
EXPECT_TRUE(d->expr->Is<IntLiteralExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
|
|
||||||
/// An identifier
|
/// An identifier
|
||||||
class Identifier : public Castable<Identifier, ast::Node> {
|
class Identifier : public Castable<Identifier, Node> {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param pid the identifier of the program that owns this node
|
/// @param pid the identifier of the program that owns this node
|
||||||
|
|
|
@ -30,10 +30,10 @@ TEST_F(IdentifierExpressionTest, Creation) {
|
||||||
TEST_F(IdentifierExpressionTest, CreationTemplated) {
|
TEST_F(IdentifierExpressionTest, CreationTemplated) {
|
||||||
auto* i = Expr(Ident("ident", true));
|
auto* i = Expr(Ident("ident", true));
|
||||||
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID()));
|
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID()));
|
||||||
auto* tmpl_ident = i->identifier->As<ast::TemplatedIdentifier>();
|
auto* tmpl_ident = i->identifier->As<TemplatedIdentifier>();
|
||||||
ASSERT_NE(tmpl_ident, nullptr);
|
ASSERT_NE(tmpl_ident, nullptr);
|
||||||
EXPECT_EQ(tmpl_ident->arguments.Length(), 1_u);
|
EXPECT_EQ(tmpl_ident->arguments.Length(), 1_u);
|
||||||
EXPECT_TRUE(tmpl_ident->arguments[0]->Is<ast::BoolLiteralExpression>());
|
EXPECT_TRUE(tmpl_ident->arguments[0]->Is<BoolLiteralExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
|
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ IfStatement::IfStatement(ProgramID pid,
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||||
if (else_statement) {
|
if (else_statement) {
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, else_statement, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, else_statement, program_id);
|
||||||
TINT_ASSERT(AST, (else_statement->IsAnyOf<ast::IfStatement, ast::BlockStatement>()));
|
TINT_ASSERT(AST, (else_statement->IsAnyOf<IfStatement, BlockStatement>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace tint::ast {
|
||||||
LocationAttribute::LocationAttribute(ProgramID pid,
|
LocationAttribute::LocationAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* exp)
|
const Expression* exp)
|
||||||
: Base(pid, nid, src), expr(exp) {}
|
: Base(pid, nid, src), expr(exp) {}
|
||||||
|
|
||||||
LocationAttribute::~LocationAttribute() = default;
|
LocationAttribute::~LocationAttribute() = default;
|
||||||
|
|
|
@ -30,7 +30,7 @@ class LocationAttribute final : public Castable<LocationAttribute, Attribute> {
|
||||||
/// @param nid the unique node identifier
|
/// @param nid the unique node identifier
|
||||||
/// @param src the source of this node
|
/// @param src the source of this node
|
||||||
/// @param expr the location expression
|
/// @param expr the location expression
|
||||||
LocationAttribute(ProgramID pid, NodeID nid, const Source& src, const ast::Expression* expr);
|
LocationAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* expr);
|
||||||
~LocationAttribute() override;
|
~LocationAttribute() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
|
@ -43,7 +43,7 @@ class LocationAttribute final : public Castable<LocationAttribute, Attribute> {
|
||||||
const LocationAttribute* Clone(CloneContext* ctx) const override;
|
const LocationAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The location expression
|
/// The location expression
|
||||||
const ast::Expression* const expr;
|
const Expression* const expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -28,7 +28,7 @@ Module::Module(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, sr
|
||||||
Module::Module(ProgramID pid,
|
Module::Module(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
utils::VectorRef<const ast::Node*> global_decls)
|
utils::VectorRef<const Node*> global_decls)
|
||||||
: Base(pid, nid, src), global_declarations_(std::move(global_decls)) {
|
: Base(pid, nid, src), global_declarations_(std::move(global_decls)) {
|
||||||
for (auto* decl : global_declarations_) {
|
for (auto* decl : global_declarations_) {
|
||||||
if (decl == nullptr) {
|
if (decl == nullptr) {
|
||||||
|
@ -41,7 +41,7 @@ Module::Module(ProgramID pid,
|
||||||
|
|
||||||
Module::~Module() = default;
|
Module::~Module() = default;
|
||||||
|
|
||||||
const ast::TypeDecl* Module::LookupType(Symbol name) const {
|
const TypeDecl* Module::LookupType(Symbol name) const {
|
||||||
for (auto* ty : TypeDecls()) {
|
for (auto* ty : TypeDecls()) {
|
||||||
if (ty->name->symbol == name) {
|
if (ty->name->symbol == name) {
|
||||||
return ty;
|
return ty;
|
||||||
|
@ -59,7 +59,7 @@ void Module::AddGlobalDeclaration(const tint::ast::Node* decl) {
|
||||||
void Module::BinGlobalDeclaration(const tint::ast::Node* decl, diag::List& diags) {
|
void Module::BinGlobalDeclaration(const tint::ast::Node* decl, diag::List& diags) {
|
||||||
Switch(
|
Switch(
|
||||||
decl, //
|
decl, //
|
||||||
[&](const ast::TypeDecl* type) {
|
[&](const TypeDecl* type) {
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
|
||||||
type_decls_.Push(type);
|
type_decls_.Push(type);
|
||||||
},
|
},
|
||||||
|
@ -86,21 +86,21 @@ void Module::BinGlobalDeclaration(const tint::ast::Node* decl, diag::List& diags
|
||||||
[&](Default) { TINT_ICE(AST, diags) << "Unknown global declaration type"; });
|
[&](Default) { TINT_ICE(AST, diags) << "Unknown global declaration type"; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::AddDiagnosticDirective(const ast::DiagnosticDirective* directive) {
|
void Module::AddDiagnosticDirective(const DiagnosticDirective* directive) {
|
||||||
TINT_ASSERT(AST, directive);
|
TINT_ASSERT(AST, directive);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, directive, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, directive, program_id);
|
||||||
global_declarations_.Push(directive);
|
global_declarations_.Push(directive);
|
||||||
diagnostic_directives_.Push(directive);
|
diagnostic_directives_.Push(directive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::AddEnable(const ast::Enable* enable) {
|
void Module::AddEnable(const Enable* enable) {
|
||||||
TINT_ASSERT(AST, enable);
|
TINT_ASSERT(AST, enable);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, enable, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, enable, program_id);
|
||||||
global_declarations_.Push(enable);
|
global_declarations_.Push(enable);
|
||||||
enables_.Push(enable);
|
enables_.Push(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::AddGlobalVariable(const ast::Variable* var) {
|
void Module::AddGlobalVariable(const Variable* var) {
|
||||||
TINT_ASSERT(AST, var);
|
TINT_ASSERT(AST, var);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id);
|
||||||
global_variables_.Push(var);
|
global_variables_.Push(var);
|
||||||
|
@ -114,14 +114,14 @@ void Module::AddConstAssert(const ConstAssert* assertion) {
|
||||||
global_declarations_.Push(assertion);
|
global_declarations_.Push(assertion);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::AddTypeDecl(const ast::TypeDecl* type) {
|
void Module::AddTypeDecl(const TypeDecl* type) {
|
||||||
TINT_ASSERT(AST, type);
|
TINT_ASSERT(AST, type);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
|
||||||
type_decls_.Push(type);
|
type_decls_.Push(type);
|
||||||
global_declarations_.Push(type);
|
global_declarations_.Push(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::AddFunction(const ast::Function* func) {
|
void Module::AddFunction(const Function* func) {
|
||||||
TINT_ASSERT(AST, func);
|
TINT_ASSERT(AST, func);
|
||||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
|
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
|
||||||
functions_.Push(func);
|
functions_.Push(func);
|
||||||
|
|
|
@ -46,7 +46,7 @@ class Module final : public Castable<Module, Node> {
|
||||||
Module(ProgramID pid,
|
Module(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
utils::VectorRef<const ast::Node*> global_decls);
|
utils::VectorRef<const Node*> global_decls);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Module() override;
|
~Module() override;
|
||||||
|
@ -80,7 +80,7 @@ class Module final : public Castable<Module, Node> {
|
||||||
auto& GlobalVariables() { return global_variables_; }
|
auto& GlobalVariables() { return global_variables_; }
|
||||||
|
|
||||||
/// @returns the global variable declarations of kind 'T' for the module
|
/// @returns the global variable declarations of kind 'T' for the module
|
||||||
template <typename T, typename = traits::EnableIfIsType<T, ast::Variable>>
|
template <typename T, typename = traits::EnableIfIsType<T, Variable>>
|
||||||
auto Globals() const {
|
auto Globals() const {
|
||||||
utils::Vector<const T*, 32> out;
|
utils::Vector<const T*, 32> out;
|
||||||
out.Reserve(global_variables_.Length());
|
out.Reserve(global_variables_.Length());
|
||||||
|
|
|
@ -135,7 +135,7 @@ const declaration_order_check_4 : i32 = 1;
|
||||||
EXPECT_EQ(Program::printer(&src), Program::printer(&dst));
|
EXPECT_EQ(Program::printer(&src), Program::printer(&dst));
|
||||||
|
|
||||||
// Check that none of the AST nodes or type pointers in dst are found in src
|
// Check that none of the AST nodes or type pointers in dst are found in src
|
||||||
std::unordered_set<const ast::Node*> src_nodes;
|
std::unordered_set<const Node*> src_nodes;
|
||||||
for (auto* src_node : src.ASTNodes().Objects()) {
|
for (auto* src_node : src.ASTNodes().Objects()) {
|
||||||
src_nodes.emplace(src_node);
|
src_nodes.emplace(src_node);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,9 +61,8 @@ TEST_F(ModuleTest, Assert_DifferentProgramID_Function) {
|
||||||
{
|
{
|
||||||
ProgramBuilder b1;
|
ProgramBuilder b1;
|
||||||
ProgramBuilder b2;
|
ProgramBuilder b2;
|
||||||
b1.AST().AddFunction(b2.create<ast::Function>(b2.Ident("func"), utils::Empty,
|
b1.AST().AddFunction(b2.create<Function>(b2.Ident("func"), utils::Empty, b2.ty.f32(),
|
||||||
b2.ty.f32(), b2.Block(), utils::Empty,
|
b2.Block(), utils::Empty, utils::Empty));
|
||||||
utils::Empty));
|
|
||||||
},
|
},
|
||||||
"internal compiler error");
|
"internal compiler error");
|
||||||
}
|
}
|
||||||
|
@ -102,7 +101,7 @@ TEST_F(ModuleTest, CloneOrder) {
|
||||||
// declaration that triggered the ReplaceAll().
|
// declaration that triggered the ReplaceAll().
|
||||||
ProgramBuilder cloned;
|
ProgramBuilder cloned;
|
||||||
CloneContext ctx(&cloned, &p);
|
CloneContext ctx(&cloned, &p);
|
||||||
ctx.ReplaceAll([&](const ast::Function*) -> const ast::Function* {
|
ctx.ReplaceAll([&](const Function*) -> const Function* {
|
||||||
ctx.dst->Alias("inserted_before_F", cloned.ty.u32());
|
ctx.dst->Alias("inserted_before_F", cloned.ty.u32());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
});
|
});
|
||||||
|
@ -110,7 +109,7 @@ TEST_F(ModuleTest, CloneOrder) {
|
||||||
ctx.dst->Alias("inserted_before_A", cloned.ty.u32());
|
ctx.dst->Alias("inserted_before_A", cloned.ty.u32());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
});
|
});
|
||||||
ctx.ReplaceAll([&](const ast::Variable*) -> const ast::Variable* {
|
ctx.ReplaceAll([&](const Variable*) -> const Variable* {
|
||||||
ctx.dst->Alias("inserted_before_V", cloned.ty.u32());
|
ctx.dst->Alias("inserted_before_V", cloned.ty.u32());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
});
|
});
|
||||||
|
@ -118,9 +117,9 @@ TEST_F(ModuleTest, CloneOrder) {
|
||||||
|
|
||||||
auto& decls = cloned.AST().GlobalDeclarations();
|
auto& decls = cloned.AST().GlobalDeclarations();
|
||||||
ASSERT_EQ(decls.Length(), 6u);
|
ASSERT_EQ(decls.Length(), 6u);
|
||||||
EXPECT_TRUE(decls[1]->Is<ast::Function>());
|
EXPECT_TRUE(decls[1]->Is<Function>());
|
||||||
EXPECT_TRUE(decls[3]->Is<ast::Alias>());
|
EXPECT_TRUE(decls[3]->Is<ast::Alias>());
|
||||||
EXPECT_TRUE(decls[5]->Is<ast::Variable>());
|
EXPECT_TRUE(decls[5]->Is<Variable>());
|
||||||
|
|
||||||
ASSERT_TRUE(decls[0]->Is<ast::Alias>());
|
ASSERT_TRUE(decls[0]->Is<ast::Alias>());
|
||||||
ASSERT_TRUE(decls[2]->Is<ast::Alias>());
|
ASSERT_TRUE(decls[2]->Is<ast::Alias>());
|
||||||
|
|
|
@ -26,8 +26,8 @@ Struct::Struct(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const Identifier* n,
|
const Identifier* n,
|
||||||
utils::VectorRef<const ast::StructMember*> m,
|
utils::VectorRef<const StructMember*> m,
|
||||||
utils::VectorRef<const ast::Attribute*> attrs)
|
utils::VectorRef<const Attribute*> attrs)
|
||||||
: Base(pid, nid, src, n), members(std::move(m)), attributes(std::move(attrs)) {
|
: Base(pid, nid, src, n), members(std::move(m)), attributes(std::move(attrs)) {
|
||||||
for (auto* mem : members) {
|
for (auto* mem : members) {
|
||||||
TINT_ASSERT(AST, mem);
|
TINT_ASSERT(AST, mem);
|
||||||
|
|
|
@ -39,8 +39,8 @@ class Struct final : public Castable<Struct, TypeDecl> {
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const Identifier* name,
|
const Identifier* name,
|
||||||
utils::VectorRef<const ast::StructMember*> members,
|
utils::VectorRef<const StructMember*> members,
|
||||||
utils::VectorRef<const ast::Attribute*> attributes);
|
utils::VectorRef<const Attribute*> attributes);
|
||||||
/// Move constructor
|
/// Move constructor
|
||||||
Struct(Struct&&);
|
Struct(Struct&&);
|
||||||
|
|
||||||
|
@ -53,10 +53,10 @@ class Struct final : public Castable<Struct, TypeDecl> {
|
||||||
const Struct* Clone(CloneContext* ctx) const override;
|
const Struct* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The members
|
/// The members
|
||||||
const utils::Vector<const ast::StructMember*, 8> members;
|
const utils::Vector<const StructMember*, 8> members;
|
||||||
|
|
||||||
/// The struct attributes
|
/// The struct attributes
|
||||||
const utils::Vector<const ast::Attribute*, 4> attributes;
|
const utils::Vector<const Attribute*, 4> attributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace tint::ast {
|
||||||
StructMemberAlignAttribute::StructMemberAlignAttribute(ProgramID pid,
|
StructMemberAlignAttribute::StructMemberAlignAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* a)
|
const Expression* a)
|
||||||
: Base(pid, nid, src), expr(a) {}
|
: Base(pid, nid, src), expr(a) {}
|
||||||
|
|
||||||
StructMemberAlignAttribute::~StructMemberAlignAttribute() = default;
|
StructMemberAlignAttribute::~StructMemberAlignAttribute() = default;
|
||||||
|
|
|
@ -34,7 +34,7 @@ class StructMemberAlignAttribute final : public Castable<StructMemberAlignAttrib
|
||||||
StructMemberAlignAttribute(ProgramID pid,
|
StructMemberAlignAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* align);
|
const Expression* align);
|
||||||
~StructMemberAlignAttribute() override;
|
~StructMemberAlignAttribute() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
|
@ -47,7 +47,7 @@ class StructMemberAlignAttribute final : public Castable<StructMemberAlignAttrib
|
||||||
const StructMemberAlignAttribute* Clone(CloneContext* ctx) const override;
|
const StructMemberAlignAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The align expression
|
/// The align expression
|
||||||
const ast::Expression* const expr;
|
const Expression* const expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace tint::ast {
|
||||||
StructMemberOffsetAttribute::StructMemberOffsetAttribute(ProgramID pid,
|
StructMemberOffsetAttribute::StructMemberOffsetAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* exp)
|
const Expression* exp)
|
||||||
: Base(pid, nid, src), expr(exp) {}
|
: Base(pid, nid, src), expr(exp) {}
|
||||||
|
|
||||||
StructMemberOffsetAttribute::~StructMemberOffsetAttribute() = default;
|
StructMemberOffsetAttribute::~StructMemberOffsetAttribute() = default;
|
||||||
|
|
|
@ -42,7 +42,7 @@ class StructMemberOffsetAttribute final : public Castable<StructMemberOffsetAttr
|
||||||
StructMemberOffsetAttribute(ProgramID pid,
|
StructMemberOffsetAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* expr);
|
const Expression* expr);
|
||||||
~StructMemberOffsetAttribute() override;
|
~StructMemberOffsetAttribute() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
|
@ -55,7 +55,7 @@ class StructMemberOffsetAttribute final : public Castable<StructMemberOffsetAttr
|
||||||
const StructMemberOffsetAttribute* Clone(CloneContext* ctx) const override;
|
const StructMemberOffsetAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The offset expression
|
/// The offset expression
|
||||||
const ast::Expression* const expr;
|
const Expression* const expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -22,8 +22,8 @@ using StructMemberOffsetAttributeTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(StructMemberOffsetAttributeTest, Creation) {
|
TEST_F(StructMemberOffsetAttributeTest, Creation) {
|
||||||
auto* d = MemberOffset(2_u);
|
auto* d = MemberOffset(2_u);
|
||||||
ASSERT_TRUE(d->expr->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(d->expr->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(2u, d->expr->As<ast::IntLiteralExpression>()->value);
|
EXPECT_EQ(2u, d->expr->As<IntLiteralExpression>()->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace tint::ast {
|
||||||
StructMemberSizeAttribute::StructMemberSizeAttribute(ProgramID pid,
|
StructMemberSizeAttribute::StructMemberSizeAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* exp)
|
const Expression* exp)
|
||||||
: Base(pid, nid, src), expr(exp) {}
|
: Base(pid, nid, src), expr(exp) {}
|
||||||
|
|
||||||
StructMemberSizeAttribute::~StructMemberSizeAttribute() = default;
|
StructMemberSizeAttribute::~StructMemberSizeAttribute() = default;
|
||||||
|
|
|
@ -31,10 +31,7 @@ class StructMemberSizeAttribute final : public Castable<StructMemberSizeAttribut
|
||||||
/// @param nid the unique node identifier
|
/// @param nid the unique node identifier
|
||||||
/// @param src the source of this node
|
/// @param src the source of this node
|
||||||
/// @param expr the size expression
|
/// @param expr the size expression
|
||||||
StructMemberSizeAttribute(ProgramID pid,
|
StructMemberSizeAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* expr);
|
||||||
NodeID nid,
|
|
||||||
const Source& src,
|
|
||||||
const ast::Expression* expr);
|
|
||||||
~StructMemberSizeAttribute() override;
|
~StructMemberSizeAttribute() override;
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
|
@ -47,7 +44,7 @@ class StructMemberSizeAttribute final : public Castable<StructMemberSizeAttribut
|
||||||
const StructMemberSizeAttribute* Clone(CloneContext* ctx) const override;
|
const StructMemberSizeAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The size expression
|
/// The size expression
|
||||||
const ast::Expression* const expr;
|
const Expression* const expr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -24,8 +24,8 @@ using StructMemberSizeAttributeTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(StructMemberSizeAttributeTest, Creation) {
|
TEST_F(StructMemberSizeAttributeTest, Creation) {
|
||||||
auto* d = MemberSize(2_u);
|
auto* d = MemberSize(2_u);
|
||||||
ASSERT_TRUE(d->expr->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(d->expr->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(2u, d->expr->As<ast::IntLiteralExpression>()->value);
|
EXPECT_EQ(2u, d->expr->As<IntLiteralExpression>()->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -23,8 +23,8 @@ using StructMemberTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(StructMemberTest, Creation) {
|
TEST_F(StructMemberTest, Creation) {
|
||||||
auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)});
|
auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)});
|
||||||
ast::CheckIdentifier(Symbols(), st->name, "a");
|
CheckIdentifier(Symbols(), st->name, "a");
|
||||||
ast::CheckIdentifier(Symbols(), st->type, "i32");
|
CheckIdentifier(Symbols(), st->type, "i32");
|
||||||
EXPECT_EQ(st->attributes.Length(), 1u);
|
EXPECT_EQ(st->attributes.Length(), 1u);
|
||||||
EXPECT_TRUE(st->attributes[0]->Is<StructMemberSizeAttribute>());
|
EXPECT_TRUE(st->attributes[0]->Is<StructMemberSizeAttribute>());
|
||||||
EXPECT_EQ(st->source.range.begin.line, 0u);
|
EXPECT_EQ(st->source.range.begin.line, 0u);
|
||||||
|
@ -36,8 +36,8 @@ TEST_F(StructMemberTest, Creation) {
|
||||||
TEST_F(StructMemberTest, CreationWithSource) {
|
TEST_F(StructMemberTest, CreationWithSource) {
|
||||||
auto* st = Member(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, "a",
|
auto* st = Member(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, "a",
|
||||||
ty.i32());
|
ty.i32());
|
||||||
ast::CheckIdentifier(Symbols(), st->name, "a");
|
CheckIdentifier(Symbols(), st->name, "a");
|
||||||
ast::CheckIdentifier(Symbols(), st->type, "i32");
|
CheckIdentifier(Symbols(), st->type, "i32");
|
||||||
EXPECT_EQ(st->attributes.Length(), 0u);
|
EXPECT_EQ(st->attributes.Length(), 0u);
|
||||||
EXPECT_EQ(st->source.range.begin.line, 27u);
|
EXPECT_EQ(st->source.range.begin.line, 27u);
|
||||||
EXPECT_EQ(st->source.range.begin.column, 4u);
|
EXPECT_EQ(st->source.range.begin.column, 4u);
|
||||||
|
@ -58,7 +58,7 @@ TEST_F(StructMemberTest, Assert_Null_Type) {
|
||||||
EXPECT_FATAL_FAILURE(
|
EXPECT_FATAL_FAILURE(
|
||||||
{
|
{
|
||||||
ProgramBuilder b;
|
ProgramBuilder b;
|
||||||
b.Member("a", ast::Type{});
|
b.Member("a", Type{});
|
||||||
},
|
},
|
||||||
"internal compiler error");
|
"internal compiler error");
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ TEST_F(AstStructTest, Assert_Null_Attribute) {
|
||||||
{
|
{
|
||||||
ProgramBuilder b;
|
ProgramBuilder b;
|
||||||
b.Structure(b.Sym("S"), utils::Vector{b.Member("a", b.ty.i32())},
|
b.Structure(b.Sym("S"), utils::Vector{b.Member("a", b.ty.i32())},
|
||||||
utils::Vector<const ast::Attribute*, 1>{nullptr});
|
utils::Vector<const Attribute*, 1>{nullptr});
|
||||||
},
|
},
|
||||||
"internal compiler error");
|
"internal compiler error");
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ TEST_F(SwitchStatementTest, IsSwitch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SwitchStatementTest, Assert_Null_Condition) {
|
TEST_F(SwitchStatementTest, Assert_Null_Condition) {
|
||||||
using CaseStatementList = utils::Vector<const ast::CaseStatement*, 2>;
|
using CaseStatementList = utils::Vector<const CaseStatement*, 2>;
|
||||||
EXPECT_FATAL_FAILURE(
|
EXPECT_FATAL_FAILURE(
|
||||||
{
|
{
|
||||||
ProgramBuilder b;
|
ProgramBuilder b;
|
||||||
|
@ -66,7 +66,7 @@ TEST_F(SwitchStatementTest, Assert_Null_Condition) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SwitchStatementTest, Assert_Null_CaseStatement) {
|
TEST_F(SwitchStatementTest, Assert_Null_CaseStatement) {
|
||||||
using CaseStatementList = utils::Vector<const ast::CaseStatement*, 2>;
|
using CaseStatementList = utils::Vector<const CaseStatement*, 2>;
|
||||||
EXPECT_FATAL_FAILURE(
|
EXPECT_FATAL_FAILURE(
|
||||||
{
|
{
|
||||||
ProgramBuilder b;
|
ProgramBuilder b;
|
||||||
|
|
|
@ -57,24 +57,22 @@ enum class TraverseOrder {
|
||||||
/// @param diags the diagnostics used for error messages
|
/// @param diags the diagnostics used for error messages
|
||||||
/// @param callback the callback function. Must be of the signature:
|
/// @param callback the callback function. Must be of the signature:
|
||||||
/// `TraverseAction(const T* expr)` or `TraverseAction(const T* expr, size_t depth)` where T
|
/// `TraverseAction(const T* expr)` or `TraverseAction(const T* expr, size_t depth)` where T
|
||||||
/// is an ast::Expression type.
|
/// is an Expression type.
|
||||||
/// @return true on success, false on error
|
/// @return true on success, false on error
|
||||||
template <TraverseOrder ORDER = TraverseOrder::LeftToRight, typename CALLBACK>
|
template <TraverseOrder ORDER = TraverseOrder::LeftToRight, typename CALLBACK>
|
||||||
bool TraverseExpressions(const ast::Expression* root, diag::List& diags, CALLBACK&& callback) {
|
bool TraverseExpressions(const Expression* root, diag::List& diags, CALLBACK&& callback) {
|
||||||
using EXPR_TYPE = std::remove_pointer_t<traits::ParameterType<CALLBACK, 0>>;
|
using EXPR_TYPE = std::remove_pointer_t<traits::ParameterType<CALLBACK, 0>>;
|
||||||
constexpr static bool kHasDepthArg = traits::SignatureOfT<CALLBACK>::parameter_count == 2;
|
constexpr static bool kHasDepthArg = traits::SignatureOfT<CALLBACK>::parameter_count == 2;
|
||||||
|
|
||||||
struct Pending {
|
struct Pending {
|
||||||
const ast::Expression* expr;
|
const Expression* expr;
|
||||||
size_t depth;
|
size_t depth;
|
||||||
};
|
};
|
||||||
|
|
||||||
utils::Vector<Pending, 32> to_visit{{root, 0}};
|
utils::Vector<Pending, 32> to_visit{{root, 0}};
|
||||||
|
|
||||||
auto push_single = [&](const ast::Expression* expr, size_t depth) {
|
auto push_single = [&](const Expression* expr, size_t depth) { to_visit.Push({expr, depth}); };
|
||||||
to_visit.Push({expr, depth});
|
auto push_pair = [&](const Expression* left, const Expression* right, size_t depth) {
|
||||||
};
|
|
||||||
auto push_pair = [&](const ast::Expression* left, const ast::Expression* right, size_t depth) {
|
|
||||||
if (ORDER == TraverseOrder::LeftToRight) {
|
if (ORDER == TraverseOrder::LeftToRight) {
|
||||||
to_visit.Push({right, depth});
|
to_visit.Push({right, depth});
|
||||||
to_visit.Push({left, depth});
|
to_visit.Push({left, depth});
|
||||||
|
@ -83,7 +81,7 @@ bool TraverseExpressions(const ast::Expression* root, diag::List& diags, CALLBAC
|
||||||
to_visit.Push({right, depth});
|
to_visit.Push({right, depth});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
auto push_list = [&](utils::VectorRef<const ast::Expression*> exprs, size_t depth) {
|
auto push_list = [&](utils::VectorRef<const Expression*> exprs, size_t depth) {
|
||||||
if (ORDER == TraverseOrder::LeftToRight) {
|
if (ORDER == TraverseOrder::LeftToRight) {
|
||||||
for (auto* expr : utils::Reverse(exprs)) {
|
for (auto* expr : utils::Reverse(exprs)) {
|
||||||
to_visit.Push({expr, depth});
|
to_visit.Push({expr, depth});
|
||||||
|
@ -97,7 +95,7 @@ bool TraverseExpressions(const ast::Expression* root, diag::List& diags, CALLBAC
|
||||||
|
|
||||||
while (!to_visit.IsEmpty()) {
|
while (!to_visit.IsEmpty()) {
|
||||||
auto p = to_visit.Pop();
|
auto p = to_visit.Pop();
|
||||||
const ast::Expression* expr = p.expr;
|
const Expression* expr = p.expr;
|
||||||
|
|
||||||
if (auto* filtered = expr->template As<EXPR_TYPE>()) {
|
if (auto* filtered = expr->template As<EXPR_TYPE>()) {
|
||||||
TraverseAction result;
|
TraverseAction result;
|
||||||
|
|
|
@ -26,66 +26,66 @@ namespace {
|
||||||
using TraverseExpressionsTest = TestHelper;
|
using TraverseExpressionsTest = TestHelper;
|
||||||
|
|
||||||
TEST_F(TraverseExpressionsTest, DescendIndexAccessor) {
|
TEST_F(TraverseExpressionsTest, DescendIndexAccessor) {
|
||||||
std::vector<const ast::Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
||||||
std::vector<const ast::Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
|
std::vector<const Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
|
||||||
auto* root = IndexAccessor(i[0], i[1]);
|
auto* root = IndexAccessor(i[0], i[1]);
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> l2r;
|
std::vector<const Expression*> l2r;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
l2r.push_back(expr);
|
l2r.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(l2r, ElementsAre(root, i[0], e[0], e[1], i[1], e[2], e[3]));
|
EXPECT_THAT(l2r, ElementsAre(root, i[0], e[0], e[1], i[1], e[2], e[3]));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> r2l;
|
std::vector<const Expression*> r2l;
|
||||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
r2l.push_back(expr);
|
r2l.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(r2l, ElementsAre(root, i[1], e[3], e[2], i[0], e[1], e[0]));
|
EXPECT_THAT(r2l, ElementsAre(root, i[1], e[3], e[2], i[0], e[1], e[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TraverseExpressionsTest, DescendBinaryExpression) {
|
TEST_F(TraverseExpressionsTest, DescendBinaryExpression) {
|
||||||
std::vector<const ast::Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
||||||
std::vector<const ast::Expression*> i = {Add(e[0], e[1]), Sub(e[2], e[3])};
|
std::vector<const Expression*> i = {Add(e[0], e[1]), Sub(e[2], e[3])};
|
||||||
auto* root = Mul(i[0], i[1]);
|
auto* root = Mul(i[0], i[1]);
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> l2r;
|
std::vector<const Expression*> l2r;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
l2r.push_back(expr);
|
l2r.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(l2r, ElementsAre(root, i[0], e[0], e[1], i[1], e[2], e[3]));
|
EXPECT_THAT(l2r, ElementsAre(root, i[0], e[0], e[1], i[1], e[2], e[3]));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> r2l;
|
std::vector<const Expression*> r2l;
|
||||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
r2l.push_back(expr);
|
r2l.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(r2l, ElementsAre(root, i[1], e[3], e[2], i[0], e[1], e[0]));
|
EXPECT_THAT(r2l, ElementsAre(root, i[1], e[3], e[2], i[0], e[1], e[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TraverseExpressionsTest, Depth) {
|
TEST_F(TraverseExpressionsTest, Depth) {
|
||||||
std::vector<const ast::Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
||||||
std::vector<const ast::Expression*> i = {Add(e[0], e[1]), Sub(e[2], e[3])};
|
std::vector<const Expression*> i = {Add(e[0], e[1]), Sub(e[2], e[3])};
|
||||||
auto* root = Mul(i[0], i[1]);
|
auto* root = Mul(i[0], i[1]);
|
||||||
|
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
size_t depths[] = {0, 1, 2, 2, 1, 2, 2};
|
size_t depths[] = {0, 1, 2, 2, 1, 2, 2};
|
||||||
{
|
{
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>( //
|
TraverseExpressions<TraverseOrder::LeftToRight>( //
|
||||||
root, Diagnostics(), [&](const ast::Expression* expr, size_t depth) {
|
root, Diagnostics(), [&](const Expression* expr, size_t depth) {
|
||||||
(void)expr;
|
(void)expr;
|
||||||
EXPECT_THAT(depth, depths[j++]);
|
EXPECT_THAT(depth, depths[j++]);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,20 +97,20 @@ TEST_F(TraverseExpressionsTest, DescendBitcastExpression) {
|
||||||
auto* b2 = Bitcast<i32>(b1);
|
auto* b2 = Bitcast<i32>(b1);
|
||||||
auto* root = Bitcast<i32>(b2);
|
auto* root = Bitcast<i32>(b2);
|
||||||
{
|
{
|
||||||
utils::Vector<const ast::Expression*, 8> l2r;
|
utils::Vector<const Expression*, 8> l2r;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
l2r.Push(expr);
|
l2r.Push(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(l2r, ElementsAre(root, b2, b1, b0, e));
|
EXPECT_THAT(l2r, ElementsAre(root, b2, b1, b0, e));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
utils::Vector<const ast::Expression*, 8> r2l;
|
utils::Vector<const Expression*, 8> r2l;
|
||||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
r2l.Push(expr);
|
r2l.Push(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(r2l, ElementsAre(root, b2, b1, b0, e));
|
EXPECT_THAT(r2l, ElementsAre(root, b2, b1, b0, e));
|
||||||
}
|
}
|
||||||
|
@ -121,20 +121,20 @@ TEST_F(TraverseExpressionsTest, DescendCallExpression) {
|
||||||
utils::Vector c{Call("a", e[0], e[1]), Call("b", e[2], e[3])};
|
utils::Vector c{Call("a", e[0], e[1]), Call("b", e[2], e[3])};
|
||||||
auto* root = Call("c", c[0], c[1]);
|
auto* root = Call("c", c[0], c[1]);
|
||||||
{
|
{
|
||||||
utils::Vector<const ast::Expression*, 8> l2r;
|
utils::Vector<const Expression*, 8> l2r;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
l2r.Push(expr);
|
l2r.Push(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(l2r, ElementsAre(root, c[0], e[0], e[1], c[1], e[2], e[3]));
|
EXPECT_THAT(l2r, ElementsAre(root, c[0], e[0], e[1], c[1], e[2], e[3]));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
utils::Vector<const ast::Expression*, 8> r2l;
|
utils::Vector<const Expression*, 8> r2l;
|
||||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
r2l.Push(expr);
|
r2l.Push(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(r2l, ElementsAre(root, c[1], e[3], e[2], c[0], e[1], e[0]));
|
EXPECT_THAT(r2l, ElementsAre(root, c[1], e[3], e[2], c[0], e[1], e[0]));
|
||||||
}
|
}
|
||||||
|
@ -145,20 +145,20 @@ TEST_F(TraverseExpressionsTest, DescendMemberAccessorExpression) {
|
||||||
auto* m = MemberAccessor(e, "a");
|
auto* m = MemberAccessor(e, "a");
|
||||||
auto* root = MemberAccessor(m, "b");
|
auto* root = MemberAccessor(m, "b");
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> l2r;
|
std::vector<const Expression*> l2r;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
l2r.push_back(expr);
|
l2r.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(l2r, ElementsAre(root, m, e));
|
EXPECT_THAT(l2r, ElementsAre(root, m, e));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> r2l;
|
std::vector<const Expression*> r2l;
|
||||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
r2l.push_back(expr);
|
r2l.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(r2l, ElementsAre(root, m, e));
|
EXPECT_THAT(r2l, ElementsAre(root, m, e));
|
||||||
}
|
}
|
||||||
|
@ -173,20 +173,20 @@ TEST_F(TraverseExpressionsTest, DescendMemberIndexExpression) {
|
||||||
auto* f = IndexAccessor(d, e);
|
auto* f = IndexAccessor(d, e);
|
||||||
auto* root = IndexAccessor(c, f);
|
auto* root = IndexAccessor(c, f);
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> l2r;
|
std::vector<const Expression*> l2r;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
l2r.push_back(expr);
|
l2r.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(l2r, ElementsAre(root, c, a, b, f, d, e));
|
EXPECT_THAT(l2r, ElementsAre(root, c, a, b, f, d, e));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> r2l;
|
std::vector<const Expression*> r2l;
|
||||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
r2l.push_back(expr);
|
r2l.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(r2l, ElementsAre(root, f, e, d, c, b, a));
|
EXPECT_THAT(r2l, ElementsAre(root, f, e, d, c, b, a));
|
||||||
}
|
}
|
||||||
|
@ -199,47 +199,47 @@ TEST_F(TraverseExpressionsTest, DescendUnaryExpression) {
|
||||||
auto* u2 = AddressOf(u1);
|
auto* u2 = AddressOf(u1);
|
||||||
auto* root = Deref(u2);
|
auto* root = Deref(u2);
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> l2r;
|
std::vector<const Expression*> l2r;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
l2r.push_back(expr);
|
l2r.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(l2r, ElementsAre(root, u2, u1, u0, e));
|
EXPECT_THAT(l2r, ElementsAre(root, u2, u1, u0, e));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::vector<const ast::Expression*> r2l;
|
std::vector<const Expression*> r2l;
|
||||||
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
|
||||||
[&](const ast::Expression* expr) {
|
[&](const Expression* expr) {
|
||||||
r2l.push_back(expr);
|
r2l.push_back(expr);
|
||||||
return ast::TraverseAction::Descend;
|
return TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(r2l, ElementsAre(root, u2, u1, u0, e));
|
EXPECT_THAT(r2l, ElementsAre(root, u2, u1, u0, e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TraverseExpressionsTest, Skip) {
|
TEST_F(TraverseExpressionsTest, Skip) {
|
||||||
std::vector<const ast::Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
||||||
std::vector<const ast::Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
|
std::vector<const Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
|
||||||
auto* root = IndexAccessor(i[0], i[1]);
|
auto* root = IndexAccessor(i[0], i[1]);
|
||||||
std::vector<const ast::Expression*> order;
|
std::vector<const Expression*> order;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(
|
TraverseExpressions<TraverseOrder::LeftToRight>(
|
||||||
root, Diagnostics(), [&](const ast::Expression* expr) {
|
root, Diagnostics(), [&](const Expression* expr) {
|
||||||
order.push_back(expr);
|
order.push_back(expr);
|
||||||
return expr == i[0] ? ast::TraverseAction::Skip : ast::TraverseAction::Descend;
|
return expr == i[0] ? TraverseAction::Skip : TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(order, ElementsAre(root, i[0], i[1], e[2], e[3]));
|
EXPECT_THAT(order, ElementsAre(root, i[0], i[1], e[2], e[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TraverseExpressionsTest, Stop) {
|
TEST_F(TraverseExpressionsTest, Stop) {
|
||||||
std::vector<const ast::Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
|
||||||
std::vector<const ast::Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
|
std::vector<const Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
|
||||||
auto* root = IndexAccessor(i[0], i[1]);
|
auto* root = IndexAccessor(i[0], i[1]);
|
||||||
std::vector<const ast::Expression*> order;
|
std::vector<const Expression*> order;
|
||||||
TraverseExpressions<TraverseOrder::LeftToRight>(
|
TraverseExpressions<TraverseOrder::LeftToRight>(
|
||||||
root, Diagnostics(), [&](const ast::Expression* expr) {
|
root, Diagnostics(), [&](const Expression* expr) {
|
||||||
order.push_back(expr);
|
order.push_back(expr);
|
||||||
return expr == i[0] ? ast::TraverseAction::Stop : ast::TraverseAction::Descend;
|
return expr == i[0] ? TraverseAction::Stop : TraverseAction::Descend;
|
||||||
});
|
});
|
||||||
EXPECT_THAT(order, ElementsAre(root, i[0]));
|
EXPECT_THAT(order, ElementsAre(root, i[0]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,8 @@ class Variable : public Castable<Variable, Node> {
|
||||||
|
|
||||||
/// @returns true if the variable has both group and binding attributes
|
/// @returns true if the variable has both group and binding attributes
|
||||||
bool HasBindingPoint() const {
|
bool HasBindingPoint() const {
|
||||||
return ast::GetAttribute<ast::BindingAttribute>(attributes) != nullptr &&
|
return HasAttribute<BindingAttribute>(attributes) &&
|
||||||
ast::GetAttribute<ast::GroupAttribute>(attributes) != nullptr;
|
HasAttribute<GroupAttribute>(attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns the kind of the variable, which can be used in diagnostics
|
/// @returns the kind of the variable, which can be used in diagnostics
|
||||||
|
|
|
@ -98,14 +98,14 @@ TEST_F(VariableTest, WithAttributes) {
|
||||||
Builtin(builtin::BuiltinValue::kPosition), Id(1200_u));
|
Builtin(builtin::BuiltinValue::kPosition), Id(1200_u));
|
||||||
|
|
||||||
auto& attributes = var->attributes;
|
auto& attributes = var->attributes;
|
||||||
EXPECT_TRUE(ast::HasAttribute<ast::LocationAttribute>(attributes));
|
EXPECT_TRUE(ast::HasAttribute<LocationAttribute>(attributes));
|
||||||
EXPECT_TRUE(ast::HasAttribute<ast::BuiltinAttribute>(attributes));
|
EXPECT_TRUE(ast::HasAttribute<BuiltinAttribute>(attributes));
|
||||||
EXPECT_TRUE(ast::HasAttribute<ast::IdAttribute>(attributes));
|
EXPECT_TRUE(ast::HasAttribute<IdAttribute>(attributes));
|
||||||
|
|
||||||
auto* location = ast::GetAttribute<ast::LocationAttribute>(attributes);
|
auto* location = GetAttribute<LocationAttribute>(attributes);
|
||||||
ASSERT_NE(nullptr, location);
|
ASSERT_NE(nullptr, location);
|
||||||
ASSERT_NE(nullptr, location->expr);
|
ASSERT_NE(nullptr, location->expr);
|
||||||
EXPECT_TRUE(location->expr->Is<ast::IntLiteralExpression>());
|
EXPECT_TRUE(location->expr->Is<IntLiteralExpression>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VariableTest, HasBindingPoint_BothProvided) {
|
TEST_F(VariableTest, HasBindingPoint_BothProvided) {
|
||||||
|
|
|
@ -25,9 +25,9 @@ namespace tint::ast {
|
||||||
WorkgroupAttribute::WorkgroupAttribute(ProgramID pid,
|
WorkgroupAttribute::WorkgroupAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* x_,
|
const Expression* x_,
|
||||||
const ast::Expression* y_,
|
const Expression* y_,
|
||||||
const ast::Expression* z_)
|
const Expression* z_)
|
||||||
: Base(pid, nid, src), x(x_), y(y_), z(z_) {}
|
: Base(pid, nid, src), x(x_), y(y_), z(z_) {}
|
||||||
|
|
||||||
WorkgroupAttribute::~WorkgroupAttribute() = default;
|
WorkgroupAttribute::~WorkgroupAttribute() = default;
|
||||||
|
|
|
@ -40,14 +40,14 @@ class WorkgroupAttribute final : public Castable<WorkgroupAttribute, Attribute>
|
||||||
WorkgroupAttribute(ProgramID pid,
|
WorkgroupAttribute(ProgramID pid,
|
||||||
NodeID nid,
|
NodeID nid,
|
||||||
const Source& src,
|
const Source& src,
|
||||||
const ast::Expression* x,
|
const Expression* x,
|
||||||
const ast::Expression* y = nullptr,
|
const Expression* y = nullptr,
|
||||||
const ast::Expression* z = nullptr);
|
const Expression* z = nullptr);
|
||||||
|
|
||||||
~WorkgroupAttribute() override;
|
~WorkgroupAttribute() override;
|
||||||
|
|
||||||
/// @returns the workgroup dimensions
|
/// @returns the workgroup dimensions
|
||||||
std::array<const ast::Expression*, 3> Values() const { return {x, y, z}; }
|
std::array<const Expression*, 3> Values() const { return {x, y, z}; }
|
||||||
|
|
||||||
/// @returns the WGSL name for the attribute
|
/// @returns the WGSL name for the attribute
|
||||||
std::string Name() const override;
|
std::string Name() const override;
|
||||||
|
@ -59,11 +59,11 @@ class WorkgroupAttribute final : public Castable<WorkgroupAttribute, Attribute>
|
||||||
const WorkgroupAttribute* Clone(CloneContext* ctx) const override;
|
const WorkgroupAttribute* Clone(CloneContext* ctx) const override;
|
||||||
|
|
||||||
/// The workgroup x dimension.
|
/// The workgroup x dimension.
|
||||||
const ast::Expression* const x;
|
const Expression* const x;
|
||||||
/// The optional workgroup y dimension. May be null.
|
/// The optional workgroup y dimension. May be null.
|
||||||
const ast::Expression* const y = nullptr;
|
const Expression* const y = nullptr;
|
||||||
/// The optional workgroup z dimension. May be null.
|
/// The optional workgroup z dimension. May be null.
|
||||||
const ast::Expression* const z = nullptr;
|
const Expression* const z = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -28,8 +28,8 @@ TEST_F(WorkgroupAttributeTest, Creation_1param) {
|
||||||
auto* d = WorkgroupSize(2_i);
|
auto* d = WorkgroupSize(2_i);
|
||||||
auto values = d->Values();
|
auto values = d->Values();
|
||||||
|
|
||||||
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(values[0]->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->value, 2);
|
EXPECT_EQ(values[0]->As<IntLiteralExpression>()->value, 2);
|
||||||
|
|
||||||
EXPECT_EQ(values[1], nullptr);
|
EXPECT_EQ(values[1], nullptr);
|
||||||
EXPECT_EQ(values[2], nullptr);
|
EXPECT_EQ(values[2], nullptr);
|
||||||
|
@ -38,11 +38,11 @@ TEST_F(WorkgroupAttributeTest, Creation_2param) {
|
||||||
auto* d = WorkgroupSize(2_i, 4_i);
|
auto* d = WorkgroupSize(2_i, 4_i);
|
||||||
auto values = d->Values();
|
auto values = d->Values();
|
||||||
|
|
||||||
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(values[0]->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->value, 2);
|
EXPECT_EQ(values[0]->As<IntLiteralExpression>()->value, 2);
|
||||||
|
|
||||||
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(values[1]->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->value, 4);
|
EXPECT_EQ(values[1]->As<IntLiteralExpression>()->value, 4);
|
||||||
|
|
||||||
EXPECT_EQ(values[2], nullptr);
|
EXPECT_EQ(values[2], nullptr);
|
||||||
}
|
}
|
||||||
|
@ -51,27 +51,27 @@ TEST_F(WorkgroupAttributeTest, Creation_3param) {
|
||||||
auto* d = WorkgroupSize(2_i, 4_i, 6_i);
|
auto* d = WorkgroupSize(2_i, 4_i, 6_i);
|
||||||
auto values = d->Values();
|
auto values = d->Values();
|
||||||
|
|
||||||
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(values[0]->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->value, 2);
|
EXPECT_EQ(values[0]->As<IntLiteralExpression>()->value, 2);
|
||||||
|
|
||||||
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(values[1]->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->value, 4);
|
EXPECT_EQ(values[1]->As<IntLiteralExpression>()->value, 4);
|
||||||
|
|
||||||
ASSERT_TRUE(values[2]->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(values[2]->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(values[2]->As<ast::IntLiteralExpression>()->value, 6);
|
EXPECT_EQ(values[2]->As<IntLiteralExpression>()->value, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WorkgroupAttributeTest, Creation_WithIdentifier) {
|
TEST_F(WorkgroupAttributeTest, Creation_WithIdentifier) {
|
||||||
auto* d = WorkgroupSize(2_i, 4_i, "depth");
|
auto* d = WorkgroupSize(2_i, 4_i, "depth");
|
||||||
auto values = d->Values();
|
auto values = d->Values();
|
||||||
|
|
||||||
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(values[0]->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->value, 2);
|
EXPECT_EQ(values[0]->As<IntLiteralExpression>()->value, 2);
|
||||||
|
|
||||||
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
|
ASSERT_TRUE(values[1]->Is<IntLiteralExpression>());
|
||||||
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->value, 4);
|
EXPECT_EQ(values[1]->As<IntLiteralExpression>()->value, 4);
|
||||||
|
|
||||||
auto* z_ident = As<ast::IdentifierExpression>(values[2]);
|
auto* z_ident = As<IdentifierExpression>(values[2]);
|
||||||
ASSERT_TRUE(z_ident);
|
ASSERT_TRUE(z_ident);
|
||||||
EXPECT_EQ(Symbols().NameFor(z_ident->identifier->symbol), "depth");
|
EXPECT_EQ(Symbols().NameFor(z_ident->identifier->symbol), "depth");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue