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

Treat the case of CFunction arguments

Cannot perform invalid implicit conversions at call for arguments.

Related to issue #16
parent 0bbc76f5
No related branches found
No related tags found
2 merge requests!37Feature/language,!27Issue/16
......@@ -4,6 +4,7 @@
#include <SymbolTable.hpp>
#include <ASTNodeDataTypeFlattener.hpp>
#include <ASTNodeNaturalConversionChecker.hpp>
#include <node_processor/CFunctionProcessor.hpp>
......@@ -29,7 +30,7 @@ ASTNodeCFunctionExpressionBuilder::_getArgumentConverter(const ASTNodeDataType&
return std::make_unique<FunctionArgumentConverter<ParameterT, double>>(argument_number);
}
default: {
throw parse_error("invalid argument type for function",
throw parse_error("unexpected error: invalid argument type for function",
std::vector{argument_node_sub_data_type.m_parent_node.begin()});
}
}
......@@ -56,6 +57,9 @@ ASTNodeCFunctionExpressionBuilder::_getArgumentConverter(const ASTNodeDataType&
}
};
ASTNodeNaturalConversionChecker{argument_node_sub_data_type.m_parent_node, argument_node_sub_data_type.m_data_type,
parameter_type};
return get_function_argument_converter_for_argument_type();
}
......
......@@ -199,22 +199,6 @@ RtoR(true);
SECTION("Z -> R")
{
SECTION("from R")
{
std::string_view data = R"(
ZtoR(1.);
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:CFunctionProcessor)
+-(language::name:ZtoR:NameProcessor)
`-(language::real:1.:ValueProcessor)
)";
CHECK_AST(data, result);
}
SECTION("from Z")
{
std::string_view data = R"(
......@@ -267,22 +251,6 @@ ZtoR(true);
SECTION("N -> R")
{
SECTION("from R")
{
std::string_view data = R"(
NtoR(1.);
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:CFunctionProcessor)
+-(language::name:NtoR:NameProcessor)
`-(language::real:1.:ValueProcessor)
)";
CHECK_AST(data, result);
}
SECTION("from Z")
{
std::string_view data = R"(
......@@ -335,55 +303,6 @@ NtoR(true);
SECTION("B -> R")
{
SECTION("from R")
{
std::string_view data = R"(
BtoR(1.);
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:CFunctionProcessor)
+-(language::name:BtoR:NameProcessor)
`-(language::real:1.:ValueProcessor)
)";
CHECK_AST(data, result);
}
SECTION("from Z")
{
std::string_view data = R"(
BtoR(1);
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:CFunctionProcessor)
+-(language::name:BtoR:NameProcessor)
`-(language::integer:1:ValueProcessor)
)";
CHECK_AST(data, result);
}
SECTION("from N")
{
std::string_view data = R"(
N n = 1;
BtoR(n);
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:CFunctionProcessor)
+-(language::name:BtoR:NameProcessor)
`-(language::name:n:NameProcessor)
)";
CHECK_AST(data, result);
}
SECTION("from B")
{
std::string_view data = R"(
......@@ -442,7 +361,7 @@ R2toB(3);
std::string_view data = R"(
RtoR("foo");
)";
CHECK_AST_THROWS_WITH(data, std::string{"invalid argument type for function"});
CHECK_AST_THROWS_WITH(data, std::string{"invalid implicit conversion: string -> R"});
}
SECTION("invalid function parameter type")
......@@ -450,7 +369,7 @@ RtoR("foo");
std::string_view data = R"(
StoB_invalid(3);
)";
CHECK_AST_THROWS_WITH(data, std::string{"unexpected error: undefined parameter type"});
CHECK_AST_THROWS_WITH(data, std::string{"invalid implicit conversion: Z -> undefined"});
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment