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

Add argument-less builtin-functions management

parent 2ff003b6
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -147,13 +147,9 @@ ASTNodeBuiltinFunctionExpressionBuilder::_buildArgumentProcessors(
throw parse_error(error_message.str(), argument_nodes.begin());
}
if (arguments_number > 1) {
for (size_t i = 0; i < arguments_number; ++i) {
this->_storeArgumentProcessor(parameter_type_list, flattened_datatype_list, i, _processor);
}
} else {
this->_storeArgumentProcessor(parameter_type_list, flattened_datatype_list, 0, _processor);
}
}
ASTNodeBuiltinFunctionExpressionBuilder::ASTNodeBuiltinFunctionExpressionBuilder(ASTNode& node)
......
......@@ -167,4 +167,47 @@ class BuiltinFunctionEmbedder : public IBuiltinFunctionEmbedder
}
};
template <typename FX>
class BuiltinFunctionEmbedder<FX, void> : public IBuiltinFunctionEmbedder
{
private:
std::function<FX(void)> m_f;
public:
PUGS_INLINE ASTNodeDataType
getReturnDataType() const final
{
return ast_node_data_type_from<FX>;
}
PUGS_INLINE std::vector<ASTNodeDataType>
getParameterDataTypes() const final
{
return {};
}
PUGS_INLINE size_t
numberOfParameters() const final
{
return 0;
}
public:
PUGS_INLINE
DataVariant
apply(const std::vector<DataVariant>&) const final
{
if constexpr (std::is_arithmetic_v<FX>) {
return {m_f()};
} else if constexpr (std::is_same_v<FX, void>) {
m_f();
return {};
} else {
return EmbeddedData(_createHandler(m_f()));
}
}
BuiltinFunctionEmbedder(std::function<void(void)> f) : m_f(f) {}
};
#endif // BUILTIN_FUNCTION_EMBEDDER_HPP
......@@ -149,7 +149,7 @@ struct expression;
struct parented_expression : if_must< open_parent, expression, close_parent >{};
struct tuple_expression;
struct function_argument_list : if_must< open_parent, list_must< sor< tuple_expression, expression >, COMMA >, close_parent >{};
struct function_argument_list : if_must< open_parent, opt< list_must< sor< tuple_expression, expression >, COMMA > >, close_parent >{};
struct function_evaluation : seq< NAME, function_argument_list > {};
struct primary_expression : sor< BOOL, REAL, INTEGER, LITERAL, function_evaluation, NAME, parented_expression > {};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment