32 #ifndef _QORE_BUILTINFUNCTION_H
34 #define _QORE_BUILTINFUNCTION_H
42 class BuiltinSignature :
public AbstractFunctionSignature {
44 DLLLOCAL BuiltinSignature(
bool extra_args,
const QoreTypeInfo* n_returnTypeInfo,
const type_vec_t& n_typeList,
const arg_vec_t& n_defaultArgList,
const name_vec_t& n_names) : AbstractFunctionSignature(n_returnTypeInfo, n_typeList, n_defaultArgList, n_names) {
45 for (
unsigned i = 0; i < typeList.size(); ++i) {
46 bool hasDefaultArg = i < defaultArgList.size() && defaultArgList[i];
53 QoreTypeInfo::concatName(typeList[i], str);
54 if (names.size() > i && !names[i].empty()) {
60 addDefaultArgument(defaultArgList[i]);
63 if (i != (typeList.size() - 1))
67 if (!typeList.empty())
73 DLLLOCAL
virtual ~BuiltinSignature() {
76 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo()
const {
77 return returnTypeInfo;
80 DLLLOCAL
virtual const QoreParseTypeInfo* getParseParamTypeInfo(
unsigned num)
const {
86 #define COMMON_BUILTIN_VARIANT_FUNCTIONS DLLLOCAL virtual int64 getFunctionality() const { return functionality; } \
87 DLLLOCAL virtual AbstractFunctionSignature* getSignature() const { return const_cast<BuiltinSignature*>(&signature); } \
88 DLLLOCAL virtual const QoreTypeInfo* parseGetReturnTypeInfo() const { return signature.getReturnTypeInfo(); }
90 class BuiltinFunctionVariantBase {
92 BuiltinSignature signature;
97 signature(n_functionality & QCF_USES_EXTRA_ARGS, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names), functionality(n_functionality) {
102 class BuiltinFunctionValueVariant :
public AbstractQoreFunctionVariant,
public BuiltinFunctionVariantBase {
108 AbstractQoreFunctionVariant(n_flags), BuiltinFunctionVariantBase(n_functionality, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names), func(m) {
112 COMMON_BUILTIN_VARIANT_FUNCTIONS
114 DLLLOCAL
virtual QoreValue evalFunction(
const char* name, CodeEvaluationHelper& ceh,
ExceptionSink* xsink)
const {
115 CodeContextHelper cch(xsink, CT_BUILTIN, name);
117 return func(ceh.getArgs(), ceh.getRuntimeFlags(), xsink);
133 AbstractQoreFunctionVariant(n_flags), BuiltinFunctionVariantBase(n_functionality, n_returnTypeInfo,
134 n_typeList, n_defaultArgList, n_names), func(m), ptr(ptr) {
138 COMMON_BUILTIN_VARIANT_FUNCTIONS
140 DLLLOCAL
virtual QoreValue evalFunction(
const char* name, CodeEvaluationHelper& ceh,
ExceptionSink* xsink)
const {
141 CodeContextHelper cch(xsink, CT_BUILTIN, name);
143 return func(ptr, ceh.getArgs(), ceh.getRuntimeFlags(), xsink);
147 #endif // _QORE_BUILTIN_FUNCTION