[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:
parent
cd077b01a9
commit
b950e80a59
|
@ -305,8 +305,8 @@ int main(int argc, const char** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tint::TypeDeterminer td(&ctx);
|
tint::TypeDeterminer td(&ctx, &mod);
|
||||||
if (!td.Determine(&mod)) {
|
if (!td.Determine()) {
|
||||||
std::cerr << td.error() << std::endl;
|
std::cerr << td.error() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,8 @@
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
|
|
||||||
TypeDeterminer::TypeDeterminer(Context* ctx) : ctx_(*ctx) {}
|
TypeDeterminer::TypeDeterminer(Context* ctx, ast::Module* mod)
|
||||||
|
: ctx_(*ctx), mod_(mod) {}
|
||||||
|
|
||||||
TypeDeterminer::~TypeDeterminer() = default;
|
TypeDeterminer::~TypeDeterminer() = default;
|
||||||
|
|
||||||
|
@ -61,16 +62,16 @@ void TypeDeterminer::set_error(const Source& src, const std::string& msg) {
|
||||||
error_ += msg;
|
error_ += msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TypeDeterminer::Determine(ast::Module* mod) {
|
bool TypeDeterminer::Determine() {
|
||||||
for (const auto& var : mod->global_variables()) {
|
for (const auto& var : mod_->global_variables()) {
|
||||||
variable_stack_.set_global(var->name(), var.get());
|
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();
|
name_to_function_[func->name()] = func.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DetermineFunctions(mod->functions())) {
|
if (!DetermineFunctions(mod_->functions())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -46,16 +46,15 @@ class TypeDeterminer {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param ctx the tint context
|
/// @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();
|
~TypeDeterminer();
|
||||||
|
|
||||||
/// @returns error messages from the type determiner
|
/// @returns error messages from the type determiner
|
||||||
const std::string& error() { return error_; }
|
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
|
/// @returns true if the type determiner was successful
|
||||||
bool Determine(ast::Module* mod);
|
bool Determine();
|
||||||
/// Determines type information for functions
|
/// Determines type information for functions
|
||||||
/// @param funcs the functions to check
|
/// @param funcs the functions to check
|
||||||
/// @returns true if the determination was successful
|
/// @returns true if the determination was successful
|
||||||
|
@ -104,6 +103,7 @@ class TypeDeterminer {
|
||||||
bool DetermineUnaryOp(ast::UnaryOpExpression* expr);
|
bool DetermineUnaryOp(ast::UnaryOpExpression* expr);
|
||||||
|
|
||||||
Context& ctx_;
|
Context& ctx_;
|
||||||
|
ast::Module* mod_;
|
||||||
std::string error_;
|
std::string error_;
|
||||||
ScopeStack<ast::Variable*> variable_stack_;
|
ScopeStack<ast::Variable*> variable_stack_;
|
||||||
std::unordered_map<std::string, ast::Function*> name_to_function_;
|
std::unordered_map<std::string, ast::Function*> name_to_function_;
|
||||||
|
|
|
@ -70,7 +70,8 @@ class FakeExpr : public ast::Expression {
|
||||||
|
|
||||||
class TypeDeterminerHelper {
|
class TypeDeterminerHelper {
|
||||||
public:
|
public:
|
||||||
TypeDeterminerHelper() : td_(std::make_unique<TypeDeterminer>(&ctx_)) {}
|
TypeDeterminerHelper()
|
||||||
|
: td_(std::make_unique<TypeDeterminer>(&ctx_, &mod_)) {}
|
||||||
|
|
||||||
TypeDeterminer* td() const { return td_.get(); }
|
TypeDeterminer* td() const { return td_.get(); }
|
||||||
ast::Module* mod() { return &mod_; }
|
ast::Module* mod() { return &mod_; }
|
||||||
|
@ -435,7 +436,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::ArrayAccessorExpression acc(
|
ast::ArrayAccessorExpression acc(
|
||||||
std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
|
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));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::ArrayAccessorExpression acc(
|
ast::ArrayAccessorExpression acc(
|
||||||
std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
|
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));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::ArrayAccessorExpression acc(
|
ast::ArrayAccessorExpression acc(
|
||||||
std::make_unique<ast::ArrayAccessorExpression>(
|
std::make_unique<ast::ArrayAccessorExpression>(
|
||||||
|
@ -505,7 +506,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Vector) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::ArrayAccessorExpression acc(
|
ast::ArrayAccessorExpression acc(
|
||||||
std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
|
std::make_unique<ast::IdentifierExpression>("my_var"), std::move(idx));
|
||||||
|
@ -533,7 +534,7 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
|
||||||
mod()->AddFunction(std::move(func));
|
mod()->AddFunction(std::move(func));
|
||||||
|
|
||||||
// Register the function
|
// Register the function
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::ExpressionList call_params;
|
ast::ExpressionList call_params;
|
||||||
ast::CallExpression call(
|
ast::CallExpression call(
|
||||||
|
@ -553,7 +554,7 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
|
||||||
mod()->AddFunction(std::move(func));
|
mod()->AddFunction(std::move(func));
|
||||||
|
|
||||||
// Register the function
|
// Register the function
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::ExpressionList call_params;
|
ast::ExpressionList call_params;
|
||||||
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -617,7 +618,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_GlobalVariable) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::IdentifierExpression ident("my_var");
|
ast::IdentifierExpression ident("my_var");
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&ident));
|
EXPECT_TRUE(td()->DetermineResultType(&ident));
|
||||||
|
@ -658,7 +659,7 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function) {
|
||||||
mod()->AddFunction(std::move(func));
|
mod()->AddFunction(std::move(func));
|
||||||
|
|
||||||
// Register the function
|
// Register the function
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::IdentifierExpression ident("my_func");
|
ast::IdentifierExpression ident("my_func");
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&ident));
|
EXPECT_TRUE(td()->DetermineResultType(&ident));
|
||||||
|
@ -688,7 +689,7 @@ TEST_F(TypeDeterminerTest, Expr_MemberAccessor_Struct) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto ident = std::make_unique<ast::IdentifierExpression>("my_struct");
|
auto ident = std::make_unique<ast::IdentifierExpression>("my_struct");
|
||||||
auto mem_ident = std::make_unique<ast::IdentifierExpression>("second_member");
|
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));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto ident = std::make_unique<ast::IdentifierExpression>("my_vec");
|
auto ident = std::make_unique<ast::IdentifierExpression>("my_vec");
|
||||||
auto swizzle = std::make_unique<ast::IdentifierExpression>("xy");
|
auto swizzle = std::make_unique<ast::IdentifierExpression>("xy");
|
||||||
|
@ -776,7 +777,7 @@ TEST_F(TypeDeterminerTest, Expr_MultiLevel) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine(mod()));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
auto ident = std::make_unique<ast::IdentifierExpression>("c");
|
auto ident = std::make_unique<ast::IdentifierExpression>("c");
|
||||||
auto mem_ident = std::make_unique<ast::IdentifierExpression>("mem");
|
auto mem_ident = std::make_unique<ast::IdentifierExpression>("mem");
|
||||||
|
@ -811,7 +812,7 @@ TEST_P(Expr_Binary_BitwiseTest, Scalar) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine(mod())) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
op, std::make_unique<ast::IdentifierExpression>("val"),
|
op, std::make_unique<ast::IdentifierExpression>("val"),
|
||||||
|
@ -833,7 +834,7 @@ TEST_P(Expr_Binary_BitwiseTest, Vector) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine(mod())) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
op, std::make_unique<ast::IdentifierExpression>("val"),
|
op, std::make_unique<ast::IdentifierExpression>("val"),
|
||||||
|
@ -869,7 +870,7 @@ TEST_P(Expr_Binary_LogicalTest, Scalar) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
op, std::make_unique<ast::IdentifierExpression>("val"),
|
op, std::make_unique<ast::IdentifierExpression>("val"),
|
||||||
|
@ -891,7 +892,7 @@ TEST_P(Expr_Binary_LogicalTest, Vector) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine(mod())) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
op, std::make_unique<ast::IdentifierExpression>("val"),
|
op, std::make_unique<ast::IdentifierExpression>("val"),
|
||||||
|
@ -919,7 +920,7 @@ TEST_P(Expr_Binary_CompareTest, Scalar) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
op, std::make_unique<ast::IdentifierExpression>("val"),
|
op, std::make_unique<ast::IdentifierExpression>("val"),
|
||||||
|
@ -941,7 +942,7 @@ TEST_P(Expr_Binary_CompareTest, Vector) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
op, std::make_unique<ast::IdentifierExpression>("val"),
|
op, std::make_unique<ast::IdentifierExpression>("val"),
|
||||||
|
@ -970,7 +971,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Scalar) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -994,7 +995,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Scalar) {
|
||||||
mod()->AddGlobalVariable(std::move(vector));
|
mod()->AddGlobalVariable(std::move(vector));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -1020,7 +1021,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Vector) {
|
||||||
mod()->AddGlobalVariable(std::move(vector));
|
mod()->AddGlobalVariable(std::move(vector));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -1043,7 +1044,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Vector) {
|
||||||
mod()->AddGlobalVariable(std::move(vector));
|
mod()->AddGlobalVariable(std::move(vector));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -1069,7 +1070,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) {
|
||||||
mod()->AddGlobalVariable(std::move(matrix));
|
mod()->AddGlobalVariable(std::move(matrix));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -1098,7 +1099,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Matrix) {
|
||||||
mod()->AddGlobalVariable(std::move(matrix));
|
mod()->AddGlobalVariable(std::move(matrix));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -1128,7 +1129,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Vector) {
|
||||||
mod()->AddGlobalVariable(std::move(matrix));
|
mod()->AddGlobalVariable(std::move(matrix));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -1155,7 +1156,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Matrix) {
|
||||||
mod()->AddGlobalVariable(std::move(matrix));
|
mod()->AddGlobalVariable(std::move(matrix));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -1182,7 +1183,7 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Matrix) {
|
||||||
mod()->AddGlobalVariable(std::move(matrix2));
|
mod()->AddGlobalVariable(std::move(matrix2));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
ASSERT_TRUE(td()->Determine((mod()))) << td()->error();
|
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||||
|
|
||||||
ast::BinaryExpression expr(
|
ast::BinaryExpression expr(
|
||||||
ast::BinaryOp::kMultiply,
|
ast::BinaryOp::kMultiply,
|
||||||
|
@ -1213,7 +1214,7 @@ TEST_P(UnaryDerivativeExpressionTest, Expr_UnaryDerivative) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine((mod())));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::UnaryDerivativeExpression der(
|
ast::UnaryDerivativeExpression der(
|
||||||
derivative, ast::DerivativeModifier::kNone,
|
derivative, ast::DerivativeModifier::kNone,
|
||||||
|
@ -1248,7 +1249,7 @@ TEST_P(UnaryMethodExpressionBoolTest, Expr_UnaryMethod_Any) {
|
||||||
ast::UnaryMethodExpression exp(op, std::move(params));
|
ast::UnaryMethodExpression exp(op, std::move(params));
|
||||||
|
|
||||||
// Register the variable
|
// Register the variable
|
||||||
EXPECT_TRUE(td()->Determine((mod())));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
||||||
ASSERT_NE(exp.result_type(), nullptr);
|
ASSERT_NE(exp.result_type(), nullptr);
|
||||||
|
@ -1277,7 +1278,7 @@ TEST_P(UnaryMethodExpressionVecTest, Expr_UnaryMethod_Bool) {
|
||||||
ast::UnaryMethodExpression exp(op, std::move(params));
|
ast::UnaryMethodExpression exp(op, std::move(params));
|
||||||
|
|
||||||
// Register the variable
|
// Register the variable
|
||||||
EXPECT_TRUE(td()->Determine((mod())));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
||||||
ASSERT_NE(exp.result_type(), nullptr);
|
ASSERT_NE(exp.result_type(), nullptr);
|
||||||
|
@ -1300,7 +1301,7 @@ TEST_P(UnaryMethodExpressionVecTest, Expr_UnaryMethod_Vec) {
|
||||||
ast::UnaryMethodExpression exp(op, std::move(params));
|
ast::UnaryMethodExpression exp(op, std::move(params));
|
||||||
|
|
||||||
// Register the variable
|
// Register the variable
|
||||||
EXPECT_TRUE(td()->Determine((mod())));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
||||||
ASSERT_NE(exp.result_type(), nullptr);
|
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));
|
ast::UnaryMethodExpression exp(ast::UnaryMethod::kDot, std::move(params));
|
||||||
|
|
||||||
// Register the variable
|
// Register the variable
|
||||||
EXPECT_TRUE(td()->Determine((mod())));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
||||||
ASSERT_NE(exp.result_type(), nullptr);
|
ASSERT_NE(exp.result_type(), nullptr);
|
||||||
|
@ -1355,7 +1356,7 @@ TEST_F(TypeDeterminerTest, Expr_UnaryMethod_OuterProduct) {
|
||||||
std::move(params));
|
std::move(params));
|
||||||
|
|
||||||
// Register the variable
|
// Register the variable
|
||||||
EXPECT_TRUE(td()->Determine((mod())));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
EXPECT_TRUE(td()->DetermineResultType(&exp));
|
||||||
ASSERT_NE(exp.result_type(), nullptr);
|
ASSERT_NE(exp.result_type(), nullptr);
|
||||||
|
@ -1379,7 +1380,7 @@ TEST_P(UnaryOpExpressionTest, Expr_UnaryOp) {
|
||||||
mod()->AddGlobalVariable(std::move(var));
|
mod()->AddGlobalVariable(std::move(var));
|
||||||
|
|
||||||
// Register the global
|
// Register the global
|
||||||
EXPECT_TRUE(td()->Determine((mod())));
|
EXPECT_TRUE(td()->Determine());
|
||||||
|
|
||||||
ast::UnaryOpExpression der(
|
ast::UnaryOpExpression der(
|
||||||
op, std::make_unique<ast::IdentifierExpression>("ident"));
|
op, std::make_unique<ast::IdentifierExpression>("ident"));
|
||||||
|
@ -1410,7 +1411,7 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) {
|
||||||
|
|
||||||
mod()->AddFunction(std::move(func));
|
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);
|
EXPECT_EQ(var_ptr->storage_class(), ast::StorageClass::kFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1431,7 +1432,7 @@ TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) {
|
||||||
|
|
||||||
mod()->AddFunction(std::move(func));
|
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);
|
EXPECT_EQ(var_ptr->storage_class(), ast::StorageClass::kNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1450,7 +1451,7 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) {
|
||||||
|
|
||||||
mod()->AddFunction(std::move(func));
|
mod()->AddFunction(std::move(func));
|
||||||
|
|
||||||
EXPECT_FALSE(td()->Determine((mod())));
|
EXPECT_FALSE(td()->Determine());
|
||||||
EXPECT_EQ(td()->error(),
|
EXPECT_EQ(td()->error(),
|
||||||
"function variable has a non-function storage class");
|
"function variable has a non-function storage class");
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,10 +61,10 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -102,13 +102,13 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -151,10 +151,10 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -192,13 +192,13 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -241,10 +241,10 @@ TEST_P(BinaryArithFloatTest, Scalar) {
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -283,13 +283,13 @@ TEST_P(BinaryArithFloatTest, Vector) {
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -325,10 +325,10 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -368,13 +368,13 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -414,10 +414,10 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -457,13 +457,13 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -503,10 +503,10 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -546,13 +546,13 @@ TEST_P(BinaryCompareFloatTest, Vector) {
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -596,14 +596,14 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
|
||||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||||
std::move(rhs));
|
std::move(rhs));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -635,14 +635,14 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
|
||||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||||
std::move(rhs));
|
std::move(rhs));
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -667,7 +667,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
|
||||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
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");
|
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
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));
|
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
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");
|
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
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");
|
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
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();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||||
|
|
|
@ -151,7 +151,8 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::Variable var("var", ast::StorageClass::kPrivate, &i32);
|
ast::Variable var("var", ast::StorageClass::kPrivate, &i32);
|
||||||
|
|
||||||
|
@ -165,7 +166,6 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
||||||
|
@ -186,7 +186,8 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
|
||||||
ast::type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
|
|
||||||
ast::Variable var("var", ast::StorageClass::kNone, &i32);
|
ast::Variable var("var", ast::StorageClass::kNone, &i32);
|
||||||
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
@ -203,7 +204,6 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
|
||||||
|
|
|
@ -47,10 +47,10 @@ TEST_F(BuilderTest, If_Empty) {
|
||||||
ast::IfStatement expr(std::move(cond), ast::StatementList{});
|
ast::IfStatement expr(std::move(cond), ast::StatementList{});
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
|
|
||||||
|
@ -89,12 +89,12 @@ TEST_F(BuilderTest, If_WithStatements) {
|
||||||
ast::IfStatement expr(std::move(cond), std::move(body));
|
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
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));
|
expr.set_else_statements(std::move(else_stmts));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
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));
|
expr.set_else_statements(std::move(else_stmts));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
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));
|
expr.set_else_statements(std::move(else_stmts));
|
||||||
|
|
||||||
Context ctx;
|
Context ctx;
|
||||||
TypeDeterminer td(&ctx);
|
ast::Module mod;
|
||||||
|
TypeDeterminer td(&ctx, &mod);
|
||||||
td.RegisterVariableForTesting(var.get());
|
td.RegisterVariableForTesting(var.get());
|
||||||
|
|
||||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||||
|
|
||||||
ast::Module mod;
|
|
||||||
Builder b(&mod);
|
Builder b(&mod);
|
||||||
b.push_function(Function{});
|
b.push_function(Function{});
|
||||||
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
|
||||||
|
|
Loading…
Reference in New Issue