Skip to content
Snippets Groups Projects

Issue/21

Merged Stéphane Del Pino requested to merge issue/21 into develop
2 files
+ 18
41
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -36,12 +36,14 @@ class PugsFunctionAdapter<OutputType(InputType...)>
template <size_t I>
[[nodiscard]] PUGS_INLINE static bool
_checkValidArgumentDataType(const ASTNode& arg_expression) noexcept
_checkValidArgumentDataType(const ASTNode& arg_expression) noexcept(NO_ASSERT)
{
using Arg = std::tuple_element_t<I, InputTuple>;
constexpr const ASTNodeDataType& expected_input_data_type = ast_node_data_type_from<Arg>;
const ASTNodeDataType& arg_data_type = arg_expression.m_data_type;
Assert(arg_expression.m_data_type == ASTNodeDataType::typename_t);
const ASTNodeDataType& arg_data_type = arg_expression.m_data_type.contentType();
return isNaturalConversion(expected_input_data_type, arg_data_type);
}
@@ -55,53 +57,28 @@ class PugsFunctionAdapter<OutputType(InputType...)>
}
[[nodiscard]] PUGS_INLINE static bool
_checkValidInputDataType(const ASTNode& input_expression) noexcept
_checkValidInputDomain(const ASTNode& input_domain_expression) noexcept
{
if constexpr (NArgs == 1) {
return _checkValidArgumentDataType<0>(input_expression);
return _checkValidArgumentDataType<0>(input_domain_expression);
} else {
if (input_expression.children.size() != NArgs) {
if ((input_domain_expression.m_data_type.contentType() != ASTNodeDataType::list_t) or
(input_domain_expression.children.size() != NArgs)) {
return false;
}
using IndexSequence = std::make_index_sequence<NArgs>;
return _checkAllInputDataType(input_expression, IndexSequence{});
return _checkAllInputDataType(input_domain_expression, IndexSequence{});
}
}
[[nodiscard]] PUGS_INLINE static bool
_checkValidOutputDataType(const ASTNode& return_expression) noexcept
_checkValidOutputDomain(const ASTNode& output_domain_expression) noexcept(NO_ASSERT)
{
constexpr const ASTNodeDataType& expected_return_data_type = ast_node_data_type_from<OutputType>;
const ASTNodeDataType& return_data_type = return_expression.m_data_type;
const ASTNodeDataType& return_data_type = output_domain_expression.m_data_type.contentType();
if (not isNaturalConversion(return_data_type, expected_return_data_type)) {
if (expected_return_data_type == ASTNodeDataType::vector_t) {
if (return_data_type == ASTNodeDataType::list_t) {
if (expected_return_data_type.dimension() != return_expression.children.size()) {
return false;
} else {
for (const auto& child : return_expression.children) {
const ASTNodeDataType& data_type = child->m_data_type;
if (not isNaturalConversion(data_type, ast_node_data_type_from<double>)) {
return false;
}
}
}
} else if ((expected_return_data_type.dimension() == 1) and
isNaturalConversion(return_data_type, ast_node_data_type_from<double>)) {
return true;
} else if (return_data_type == ast_node_data_type_from<int64_t>) {
// 0 is the only valid value for vectors
return (return_expression.string() == "0");
} else {
return false;
}
} else {
return false;
}
}
return true;
return isNaturalConversion(return_data_type, expected_return_data_type);
}
template <typename Arg, typename... RemainingArgs>
@@ -124,10 +101,10 @@ class PugsFunctionAdapter<OutputType(InputType...)>
PUGS_INLINE static void
_checkFunction(const FunctionDescriptor& function)
{
bool has_valid_input = _checkValidInputDataType(*function.definitionNode().children[0]);
bool has_valid_output = _checkValidOutputDataType(*function.definitionNode().children[1]);
bool has_valid_input_domain = _checkValidInputDomain(*function.domainMappingNode().children[0]);
bool has_valid_output = _checkValidOutputDomain(*function.domainMappingNode().children[1]);
if (not(has_valid_input and has_valid_output)) {
if (not(has_valid_input_domain and has_valid_output)) {
std::ostringstream error_message;
error_message << "invalid function type" << rang::style::reset << "\nnote: expecting " << rang::fgB::yellow
<< _getInputDataTypeName() << " -> " << dataTypeName(ast_node_data_type_from<OutputType>)
Loading