[type-determiner] Move ast::Module to constructor.

This CL moves the ast::Module to be provided to the type determiner
constructor so we can access it for things like the imports.

Change-Id: I110fffe669a8a007461bf84d30d85d70405e37be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19761
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-04-20 14:20:01 +00:00 committed by dan sinclair
parent cd077b01a9
commit b950e80a59
7 changed files with 102 additions and 100 deletions

View File

@ -305,8 +305,8 @@ int main(int argc, const char** argv) {
return 1;
}
tint::TypeDeterminer td(&ctx);
if (!td.Determine(&mod)) {
tint::TypeDeterminer td(&ctx, &mod);
if (!td.Determine()) {
std::cerr << td.error() << std::endl;
return 1;
}

View File

@ -48,7 +48,8 @@
namespace tint {
TypeDeterminer::TypeDeterminer(Context* ctx) : ctx_(*ctx) {}
TypeDeterminer::TypeDeterminer(Context* ctx, ast::Module* mod)
: ctx_(*ctx), mod_(mod) {}
TypeDeterminer::~TypeDeterminer() = default;
@ -61,16 +62,16 @@ void TypeDeterminer::set_error(const Source& src, const std::string& msg) {
error_ += msg;
}
bool TypeDeterminer::Determine(ast::Module* mod) {
for (const auto& var : mod->global_variables()) {
bool TypeDeterminer::Determine() {
for (const auto& var : mod_->global_variables()) {
variable_stack_.set_global(var->name(), var.get());
}
for (const auto& func : mod->functions()) {
for (const auto& func : mod_->functions()) {
name_to_function_[func->name()] = func.get();
}
if (!DetermineFunctions(mod->functions())) {
if (!DetermineFunctions(mod_->functions())) {
return false;
}
return true;

View File

@ -46,16 +46,15 @@ class TypeDeterminer {
public:
/// Constructor
/// @param ctx the tint context
explicit TypeDeterminer(Context* ctx);
/// @param mod the module to update with typing information
TypeDeterminer(Context* ctx, ast::Module* mod);
~TypeDeterminer();
/// @returns error messages from the type determiner
const std::string& error() { return error_; }
/// Runs the type determiner
/// @param mod the module to update with typing information
/// @returns true if the type determiner was successful
bool Determine(ast::Module* mod);
bool Determine();
/// Determines type information for functions
/// @param funcs the functions to check
/// @returns true if the determination was successful
@ -104,6 +103,7 @@ class TypeDeterminer {
bool DetermineUnaryOp(ast::UnaryOpExpression* expr);
Context& ctx_;
ast::Module* mod_;
std::string error_;
ScopeStack<ast::Variable*> variable_stack_;
std::unordered_map<std::string, ast::Function*> name_to_function_;

View File

@ -70,7 +70,8 @@ class FakeExpr : public ast::Expression {
class TypeDeterminerHelper {
public:
TypeDeterminerHelper() : td_(std::make_unique<TypeDeterminer>(&ctx_)) {}
TypeDeterminerHelper()
: td_(std::make_unique<TypeDeterminer>(&ctx_, &mod_)) {}
TypeDeterminer* td() const { return td_.get(); }
ast::Module* mod() { return &mod_; }
@ -435,7 +436,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
ast::ArrayAccessorExpression acc(
std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
@ -456,7 +457,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
ast::ArrayAccessorExpression acc(
std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
@ -480,7 +481,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix_BothDimensions) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
ast::ArrayAccessorExpression acc(
std::make_unique<ast::ArrayAccessorExpression>(
@ -505,7 +506,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
ast::ArrayAccessorExpression acc(
std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
@ -533,7 +534,7 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
mod()->AddFunction(std::move(func));
// Register the function
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
ast::ExpressionList call_params;
ast::CallExpression call(
@ -553,7 +554,7 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
mod()->AddFunction(std::move(func));
// Register the function
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
ast::ExpressionList call_params;
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
@ -617,7 +618,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalVariable) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
ast::IdentifierExpression ident("my_var");
EXPECT_TRUE(td()->DetermineResultType(&ident));
@ -658,7 +659,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function) {
mod()->AddFunction(std::move(func));
// Register the function
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
ast::IdentifierExpression ident("my_func");
EXPECT_TRUE(td()->DetermineResultType(&ident));
@ -688,7 +689,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
auto ident = std::make_unique<ast::IdentifierExpression>("my_struct");
auto mem_ident = std::make_unique<ast::IdentifierExpression>("second_member");
@ -708,7 +709,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_VectorSwizzle) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
auto ident = std::make_unique<ast::IdentifierExpression>("my_vec");
auto swizzle = std::make_unique<ast::IdentifierExpression>("xy");
@ -776,7 +777,7 @@ TEST_F(TypeDeterminerTest, Expr_MultiLevel) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine(mod()));
EXPECT_TRUE(td()->Determine());
auto ident = std::make_unique<ast::IdentifierExpression>("c");
auto mem_ident = std::make_unique<ast::IdentifierExpression>("mem");
@ -811,7 +812,7 @@ TEST_P(Expr_Binary_BitwiseTest, Scalar) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
ASSERT_TRUE(td()->Determine(mod())) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
op, std::make_unique<ast::IdentifierExpression>("val"),
@ -833,7 +834,7 @@ TEST_P(Expr_Binary_BitwiseTest, Vector) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
ASSERT_TRUE(td()->Determine(mod())) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
op, std::make_unique<ast::IdentifierExpression>("val"),
@ -869,7 +870,7 @@ TEST_P(Expr_Binary_LogicalTest, Scalar) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
op, std::make_unique<ast::IdentifierExpression>("val"),
@ -891,7 +892,7 @@ TEST_P(Expr_Binary_LogicalTest, Vector) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
ASSERT_TRUE(td()->Determine(mod())) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
op, std::make_unique<ast::IdentifierExpression>("val"),
@ -919,7 +920,7 @@ TEST_P(Expr_Binary_CompareTest, Scalar) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
op, std::make_unique<ast::IdentifierExpression>("val"),
@ -941,7 +942,7 @@ TEST_P(Expr_Binary_CompareTest, Vector) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
op, std::make_unique<ast::IdentifierExpression>("val"),
@ -970,7 +971,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Scalar) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -994,7 +995,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Scalar) {
mod()->AddGlobalVariable(std::move(vector));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -1020,7 +1021,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Vector) {
mod()->AddGlobalVariable(std::move(vector));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -1043,7 +1044,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Vector) {
mod()->AddGlobalVariable(std::move(vector));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -1069,7 +1070,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) {
mod()->AddGlobalVariable(std::move(matrix));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -1098,7 +1099,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Matrix) {
mod()->AddGlobalVariable(std::move(matrix));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -1128,7 +1129,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Vector) {
mod()->AddGlobalVariable(std::move(matrix));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -1155,7 +1156,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Matrix) {
mod()->AddGlobalVariable(std::move(matrix));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -1182,7 +1183,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Matrix) {
mod()->AddGlobalVariable(std::move(matrix2));
// Register the global
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
ASSERT_TRUE(td()->Determine()) << td()->error();
ast::BinaryExpression expr(
ast::BinaryOp::kMultiply,
@ -1213,7 +1214,7 @@ TEST_P(UnaryDerivativeExpressionTest, Expr_UnaryDerivative) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine((mod())));
EXPECT_TRUE(td()->Determine());
ast::UnaryDerivativeExpression der(
derivative, ast::DerivativeModifier::kNone,
@ -1248,7 +1249,7 @@ TEST_P(UnaryMethodExpressionBoolTest, Expr_UnaryMethod_Any) {
ast::UnaryMethodExpression exp(op, std::move(params));
// Register the variable
EXPECT_TRUE(td()->Determine((mod())));
EXPECT_TRUE(td()->Determine());
EXPECT_TRUE(td()->DetermineResultType(&exp));
ASSERT_NE(exp.result_type(), nullptr);
@ -1277,7 +1278,7 @@ TEST_P(UnaryMethodExpressionVecTest, Expr_UnaryMethod_Bool) {
ast::UnaryMethodExpression exp(op, std::move(params));
// Register the variable
EXPECT_TRUE(td()->Determine((mod())));
EXPECT_TRUE(td()->Determine());
EXPECT_TRUE(td()->DetermineResultType(&exp));
ASSERT_NE(exp.result_type(), nullptr);
@ -1300,7 +1301,7 @@ TEST_P(UnaryMethodExpressionVecTest, Expr_UnaryMethod_Vec) {
ast::UnaryMethodExpression exp(op, std::move(params));
// Register the variable
EXPECT_TRUE(td()->Determine((mod())));
EXPECT_TRUE(td()->Determine());
EXPECT_TRUE(td()->DetermineResultType(&exp));
ASSERT_NE(exp.result_type(), nullptr);
@ -1328,7 +1329,7 @@ TEST_F(TypeDeterminerTest, Expr_UnaryMethod_Dot) {
ast::UnaryMethodExpression exp(ast::UnaryMethod::kDot, std::move(params));
// Register the variable
EXPECT_TRUE(td()->Determine((mod())));
EXPECT_TRUE(td()->Determine());
EXPECT_TRUE(td()->DetermineResultType(&exp));
ASSERT_NE(exp.result_type(), nullptr);
@ -1355,7 +1356,7 @@ TEST_F(TypeDeterminerTest, Expr_UnaryMethod_OuterProduct) {
std::move(params));
// Register the variable
EXPECT_TRUE(td()->Determine((mod())));
EXPECT_TRUE(td()->Determine());
EXPECT_TRUE(td()->DetermineResultType(&exp));
ASSERT_NE(exp.result_type(), nullptr);
@ -1379,7 +1380,7 @@ TEST_P(UnaryOpExpressionTest, Expr_UnaryOp) {
mod()->AddGlobalVariable(std::move(var));
// Register the global
EXPECT_TRUE(td()->Determine((mod())));
EXPECT_TRUE(td()->Determine());
ast::UnaryOpExpression der(
op, std::make_unique<ast::IdentifierExpression>("ident"));
@ -1410,7 +1411,7 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) {
mod()->AddFunction(std::move(func));
EXPECT_TRUE(td()->Determine((mod()))) << td()->error();
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_EQ(var_ptr->storage_class(), ast::StorageClass::kFunction);
}
@ -1431,7 +1432,7 @@ TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) {
mod()->AddFunction(std::move(func));
EXPECT_TRUE(td()->Determine((mod()))) << td()->error();
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_EQ(var_ptr->storage_class(), ast::StorageClass::kNone);
}
@ -1450,7 +1451,7 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) {
mod()->AddFunction(std::move(func));
EXPECT_FALSE(td()->Determine((mod())));
EXPECT_FALSE(td()->Determine());
EXPECT_EQ(td()->error(),
"function variable has a non-function storage class");
}

View File

@ -61,10 +61,10 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -102,13 +102,13 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -151,10 +151,10 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -192,13 +192,13 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -241,10 +241,10 @@ TEST_P(BinaryArithFloatTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -283,13 +283,13 @@ TEST_P(BinaryArithFloatTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -325,10 +325,10 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -368,13 +368,13 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -414,10 +414,10 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -457,13 +457,13 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -503,10 +503,10 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -546,13 +546,13 @@ TEST_P(BinaryCompareFloatTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -596,14 +596,14 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -635,14 +635,14 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -667,7 +667,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@ -675,7 +676,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@ -705,7 +705,8 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@ -713,7 +714,6 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@ -752,7 +752,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@ -760,7 +761,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@ -801,7 +801,8 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@ -809,7 +810,6 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@ -840,7 +840,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@ -848,7 +849,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();

View File

@ -151,7 +151,8 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
ast::type::I32Type i32;
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::Variable var("var", ast::StorageClass::kPrivate, &i32);
@ -165,7 +166,6 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
@ -186,7 +186,8 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
ast::type::I32Type i32;
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::Variable var("var", ast::StorageClass::kNone, &i32);
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
@ -203,7 +204,6 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();

View File

@ -47,10 +47,10 @@ TEST_F(BuilderTest, If_Empty) {
ast::IfStatement expr(std::move(cond), ast::StatementList{});
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@ -89,12 +89,12 @@ TEST_F(BuilderTest, If_WithStatements) {
ast::IfStatement expr(std::move(cond), std::move(body));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@ -152,12 +152,12 @@ TEST_F(BuilderTest, If_WithElse) {
expr.set_else_statements(std::move(else_stmts));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@ -222,12 +222,12 @@ TEST_F(BuilderTest, If_WithElseIf) {
expr.set_else_statements(std::move(else_stmts));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@ -316,12 +316,12 @@ TEST_F(BuilderTest, If_WithMultiple) {
expr.set_else_statements(std::move(else_stmts));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();