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

Simplify unary operators registration

parent ddea58da
No related branches found
No related tags found
1 merge request!89Add missing compatibility check when affecting lists to R^d or R^dxd
......@@ -13,6 +13,7 @@ class IUnaryOperatorProcessorBuilder
public:
[[nodiscard]] virtual std::unique_ptr<INodeProcessor> getNodeProcessor(ASTNode& node) const = 0;
[[nodiscard]] virtual ASTNodeDataType getOperandDataType() const = 0;
[[nodiscard]] virtual ASTNodeDataType getReturnValueType() const = 0;
virtual ~IUnaryOperatorProcessorBuilder() = default;
......
......@@ -68,10 +68,11 @@ class OperatorRepository
const std::string binary_operator_type_name =
binaryOperatorMangler<BinaryOperatorTypeT>(processor_builder->getDataTypeOfA(),
processor_builder->getDataTypeOfB());
if (not m_binary_operator_builder_list
.try_emplace(binary_operator_type_name,
Descriptor{processor_builder->getReturnValueType(), processor_builder})
.second) {
if (auto [i_descriptor, success] =
m_binary_operator_builder_list.try_emplace(binary_operator_type_name,
Descriptor{processor_builder->getReturnValueType(),
processor_builder});
not success) {
// LCOV_EXCL_START
throw UnexpectedError(binary_operator_type_name + " has already an entry");
// LCOV_EXCL_STOP
......@@ -85,10 +86,11 @@ class OperatorRepository
const std::shared_ptr<const IAffectationProcessorBuilder>& processor_builder)
{
const std::string affectation_type_name = affectationMangler<OperatorTypeT>(lhs_type, rhs_type);
if (not m_affectation_builder_list
.try_emplace(affectation_type_name,
Descriptor{ASTNodeDataType::build<ASTNodeDataType::void_t>(), processor_builder})
.second) {
if (auto [i_descriptor, success] =
m_affectation_builder_list.try_emplace(affectation_type_name,
Descriptor{ASTNodeDataType::build<ASTNodeDataType::void_t>(),
processor_builder});
not success) {
// LCOV_EXCL_START
throw UnexpectedError(affectation_type_name + " has already an entry");
// LCOV_EXCL_STOP
......@@ -114,10 +116,10 @@ class OperatorRepository
template <typename OperatorTypeT>
void
addUnaryOperator(const ASTNodeDataType& operand_type,
const std::shared_ptr<const IUnaryOperatorProcessorBuilder>& processor_builder)
addUnaryOperator(const std::shared_ptr<const IUnaryOperatorProcessorBuilder>& processor_builder)
{
const std::string unary_operator_type_name = unaryOperatorMangler<OperatorTypeT>(operand_type);
const std::string unary_operator_type_name =
unaryOperatorMangler<OperatorTypeT>(processor_builder->getOperandDataType());
if (auto [i_descriptor, success] =
m_unary_operator_builder_list.try_emplace(unary_operator_type_name,
Descriptor{processor_builder->getReturnValueType(),
......
......@@ -15,6 +15,12 @@ class UnaryOperatorProcessorBuilder final : public IUnaryOperatorProcessorBuilde
public:
UnaryOperatorProcessorBuilder() = default;
ASTNodeDataType
getOperandDataType() const
{
return ast_node_data_type_from<DataT>;
}
ASTNodeDataType
getReturnValueType() const
{
......
......@@ -8,10 +8,8 @@ UnaryOperatorRegisterForB::_register_unary_minus()
{
OperatorRepository& repository = OperatorRepository::instance();
auto B = ASTNodeDataType::build<ASTNodeDataType::bool_t>();
repository.addUnaryOperator<
language::unary_minus>(B, std::make_shared<UnaryOperatorProcessorBuilder<language::unary_minus, int64_t, bool>>());
repository.addUnaryOperator<language::unary_minus>(
std::make_shared<UnaryOperatorProcessorBuilder<language::unary_minus, int64_t, bool>>());
}
void
......@@ -19,10 +17,8 @@ UnaryOperatorRegisterForB::_register_unary_not()
{
OperatorRepository& repository = OperatorRepository::instance();
auto B = ASTNodeDataType::build<ASTNodeDataType::bool_t>();
repository.addUnaryOperator<
language::unary_not>(B, std::make_shared<UnaryOperatorProcessorBuilder<language::unary_not, bool, bool>>());
repository.addUnaryOperator<language::unary_not>(
std::make_shared<UnaryOperatorProcessorBuilder<language::unary_not, bool, bool>>());
}
UnaryOperatorRegisterForB::UnaryOperatorRegisterForB()
......
......@@ -8,10 +8,7 @@ UnaryOperatorRegisterForN::_register_unary_minus()
{
OperatorRepository& repository = OperatorRepository::instance();
auto N = ASTNodeDataType::build<ASTNodeDataType::unsigned_int_t>();
repository.addUnaryOperator<
language::unary_minus>(N,
repository.addUnaryOperator<language::unary_minus>(
std::make_shared<UnaryOperatorProcessorBuilder<language::unary_minus, int64_t, uint64_t>>());
}
......
......@@ -8,10 +8,8 @@ UnaryOperatorRegisterForR::_register_unary_minus()
{
OperatorRepository& repository = OperatorRepository::instance();
auto R = ASTNodeDataType::build<ASTNodeDataType::double_t>();
repository.addUnaryOperator<
language::unary_minus>(R, std::make_shared<UnaryOperatorProcessorBuilder<language::unary_minus, double, double>>());
repository.addUnaryOperator<language::unary_minus>(
std::make_shared<UnaryOperatorProcessorBuilder<language::unary_minus, double, double>>());
}
UnaryOperatorRegisterForR::UnaryOperatorRegisterForR()
......
......@@ -9,12 +9,9 @@ UnaryOperatorRegisterForRn<Dimension>::_register_unary_minus()
{
OperatorRepository& repository = OperatorRepository::instance();
auto Rn = ASTNodeDataType::build<ASTNodeDataType::vector_t>(Dimension);
repository
.addUnaryOperator<language::unary_minus>(Rn,
std::make_shared<UnaryOperatorProcessorBuilder<
language::unary_minus, TinyVector<Dimension>, TinyVector<Dimension>>>());
repository.addUnaryOperator<language::unary_minus>(
std::make_shared<
UnaryOperatorProcessorBuilder<language::unary_minus, TinyVector<Dimension>, TinyVector<Dimension>>>());
}
template <size_t Dimension>
......
......@@ -9,12 +9,9 @@ UnaryOperatorRegisterForRnxn<Dimension>::_register_unary_minus()
{
OperatorRepository& repository = OperatorRepository::instance();
auto Rnxn = ASTNodeDataType::build<ASTNodeDataType::matrix_t>(Dimension, Dimension);
repository
.addUnaryOperator<language::unary_minus>(Rnxn,
std::make_shared<UnaryOperatorProcessorBuilder<
language::unary_minus, TinyMatrix<Dimension>, TinyMatrix<Dimension>>>());
repository.addUnaryOperator<language::unary_minus>(
std::make_shared<
UnaryOperatorProcessorBuilder<language::unary_minus, TinyMatrix<Dimension>, TinyMatrix<Dimension>>>());
}
template <size_t Dimension>
......
......@@ -8,10 +8,7 @@ UnaryOperatorRegisterForZ::_register_unary_minus()
{
OperatorRepository& repository = OperatorRepository::instance();
auto Z = ASTNodeDataType::build<ASTNodeDataType::int_t>();
repository.addUnaryOperator<
language::unary_minus>(Z,
repository.addUnaryOperator<language::unary_minus>(
std::make_shared<UnaryOperatorProcessorBuilder<language::unary_minus, int64_t, int64_t>>());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment