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/CMakeLists.txt b/src/CMakeLists.txt
index 1f2c161..dc4328e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -59,8 +59,8 @@
ast/case_statement.h
ast/cast_expression.cc
ast/cast_expression.h
- ast/const_initializer_expression.cc
- ast/const_initializer_expression.h
+ ast/constructor_expression.cc
+ ast/constructor_expression.h
ast/continue_statement.cc
ast/continue_statement.h
ast/decorated_variable.cc
@@ -85,8 +85,6 @@
ast/if_statement.h
ast/import.cc
ast/import.h
- ast/initializer_expression.cc
- ast/initializer_expression.h
ast/int_literal.cc
ast/int_literal.h
ast/kill_statement.cc
@@ -113,6 +111,8 @@
ast/relational_expression.h
ast/return_statement.cc
ast/return_statement.h
+ ast/scalar_constructor_expression.cc
+ ast/scalar_constructor_expression.h
ast/set_decoration.cc
ast/set_decoration.h
ast/statement.cc
@@ -133,8 +133,8 @@
ast/struct_member_offset_decoration.h
ast/switch_statement.cc
ast/switch_statement.h
- ast/type_initializer_expression.h
- ast/type_initializer_expression.cc
+ ast/type_constructor_expression.h
+ ast/type_constructor_expression.cc
ast/type/alias_type.cc
ast/type/alias_type.h
ast/type/array_type.cc
@@ -260,7 +260,6 @@
ast/call_expression_test.cc
ast/case_statement_test.cc
ast/cast_expression_test.cc
- ast/const_initializer_expression_test.cc
ast/continue_statement_test.cc
ast/decorated_variable_test.cc
ast/else_statement_test.cc
@@ -281,6 +280,7 @@
ast/regardless_statement_test.cc
ast/relational_expression_test.cc
ast/return_statement_test.cc
+ ast/scalar_constructor_expression_test.cc
ast/set_decoration_test.cc
ast/struct_member_test.cc
ast/struct_member_offset_decoration_test.cc
@@ -296,7 +296,7 @@
ast/type/struct_type_test.cc
ast/type/u32_type_test.cc
ast/type/vector_type_test.cc
- ast/type_initializer_expression_test.cc
+ ast/type_constructor_expression_test.cc
ast/uint_literal_test.cc
ast/unary_derivative_expression_test.cc
ast/unary_method_expression_test.cc
@@ -410,10 +410,10 @@
if(${TINT_BUILD_SPV_WRITER})
list(APPEND TINT_TEST_SRCS
writer/spirv/binary_writer_test.cc
+ writer/spirv/builder_constructor_expression_test.cc
writer/spirv/builder_entry_point_test.cc
writer/spirv/builder_function_test.cc
writer/spirv/builder_global_variable_test.cc
- writer/spirv/builder_initializer_expression_test.cc
writer/spirv/builder_literal_test.cc
writer/spirv/builder_return_test.cc
writer/spirv/builder_test.cc
@@ -436,6 +436,7 @@
writer/wgsl/generator_impl_call_test.cc
writer/wgsl/generator_impl_case_test.cc
writer/wgsl/generator_impl_cast_test.cc
+ writer/wgsl/generator_impl_constructor_test.cc
writer/wgsl/generator_impl_continue_test.cc
writer/wgsl/generator_impl_else_test.cc
writer/wgsl/generator_impl_entry_point_test.cc
@@ -444,7 +445,6 @@
writer/wgsl/generator_impl_identifier_test.cc
writer/wgsl/generator_impl_if_test.cc
writer/wgsl/generator_impl_import_test.cc
- writer/wgsl/generator_impl_initializer_test.cc
writer/wgsl/generator_impl_kill_test.cc
writer/wgsl/generator_impl_loop_test.cc
writer/wgsl/generator_impl_member_accessor_test.cc
diff --git a/src/ast/array_accessor_expression.h b/src/ast/array_accessor_expression.h
index 5988085..73a866e 100644
--- a/src/ast/array_accessor_expression.h
+++ b/src/ast/array_accessor_expression.h
@@ -35,7 +35,7 @@
ArrayAccessorExpression(std::unique_ptr<Expression> array,
std::unique_ptr<Expression> idx_expr);
/// Constructor
- /// @param source the initializer source
+ /// @param source the array accessor source
/// @param array the array
/// @param idx_expr the index expression
ArrayAccessorExpression(const Source& source,
diff --git a/src/ast/as_expression.h b/src/ast/as_expression.h
index 0a7649b..e2d1cc1 100644
--- a/src/ast/as_expression.h
+++ b/src/ast/as_expression.h
@@ -36,7 +36,7 @@
/// @param expr the expr
AsExpression(type::Type* type, std::unique_ptr<Expression> expr);
/// Constructor
- /// @param source the initializer source
+ /// @param source the as expression source
/// @param type the type
/// @param expr the expr
AsExpression(const Source& source,
diff --git a/src/ast/assignment_statement.h b/src/ast/assignment_statement.h
index 4f6e6b8..c49472c 100644
--- a/src/ast/assignment_statement.h
+++ b/src/ast/assignment_statement.h
@@ -36,7 +36,7 @@
AssignmentStatement(std::unique_ptr<Expression> lhs,
std::unique_ptr<Expression> rhs);
/// Constructor
- /// @param source the initializer source
+ /// @param source the assignment statement source
/// @param lhs the left side of the expression
/// @param rhs the right side of the expression
AssignmentStatement(const Source& source,
diff --git a/src/ast/break_statement.h b/src/ast/break_statement.h
index aaa8526..298933c 100644
--- a/src/ast/break_statement.h
+++ b/src/ast/break_statement.h
@@ -31,7 +31,7 @@
/// Constructor
BreakStatement();
/// Constructor
- /// @param source the initializer source
+ /// @param source the break statement source
explicit BreakStatement(const Source& source);
/// Constructor
/// @param condition the condition type
@@ -39,7 +39,7 @@
BreakStatement(StatementCondition condition,
std::unique_ptr<Expression> conditional);
/// Constructor
- /// @param source the initializer source
+ /// @param source the break statement source
/// @param condition the condition type
/// @param conditional the condition expression
BreakStatement(const Source& source,
diff --git a/src/ast/call_expression.h b/src/ast/call_expression.h
index 0644d69..56df9b9 100644
--- a/src/ast/call_expression.h
+++ b/src/ast/call_expression.h
@@ -36,7 +36,7 @@
CallExpression(std::unique_ptr<Expression> func,
std::vector<std::unique_ptr<Expression>> params);
/// Constructor
- /// @param source the initializer source
+ /// @param source the call expression source
/// @param func the function
/// @param params the parameters
CallExpression(const Source& source,
diff --git a/src/ast/cast_expression.h b/src/ast/cast_expression.h
index 0deb715..52966a2 100644
--- a/src/ast/cast_expression.h
+++ b/src/ast/cast_expression.h
@@ -36,7 +36,7 @@
/// @param expr the expr
CastExpression(type::Type* type, std::unique_ptr<Expression> expr);
/// Constructor
- /// @param source the initializer source
+ /// @param source the cast expression source
/// @param type the type
/// @param expr the expr
CastExpression(const Source& source,
diff --git a/src/ast/const_initializer_expression.cc b/src/ast/const_initializer_expression.cc
deleted file mode 100644
index 101bb75..0000000
--- a/src/ast/const_initializer_expression.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2020 The Tint Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "src/ast/const_initializer_expression.h"
-
-namespace tint {
-namespace ast {
-
-ConstInitializerExpression::ConstInitializerExpression()
- : InitializerExpression() {}
-
-ConstInitializerExpression::ConstInitializerExpression(
- std::unique_ptr<Literal> literal)
- : InitializerExpression(), literal_(std::move(literal)) {}
-
-ConstInitializerExpression::ConstInitializerExpression(
- const Source& source,
- std::unique_ptr<Literal> litearl)
- : InitializerExpression(source), literal_(std::move(litearl)) {}
-
-ConstInitializerExpression::~ConstInitializerExpression() = default;
-
-bool ConstInitializerExpression::IsValid() const {
- return literal_ != nullptr;
-}
-
-void ConstInitializerExpression::to_str(std::ostream& out,
- size_t indent) const {
- make_indent(out, indent);
- out << "ConstInitializer{" << literal_->to_str() << "}" << std::endl;
-}
-
-} // namespace ast
-} // namespace tint
diff --git a/src/ast/constructor_expression.cc b/src/ast/constructor_expression.cc
new file mode 100644
index 0000000..9ff88b4
--- /dev/null
+++ b/src/ast/constructor_expression.cc
@@ -0,0 +1,43 @@
+// Copyright 2020 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/ast/constructor_expression.h"
+
+#include <assert.h>
+
+#include "src/ast/scalar_constructor_expression.h"
+#include "src/ast/type_constructor_expression.h"
+
+namespace tint {
+namespace ast {
+
+ConstructorExpression::ConstructorExpression() = default;
+
+ConstructorExpression::~ConstructorExpression() = default;
+
+ConstructorExpression::ConstructorExpression(const Source& source)
+ : Expression(source) {}
+
+ScalarConstructorExpression* ConstructorExpression::AsScalarConstructor() {
+ assert(IsScalarConstructor());
+ return static_cast<ScalarConstructorExpression*>(this);
+}
+
+TypeConstructorExpression* ConstructorExpression::AsTypeConstructor() {
+ assert(IsTypeConstructor());
+ return static_cast<TypeConstructorExpression*>(this);
+}
+
+} // namespace ast
+} // namespace tint
diff --git a/src/ast/constructor_expression.h b/src/ast/constructor_expression.h
new file mode 100644
index 0000000..6846768
--- /dev/null
+++ b/src/ast/constructor_expression.h
@@ -0,0 +1,60 @@
+// Copyright 2020 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_AST_CONSTRUCTOR_EXPRESSION_H_
+#define SRC_AST_CONSTRUCTOR_EXPRESSION_H_
+
+#include "src/ast/expression.h"
+
+namespace tint {
+namespace ast {
+
+class ScalarConstructorExpression;
+class TypeConstructorExpression;
+
+/// Base class for constructor style expressions
+class ConstructorExpression : public Expression {
+ public:
+ ~ConstructorExpression() override;
+
+ /// @returns true if this is an constructor expression
+ bool IsConstructor() const override { return true; }
+
+ /// @returns true if this is a scalar constructor
+ virtual bool IsScalarConstructor() const { return false; }
+ /// @returns true if this is a type constructor
+ virtual bool IsTypeConstructor() const { return false; }
+
+ /// @returns this as a scalar constructor expression
+ ScalarConstructorExpression* AsScalarConstructor();
+ /// @returns this as a type constructor expression
+ TypeConstructorExpression* AsTypeConstructor();
+
+ protected:
+ /// Constructor
+ ConstructorExpression();
+ /// Constructor
+ /// @param source the constructor source
+ explicit ConstructorExpression(const Source& source);
+ /// Move constructor
+ ConstructorExpression(ConstructorExpression&&) = default;
+
+ private:
+ ConstructorExpression(const ConstructorExpression&) = delete;
+};
+
+} // namespace ast
+} // namespace tint
+
+#endif // SRC_AST_CONSTRUCTOR_EXPRESSION_H_
diff --git a/src/ast/continue_statement.h b/src/ast/continue_statement.h
index 26789f9..69aaaa6 100644
--- a/src/ast/continue_statement.h
+++ b/src/ast/continue_statement.h
@@ -31,7 +31,7 @@
/// Constructor
ContinueStatement();
/// Constructor
- /// @param source the initializer source
+ /// @param source the continue statement source
explicit ContinueStatement(const Source& source);
/// Constructor
/// @param condition the condition type
@@ -39,7 +39,7 @@
ContinueStatement(StatementCondition condition,
std::unique_ptr<Expression> conditional);
/// Constructor
- /// @param source the initializer source
+ /// @param source the continue statement source
/// @param condition the condition type
/// @param conditional the condition expression
ContinueStatement(const Source& source,
diff --git a/src/ast/decorated_variable.cc b/src/ast/decorated_variable.cc
index 038aaed..d5fc6cc 100644
--- a/src/ast/decorated_variable.cc
+++ b/src/ast/decorated_variable.cc
@@ -45,7 +45,7 @@
out << "}" << std::endl;
info_to_str(out, indent + 2);
- initializer_to_str(out, indent + 2);
+ constructor_to_str(out, indent + 2);
make_indent(out, indent);
out << "}" << std::endl;
}
diff --git a/src/ast/decorated_variable_test.cc b/src/ast/decorated_variable_test.cc
index fd4ad62..6d96f8e 100644
--- a/src/ast/decorated_variable_test.cc
+++ b/src/ast/decorated_variable_test.cc
@@ -70,7 +70,7 @@
type::F32Type t;
auto var = std::make_unique<Variable>("my_var", StorageClass::kFunction, &t);
DecoratedVariable dv(std::move(var));
- dv.set_initializer(std::make_unique<IdentifierExpression>("expr"));
+ dv.set_constructor(std::make_unique<IdentifierExpression>("expr"));
std::vector<std::unique_ptr<VariableDecoration>> decos;
decos.push_back(std::make_unique<BindingDecoration>(2));
diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc
index 3e1aadc..8e5143d 100644
--- a/src/ast/else_statement_test.cc
+++ b/src/ast/else_statement_test.cc
@@ -16,9 +16,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/if_statement.h"
#include "src/ast/nop_statement.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/bool_type.h"
namespace tint {
@@ -29,7 +29,7 @@
TEST_F(ElseStatementTest, Creation) {
ast::type::BoolType bool_type;
- auto cond = std::make_unique<ConstInitializerExpression>(
+ auto cond = std::make_unique<ScalarConstructorExpression>(
std::make_unique<BoolLiteral>(&bool_type, true));
std::vector<std::unique_ptr<Statement>> body;
body.push_back(std::make_unique<NopStatement>());
@@ -57,7 +57,7 @@
TEST_F(ElseStatementTest, HasCondition) {
ast::type::BoolType bool_type;
- auto cond = std::make_unique<ConstInitializerExpression>(
+ auto cond = std::make_unique<ScalarConstructorExpression>(
std::make_unique<BoolLiteral>(&bool_type, true));
ElseStatement e(std::move(cond), {});
EXPECT_TRUE(e.HasCondition());
@@ -91,7 +91,7 @@
}
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
- auto cond = std::make_unique<ConstInitializerExpression>();
+ auto cond = std::make_unique<ScalarConstructorExpression>();
ElseStatement e(std::move(cond), {});
EXPECT_FALSE(e.IsValid());
}
@@ -106,7 +106,7 @@
TEST_F(ElseStatementTest, ToStr) {
ast::type::BoolType bool_type;
- auto cond = std::make_unique<ConstInitializerExpression>(
+ auto cond = std::make_unique<ScalarConstructorExpression>(
std::make_unique<BoolLiteral>(&bool_type, true));
std::vector<std::unique_ptr<Statement>> body;
body.push_back(std::make_unique<NopStatement>());
@@ -116,7 +116,7 @@
e.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Else{
(
- ConstInitializer{true}
+ ScalarConstructor{true}
)
{
Nop{}
diff --git a/src/ast/expression.cc b/src/ast/expression.cc
index 78041d6..08e536e 100644
--- a/src/ast/expression.cc
+++ b/src/ast/expression.cc
@@ -20,8 +20,8 @@
#include "src/ast/as_expression.h"
#include "src/ast/call_expression.h"
#include "src/ast/cast_expression.h"
+#include "src/ast/constructor_expression.h"
#include "src/ast/identifier_expression.h"
-#include "src/ast/initializer_expression.h"
#include "src/ast/member_accessor_expression.h"
#include "src/ast/relational_expression.h"
#include "src/ast/unary_derivative_expression.h"
@@ -62,9 +62,9 @@
return static_cast<IdentifierExpression*>(this);
}
-InitializerExpression* Expression::AsInitializer() {
- assert(IsInitializer());
- return static_cast<InitializerExpression*>(this);
+ConstructorExpression* Expression::AsConstructor() {
+ assert(IsConstructor());
+ return static_cast<ConstructorExpression*>(this);
}
MemberAccessorExpression* Expression::AsMemberAccessor() {
diff --git a/src/ast/expression.h b/src/ast/expression.h
index ebc694b..67ad3c9 100644
--- a/src/ast/expression.h
+++ b/src/ast/expression.h
@@ -25,7 +25,7 @@
class CallExpression;
class CastExpression;
class IdentifierExpression;
-class InitializerExpression;
+class ConstructorExpression;
class MemberAccessorExpression;
class RelationalExpression;
class UnaryDerivativeExpression;
@@ -47,8 +47,8 @@
virtual bool IsCast() const { return false; }
/// @returns true if this is an identifier expression
virtual bool IsIdentifier() const { return false; }
- /// @returns true if this is an initializer expression
- virtual bool IsInitializer() const { return false; }
+ /// @returns true if this is an constructor expression
+ virtual bool IsConstructor() const { return false; }
/// @returns true if this is a member accessor expression
virtual bool IsMemberAccessor() const { return false; }
/// @returns true if this is a relational expression
@@ -70,8 +70,8 @@
CastExpression* AsCast();
/// @returns the expression as an identifier
IdentifierExpression* AsIdentifier();
- /// @returns the expression as an initializer
- InitializerExpression* AsInitializer();
+ /// @returns the expression as an constructor
+ ConstructorExpression* AsConstructor();
/// @returns the expression as a member accessor
MemberAccessorExpression* AsMemberAccessor();
/// @returns the expression as a relational expression
diff --git a/src/ast/identifier_expression.h b/src/ast/identifier_expression.h
index 8efe83c..38adc73 100644
--- a/src/ast/identifier_expression.h
+++ b/src/ast/identifier_expression.h
@@ -39,7 +39,7 @@
/// @param name the name
explicit IdentifierExpression(std::vector<std::string> name);
/// Constructor
- /// @param source the initializer source
+ /// @param source the identifier expression source
/// @param name the name
IdentifierExpression(const Source& source, std::vector<std::string> name);
/// Move constructor
diff --git a/src/ast/initializer_expression.cc b/src/ast/initializer_expression.cc
deleted file mode 100644
index f28f3c3..0000000
--- a/src/ast/initializer_expression.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2020 The Tint Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "src/ast/initializer_expression.h"
-
-#include <assert.h>
-
-#include "src/ast/const_initializer_expression.h"
-#include "src/ast/type_initializer_expression.h"
-
-namespace tint {
-namespace ast {
-
-InitializerExpression::InitializerExpression() = default;
-
-InitializerExpression::~InitializerExpression() = default;
-
-InitializerExpression::InitializerExpression(const Source& source)
- : Expression(source) {}
-
-ConstInitializerExpression* InitializerExpression::AsConstInitializer() {
- assert(IsConstInitializer());
- return static_cast<ConstInitializerExpression*>(this);
-}
-
-TypeInitializerExpression* InitializerExpression::AsTypeInitializer() {
- assert(IsTypeInitializer());
- return static_cast<TypeInitializerExpression*>(this);
-}
-
-} // namespace ast
-} // namespace tint
diff --git a/src/ast/initializer_expression.h b/src/ast/initializer_expression.h
deleted file mode 100644
index 0067c20..0000000
--- a/src/ast/initializer_expression.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2020 The Tint Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef SRC_AST_INITIALIZER_EXPRESSION_H_
-#define SRC_AST_INITIALIZER_EXPRESSION_H_
-
-#include "src/ast/expression.h"
-
-namespace tint {
-namespace ast {
-
-class ConstInitializerExpression;
-class TypeInitializerExpression;
-
-/// Base class for initializer style expressions
-class InitializerExpression : public Expression {
- public:
- ~InitializerExpression() override;
-
- /// @returns true if this is an initializer expression
- bool IsInitializer() const override { return true; }
-
- /// @returns true if this is a constant initializer
- virtual bool IsConstInitializer() const { return false; }
- /// @returns true if this is a type initializer
- virtual bool IsTypeInitializer() const { return false; }
-
- /// @returns this as a const initializer expression
- ConstInitializerExpression* AsConstInitializer();
- /// @returns this as a type initializer expression
- TypeInitializerExpression* AsTypeInitializer();
-
- protected:
- /// Constructor
- InitializerExpression();
- /// Constructor
- /// @param source the initializer source
- explicit InitializerExpression(const Source& source);
- /// Move constructor
- InitializerExpression(InitializerExpression&&) = default;
-
- private:
- InitializerExpression(const InitializerExpression&) = delete;
-};
-
-} // namespace ast
-} // namespace tint
-
-#endif // SRC_AST_INITIALIZER_EXPRESSION_H_
diff --git a/src/ast/kill_statement.h b/src/ast/kill_statement.h
index 15bf061..bbb1040 100644
--- a/src/ast/kill_statement.h
+++ b/src/ast/kill_statement.h
@@ -26,7 +26,7 @@
/// Constructor
KillStatement();
/// Constructor
- /// @param source the initializer source
+ /// @param source the kill statement source
explicit KillStatement(const Source& source);
/// Move constructor
KillStatement(KillStatement&&) = default;
diff --git a/src/ast/loop_statement.h b/src/ast/loop_statement.h
index 73e8b7f..e7bd755 100644
--- a/src/ast/loop_statement.h
+++ b/src/ast/loop_statement.h
@@ -35,7 +35,7 @@
LoopStatement(std::vector<std::unique_ptr<Statement>> body,
std::vector<std::unique_ptr<Statement>> continuing);
/// Constructor
- /// @param source the initializer source
+ /// @param source the loop statement source
/// @param body the body statements
/// @param continuing the continuing statements
LoopStatement(const Source& source,
diff --git a/src/ast/member_accessor_expression.h b/src/ast/member_accessor_expression.h
index 996e3ae..b8e0dce 100644
--- a/src/ast/member_accessor_expression.h
+++ b/src/ast/member_accessor_expression.h
@@ -37,7 +37,7 @@
MemberAccessorExpression(std::unique_ptr<Expression> structure,
std::unique_ptr<IdentifierExpression> member);
/// Constructor
- /// @param source the initializer source
+ /// @param source the member accessor expression source
/// @param structure the structure
/// @param member the member
MemberAccessorExpression(const Source& source,
diff --git a/src/ast/nop_statement.h b/src/ast/nop_statement.h
index 6585728..551ba29 100644
--- a/src/ast/nop_statement.h
+++ b/src/ast/nop_statement.h
@@ -26,7 +26,7 @@
/// Constructor
NopStatement();
/// Constructor
- /// @param source the initializer source
+ /// @param source the nop statement source
explicit NopStatement(const Source& source);
/// Move constructor
NopStatement(NopStatement&&) = default;
diff --git a/src/ast/regardless_statement.h b/src/ast/regardless_statement.h
index cada546..06e2959 100644
--- a/src/ast/regardless_statement.h
+++ b/src/ast/regardless_statement.h
@@ -36,7 +36,7 @@
RegardlessStatement(std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body);
/// Constructor
- /// @param source the initializer source
+ /// @param source the regardless statement source
/// @param condition the condition expression
/// @param body the body statements
RegardlessStatement(const Source& source,
diff --git a/src/ast/relational_expression.h b/src/ast/relational_expression.h
index a35733d..d52afba 100644
--- a/src/ast/relational_expression.h
+++ b/src/ast/relational_expression.h
@@ -61,7 +61,7 @@
std::unique_ptr<Expression> lhs,
std::unique_ptr<Expression> rhs);
/// Constructor
- /// @param source the initializer source
+ /// @param source the relational expression source
/// @param relation the relation type
/// @param lhs the left side of the expression
/// @param rhs the right side of the expression
diff --git a/src/ast/return_statement.h b/src/ast/return_statement.h
index ada4844..216e964 100644
--- a/src/ast/return_statement.h
+++ b/src/ast/return_statement.h
@@ -36,7 +36,7 @@
/// @param value the return value
explicit ReturnStatement(std::unique_ptr<Expression> value);
/// Constructor
- /// @param source the initializer source
+ /// @param source the return statement source
/// @param value the return value
ReturnStatement(const Source& source, std::unique_ptr<Expression> value);
/// Move constructor
diff --git a/src/ast/scalar_constructor_expression.cc b/src/ast/scalar_constructor_expression.cc
new file mode 100644
index 0000000..7c8cd82
--- /dev/null
+++ b/src/ast/scalar_constructor_expression.cc
@@ -0,0 +1,45 @@
+// Copyright 2020 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/ast/scalar_constructor_expression.h"
+
+namespace tint {
+namespace ast {
+
+ScalarConstructorExpression::ScalarConstructorExpression()
+ : ConstructorExpression() {}
+
+ScalarConstructorExpression::ScalarConstructorExpression(
+ std::unique_ptr<Literal> literal)
+ : ConstructorExpression(), literal_(std::move(literal)) {}
+
+ScalarConstructorExpression::ScalarConstructorExpression(
+ const Source& source,
+ std::unique_ptr<Literal> litearl)
+ : ConstructorExpression(source), literal_(std::move(litearl)) {}
+
+ScalarConstructorExpression::~ScalarConstructorExpression() = default;
+
+bool ScalarConstructorExpression::IsValid() const {
+ return literal_ != nullptr;
+}
+
+void ScalarConstructorExpression::to_str(std::ostream& out,
+ size_t indent) const {
+ make_indent(out, indent);
+ out << "ScalarConstructor{" << literal_->to_str() << "}" << std::endl;
+}
+
+} // namespace ast
+} // namespace tint
diff --git a/src/ast/const_initializer_expression.h b/src/ast/scalar_constructor_expression.h
similarity index 63%
rename from src/ast/const_initializer_expression.h
rename to src/ast/scalar_constructor_expression.h
index 46af8f4..2f977ab 100644
--- a/src/ast/const_initializer_expression.h
+++ b/src/ast/scalar_constructor_expression.h
@@ -12,37 +12,37 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef SRC_AST_CONST_INITIALIZER_EXPRESSION_H_
-#define SRC_AST_CONST_INITIALIZER_EXPRESSION_H_
+#ifndef SRC_AST_SCALAR_CONSTRUCTOR_EXPRESSION_H_
+#define SRC_AST_SCALAR_CONSTRUCTOR_EXPRESSION_H_
#include <memory>
#include <utility>
-#include "src/ast/initializer_expression.h"
+#include "src/ast/constructor_expression.h"
#include "src/ast/literal.h"
namespace tint {
namespace ast {
-/// A constant initializer
-class ConstInitializerExpression : public InitializerExpression {
+/// A scalar constructor
+class ScalarConstructorExpression : public ConstructorExpression {
public:
/// Constructor
- ConstInitializerExpression();
+ ScalarConstructorExpression();
/// Constructor
/// @param literal the const literal
- explicit ConstInitializerExpression(std::unique_ptr<Literal> literal);
+ explicit ScalarConstructorExpression(std::unique_ptr<Literal> literal);
/// Constructor
- /// @param source the initializer source
+ /// @param source the constructor source
/// @param literal the const literal
- ConstInitializerExpression(const Source& source,
- std::unique_ptr<Literal> literal);
+ ScalarConstructorExpression(const Source& source,
+ std::unique_ptr<Literal> literal);
/// Move constructor
- ConstInitializerExpression(ConstInitializerExpression&&) = default;
- ~ConstInitializerExpression() override;
+ ScalarConstructorExpression(ScalarConstructorExpression&&) = default;
+ ~ScalarConstructorExpression() override;
- /// @returns true if this is a constant initializer
- bool IsConstInitializer() const override { return true; }
+ /// @returns true if this is a scalar constructor
+ bool IsScalarConstructor() const override { return true; }
/// Set the literal value
/// @param literal the literal
@@ -61,7 +61,7 @@
void to_str(std::ostream& out, size_t indent) const override;
private:
- ConstInitializerExpression(const ConstInitializerExpression&) = delete;
+ ScalarConstructorExpression(const ScalarConstructorExpression&) = delete;
std::unique_ptr<Literal> literal_;
};
@@ -69,4 +69,4 @@
} // namespace ast
} // namespace tint
-#endif // SRC_AST_CONST_INITIALIZER_EXPRESSION_H_
+#endif // SRC_AST_SCALAR_CONSTRUCTOR_EXPRESSION_H_
diff --git a/src/ast/const_initializer_expression_test.cc b/src/ast/scalar_constructor_expression_test.cc
similarity index 67%
rename from src/ast/const_initializer_expression_test.cc
rename to src/ast/scalar_constructor_expression_test.cc
index 243df54..817905d 100644
--- a/src/ast/const_initializer_expression_test.cc
+++ b/src/ast/scalar_constructor_expression_test.cc
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "src/ast/const_initializer_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
@@ -22,44 +22,44 @@
namespace ast {
namespace {
-using ConstInitializerExpressionTest = testing::Test;
+using ScalarConstructorExpressionTest = testing::Test;
-TEST_F(ConstInitializerExpressionTest, Creation) {
+TEST_F(ScalarConstructorExpressionTest, Creation) {
ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true);
auto b_ptr = b.get();
- ConstInitializerExpression c(std::move(b));
+ ScalarConstructorExpression c(std::move(b));
EXPECT_EQ(c.literal(), b_ptr);
}
-TEST_F(ConstInitializerExpressionTest, Creation_WithSource) {
+TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true);
- ConstInitializerExpression c(Source{20, 2}, std::move(b));
+ ScalarConstructorExpression c(Source{20, 2}, std::move(b));
auto src = c.source();
EXPECT_EQ(src.line, 20);
EXPECT_EQ(src.column, 2);
}
-TEST_F(ConstInitializerExpressionTest, IsValid) {
+TEST_F(ScalarConstructorExpressionTest, IsValid) {
ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true);
- ConstInitializerExpression c(std::move(b));
+ ScalarConstructorExpression c(std::move(b));
EXPECT_TRUE(c.IsValid());
}
-TEST_F(ConstInitializerExpressionTest, IsValid_MissingLiteral) {
- ConstInitializerExpression c;
+TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
+ ScalarConstructorExpression c;
EXPECT_FALSE(c.IsValid());
}
-TEST_F(ConstInitializerExpressionTest, ToStr) {
+TEST_F(ScalarConstructorExpressionTest, ToStr) {
ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true);
- ConstInitializerExpression c(std::move(b));
+ ScalarConstructorExpression c(std::move(b));
std::ostringstream out;
c.to_str(out, 2);
- EXPECT_EQ(out.str(), R"( ConstInitializer{true}
+ EXPECT_EQ(out.str(), R"( ScalarConstructor{true}
)");
}
diff --git a/src/ast/type_initializer_expression.cc b/src/ast/type_constructor_expression.cc
similarity index 69%
rename from src/ast/type_initializer_expression.cc
rename to src/ast/type_constructor_expression.cc
index 5b47387..4b33bbc 100644
--- a/src/ast/type_initializer_expression.cc
+++ b/src/ast/type_constructor_expression.cc
@@ -12,28 +12,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "src/ast/type_initializer_expression.h"
+#include "src/ast/type_constructor_expression.h"
namespace tint {
namespace ast {
-TypeInitializerExpression::TypeInitializerExpression()
- : InitializerExpression() {}
+TypeConstructorExpression::TypeConstructorExpression()
+ : ConstructorExpression() {}
-TypeInitializerExpression::TypeInitializerExpression(
+TypeConstructorExpression::TypeConstructorExpression(
type::Type* type,
std::vector<std::unique_ptr<Expression>> values)
- : InitializerExpression(), type_(type), values_(std::move(values)) {}
+ : ConstructorExpression(), type_(type), values_(std::move(values)) {}
-TypeInitializerExpression::TypeInitializerExpression(
+TypeConstructorExpression::TypeConstructorExpression(
const Source& source,
type::Type* type,
std::vector<std::unique_ptr<Expression>> values)
- : InitializerExpression(source), type_(type), values_(std::move(values)) {}
+ : ConstructorExpression(source), type_(type), values_(std::move(values)) {}
-TypeInitializerExpression::~TypeInitializerExpression() = default;
+TypeConstructorExpression::~TypeConstructorExpression() = default;
-bool TypeInitializerExpression::IsValid() const {
+bool TypeConstructorExpression::IsValid() const {
if (values_.empty()) {
return false;
}
@@ -48,9 +48,9 @@
return true;
}
-void TypeInitializerExpression::to_str(std::ostream& out, size_t indent) const {
+void TypeConstructorExpression::to_str(std::ostream& out, size_t indent) const {
make_indent(out, indent);
- out << "TypeInitializer{" << std::endl;
+ out << "TypeConstructor{" << std::endl;
make_indent(out, indent + 2);
out << type_->type_name() << std::endl;
diff --git a/src/ast/type_initializer_expression.h b/src/ast/type_constructor_expression.h
similarity index 72%
rename from src/ast/type_initializer_expression.h
rename to src/ast/type_constructor_expression.h
index 118eac4..fdc3941 100644
--- a/src/ast/type_initializer_expression.h
+++ b/src/ast/type_constructor_expression.h
@@ -12,42 +12,42 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef SRC_AST_TYPE_INITIALIZER_EXPRESSION_H_
-#define SRC_AST_TYPE_INITIALIZER_EXPRESSION_H_
+#ifndef SRC_AST_TYPE_CONSTRUCTOR_EXPRESSION_H_
+#define SRC_AST_TYPE_CONSTRUCTOR_EXPRESSION_H_
#include <memory>
#include <utility>
#include <vector>
-#include "src/ast/initializer_expression.h"
+#include "src/ast/constructor_expression.h"
#include "src/ast/type/type.h"
namespace tint {
namespace ast {
-/// A type specific initializer
-class TypeInitializerExpression : public InitializerExpression {
+/// A type specific constructor
+class TypeConstructorExpression : public ConstructorExpression {
public:
- TypeInitializerExpression();
+ TypeConstructorExpression();
/// Constructor
/// @param type the type
/// @param values the values
- explicit TypeInitializerExpression(
+ explicit TypeConstructorExpression(
type::Type* type,
std::vector<std::unique_ptr<Expression>> values);
/// Constructor
- /// @param source the initializer source
+ /// @param source the constructor source
/// @param type the type
- /// @param values the initializer values
- TypeInitializerExpression(const Source& source,
+ /// @param values the constructor values
+ TypeConstructorExpression(const Source& source,
type::Type* type,
std::vector<std::unique_ptr<Expression>> values);
/// Move constructor
- TypeInitializerExpression(TypeInitializerExpression&&) = default;
- ~TypeInitializerExpression() override;
+ TypeConstructorExpression(TypeConstructorExpression&&) = default;
+ ~TypeConstructorExpression() override;
- /// @returns true if this is a type initializer
- bool IsTypeInitializer() const override { return true; }
+ /// @returns true if this is a type constructor
+ bool IsTypeConstructor() const override { return true; }
/// Set the type
/// @param type the type
@@ -74,7 +74,7 @@
void to_str(std::ostream& out, size_t indent) const override;
private:
- TypeInitializerExpression(const TypeInitializerExpression&) = delete;
+ TypeConstructorExpression(const TypeConstructorExpression&) = delete;
type::Type* type_ = nullptr;
std::vector<std::unique_ptr<Expression>> values_;
@@ -83,4 +83,4 @@
} // namespace ast
} // namespace tint
-#endif // SRC_AST_TYPE_INITIALIZER_EXPRESSION_H_
+#endif // SRC_AST_TYPE_CONSTRUCTOR_EXPRESSION_H_
diff --git a/src/ast/type_initializer_expression_test.cc b/src/ast/type_constructor_expression_test.cc
similarity index 68%
rename from src/ast/type_initializer_expression_test.cc
rename to src/ast/type_constructor_expression_test.cc
index 80c5f98..4166995 100644
--- a/src/ast/type_initializer_expression_test.cc
+++ b/src/ast/type_constructor_expression_test.cc
@@ -12,11 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "src/ast/type_initializer_expression.h"
+#include "src/ast/type_constructor_expression.h"
+#include <memory>
#include <sstream>
+#include <vector>
#include "gtest/gtest.h"
+#include "src/ast/constructor_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/vector_type.h"
@@ -25,82 +28,82 @@
namespace ast {
namespace {
-using TypeInitializerExpressionTest = testing::Test;
+using TypeConstructorExpressionTest = testing::Test;
-TEST_F(TypeInitializerExpressionTest, Creation) {
+TEST_F(TypeConstructorExpressionTest, Creation) {
type::F32Type f32;
std::vector<std::unique_ptr<Expression>> expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
auto expr_ptr = expr[0].get();
- TypeInitializerExpression t(&f32, std::move(expr));
+ TypeConstructorExpression t(&f32, std::move(expr));
EXPECT_EQ(t.type(), &f32);
ASSERT_EQ(t.values().size(), 1);
EXPECT_EQ(t.values()[0].get(), expr_ptr);
}
-TEST_F(TypeInitializerExpressionTest, Creation_WithSource) {
+TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
type::F32Type f32;
std::vector<std::unique_ptr<Expression>> expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
- TypeInitializerExpression t(Source{20, 2}, &f32, std::move(expr));
+ TypeConstructorExpression t(Source{20, 2}, &f32, std::move(expr));
auto src = t.source();
EXPECT_EQ(src.line, 20);
EXPECT_EQ(src.column, 2);
}
-TEST_F(TypeInitializerExpressionTest, IsTypeInitializer) {
- TypeInitializerExpression t;
- EXPECT_TRUE(t.IsTypeInitializer());
+TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
+ TypeConstructorExpression t;
+ EXPECT_TRUE(t.IsTypeConstructor());
}
-TEST_F(TypeInitializerExpressionTest, IsValid) {
+TEST_F(TypeConstructorExpressionTest, IsValid) {
type::F32Type f32;
std::vector<std::unique_ptr<Expression>> expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
- TypeInitializerExpression t(&f32, std::move(expr));
+ TypeConstructorExpression t(&f32, std::move(expr));
EXPECT_TRUE(t.IsValid());
}
-TEST_F(TypeInitializerExpressionTest, IsValid_NullType) {
+TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
std::vector<std::unique_ptr<Expression>> expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
- TypeInitializerExpression t;
+ TypeConstructorExpression t;
t.set_values(std::move(expr));
EXPECT_FALSE(t.IsValid());
}
-TEST_F(TypeInitializerExpressionTest, IsValid_NullValue) {
+TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
type::F32Type f32;
std::vector<std::unique_ptr<Expression>> expr;
expr.push_back(std::make_unique<IdentifierExpression>("expr"));
expr.push_back(nullptr);
- TypeInitializerExpression t(&f32, std::move(expr));
+ TypeConstructorExpression t(&f32, std::move(expr));
EXPECT_FALSE(t.IsValid());
}
-TEST_F(TypeInitializerExpressionTest, IsValid_InvalidValue) {
+TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
type::F32Type f32;
std::vector<std::unique_ptr<Expression>> expr;
expr.push_back(std::make_unique<IdentifierExpression>(""));
- TypeInitializerExpression t(&f32, std::move(expr));
+ TypeConstructorExpression t(&f32, std::move(expr));
EXPECT_FALSE(t.IsValid());
}
-TEST_F(TypeInitializerExpressionTest, IsValid_EmptyValue) {
+TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) {
type::F32Type f32;
std::vector<std::unique_ptr<Expression>> expr;
- TypeInitializerExpression t(&f32, std::move(expr));
+ TypeConstructorExpression t(&f32, std::move(expr));
EXPECT_FALSE(t.IsValid());
}
-TEST_F(TypeInitializerExpressionTest, ToStr) {
+TEST_F(TypeConstructorExpressionTest, ToStr) {
type::F32Type f32;
type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<Expression>> expr;
@@ -108,10 +111,10 @@
expr.push_back(std::make_unique<IdentifierExpression>("expr_2"));
expr.push_back(std::make_unique<IdentifierExpression>("expr_3"));
- TypeInitializerExpression t(&vec, std::move(expr));
+ TypeConstructorExpression t(&vec, std::move(expr));
std::ostringstream out;
t.to_str(out, 2);
- EXPECT_EQ(out.str(), R"( TypeInitializer{
+ EXPECT_EQ(out.str(), R"( TypeConstructor{
__vec_3__f32
Identifier{expr_1}
Identifier{expr_2}
diff --git a/src/ast/unary_derivative_expression.h b/src/ast/unary_derivative_expression.h
index d8568f2..48d592a 100644
--- a/src/ast/unary_derivative_expression.h
+++ b/src/ast/unary_derivative_expression.h
@@ -39,7 +39,7 @@
DerivativeModifier mod,
std::unique_ptr<Expression> param);
/// Constructor
- /// @param source the initializer source
+ /// @param source the unary derivative expression source
/// @param op the op
/// @param mod the derivative modifier
/// @param param the param
diff --git a/src/ast/unary_method_expression.h b/src/ast/unary_method_expression.h
index def96cf..8e67471 100644
--- a/src/ast/unary_method_expression.h
+++ b/src/ast/unary_method_expression.h
@@ -37,7 +37,7 @@
UnaryMethodExpression(UnaryMethod op,
std::vector<std::unique_ptr<Expression>> params);
/// Constructor
- /// @param source the initializer source
+ /// @param source the unary method source
/// @param op the op
/// @param params the params
UnaryMethodExpression(const Source& source,
diff --git a/src/ast/unary_op_expression.h b/src/ast/unary_op_expression.h
index 934a95f..4b4ba3d 100644
--- a/src/ast/unary_op_expression.h
+++ b/src/ast/unary_op_expression.h
@@ -35,7 +35,7 @@
/// @param expr the expr
UnaryOpExpression(UnaryOp op, std::unique_ptr<Expression> expr);
/// Constructor
- /// @param source the initializer source
+ /// @param source the unary op expression source
/// @param op the op
/// @param expr the expr
UnaryOpExpression(const Source& source,
diff --git a/src/ast/unless_statement.h b/src/ast/unless_statement.h
index 718eded8d..26440b4 100644
--- a/src/ast/unless_statement.h
+++ b/src/ast/unless_statement.h
@@ -36,7 +36,7 @@
UnlessStatement(std::unique_ptr<Expression> condition,
std::vector<std::unique_ptr<Statement>> body);
/// Constructor
- /// @param source the initializer source
+ /// @param source the unless statement source
/// @param condition the condition expression
/// @param body the body statements
UnlessStatement(const Source& source,
diff --git a/src/ast/variable.cc b/src/ast/variable.cc
index 9b02998..33e6b79 100644
--- a/src/ast/variable.cc
+++ b/src/ast/variable.cc
@@ -44,7 +44,7 @@
if (type_ == nullptr) {
return false;
}
- if (initializer_ && !initializer_->IsValid()) {
+ if (constructor_ && !constructor_->IsValid()) {
return false;
}
return true;
@@ -59,14 +59,14 @@
out << type_->type_name() << std::endl;
}
-void Variable::initializer_to_str(std::ostream& out, size_t indent) const {
- if (initializer_ == nullptr)
+void Variable::constructor_to_str(std::ostream& out, size_t indent) const {
+ if (constructor_ == nullptr)
return;
make_indent(out, indent);
out << "{" << std::endl;
- initializer_->to_str(out, indent + 2);
+ constructor_->to_str(out, indent + 2);
make_indent(out, indent);
out << "}" << std::endl;
@@ -76,7 +76,7 @@
make_indent(out, indent);
out << "Variable{" << std::endl;
info_to_str(out, indent + 2);
- initializer_to_str(out, indent + 2);
+ constructor_to_str(out, indent + 2);
make_indent(out, indent);
out << "}" << std::endl;
}
diff --git a/src/ast/variable.h b/src/ast/variable.h
index 752296d..5a6c382 100644
--- a/src/ast/variable.h
+++ b/src/ast/variable.h
@@ -72,15 +72,15 @@
/// @returns the storage class
StorageClass storage_class() const { return storage_class_; }
- /// Sets the initializer
- /// @param expr the initializer expression
- void set_initializer(std::unique_ptr<Expression> expr) {
- initializer_ = std::move(expr);
+ /// Sets the constructor
+ /// @param expr the constructor expression
+ void set_constructor(std::unique_ptr<Expression> expr) {
+ constructor_ = std::move(expr);
}
- /// @returns the initializer expression or nullptr if none set
- Expression* initializer() const { return initializer_.get(); }
- /// @returns true if the variable has an initializer
- bool has_initializer() const { return initializer_ != nullptr; }
+ /// @returns the constructor expression or nullptr if none set
+ Expression* constructor() const { return constructor_.get(); }
+ /// @returns true if the variable has an constructor
+ bool has_constructor() const { return constructor_ != nullptr; }
/// Sets if the variable is constant
/// @param val the value to be set
@@ -107,10 +107,10 @@
/// @param out the stream to write to
/// @param indent number of spaces to indent the node when writing
void info_to_str(std::ostream& out, size_t indent) const;
- /// Output initializer for this variable.
+ /// Output constructor for this variable.
/// @param out the stream to write to
/// @param indent number of spaces to indent the node when writing
- void initializer_to_str(std::ostream& out, size_t indent) const;
+ void constructor_to_str(std::ostream& out, size_t indent) const;
private:
Variable(const Variable&) = delete;
@@ -119,7 +119,7 @@
std::string name_;
StorageClass storage_class_ = StorageClass::kNone;
type::Type* type_ = nullptr;
- std::unique_ptr<Expression> initializer_;
+ std::unique_ptr<Expression> constructor_;
};
} // namespace ast
diff --git a/src/ast/variable_statement.h b/src/ast/variable_statement.h
index 0464369..51d2b6e 100644
--- a/src/ast/variable_statement.h
+++ b/src/ast/variable_statement.h
@@ -34,7 +34,7 @@
/// @param variable the variable
explicit VariableStatement(std::unique_ptr<Variable> variable);
/// Constructor
- /// @param source the initializer source
+ /// @param source the variable statement source
/// @param variable the variable
VariableStatement(const Source& source, std::unique_ptr<Variable> variable);
/// Move constructor
diff --git a/src/ast/variable_test.cc b/src/ast/variable_test.cc
index 1a33e3f..1e4b72c 100644
--- a/src/ast/variable_test.cc
+++ b/src/ast/variable_test.cc
@@ -71,10 +71,10 @@
EXPECT_TRUE(v.IsValid());
}
-TEST_F(VariableTest, IsValid_WithInitializer) {
+TEST_F(VariableTest, IsValid_WithConstructor) {
type::I32Type t;
Variable v{"my_var", StorageClass::kNone, &t};
- v.set_initializer(std::make_unique<IdentifierExpression>("ident"));
+ v.set_constructor(std::make_unique<IdentifierExpression>("ident"));
EXPECT_TRUE(v.IsValid());
}
@@ -94,10 +94,10 @@
EXPECT_FALSE(v.IsValid());
}
-TEST_F(VariableTest, IsValid_InvalidInitializer) {
+TEST_F(VariableTest, IsValid_InvalidConstructor) {
type::I32Type t;
Variable v{"my_var", StorageClass::kNone, &t};
- v.set_initializer(std::make_unique<IdentifierExpression>(""));
+ v.set_constructor(std::make_unique<IdentifierExpression>(""));
EXPECT_FALSE(v.IsValid());
}
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index 70ed71f..ad795bb 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -25,7 +25,6 @@
#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/continue_statement.h"
#include "src/ast/decorated_variable.h"
#include "src/ast/else_statement.h"
@@ -40,6 +39,7 @@
#include "src/ast/nop_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_condition.h"
#include "src/ast/struct_member_offset_decoration.h"
@@ -55,7 +55,7 @@
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/ast/type/void_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.h"
#include "src/ast/unary_derivative_expression.h"
@@ -347,7 +347,7 @@
return nullptr;
}
- var->set_initializer(std::move(expr));
+ var->set_constructor(std::move(expr));
}
return var;
}
@@ -386,10 +386,10 @@
if (has_error())
return nullptr;
if (init == nullptr) {
- set_error(peek(), "error parsing constant initializer");
+ set_error(peek(), "error parsing scalar constructor");
return nullptr;
}
- var->set_initializer(std::move(init));
+ var->set_constructor(std::move(init));
return var;
}
@@ -1689,18 +1689,18 @@
return nullptr;
}
- auto initializer = logical_or_expression();
+ auto constructor = logical_or_expression();
if (has_error())
return nullptr;
- if (initializer == nullptr) {
- set_error(peek(), "missing initializer for const declaration");
+ if (constructor == nullptr) {
+ set_error(peek(), "missing constructor for const declaration");
return nullptr;
}
auto var = std::make_unique<ast::Variable>(source, name,
ast::StorageClass::kNone, type);
var->set_is_const(true);
- var->set_initializer(std::move(initializer));
+ var->set_constructor(std::move(constructor));
return std::make_unique<ast::VariableStatement>(source, std::move(var));
}
@@ -1714,14 +1714,14 @@
t = peek();
if (t.IsEqual()) {
next(); // Consume the peek
- auto initializer = logical_or_expression();
+ auto constructor = logical_or_expression();
if (has_error())
return nullptr;
- if (initializer == nullptr) {
- set_error(peek(), "missing initializer for variable declaration");
+ if (constructor == nullptr) {
+ set_error(peek(), "missing constructor for variable declaration");
return nullptr;
}
- var->set_initializer(std::move(initializer));
+ var->set_constructor(std::move(constructor));
}
return std::make_unique<ast::VariableStatement>(source, std::move(var));
@@ -2137,7 +2137,7 @@
// const_expr
// : type_decl PAREN_LEFT (const_expr COMMA)? const_expr PAREN_RIGHT
// | const_literal
-std::unique_ptr<ast::InitializerExpression> ParserImpl::const_expr() {
+std::unique_ptr<ast::ConstructorExpression> ParserImpl::const_expr() {
auto t = peek();
auto source = t.source();
@@ -2145,7 +2145,7 @@
if (type != nullptr) {
t = next();
if (!t.IsParenLeft()) {
- set_error(t, "missing ( for type initializer");
+ set_error(t, "missing ( for type constructor");
return nullptr;
}
@@ -2177,10 +2177,10 @@
t = next();
if (!t.IsParenRight()) {
- set_error(t, "missing ) for type initializer");
+ set_error(t, "missing ) for type constructor");
return nullptr;
}
- return std::make_unique<ast::TypeInitializerExpression>(source, type,
+ return std::make_unique<ast::TypeConstructorExpression>(source, type,
std::move(params));
}
@@ -2191,8 +2191,8 @@
set_error(peek(), "unable to parse const literal");
return nullptr;
}
- return std::make_unique<ast::ConstInitializerExpression>(source,
- std::move(lit));
+ return std::make_unique<ast::ScalarConstructorExpression>(source,
+ std::move(lit));
}
// primary_expression
@@ -2210,8 +2210,8 @@
if (has_error())
return nullptr;
if (lit != nullptr) {
- return std::make_unique<ast::ConstInitializerExpression>(source,
- std::move(lit));
+ return std::make_unique<ast::ScalarConstructorExpression>(source,
+ std::move(lit));
}
t = peek();
@@ -2293,7 +2293,7 @@
if (type != nullptr) {
t = next();
if (!t.IsParenLeft()) {
- set_error(t, "missing ( for type initializer");
+ set_error(t, "missing ( for type constructor");
return nullptr;
}
@@ -2303,10 +2303,10 @@
t = next();
if (!t.IsParenRight()) {
- set_error(t, "missing ) for type initializer");
+ set_error(t, "missing ) for type constructor");
return nullptr;
}
- return std::make_unique<ast::TypeInitializerExpression>(source, type,
+ return std::make_unique<ast::TypeConstructorExpression>(source, type,
std::move(params));
}
return nullptr;
diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h
index 6c8e813..22bfb7e 100644
--- a/src/reader/wgsl/parser_impl.h
+++ b/src/reader/wgsl/parser_impl.h
@@ -24,11 +24,11 @@
#include "src/ast/assignment_statement.h"
#include "src/ast/builtin.h"
+#include "src/ast/constructor_expression.h"
#include "src/ast/derivative_modifier.h"
#include "src/ast/entry_point.h"
#include "src/ast/function.h"
#include "src/ast/import.h"
-#include "src/ast/initializer_expression.h"
#include "src/ast/literal.h"
#include "src/ast/loop_statement.h"
#include "src/ast/module.h"
@@ -239,8 +239,8 @@
/// @returns the const literal parsed or nullptr if none found
std::unique_ptr<ast::Literal> const_literal();
/// Parses a `const_expr` grammar element
- /// @returns the parsed initializer expression or nullptr on error
- std::unique_ptr<ast::InitializerExpression> const_expr();
+ /// @returns the parsed constructor expression or nullptr on error
+ std::unique_ptr<ast::ConstructorExpression> const_expr();
/// Parses a `primary_expression` grammar element
/// @returns the parsed expression or nullptr
std::unique_ptr<ast::Expression> primary_expression();
diff --git a/src/reader/wgsl/parser_impl_additive_expression_test.cc b/src/reader/wgsl/parser_impl_additive_expression_test.cc
index 14ca2c2..db4b4a2 100644
--- a/src/reader/wgsl/parser_impl_additive_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_additive_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -62,9 +62,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_and_expression_test.cc b/src/reader/wgsl/parser_impl_and_expression_test.cc
index dac8bc9..4f55afe 100644
--- a/src/reader/wgsl/parser_impl_and_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_and_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_argument_expression_list_test.cc b/src/reader/wgsl/parser_impl_argument_expression_list_test.cc
index eac942a..3155ee8 100644
--- a/src/reader/wgsl/parser_impl_argument_expression_list_test.cc
+++ b/src/reader/wgsl/parser_impl_argument_expression_list_test.cc
@@ -14,9 +14,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/unary_derivative_expression.h"
#include "src/ast/unary_method_expression.h"
#include "src/ast/unary_op_expression.h"
@@ -44,7 +44,7 @@
ASSERT_EQ(e.size(), 3);
ASSERT_TRUE(e[0]->IsIdentifier());
- ASSERT_TRUE(e[1]->IsInitializer());
+ ASSERT_TRUE(e[1]->IsConstructor());
ASSERT_TRUE(e[2]->IsRelational());
}
diff --git a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc
index 2ef65b0..b4cc88d 100644
--- a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc
+++ b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc
@@ -15,11 +15,11 @@
#include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.h"
#include "src/ast/assignment_statement.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/literal.h"
#include "src/ast/member_accessor_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -43,10 +43,10 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(e->rhs()->IsInitializer());
- ASSERT_TRUE(e->rhs()->AsInitializer()->IsConstInitializer());
+ ASSERT_TRUE(e->rhs()->IsConstructor());
+ ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor());
- auto init = e->rhs()->AsInitializer()->AsConstInitializer();
+ auto init = e->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_NE(init->literal(), nullptr);
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 123);
@@ -62,9 +62,9 @@
ASSERT_NE(e->lhs(), nullptr);
ASSERT_NE(e->rhs(), nullptr);
- ASSERT_TRUE(e->rhs()->IsInitializer());
- ASSERT_TRUE(e->rhs()->AsInitializer()->IsConstInitializer());
- auto init = e->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(e->rhs()->IsConstructor());
+ ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = e->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_NE(init->literal(), nullptr);
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 123);
@@ -80,9 +80,9 @@
ASSERT_TRUE(mem->structure()->IsArrayAccessor());
auto ary = mem->structure()->AsArrayAccessor();
- ASSERT_TRUE(ary->idx_expr()->IsInitializer());
- ASSERT_TRUE(ary->idx_expr()->AsInitializer()->IsConstInitializer());
- init = ary->idx_expr()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(ary->idx_expr()->IsConstructor());
+ ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
+ init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
ASSERT_NE(init->literal(), nullptr);
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 2);
diff --git a/src/reader/wgsl/parser_impl_const_expr_test.cc b/src/reader/wgsl/parser_impl_const_expr_test.cc
index f76ee53..ca18fcf 100644
--- a/src/reader/wgsl/parser_impl_const_expr_test.cc
+++ b/src/reader/wgsl/parser_impl_const_expr_test.cc
@@ -14,10 +14,10 @@
#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/scalar_constructor_expression.h"
#include "src/ast/type/vector_type.h"
-#include "src/ast/type_initializer_expression.h"
+#include "src/ast/type_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -31,25 +31,25 @@
auto e = p->const_expr();
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr);
- ASSERT_TRUE(e->IsInitializer());
- ASSERT_TRUE(e->AsInitializer()->IsTypeInitializer());
+ ASSERT_TRUE(e->IsConstructor());
+ ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor());
- auto t = e->AsInitializer()->AsTypeInitializer();
+ auto t = e->AsConstructor()->AsTypeConstructor();
ASSERT_TRUE(t->type()->IsVector());
EXPECT_EQ(t->type()->AsVector()->size(), 2);
ASSERT_EQ(t->values().size(), 2);
auto& v = t->values();
- ASSERT_TRUE(v[0]->IsInitializer());
- ASSERT_TRUE(v[0]->AsInitializer()->IsConstInitializer());
- auto c = v[0]->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(v[0]->IsConstructor());
+ ASSERT_TRUE(v[0]->AsConstructor()->IsScalarConstructor());
+ auto c = v[0]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(c->literal()->IsFloat());
EXPECT_FLOAT_EQ(c->literal()->AsFloat()->value(), 1.);
- ASSERT_TRUE(v[1]->IsInitializer());
- ASSERT_TRUE(v[1]->AsInitializer()->IsConstInitializer());
- c = v[1]->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(v[1]->IsConstructor());
+ ASSERT_TRUE(v[1]->AsConstructor()->IsScalarConstructor());
+ c = v[1]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(c->literal()->IsFloat());
EXPECT_FLOAT_EQ(c->literal()->AsFloat()->value(), 2.);
}
@@ -59,7 +59,7 @@
auto e = p->const_expr();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:17: missing ) for type initializer");
+ EXPECT_EQ(p->error(), "1:17: missing ) for type constructor");
}
TEST_F(ParserImplTest, ConstExpr_TypeDecl_MissingLeftParen) {
@@ -67,7 +67,7 @@
auto e = p->const_expr();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:11: missing ( for type initializer");
+ EXPECT_EQ(p->error(), "1:11: missing ( for type constructor");
}
TEST_F(ParserImplTest, ConstExpr_TypeDecl_HangingComma) {
@@ -83,7 +83,7 @@
auto e = p->const_expr();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:14: missing ) for type initializer");
+ EXPECT_EQ(p->error(), "1:14: missing ) for type constructor");
}
TEST_F(ParserImplTest, ConstExpr_MissingExpr) {
@@ -107,9 +107,9 @@
auto e = p->const_expr();
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr);
- ASSERT_TRUE(e->IsInitializer());
- ASSERT_TRUE(e->AsInitializer()->IsConstInitializer());
- auto c = e->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(e->IsConstructor());
+ ASSERT_TRUE(e->AsConstructor()->IsScalarConstructor());
+ auto c = e->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(c->literal()->IsBool());
EXPECT_TRUE(c->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_equality_expression_test.cc b/src/reader/wgsl/parser_impl_equality_expression_test.cc
index a0ec16d..7193229 100644
--- a/src/reader/wgsl/parser_impl_equality_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_equality_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -62,9 +62,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc
index 66ef301..626a9ac 100644
--- a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc
index d006297..3f53a04 100644
--- a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc
+++ b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc
@@ -34,8 +34,8 @@
ASSERT_NE(e->type(), nullptr);
EXPECT_TRUE(e->type()->IsF32());
- ASSERT_NE(e->initializer(), nullptr);
- EXPECT_TRUE(e->initializer()->IsInitializer());
+ ASSERT_NE(e->constructor(), nullptr);
+ EXPECT_TRUE(e->constructor()->IsConstructor());
}
TEST_F(ParserImplTest, GlobalConstantDecl_MissingEqual) {
diff --git a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc
index b65d697..d7ff3c6 100644
--- a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc
+++ b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc
@@ -23,7 +23,7 @@
namespace wgsl {
namespace {
-TEST_F(ParserImplTest, GlobalVariableDecl_WithoutInitializer) {
+TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) {
auto p = parser("var<out> a : f32");
auto e = p->global_variable_decl();
ASSERT_FALSE(p->has_error()) << p->error();
@@ -33,11 +33,11 @@
EXPECT_TRUE(e->type()->IsF32());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
- ASSERT_EQ(e->initializer(), nullptr);
+ ASSERT_EQ(e->constructor(), nullptr);
ASSERT_FALSE(e->IsDecorated());
}
-TEST_F(ParserImplTest, GlobalVariableDecl_WithInitializer) {
+TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
auto p = parser("var<out> a : f32 = 1.");
auto e = p->global_variable_decl();
ASSERT_FALSE(p->has_error()) << p->error();
@@ -47,9 +47,9 @@
EXPECT_TRUE(e->type()->IsF32());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
- ASSERT_NE(e->initializer(), nullptr);
- ASSERT_TRUE(e->initializer()->IsInitializer());
- ASSERT_TRUE(e->initializer()->AsInitializer()->IsConstInitializer());
+ ASSERT_NE(e->constructor(), nullptr);
+ ASSERT_TRUE(e->constructor()->IsConstructor());
+ ASSERT_TRUE(e->constructor()->AsConstructor()->IsScalarConstructor());
ASSERT_FALSE(e->IsDecorated());
}
@@ -66,7 +66,7 @@
EXPECT_TRUE(e->type()->IsF32());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
- ASSERT_EQ(e->initializer(), nullptr);
+ ASSERT_EQ(e->constructor(), nullptr);
ASSERT_TRUE(e->IsDecorated());
auto v = e->AsDecorated();
diff --git a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc
index 34ba2b0..4bd9c44 100644
--- a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc
index 4ae2510..9483649 100644
--- a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc
index c7e1468..3fb303a 100644
--- a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc
index e46e47f..9d6e2f7 100644
--- a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -62,9 +62,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -84,9 +84,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_postfix_expression_test.cc b/src/reader/wgsl/parser_impl_postfix_expression_test.cc
index 74dea91..a9c63e9 100644
--- a/src/reader/wgsl/parser_impl_postfix_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_postfix_expression_test.cc
@@ -15,10 +15,10 @@
#include "gtest/gtest.h"
#include "src/ast/array_accessor_expression.h"
#include "src/ast/call_expression.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/member_accessor_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/unary_derivative_expression.h"
#include "src/ast/unary_method_expression.h"
#include "src/ast/unary_op_expression.h"
@@ -44,9 +44,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(ary->idx_expr()->IsInitializer());
- ASSERT_TRUE(ary->idx_expr()->AsInitializer()->IsConstInitializer());
- auto c = ary->idx_expr()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(ary->idx_expr()->IsConstructor());
+ ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
+ auto c = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(c->literal()->IsInt());
EXPECT_EQ(c->literal()->AsInt()->value(), 1);
}
@@ -125,7 +125,7 @@
EXPECT_EQ(func->name()[1], "test");
EXPECT_EQ(c->params().size(), 3);
- EXPECT_TRUE(c->params()[0]->IsInitializer());
+ EXPECT_TRUE(c->params()[0]->IsConstructor());
EXPECT_TRUE(c->params()[1]->IsIdentifier());
EXPECT_TRUE(c->params()[2]->IsRelational());
}
diff --git a/src/reader/wgsl/parser_impl_primary_expression_test.cc b/src/reader/wgsl/parser_impl_primary_expression_test.cc
index a6c2478..0ce6138 100644
--- a/src/reader/wgsl/parser_impl_primary_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_primary_expression_test.cc
@@ -17,12 +17,12 @@
#include "src/ast/as_expression.h"
#include "src/ast/bool_literal.h"
#include "src/ast/cast_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/f32_type.h"
#include "src/ast/type/i32_type.h"
-#include "src/ast/type_initializer_expression.h"
+#include "src/ast/type_constructor_expression.h"
#include "src/ast/unary_derivative_expression.h"
#include "src/ast/unary_method_expression.h"
#include "src/ast/unary_op_expression.h"
@@ -73,33 +73,33 @@
auto e = p->primary_expression();
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr);
- ASSERT_TRUE(e->IsInitializer());
- ASSERT_TRUE(e->AsInitializer()->IsTypeInitializer());
- auto ty = e->AsInitializer()->AsTypeInitializer();
+ ASSERT_TRUE(e->IsConstructor());
+ ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor());
+ auto ty = e->AsConstructor()->AsTypeConstructor();
ASSERT_EQ(ty->values().size(), 4);
const auto& val = ty->values();
- ASSERT_TRUE(val[0]->IsInitializer());
- ASSERT_TRUE(val[0]->AsInitializer()->IsConstInitializer());
- auto ident = val[0]->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(val[0]->IsConstructor());
+ ASSERT_TRUE(val[0]->AsConstructor()->IsScalarConstructor());
+ auto ident = val[0]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(ident->literal()->IsInt());
EXPECT_EQ(ident->literal()->AsInt()->value(), 1);
- ASSERT_TRUE(val[1]->IsInitializer());
- ASSERT_TRUE(val[1]->AsInitializer()->IsConstInitializer());
- ident = val[1]->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(val[1]->IsConstructor());
+ ASSERT_TRUE(val[1]->AsConstructor()->IsScalarConstructor());
+ ident = val[1]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(ident->literal()->IsInt());
EXPECT_EQ(ident->literal()->AsInt()->value(), 2);
- ASSERT_TRUE(val[2]->IsInitializer());
- ASSERT_TRUE(val[2]->AsInitializer()->IsConstInitializer());
- ident = val[2]->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(val[2]->IsConstructor());
+ ASSERT_TRUE(val[2]->AsConstructor()->IsScalarConstructor());
+ ident = val[2]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(ident->literal()->IsInt());
EXPECT_EQ(ident->literal()->AsInt()->value(), 3);
- ASSERT_TRUE(val[3]->IsInitializer());
- ASSERT_TRUE(val[3]->AsInitializer()->IsConstInitializer());
- ident = val[3]->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(val[3]->IsConstructor());
+ ASSERT_TRUE(val[3]->AsConstructor()->IsScalarConstructor());
+ ident = val[3]->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(ident->literal()->IsInt());
EXPECT_EQ(ident->literal()->AsInt()->value(), 4);
}
@@ -117,7 +117,7 @@
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:11: missing ( for type initializer");
+ EXPECT_EQ(p->error(), "1:11: missing ( for type constructor");
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_MissingRightParen) {
@@ -125,7 +125,7 @@
auto e = p->primary_expression();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:25: missing ) for type initializer");
+ EXPECT_EQ(p->error(), "1:25: missing ) for type constructor");
}
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_InvalidValue) {
@@ -141,9 +141,9 @@
auto e = p->primary_expression();
ASSERT_FALSE(p->has_error());
ASSERT_NE(e, nullptr);
- ASSERT_TRUE(e->IsInitializer());
- ASSERT_TRUE(e->AsInitializer()->IsConstInitializer());
- auto init = e->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(e->IsConstructor());
+ ASSERT_TRUE(e->AsConstructor()->IsScalarConstructor());
+ auto init = e->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
EXPECT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -192,8 +192,8 @@
auto c = e->AsCast();
ASSERT_EQ(c->type(), f32_type);
- ASSERT_TRUE(c->expr()->IsInitializer());
- ASSERT_TRUE(c->expr()->AsInitializer()->IsConstInitializer());
+ ASSERT_TRUE(c->expr()->IsConstructor());
+ ASSERT_TRUE(c->expr()->AsConstructor()->IsScalarConstructor());
}
TEST_F(ParserImplTest, PrimaryExpression_Cast_MissingGreaterThan) {
@@ -264,8 +264,8 @@
auto c = e->AsAs();
ASSERT_EQ(c->type(), f32_type);
- ASSERT_TRUE(c->expr()->IsInitializer());
- ASSERT_TRUE(c->expr()->AsInitializer()->IsConstInitializer());
+ ASSERT_TRUE(c->expr()->IsConstructor());
+ ASSERT_TRUE(c->expr()->AsConstructor()->IsScalarConstructor());
}
TEST_F(ParserImplTest, PrimaryExpression_As_MissingGreaterThan) {
diff --git a/src/reader/wgsl/parser_impl_relational_expression_test.cc b/src/reader/wgsl/parser_impl_relational_expression_test.cc
index b7a41d6..5673535 100644
--- a/src/reader/wgsl/parser_impl_relational_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_relational_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -62,9 +62,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -84,9 +84,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -106,9 +106,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_shift_expression_test.cc b/src/reader/wgsl/parser_impl_shift_expression_test.cc
index 0fd54b9..76f5270 100644
--- a/src/reader/wgsl/parser_impl_shift_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_shift_expression_test.cc
@@ -14,9 +14,9 @@
#include "gtest/gtest.h"
#include "src/ast/bool_literal.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,9 +40,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -62,9 +62,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
@@ -84,9 +84,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(rel->rhs()->IsInitializer());
- ASSERT_TRUE(rel->rhs()->AsInitializer()->IsConstInitializer());
- auto init = rel->rhs()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(rel->rhs()->IsConstructor());
+ ASSERT_TRUE(rel->rhs()->AsConstructor()->IsScalarConstructor());
+ auto init = rel->rhs()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsBool());
ASSERT_TRUE(init->literal()->AsBool()->IsTrue());
}
diff --git a/src/reader/wgsl/parser_impl_statement_test.cc b/src/reader/wgsl/parser_impl_statement_test.cc
index 3a4d846..51082cc 100644
--- a/src/reader/wgsl/parser_impl_statement_test.cc
+++ b/src/reader/wgsl/parser_impl_statement_test.cc
@@ -138,7 +138,7 @@
auto e = p->statement();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:14: missing initializer for variable declaration");
+ EXPECT_EQ(p->error(), "1:14: missing constructor for variable declaration");
}
TEST_F(ParserImplTest, Statement_Variable_MissingSemicolon) {
diff --git a/src/reader/wgsl/parser_impl_unary_expression_test.cc b/src/reader/wgsl/parser_impl_unary_expression_test.cc
index 37ac9cf..090c9af 100644
--- a/src/reader/wgsl/parser_impl_unary_expression_test.cc
+++ b/src/reader/wgsl/parser_impl_unary_expression_test.cc
@@ -14,9 +14,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/unary_derivative_expression.h"
#include "src/ast/unary_method_expression.h"
#include "src/ast/unary_op_expression.h"
@@ -41,9 +41,9 @@
ASSERT_EQ(ident->name().size(), 1);
EXPECT_EQ(ident->name()[0], "a");
- ASSERT_TRUE(ary->idx_expr()->IsInitializer());
- ASSERT_TRUE(ary->idx_expr()->AsInitializer()->IsConstInitializer());
- auto init = ary->idx_expr()->AsInitializer()->AsConstInitializer();
+ ASSERT_TRUE(ary->idx_expr()->IsConstructor());
+ ASSERT_TRUE(ary->idx_expr()->AsConstructor()->IsScalarConstructor());
+ auto init = ary->idx_expr()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsInt());
ASSERT_EQ(init->literal()->AsInt()->value(), 2);
}
@@ -58,10 +58,10 @@
auto u = e->AsUnaryOp();
ASSERT_EQ(u->op(), ast::UnaryOp::kNegation);
- ASSERT_TRUE(u->expr()->IsInitializer());
- ASSERT_TRUE(u->expr()->AsInitializer()->IsConstInitializer());
+ ASSERT_TRUE(u->expr()->IsConstructor());
+ ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
- auto init = u->expr()->AsInitializer()->AsConstInitializer();
+ auto init = u->expr()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 1);
}
@@ -84,10 +84,10 @@
auto u = e->AsUnaryOp();
ASSERT_EQ(u->op(), ast::UnaryOp::kNot);
- ASSERT_TRUE(u->expr()->IsInitializer());
- ASSERT_TRUE(u->expr()->AsInitializer()->IsConstInitializer());
+ ASSERT_TRUE(u->expr()->IsConstructor());
+ ASSERT_TRUE(u->expr()->AsConstructor()->IsScalarConstructor());
- auto init = u->expr()->AsInitializer()->AsConstInitializer();
+ auto init = u->expr()->AsConstructor()->AsScalarConstructor();
ASSERT_TRUE(init->literal()->IsInt());
EXPECT_EQ(init->literal()->AsInt()->value(), 1);
}
diff --git a/src/reader/wgsl/parser_impl_variable_stmt_test.cc b/src/reader/wgsl/parser_impl_variable_stmt_test.cc
index 10b5728..8777380 100644
--- a/src/reader/wgsl/parser_impl_variable_stmt_test.cc
+++ b/src/reader/wgsl/parser_impl_variable_stmt_test.cc
@@ -32,7 +32,7 @@
ASSERT_NE(e->variable(), nullptr);
EXPECT_EQ(e->variable()->name(), "a");
- EXPECT_EQ(e->variable()->initializer(), nullptr);
+ EXPECT_EQ(e->variable()->constructor(), nullptr);
}
TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
@@ -44,8 +44,8 @@
ASSERT_NE(e->variable(), nullptr);
EXPECT_EQ(e->variable()->name(), "a");
- ASSERT_NE(e->variable()->initializer(), nullptr);
- EXPECT_TRUE(e->variable()->initializer()->IsInitializer());
+ ASSERT_NE(e->variable()->constructor(), nullptr);
+ EXPECT_TRUE(e->variable()->constructor()->IsConstructor());
}
TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) {
@@ -56,12 +56,12 @@
EXPECT_EQ(p->error(), "1:9: unknown type alias 'invalid'");
}
-TEST_F(ParserImplTest, VariableStmt_VariableDecl_InitializerInvalid) {
+TEST_F(ParserImplTest, VariableStmt_VariableDecl_ConstructorInvalid) {
auto p = parser("var a : i32 = if(a) {}");
auto e = p->variable_stmt();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:15: missing initializer for variable declaration");
+ EXPECT_EQ(p->error(), "1:15: missing constructor for variable declaration");
}
TEST_F(ParserImplTest, VariableStmt_Const) {
@@ -88,20 +88,20 @@
EXPECT_EQ(p->error(), "1:15: missing = for constant declaration");
}
-TEST_F(ParserImplTest, VariableStmt_Const_MissingInitializer) {
+TEST_F(ParserImplTest, VariableStmt_Const_MissingConstructor) {
auto p = parser("const a : i32 =");
auto e = p->variable_stmt();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:16: missing initializer for const declaration");
+ EXPECT_EQ(p->error(), "1:16: missing constructor for const declaration");
}
-TEST_F(ParserImplTest, VariableStmt_Const_InvalidInitializer) {
+TEST_F(ParserImplTest, VariableStmt_Const_InvalidConstructor) {
auto p = parser("const a : i32 = if (a) {}");
auto e = p->variable_stmt();
ASSERT_TRUE(p->has_error());
ASSERT_EQ(e, nullptr);
- EXPECT_EQ(p->error(), "1:17: missing initializer for const declaration");
+ EXPECT_EQ(p->error(), "1:17: missing constructor for const declaration");
}
} // namespace
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index 32b0d98..d0e10eb 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -20,13 +20,13 @@
#include "src/ast/binding_decoration.h"
#include "src/ast/bool_literal.h"
#include "src/ast/builtin_decoration.h"
-#include "src/ast/const_initializer_expression.h"
+#include "src/ast/constructor_expression.h"
#include "src/ast/decorated_variable.h"
#include "src/ast/float_literal.h"
-#include "src/ast/initializer_expression.h"
#include "src/ast/int_literal.h"
#include "src/ast/location_decoration.h"
#include "src/ast/return_statement.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/set_decoration.h"
#include "src/ast/struct.h"
#include "src/ast/struct_member.h"
@@ -37,7 +37,7 @@
#include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_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"
namespace tint {
@@ -173,8 +173,8 @@
}
uint32_t Builder::GenerateExpression(ast::Expression* expr) {
- if (expr->IsInitializer()) {
- return GenerateInitializerExpression(expr->AsInitializer(), false);
+ if (expr->IsConstructor()) {
+ return GenerateConstructorExpression(expr->AsConstructor(), false);
}
error_ = "unknown expression type";
@@ -239,13 +239,13 @@
bool Builder::GenerateGlobalVariable(ast::Variable* var) {
uint32_t init_id = 0;
- if (var->has_initializer()) {
- if (!var->initializer()->IsInitializer()) {
- error_ = "constant initializer expected";
+ if (var->has_constructor()) {
+ if (!var->constructor()->IsConstructor()) {
+ error_ = "scalar constructor expected";
return false;
}
- init_id = GenerateInitializerExpression(var->initializer()->AsInitializer(),
+ init_id = GenerateConstructorExpression(var->constructor()->AsConstructor(),
true);
if (init_id == 0) {
return false;
@@ -253,8 +253,8 @@
}
if (var->is_const()) {
- if (!var->has_initializer()) {
- error_ = "missing initializer for constant";
+ if (!var->has_constructor()) {
+ error_ = "missing constructor for constant";
return false;
}
@@ -280,7 +280,7 @@
std::vector<Operand> ops = {Operand::Int(type_id), result,
Operand::Int(ConvertStorageClass(sc))};
- if (var->has_initializer()) {
+ if (var->has_constructor()) {
ops.push_back(Operand::Int(init_id));
}
@@ -327,14 +327,14 @@
import_name_to_id_[imp->name()] = id;
}
-uint32_t Builder::GenerateInitializerExpression(
- ast::InitializerExpression* expr,
+uint32_t Builder::GenerateConstructorExpression(
+ ast::ConstructorExpression* expr,
bool is_global_init) {
- if (expr->IsConstInitializer()) {
- return GenerateLiteralIfNeeded(expr->AsConstInitializer()->literal());
+ if (expr->IsScalarConstructor()) {
+ return GenerateLiteralIfNeeded(expr->AsScalarConstructor()->literal());
}
- if (expr->IsTypeInitializer()) {
- auto init = expr->AsTypeInitializer();
+ if (expr->IsTypeConstructor()) {
+ auto init = expr->AsTypeConstructor();
auto type_id = GenerateTypeIfNeeded(init->type());
if (type_id == 0) {
return 0;
@@ -345,12 +345,12 @@
std::vector<Operand> ops;
for (const auto& e : init->values()) {
- if (is_global_init && !e->IsInitializer()) {
- error_ = "initializer must be a constant expression";
+ if (is_global_init && !e->IsConstructor()) {
+ error_ = "constructor must be a constant expression";
return 0;
}
auto id =
- GenerateInitializerExpression(e->AsInitializer(), is_global_init);
+ GenerateConstructorExpression(e->AsConstructor(), is_global_init);
if (id == 0) {
return 0;
}
@@ -375,7 +375,7 @@
return result.to_i();
}
- error_ = "unknown initializer expression";
+ error_ = "unknown constructor expression";
return 0;
}
diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h
index a7429bb..79082d7 100644
--- a/src/writer/spirv/builder.h
+++ b/src/writer/spirv/builder.h
@@ -156,11 +156,11 @@
/// Generates an import instruction
/// @param imp the import
void GenerateImport(ast::Import* imp);
- /// Generates an initializer expression
+ /// Generates an constructor expression
/// @param expr the expression to generate
- /// @param is_global_init set true if this is a global variable initializer
+ /// @param is_global_init set true if this is a global variable constructor
/// @returns the ID of the expression or 0 on failure.
- uint32_t GenerateInitializerExpression(ast::InitializerExpression* expr,
+ uint32_t GenerateConstructorExpression(ast::ConstructorExpression* expr,
bool is_global_init);
/// Generates a literal constant if needed
/// @param lit the literal to generate
diff --git a/src/writer/spirv/builder_initializer_expression_test.cc b/src/writer/spirv/builder_constructor_expression_test.cc
similarity index 65%
rename from src/writer/spirv/builder_initializer_expression_test.cc
rename to src/writer/spirv/builder_constructor_expression_test.cc
index 443493f..51bb271 100644
--- a/src/writer/spirv/builder_initializer_expression_test.cc
+++ b/src/writer/spirv/builder_constructor_expression_test.cc
@@ -17,12 +17,12 @@
#include "gtest/gtest.h"
#include "spirv/unified1/spirv.h"
#include "spirv/unified1/spirv.hpp11"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/relational_expression.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/f32_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/writer/spirv/builder.h"
#include "src/writer/spirv/spv_dump.h"
@@ -33,13 +33,13 @@
using BuilderTest = testing::Test;
-TEST_F(BuilderTest, Initializer_Const) {
+TEST_F(BuilderTest, Constructor_Const) {
ast::type::F32Type f32;
auto fl = std::make_unique<ast::FloatLiteral>(&f32, 42.2f);
- ast::ConstInitializerExpression c(std::move(fl));
+ ast::ScalarConstructorExpression c(std::move(fl));
Builder b;
- EXPECT_EQ(b.GenerateInitializerExpression(&c, true), 2);
+ EXPECT_EQ(b.GenerateConstructorExpression(&c, true), 2);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
@@ -47,22 +47,22 @@
)");
}
-TEST_F(BuilderTest, Initializer_Type) {
+TEST_F(BuilderTest, Constructor_Type) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
- ast::TypeInitializerExpression t(&vec, std::move(vals));
+ ast::TypeConstructorExpression t(&vec, std::move(vals));
Builder b;
- EXPECT_EQ(b.GenerateInitializerExpression(&t, true), 5);
+ EXPECT_EQ(b.GenerateConstructorExpression(&t, true), 5);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
@@ -73,47 +73,47 @@
)");
}
-TEST_F(BuilderTest, Initializer_Type_Dedups) {
+TEST_F(BuilderTest, Constructor_Type_Dedups) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
- ast::TypeInitializerExpression t(&vec, std::move(vals));
+ ast::TypeConstructorExpression t(&vec, std::move(vals));
Builder b;
- EXPECT_EQ(b.GenerateInitializerExpression(&t, true), 5);
- EXPECT_EQ(b.GenerateInitializerExpression(&t, true), 5);
+ EXPECT_EQ(b.GenerateConstructorExpression(&t, true), 5);
+ EXPECT_EQ(b.GenerateConstructorExpression(&t, true), 5);
ASSERT_FALSE(b.has_error()) << b.error();
}
-TEST_F(BuilderTest, Initializer_NonConst_Type_Fails) {
+TEST_F(BuilderTest, Constructor_NonConst_Type_Fails) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 2);
auto rel = std::make_unique<ast::RelationalExpression>(
ast::Relation::kAdd,
- std::make_unique<ast::ConstInitializerExpression>(
+ std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)),
- std::make_unique<ast::ConstInitializerExpression>(
+ std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
std::vector<std::unique_ptr<ast::Expression>> vals;
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::move(rel));
- ast::TypeInitializerExpression t(&vec, std::move(vals));
+ ast::TypeConstructorExpression t(&vec, std::move(vals));
Builder b;
- EXPECT_EQ(b.GenerateInitializerExpression(&t, true), 0);
+ EXPECT_EQ(b.GenerateConstructorExpression(&t, true), 0);
EXPECT_TRUE(b.has_error());
- EXPECT_EQ(b.error(), R"(initializer must be a constant expression)");
+ EXPECT_EQ(b.error(), R"(constructor must be a constant expression)");
}
} // namespace
diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc
index 0a66899..3f2deac 100644
--- a/src/writer/spirv/builder_global_variable_test.cc
+++ b/src/writer/spirv/builder_global_variable_test.cc
@@ -18,15 +18,15 @@
#include "src/ast/binding_decoration.h"
#include "src/ast/builtin.h"
#include "src/ast/builtin_decoration.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/decorated_variable.h"
#include "src/ast/float_literal.h"
#include "src/ast/location_decoration.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/set_decoration.h"
#include "src/ast/storage_class.h"
#include "src/ast/type/f32_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/variable.h"
#include "src/ast/variable_decoration.h"
#include "src/writer/spirv/builder.h"
@@ -67,23 +67,23 @@
)");
}
-TEST_F(BuilderTest, GlobalVar_WithInitializer) {
+TEST_F(BuilderTest, GlobalVar_WithConstructor) {
ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
auto init =
- std::make_unique<ast::TypeInitializerExpression>(&vec, std::move(vals));
+ std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
- v.set_initializer(std::move(init));
+ v.set_constructor(std::move(init));
Builder b;
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
@@ -106,18 +106,18 @@
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
auto init =
- std::make_unique<ast::TypeInitializerExpression>(&vec, std::move(vals));
+ std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
- v.set_initializer(std::move(init));
+ v.set_constructor(std::move(init));
v.set_is_const(true);
Builder b;
diff --git a/src/writer/spirv/builder_return_test.cc b/src/writer/spirv/builder_return_test.cc
index 57134e6..038bbb7 100644
--- a/src/writer/spirv/builder_return_test.cc
+++ b/src/writer/spirv/builder_return_test.cc
@@ -15,12 +15,12 @@
#include <memory>
#include "gtest/gtest.h"
-#include "src/ast/const_initializer_expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/return_statement.h"
+#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/f32_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/writer/spirv/builder.h"
#include "src/writer/spirv/spv_dump.h"
@@ -47,15 +47,15 @@
ast::type::VectorType vec(&f32, 3);
std::vector<std::unique_ptr<ast::Expression>> vals;
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
- vals.push_back(std::make_unique<ast::ConstInitializerExpression>(
+ vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
auto val =
- std::make_unique<ast::TypeInitializerExpression>(&vec, std::move(vals));
+ std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
ast::ReturnStatement ret(std::move(val));
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;