ast: Add 'Expression' suffix to literals (2/2)

Literals are now expressions, so in keeping with all the other
expression types, suffix the class name with Expression.

I'm not overly keen on requiring everything to have an Expression
suffix, but consistency is better than personal preference.

Note: this should have been part of 30848b6, but I managed to drop
this change instead of squashing it. Opps.

Bug: tint:888
Change-Id: Idfaf96abe165a6bf5028e60a160e7408aa2bf9db
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68943
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-11-10 19:23:07 +00:00 committed by Ben Clayton
parent 6595b386b5
commit 5c9a80b6f6
77 changed files with 449 additions and 417 deletions

View File

@ -30,7 +30,7 @@ std::string SizeExprToString(const Expression* size,
if (auto* ident = size->As<IdentifierExpression>()) {
return symbols.NameFor(ident->symbol);
}
if (auto* literal = size->As<IntLiteral>()) {
if (auto* literal = size->As<IntLiteralExpression>()) {
return std::to_string(literal->ValueAsU32());
}
// This will never be exposed to the user as the Resolver will reject this

View File

@ -16,20 +16,23 @@
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteral);
TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteralExpression);
namespace tint {
namespace ast {
BoolLiteral::BoolLiteral(ProgramID pid, const Source& src, bool val)
BoolLiteralExpression::BoolLiteralExpression(ProgramID pid,
const Source& src,
bool val)
: Base(pid, src), value(val) {}
BoolLiteral::~BoolLiteral() = default;
BoolLiteralExpression::~BoolLiteralExpression() = default;
const BoolLiteral* BoolLiteral::Clone(CloneContext* ctx) const {
const BoolLiteralExpression* BoolLiteralExpression::Clone(
CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<BoolLiteral>(src, value);
return ctx->dst->create<BoolLiteralExpression>(src, value);
}
} // namespace ast

View File

@ -23,20 +23,21 @@ namespace tint {
namespace ast {
/// A boolean literal
class BoolLiteral : public Castable<BoolLiteral, Literal> {
class BoolLiteralExpression
: public Castable<BoolLiteralExpression, LiteralExpression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param value the bool literals value
BoolLiteral(ProgramID pid, const Source& src, bool value);
~BoolLiteral() override;
BoolLiteralExpression(ProgramID pid, const Source& src, bool value);
~BoolLiteralExpression() override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
const BoolLiteral* Clone(CloneContext* ctx) const override;
const BoolLiteralExpression* Clone(CloneContext* ctx) const override;
/// The boolean literal value
const bool value;

View File

@ -18,17 +18,17 @@ namespace tint {
namespace ast {
namespace {
using BoolLiteralTest = TestHelper;
using BoolLiteralExpressionTest = TestHelper;
TEST_F(BoolLiteralTest, True) {
auto* b = create<BoolLiteral>(true);
ASSERT_TRUE(b->Is<BoolLiteral>());
TEST_F(BoolLiteralExpressionTest, True) {
auto* b = create<BoolLiteralExpression>(true);
ASSERT_TRUE(b->Is<BoolLiteralExpression>());
ASSERT_TRUE(b->value);
}
TEST_F(BoolLiteralTest, False) {
auto* b = create<BoolLiteral>(false);
ASSERT_TRUE(b->Is<BoolLiteral>());
TEST_F(BoolLiteralExpressionTest, False) {
auto* b = create<BoolLiteralExpression>(false);
ASSERT_TRUE(b->Is<BoolLiteralExpression>());
ASSERT_FALSE(b->value);
}

View File

@ -24,7 +24,7 @@ namespace tint {
namespace ast {
/// A list of case literals
using CaseSelectorList = std::vector<const IntLiteral*>;
using CaseSelectorList = std::vector<const IntLiteralExpression*>;
/// A case statement
class CaseStatement : public Castable<CaseStatement, Statement> {

View File

@ -27,7 +27,7 @@ using CaseStatementTest = TestHelper;
TEST_F(CaseStatementTest, Creation_i32) {
CaseSelectorList b;
auto* selector = create<SintLiteral>(2);
auto* selector = create<SintLiteralExpression>(2);
b.push_back(selector);
auto* discard = create<DiscardStatement>();
@ -42,7 +42,7 @@ TEST_F(CaseStatementTest, Creation_i32) {
TEST_F(CaseStatementTest, Creation_u32) {
CaseSelectorList b;
auto* selector = create<UintLiteral>(2u);
auto* selector = create<UintLiteralExpression>(2u);
b.push_back(selector);
auto* discard = create<DiscardStatement>();
@ -57,7 +57,7 @@ TEST_F(CaseStatementTest, Creation_u32) {
TEST_F(CaseStatementTest, Creation_WithSource) {
CaseSelectorList b;
b.push_back(create<SintLiteral>(2));
b.push_back(create<SintLiteralExpression>(2));
auto* body = create<BlockStatement>(StatementList{
create<DiscardStatement>(),
@ -78,7 +78,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
CaseSelectorList b;
b.push_back(create<SintLiteral>(2));
b.push_back(create<SintLiteralExpression>(2));
auto* c = create<CaseStatement>(b, create<BlockStatement>(StatementList{}));
EXPECT_FALSE(c->IsDefault());
@ -125,7 +125,8 @@ TEST_F(CaseStatementTest, Assert_DifferentProgramID_Selector) {
{
ProgramBuilder b1;
ProgramBuilder b2;
b1.create<CaseStatement>(CaseSelectorList{b2.create<SintLiteral>(2)},
b1.create<CaseStatement>(
CaseSelectorList{b2.create<SintLiteralExpression>(2)},
b1.create<BlockStatement>(StatementList{}));
},
"internal compiler error");

View File

@ -18,20 +18,23 @@
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::FloatLiteral);
TINT_INSTANTIATE_TYPEINFO(tint::ast::FloatLiteralExpression);
namespace tint {
namespace ast {
FloatLiteral::FloatLiteral(ProgramID pid, const Source& src, float val)
FloatLiteralExpression::FloatLiteralExpression(ProgramID pid,
const Source& src,
float val)
: Base(pid, src), value(val) {}
FloatLiteral::~FloatLiteral() = default;
FloatLiteralExpression::~FloatLiteralExpression() = default;
const FloatLiteral* FloatLiteral::Clone(CloneContext* ctx) const {
const FloatLiteralExpression* FloatLiteralExpression::Clone(
CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<FloatLiteral>(src, value);
return ctx->dst->create<FloatLiteralExpression>(src, value);
}
} // namespace ast

View File

@ -23,20 +23,21 @@ namespace tint {
namespace ast {
/// A float literal
class FloatLiteral : public Castable<FloatLiteral, Literal> {
class FloatLiteralExpression
: public Castable<FloatLiteralExpression, LiteralExpression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param value the float literals value
FloatLiteral(ProgramID pid, const Source& src, float value);
~FloatLiteral() override;
FloatLiteralExpression(ProgramID pid, const Source& src, float value);
~FloatLiteralExpression() override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
const FloatLiteral* Clone(CloneContext* ctx) const override;
const FloatLiteralExpression* Clone(CloneContext* ctx) const override;
/// The float literal value
const float value;

View File

@ -18,11 +18,11 @@ namespace tint {
namespace ast {
namespace {
using FloatLiteralTest = TestHelper;
using FloatLiteralExpressionTest = TestHelper;
TEST_F(FloatLiteralTest, Value) {
auto* f = create<FloatLiteral>(47.2f);
ASSERT_TRUE(f->Is<FloatLiteral>());
TEST_F(FloatLiteralExpressionTest, Value) {
auto* f = create<FloatLiteralExpression>(47.2f);
ASSERT_TRUE(f->Is<FloatLiteralExpression>());
EXPECT_EQ(f->value, 47.2f);
}

View File

@ -14,14 +14,15 @@
#include "src/ast/int_literal_expression.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::IntLiteral);
TINT_INSTANTIATE_TYPEINFO(tint::ast::IntLiteralExpression);
namespace tint {
namespace ast {
IntLiteral::IntLiteral(ProgramID pid, const Source& src) : Base(pid, src) {}
IntLiteralExpression::IntLiteralExpression(ProgramID pid, const Source& src)
: Base(pid, src) {}
IntLiteral::~IntLiteral() = default;
IntLiteralExpression::~IntLiteralExpression() = default;
} // namespace ast
} // namespace tint

View File

@ -21,9 +21,10 @@ namespace tint {
namespace ast {
/// An integer literal. This could be either signed or unsigned.
class IntLiteral : public Castable<IntLiteral, Literal> {
class IntLiteralExpression
: public Castable<IntLiteralExpression, LiteralExpression> {
public:
~IntLiteral() override;
~IntLiteralExpression() override;
/// @returns the literal value as a u32
virtual uint32_t ValueAsU32() const = 0;
@ -35,7 +36,7 @@ class IntLiteral : public Castable<IntLiteral, Literal> {
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
IntLiteral(ProgramID pid, const Source& src);
IntLiteralExpression(ProgramID pid, const Source& src);
}; // namespace ast
} // namespace ast

View File

@ -18,16 +18,16 @@ namespace tint {
namespace ast {
namespace {
using IntLiteralTest = TestHelper;
using IntLiteralExpressionTest = TestHelper;
TEST_F(IntLiteralTest, Sint_IsInt) {
auto* i = create<SintLiteral>(47);
ASSERT_TRUE(i->Is<IntLiteral>());
TEST_F(IntLiteralExpressionTest, Sint_IsInt) {
auto* i = create<SintLiteralExpression>(47);
ASSERT_TRUE(i->Is<IntLiteralExpression>());
}
TEST_F(IntLiteralTest, Uint_IsInt) {
auto* i = create<UintLiteral>(42);
EXPECT_TRUE(i->Is<IntLiteral>());
TEST_F(IntLiteralExpressionTest, Uint_IsInt) {
auto* i = create<UintLiteralExpression>(42);
EXPECT_TRUE(i->Is<IntLiteralExpression>());
}
} // namespace

View File

@ -14,14 +14,15 @@
#include "src/ast/literal_expression.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::Literal);
TINT_INSTANTIATE_TYPEINFO(tint::ast::LiteralExpression);
namespace tint {
namespace ast {
Literal::Literal(ProgramID pid, const Source& src) : Base(pid, src) {}
LiteralExpression::LiteralExpression(ProgramID pid, const Source& src)
: Base(pid, src) {}
Literal::~Literal() = default;
LiteralExpression::~LiteralExpression() = default;
} // namespace ast
} // namespace tint

View File

@ -23,15 +23,15 @@ namespace tint {
namespace ast {
/// Base class for a literal value expressions
class Literal : public Castable<Literal, Expression> {
class LiteralExpression : public Castable<LiteralExpression, Expression> {
public:
~Literal() override;
~LiteralExpression() override;
protected:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param src the input source
Literal(ProgramID pid, const Source& src);
LiteralExpression(ProgramID pid, const Source& src);
};
} // namespace ast

View File

@ -16,24 +16,27 @@
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::SintLiteral);
TINT_INSTANTIATE_TYPEINFO(tint::ast::SintLiteralExpression);
namespace tint {
namespace ast {
SintLiteral::SintLiteral(ProgramID pid, const Source& src, int32_t val)
SintLiteralExpression::SintLiteralExpression(ProgramID pid,
const Source& src,
int32_t val)
: Base(pid, src), value(val) {}
SintLiteral::~SintLiteral() = default;
SintLiteralExpression::~SintLiteralExpression() = default;
uint32_t SintLiteral::ValueAsU32() const {
uint32_t SintLiteralExpression::ValueAsU32() const {
return static_cast<uint32_t>(value);
}
const SintLiteral* SintLiteral::Clone(CloneContext* ctx) const {
const SintLiteralExpression* SintLiteralExpression::Clone(
CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<SintLiteral>(src, value);
return ctx->dst->create<SintLiteralExpression>(src, value);
}
} // namespace ast

View File

@ -23,14 +23,15 @@ namespace tint {
namespace ast {
/// A signed int literal
class SintLiteral : public Castable<SintLiteral, IntLiteral> {
class SintLiteralExpression
: public Castable<SintLiteralExpression, IntLiteralExpression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param value the signed int literals value
SintLiteral(ProgramID pid, const Source& src, int32_t value);
~SintLiteral() override;
SintLiteralExpression(ProgramID pid, const Source& src, int32_t value);
~SintLiteralExpression() override;
/// @returns the literal value as a u32
uint32_t ValueAsU32() const override;
@ -39,7 +40,7 @@ class SintLiteral : public Castable<SintLiteral, IntLiteral> {
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
const SintLiteral* Clone(CloneContext* ctx) const override;
const SintLiteralExpression* Clone(CloneContext* ctx) const override;
/// The int literal value
const int32_t value;

View File

@ -18,11 +18,11 @@ namespace tint {
namespace ast {
namespace {
using SintLiteralTest = TestHelper;
using SintLiteralExpressionTest = TestHelper;
TEST_F(SintLiteralTest, Value) {
auto* i = create<SintLiteral>(47);
ASSERT_TRUE(i->Is<SintLiteral>());
TEST_F(SintLiteralExpressionTest, Value) {
auto* i = create<SintLiteralExpression>(47);
ASSERT_TRUE(i->Is<SintLiteralExpression>());
EXPECT_EQ(i->value, 47);
}

View File

@ -25,7 +25,7 @@ using SwitchStatementTest = TestHelper;
TEST_F(SwitchStatementTest, Creation) {
CaseSelectorList lit;
lit.push_back(create<SintLiteral>(1));
lit.push_back(create<SintLiteralExpression>(1));
auto* ident = Expr("ident");
CaseStatementList body;
@ -50,7 +50,7 @@ TEST_F(SwitchStatementTest, Creation_WithSource) {
TEST_F(SwitchStatementTest, IsSwitch) {
CaseSelectorList lit;
lit.push_back(create<SintLiteral>(2));
lit.push_back(create<SintLiteralExpression>(2));
auto* ident = Expr("ident");
CaseStatementList body;

View File

@ -122,7 +122,7 @@ bool TraverseExpressions(const ast::Expression* root,
to_visit.push_back(member->structure);
} else if (auto* unary = expr->As<UnaryOpExpression>()) {
to_visit.push_back(unary->expr);
} else if (expr->IsAnyOf<Literal, IdentifierExpression,
} else if (expr->IsAnyOf<LiteralExpression, IdentifierExpression,
PhonyExpression>()) {
// Leaf expression
} else {

View File

@ -16,24 +16,27 @@
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::UintLiteral);
TINT_INSTANTIATE_TYPEINFO(tint::ast::UintLiteralExpression);
namespace tint {
namespace ast {
UintLiteral::UintLiteral(ProgramID pid, const Source& src, uint32_t val)
UintLiteralExpression::UintLiteralExpression(ProgramID pid,
const Source& src,
uint32_t val)
: Base(pid, src), value(val) {}
UintLiteral::~UintLiteral() = default;
UintLiteralExpression::~UintLiteralExpression() = default;
uint32_t UintLiteral::ValueAsU32() const {
uint32_t UintLiteralExpression::ValueAsU32() const {
return value;
}
const UintLiteral* UintLiteral::Clone(CloneContext* ctx) const {
const UintLiteralExpression* UintLiteralExpression::Clone(
CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<UintLiteral>(src, value);
return ctx->dst->create<UintLiteralExpression>(src, value);
}
} // namespace ast

View File

@ -23,14 +23,15 @@ namespace tint {
namespace ast {
/// A uint literal
class UintLiteral : public Castable<UintLiteral, IntLiteral> {
class UintLiteralExpression
: public Castable<UintLiteralExpression, IntLiteralExpression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node
/// @param src the source of this node
/// @param value the uint literals value
UintLiteral(ProgramID pid, const Source& src, uint32_t value);
~UintLiteral() override;
UintLiteralExpression(ProgramID pid, const Source& src, uint32_t value);
~UintLiteralExpression() override;
/// @returns the literal value as a u32
uint32_t ValueAsU32() const override;
@ -39,7 +40,7 @@ class UintLiteral : public Castable<UintLiteral, IntLiteral> {
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
const UintLiteral* Clone(CloneContext* ctx) const override;
const UintLiteralExpression* Clone(CloneContext* ctx) const override;
/// The int literal value
const uint32_t value;

View File

@ -18,11 +18,11 @@ namespace tint {
namespace ast {
namespace {
using UintLiteralTest = TestHelper;
using UintLiteralExpressionTest = TestHelper;
TEST_F(UintLiteralTest, Value) {
auto* u = create<UintLiteral>(47);
ASSERT_TRUE(u->Is<UintLiteral>());
TEST_F(UintLiteralExpressionTest, Value) {
auto* u = create<UintLiteralExpression>(47);
ASSERT_TRUE(u->Is<UintLiteralExpression>());
EXPECT_EQ(u->value, 47u);
}

View File

@ -27,8 +27,8 @@ TEST_F(WorkgroupDecorationTest, Creation_1param) {
auto* d = WorkgroupSize(2);
auto values = d->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 2u);
EXPECT_EQ(values[1], nullptr);
EXPECT_EQ(values[2], nullptr);
@ -37,11 +37,11 @@ TEST_F(WorkgroupDecorationTest, Creation_2param) {
auto* d = WorkgroupSize(2, 4);
auto values = d->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteral>());
EXPECT_EQ(values[1]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
EXPECT_EQ(values[2], nullptr);
}
@ -50,25 +50,25 @@ TEST_F(WorkgroupDecorationTest, Creation_3param) {
auto* d = WorkgroupSize(2, 4, 6);
auto values = d->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteral>());
EXPECT_EQ(values[1]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteral>());
EXPECT_EQ(values[2]->As<ast::IntLiteral>()->ValueAsU32(), 6u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[2]->As<ast::IntLiteralExpression>()->ValueAsU32(), 6u);
}
TEST_F(WorkgroupDecorationTest, Creation_WithIdentifier) {
auto* d = WorkgroupSize(2, 4, "depth");
auto values = d->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteral>());
EXPECT_EQ(values[1]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
auto* z_ident = As<ast::IdentifierExpression>(values[2]);
ASSERT_TRUE(z_ident);

View File

@ -251,10 +251,10 @@ class CloneContext {
/// Example:
///
/// ```
/// // Replace all ast::UintLiterals with the number 42
/// // Replace all ast::UintLiteralExpressions with the number 42
/// CloneCtx ctx(&out, in);
/// ctx.ReplaceAll([&] (ast::UintLiteral* l) {
/// return ctx->dst->create<ast::UintLiteral>(
/// ctx.ReplaceAll([&] (ast::UintLiteralExpression* l) {
/// return ctx->dst->create<ast::UintLiteralExpression>(
/// ctx->Clone(l->source),
/// ctx->Clone(l->type),
/// 42);

View File

@ -263,29 +263,29 @@ std::map<uint32_t, Scalar> Inspector::GetConstantIDs() {
continue;
}
auto* literal = var->constructor->As<ast::Literal>();
auto* literal = var->constructor->As<ast::LiteralExpression>();
if (!literal) {
// This is invalid WGSL, but handling gracefully.
result[constant_id] = Scalar();
continue;
}
if (auto* l = literal->As<ast::BoolLiteral>()) {
if (auto* l = literal->As<ast::BoolLiteralExpression>()) {
result[constant_id] = Scalar(l->value);
continue;
}
if (auto* l = literal->As<ast::UintLiteral>()) {
if (auto* l = literal->As<ast::UintLiteralExpression>()) {
result[constant_id] = Scalar(l->value);
continue;
}
if (auto* l = literal->As<ast::SintLiteral>()) {
if (auto* l = literal->As<ast::SintLiteralExpression>()) {
result[constant_id] = Scalar(l->value);
continue;
}
if (auto* l = literal->As<ast::FloatLiteral>()) {
if (auto* l = literal->As<ast::FloatLiteralExpression>()) {
result[constant_id] = Scalar(l->value);
continue;
}

View File

@ -1037,53 +1037,53 @@ class ProgramBuilder {
/// @param source the source information
/// @param value the boolean value
/// @return a Scalar constructor for the given value
const ast::Literal* Expr(const Source& source, bool value) {
return create<ast::BoolLiteral>(source, value);
const ast::LiteralExpression* Expr(const Source& source, bool value) {
return create<ast::BoolLiteralExpression>(source, value);
}
/// @param value the boolean value
/// @return a Scalar constructor for the given value
const ast::BoolLiteral* Expr(bool value) {
return create<ast::BoolLiteral>(value);
const ast::BoolLiteralExpression* Expr(bool value) {
return create<ast::BoolLiteralExpression>(value);
}
/// @param source the source information
/// @param value the float value
/// @return a Scalar constructor for the given value
const ast::FloatLiteral* Expr(const Source& source, f32 value) {
return create<ast::FloatLiteral>(source, value);
const ast::FloatLiteralExpression* Expr(const Source& source, f32 value) {
return create<ast::FloatLiteralExpression>(source, value);
}
/// @param value the float value
/// @return a Scalar constructor for the given value
const ast::FloatLiteral* Expr(f32 value) {
return create<ast::FloatLiteral>(value);
const ast::FloatLiteralExpression* Expr(f32 value) {
return create<ast::FloatLiteralExpression>(value);
}
/// @param source the source information
/// @param value the integer value
/// @return a Scalar constructor for the given value
const ast::Literal* Expr(const Source& source, i32 value) {
return create<ast::SintLiteral>(source, value);
const ast::LiteralExpression* Expr(const Source& source, i32 value) {
return create<ast::SintLiteralExpression>(source, value);
}
/// @param value the integer value
/// @return a Scalar constructor for the given value
const ast::SintLiteral* Expr(i32 value) {
return create<ast::SintLiteral>(value);
const ast::SintLiteralExpression* Expr(i32 value) {
return create<ast::SintLiteralExpression>(value);
}
/// @param source the source information
/// @param value the unsigned int value
/// @return a Scalar constructor for the given value
const ast::UintLiteral* Expr(const Source& source, u32 value) {
return create<ast::UintLiteral>(source, value);
const ast::UintLiteralExpression* Expr(const Source& source, u32 value) {
return create<ast::UintLiteralExpression>(source, value);
}
/// @param value the unsigned int value
/// @return a Scalar constructor for the given value
const ast::UintLiteral* Expr(u32 value) {
return create<ast::UintLiteral>(value);
const ast::UintLiteralExpression* Expr(u32 value) {
return create<ast::UintLiteralExpression>(value);
}
/// Converts `arg` to an `ast::Expression` using `Expr()`, then appends it to
@ -1127,53 +1127,53 @@ class ProgramBuilder {
/// @param source the source location for the literal
/// @param val the boolan value
/// @return a boolean literal with the given value
const ast::BoolLiteral* Literal(const Source& source, bool val) {
return create<ast::BoolLiteral>(source, val);
const ast::BoolLiteralExpression* Literal(const Source& source, bool val) {
return create<ast::BoolLiteralExpression>(source, val);
}
/// @param val the boolan value
/// @return a boolean literal with the given value
const ast::BoolLiteral* Literal(bool val) {
return create<ast::BoolLiteral>(val);
const ast::BoolLiteralExpression* Literal(bool val) {
return create<ast::BoolLiteralExpression>(val);
}
/// @param source the source location for the literal
/// @param val the float value
/// @return a float literal with the given value
const ast::FloatLiteral* Literal(const Source& source, f32 val) {
return create<ast::FloatLiteral>(source, val);
const ast::FloatLiteralExpression* Literal(const Source& source, f32 val) {
return create<ast::FloatLiteralExpression>(source, val);
}
/// @param val the float value
/// @return a float literal with the given value
const ast::FloatLiteral* Literal(f32 val) {
return create<ast::FloatLiteral>(val);
const ast::FloatLiteralExpression* Literal(f32 val) {
return create<ast::FloatLiteralExpression>(val);
}
/// @param source the source location for the literal
/// @param val the unsigned int value
/// @return a ast::UintLiteral with the given value
const ast::UintLiteral* Literal(const Source& source, u32 val) {
return create<ast::UintLiteral>(source, val);
const ast::UintLiteralExpression* Literal(const Source& source, u32 val) {
return create<ast::UintLiteralExpression>(source, val);
}
/// @param val the unsigned int value
/// @return a ast::UintLiteral with the given value
const ast::UintLiteral* Literal(u32 val) {
return create<ast::UintLiteral>(val);
const ast::UintLiteralExpression* Literal(u32 val) {
return create<ast::UintLiteralExpression>(val);
}
/// @param source the source location for the literal
/// @param val the integer value
/// @return the ast::SintLiteral with the given value
const ast::SintLiteral* Literal(const Source& source, i32 val) {
return create<ast::SintLiteral>(source, val);
const ast::SintLiteralExpression* Literal(const Source& source, i32 val) {
return create<ast::SintLiteralExpression>(source, val);
}
/// @param val the integer value
/// @return the ast::SintLiteral with the given value
const ast::SintLiteral* Literal(i32 val) {
return create<ast::SintLiteral>(val);
const ast::SintLiteralExpression* Literal(i32 val) {
return create<ast::SintLiteralExpression>(val);
}
/// @param args the arguments for the type constructor
@ -2237,7 +2237,7 @@ class ProgramBuilder {
/// @param selector a single case selector
/// @param body the case body
/// @returns the case statement pointer
const ast::CaseStatement* Case(const ast::IntLiteral* selector,
const ast::CaseStatement* Case(const ast::IntLiteralExpression* selector,
const ast::BlockStatement* body = nullptr) {
return Case(ast::CaseSelectorList{selector}, body);
}

View File

@ -2548,7 +2548,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
return source_expr;
}
case SkipReason::kPointSizeBuiltinValue: {
return {ty_.F32(), create<ast::FloatLiteral>(Source{}, 1.0f)};
return {ty_.F32(), create<ast::FloatLiteralExpression>(Source{}, 1.0f)};
}
case SkipReason::kPointSizeBuiltinPointer:
Fail() << "unhandled use of a pointer to the PointSize builtin, with ID: "
@ -3063,9 +3063,11 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
// The Tint AST handles 32-bit values.
const uint32_t value32 = uint32_t(value & 0xFFFFFFFF);
if (selector.type->IsUnsignedScalarOrVector()) {
selectors.emplace_back(create<ast::UintLiteral>(Source{}, value32));
selectors.emplace_back(
create<ast::UintLiteralExpression>(Source{}, value32));
} else {
selectors.emplace_back(create<ast::SintLiteral>(Source{}, value32));
selectors.emplace_back(
create<ast::SintLiteralExpression>(Source{}, value32));
}
}
}
@ -4475,7 +4477,7 @@ TypedExpression FunctionEmitter::MakeCompositeValueDecomposition(
auto current_type_id = composite_type_id;
auto make_index = [this](uint32_t literal) {
return create<ast::UintLiteral>(Source{}, literal);
return create<ast::UintLiteralExpression>(Source{}, literal);
};
// Build up a nested expression for the decomposition by walking down the type
@ -4591,11 +4593,11 @@ TypedExpression FunctionEmitter::MakeCompositeValueDecomposition(
}
const ast::Expression* FunctionEmitter::MakeTrue(const Source& source) const {
return create<ast::BoolLiteral>(source, true);
return create<ast::BoolLiteralExpression>(source, true);
}
const ast::Expression* FunctionEmitter::MakeFalse(const Source& source) const {
return create<ast::BoolLiteral>(source, false);
return create<ast::BoolLiteralExpression>(source, false);
}
TypedExpression FunctionEmitter::MakeVectorShuffle(

View File

@ -1353,13 +1353,13 @@ bool ParserImpl::EmitScalarSpecConstants() {
for (auto& inst : module_->types_values()) {
// These will be populated for a valid scalar spec constant.
const Type* ast_type = nullptr;
ast::Literal* ast_expr = nullptr;
ast::LiteralExpression* ast_expr = nullptr;
switch (inst.opcode()) {
case SpvOpSpecConstantTrue:
case SpvOpSpecConstantFalse: {
ast_type = ConvertType(inst.type_id());
ast_expr = create<ast::BoolLiteral>(
ast_expr = create<ast::BoolLiteralExpression>(
Source{}, inst.opcode() == SpvOpSpecConstantTrue);
break;
}
@ -1367,16 +1367,16 @@ bool ParserImpl::EmitScalarSpecConstants() {
ast_type = ConvertType(inst.type_id());
const uint32_t literal_value = inst.GetSingleWordInOperand(0);
if (ast_type->Is<I32>()) {
ast_expr = create<ast::SintLiteral>(
ast_expr = create<ast::SintLiteralExpression>(
Source{}, static_cast<int32_t>(literal_value));
} else if (ast_type->Is<U32>()) {
ast_expr = create<ast::UintLiteral>(
ast_expr = create<ast::UintLiteralExpression>(
Source{}, static_cast<uint32_t>(literal_value));
} else if (ast_type->Is<F32>()) {
float float_value;
// Copy the bits so we can read them as a float.
std::memcpy(&float_value, &literal_value, sizeof(float_value));
ast_expr = create<ast::FloatLiteral>(Source{}, float_value);
ast_expr = create<ast::FloatLiteralExpression>(Source{}, float_value);
} else {
return Fail() << " invalid result type for OpSpecConstant "
<< inst.PrettyPrint();
@ -1955,20 +1955,22 @@ TypedExpression ParserImpl::MakeConstantExpressionForScalarSpirvConstant(
// Currently "null<type>" is missing from the WGSL parser.
// See https://bugs.chromium.org/p/tint/issues/detail?id=34
if (ast_type->Is<U32>()) {
return {ty_.U32(), create<ast::UintLiteral>(source, spirv_const->GetU32())};
return {ty_.U32(),
create<ast::UintLiteralExpression>(source, spirv_const->GetU32())};
}
if (ast_type->Is<I32>()) {
return {ty_.I32(), create<ast::SintLiteral>(source, spirv_const->GetS32())};
return {ty_.I32(),
create<ast::SintLiteralExpression>(source, spirv_const->GetS32())};
}
if (ast_type->Is<F32>()) {
return {ty_.F32(),
create<ast::FloatLiteral>(source, spirv_const->GetFloat())};
return {ty_.F32(), create<ast::FloatLiteralExpression>(
source, spirv_const->GetFloat())};
}
if (ast_type->Is<Bool>()) {
const bool value = spirv_const->AsNullConstant()
? false
: spirv_const->AsBoolConstant()->value();
return {ty_.Bool(), create<ast::BoolLiteral>(source, value)};
return {ty_.Bool(), create<ast::BoolLiteralExpression>(source, value)};
}
Fail() << "expected scalar constant";
return {};
@ -1989,16 +1991,16 @@ const ast::Expression* ParserImpl::MakeNullValue(const Type* type) {
type = type->UnwrapAlias();
if (type->Is<Bool>()) {
return create<ast::BoolLiteral>(Source{}, false);
return create<ast::BoolLiteralExpression>(Source{}, false);
}
if (type->Is<U32>()) {
return create<ast::UintLiteral>(Source{}, 0u);
return create<ast::UintLiteralExpression>(Source{}, 0u);
}
if (type->Is<I32>()) {
return create<ast::SintLiteral>(Source{}, 0);
return create<ast::SintLiteralExpression>(Source{}, 0);
}
if (type->Is<F32>()) {
return create<ast::FloatLiteral>(Source{}, 0.0f);
return create<ast::FloatLiteralExpression>(Source{}, 0.0f);
}
if (type->Is<Alias>()) {
// TODO(amaiorano): No type constructor for TypeName (yet?)

View File

@ -1947,12 +1947,12 @@ Expect<ast::CaseSelectorList> ParserImpl::expect_case_selectors() {
return Failure::kErrored;
} else if (!cond.matched) {
break;
} else if (!cond->Is<ast::IntLiteral>()) {
} else if (!cond->Is<ast::IntLiteralExpression>()) {
return add_error(cond.value->source,
"invalid case selector must be an integer value");
}
selectors.push_back(cond.value->As<ast::IntLiteral>());
selectors.push_back(cond.value->As<ast::IntLiteralExpression>());
if (!match(Token::Type::kComma)) {
break;
@ -2841,22 +2841,22 @@ Maybe<const ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
// | FLOAT_LITERAL
// | TRUE
// | FALSE
Maybe<const ast::Literal*> ParserImpl::const_literal() {
Maybe<const ast::LiteralExpression*> ParserImpl::const_literal() {
auto t = peek();
if (t.IsError()) {
return add_error(t.source(), t.to_str());
}
if (match(Token::Type::kTrue)) {
return create<ast::BoolLiteral>(t.source(), true);
return create<ast::BoolLiteralExpression>(t.source(), true);
}
if (match(Token::Type::kFalse)) {
return create<ast::BoolLiteral>(t.source(), false);
return create<ast::BoolLiteralExpression>(t.source(), false);
}
if (match(Token::Type::kSintLiteral)) {
return create<ast::SintLiteral>(t.source(), t.to_i32());
return create<ast::SintLiteralExpression>(t.source(), t.to_i32());
}
if (match(Token::Type::kUintLiteral)) {
return create<ast::UintLiteral>(t.source(), t.to_u32());
return create<ast::UintLiteralExpression>(t.source(), t.to_u32());
}
if (match(Token::Type::kFloatLiteral)) {
auto p = peek();
@ -2865,7 +2865,7 @@ Maybe<const ast::Literal*> ParserImpl::const_literal() {
return add_error(p.source(),
"float literals must not be suffixed with 'f'");
}
return create<ast::FloatLiteral>(t.source(), t.to_f32());
return create<ast::FloatLiteralExpression>(t.source(), t.to_f32());
}
return Failure::kNoMatch;
}

View File

@ -568,7 +568,7 @@ class ParserImpl {
Maybe<const ast::BlockStatement*> continuing_stmt();
/// Parses a `const_literal` grammar element
/// @returns the const literal parsed or nullptr if none found
Maybe<const ast::Literal*> const_literal();
Maybe<const ast::LiteralExpression*> const_literal();
/// Parses a `const_expr` grammar element, erroring on parse failure.
/// @returns the parsed constructor expression or nullptr on error
Expect<const ast::Expression*> expect_const_expr();

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) {
@ -55,8 +55,8 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, AdditiveExpression_InvalidLHS) {

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, AndExpression_Parses) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, AndExpression_InvalidLHS) {

View File

@ -46,7 +46,7 @@ TEST_F(ParserImplTest, ArgumentExpressionList_ParsesMultiple) {
ASSERT_EQ(e.value.size(), 3u);
ASSERT_TRUE(e.value[0]->Is<ast::IdentifierExpression>());
ASSERT_TRUE(e.value[1]->Is<ast::Literal>());
ASSERT_TRUE(e.value[1]->Is<ast::LiteralExpression>());
ASSERT_TRUE(e.value[2]->Is<ast::BinaryExpression>());
}
@ -58,7 +58,7 @@ TEST_F(ParserImplTest, ArgumentExpressionList_TrailingComma) {
ASSERT_EQ(e.value.size(), 2u);
ASSERT_TRUE(e.value[0]->Is<ast::IdentifierExpression>());
ASSERT_TRUE(e.value[1]->Is<ast::Literal>());
ASSERT_TRUE(e.value[1]->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, ArgumentExpressionList_HandlesMissingLeftParen) {

View File

@ -36,8 +36,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(e->rhs, nullptr);
ASSERT_TRUE(e->rhs->Is<ast::SintLiteral>());
EXPECT_EQ(e->rhs->As<ast::SintLiteral>()->value, 123);
ASSERT_TRUE(e->rhs->Is<ast::SintLiteralExpression>());
EXPECT_EQ(e->rhs->As<ast::SintLiteralExpression>()->value, 123);
}
TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
@ -53,8 +53,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
ASSERT_NE(e->rhs, nullptr);
ASSERT_NE(e->rhs, nullptr);
ASSERT_TRUE(e->rhs->Is<ast::SintLiteral>());
EXPECT_EQ(e->rhs->As<ast::SintLiteral>()->value, 123);
ASSERT_TRUE(e->rhs->Is<ast::SintLiteralExpression>());
EXPECT_EQ(e->rhs->As<ast::SintLiteralExpression>()->value, 123);
ASSERT_TRUE(e->lhs->Is<ast::MemberAccessorExpression>());
auto* mem = e->lhs->As<ast::MemberAccessorExpression>();
@ -67,8 +67,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
auto* idx = mem->structure->As<ast::IndexAccessorExpression>();
ASSERT_NE(idx->index, nullptr);
ASSERT_TRUE(idx->index->Is<ast::SintLiteral>());
EXPECT_EQ(idx->index->As<ast::SintLiteral>()->value, 2);
ASSERT_TRUE(idx->index->Is<ast::SintLiteralExpression>());
EXPECT_EQ(idx->index->As<ast::SintLiteralExpression>()->value, 2);
ASSERT_TRUE(idx->object->Is<ast::MemberAccessorExpression>());
mem = idx->object->As<ast::MemberAccessorExpression>();
@ -101,8 +101,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToPhony) {
ASSERT_NE(e->rhs, nullptr);
ASSERT_NE(e->rhs, nullptr);
ASSERT_TRUE(e->rhs->Is<ast::SintLiteral>());
EXPECT_EQ(e->rhs->As<ast::SintLiteral>()->value, 123);
ASSERT_TRUE(e->rhs->Is<ast::SintLiteralExpression>());
EXPECT_EQ(e->rhs->As<ast::SintLiteralExpression>()->value, 123);
ASSERT_TRUE(e->lhs->Is<ast::PhonyExpression>());
}

View File

@ -55,7 +55,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) {
EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("a"));
EXPECT_EQ(c->args.size(), 3u);
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteral>());
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>());
EXPECT_TRUE(c->args[1]->Is<ast::IdentifierExpression>());
EXPECT_TRUE(c->args[2]->Is<ast::BinaryExpression>());
}
@ -74,7 +74,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams_TrailingComma) {
EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("a"));
EXPECT_EQ(c->args.size(), 2u);
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteral>());
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>());
EXPECT_TRUE(c->args[1]->Is<ast::IdentifierExpression>());
}

View File

@ -33,11 +33,11 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) {
ASSERT_EQ(t->values.size(), 2u);
auto& v = t->values;
ASSERT_TRUE(v[0]->Is<ast::FloatLiteral>());
EXPECT_FLOAT_EQ(v[0]->As<ast::FloatLiteral>()->value, 1.);
ASSERT_TRUE(v[0]->Is<ast::FloatLiteralExpression>());
EXPECT_FLOAT_EQ(v[0]->As<ast::FloatLiteralExpression>()->value, 1.);
ASSERT_TRUE(v[1]->Is<ast::FloatLiteral>());
EXPECT_FLOAT_EQ(v[1]->As<ast::FloatLiteral>()->value, 2.);
ASSERT_TRUE(v[1]->Is<ast::FloatLiteralExpression>());
EXPECT_FLOAT_EQ(v[1]->As<ast::FloatLiteralExpression>()->value, 2.);
}
TEST_F(ParserImplTest, ConstExpr_TypeDecl_Empty) {
@ -66,8 +66,8 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl_TrailingComma) {
EXPECT_EQ(t->type->As<ast::Vector>()->width, 2u);
ASSERT_EQ(t->values.size(), 2u);
ASSERT_TRUE(t->values[0]->Is<ast::Literal>());
ASSERT_TRUE(t->values[1]->Is<ast::Literal>());
ASSERT_TRUE(t->values[0]->Is<ast::LiteralExpression>());
ASSERT_TRUE(t->values[1]->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, ConstExpr_TypeDecl_MissingRightParen) {
@ -112,8 +112,8 @@ TEST_F(ParserImplTest, ConstExpr_ConstLiteral) {
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_FALSE(e.errored);
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e.value->Is<ast::BoolLiteral>());
EXPECT_TRUE(e.value->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(e.value->Is<ast::BoolLiteralExpression>());
EXPECT_TRUE(e.value->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, ConstExpr_ConstLiteral_Invalid) {

View File

@ -48,8 +48,8 @@ TEST_F(ParserImplTest, ConstLiteral_Int) {
EXPECT_FALSE(c.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(c.value, nullptr);
ASSERT_TRUE(c->Is<ast::SintLiteral>());
EXPECT_EQ(c->As<ast::SintLiteral>()->value, -234);
ASSERT_TRUE(c->Is<ast::SintLiteralExpression>());
EXPECT_EQ(c->As<ast::SintLiteralExpression>()->value, -234);
EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}}));
}
@ -60,8 +60,8 @@ TEST_F(ParserImplTest, ConstLiteral_Uint) {
EXPECT_FALSE(c.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(c.value, nullptr);
ASSERT_TRUE(c->Is<ast::UintLiteral>());
EXPECT_EQ(c->As<ast::UintLiteral>()->value, 234u);
ASSERT_TRUE(c->Is<ast::UintLiteralExpression>());
EXPECT_EQ(c->As<ast::UintLiteralExpression>()->value, 234u);
EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}}));
}
@ -72,8 +72,8 @@ TEST_F(ParserImplTest, ConstLiteral_Float) {
EXPECT_FALSE(c.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(c.value, nullptr);
ASSERT_TRUE(c->Is<ast::FloatLiteral>());
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteral>()->value, 234e12f);
ASSERT_TRUE(c->Is<ast::FloatLiteralExpression>());
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteralExpression>()->value, 234e12f);
EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 8u}}));
}
@ -136,8 +136,8 @@ TEST_P(ParserImplFloatLiteralTest, Parse) {
EXPECT_FALSE(c.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(c.value, nullptr);
ASSERT_TRUE(c->Is<ast::FloatLiteral>());
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteral>()->value, params.expected);
ASSERT_TRUE(c->Is<ast::FloatLiteralExpression>());
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteralExpression>()->value, params.expected);
}
FloatLiteralTestCase float_literal_test_cases[] = {
@ -394,8 +394,8 @@ TEST_F(ParserImplTest, ConstLiteral_FloatHighest) {
EXPECT_FALSE(c.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(c.value, nullptr);
ASSERT_TRUE(c->Is<ast::FloatLiteral>());
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteral>()->value,
ASSERT_TRUE(c->Is<ast::FloatLiteralExpression>());
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteralExpression>()->value,
std::numeric_limits<float>::max());
EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 42u}}));
}
@ -417,8 +417,8 @@ TEST_F(ParserImplTest, ConstLiteral_FloatLowest) {
EXPECT_FALSE(c.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(c.value, nullptr);
ASSERT_TRUE(c->Is<ast::FloatLiteral>());
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteral>()->value,
ASSERT_TRUE(c->Is<ast::FloatLiteralExpression>());
EXPECT_FLOAT_EQ(c->As<ast::FloatLiteralExpression>()->value,
std::numeric_limits<float>::lowest());
EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 43u}}));
}
@ -430,8 +430,8 @@ TEST_F(ParserImplTest, ConstLiteral_True) {
EXPECT_FALSE(c.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(c.value, nullptr);
ASSERT_TRUE(c->Is<ast::BoolLiteral>());
EXPECT_TRUE(c->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(c->Is<ast::BoolLiteralExpression>());
EXPECT_TRUE(c->As<ast::BoolLiteralExpression>()->value);
EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}}));
}
@ -442,8 +442,8 @@ TEST_F(ParserImplTest, ConstLiteral_False) {
EXPECT_FALSE(c.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(c.value, nullptr);
ASSERT_TRUE(c->Is<ast::BoolLiteral>());
EXPECT_FALSE(c->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(c->Is<ast::BoolLiteralExpression>());
EXPECT_FALSE(c->As<ast::BoolLiteralExpression>()->value);
EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 6u}}));
}

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) {
@ -55,8 +55,8 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, EqualityExpression_InvalidLHS) {

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, ExclusiveOrExpression_InvalidLHS) {

View File

@ -71,14 +71,14 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
auto values = decorations[0]->As<ast::WorkgroupDecoration>()->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteral>());
EXPECT_EQ(values[1]->As<ast::IntLiteral>()->ValueAsU32(), 3u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->ValueAsU32(), 3u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteral>());
EXPECT_EQ(values[2]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[2]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
auto* body = f->body;
ASSERT_EQ(body->statements.size(), 1u);
@ -110,14 +110,14 @@ fn main() { return; })");
ASSERT_TRUE(decorations[0]->Is<ast::WorkgroupDecoration>());
auto values = decorations[0]->As<ast::WorkgroupDecoration>()->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteral>());
EXPECT_EQ(values[1]->As<ast::IntLiteral>()->ValueAsU32(), 3u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->ValueAsU32(), 3u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteral>());
EXPECT_EQ(values[2]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[2]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
ASSERT_TRUE(decorations[1]->Is<ast::StageDecoration>());
EXPECT_EQ(decorations[1]->As<ast::StageDecoration>()->stage,
@ -154,14 +154,14 @@ fn main() { return; })");
ASSERT_TRUE(decos[0]->Is<ast::WorkgroupDecoration>());
auto values = decos[0]->As<ast::WorkgroupDecoration>()->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 2u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteral>());
EXPECT_EQ(values[1]->As<ast::IntLiteral>()->ValueAsU32(), 3u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->ValueAsU32(), 3u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteral>());
EXPECT_EQ(values[2]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[2]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
ASSERT_TRUE(decos[1]->Is<ast::StageDecoration>());
EXPECT_EQ(decos[1]->As<ast::StageDecoration>()->stage,

View File

@ -36,10 +36,10 @@ TEST_F(ParserImplTest, DecorationList_Parses) {
ASSERT_TRUE(deco_0->Is<ast::WorkgroupDecoration>());
const ast::Expression* x = deco_0->As<ast::WorkgroupDecoration>()->x;
ASSERT_NE(x, nullptr);
auto* x_literal = x->As<ast::Literal>();
auto* x_literal = x->As<ast::LiteralExpression>();
ASSERT_NE(x_literal, nullptr);
ASSERT_TRUE(x_literal->Is<ast::IntLiteral>());
EXPECT_EQ(x_literal->As<ast::IntLiteral>()->ValueAsU32(), 2u);
ASSERT_TRUE(x_literal->Is<ast::IntLiteralExpression>());
EXPECT_EQ(x_literal->As<ast::IntLiteralExpression>()->ValueAsU32(), 2u);
ASSERT_TRUE(deco_1->Is<ast::StageDecoration>());
EXPECT_EQ(deco_1->As<ast::StageDecoration>()->stage,

View File

@ -34,8 +34,8 @@ TEST_F(ParserImplTest, Decoration_Workgroup) {
auto values = func_deco->As<ast::WorkgroupDecoration>()->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
EXPECT_EQ(values[1], nullptr);
EXPECT_EQ(values[2], nullptr);
@ -54,11 +54,11 @@ TEST_F(ParserImplTest, Decoration_Workgroup_2Param) {
auto values = func_deco->As<ast::WorkgroupDecoration>()->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteral>());
EXPECT_EQ(values[1]->As<ast::IntLiteral>()->ValueAsU32(), 5u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->ValueAsU32(), 5u);
EXPECT_EQ(values[2], nullptr);
}
@ -76,14 +76,14 @@ TEST_F(ParserImplTest, Decoration_Workgroup_3Param) {
auto values = func_deco->As<ast::WorkgroupDecoration>()->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteral>());
EXPECT_EQ(values[1]->As<ast::IntLiteral>()->ValueAsU32(), 5u);
ASSERT_TRUE(values[1]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::IntLiteralExpression>()->ValueAsU32(), 5u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteral>());
EXPECT_EQ(values[2]->As<ast::IntLiteral>()->ValueAsU32(), 6u);
ASSERT_TRUE(values[2]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[2]->As<ast::IntLiteralExpression>()->ValueAsU32(), 6u);
}
TEST_F(ParserImplTest, Decoration_Workgroup_WithIdent) {
@ -99,8 +99,8 @@ TEST_F(ParserImplTest, Decoration_Workgroup_WithIdent) {
auto values = func_deco->As<ast::WorkgroupDecoration>()->Values();
ASSERT_TRUE(values[0]->Is<ast::IntLiteral>());
EXPECT_EQ(values[0]->As<ast::IntLiteral>()->ValueAsU32(), 4u);
ASSERT_TRUE(values[0]->Is<ast::IntLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::IntLiteralExpression>()->ValueAsU32(), 4u);
ASSERT_NE(values[1], nullptr);
auto* y_ident = values[1]->As<ast::IdentifierExpression>();

View File

@ -42,7 +42,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) {
EXPECT_EQ(e->source.range.end.column, 6u);
ASSERT_NE(e->constructor, nullptr);
EXPECT_TRUE(e->constructor->Is<ast::Literal>());
EXPECT_TRUE(e->constructor->Is<ast::LiteralExpression>());
EXPECT_FALSE(
ast::HasDecoration<ast::OverrideDecoration>(e.value->decorations));
@ -69,7 +69,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl_Inferred) {
EXPECT_EQ(e->source.range.end.column, 6u);
ASSERT_NE(e->constructor, nullptr);
EXPECT_TRUE(e->constructor->Is<ast::Literal>());
EXPECT_TRUE(e->constructor->Is<ast::LiteralExpression>());
EXPECT_FALSE(
ast::HasDecoration<ast::OverrideDecoration>(e.value->decorations));
@ -137,7 +137,7 @@ TEST_F(ParserImplTest, GlobalConstantDec_Override_WithId) {
EXPECT_EQ(e->source.range.end.column, 22u);
ASSERT_NE(e->constructor, nullptr);
EXPECT_TRUE(e->constructor->Is<ast::Literal>());
EXPECT_TRUE(e->constructor->Is<ast::LiteralExpression>());
auto* override_deco =
ast::GetDecoration<ast::OverrideDecoration>(e.value->decorations);
@ -169,7 +169,7 @@ TEST_F(ParserImplTest, GlobalConstantDec_Override_WithoutId) {
EXPECT_EQ(e->source.range.end.column, 19u);
ASSERT_NE(e->constructor, nullptr);
EXPECT_TRUE(e->constructor->Is<ast::Literal>());
EXPECT_TRUE(e->constructor->Is<ast::LiteralExpression>());
auto* override_deco =
ast::GetDecoration<ast::OverrideDecoration>(e.value->decorations);

View File

@ -63,7 +63,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
EXPECT_EQ(e->source.range.end.column, 15u);
ASSERT_NE(e->constructor, nullptr);
ASSERT_TRUE(e->constructor->Is<ast::FloatLiteral>());
ASSERT_TRUE(e->constructor->Is<ast::FloatLiteralExpression>());
}
TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) {

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, InclusiveOrExpression_InvalidLHS) {

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, LogicalAndExpression_InvalidLHS) {

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, LogicalOrExpression_InvalidLHS) {

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) {
@ -55,8 +55,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) {
@ -75,8 +75,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, MultiplicativeExpression_InvalidLHS) {

View File

@ -44,17 +44,17 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {
ASSERT_EQ(ty->values.size(), 4u);
const auto& val = ty->values;
ASSERT_TRUE(val[0]->Is<ast::SintLiteral>());
EXPECT_EQ(val[0]->As<ast::SintLiteral>()->value, 1);
ASSERT_TRUE(val[0]->Is<ast::SintLiteralExpression>());
EXPECT_EQ(val[0]->As<ast::SintLiteralExpression>()->value, 1);
ASSERT_TRUE(val[1]->Is<ast::SintLiteral>());
EXPECT_EQ(val[1]->As<ast::SintLiteral>()->value, 2);
ASSERT_TRUE(val[1]->Is<ast::SintLiteralExpression>());
EXPECT_EQ(val[1]->As<ast::SintLiteralExpression>()->value, 2);
ASSERT_TRUE(val[2]->Is<ast::SintLiteral>());
EXPECT_EQ(val[2]->As<ast::SintLiteral>()->value, 3);
ASSERT_TRUE(val[2]->Is<ast::SintLiteralExpression>());
EXPECT_EQ(val[2]->As<ast::SintLiteralExpression>()->value, 3);
ASSERT_TRUE(val[3]->Is<ast::SintLiteral>());
EXPECT_EQ(val[3]->As<ast::SintLiteral>()->value, 4);
ASSERT_TRUE(val[3]->Is<ast::SintLiteralExpression>());
EXPECT_EQ(val[3]->As<ast::SintLiteralExpression>()->value, 4);
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_ZeroConstructor) {
@ -159,11 +159,11 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructConstructor_NotEmpty) {
auto values = constructor->values;
ASSERT_EQ(values.size(), 2u);
ASSERT_TRUE(values[0]->Is<ast::UintLiteral>());
EXPECT_EQ(values[0]->As<ast::UintLiteral>()->value, 1u);
ASSERT_TRUE(values[0]->Is<ast::UintLiteralExpression>());
EXPECT_EQ(values[0]->As<ast::UintLiteralExpression>()->value, 1u);
ASSERT_TRUE(values[1]->Is<ast::FloatLiteral>());
EXPECT_EQ(values[1]->As<ast::FloatLiteral>()->value, 2.f);
ASSERT_TRUE(values[1]->Is<ast::FloatLiteralExpression>());
EXPECT_EQ(values[1]->As<ast::FloatLiteralExpression>()->value, 2.f);
}
TEST_F(ParserImplTest, PrimaryExpression_ConstLiteral_True) {
@ -173,8 +173,8 @@ TEST_F(ParserImplTest, PrimaryExpression_ConstLiteral_True) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->Is<ast::BoolLiteral>());
EXPECT_TRUE(e->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(e->Is<ast::BoolLiteralExpression>());
EXPECT_TRUE(e->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, PrimaryExpression_ParenExpr) {
@ -231,7 +231,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
ASSERT_TRUE(c->type->Is<ast::F32>());
ASSERT_EQ(c->values.size(), 1u);
ASSERT_TRUE(c->values[0]->Is<ast::IntLiteral>());
ASSERT_TRUE(c->values[0]->Is<ast::IntLiteralExpression>());
}
TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
@ -246,7 +246,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
auto* c = e->As<ast::BitcastExpression>();
ASSERT_TRUE(c->type->Is<ast::F32>());
ASSERT_TRUE(c->expr->Is<ast::IntLiteral>());
ASSERT_TRUE(c->expr->Is<ast::IntLiteralExpression>());
}
TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingGreaterThan) {

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) {
@ -55,8 +55,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) {
@ -75,8 +75,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) {
@ -95,8 +95,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, RelationalExpression_InvalidLHS) {

View File

@ -35,8 +35,8 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
@ -55,8 +55,8 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
auto* ident = rel->lhs->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteral>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteral>()->value);
ASSERT_TRUE(rel->rhs->Is<ast::BoolLiteralExpression>());
ASSERT_TRUE(rel->rhs->As<ast::BoolLiteralExpression>()->value);
}
TEST_F(ParserImplTest, ShiftExpression_InvalidSpaceLeft) {

View File

@ -34,8 +34,8 @@ TEST_F(ParserImplTest, SingularExpression_Array_ConstantIndex) {
auto* ident = idx->object->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(idx->index->Is<ast::SintLiteral>());
EXPECT_EQ(idx->index->As<ast::SintLiteral>()->value, 1);
ASSERT_TRUE(idx->index->Is<ast::SintLiteralExpression>());
EXPECT_EQ(idx->index->As<ast::SintLiteralExpression>()->value, 1);
}
TEST_F(ParserImplTest, SingularExpression_Array_ExpressionIndex) {
@ -116,7 +116,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_WithArgs) {
EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("test"));
EXPECT_EQ(c->args.size(), 3u);
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteral>());
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>());
EXPECT_TRUE(c->args[1]->Is<ast::IdentifierExpression>());
EXPECT_TRUE(c->args[2]->Is<ast::BinaryExpression>());
}

View File

@ -455,7 +455,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) {
EXPECT_EQ(a->decorations.size(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}}));
auto* size = a->count->As<ast::SintLiteral>();
auto* size = a->count->As<ast::SintLiteralExpression>();
ASSERT_NE(size, nullptr);
EXPECT_EQ(size->ValueAsI32(), 5);
}
@ -475,7 +475,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) {
EXPECT_EQ(a->decorations.size(), 0u);
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}}));
auto* size = a->count->As<ast::UintLiteral>();
auto* size = a->count->As<ast::UintLiteralExpression>();
ASSERT_NE(size, nullptr);
EXPECT_EQ(size->ValueAsU32(), 5u);
}
@ -513,7 +513,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_Stride) {
ASSERT_FALSE(a->IsRuntimeArray());
ASSERT_TRUE(a->type->Is<ast::F32>());
auto* size = a->count->As<ast::SintLiteral>();
auto* size = a->count->As<ast::SintLiteralExpression>();
ASSERT_NE(size, nullptr);
EXPECT_EQ(size->ValueAsI32(), 5);

View File

@ -34,8 +34,8 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) {
auto* ident = idx->object->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a"));
ASSERT_TRUE(idx->index->Is<ast::SintLiteral>());
ASSERT_EQ(idx->index->As<ast::SintLiteral>()->value, 2);
ASSERT_TRUE(idx->index->Is<ast::SintLiteralExpression>());
ASSERT_EQ(idx->index->As<ast::SintLiteralExpression>()->value, 2);
}
TEST_F(ParserImplTest, UnaryExpression_Minus) {
@ -50,8 +50,8 @@ TEST_F(ParserImplTest, UnaryExpression_Minus) {
auto* u = e->As<ast::UnaryOpExpression>();
ASSERT_EQ(u->op, ast::UnaryOp::kNegation);
ASSERT_TRUE(u->expr->Is<ast::SintLiteral>());
EXPECT_EQ(u->expr->As<ast::SintLiteral>()->value, 1);
ASSERT_TRUE(u->expr->Is<ast::SintLiteralExpression>());
EXPECT_EQ(u->expr->As<ast::SintLiteralExpression>()->value, 1);
}
TEST_F(ParserImplTest, UnaryExpression_AddressOf) {
@ -132,8 +132,8 @@ TEST_F(ParserImplTest, UnaryExpression_Bang) {
auto* u = e->As<ast::UnaryOpExpression>();
ASSERT_EQ(u->op, ast::UnaryOp::kNot);
ASSERT_TRUE(u->expr->Is<ast::SintLiteral>());
EXPECT_EQ(u->expr->As<ast::SintLiteral>()->value, 1);
ASSERT_TRUE(u->expr->Is<ast::SintLiteralExpression>());
EXPECT_EQ(u->expr->As<ast::SintLiteralExpression>()->value, 1);
}
TEST_F(ParserImplTest, UnaryExpression_Bang_InvalidRHS) {
@ -158,8 +158,8 @@ TEST_F(ParserImplTest, UnaryExpression_Tilde) {
auto* u = e->As<ast::UnaryOpExpression>();
ASSERT_EQ(u->op, ast::UnaryOp::kComplement);
ASSERT_TRUE(u->expr->Is<ast::SintLiteral>());
EXPECT_EQ(u->expr->As<ast::SintLiteral>()->value, 1);
ASSERT_TRUE(u->expr->Is<ast::SintLiteralExpression>());
EXPECT_EQ(u->expr->As<ast::SintLiteralExpression>()->value, 1);
}
TEST_F(ParserImplTest, UnaryExpression_PrefixPlusPlus) {

View File

@ -55,7 +55,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
ASSERT_EQ(e->source.range.end.column, 6u);
ASSERT_NE(e->variable->constructor, nullptr);
EXPECT_TRUE(e->variable->constructor->Is<ast::Literal>());
EXPECT_TRUE(e->variable->constructor->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) {

View File

@ -2015,7 +2015,7 @@ bool Resolver::WorkgroupSizeFor(const ast::Function* func,
ws[i].value = 0;
continue;
}
} else if (!expr->Is<ast::Literal>()) {
} else if (!expr->Is<ast::LiteralExpression>()) {
AddError(
"workgroup_size argument must be either a literal or a "
"module-scope constant",
@ -2367,7 +2367,7 @@ sem::Expression* Resolver::Expression(const ast::Expression* root) {
sem_expr = TypeConstructor(ctor);
} else if (auto* ident = expr->As<ast::IdentifierExpression>()) {
sem_expr = Identifier(ident);
} else if (auto* literal = expr->As<ast::Literal>()) {
} else if (auto* literal = expr->As<ast::LiteralExpression>()) {
sem_expr = Literal(literal);
} else if (auto* member = expr->As<ast::MemberAccessorExpression>()) {
sem_expr = MemberAccessor(member);
@ -2424,7 +2424,7 @@ sem::Expression* Resolver::IndexAccessor(
if (!parent_raw_ty->Is<sem::Reference>()) {
// TODO(bclayton): expand this to allow any const_expr expression
// https://github.com/gpuweb/gpuweb/issues/1272
if (!idx->As<ast::IntLiteral>()) {
if (!idx->As<ast::IntLiteralExpression>()) {
AddError("index must be signed or unsigned integer literal",
idx->source);
return nullptr;
@ -2617,7 +2617,8 @@ bool Resolver::ValidateTextureIntrinsicFunction(const sem::Call* call) {
bool is_const_expr = true;
ast::TraverseExpressions(
arg->Declaration(), diagnostics_, [&](const ast::Expression* e) {
if (e->IsAnyOf<ast::Literal, ast::TypeConstructorExpression>()) {
if (e->IsAnyOf<ast::LiteralExpression,
ast::TypeConstructorExpression>()) {
return ast::TraverseAction::Descend;
}
is_const_expr = false;
@ -2764,7 +2765,7 @@ sem::Expression* Resolver::TypeConstructor(
return builder_->create<sem::Expression>(expr, ty, current_statement_, val);
}
sem::Expression* Resolver::Literal(const ast::Literal* literal) {
sem::Expression* Resolver::Literal(const ast::LiteralExpression* literal) {
auto* ty = TypeOf(literal);
if (!ty) {
return nullptr;
@ -3574,17 +3575,17 @@ std::string Resolver::RawTypeNameOf(const sem::Type* ty) {
return ty->FriendlyName(builder_->Symbols());
}
sem::Type* Resolver::TypeOf(const ast::Literal* lit) {
if (lit->Is<ast::SintLiteral>()) {
sem::Type* Resolver::TypeOf(const ast::LiteralExpression* lit) {
if (lit->Is<ast::SintLiteralExpression>()) {
return builder_->create<sem::I32>();
}
if (lit->Is<ast::UintLiteral>()) {
if (lit->Is<ast::UintLiteralExpression>()) {
return builder_->create<sem::U32>();
}
if (lit->Is<ast::FloatLiteral>()) {
if (lit->Is<ast::FloatLiteralExpression>()) {
return builder_->create<sem::F32>();
}
if (lit->Is<ast::BoolLiteral>()) {
if (lit->Is<ast::BoolLiteralExpression>()) {
return builder_->create<sem::Bool>();
}
TINT_UNREACHABLE(Resolver, diagnostics_)
@ -3780,7 +3781,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) {
}
count_expr = var->Declaration()->constructor;
} else if (!count_expr->Is<ast::Literal>()) {
} else if (!count_expr->Is<ast::LiteralExpression>()) {
AddError(
"array size expression must be either a literal or a module-scope "
"constant",
@ -4259,7 +4260,7 @@ bool Resolver::ValidateSwitch(const ast::SwitchStatement* s) {
auto v = selector->ValueAsU32();
auto it = selectors.find(v);
if (it != selectors.end()) {
auto val = selector->Is<ast::IntLiteral>()
auto val = selector->Is<ast::IntLiteralExpression>()
? std::to_string(selector->ValueAsI32())
: std::to_string(selector->ValueAsU32());
AddError("duplicate switch case '" + val + "'", selector->source);

View File

@ -176,7 +176,7 @@ class Resolver {
sem::Call* FunctionCall(const ast::CallExpression*);
sem::Expression* Identifier(const ast::IdentifierExpression*);
sem::Call* IntrinsicCall(const ast::CallExpression*, sem::IntrinsicType);
sem::Expression* Literal(const ast::Literal*);
sem::Expression* Literal(const ast::LiteralExpression*);
sem::Expression* MemberAccessor(const ast::MemberAccessorExpression*);
sem::Expression* TypeConstructor(const ast::TypeConstructorExpression*);
sem::Expression* UnaryOp(const ast::UnaryOpExpression*);
@ -329,7 +329,7 @@ class Resolver {
/// @returns the semantic type of the AST literal `lit`
/// @param lit the literal
sem::Type* TypeOf(const ast::Literal* lit);
sem::Type* TypeOf(const ast::LiteralExpression* lit);
/// Assigns `stmt` to #current_statement_, #current_compound_statement_, and
/// possibly #current_block_, pushes the variable scope, then calls
@ -376,7 +376,7 @@ class Resolver {
sem::Constant EvaluateConstantValue(const ast::Expression* expr,
const sem::Type* type);
sem::Constant EvaluateConstantValue(const ast::Literal* literal,
sem::Constant EvaluateConstantValue(const ast::LiteralExpression* literal,
const sem::Type* type);
sem::Constant EvaluateConstantValue(
const ast::TypeConstructorExpression* type_ctor,

View File

@ -29,7 +29,7 @@ using f32 = ProgramBuilder::f32;
sem::Constant Resolver::EvaluateConstantValue(const ast::Expression* expr,
const sem::Type* type) {
if (auto* e = expr->As<ast::Literal>()) {
if (auto* e = expr->As<ast::LiteralExpression>()) {
return EvaluateConstantValue(e, type);
}
if (auto* e = expr->As<ast::TypeConstructorExpression>()) {
@ -38,18 +38,19 @@ sem::Constant Resolver::EvaluateConstantValue(const ast::Expression* expr,
return {};
}
sem::Constant Resolver::EvaluateConstantValue(const ast::Literal* literal,
sem::Constant Resolver::EvaluateConstantValue(
const ast::LiteralExpression* literal,
const sem::Type* type) {
if (auto* lit = literal->As<ast::SintLiteral>()) {
if (auto* lit = literal->As<ast::SintLiteralExpression>()) {
return {type, {lit->ValueAsI32()}};
}
if (auto* lit = literal->As<ast::UintLiteral>()) {
if (auto* lit = literal->As<ast::UintLiteralExpression>()) {
return {type, {lit->ValueAsU32()}};
}
if (auto* lit = literal->As<ast::FloatLiteral>()) {
if (auto* lit = literal->As<ast::FloatLiteralExpression>()) {
return {type, {lit->value}};
}
if (auto* lit = literal->As<ast::BoolLiteral>()) {
if (auto* lit = literal->As<ast::BoolLiteralExpression>()) {
return {type, {lit->value}};
}
TINT_UNREACHABLE(Resolver, builder_->Diagnostics());

View File

@ -114,7 +114,7 @@ TEST_F(ResolverTest, Stmt_Case) {
auto* assign = Assign(lhs, rhs);
auto* block = Block(assign);
ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(3));
lit.push_back(create<ast::SintLiteralExpression>(3));
auto* cse = create<ast::CaseStatement>(lit, block);
auto* cond_var = Var("c", ty.i32());
auto* sw = Switch(cond_var, cse, DefaultCase());

View File

@ -330,9 +330,9 @@ struct DecomposeMemoryAccess::State {
/// @param expr the expression to convert to an Offset
/// @returns an Offset for the given ast::Expression
const Offset* ToOffset(const ast::Expression* expr) {
if (auto* u32 = expr->As<ast::UintLiteral>()) {
if (auto* u32 = expr->As<ast::UintLiteralExpression>()) {
return offsets_.Create<OffsetLiteral>(u32->value);
} else if (auto* i32 = expr->As<ast::SintLiteral>()) {
} else if (auto* i32 = expr->As<ast::SintLiteralExpression>()) {
if (i32->value > 0) {
return offsets_.Create<OffsetLiteral>(i32->value);
}

View File

@ -81,8 +81,10 @@ void FoldConstants::Run(CloneContext& ctx, const DataMap&, DataMap&) {
}
if (ty->is_scalar()) {
return value.WithScalarAt(
0, [&](auto&& s) -> const ast::Literal* { return ctx.dst->Expr(s); });
return value.WithScalarAt(0,
[&](auto&& s) -> const ast::LiteralExpression* {
return ctx.dst->Expr(s);
});
}
return nullptr;

View File

@ -37,7 +37,7 @@ const ast::VariableDeclStatement* AsTrivialLetDecl(const ast::Statement* stmt) {
return nullptr;
}
auto* ctor = var->constructor;
if (!IsAnyOf<ast::IdentifierExpression, ast::Literal>(ctor)) {
if (!IsAnyOf<ast::IdentifierExpression, ast::LiteralExpression>(ctor)) {
return nullptr;
}
return var_decl;

View File

@ -46,7 +46,7 @@ void CollectSavedArrayIndices(const Program* program,
if (auto* a = expr->As<ast::IndexAccessorExpression>()) {
CollectSavedArrayIndices(program, a->object, cb);
if (!a->index->Is<ast::Literal>()) {
if (!a->index->Is<ast::LiteralExpression>()) {
cb(a->index);
}
return;

View File

@ -84,7 +84,7 @@ TEST_F(CreateASTTypeForTest, ArrayImplicitStride) {
ASSERT_TRUE(arr->As<ast::Array>()->type->Is<ast::F32>());
ASSERT_EQ(arr->As<ast::Array>()->decorations.size(), 0u);
auto* size = arr->As<ast::Array>()->count->As<ast::IntLiteral>();
auto* size = arr->As<ast::Array>()->count->As<ast::IntLiteralExpression>();
ASSERT_NE(size, nullptr);
EXPECT_EQ(size->ValueAsI32(), 2);
}
@ -104,7 +104,7 @@ TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) {
->stride,
64u);
auto* size = arr->As<ast::Array>()->count->As<ast::IntLiteral>();
auto* size = arr->As<ast::Array>()->count->As<ast::IntLiteralExpression>();
ASSERT_NE(size, nullptr);
EXPECT_EQ(size->ValueAsI32(), 2);
}

View File

@ -85,7 +85,7 @@ const ast::TypeConstructorExpression* AppendVector(
const auto num_supplied = vc->values.size();
if (num_supplied == 0) {
// Zero-value vector constructor. Populate with zeros
auto buildZero = [&]() -> const ast::Literal* {
auto buildZero = [&]() -> const ast::LiteralExpression* {
if (packed_el_sem_ty->Is<sem::I32>()) {
return b->Expr(0);
} else if (packed_el_sem_ty->Is<sem::U32>()) {

View File

@ -249,7 +249,7 @@ TEST_F(AppendVectorTest, ZeroVec3i32_i32) {
ASSERT_NE(vec_0004, nullptr);
ASSERT_EQ(vec_0004->values.size(), 4u);
for (size_t i = 0; i < 3; i++) {
auto* literal = As<ast::SintLiteral>(vec_0004->values[i]);
auto* literal = As<ast::SintLiteralExpression>(vec_0004->values[i]);
ASSERT_NE(literal, nullptr);
EXPECT_EQ(literal->value, 0);
}

View File

@ -1472,7 +1472,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out,
if (auto* i = expr->As<ast::IdentifierExpression>()) {
return EmitIdentifier(out, i);
}
if (auto* l = expr->As<ast::Literal>()) {
if (auto* l = expr->As<ast::LiteralExpression>()) {
return EmitLiteral(out, l);
}
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
@ -2008,10 +2008,11 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
return true;
}
bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) {
if (auto* l = lit->As<ast::BoolLiteral>()) {
bool GeneratorImpl::EmitLiteral(std::ostream& out,
const ast::LiteralExpression* lit) {
if (auto* l = lit->As<ast::BoolLiteralExpression>()) {
out << (l->value ? "true" : "false");
} else if (auto* fl = lit->As<ast::FloatLiteral>()) {
} else if (auto* fl = lit->As<ast::FloatLiteralExpression>()) {
if (std::isinf(fl->value)) {
out << (fl->value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)");
} else if (std::isnan(fl->value)) {
@ -2019,9 +2020,9 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) {
} else {
out << FloatToString(fl->value) << "f";
}
} else if (auto* sl = lit->As<ast::SintLiteral>()) {
} else if (auto* sl = lit->As<ast::SintLiteralExpression>()) {
out << sl->value;
} else if (auto* ul = lit->As<ast::UintLiteral>()) {
} else if (auto* ul = lit->As<ast::UintLiteralExpression>()) {
out << ul->value << "u";
} else {
diagnostics_.add_error(diag::System::Writer, "unknown literal type");

View File

@ -254,7 +254,7 @@ class GeneratorImpl : public TextGenerator {
/// @param out the output stream
/// @param lit the literal to emit
/// @returns true if the literal was successfully emitted
bool EmitLiteral(std::ostream& out, const ast::Literal* lit);
bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* lit);
/// Handles a loop statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted

View File

@ -2204,7 +2204,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out,
if (auto* i = expr->As<ast::IdentifierExpression>()) {
return EmitIdentifier(out, i);
}
if (auto* l = expr->As<ast::Literal>()) {
if (auto* l = expr->As<ast::LiteralExpression>()) {
return EmitLiteral(out, l);
}
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
@ -2683,10 +2683,11 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
return true;
}
bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) {
if (auto* l = lit->As<ast::BoolLiteral>()) {
bool GeneratorImpl::EmitLiteral(std::ostream& out,
const ast::LiteralExpression* lit) {
if (auto* l = lit->As<ast::BoolLiteralExpression>()) {
out << (l->value ? "true" : "false");
} else if (auto* fl = lit->As<ast::FloatLiteral>()) {
} else if (auto* fl = lit->As<ast::FloatLiteralExpression>()) {
if (std::isinf(fl->value)) {
out << (fl->value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)");
} else if (std::isnan(fl->value)) {
@ -2694,9 +2695,9 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) {
} else {
out << FloatToString(fl->value) << "f";
}
} else if (auto* sl = lit->As<ast::SintLiteral>()) {
} else if (auto* sl = lit->As<ast::SintLiteralExpression>()) {
out << sl->value;
} else if (auto* ul = lit->As<ast::UintLiteral>()) {
} else if (auto* ul = lit->As<ast::UintLiteralExpression>()) {
out << ul->value << "u";
} else {
diagnostics_.add_error(diag::System::Writer, "unknown literal type");

View File

@ -287,7 +287,7 @@ class GeneratorImpl : public TextGenerator {
/// @param out the output stream
/// @param lit the literal to emit
/// @returns true if the literal was successfully emitted
bool EmitLiteral(std::ostream& out, const ast::Literal* lit);
bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* lit);
/// Handles a loop statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted

View File

@ -1379,10 +1379,11 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const sem::Type* type) {
return true;
}
bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) {
if (auto* l = lit->As<ast::BoolLiteral>()) {
bool GeneratorImpl::EmitLiteral(std::ostream& out,
const ast::LiteralExpression* lit) {
if (auto* l = lit->As<ast::BoolLiteralExpression>()) {
out << (l->value ? "true" : "false");
} else if (auto* fl = lit->As<ast::FloatLiteral>()) {
} else if (auto* fl = lit->As<ast::FloatLiteralExpression>()) {
if (std::isinf(fl->value)) {
out << (fl->value >= 0 ? "INFINITY" : "-INFINITY");
} else if (std::isnan(fl->value)) {
@ -1390,7 +1391,7 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) {
} else {
out << FloatToString(fl->value) << "f";
}
} else if (auto* sl = lit->As<ast::SintLiteral>()) {
} else if (auto* sl = lit->As<ast::SintLiteralExpression>()) {
// MSL (and C++) parse `-2147483648` as a `long` because it parses unary
// minus and `2147483648` as separate tokens, and the latter doesn't
// fit into an (32-bit) `int`. WGSL, OTOH, parses this as an `i32`. To avoid
@ -1402,7 +1403,7 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) {
} else {
out << sl->value;
}
} else if (auto* ul = lit->As<ast::UintLiteral>()) {
} else if (auto* ul = lit->As<ast::UintLiteralExpression>()) {
out << ul->value << "u";
} else {
diagnostics_.add_error(diag::System::Writer, "unknown literal type");
@ -1431,7 +1432,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out,
if (auto* i = expr->As<ast::IdentifierExpression>()) {
return EmitIdentifier(out, i);
}
if (auto* l = expr->As<ast::Literal>()) {
if (auto* l = expr->As<ast::LiteralExpression>()) {
return EmitLiteral(out, l);
}
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {

View File

@ -216,7 +216,7 @@ class GeneratorImpl : public TextGenerator {
/// @param out the output of the expression stream
/// @param lit the literal to emit
/// @returns true if the literal was successfully emitted
bool EmitLiteral(std::ostream& out, const ast::Literal* lit);
bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* lit);
/// Handles a loop statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted

View File

@ -583,7 +583,7 @@ uint32_t Builder::GenerateExpression(const ast::Expression* expr) {
if (auto* i = expr->As<ast::IdentifierExpression>()) {
return GenerateIdentifierExpression(i);
}
if (auto* l = expr->As<ast::Literal>()) {
if (auto* l = expr->As<ast::LiteralExpression>()) {
return GenerateLiteralIfNeeded(nullptr, l);
}
if (auto* m = expr->As<ast::MemberAccessorExpression>()) {
@ -777,16 +777,16 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* var) {
// SPIR-V requires specialization constants to have initializers.
if (type->Is<sem::F32>()) {
ast::FloatLiteral l(ProgramID(), Source{}, 0.0f);
ast::FloatLiteralExpression l(ProgramID(), Source{}, 0.0f);
init_id = GenerateLiteralIfNeeded(var, &l);
} else if (type->Is<sem::U32>()) {
ast::UintLiteral l(ProgramID(), Source{}, 0);
ast::UintLiteralExpression l(ProgramID(), Source{}, 0);
init_id = GenerateLiteralIfNeeded(var, &l);
} else if (type->Is<sem::I32>()) {
ast::SintLiteral l(ProgramID(), Source{}, 0);
ast::SintLiteralExpression l(ProgramID(), Source{}, 0);
init_id = GenerateLiteralIfNeeded(var, &l);
} else if (type->Is<sem::Bool>()) {
ast::BoolLiteral l(ProgramID(), Source{}, false);
ast::BoolLiteralExpression l(ProgramID(), Source{}, false);
init_id = GenerateLiteralIfNeeded(var, &l);
} else {
error_ = "invalid type for pipeline constant ID, must be scalar";
@ -928,7 +928,7 @@ bool Builder::GenerateIndexAccessor(const ast::IndexAccessorExpression* expr,
auto extract_id = extract.to_i();
// If the index is a literal, we use OpCompositeExtract.
if (auto* literal = expr->index->As<ast::IntLiteral>()) {
if (auto* literal = expr->index->As<ast::IntLiteralExpression>()) {
if (!push_function_inst(spv::Op::OpCompositeExtract,
{Operand::Int(result_type_id), extract,
Operand::Int(info->source_id),
@ -1256,7 +1256,7 @@ uint32_t Builder::GetGLSLstd450Import() {
uint32_t Builder::GenerateConstructorExpression(const ast::Variable* var,
const ast::Expression* expr) {
if (auto* literal = expr->As<ast::Literal>()) {
if (auto* literal = expr->As<ast::LiteralExpression>()) {
return GenerateLiteralIfNeeded(var, literal);
}
if (auto* type = expr->As<ast::TypeConstructorExpression>()) {
@ -1269,7 +1269,7 @@ uint32_t Builder::GenerateConstructorExpression(const ast::Variable* var,
bool Builder::is_constructor_const(const ast::Expression* expr,
bool is_global_init) {
if (expr->Is<ast::Literal>()) {
if (expr->Is<ast::LiteralExpression>()) {
return true;
}
@ -1281,7 +1281,7 @@ bool Builder::is_constructor_const(const ast::Expression* expr,
for (size_t i = 0; i < tc->values.size(); ++i) {
auto* e = tc->values[i];
if (!e->IsAnyOf<ast::TypeConstructorExpression, ast::Literal>()) {
if (!e->IsAnyOf<ast::TypeConstructorExpression, ast::LiteralExpression>()) {
if (is_global_init) {
error_ = "constructor must be a constant expression";
return false;
@ -1295,7 +1295,7 @@ bool Builder::is_constructor_const(const ast::Expression* expr,
return false;
}
auto* lit = e->As<ast::Literal>();
auto* lit = e->As<ast::LiteralExpression>();
if (result_type->Is<sem::Vector>() && lit == nullptr) {
return false;
}
@ -1610,18 +1610,18 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(
uint32_t one_id;
uint32_t zero_id;
if (to_elem_type->Is<sem::F32>()) {
ast::FloatLiteral one(ProgramID(), Source{}, 1.0f);
ast::FloatLiteral zero(ProgramID(), Source{}, 0.0f);
ast::FloatLiteralExpression one(ProgramID(), Source{}, 1.0f);
ast::FloatLiteralExpression zero(ProgramID(), Source{}, 0.0f);
one_id = GenerateLiteralIfNeeded(nullptr, &one);
zero_id = GenerateLiteralIfNeeded(nullptr, &zero);
} else if (to_elem_type->Is<sem::U32>()) {
ast::UintLiteral one(ProgramID(), Source{}, 1);
ast::UintLiteral zero(ProgramID(), Source{}, 0);
ast::UintLiteralExpression one(ProgramID(), Source{}, 1);
ast::UintLiteralExpression zero(ProgramID(), Source{}, 0);
one_id = GenerateLiteralIfNeeded(nullptr, &one);
zero_id = GenerateLiteralIfNeeded(nullptr, &zero);
} else if (to_elem_type->Is<sem::I32>()) {
ast::SintLiteral one(ProgramID(), Source{}, 1);
ast::SintLiteral zero(ProgramID(), Source{}, 0);
ast::SintLiteralExpression one(ProgramID(), Source{}, 1);
ast::SintLiteralExpression zero(ProgramID(), Source{}, 0);
one_id = GenerateLiteralIfNeeded(nullptr, &one);
zero_id = GenerateLiteralIfNeeded(nullptr, &zero);
} else {
@ -1665,7 +1665,7 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough(
}
uint32_t Builder::GenerateLiteralIfNeeded(const ast::Variable* var,
const ast::Literal* lit) {
const ast::LiteralExpression* lit) {
ScalarConstant constant;
auto* global = builder_.Sem().Get<sem::GlobalVariable>(var);
@ -1674,16 +1674,16 @@ uint32_t Builder::GenerateLiteralIfNeeded(const ast::Variable* var,
constant.constant_id = global->ConstantId();
}
if (auto* l = lit->As<ast::BoolLiteral>()) {
if (auto* l = lit->As<ast::BoolLiteralExpression>()) {
constant.kind = ScalarConstant::Kind::kBool;
constant.value.b = l->value;
} else if (auto* sl = lit->As<ast::SintLiteral>()) {
} else if (auto* sl = lit->As<ast::SintLiteralExpression>()) {
constant.kind = ScalarConstant::Kind::kI32;
constant.value.i32 = sl->value;
} else if (auto* ul = lit->As<ast::UintLiteral>()) {
} else if (auto* ul = lit->As<ast::UintLiteralExpression>()) {
constant.kind = ScalarConstant::Kind::kU32;
constant.value.u32 = ul->value;
} else if (auto* fl = lit->As<ast::FloatLiteral>()) {
} else if (auto* fl = lit->As<ast::FloatLiteralExpression>()) {
constant.kind = ScalarConstant::Kind::kF32;
constant.value.f32 = fl->value;
} else {
@ -2920,7 +2920,7 @@ bool Builder::GenerateTextureIntrinsic(const ast::CallExpression* call,
op = spv::Op::OpImageQuerySizeLod;
spirv_params.emplace_back(gen(level));
} else {
ast::SintLiteral i32_0(ProgramID(), Source{}, 0);
ast::SintLiteralExpression i32_0(ProgramID(), Source{}, 0);
op = spv::Op::OpImageQuerySizeLod;
spirv_params.emplace_back(
Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0)));
@ -2952,7 +2952,7 @@ bool Builder::GenerateTextureIntrinsic(const ast::CallExpression* call,
texture_type->Is<sem::StorageTexture>()) {
op = spv::Op::OpImageQuerySize;
} else {
ast::SintLiteral i32_0(ProgramID(), Source{}, 0);
ast::SintLiteralExpression i32_0(ProgramID(), Source{}, 0);
op = spv::Op::OpImageQuerySizeLod;
spirv_params.emplace_back(
Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0)));
@ -3074,7 +3074,7 @@ bool Builder::GenerateTextureIntrinsic(const ast::CallExpression* call,
}
spirv_params.emplace_back(gen_arg(Usage::kDepthRef));
ast::FloatLiteral float_0(ProgramID(), Source{}, 0.0);
ast::FloatLiteralExpression float_0(ProgramID(), Source{}, 0.0);
image_operands.emplace_back(ImageOperand{
SpvImageOperandsLodMask,
Operand::Int(GenerateLiteralIfNeeded(nullptr, &float_0))});
@ -3625,7 +3625,7 @@ bool Builder::GenerateSwitchStatement(const ast::SwitchStatement* stmt) {
case_ids.push_back(block_id);
for (auto* selector : item->selectors) {
auto* int_literal = selector->As<ast::IntLiteral>();
auto* int_literal = selector->As<ast::IntLiteralExpression>();
if (!int_literal) {
error_ = "expected integer literal for switch case label";
return false;

View File

@ -353,7 +353,7 @@ class Builder {
/// @param lit the literal to generate
/// @returns the ID on success or 0 on failure
uint32_t GenerateLiteralIfNeeded(const ast::Variable* var,
const ast::Literal* lit);
const ast::LiteralExpression* lit);
/// Generates a binary expression
/// @param expr the expression to generate
/// @returns the expression ID on success or 0 otherwise

View File

@ -22,7 +22,7 @@ namespace spirv {
using BuilderTest = TestHelper;
TEST_F(BuilderTest, Literal_Bool_True) {
auto* b_true = create<ast::BoolLiteral>(true);
auto* b_true = create<ast::BoolLiteralExpression>(true);
WrapInFunction(b_true);
spirv::Builder& b = Build();
@ -37,7 +37,7 @@ TEST_F(BuilderTest, Literal_Bool_True) {
}
TEST_F(BuilderTest, Literal_Bool_False) {
auto* b_false = create<ast::BoolLiteral>(false);
auto* b_false = create<ast::BoolLiteralExpression>(false);
WrapInFunction(b_false);
spirv::Builder& b = Build();
@ -52,8 +52,8 @@ TEST_F(BuilderTest, Literal_Bool_False) {
}
TEST_F(BuilderTest, Literal_Bool_Dedup) {
auto* b_true = create<ast::BoolLiteral>(true);
auto* b_false = create<ast::BoolLiteral>(false);
auto* b_true = create<ast::BoolLiteralExpression>(true);
auto* b_false = create<ast::BoolLiteralExpression>(false);
WrapInFunction(b_true, b_false);
spirv::Builder& b = Build();
@ -72,7 +72,7 @@ TEST_F(BuilderTest, Literal_Bool_Dedup) {
}
TEST_F(BuilderTest, Literal_I32) {
auto* i = create<ast::SintLiteral>(-23);
auto* i = create<ast::SintLiteralExpression>(-23);
WrapInFunction(i);
spirv::Builder& b = Build();
@ -86,8 +86,8 @@ TEST_F(BuilderTest, Literal_I32) {
}
TEST_F(BuilderTest, Literal_I32_Dedup) {
auto* i1 = create<ast::SintLiteral>(-23);
auto* i2 = create<ast::SintLiteral>(-23);
auto* i1 = create<ast::SintLiteralExpression>(-23);
auto* i2 = create<ast::SintLiteralExpression>(-23);
WrapInFunction(i1, i2);
spirv::Builder& b = Build();
@ -102,7 +102,7 @@ TEST_F(BuilderTest, Literal_I32_Dedup) {
}
TEST_F(BuilderTest, Literal_U32) {
auto* i = create<ast::UintLiteral>(23);
auto* i = create<ast::UintLiteralExpression>(23);
WrapInFunction(i);
spirv::Builder& b = Build();
@ -117,8 +117,8 @@ TEST_F(BuilderTest, Literal_U32) {
}
TEST_F(BuilderTest, Literal_U32_Dedup) {
auto* i1 = create<ast::UintLiteral>(23);
auto* i2 = create<ast::UintLiteral>(23);
auto* i1 = create<ast::UintLiteralExpression>(23);
auto* i2 = create<ast::UintLiteralExpression>(23);
WrapInFunction(i1, i2);
spirv::Builder& b = Build();
@ -133,7 +133,7 @@ TEST_F(BuilderTest, Literal_U32_Dedup) {
}
TEST_F(BuilderTest, Literal_F32) {
auto* i = create<ast::FloatLiteral>(23.245f);
auto* i = create<ast::FloatLiteralExpression>(23.245f);
WrapInFunction(i);
spirv::Builder& b = Build();
@ -148,8 +148,8 @@ TEST_F(BuilderTest, Literal_F32) {
}
TEST_F(BuilderTest, Literal_F32_Dedup) {
auto* i1 = create<ast::FloatLiteral>(23.245f);
auto* i2 = create<ast::FloatLiteral>(23.245f);
auto* i1 = create<ast::FloatLiteralExpression>(23.245f);
auto* i2 = create<ast::FloatLiteralExpression>(23.245f);
WrapInFunction(i1, i2);
spirv::Builder& b = Build();

View File

@ -131,7 +131,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out,
if (auto* i = expr->As<ast::IdentifierExpression>()) {
return EmitIdentifier(out, i);
}
if (auto* l = expr->As<ast::Literal>()) {
if (auto* l = expr->As<ast::LiteralExpression>()) {
return EmitLiteral(out, l);
}
if (auto* c = expr->As<ast::TypeConstructorExpression>()) {
@ -268,14 +268,15 @@ bool GeneratorImpl::EmitTypeConstructor(
return true;
}
bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) {
if (auto* bl = lit->As<ast::BoolLiteral>()) {
bool GeneratorImpl::EmitLiteral(std::ostream& out,
const ast::LiteralExpression* lit) {
if (auto* bl = lit->As<ast::BoolLiteralExpression>()) {
out << (bl->value ? "true" : "false");
} else if (auto* fl = lit->As<ast::FloatLiteral>()) {
} else if (auto* fl = lit->As<ast::FloatLiteralExpression>()) {
out << FloatToBitPreservingString(fl->value);
} else if (auto* sl = lit->As<ast::SintLiteral>()) {
} else if (auto* sl = lit->As<ast::SintLiteralExpression>()) {
out << sl->value;
} else if (auto* ul = lit->As<ast::UintLiteral>()) {
} else if (auto* ul = lit->As<ast::UintLiteralExpression>()) {
out << ul->value << "u";
} else {
diagnostics_.add_error(diag::System::Writer, "unknown literal type");

View File

@ -99,7 +99,7 @@ class GeneratorImpl : public TextGenerator {
/// @param out the output of the expression stream
/// @param expr the literal expression expression
/// @returns true if the literal expression is emitted
bool EmitLiteral(std::ostream& out, const ast::Literal* expr);
bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* expr);
/// Handles a continue statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully