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:
Ben Clayton 2023-02-22 00:08:55 +00:00 committed by Dawn LUCI CQ
parent 4a88a3287e
commit 5662f79b24
48 changed files with 216 additions and 227 deletions

View File

@ -127,11 +127,11 @@ class BinaryExpression final : public Castable<BinaryExpression, Expression> {
/// @returns true if the op is an arithmetic operation
inline bool IsArithmetic(BinaryOp op) {
switch (op) {
case ast::BinaryOp::kAdd:
case ast::BinaryOp::kSubtract:
case ast::BinaryOp::kMultiply:
case ast::BinaryOp::kDivide:
case ast::BinaryOp::kModulo:
case BinaryOp::kAdd:
case BinaryOp::kSubtract:
case BinaryOp::kMultiply:
case BinaryOp::kDivide:
case BinaryOp::kModulo:
return true;
default:
return false;
@ -142,12 +142,12 @@ inline bool IsArithmetic(BinaryOp op) {
/// @returns true if the op is a comparison operation
inline bool IsComparison(BinaryOp op) {
switch (op) {
case ast::BinaryOp::kEqual:
case ast::BinaryOp::kNotEqual:
case ast::BinaryOp::kLessThan:
case ast::BinaryOp::kLessThanEqual:
case ast::BinaryOp::kGreaterThan:
case ast::BinaryOp::kGreaterThanEqual:
case BinaryOp::kEqual:
case BinaryOp::kNotEqual:
case BinaryOp::kLessThan:
case BinaryOp::kLessThanEqual:
case BinaryOp::kGreaterThan:
case BinaryOp::kGreaterThanEqual:
return true;
default:
return false;
@ -158,9 +158,9 @@ inline bool IsComparison(BinaryOp op) {
/// @returns true if the op is a bitwise operation
inline bool IsBitwise(BinaryOp op) {
switch (op) {
case ast::BinaryOp::kAnd:
case ast::BinaryOp::kOr:
case ast::BinaryOp::kXor:
case BinaryOp::kAnd:
case BinaryOp::kOr:
case BinaryOp::kXor:
return true;
default:
return false;
@ -171,8 +171,8 @@ inline bool IsBitwise(BinaryOp op) {
/// @returns true if the op is a bit shift operation
inline bool IsBitshift(BinaryOp op) {
switch (op) {
case ast::BinaryOp::kShiftLeft:
case ast::BinaryOp::kShiftRight:
case BinaryOp::kShiftLeft:
case BinaryOp::kShiftRight:
return true;
default:
return false;
@ -181,8 +181,8 @@ inline bool IsBitshift(BinaryOp op) {
inline bool BinaryExpression::IsLogical() const {
switch (op) {
case ast::BinaryOp::kLogicalAnd:
case ast::BinaryOp::kLogicalOr:
case BinaryOp::kLogicalAnd:
case BinaryOp::kLogicalOr:
return true;
default:
return false;

View File

@ -25,7 +25,7 @@ namespace tint::ast {
BindingAttribute::BindingAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* exp)
const Expression* exp)
: Base(pid, nid, src), expr(exp) {}
BindingAttribute::~BindingAttribute() = default;

View File

@ -30,7 +30,7 @@ class BindingAttribute final : public Castable<BindingAttribute, Attribute> {
/// @param nid the unique node identifier
/// @param src the source of this node
/// @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;
/// @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;
/// the binding expression
const ast::Expression* const expr;
const Expression* const expr;
};
} // namespace tint::ast

View File

@ -63,8 +63,7 @@ TEST_F(BlockStatementTest, Assert_Null_Statement) {
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;
b.create<BlockStatement>(utils::Vector<const ast::Statement*, 1>{nullptr},
utils::Empty);
b.create<BlockStatement>(utils::Vector<const Statement*, 1>{nullptr}, utils::Empty);
},
"internal compiler error");
}

View File

@ -128,13 +128,13 @@ std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data) {
return out;
}
ast::Type TextureOverloadCase::BuildResultVectorComponentType(ProgramBuilder* b) const {
Type TextureOverloadCase::BuildResultVectorComponentType(ProgramBuilder* b) const {
switch (texture_data_type) {
case ast::builtin::test::TextureDataType::kF32:
case builtin::test::TextureDataType::kF32:
return b->ty.f32();
case ast::builtin::test::TextureDataType::kU32:
case builtin::test::TextureDataType::kU32:
return b->ty.u32();
case ast::builtin::test::TextureDataType::kI32:
case builtin::test::TextureDataType::kI32:
return b->ty.i32();
}
@ -142,31 +142,31 @@ ast::Type TextureOverloadCase::BuildResultVectorComponentType(ProgramBuilder* b)
return {};
}
const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b) const {
const Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b) const {
utils::Vector attrs{
b->Group(0_u),
b->Binding(0_a),
};
switch (texture_kind) {
case ast::builtin::test::TextureKind::kRegular:
case builtin::test::TextureKind::kRegular:
return b->GlobalVar(
kTextureName,
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);
case ast::builtin::test::TextureKind::kDepthMultisampled:
case builtin::test::TextureKind::kDepthMultisampled:
return b->GlobalVar(kTextureName, b->ty.depth_multisampled_texture(texture_dimension),
attrs);
case ast::builtin::test::TextureKind::kMultisampled:
case builtin::test::TextureKind::kMultisampled:
return b->GlobalVar(
kTextureName,
b->ty.multisampled_texture(texture_dimension, BuildResultVectorComponentType(b)),
attrs);
case ast::builtin::test::TextureKind::kStorage: {
case builtin::test::TextureKind::kStorage: {
auto st = b->ty.storage_texture(texture_dimension, texel_format, access);
return b->GlobalVar(kTextureName, st, attrs);
}
@ -176,7 +176,7 @@ const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b
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)};
return b->GlobalVar(kSamplerName, b->ty.sampler(sampler_kind), attrs);
}

View File

@ -185,8 +185,8 @@ bool ReturnsVoid(ValidTextureOverload texture_overload);
/// Describes a texture builtin overload
struct TextureOverloadCase {
/// Args is a list of ast::Expression used as arguments to the texture overload case.
using Args = utils::Vector<const ast::Expression*, 8>;
/// Args is a list of Expression used as arguments to the texture overload case.
using Args = utils::Vector<const Expression*, 8>;
/// Constructor for textureSample...() functions
TextureOverloadCase(ValidTextureOverload,
@ -225,15 +225,15 @@ struct TextureOverloadCase {
/// @param builder the AST builder used for the test
/// @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
/// @returns a variable holding the test texture, automatically registered as
/// 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
/// @returns a Variable holding the test sampler, automatically registered as
/// a global variable.
const ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
const Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
/// The enumerator for this overload
const ValidTextureOverload overload;

View File

@ -22,7 +22,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CaseSelector);
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) {}
CaseSelector::CaseSelector(CaseSelector&&) = default;

View File

@ -26,7 +26,7 @@ namespace tint::ast {
DiagnosticAttribute::DiagnosticAttribute(ProgramID pid,
NodeID nid,
const Source& src,
ast::DiagnosticControl&& dc)
DiagnosticControl&& dc)
: Base(pid, nid, src), control(std::move(dc)) {}
DiagnosticAttribute::~DiagnosticAttribute() = default;

View File

@ -30,7 +30,7 @@ class DiagnosticAttribute final : public Castable<DiagnosticAttribute, Attribute
/// @param nid the unique node identifier
/// @param src the source of this node
/// @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;
/// @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;
/// The diagnostic control.
const ast::DiagnosticControl control;
const DiagnosticControl control;
};
} // namespace tint::ast

View File

@ -28,7 +28,7 @@ TEST_F(DiagnosticControlTest, Assert_RuleNotTemplated) {
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;
ast::DiagnosticControl control(builtin::DiagnosticSeverity::kWarning,
DiagnosticControl control(builtin::DiagnosticSeverity::kWarning,
b.Ident("name", "a", "b", "c"));
},
"internal compiler error");

View File

@ -22,15 +22,14 @@ namespace {
using DiagnosticDirectiveTest = TestHelper;
TEST_F(DiagnosticDirectiveTest, Creation) {
auto* name = Ident("foo");
DiagnosticControl control(builtin::DiagnosticSeverity::kWarning, name);
auto* diag = create<ast::DiagnosticDirective>(Source{{{10, 5}, {10, 15}}}, std::move(control));
auto* diag = DiagnosticDirective(Source{{{10, 5}, {10, 15}}},
builtin::DiagnosticSeverity::kWarning, "foo");
EXPECT_EQ(diag->source.range.begin.line, 10u);
EXPECT_EQ(diag->source.range.begin.column, 5u);
EXPECT_EQ(diag->source.range.end.line, 10u);
EXPECT_EQ(diag->source.range.end.column, 15u);
EXPECT_EQ(diag->control.severity, builtin::DiagnosticSeverity::kWarning);
EXPECT_EQ(diag->control.rule_name, name);
CheckIdentifier(Symbols(), diag->control.rule_name, "foo");
}
} // namespace

View File

@ -22,7 +22,7 @@ namespace {
using EnableTest = TestHelper;
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.column, 2u);
EXPECT_EQ(ext->source.range.end.line, 20u);

View File

@ -68,7 +68,7 @@ class Function final : public Castable<Function, Node> {
ast::PipelineStage PipelineStage() const;
/// @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`
/// `ctx`.
@ -111,12 +111,12 @@ class FunctionList : public utils::Vector<const Function*, 8> {
/// @param sym the function symbol to search for
/// @param stage the pipeline stage
/// @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
/// @returns true if the Builder contains an entrypoint function with
/// the given stage
bool HasStage(PipelineStage stage) const;
bool HasStage(ast::PipelineStage stage) const;
};
} // namespace tint::ast

View File

@ -65,23 +65,23 @@ TEST_F(FunctionTest, Creation_Body_Vector) {
auto* f = Func("func", utils::Empty, ty.void_(), utils::Vector{Discard(), Return()});
ASSERT_NE(f->body, nullptr);
ASSERT_EQ(f->body->statements.Length(), 2u);
EXPECT_TRUE(f->body->statements[0]->Is<ast::DiscardStatement>());
EXPECT_TRUE(f->body->statements[1]->Is<ast::ReturnStatement>());
EXPECT_TRUE(f->body->statements[0]->Is<DiscardStatement>());
EXPECT_TRUE(f->body->statements[1]->Is<ReturnStatement>());
}
TEST_F(FunctionTest, Creation_Body_Block) {
auto* f = Func("func", utils::Empty, ty.void_(), Block(Discard(), Return()));
ASSERT_NE(f->body, nullptr);
ASSERT_EQ(f->body->statements.Length(), 2u);
EXPECT_TRUE(f->body->statements[0]->Is<ast::DiscardStatement>());
EXPECT_TRUE(f->body->statements[1]->Is<ast::ReturnStatement>());
EXPECT_TRUE(f->body->statements[0]->Is<DiscardStatement>());
EXPECT_TRUE(f->body->statements[1]->Is<ReturnStatement>());
}
TEST_F(FunctionTest, Creation_Body_Stmt) {
auto* f = Func("func", utils::Empty, ty.void_(), Return());
ASSERT_NE(f->body, nullptr);
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) {
@ -117,7 +117,7 @@ TEST_F(FunctionTest, Assert_TemplatedName) {
}
TEST_F(FunctionTest, Assert_NullParam) {
using ParamList = utils::Vector<const ast::Parameter*, 2>;
using ParamList = utils::Vector<const Parameter*, 2>;
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;

View File

@ -22,10 +22,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupAttribute);
namespace tint::ast {
GroupAttribute::GroupAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* exp)
GroupAttribute::GroupAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* exp)
: Base(pid, nid, src), expr(exp) {}
GroupAttribute::~GroupAttribute() = default;

View File

@ -30,7 +30,7 @@ class GroupAttribute final : public Castable<GroupAttribute, Attribute> {
/// @param nid the unique node identifier
/// @param src the source of this node
/// @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;
/// @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;
/// The group expression
const ast::Expression* const expr;
const Expression* const expr;
};
} // namespace tint::ast

View File

@ -22,7 +22,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::IdAttribute);
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) {}
IdAttribute::~IdAttribute() = default;

View File

@ -30,7 +30,7 @@ class IdAttribute final : public Castable<IdAttribute, Attribute> {
/// @param nid the unique node identifier
/// @param src the source of this node
/// @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;
/// @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;
/// The id expression
const ast::Expression* const expr;
const Expression* const expr;
};
} // namespace tint::ast

View File

@ -24,7 +24,7 @@ using IdAttributeTest = TestHelper;
TEST_F(IdAttributeTest, Creation) {
auto* d = Id(12_a);
EXPECT_TRUE(d->expr->Is<ast::IntLiteralExpression>());
EXPECT_TRUE(d->expr->Is<IntLiteralExpression>());
}
} // namespace

View File

@ -20,7 +20,7 @@
namespace tint::ast {
/// An identifier
class Identifier : public Castable<Identifier, ast::Node> {
class Identifier : public Castable<Identifier, Node> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -30,10 +30,10 @@ TEST_F(IdentifierExpressionTest, Creation) {
TEST_F(IdentifierExpressionTest, CreationTemplated) {
auto* i = Expr(Ident("ident", true));
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);
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) {

View File

@ -33,7 +33,7 @@ IfStatement::IfStatement(ProgramID pid,
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
if (else_statement) {
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>()));
}
}

View File

@ -25,7 +25,7 @@ namespace tint::ast {
LocationAttribute::LocationAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* exp)
const Expression* exp)
: Base(pid, nid, src), expr(exp) {}
LocationAttribute::~LocationAttribute() = default;

View File

@ -30,7 +30,7 @@ class LocationAttribute final : public Castable<LocationAttribute, Attribute> {
/// @param nid the unique node identifier
/// @param src the source of this node
/// @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;
/// @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;
/// The location expression
const ast::Expression* const expr;
const Expression* const expr;
};
} // namespace tint::ast

View File

@ -28,7 +28,7 @@ Module::Module(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, sr
Module::Module(ProgramID pid,
NodeID nid,
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)) {
for (auto* decl : global_declarations_) {
if (decl == nullptr) {
@ -41,7 +41,7 @@ Module::Module(ProgramID pid,
Module::~Module() = default;
const ast::TypeDecl* Module::LookupType(Symbol name) const {
const TypeDecl* Module::LookupType(Symbol name) const {
for (auto* ty : TypeDecls()) {
if (ty->name->symbol == name) {
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) {
Switch(
decl, //
[&](const ast::TypeDecl* type) {
[&](const TypeDecl* type) {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
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"; });
}
void Module::AddDiagnosticDirective(const ast::DiagnosticDirective* directive) {
void Module::AddDiagnosticDirective(const DiagnosticDirective* directive) {
TINT_ASSERT(AST, directive);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, directive, program_id);
global_declarations_.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_PROGRAM_IDS_EQUAL_IF_VALID(AST, enable, program_id);
global_declarations_.Push(enable);
enables_.Push(enable);
}
void Module::AddGlobalVariable(const ast::Variable* var) {
void Module::AddGlobalVariable(const Variable* var) {
TINT_ASSERT(AST, var);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, var, program_id);
global_variables_.Push(var);
@ -114,14 +114,14 @@ void Module::AddConstAssert(const ConstAssert* assertion) {
global_declarations_.Push(assertion);
}
void Module::AddTypeDecl(const ast::TypeDecl* type) {
void Module::AddTypeDecl(const TypeDecl* type) {
TINT_ASSERT(AST, type);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
type_decls_.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_PROGRAM_IDS_EQUAL_IF_VALID(AST, func, program_id);
functions_.Push(func);

View File

@ -46,7 +46,7 @@ class Module final : public Castable<Module, Node> {
Module(ProgramID pid,
NodeID nid,
const Source& src,
utils::VectorRef<const ast::Node*> global_decls);
utils::VectorRef<const Node*> global_decls);
/// Destructor
~Module() override;
@ -80,7 +80,7 @@ class Module final : public Castable<Module, Node> {
auto& GlobalVariables() { return global_variables_; }
/// @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 {
utils::Vector<const T*, 32> out;
out.Reserve(global_variables_.Length());

View File

@ -135,7 +135,7 @@ const declaration_order_check_4 : i32 = 1;
EXPECT_EQ(Program::printer(&src), Program::printer(&dst));
// 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()) {
src_nodes.emplace(src_node);
}

View File

@ -61,9 +61,8 @@ TEST_F(ModuleTest, Assert_DifferentProgramID_Function) {
{
ProgramBuilder b1;
ProgramBuilder b2;
b1.AST().AddFunction(b2.create<ast::Function>(b2.Ident("func"), utils::Empty,
b2.ty.f32(), b2.Block(), utils::Empty,
utils::Empty));
b1.AST().AddFunction(b2.create<Function>(b2.Ident("func"), utils::Empty, b2.ty.f32(),
b2.Block(), utils::Empty, utils::Empty));
},
"internal compiler error");
}
@ -102,7 +101,7 @@ TEST_F(ModuleTest, CloneOrder) {
// declaration that triggered the ReplaceAll().
ProgramBuilder cloned;
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());
return nullptr;
});
@ -110,7 +109,7 @@ TEST_F(ModuleTest, CloneOrder) {
ctx.dst->Alias("inserted_before_A", cloned.ty.u32());
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());
return nullptr;
});
@ -118,9 +117,9 @@ TEST_F(ModuleTest, CloneOrder) {
auto& decls = cloned.AST().GlobalDeclarations();
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[5]->Is<ast::Variable>());
EXPECT_TRUE(decls[5]->Is<Variable>());
ASSERT_TRUE(decls[0]->Is<ast::Alias>());
ASSERT_TRUE(decls[2]->Is<ast::Alias>());

View File

@ -26,8 +26,8 @@ Struct::Struct(ProgramID pid,
NodeID nid,
const Source& src,
const Identifier* n,
utils::VectorRef<const ast::StructMember*> m,
utils::VectorRef<const ast::Attribute*> attrs)
utils::VectorRef<const StructMember*> m,
utils::VectorRef<const Attribute*> attrs)
: Base(pid, nid, src, n), members(std::move(m)), attributes(std::move(attrs)) {
for (auto* mem : members) {
TINT_ASSERT(AST, mem);

View File

@ -39,8 +39,8 @@ class Struct final : public Castable<Struct, TypeDecl> {
NodeID nid,
const Source& src,
const Identifier* name,
utils::VectorRef<const ast::StructMember*> members,
utils::VectorRef<const ast::Attribute*> attributes);
utils::VectorRef<const StructMember*> members,
utils::VectorRef<const Attribute*> attributes);
/// Move constructor
Struct(Struct&&);
@ -53,10 +53,10 @@ class Struct final : public Castable<Struct, TypeDecl> {
const Struct* Clone(CloneContext* ctx) const override;
/// The members
const utils::Vector<const ast::StructMember*, 8> members;
const utils::Vector<const StructMember*, 8> members;
/// The struct attributes
const utils::Vector<const ast::Attribute*, 4> attributes;
const utils::Vector<const Attribute*, 4> attributes;
};
} // namespace tint::ast

View File

@ -26,7 +26,7 @@ namespace tint::ast {
StructMemberAlignAttribute::StructMemberAlignAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* a)
const Expression* a)
: Base(pid, nid, src), expr(a) {}
StructMemberAlignAttribute::~StructMemberAlignAttribute() = default;

View File

@ -34,7 +34,7 @@ class StructMemberAlignAttribute final : public Castable<StructMemberAlignAttrib
StructMemberAlignAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* align);
const Expression* align);
~StructMemberAlignAttribute() override;
/// @returns the WGSL name for the attribute
@ -47,7 +47,7 @@ class StructMemberAlignAttribute final : public Castable<StructMemberAlignAttrib
const StructMemberAlignAttribute* Clone(CloneContext* ctx) const override;
/// The align expression
const ast::Expression* const expr;
const Expression* const expr;
};
} // namespace tint::ast

View File

@ -25,7 +25,7 @@ namespace tint::ast {
StructMemberOffsetAttribute::StructMemberOffsetAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* exp)
const Expression* exp)
: Base(pid, nid, src), expr(exp) {}
StructMemberOffsetAttribute::~StructMemberOffsetAttribute() = default;

View File

@ -42,7 +42,7 @@ class StructMemberOffsetAttribute final : public Castable<StructMemberOffsetAttr
StructMemberOffsetAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* expr);
const Expression* expr);
~StructMemberOffsetAttribute() override;
/// @returns the WGSL name for the attribute
@ -55,7 +55,7 @@ class StructMemberOffsetAttribute final : public Castable<StructMemberOffsetAttr
const StructMemberOffsetAttribute* Clone(CloneContext* ctx) const override;
/// The offset expression
const ast::Expression* const expr;
const Expression* const expr;
};
} // namespace tint::ast

View File

@ -22,8 +22,8 @@ using StructMemberOffsetAttributeTest = TestHelper;
TEST_F(StructMemberOffsetAttributeTest, Creation) {
auto* d = MemberOffset(2_u);
ASSERT_TRUE(d->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(2u, d->expr->As<ast::IntLiteralExpression>()->value);
ASSERT_TRUE(d->expr->Is<IntLiteralExpression>());
EXPECT_EQ(2u, d->expr->As<IntLiteralExpression>()->value);
}
} // namespace

View File

@ -26,7 +26,7 @@ namespace tint::ast {
StructMemberSizeAttribute::StructMemberSizeAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* exp)
const Expression* exp)
: Base(pid, nid, src), expr(exp) {}
StructMemberSizeAttribute::~StructMemberSizeAttribute() = default;

View File

@ -31,10 +31,7 @@ class StructMemberSizeAttribute final : public Castable<StructMemberSizeAttribut
/// @param nid the unique node identifier
/// @param src the source of this node
/// @param expr the size expression
StructMemberSizeAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* expr);
StructMemberSizeAttribute(ProgramID pid, NodeID nid, const Source& src, const Expression* expr);
~StructMemberSizeAttribute() override;
/// @returns the WGSL name for the attribute
@ -47,7 +44,7 @@ class StructMemberSizeAttribute final : public Castable<StructMemberSizeAttribut
const StructMemberSizeAttribute* Clone(CloneContext* ctx) const override;
/// The size expression
const ast::Expression* const expr;
const Expression* const expr;
};
} // namespace tint::ast

View File

@ -24,8 +24,8 @@ using StructMemberSizeAttributeTest = TestHelper;
TEST_F(StructMemberSizeAttributeTest, Creation) {
auto* d = MemberSize(2_u);
ASSERT_TRUE(d->expr->Is<ast::IntLiteralExpression>());
EXPECT_EQ(2u, d->expr->As<ast::IntLiteralExpression>()->value);
ASSERT_TRUE(d->expr->Is<IntLiteralExpression>());
EXPECT_EQ(2u, d->expr->As<IntLiteralExpression>()->value);
}
} // namespace

View File

@ -23,8 +23,8 @@ using StructMemberTest = TestHelper;
TEST_F(StructMemberTest, Creation) {
auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)});
ast::CheckIdentifier(Symbols(), st->name, "a");
ast::CheckIdentifier(Symbols(), st->type, "i32");
CheckIdentifier(Symbols(), st->name, "a");
CheckIdentifier(Symbols(), st->type, "i32");
EXPECT_EQ(st->attributes.Length(), 1u);
EXPECT_TRUE(st->attributes[0]->Is<StructMemberSizeAttribute>());
EXPECT_EQ(st->source.range.begin.line, 0u);
@ -36,8 +36,8 @@ TEST_F(StructMemberTest, Creation) {
TEST_F(StructMemberTest, CreationWithSource) {
auto* st = Member(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, "a",
ty.i32());
ast::CheckIdentifier(Symbols(), st->name, "a");
ast::CheckIdentifier(Symbols(), st->type, "i32");
CheckIdentifier(Symbols(), st->name, "a");
CheckIdentifier(Symbols(), st->type, "i32");
EXPECT_EQ(st->attributes.Length(), 0u);
EXPECT_EQ(st->source.range.begin.line, 27u);
EXPECT_EQ(st->source.range.begin.column, 4u);
@ -58,7 +58,7 @@ TEST_F(StructMemberTest, Assert_Null_Type) {
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;
b.Member("a", ast::Type{});
b.Member("a", Type{});
},
"internal compiler error");
}

View File

@ -83,7 +83,7 @@ TEST_F(AstStructTest, Assert_Null_Attribute) {
{
ProgramBuilder b;
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");
}

View File

@ -53,7 +53,7 @@ TEST_F(SwitchStatementTest, IsSwitch) {
}
TEST_F(SwitchStatementTest, Assert_Null_Condition) {
using CaseStatementList = utils::Vector<const ast::CaseStatement*, 2>;
using CaseStatementList = utils::Vector<const CaseStatement*, 2>;
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;
@ -66,7 +66,7 @@ TEST_F(SwitchStatementTest, Assert_Null_Condition) {
}
TEST_F(SwitchStatementTest, Assert_Null_CaseStatement) {
using CaseStatementList = utils::Vector<const ast::CaseStatement*, 2>;
using CaseStatementList = utils::Vector<const CaseStatement*, 2>;
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;

View File

@ -57,24 +57,22 @@ enum class TraverseOrder {
/// @param diags the diagnostics used for error messages
/// @param callback the callback function. Must be of the signature:
/// `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
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>>;
constexpr static bool kHasDepthArg = traits::SignatureOfT<CALLBACK>::parameter_count == 2;
struct Pending {
const ast::Expression* expr;
const Expression* expr;
size_t depth;
};
utils::Vector<Pending, 32> to_visit{{root, 0}};
auto push_single = [&](const ast::Expression* expr, size_t depth) {
to_visit.Push({expr, depth});
};
auto push_pair = [&](const ast::Expression* left, const ast::Expression* right, size_t depth) {
auto push_single = [&](const Expression* expr, size_t depth) { to_visit.Push({expr, depth}); };
auto push_pair = [&](const Expression* left, const Expression* right, size_t depth) {
if (ORDER == TraverseOrder::LeftToRight) {
to_visit.Push({right, 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});
}
};
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) {
for (auto* expr : utils::Reverse(exprs)) {
to_visit.Push({expr, depth});
@ -97,7 +95,7 @@ bool TraverseExpressions(const ast::Expression* root, diag::List& diags, CALLBAC
while (!to_visit.IsEmpty()) {
auto p = to_visit.Pop();
const ast::Expression* expr = p.expr;
const Expression* expr = p.expr;
if (auto* filtered = expr->template As<EXPR_TYPE>()) {
TraverseAction result;

View File

@ -26,66 +26,66 @@ namespace {
using TraverseExpressionsTest = TestHelper;
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 ast::Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
std::vector<const Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
auto* root = IndexAccessor(i[0], i[1]);
{
std::vector<const ast::Expression*> l2r;
std::vector<const Expression*> l2r;
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* 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]));
}
{
std::vector<const ast::Expression*> r2l;
std::vector<const Expression*> r2l;
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* 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]));
}
}
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 ast::Expression*> i = {Add(e[0], e[1]), Sub(e[2], e[3])};
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
std::vector<const Expression*> i = {Add(e[0], e[1]), Sub(e[2], e[3])};
auto* root = Mul(i[0], i[1]);
{
std::vector<const ast::Expression*> l2r;
std::vector<const Expression*> l2r;
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* 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]));
}
{
std::vector<const ast::Expression*> r2l;
std::vector<const Expression*> r2l;
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* 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]));
}
}
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 ast::Expression*> i = {Add(e[0], e[1]), Sub(e[2], e[3])};
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
std::vector<const Expression*> i = {Add(e[0], e[1]), Sub(e[2], e[3])};
auto* root = Mul(i[0], i[1]);
size_t j = 0;
size_t depths[] = {0, 1, 2, 2, 1, 2, 2};
{
TraverseExpressions<TraverseOrder::LeftToRight>( //
root, Diagnostics(), [&](const ast::Expression* expr, size_t depth) {
root, Diagnostics(), [&](const Expression* expr, size_t depth) {
(void)expr;
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* root = Bitcast<i32>(b2);
{
utils::Vector<const ast::Expression*, 8> l2r;
utils::Vector<const Expression*, 8> l2r;
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* expr) {
l2r.Push(expr);
return ast::TraverseAction::Descend;
return TraverseAction::Descend;
});
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(),
[&](const ast::Expression* expr) {
[&](const Expression* expr) {
r2l.Push(expr);
return ast::TraverseAction::Descend;
return TraverseAction::Descend;
});
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])};
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(),
[&](const ast::Expression* expr) {
[&](const Expression* 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]));
}
{
utils::Vector<const ast::Expression*, 8> r2l;
utils::Vector<const Expression*, 8> r2l;
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* 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]));
}
@ -145,20 +145,20 @@ TEST_F(TraverseExpressionsTest, DescendMemberAccessorExpression) {
auto* m = MemberAccessor(e, "a");
auto* root = MemberAccessor(m, "b");
{
std::vector<const ast::Expression*> l2r;
std::vector<const Expression*> l2r;
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* expr) {
l2r.push_back(expr);
return ast::TraverseAction::Descend;
return TraverseAction::Descend;
});
EXPECT_THAT(l2r, ElementsAre(root, m, e));
}
{
std::vector<const ast::Expression*> r2l;
std::vector<const Expression*> r2l;
TraverseExpressions<TraverseOrder::RightToLeft>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* expr) {
r2l.push_back(expr);
return ast::TraverseAction::Descend;
return TraverseAction::Descend;
});
EXPECT_THAT(r2l, ElementsAre(root, m, e));
}
@ -173,20 +173,20 @@ TEST_F(TraverseExpressionsTest, DescendMemberIndexExpression) {
auto* f = IndexAccessor(d, e);
auto* root = IndexAccessor(c, f);
{
std::vector<const ast::Expression*> l2r;
std::vector<const Expression*> l2r;
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* expr) {
l2r.push_back(expr);
return ast::TraverseAction::Descend;
return TraverseAction::Descend;
});
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(),
[&](const ast::Expression* expr) {
[&](const Expression* expr) {
r2l.push_back(expr);
return ast::TraverseAction::Descend;
return TraverseAction::Descend;
});
EXPECT_THAT(r2l, ElementsAre(root, f, e, d, c, b, a));
}
@ -199,47 +199,47 @@ TEST_F(TraverseExpressionsTest, DescendUnaryExpression) {
auto* u2 = AddressOf(u1);
auto* root = Deref(u2);
{
std::vector<const ast::Expression*> l2r;
std::vector<const Expression*> l2r;
TraverseExpressions<TraverseOrder::LeftToRight>(root, Diagnostics(),
[&](const ast::Expression* expr) {
[&](const Expression* expr) {
l2r.push_back(expr);
return ast::TraverseAction::Descend;
return TraverseAction::Descend;
});
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(),
[&](const ast::Expression* expr) {
[&](const Expression* expr) {
r2l.push_back(expr);
return ast::TraverseAction::Descend;
return TraverseAction::Descend;
});
EXPECT_THAT(r2l, ElementsAre(root, u2, u1, u0, e));
}
}
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 ast::Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
std::vector<const Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
auto* root = IndexAccessor(i[0], i[1]);
std::vector<const ast::Expression*> order;
std::vector<const Expression*> order;
TraverseExpressions<TraverseOrder::LeftToRight>(
root, Diagnostics(), [&](const ast::Expression* expr) {
root, Diagnostics(), [&](const Expression* 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]));
}
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 ast::Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
std::vector<const Expression*> e = {Expr(1_i), Expr(1_i), Expr(1_i), Expr(1_i)};
std::vector<const Expression*> i = {IndexAccessor(e[0], e[1]), IndexAccessor(e[2], e[3])};
auto* root = IndexAccessor(i[0], i[1]);
std::vector<const ast::Expression*> order;
std::vector<const Expression*> order;
TraverseExpressions<TraverseOrder::LeftToRight>(
root, Diagnostics(), [&](const ast::Expression* expr) {
root, Diagnostics(), [&](const Expression* 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]));
}

View File

@ -66,8 +66,8 @@ class Variable : public Castable<Variable, Node> {
/// @returns true if the variable has both group and binding attributes
bool HasBindingPoint() const {
return ast::GetAttribute<ast::BindingAttribute>(attributes) != nullptr &&
ast::GetAttribute<ast::GroupAttribute>(attributes) != nullptr;
return HasAttribute<BindingAttribute>(attributes) &&
HasAttribute<GroupAttribute>(attributes);
}
/// @returns the kind of the variable, which can be used in diagnostics

View File

@ -98,14 +98,14 @@ TEST_F(VariableTest, WithAttributes) {
Builtin(builtin::BuiltinValue::kPosition), Id(1200_u));
auto& attributes = var->attributes;
EXPECT_TRUE(ast::HasAttribute<ast::LocationAttribute>(attributes));
EXPECT_TRUE(ast::HasAttribute<ast::BuiltinAttribute>(attributes));
EXPECT_TRUE(ast::HasAttribute<ast::IdAttribute>(attributes));
EXPECT_TRUE(ast::HasAttribute<LocationAttribute>(attributes));
EXPECT_TRUE(ast::HasAttribute<BuiltinAttribute>(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->expr);
EXPECT_TRUE(location->expr->Is<ast::IntLiteralExpression>());
EXPECT_TRUE(location->expr->Is<IntLiteralExpression>());
}
TEST_F(VariableTest, HasBindingPoint_BothProvided) {

View File

@ -25,9 +25,9 @@ namespace tint::ast {
WorkgroupAttribute::WorkgroupAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* x_,
const ast::Expression* y_,
const ast::Expression* z_)
const Expression* x_,
const Expression* y_,
const Expression* z_)
: Base(pid, nid, src), x(x_), y(y_), z(z_) {}
WorkgroupAttribute::~WorkgroupAttribute() = default;

View File

@ -40,14 +40,14 @@ class WorkgroupAttribute final : public Castable<WorkgroupAttribute, Attribute>
WorkgroupAttribute(ProgramID pid,
NodeID nid,
const Source& src,
const ast::Expression* x,
const ast::Expression* y = nullptr,
const ast::Expression* z = nullptr);
const Expression* x,
const Expression* y = nullptr,
const Expression* z = nullptr);
~WorkgroupAttribute() override;
/// @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
std::string Name() const override;
@ -59,11 +59,11 @@ class WorkgroupAttribute final : public Castable<WorkgroupAttribute, Attribute>
const WorkgroupAttribute* Clone(CloneContext* ctx) const override;
/// The workgroup x dimension.
const ast::Expression* const x;
const Expression* const x;
/// 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.
const ast::Expression* const z = nullptr;
const Expression* const z = nullptr;
};
} // namespace tint::ast

