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>
This commit is contained in:
dan sinclair 2020-03-30 22:46:06 +00:00 committed by dan sinclair
parent e68c9b4075
commit a322f5ddfa
70 changed files with 567 additions and 564 deletions

View File

@ -59,8 +59,8 @@ set(TINT_LIB_SRCS
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 @@ set(TINT_LIB_SRCS
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 @@ set(TINT_LIB_SRCS
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 @@ set(TINT_LIB_SRCS
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 @@ set(TINT_TEST_SRCS
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 @@ set(TINT_TEST_SRCS
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 @@ set(TINT_TEST_SRCS
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 @@ endif()
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 @@ if(${TINT_BUILD_WGSL_WRITER})
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 @@ if(${TINT_BUILD_WGSL_WRITER})
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

View File

@ -35,7 +35,7 @@ class ArrayAccessorExpression : public Expression {
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,

View File

@ -36,7 +36,7 @@ class AsExpression : public Expression {
/// @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,

View File

@ -36,7 +36,7 @@ class AssignmentStatement : public Statement {
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,

View File

@ -31,7 +31,7 @@ class BreakStatement : public Statement {
/// 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 @@ class BreakStatement : public Statement {
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,

View File

@ -36,7 +36,7 @@ class CallExpression : public Expression {
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,

View File

@ -36,7 +36,7 @@ class CastExpression : public Expression {
/// @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,

View File

@ -12,31 +12,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/ast/initializer_expression.h"
#include "src/ast/constructor_expression.h"
#include <assert.h>
#include "src/ast/const_initializer_expression.h"
#include "src/ast/type_initializer_expression.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type_constructor_expression.h"
namespace tint {
namespace ast {
InitializerExpression::InitializerExpression() = default;
ConstructorExpression::ConstructorExpression() = default;
InitializerExpression::~InitializerExpression() = default;
ConstructorExpression::~ConstructorExpression() = default;
InitializerExpression::InitializerExpression(const Source& source)
ConstructorExpression::ConstructorExpression(const Source& source)
: Expression(source) {}
ConstInitializerExpression* InitializerExpression::AsConstInitializer() {
assert(IsConstInitializer());
return static_cast<ConstInitializerExpression*>(this);
ScalarConstructorExpression* ConstructorExpression::AsScalarConstructor() {
assert(IsScalarConstructor());
return static_cast<ScalarConstructorExpression*>(this);
}
TypeInitializerExpression* InitializerExpression::AsTypeInitializer() {
assert(IsTypeInitializer());
return static_cast<TypeInitializerExpression*>(this);
TypeConstructorExpression* ConstructorExpression::AsTypeConstructor() {
assert(IsTypeConstructor());
return static_cast<TypeConstructorExpression*>(this);
}
} // namespace ast

View File

@ -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_

View File

@ -31,7 +31,7 @@ class ContinueStatement : public Statement {
/// 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 @@ class ContinueStatement : public Statement {
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,

View File

@ -45,7 +45,7 @@ void DecoratedVariable::to_str(std::ostream& out, size_t indent) const {
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;
}

View File

@ -70,7 +70,7 @@ TEST_F(DecoratedVariableTest, to_str) {
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));

View File

@ -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 @@ using ElseStatementTest = testing::Test;
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, IsElse) {
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_WithNullBodyStatement) {
}
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, IsValid_InvalidBodyStatement) {
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 @@ TEST_F(ElseStatementTest, ToStr) {
e.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Else{
(
ConstInitializer{true}
ScalarConstructor{true}
)
{
Nop{}

View File

@ -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 @@ IdentifierExpression* Expression::AsIdentifier() {
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() {

View File

@ -25,7 +25,7 @@ class AsExpression;
class CallExpression;
class CastExpression;
class IdentifierExpression;
class InitializerExpression;
class ConstructorExpression;
class MemberAccessorExpression;
class RelationalExpression;
class UnaryDerivativeExpression;
@ -47,8 +47,8 @@ class Expression : public Node {
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 @@ class Expression : public Node {
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

View File

@ -39,7 +39,7 @@ class IdentifierExpression : public Expression {
/// @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

View File

@ -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_

View File

@ -26,7 +26,7 @@ class KillStatement : public Statement {
/// Constructor
KillStatement();
/// Constructor
/// @param source the initializer source
/// @param source the kill statement source
explicit KillStatement(const Source& source);
/// Move constructor
KillStatement(KillStatement&&) = default;

View File

@ -35,7 +35,7 @@ class LoopStatement : public Statement {
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,

View File

@ -37,7 +37,7 @@ class MemberAccessorExpression : public Expression {
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,

View File

@ -26,7 +26,7 @@ class NopStatement : public Statement {
/// Constructor
NopStatement();
/// Constructor
/// @param source the initializer source
/// @param source the nop statement source
explicit NopStatement(const Source& source);
/// Move constructor
NopStatement(NopStatement&&) = default;

View File

@ -36,7 +36,7 @@ class RegardlessStatement : public Statement {
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,

View File

@ -61,7 +61,7 @@ class RelationalExpression : public Expression {
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

View File

@ -36,7 +36,7 @@ class ReturnStatement : public Statement {
/// @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

View File

@ -12,33 +12,33 @@
// 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"
namespace tint {
namespace ast {
ConstInitializerExpression::ConstInitializerExpression()
: InitializerExpression() {}
ScalarConstructorExpression::ScalarConstructorExpression()
: ConstructorExpression() {}
ConstInitializerExpression::ConstInitializerExpression(
ScalarConstructorExpression::ScalarConstructorExpression(
std::unique_ptr<Literal> literal)
: InitializerExpression(), literal_(std::move(literal)) {}
: ConstructorExpression(), literal_(std::move(literal)) {}
ConstInitializerExpression::ConstInitializerExpression(
ScalarConstructorExpression::ScalarConstructorExpression(
const Source& source,
std::unique_ptr<Literal> litearl)
: InitializerExpression(source), literal_(std::move(litearl)) {}
: ConstructorExpression(source), literal_(std::move(litearl)) {}
ConstInitializerExpression::~ConstInitializerExpression() = default;
ScalarConstructorExpression::~ScalarConstructorExpression() = default;
bool ConstInitializerExpression::IsValid() const {
bool ScalarConstructorExpression::IsValid() const {
return literal_ != nullptr;
}
void ConstInitializerExpression::to_str(std::ostream& out,
size_t indent) const {
void ScalarConstructorExpression::to_str(std::ostream& out,
size_t indent) const {
make_indent(out, indent);
out << "ConstInitializer{" << literal_->to_str() << "}" << std::endl;
out << "ScalarConstructor{" << literal_->to_str() << "}" << std::endl;
}
} // namespace ast

View File

@ -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 @@ class ConstInitializerExpression : public InitializerExpression {
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 @@ class ConstInitializerExpression : public InitializerExpression {
} // namespace ast
} // namespace tint
#endif // SRC_AST_CONST_INITIALIZER_EXPRESSION_H_
#endif // SRC_AST_SCALAR_CONSTRUCTOR_EXPRESSION_H_

View File

@ -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 tint {
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}
)");
}

View File

@ -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 @@ bool TypeInitializerExpression::IsValid() const {
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;

View File

@ -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 @@ class TypeInitializerExpression : public InitializerExpression {
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 @@ class TypeInitializerExpression : public InitializerExpression {
} // namespace ast
} // namespace tint
#endif // SRC_AST_TYPE_INITIALIZER_EXPRESSION_H_
#endif // SRC_AST_TYPE_CONSTRUCTOR_EXPRESSION_H_

View File

@ -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 tint {
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 @@ TEST_F(TypeInitializerExpressionTest, ToStr) {
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}

View File

@ -39,7 +39,7 @@ class UnaryDerivativeExpression : public Expression {
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

View File

@ -37,7 +37,7 @@ class UnaryMethodExpression : public Expression {
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,

View File

@ -35,7 +35,7 @@ class UnaryOpExpression : public Expression {
/// @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,

View File

@ -36,7 +36,7 @@ class UnlessStatement : public Statement {
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,

View File

@ -44,7 +44,7 @@ bool Variable::IsValid() const {
if (type_ == nullptr) {
return false;
}
if (initializer_ && !initializer_->IsValid()) {
if (constructor_ && !constructor_->IsValid()) {
return false;
}
return true;
@ -59,14 +59,14 @@ void Variable::info_to_str(std::ostream& out, size_t indent) const {
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 @@ void Variable::to_str(std::ostream& out, size_t indent) const {
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;
}

View File

@ -72,15 +72,15 @@ class Variable : public Node {
/// @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 @@ class Variable : public Node {
/// @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 @@ class Variable : public Node {
std::string name_;
StorageClass storage_class_ = StorageClass::kNone;
type::Type* type_ = nullptr;
std::unique_ptr<Expression> initializer_;
std::unique_ptr<Expression> constructor_;
};
} // namespace ast

View File

@ -34,7 +34,7 @@ class VariableStatement : public Statement {
/// @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

View File

@ -71,10 +71,10 @@ TEST_F(VariableTest, IsValid) {
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 @@ TEST_F(VariableTest, IsValid_MissingBoth) {
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());
}

View File

@ -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 @@ std::unique_ptr<ast::Variable> ParserImpl::global_variable_decl() {
return nullptr;
}
var->set_initializer(std::move(expr));
var->set_constructor(std::move(expr));
}
return var;
}
@ -386,10 +386,10 @@ std::unique_ptr<ast::Variable> ParserImpl::global_constant_decl() {
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 @@ std::unique_ptr<ast::VariableStatement> ParserImpl::variable_stmt() {
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 @@ std::unique_ptr<ast::VariableStatement> ParserImpl::variable_stmt() {
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 @@ std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
// 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 @@ std::unique_ptr<ast::InitializerExpression> ParserImpl::const_expr() {
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 @@ std::unique_ptr<ast::InitializerExpression> ParserImpl::const_expr() {
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 @@ std::unique_ptr<ast::InitializerExpression> ParserImpl::const_expr() {
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 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
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 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
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 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
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;

View File

@ -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 @@ class ParserImpl {
/// @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();

View File

@ -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 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
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 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, AndExpression_Parses) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, ArgumentExpressionList_ParsesMultiple) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
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 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
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 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
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);

View File

@ -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 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) {
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 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl_MissingRightParen) {
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 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl_MissingLeftParen) {
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 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl_MissingComma) {
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 @@ TEST_F(ParserImplTest, ConstExpr_ConstLiteral) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) {
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 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) {
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());
}

View File

@ -34,8 +34,8 @@ TEST_F(ParserImplTest, GlobalConstantDecl) {
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) {

View File

@ -23,7 +23,7 @@ namespace reader {
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 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutInitializer) {
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 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithInitializer) {
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 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) {
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();

View File

@ -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 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) {
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 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) {
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 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ConstantIndex) {
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 @@ TEST_F(ParserImplTest, PostfixExpression_Call_WithArgs) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {
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 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_MissingLeftParen) {
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 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_MissingRightParen) {
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 @@ TEST_F(ParserImplTest, PrimaryExpression_ConstLiteral_True) {
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 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
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 @@ TEST_F(ParserImplTest, PrimaryExpression_As) {
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) {

View File

@ -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 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) {
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 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) {
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 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) {
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 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) {
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());
}

View File

@ -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 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) {
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 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
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 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRightArith) {
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());
}

View File

@ -138,7 +138,7 @@ TEST_F(ParserImplTest, Statement_Variable_Invalid) {
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) {

View File

@ -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 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) {
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 @@ TEST_F(ParserImplTest, UnaryExpression_Minus) {
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 @@ TEST_F(ParserImplTest, UnaryExpression_Bang) {
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);
}

View File

@ -32,7 +32,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
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 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
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 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) {
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 @@ TEST_F(ParserImplTest, VariableStmt_Const_MissingEqual) {
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

View File

@ -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 @@ bool Builder::GenerateEntryPoint(ast::EntryPoint* ep) {
}
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 @@ uint32_t Builder::GenerateFunctionTypeIfNeeded(ast::Function* func) {
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 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
}
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 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
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 @@ void Builder::GenerateImport(ast::Import* imp) {
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 @@ uint32_t Builder::GenerateInitializerExpression(
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 @@ uint32_t Builder::GenerateInitializerExpression(
return result.to_i();
}
error_ = "unknown initializer expression";
error_ = "unknown constructor expression";
return 0;
}

View File

@ -156,11 +156,11 @@ class Builder {
/// 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

View File

@ -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 @@ namespace {
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_Const) {
)");
}
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) {
)");
}
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

View File

@ -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_WithStorageClass) {
)");
}
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 @@ TEST_F(BuilderTest, GlobalVar_Const) {
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;

View File

@ -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 @@ TEST_F(BuilderTest, Return_WithValue) {
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));

View File

@ -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 @@ bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
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 @@ bool GeneratorImpl::EmitCast(ast::CastExpression* expr) {
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 @@ bool GeneratorImpl::EmitTypeInitializer(ast::TypeInitializerExpression* expr) {
return true;
}
bool GeneratorImpl::EmitConstInitializer(
ast::ConstInitializerExpression* expr) {
bool GeneratorImpl::EmitScalarConstructor(
ast::ScalarConstructorExpression* expr) {
return EmitLiteral(expr->literal());
}
@ -480,9 +480,9 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) {
return false;
}
if (var->initializer() != nullptr) {
if (var->constructor() != nullptr) {
out_ << " = ";
if (!EmitExpression(var->initializer())) {
if (!EmitExpression(var->constructor())) {
return false;
}
}

View File

@ -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 @@ class GeneratorImpl {
/// @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 @@ class GeneratorImpl {
/// @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 @@ class GeneratorImpl {
/// @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

View File

@ -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 @@ using GeneratorImplTest = testing::Test;
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));

View File

@ -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 @@ namespace {
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 @@ TEST_F(GeneratorImplTest, EmitInitializer_Type_Vec) {
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 @@ TEST_F(GeneratorImplTest, EmitInitializer_Type_Mat) {
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 @@ TEST_F(GeneratorImplTest, EmitInitializer_Type_Array) {
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), " +

View File

@ -91,12 +91,12 @@ TEST_F(GeneratorImplTest, EmitVariable_Decorated_Multiple) {
)");
}
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 @@ TEST_F(GeneratorImplTest, EmitVariable_Const) {
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;