mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 15:16:16 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
const sem::Type* type) {
|
||||
if (auto* lit = literal->As<ast::SintLiteral>()) {
|
||||
sem::Constant Resolver::EvaluateConstantValue(
|
||||
const ast::LiteralExpression* literal,
|
||||
const sem::Type* type) {
|
||||
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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user