View File

@ -28,8 +28,8 @@ TEST_F(WorkgroupAttributeTest, Creation_1param) {
auto* d = WorkgroupSize(2_i);
auto values = d->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->value, 2);
ASSERT_TRUE(values[0]->Is<IntLiteralExpression>());
EXPECT_EQ(values[0]->As<IntLiteralExpression>()->value, 2);
EXPECT_EQ(values[1], nullptr);
EXPECT_EQ(values[2], nullptr);
@ -38,11 +38,11 @@ TEST_F(WorkgroupAttributeTest, Creation_2param) {
auto* d = WorkgroupSize(2_i, 4_i);
auto values = d->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->value, 2);
ASSERT_TRUE(values[0]->Is<IntLiteralExpression>());
EXPECT_EQ(values[0]->As<IntLiteralExpression>()->value, 2);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->value, 4);
ASSERT_TRUE(values[1]->Is<IntLiteralExpression>());
EXPECT_EQ(values[1]->As<IntLiteralExpression>()->value, 4);
EXPECT_EQ(values[2], nullptr);
}
@ -51,27 +51,27 @@ TEST_F(WorkgroupAttributeTest, Creation_3param) {
auto* d = WorkgroupSize(2_i, 4_i, 6_i);
auto values = d->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->value, 2);
ASSERT_TRUE(values[0]->Is<IntLiteralExpression>());
EXPECT_EQ(values[0]->As<IntLiteralExpression>()->value, 2);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->value, 4);
ASSERT_TRUE(values[1]->Is<IntLiteralExpression>());
EXPECT_EQ(values[1]->As<IntLiteralExpression>()->value, 4);
ASSERT_TRUE(values[2]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[2]->As<ast::IntLiteralExpression>()->value, 6);
ASSERT_TRUE(values[2]->Is<IntLiteralExpression>());
EXPECT_EQ(values[2]->As<IntLiteralExpression>()->value, 6);
}
TEST_F(WorkgroupAttributeTest, Creation_WithIdentifier) {
auto* d = WorkgroupSize(2_i, 4_i, "depth");
auto values = d->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->value, 2);
ASSERT_TRUE(values[0]->Is<IntLiteralExpression>());
EXPECT_EQ(values[0]->As<IntLiteralExpression>()->value, 2);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->value, 4);
ASSERT_TRUE(values[1]->Is<IntLiteralExpression>());
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);
EXPECT_EQ(Symbols().NameFor(z_ident->identifier->symbol), "depth");
}