mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 21:47:47 +00:00
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:
committed by
dan sinclair
parent
e68c9b4075
commit
a322f5ddfa
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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), " +
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user