Update internals to initializer instead of constructor.

This CL catches up the internals (along with a few error messages) to
say `initializer` instead of `constructor.

Bug: tint:1600
Change-Id: I8e56572c310d77da1130380bdd32b334f27c8e46
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106462
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
dan sinclair
2022-10-20 13:38:28 +00:00
committed by Dawn LUCI CQ
parent 56ce1a2155
commit 6e77b47ed9
155 changed files with 6593 additions and 6593 deletions

View File

@@ -2492,18 +2492,18 @@ bool FunctionEmitter::EmitFunctionVariables() {
if (failed()) {
return false;
}
const ast::Expression* constructor = nullptr;
const ast::Expression* initializer = nullptr;
if (inst.NumInOperands() > 1) {
// SPIR-V initializers are always constants.
// (OpenCL also allows the ID of an OpVariable, but we don't handle that
// here.)
constructor = parser_impl_.MakeConstantExpression(inst.GetSingleWordInOperand(1)).expr;
if (!constructor) {
initializer = parser_impl_.MakeConstantExpression(inst.GetSingleWordInOperand(1)).expr;
if (!initializer) {
return false;
}
}
auto* var = parser_impl_.MakeVar(inst.result_id(), ast::AddressSpace::kNone, var_store_type,
constructor, AttributeList{});
initializer, AttributeList{});
auto* var_decl_stmt = create<ast::VariableDeclStatement>(Source{}, var);
AddStatement(var_decl_stmt);
auto* var_type = ty_.Reference(var_store_type, ast::AddressSpace::kNone);
@@ -3967,7 +3967,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(const spvtools::opt::Inst
if (ext_opcode == GLSLstd450Ldexp) {
// WGSL requires the second argument to be signed.
// Use a type constructor to convert it, which is the same as a bitcast.
// Use a type initializer to convert it, which is the same as a bitcast.
// If the value would go from very large positive to negative, then the
// original result would have been infinity. And since WGSL
// implementations may assume that infinities are not present, then we
@@ -4705,7 +4705,7 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(const spvtools::opt::Instruct
// Idiomatic vector accessors.
// Generate an ast::TypeConstructor expression.
// Generate an ast::TypeInitializer expression.
// Assume the literal indices are valid, and there is a valid number of them.
auto source = GetSourceForInst(inst);
const Vector* result_type = As<Vector>(parser_impl_.ConvertType(inst.type_id()));

View File

@@ -957,7 +957,7 @@ class FunctionEmitter {
const spvtools::opt::Instruction& image_access);
/// Returns the given value as an I32. If it's already an I32 then this
/// return the given value. Otherwise, wrap the value in a TypeConstructor
/// return the given value. Otherwise, wrap the value in a TypeInitializer
/// expression.
/// @param value the value to pass through or convert
/// @returns the value as an I32 value.
@@ -965,7 +965,7 @@ class FunctionEmitter {
/// Returns the given value as a signed integer type of the same shape
/// if the value is unsigned scalar or vector, by wrapping the value
/// with a TypeConstructor expression. Returns the value itself if the
/// with a TypeInitializer expression. Returns the value itself if the
/// value otherwise.
/// @param value the value to pass through or convert
/// @returns the value itself, or converted to signed integral
@@ -1277,7 +1277,7 @@ class FunctionEmitter {
TypedExpression Dereference(TypedExpression expr);
/// Creates a new `ast::Node` owned by the ProgramBuilder.
/// @param args the arguments to pass to the type constructor
/// @param args the arguments to pass to the type initializer
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) const {

View File

@@ -977,7 +977,7 @@ TEST_F(SpvParserTest, DISABLED_WorkgroupSize_Overridable) {
none
__u32
{
ScalarConstructor[not set]{2}
ScalarInitializer[not set]{2}
}
}
VariableConst{
@@ -988,7 +988,7 @@ TEST_F(SpvParserTest, DISABLED_WorkgroupSize_Overridable) {
none
__u32
{
ScalarConstructor[not set]{4}
ScalarInitializer[not set]{4}
}
}
VariableConst{
@@ -999,7 +999,7 @@ TEST_F(SpvParserTest, DISABLED_WorkgroupSize_Overridable) {
none
__u32
{
ScalarConstructor[not set]{8}
ScalarInitializer[not set]{8}
}
}
)")) << got;
@@ -1010,11 +1010,11 @@ TEST_F(SpvParserTest, DISABLED_WorkgroupSize_Overridable) {
none
__vec_3__u32
{
TypeConstructor[not set]{
TypeInitializer[not set]{
__vec_3__u32
ScalarConstructor[not set]{2}
ScalarConstructor[not set]{4}
ScalarConstructor[not set]{8}
ScalarInitializer[not set]{2}
ScalarInitializer[not set]{4}
ScalarInitializer[not set]{8}
}
}
}

View File

@@ -1485,16 +1485,16 @@ bool ParserImpl::EmitModuleScopeVariables() {
auto* ast_store_type = ast_type->As<Pointer>()->type;
auto ast_address_space = ast_type->As<Pointer>()->address_space;
const ast::Expression* ast_constructor = nullptr;
const ast::Expression* ast_initializer = nullptr;
if (var.NumInOperands() > 1) {
// SPIR-V initializers are always constants.
// (OpenCL also allows the ID of an OpVariable, but we don't handle that
// here.)
ast_constructor = MakeConstantExpression(var.GetSingleWordInOperand(1)).expr;
ast_initializer = MakeConstantExpression(var.GetSingleWordInOperand(1)).expr;
}
auto* ast_var = MakeVar(var.result_id(), ast_address_space, ast_store_type, ast_constructor,
auto* ast_var = MakeVar(var.result_id(), ast_address_space, ast_store_type, ast_initializer,
utils::Empty);
// TODO(dneto): initializers (a.k.a. constructor expression)
// TODO(dneto): initializers (a.k.a. initializer expression)
if (ast_var) {
builder_.AST().AddGlobalVariable(ast_var);
module_variable_.GetOrCreate(var.result_id(), [ast_var] { return ast_var; });
@@ -1505,14 +1505,14 @@ bool ParserImpl::EmitModuleScopeVariables() {
if (builtin_position_.per_vertex_var_id) {
// Make sure the variable has a name.
namer_.SuggestSanitizedName(builtin_position_.per_vertex_var_id, "gl_Position");
const ast::Expression* ast_constructor = nullptr;
const ast::Expression* ast_initializer = nullptr;
if (builtin_position_.per_vertex_var_init_id) {
// The initializer is complex.
const auto* init = def_use_mgr_->GetDef(builtin_position_.per_vertex_var_init_id);
switch (init->opcode()) {
case SpvOpConstantComposite:
case SpvOpSpecConstantComposite:
ast_constructor =
ast_initializer =
MakeConstantExpression(
init->GetSingleWordInOperand(builtin_position_.position_member_index))
.expr;
@@ -1527,7 +1527,7 @@ bool ParserImpl::EmitModuleScopeVariables() {
auto* ast_var =
MakeVar(builtin_position_.per_vertex_var_id,
enum_converter_.ToAddressSpace(builtin_position_.storage_class),
ConvertType(builtin_position_.position_member_type_id), ast_constructor, {});
ConvertType(builtin_position_.position_member_type_id), ast_initializer, {});
builder_.AST().AddGlobalVariable(ast_var);
module_variable_.GetOrCreate(builtin_position_.per_vertex_var_id,
@@ -1562,7 +1562,7 @@ const spvtools::opt::analysis::IntConstant* ParserImpl::GetArraySize(uint32_t va
ast::Var* ParserImpl::MakeVar(uint32_t id,
ast::AddressSpace address_space,
const Type* storage_type,
const ast::Expression* constructor,
const ast::Expression* initializer,
AttributeList decorations) {
if (storage_type == nullptr) {
Fail() << "internal error: can't make ast::Variable for null type";
@@ -1593,23 +1593,23 @@ ast::Var* ParserImpl::MakeVar(uint32_t id,
auto sym = builder_.Symbols().Register(namer_.Name(id));
return create<ast::Var>(Source{}, sym, storage_type->Build(builder_), address_space, access,
constructor, decorations);
initializer, decorations);
}
ast::Let* ParserImpl::MakeLet(uint32_t id, const Type* type, const ast::Expression* constructor) {
ast::Let* ParserImpl::MakeLet(uint32_t id, const Type* type, const ast::Expression* initializer) {
auto sym = builder_.Symbols().Register(namer_.Name(id));
return create<ast::Let>(Source{}, sym, type->Build(builder_), constructor, utils::Empty);
return create<ast::Let>(Source{}, sym, type->Build(builder_), initializer, utils::Empty);
}
ast::Override* ParserImpl::MakeOverride(uint32_t id,
const Type* type,
const ast::Expression* constructor,
const ast::Expression* initializer,
AttributeList decorations) {
if (!ConvertDecorationsForVariable(id, &type, &decorations, false)) {
return nullptr;
}
auto sym = builder_.Symbols().Register(namer_.Name(id));
return create<ast::Override>(Source{}, sym, type->Build(builder_), constructor, decorations);
return create<ast::Override>(Source{}, sym, type->Build(builder_), initializer, decorations);
}
ast::Parameter* ParserImpl::MakeParameter(uint32_t id,
@@ -1965,7 +1965,7 @@ TypedExpression ParserImpl::MakeConstantExpressionForScalarSpirvConstant(
}
const ast::Expression* ParserImpl::MakeNullValue(const Type* type) {
// TODO(dneto): Use the no-operands constructor syntax when it becomes
// TODO(dneto): Use the no-operands initializer syntax when it becomes
// available in Tint.
// https://github.com/gpuweb/gpuweb/issues/685
// https://bugs.chromium.org/p/tint/issues/detail?id=34

View File

@@ -427,32 +427,32 @@ class ParserImpl : Reader {
/// @param id the SPIR-V result ID
/// @param address_space the address space, which cannot be ast::AddressSpace::kNone
/// @param storage_type the storage type of the variable
/// @param constructor the variable constructor
/// @param initializer the variable initializer
/// @param decorations the variable decorations
/// @returns a new Variable node, or null in the ignorable variable case and
/// in the error case
ast::Var* MakeVar(uint32_t id,
ast::AddressSpace address_space,
const Type* storage_type,
const ast::Expression* constructor,
const ast::Expression* initializer,
AttributeList decorations);
/// Creates an AST 'let' node for a SPIR-V ID, including any attached decorations,.
/// @param id the SPIR-V result ID
/// @param type the type of the variable
/// @param constructor the variable constructor
/// @param initializer the variable initializer
/// @returns the AST 'let' node
ast::Let* MakeLet(uint32_t id, const Type* type, const ast::Expression* constructor);
ast::Let* MakeLet(uint32_t id, const Type* type, const ast::Expression* initializer);
/// Creates an AST 'override' node for a SPIR-V ID, including any attached decorations.
/// @param id the SPIR-V result ID
/// @param type the type of the variable
/// @param constructor the variable constructor
/// @param initializer the variable initializer
/// @param decorations the variable decorations
/// @returns the AST 'override' node
ast::Override* MakeOverride(uint32_t id,
const Type* type,
const ast::Expression* constructor,
const ast::Expression* initializer,
AttributeList decorations);
/// Creates an AST parameter node for a SPIR-V ID, including any attached decorations, unless
@@ -780,7 +780,7 @@ class ParserImpl : Reader {
uint32_t* array_stride);
/// Creates a new `ast::Node` owned by the ProgramBuilder.
/// @param args the arguments to pass to the type constructor
/// @param args the arguments to pass to the type initializer
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {

View File

@@ -2939,7 +2939,7 @@ INSTANTIATE_TEST_SUITE_P(
INSTANTIATE_TEST_SUITE_P(
// When SPIR-V wants the result type to be unsigned, we have to
// insert a type constructor or bitcast for WGSL to do the type
// insert a type initializer or bitcast for WGSL to do the type
// coercion. But the algorithm already does that as a matter
// of course.
ImageQuerySizeLod_NonArrayed_UnsignedResult_SignedLevel,

View File

@@ -2555,7 +2555,7 @@ Maybe<const ast::Expression*> ParserImpl::primary_expression() {
return Failure::kErrored;
}
if (call.matched) {
auto params = expect_argument_expression_list("type constructor");
auto params = expect_argument_expression_list("type initializer");
if (params.errored) {
return Failure::kErrored;
}

View File

@@ -186,17 +186,17 @@ fn f() { f() }
)");
}
TEST_F(ParserImplErrorTest, ConstructorExprMissingLParen) {
TEST_F(ParserImplErrorTest, InitializerExprMissingLParen) {
EXPECT("fn f() { x = vec2<u32>1,2); }",
R"(test.wgsl:1:23 error: expected '(' for type constructor
R"(test.wgsl:1:23 error: expected '(' for type initializer
fn f() { x = vec2<u32>1,2); }
^
)");
}
TEST_F(ParserImplErrorTest, ConstructorExprMissingRParen) {
TEST_F(ParserImplErrorTest, InitializerExprMissingRParen) {
EXPECT("fn f() { x = vec2<u32>(1,2; }",
R"(test.wgsl:1:27 error: expected ')' for type constructor
R"(test.wgsl:1:27 error: expected ')' for type initializer
fn f() { x = vec2<u32>(1,2; }
^
)");
@@ -218,7 +218,7 @@ fn f() { let a : i32; }
)");
}
TEST_F(ParserImplErrorTest, ConstVarStmtMissingConstructor) {
TEST_F(ParserImplErrorTest, ConstVarStmtMissingInitializer) {
EXPECT("fn f() { let a : i32 = >; }",
R"(test.wgsl:1:24 error: missing initializer for 'let' declaration
fn f() { let a : i32 = >; }
@@ -530,7 +530,7 @@ const i : i32 = 1
TEST_F(ParserImplErrorTest, GlobalDeclConstMissingLParen) {
EXPECT("const i : vec2<i32> = vec2<i32>;",
R"(test.wgsl:1:32 error: expected '(' for type constructor
R"(test.wgsl:1:32 error: expected '(' for type initializer
const i : vec2<i32> = vec2<i32>;
^
)");
@@ -538,7 +538,7 @@ const i : vec2<i32> = vec2<i32>;
TEST_F(ParserImplErrorTest, GlobalDeclConstMissingRParen) {
EXPECT("const i : vec2<i32> = vec2<i32>(1., 2.;",
R"(test.wgsl:1:39 error: expected ')' for type constructor
R"(test.wgsl:1:39 error: expected ')' for type initializer
const i : vec2<i32> = vec2<i32>(1., 2.;
^
)");
@@ -581,7 +581,7 @@ TEST_F(ParserImplErrorTest, GlobalDeclConstExprMaxDepth) {
TEST_F(ParserImplErrorTest, GlobalDeclConstExprMissingLParen) {
EXPECT("const i : vec2<i32> = vec2<i32> 1, 2);",
R"(test.wgsl:1:33 error: expected '(' for type constructor
R"(test.wgsl:1:33 error: expected '(' for type initializer
const i : vec2<i32> = vec2<i32> 1, 2);
^
)");
@@ -589,7 +589,7 @@ const i : vec2<i32> = vec2<i32> 1, 2);
TEST_F(ParserImplErrorTest, GlobalDeclConstExprMissingRParen) {
EXPECT("const i : vec2<i32> = vec2<i32>(1, 2;",
R"(test.wgsl:1:37 error: expected ')' for type constructor
R"(test.wgsl:1:37 error: expected ')' for type initializer
const i : vec2<i32> = vec2<i32>(1, 2;
^
)");
@@ -628,7 +628,7 @@ TEST_F(ParserImplErrorTest, GlobalDeclLetMissingLParen) {
let i : vec2<i32> = vec2<i32>;
^^^
test.wgsl:1:30 error: expected '(' for type constructor
test.wgsl:1:30 error: expected '(' for type initializer
let i : vec2<i32> = vec2<i32>;
^
)");
@@ -641,7 +641,7 @@ TEST_F(ParserImplErrorTest, GlobalDeclLetMissingRParen) {
let i : vec2<i32> = vec2<i32>(1., 2.;
^^^
test.wgsl:1:37 error: expected ')' for type constructor
test.wgsl:1:37 error: expected ')' for type initializer
let i : vec2<i32> = vec2<i32>(1., 2.;
^
)");
@@ -667,7 +667,7 @@ TEST_F(ParserImplErrorTest, GlobalDeclLetExprMissingLParen) {
let i : vec2<i32> = vec2<i32> 1, 2);
^^^
test.wgsl:1:31 error: expected '(' for type constructor
test.wgsl:1:31 error: expected '(' for type initializer
let i : vec2<i32> = vec2<i32> 1, 2);
^
)");
@@ -680,7 +680,7 @@ TEST_F(ParserImplErrorTest, GlobalDeclLetExprMissingRParen) {
let i : vec2<i32> = vec2<i32>(1, 2;
^^^
test.wgsl:1:35 error: expected ')' for type constructor
test.wgsl:1:35 error: expected ')' for type initializer
let i : vec2<i32> = vec2<i32>(1, 2;
^
)");

View File

@@ -58,7 +58,7 @@ TEST_F(ForStmtTest, InitializerStatementDecl) {
ASSERT_TRUE(Is<ast::VariableDeclStatement>(fl->initializer));
auto* var = fl->initializer->As<ast::VariableDeclStatement>()->variable;
EXPECT_TRUE(var->Is<ast::Var>());
EXPECT_EQ(var->constructor, nullptr);
EXPECT_EQ(var->initializer, nullptr);
EXPECT_EQ(fl->condition, nullptr);
EXPECT_EQ(fl->continuing, nullptr);
EXPECT_TRUE(fl->body->Empty());
@@ -75,7 +75,7 @@ TEST_F(ForStmtTest, InitializerStatementDeclEqual) {
ASSERT_TRUE(Is<ast::VariableDeclStatement>(fl->initializer));
auto* var = fl->initializer->As<ast::VariableDeclStatement>()->variable;
EXPECT_TRUE(var->Is<ast::Var>());
EXPECT_NE(var->constructor, nullptr);
EXPECT_NE(var->initializer, nullptr);
EXPECT_EQ(fl->condition, nullptr);
EXPECT_EQ(fl->continuing, nullptr);
EXPECT_TRUE(fl->body->Empty());
@@ -91,7 +91,7 @@ TEST_F(ForStmtTest, InitializerStatementConstDecl) {
ASSERT_TRUE(Is<ast::VariableDeclStatement>(fl->initializer));
auto* var = fl->initializer->As<ast::VariableDeclStatement>()->variable;
EXPECT_TRUE(var->Is<ast::Let>());
EXPECT_NE(var->constructor, nullptr);
EXPECT_NE(var->initializer, nullptr);
EXPECT_EQ(fl->condition, nullptr);
EXPECT_EQ(fl->continuing, nullptr);
EXPECT_TRUE(fl->body->Empty());

View File

@@ -39,8 +39,8 @@ TEST_F(ParserImplTest, GlobalLetDecl) {
EXPECT_EQ(const_->source.range.end.line, 1u);
EXPECT_EQ(const_->source.range.end.column, 6u);
ASSERT_NE(const_->constructor, nullptr);
EXPECT_TRUE(const_->constructor->Is<ast::LiteralExpression>());
ASSERT_NE(const_->initializer, nullptr);
EXPECT_TRUE(const_->initializer->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, GlobalLetDecl_Inferred) {
@@ -63,8 +63,8 @@ TEST_F(ParserImplTest, GlobalLetDecl_Inferred) {
EXPECT_EQ(const_->source.range.end.line, 1u);
EXPECT_EQ(const_->source.range.end.column, 6u);
ASSERT_NE(const_->constructor, nullptr);
EXPECT_TRUE(const_->constructor->Is<ast::LiteralExpression>());
ASSERT_NE(const_->initializer, nullptr);
EXPECT_TRUE(const_->initializer->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, GlobalLetDecl_InvalidExpression) {
@@ -120,8 +120,8 @@ TEST_F(ParserImplTest, GlobalConstDecl) {
EXPECT_EQ(c->source.range.end.line, 1u);
EXPECT_EQ(c->source.range.end.column, 8u);
ASSERT_NE(c->constructor, nullptr);
EXPECT_TRUE(c->constructor->Is<ast::LiteralExpression>());
ASSERT_NE(c->initializer, nullptr);
EXPECT_TRUE(c->initializer->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, GlobalConstDecl_Inferred) {
@@ -144,8 +144,8 @@ TEST_F(ParserImplTest, GlobalConstDecl_Inferred) {
EXPECT_EQ(c->source.range.end.line, 1u);
EXPECT_EQ(c->source.range.end.column, 8u);
ASSERT_NE(c->constructor, nullptr);
EXPECT_TRUE(c->constructor->Is<ast::LiteralExpression>());
ASSERT_NE(c->initializer, nullptr);
EXPECT_TRUE(c->initializer->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, GlobalConstDecl_InvalidExpression) {
@@ -196,8 +196,8 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId) {
EXPECT_EQ(override->source.range.end.line, 1u);
EXPECT_EQ(override->source.range.end.column, 18u);
ASSERT_NE(override->constructor, nullptr);
EXPECT_TRUE(override->constructor->Is<ast::LiteralExpression>());
ASSERT_NE(override->initializer, nullptr);
EXPECT_TRUE(override->initializer->Is<ast::LiteralExpression>());
auto* override_attr = ast::GetAttribute<ast::IdAttribute>(override->attributes);
ASSERT_NE(override_attr, nullptr);
@@ -226,8 +226,8 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId_TrailingComma) {
EXPECT_EQ(override->source.range.end.line, 1u);
EXPECT_EQ(override->source.range.end.column, 19u);
ASSERT_NE(override->constructor, nullptr);
EXPECT_TRUE(override->constructor->Is<ast::LiteralExpression>());
ASSERT_NE(override->initializer, nullptr);
EXPECT_TRUE(override->initializer->Is<ast::LiteralExpression>());
auto* override_attr = ast::GetAttribute<ast::IdAttribute>(override->attributes);
ASSERT_NE(override_attr, nullptr);
@@ -256,8 +256,8 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithoutId) {
EXPECT_EQ(override->source.range.end.line, 1u);
EXPECT_EQ(override->source.range.end.column, 11u);
ASSERT_NE(override->constructor, nullptr);
EXPECT_TRUE(override->constructor->Is<ast::LiteralExpression>());
ASSERT_NE(override->initializer, nullptr);
EXPECT_TRUE(override->initializer->Is<ast::LiteralExpression>());
auto* id_attr = ast::GetAttribute<ast::IdAttribute>(override->attributes);
ASSERT_EQ(id_attr, nullptr);

View File

@@ -17,7 +17,7 @@
namespace tint::reader::wgsl {
namespace {
TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) {
TEST_F(ParserImplTest, GlobalVariableDecl_WithoutInitializer) {
auto p = parser("var<private> a : f32");
auto attrs = p->attribute_list();
EXPECT_FALSE(attrs.errored);
@@ -38,10 +38,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) {
EXPECT_EQ(var->source.range.end.line, 1u);
EXPECT_EQ(var->source.range.end.column, 15u);
ASSERT_EQ(var->constructor, nullptr);
ASSERT_EQ(var->initializer, nullptr);
}
TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
TEST_F(ParserImplTest, GlobalVariableDecl_WithInitializer) {
auto p = parser("var<private> a : f32 = 1.");
auto attrs = p->attribute_list();
EXPECT_FALSE(attrs.errored);
@@ -62,8 +62,8 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
EXPECT_EQ(var->source.range.end.line, 1u);
EXPECT_EQ(var->source.range.end.column, 15u);
ASSERT_NE(var->constructor, nullptr);
ASSERT_TRUE(var->constructor->Is<ast::FloatLiteralExpression>());
ASSERT_NE(var->initializer, nullptr);
ASSERT_TRUE(var->initializer->Is<ast::FloatLiteralExpression>());
}
TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute) {
@@ -88,7 +88,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute) {
EXPECT_EQ(var->source.range.end.line, 1u);
EXPECT_EQ(var->source.range.end.column, 37u);
ASSERT_EQ(var->constructor, nullptr);
ASSERT_EQ(var->initializer, nullptr);
auto& attributes = var->attributes;
ASSERT_EQ(attributes.Length(), 2u);
@@ -119,7 +119,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute_MulitpleGroups) {
EXPECT_EQ(var->source.range.end.line, 1u);
EXPECT_EQ(var->source.range.end.column, 37u);
ASSERT_EQ(var->constructor, nullptr);
ASSERT_EQ(var->initializer, nullptr);
auto& attributes = var->attributes;
ASSERT_EQ(attributes.Length(), 2u);

View File

@@ -65,7 +65,7 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {
ast::IntLiteralExpression::Suffix::kNone);
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_ZeroConstructor) {
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_ZeroInitializer) {
auto p = parser("vec4<i32>()");
auto e = p->primary_expression();
EXPECT_TRUE(e.matched);
@@ -96,7 +96,7 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_MissingLeftParen) {
EXPECT_TRUE(e.errored);
EXPECT_EQ(e.value, nullptr);
ASSERT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:11: expected '(' for type constructor");
EXPECT_EQ(p->error(), "1:11: expected '(' for type initializer");
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_MissingRightParen) {
@@ -106,7 +106,7 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_MissingRightParen) {
EXPECT_TRUE(e.errored);
EXPECT_EQ(e.value, nullptr);
ASSERT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:25: expected ')' for type constructor");
EXPECT_EQ(p->error(), "1:25: expected ')' for type initializer");
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_InvalidValue) {
@@ -116,10 +116,10 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_InvalidValue) {
EXPECT_TRUE(e.errored);
EXPECT_EQ(e.value, nullptr);
ASSERT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:5: expected ')' for type constructor");
EXPECT_EQ(p->error(), "1:5: expected ')' for type initializer");
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructConstructor_Empty) {
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructInitializer_Empty) {
auto p = parser(R"(
struct S { a : i32, b : f32, }
S()
@@ -143,7 +143,7 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructConstructor_Empty) {
ASSERT_EQ(call->args.Length(), 0u);
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructConstructor_NotEmpty) {
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructInitializer_NotEmpty) {
auto p = parser(R"(
struct S { a : i32, b : f32, }
S(1u, 2.0)

View File

@@ -33,7 +33,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
ASSERT_EQ(e->source.range.end.line, 1u);
ASSERT_EQ(e->source.range.end.column, 6u);
EXPECT_EQ(e->variable->constructor, nullptr);
EXPECT_EQ(e->variable->initializer, nullptr);
}
TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
@@ -52,11 +52,11 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
ASSERT_EQ(e->source.range.end.line, 1u);
ASSERT_EQ(e->source.range.end.column, 6u);
ASSERT_NE(e->variable->constructor, nullptr);
EXPECT_TRUE(e->variable->constructor->Is<ast::LiteralExpression>());
ASSERT_NE(e->variable->initializer, nullptr);
EXPECT_TRUE(e->variable->initializer->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ConstructorInvalid) {
TEST_F(ParserImplTest, VariableStmt_VariableDecl_InitializerInvalid) {
auto p = parser("var a : i32 = if(a) {}");
auto e = p->variable_statement();
EXPECT_FALSE(e.matched);
@@ -77,8 +77,8 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit) {
ASSERT_NE(e->variable, nullptr);
EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(e->variable->constructor, nullptr);
auto* call = e->variable->constructor->As<ast::CallExpression>();
ASSERT_NE(e->variable->initializer, nullptr);
auto* call = e->variable->initializer->As<ast::CallExpression>();
ASSERT_NE(call, nullptr);
EXPECT_EQ(call->target.name, nullptr);
EXPECT_NE(call->target.type, nullptr);
@@ -95,8 +95,8 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) {
ASSERT_NE(e->variable, nullptr);
EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(e->variable->constructor, nullptr);
auto* call = e->variable->constructor->As<ast::CallExpression>();
ASSERT_NE(e->variable->initializer, nullptr);
auto* call = e->variable->initializer->As<ast::CallExpression>();
ASSERT_NE(call, nullptr);
EXPECT_EQ(call->target.name, nullptr);
EXPECT_NE(call->target.type, nullptr);
@@ -113,8 +113,8 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) {
ASSERT_NE(e->variable, nullptr);
EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(e->variable->constructor, nullptr);
auto* call = e->variable->constructor->As<ast::CallExpression>();
ASSERT_NE(e->variable->initializer, nullptr);
auto* call = e->variable->initializer->As<ast::CallExpression>();
ASSERT_NE(call, nullptr);
EXPECT_EQ(call->target.name, nullptr);
EXPECT_NE(call->target.type, nullptr);
@@ -131,8 +131,8 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) {
ASSERT_NE(e->variable, nullptr);
EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(e->variable->constructor, nullptr);
auto* call = e->variable->constructor->As<ast::CallExpression>();
ASSERT_NE(e->variable->initializer, nullptr);
auto* call = e->variable->initializer->As<ast::CallExpression>();
ASSERT_NE(call, nullptr);
EXPECT_EQ(call->target.name, nullptr);
EXPECT_NE(call->target.type, nullptr);
@@ -164,10 +164,10 @@ TEST_F(ParserImplTest, VariableStmt_Let_ComplexExpression) {
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
auto* decl = e->As<ast::VariableDeclStatement>();
ASSERT_NE(decl->variable->constructor, nullptr);
ASSERT_NE(decl->variable->initializer, nullptr);
ASSERT_TRUE(decl->variable->constructor->Is<ast::BinaryExpression>());
auto* expr = decl->variable->constructor->As<ast::BinaryExpression>();
ASSERT_TRUE(decl->variable->initializer->Is<ast::BinaryExpression>());
auto* expr = decl->variable->initializer->As<ast::BinaryExpression>();
EXPECT_EQ(expr->op, ast::BinaryOp::kAdd);
ASSERT_TRUE(expr->lhs->Is<ast::IdentifierExpression>());
@@ -189,7 +189,7 @@ TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) {
EXPECT_EQ(p->error(), "1:13: expected '=' for 'let' declaration");
}
TEST_F(ParserImplTest, VariableStmt_Let_MissingConstructor) {
TEST_F(ParserImplTest, VariableStmt_Let_MissingInitializer) {
auto p = parser("let a : i32 =");
auto e = p->variable_statement();
EXPECT_FALSE(e.matched);
@@ -199,7 +199,7 @@ TEST_F(ParserImplTest, VariableStmt_Let_MissingConstructor) {
EXPECT_EQ(p->error(), "1:14: missing initializer for 'let' declaration");
}
TEST_F(ParserImplTest, VariableStmt_Let_InvalidConstructor) {
TEST_F(ParserImplTest, VariableStmt_Let_InvalidInitializer) {
auto p = parser("let a : i32 = if (a) {}");
auto e = p->variable_statement();
EXPECT_FALSE(e.matched);

View File

@@ -94,7 +94,7 @@ class WhileStmtErrorTest : public ParserImplTest {
// Test a while loop with missing left parenthesis is invalid.
TEST_F(WhileStmtErrorTest, MissingLeftParen) {
std::string while_str = "while bool) { }";
std::string error_str = "1:11: expected '(' for type constructor";
std::string error_str = "1:11: expected '(' for type initializer";
TestWhileWithError(while_str, error_str);
}