Skip to content
Snippets Groups Projects
Commit 39e8b549 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Change unary operator expression builder

One now use OperatorRepository
parent 46f9c3d9
No related branches found
No related tags found
1 merge request!70Feature/language reduce static
#ifndef UNARY_OPERATOR_REGISTER_FOR_R3_HPP
#define UNARY_OPERATOR_REGISTER_FOR_R3_HPP
#include <language/utils/OperatorRepository.hpp>
class UnaryOperatorRegisterForR3
{
private:
void _register_unary_minus();
public:
UnaryOperatorRegisterForR3();
};
#endif // UNARY_OPERATOR_REGISTER_FOR_R3_HPP
#include <language/utils/UnaryOperatorRegisterForZ.hpp>
#include <language/utils/OperatorRepository.hpp>
#include <language/utils/UnaryOperatorProcessorBuilder.hpp>
void
UnaryOperatorRegisterForZ::_register_unary_minus()
{
OperatorRepository& repository = OperatorRepository::instance();
auto Z = ASTNodeDataType::build<ASTNodeDataType::int_t>();
repository.addUnaryOperator<
language::unary_minus>(Z,
std::make_shared<UnaryOperatorProcessorBuilder<language::unary_minus, int64_t, int64_t>>());
}
UnaryOperatorRegisterForZ::UnaryOperatorRegisterForZ()
{
this->_register_unary_minus();
}
#ifndef UNARY_OPERATOR_REGISTER_FOR_Z_HPP
#define UNARY_OPERATOR_REGISTER_FOR_Z_HPP
#include <language/utils/OperatorRepository.hpp>
class UnaryOperatorRegisterForZ
{
private:
void _register_unary_minus();
public:
UnaryOperatorRegisterForZ();
};
#endif // UNARY_OPERATOR_REGISTER_FOR_Z_HPP
......@@ -191,27 +191,13 @@ not b;
SECTION("Errors")
{
SECTION("Invalid unary operator")
{
auto ast = std::make_unique<ASTNode>();
REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast}, "unexpected error: undefined unary operator");
}
SECTION("Invalid unary operator")
{
auto ast = std::make_unique<ASTNode>();
REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast}, "unexpected error: undefined unary operator");
}
SECTION("Invalid value type for unary minus")
{
auto ast = std::make_unique<ASTNode>();
ast->set_type<language::unary_minus>();
ast->children.emplace_back(std::make_unique<ASTNode>());
REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast}, "undefined value type for unary operator");
REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast}, "undefined unary operator type: - undefined");
}
SECTION("errors")
......@@ -228,18 +214,7 @@ not b;
ast->set_type<language::unary_not>();
ast->children.emplace_back(std::make_unique<ASTNode>());
REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast}, "undefined value type for unary operator");
}
SECTION("Invalid data type for unary operator")
{
auto ast = std::make_unique<ASTNode>();
ast->set_type<language::unary_minus>();
ast->m_data_type = ASTNodeDataType::build<ASTNodeDataType::int_t>();
ast->children.emplace_back(std::make_unique<ASTNode>());
REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast},
"unexpected error: invalid operand type for unary operator");
REQUIRE_THROWS_WITH(ASTNodeUnaryOperatorExpressionBuilder{*ast}, "undefined unary operator type: not undefined");
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment