Update initializer names.
This Cl updates the names of the initializer expressions to be clearer.
* InitializerExpression -> ConstructorExpression
* ConstInitializerExpression -> ScalarConstructorExpression
* TypeInitializerExpression -> TypeConstructorExpression
Bug: tint:26
Change-Id: Ib046497f589cc65d1d64bc172015588348feeffe
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18340
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc
index c288b9d..d7bbf89 100644
--- a/src/writer/wgsl/generator_impl.cc
+++ b/src/writer/wgsl/generator_impl.cc
@@ -27,14 +27,13 @@
#include "src/ast/call_expression.h"
#include "src/ast/case_statement.h"
#include "src/ast/cast_expression.h"
-#include "src/ast/const_initializer_expression.h"
+#include "src/ast/constructor_expression.h"
#include "src/ast/continue_statement.h"
#include "src/ast/decorated_variable.h"
#include "src/ast/else_statement.h"
#include "src/ast/float_literal.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/if_statement.h"
-#include "src/ast/initializer_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/location_decoration.h"
#include "src/ast/loop_statement.h"
@@ -42,6 +41,7 @@
#include "src/ast/regardless_statement.h"
#include "src/ast/relational_expression.h"
#include "src/ast/return_statement.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/set_decoration.h"
#include "src/ast/statement.h"
#include "src/ast/struct.h"
@@ -53,7 +53,7 @@
#include "src/ast/type/pointer_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/vector_type.h"
-#include "src/ast/type_initializer_expression.h"
+#include "src/ast/type_constructor_expression.h"
#include "src/ast/uint_literal.h"
#include "src/ast/unary_derivative_expression.h"
#include "src/ast/unary_method_expression.h"
@@ -158,8 +158,8 @@
if (expr->IsIdentifier()) {
return EmitIdentifier(expr->AsIdentifier());
}
- if (expr->IsInitializer()) {
- return EmitInitializer(expr->AsInitializer());
+ if (expr->IsConstructor()) {
+ return EmitConstructor(expr->AsConstructor());
}
if (expr->IsMemberAccessor()) {
return EmitMemberAccessor(expr->AsMemberAccessor());
@@ -259,14 +259,14 @@
return true;
}
-bool GeneratorImpl::EmitInitializer(ast::InitializerExpression* expr) {
- if (expr->IsConstInitializer()) {
- return EmitConstInitializer(expr->AsConstInitializer());
+bool GeneratorImpl::EmitConstructor(ast::ConstructorExpression* expr) {
+ if (expr->IsScalarConstructor()) {
+ return EmitScalarConstructor(expr->AsScalarConstructor());
}
- return EmitTypeInitializer(expr->AsTypeInitializer());
+ return EmitTypeConstructor(expr->AsTypeConstructor());
}
-bool GeneratorImpl::EmitTypeInitializer(ast::TypeInitializerExpression* expr) {
+bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) {
if (!EmitType(expr->type())) {
return false;
}
@@ -289,8 +289,8 @@
return true;
}
-bool GeneratorImpl::EmitConstInitializer(
- ast::ConstInitializerExpression* expr) {
+bool GeneratorImpl::EmitScalarConstructor(
+ ast::ScalarConstructorExpression* expr) {
return EmitLiteral(expr->literal());
}
@@ -480,9 +480,9 @@
return false;
}
- if (var->initializer() != nullptr) {
+ if (var->constructor() != nullptr) {
out_ << " = ";
- if (!EmitExpression(var->initializer())) {
+ if (!EmitExpression(var->constructor())) {
return false;
}
}
diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h
index 8ec4572..d8b26b3 100644
--- a/src/writer/wgsl/generator_impl.h
+++ b/src/writer/wgsl/generator_impl.h
@@ -21,15 +21,15 @@
#include <vector>
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/const_initializer_expression.h"
+#include "src/ast/constructor_expression.h"
#include "src/ast/entry_point.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/import.h"
-#include "src/ast/initializer_expression.h"
#include "src/ast/module.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/alias_type.h"
#include "src/ast/type/type.h"
-#include "src/ast/type_initializer_expression.h"
+#include "src/ast/type_constructor_expression.h"
#include "src/ast/variable.h"
namespace tint {
@@ -100,10 +100,10 @@
/// @param expr the cast expression
/// @returns true if the cast was emitted
bool EmitCast(ast::CastExpression* expr);
- /// Handles generating a const initializer
- /// @param expr the const initializer expression
- /// @returns true if the initializer is emitted
- bool EmitConstInitializer(ast::ConstInitializerExpression* expr);
+ /// Handles generating a scalar constructor
+ /// @param expr the scalar constructor expression
+ /// @returns true if the scalar constructor is emitted
+ bool EmitScalarConstructor(ast::ScalarConstructorExpression* expr);
/// Handles a continue statement
/// @param stmt the statement to emit
/// @returns true if the statement was emitted successfully
@@ -140,10 +140,10 @@
/// @param import the import to generate
/// @returns true if the import was emitted
bool EmitImport(const ast::Import* import);
- /// Handles generating initializer expressions
- /// @param expr the initializer expression
+ /// Handles generating constructor expressions
+ /// @param expr the constructor expression
/// @returns true if the expression was emitted
- bool EmitInitializer(ast::InitializerExpression* expr);
+ bool EmitConstructor(ast::ConstructorExpression* expr);
/// Handles generating a kill statement
/// @param stmt the kill statement
/// @returns true if the statement was successfully emitted
@@ -198,10 +198,10 @@
/// @param type the type to generate
/// @returns true if the type is emitted
bool EmitType(ast::type::Type* type);
- /// Handles emitting a type initializer
- /// @param expr the type initializer expression
- /// @returns true if the initializer is emitted
- bool EmitTypeInitializer(ast::TypeInitializerExpression* expr);
+ /// Handles emitting a type constructor
+ /// @param expr the type constructor expression
+ /// @returns true if the constructor is emitted
+ bool EmitTypeConstructor(ast::TypeConstructorExpression* expr);
/// Handles a unary derivative expression
/// @param expr the expression to emit
/// @returns true if the expression was emitted
diff --git a/src/writer/wgsl/generator_impl_array_accessor_test.cc b/src/writer/wgsl/generator_impl_array_accessor_test.cc
index 4fd4c9d..437fcba 100644
--- a/src/writer/wgsl/generator_impl_array_accessor_test.cc
+++ b/src/writer/wgsl/generator_impl_array_accessor_test.cc
@@ -16,9 +16,9 @@
#include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/int_literal.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/i32_type.h"
#include "src/writer/wgsl/generator_impl.h"
@@ -32,7 +32,7 @@
TEST_F(GeneratorImplTest, EmitExpression_ArrayAccessor) {
ast::type::I32Type i32;
auto lit = std::make_unique<ast::IntLiteral>(&i32, 5);
- auto idx = std::make_unique<ast::ConstInitializerExpression>(std::move(lit));
+ auto idx = std::make_unique<ast::ScalarConstructorExpression>(std::move(lit));
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
diff --git a/src/writer/wgsl/generator_impl_initializer_test.cc b/src/writer/wgsl/generator_impl_constructor_test.cc
similarity index 62%
rename from src/writer/wgsl/generator_impl_initializer_test.cc
rename to src/writer/wgsl/generator_impl_constructor_test.cc
index 44ae88a..4b3cd9a 100644
--- a/src/writer/wgsl/generator_impl_initializer_test.cc
+++ b/src/writer/wgsl/generator_impl_constructor_test.cc
@@ -17,9 +17,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/int_literal.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h"
@@ -37,107 +37,107 @@
using GeneratorImplTest = testing::Test;
-TEST_F(GeneratorImplTest, EmitInitializer_Bool) {
+TEST_F(GeneratorImplTest, EmitConstructor_Bool) {
ast::type::BoolType bool_type;
auto lit = std::make_unique<ast::BoolLiteral>(&bool_type, false);
- ast::ConstInitializerExpression expr(std::move(lit));
+ ast::ScalarConstructorExpression expr(std::move(lit));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "false");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Int) {
+TEST_F(GeneratorImplTest, EmitConstructor_Int) {
ast::type::I32Type i32;
auto lit = std::make_unique<ast::IntLiteral>(&i32, -12345);
- ast::ConstInitializerExpression expr(std::move(lit));
+ ast::ScalarConstructorExpression expr(std::move(lit));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "-12345");
}
-TEST_F(GeneratorImplTest, EmitInitializer_UInt) {
+TEST_F(GeneratorImplTest, EmitConstructor_UInt) {
ast::type::U32Type u32;
auto lit = std::make_unique<ast::UintLiteral>(&u32, 56779);
- ast::ConstInitializerExpression expr(std::move(lit));
+ ast::ScalarConstructorExpression expr(std::move(lit));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "56779u");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Float) {
+TEST_F(GeneratorImplTest, EmitConstructor_Float) {
ast::type::F32Type f32;
auto lit = std::make_unique<ast::FloatLiteral>(&f32, 1.5e27);
- ast::ConstInitializerExpression expr(std::move(lit));
+ ast::ScalarConstructorExpression expr(std::move(lit));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "1.49999995e+27");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Type_Float) {
+TEST_F(GeneratorImplTest, EmitConstructor_Type_Float) {
ast::type::F32Type f32;
auto lit = std::make_unique<ast::FloatLiteral>(&f32, -1.2e-5);
std::vector<std::unique_ptr<ast::Expression>> values;
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
- ast::TypeInitializerExpression expr(&f32, std::move(values));
+ ast::TypeConstructorExpression expr(&f32, std::move(values));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "f32(-1.20000004e-05)");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Type_Bool) {
+TEST_F(GeneratorImplTest, EmitConstructor_Type_Bool) {
ast::type::BoolType b;
auto lit = std::make_unique<ast::BoolLiteral>(&b, true);
std::vector<std::unique_ptr<ast::Expression>> values;
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
- ast::TypeInitializerExpression expr(&b, std::move(values));
+ ast::TypeConstructorExpression expr(&b, std::move(values));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "bool(true)");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Type_Int) {
+TEST_F(GeneratorImplTest, EmitConstructor_Type_Int) {
ast::type::I32Type i32;
auto lit = std::make_unique<ast::IntLiteral>(&i32, -12345);
std::vector<std::unique_ptr<ast::Expression>> values;
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
- ast::TypeInitializerExpression expr(&i32, std::move(values));
+ ast::TypeConstructorExpression expr(&i32, std::move(values));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "i32(-12345)");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Type_Uint) {
+TEST_F(GeneratorImplTest, EmitConstructor_Type_Uint) {
ast::type::U32Type u32;
auto lit = std::make_unique<ast::UintLiteral>(&u32, 12345);
std::vector<std::unique_ptr<ast::Expression>> values;
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
- ast::TypeInitializerExpression expr(&u32, std::move(values));
+ ast::TypeConstructorExpression expr(&u32, std::move(values));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "u32(12345u)");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Type_Vec) {
+TEST_F(GeneratorImplTest, EmitConstructor_Type_Vec) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
@@ -146,20 +146,20 @@
auto lit3 = std::make_unique<ast::FloatLiteral>(&f32, 3.f);
std::vector<std::unique_ptr<ast::Expression>> values;
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit1)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit2)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit3)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit3)));
- ast::TypeInitializerExpression expr(&vec, std::move(values));
+ ast::TypeConstructorExpression expr(&vec, std::move(values));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), "vec3<f32>(1.00000000, 2.00000000, 3.00000000)");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Type_Mat) {
+TEST_F(GeneratorImplTest, EmitConstructor_Type_Mat) {
ast::type::F32Type f32;
ast::type::MatrixType mat(&f32, 3, 2);
@@ -173,25 +173,25 @@
std::vector<std::unique_ptr<ast::Expression>> values;
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit1)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit2)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
- mat_values.push_back(std::make_unique<ast::TypeInitializerExpression>(
+ mat_values.push_back(std::make_unique<ast::TypeConstructorExpression>(
&vec, std::move(values)));
}
- ast::TypeInitializerExpression expr(&mat, std::move(mat_values));
+ ast::TypeConstructorExpression expr(&mat, std::move(mat_values));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(),
std::string("mat2x3<f32>(vec2<f32>(1.00000000, 2.00000000), ") +
"vec2<f32>(3.00000000, 4.00000000), " +
"vec2<f32>(5.00000000, 6.00000000))");
}
-TEST_F(GeneratorImplTest, EmitInitializer_Type_Array) {
+TEST_F(GeneratorImplTest, EmitConstructor_Type_Array) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
ast::type::ArrayType ary(&vec, 3);
@@ -205,20 +205,20 @@
std::vector<std::unique_ptr<ast::Expression>> values;
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit1)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1)));
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit2)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(
- std::make_unique<ast::ConstInitializerExpression>(std::move(lit3)));
+ std::make_unique<ast::ScalarConstructorExpression>(std::move(lit3)));
- ary_values.push_back(std::make_unique<ast::TypeInitializerExpression>(
+ ary_values.push_back(std::make_unique<ast::TypeConstructorExpression>(
&vec, std::move(values)));
}
- ast::TypeInitializerExpression expr(&ary, std::move(ary_values));
+ ast::TypeConstructorExpression expr(&ary, std::move(ary_values));
GeneratorImpl g;
- ASSERT_TRUE(g.EmitInitializer(&expr)) << g.error();
+ ASSERT_TRUE(g.EmitConstructor(&expr)) << g.error();
EXPECT_EQ(g.result(), std::string("array<vec3<f32>, 3>(") +
"vec3<f32>(1.00000000, 2.00000000, 3.00000000), " +
"vec3<f32>(4.00000000, 5.00000000, 6.00000000), " +
diff --git a/src/writer/wgsl/generator_impl_variable_test.cc b/src/writer/wgsl/generator_impl_variable_test.cc
index 06463e8..dce656a 100644
--- a/src/writer/wgsl/generator_impl_variable_test.cc
+++ b/src/writer/wgsl/generator_impl_variable_test.cc
@@ -91,12 +91,12 @@
)");
}
-TEST_F(GeneratorImplTest, EmitVariable_Initializer) {
+TEST_F(GeneratorImplTest, EmitVariable_Constructor) {
auto ident = std::make_unique<ast::IdentifierExpression>("initializer");
ast::type::F32Type f32;
ast::Variable v("a", ast::StorageClass::kNone, &f32);
- v.set_initializer(std::move(ident));
+ v.set_constructor(std::move(ident));
GeneratorImpl g;
ASSERT_TRUE(g.EmitVariable(&v)) << g.error();
@@ -109,7 +109,7 @@
ast::type::F32Type f32;
ast::Variable v("a", ast::StorageClass::kNone, &f32);
- v.set_initializer(std::move(ident));
+ v.set_constructor(std::move(ident));
v.set_is_const(true);
GeneratorImpl g;