32 #ifndef _QORE_FUNCTION_H
34 #define _QORE_FUNCTION_H
42 #include "qore/intern/QoreListNodeEvalOptionalRefHolder.h"
44 class qore_class_private;
51 class QoreOperatorNode;
54 class qore_class_private;
55 class qore_ns_private;
57 typedef std::vector<QoreParseTypeInfo*> ptype_vec_t;
58 typedef std::vector<LocalVar*> lvar_vec_t;
60 class AbstractFunctionSignature {
62 unsigned short num_param_types = 0,
65 const QoreTypeInfo* returnTypeInfo;
74 DLLLOCAL AbstractFunctionSignature(
const QoreTypeInfo* n_returnTypeInfo =
nullptr) : returnTypeInfo(n_returnTypeInfo) {
77 DLLLOCAL AbstractFunctionSignature(
const QoreTypeInfo* n_returnTypeInfo,
const type_vec_t& n_typeList,
const arg_vec_t& n_defaultArgList,
const name_vec_t& n_names) : returnTypeInfo(n_returnTypeInfo), typeList(n_typeList), defaultArgList(n_defaultArgList), names(n_names) {
80 DLLLOCAL
virtual ~AbstractFunctionSignature() {
82 for (arg_vec_t::iterator i = defaultArgList.begin(), e = defaultArgList.end(); i != e; ++i) {
83 (*i).discard(
nullptr);
88 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo()
const = 0;
90 DLLLOCAL
virtual const QoreParseTypeInfo* getParseParamTypeInfo(
unsigned num)
const = 0;
92 DLLLOCAL
const QoreTypeInfo* getReturnTypeInfo()
const {
93 return returnTypeInfo;
96 DLLLOCAL
const arg_vec_t& getDefaultArgList()
const {
97 return defaultArgList;
100 DLLLOCAL
const type_vec_t& getTypeList()
const {
104 DLLLOCAL
const name_vec_t& getParamNames()
const {
109 assert(i < defaultArgList.size());
110 return defaultArgList[i].eval(xsink);
113 DLLLOCAL
const char* getSignatureText()
const {
117 DLLLOCAL
virtual void addAbstractParameterSignature(std::string& str)
const {
118 for (
unsigned i = 0; i < typeList.size(); ++i) {
119 str.append(QoreTypeInfo::getName(typeList[i]));
120 if (i != typeList.size() - 1)
125 DLLLOCAL
unsigned numParams()
const {
126 return (
unsigned)typeList.size();
130 DLLLOCAL
unsigned getParamTypes()
const {
131 return num_param_types;
134 DLLLOCAL
unsigned getMinParamTypes()
const {
135 return min_param_types;
138 DLLLOCAL
const QoreTypeInfo* getParamTypeInfo(
unsigned num)
const {
139 return num >= typeList.size() ? 0 : typeList[num];
142 DLLLOCAL
bool hasDefaultArg(
unsigned i)
const {
143 return i >= defaultArgList.size() || !defaultArgList[i] ? false :
true;
147 DLLLOCAL
void addDefaultArgument(
QoreValue arg);
149 DLLLOCAL
const char* getName(
unsigned i)
const {
150 return i < names.size() ? names[i].c_str() : 0;
153 DLLLOCAL
bool operator==(
const AbstractFunctionSignature& sig)
const;
158 QoreParseTypeInfo* parseTypeInfo;
159 const QoreTypeInfo* typeInfo;
162 DLLLOCAL RetTypeInfo(QoreParseTypeInfo* n_parseTypeInfo,
const QoreTypeInfo* n_typeInfo) : parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
164 DLLLOCAL ~RetTypeInfo() {
165 delete parseTypeInfo;
167 DLLLOCAL
const QoreTypeInfo* getTypeInfo()
const {
170 DLLLOCAL QoreParseTypeInfo* takeParseTypeInfo() {
171 QoreParseTypeInfo* rv = parseTypeInfo;
177 class UserSignature :
public AbstractFunctionSignature {
179 ptype_vec_t parseTypeList;
180 QoreParseTypeInfo* parseReturnTypeInfo;
182 const QoreProgramLocation* loc;
184 DLLLOCAL
void pushParam(BarewordNode* b,
bool needs_types,
bool bare_refs);
185 DLLLOCAL
void pushParam(QoreOperatorNode* t,
bool needs_types);
186 DLLLOCAL
void pushParam(VarRefNode* v,
QoreValue defArg,
bool needs_types);
188 DLLLOCAL
void param_error() {
189 parse_error(*loc,
"parameter list contains non-variable reference expressions");
198 DLLLOCAL UserSignature(
int n_first_line,
int n_last_line,
QoreValue params, RetTypeInfo* retTypeInfo,
int64 po);
200 DLLLOCAL
virtual ~UserSignature() {
201 for (ptype_vec_t::iterator i = parseTypeList.begin(), e = parseTypeList.end(); i != e; ++i)
203 delete parseReturnTypeInfo;
206 DLLLOCAL
void setFirstParamType(
const QoreTypeInfo* typeInfo) {
207 assert(!typeList.empty());
208 typeList[0] = typeInfo;
211 DLLLOCAL
void setSelfId(LocalVar* n_selfid) {
216 DLLLOCAL LocalVar* getSelfId()
const {
220 DLLLOCAL
virtual const QoreParseTypeInfo* getParseParamTypeInfo(
unsigned num)
const {
221 return num < parseTypeList.size() ? parseTypeList[num] :
nullptr;
225 DLLLOCAL
void resolve();
227 DLLLOCAL
virtual void addAbstractParameterSignature(std::string& str)
const {
229 AbstractFunctionSignature::addAbstractParameterSignature(str);
233 for (
unsigned i = 0; i < parseTypeList.size(); ++i) {
234 if (!parseTypeList[i] && typeList.size() > i && typeList[i])
235 str.append(QoreTypeInfo::getName(typeList[i]));
237 str.append(QoreParseTypeInfo::getName(parseTypeList[i]));
238 if (i != parseTypeList.size() - 1)
244 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo()
const {
245 const_cast<UserSignature*
>(
this)->resolve();
246 return returnTypeInfo;
249 DLLLOCAL
const QoreProgramLocation* getParseLocation()
const {
253 DLLLOCAL
bool hasReturnTypeInfo()
const {
254 return parseReturnTypeInfo || returnTypeInfo;
257 DLLLOCAL
void parseInitPushLocalVars(
const QoreTypeInfo* classTypeInfo);
260 DLLLOCAL
void parseInitPopLocalVars();
263 class AbstractQoreFunctionVariant;
280 DLLLOCAL CodeEvaluationHelper(
ExceptionSink* n_xsink,
const QoreFunction* func,
281 const AbstractQoreFunctionVariant*& variant,
const char* n_name,
const QoreListNode* args =
nullptr,
282 QoreObject*
self =
nullptr,
const qore_class_private* n_qc =
nullptr, qore_call_t n_ct = CT_UNUSED,
283 bool is_copy =
false,
const qore_class_private* cctx =
nullptr);
299 DLLLOCAL CodeEvaluationHelper(
ExceptionSink* n_xsink,
const QoreFunction* func,
300 const AbstractQoreFunctionVariant*& variant,
const char* n_name,
QoreListNode* args,
301 QoreObject*
self =
nullptr,
const qore_class_private* n_qc =
nullptr, qore_call_t n_ct = CT_UNUSED,
302 bool is_copy =
false,
const qore_class_private* cctx =
nullptr);
304 DLLLOCAL ~CodeEvaluationHelper();
306 DLLLOCAL
void setReturnTypeInfo(
const QoreTypeInfo* n_returnTypeInfo) {
307 returnTypeInfo = saveReturnTypeInfo(n_returnTypeInfo);
311 DLLLOCAL
void setCallType(qore_call_t n_ct) {
327 DLLLOCAL
int processDefaultArgs(
const QoreFunction* func,
const AbstractQoreFunctionVariant* variant,
328 bool check_args,
bool is_copy,
QoreObject*
self);
332 tmp.assign(
true, n_args);
352 DLLLOCAL
const qore_class_private* getClass()
const {
357 DLLLOCAL
virtual const QoreProgramLocation&
getLocation()
const {
363 DLLLOCAL
virtual const std::string&
getCallName()
const {
376 DLLLOCAL
virtual const AbstractStatement*
getStatement()
const {
385 const qore_class_private* qc;
386 const QoreProgramLocation* loc;
388 const QoreTypeInfo* returnTypeInfo;
390 const AbstractStatement* stmt =
nullptr;
392 std::string callName;
394 const QoreProgramLocation* old_runtime_loc =
nullptr;
395 bool restore_stack =
false;
397 DLLLOCAL
void init(
const QoreFunction* func,
const AbstractQoreFunctionVariant*& variant,
bool is_copy,
398 const qore_class_private* cctx,
QoreObject*
self);
400 DLLLOCAL
void setCallName(
const QoreFunction* func);
403 class UserVariantBase;
409 DLLLOCAL AbstractQoreFunctionVariant(
const AbstractQoreFunctionVariant& old);
410 DLLLOCAL AbstractQoreFunctionVariant& operator=(AbstractQoreFunctionVariant& orig);
417 DLLLOCAL
virtual ~AbstractQoreFunctionVariant() {}
420 DLLLOCAL AbstractQoreFunctionVariant(
int64 n_flags,
bool n_is_user =
false) : flags(n_flags), is_user(n_is_user) {
423 DLLLOCAL
virtual AbstractFunctionSignature* getSignature()
const = 0;
424 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo()
const = 0;
426 DLLLOCAL
const QoreTypeInfo* getReturnTypeInfo()
const {
427 return getSignature()->getReturnTypeInfo();
430 DLLLOCAL
unsigned numParams()
const {
431 AbstractFunctionSignature* sig = getSignature();
432 return sig ? sig->numParams() : 0;
435 DLLLOCAL qore_call_t getCallType()
const {
436 return is_user ? CT_USER : CT_BUILTIN;
439 DLLLOCAL
int64 getParseOptions(
int64 po)
const;
441 DLLLOCAL
int64 getFlags()
const {
445 DLLLOCAL
virtual int64 getFunctionality()
const = 0;
448 DLLLOCAL
virtual void setRecheck() {
452 DLLLOCAL
void parseResolveUserSignature();
454 DLLLOCAL
virtual UserVariantBase* getUserVariantBase() {
458 DLLLOCAL
const UserVariantBase* getUserVariantBase()
const {
460 return is_user ?
const_cast<AbstractQoreFunctionVariant*
>(
this)->getUserVariantBase() : nullptr;
463 DLLLOCAL
virtual QoreValue evalFunction(
const char* name, CodeEvaluationHelper& ceh,
ExceptionSink* xsink)
const {
468 DLLLOCAL
virtual const QoreClass* getClass()
const {
472 DLLLOCAL
const char* className()
const {
474 return qc ? qc->
getName() :
nullptr;
477 DLLLOCAL
bool isSignatureIdentical(
const AbstractFunctionSignature& sig)
const {
479 return *(getSignature()) == sig;
483 DLLLOCAL LocalVar* getSelfId()
const;
485 DLLLOCAL AbstractQoreFunctionVariant* ref() {
490 DLLLOCAL
void deref() {
496 DLLLOCAL
bool isUser()
const {
500 DLLLOCAL
bool hasBody()
const;
502 DLLLOCAL
virtual bool isModulePublic()
const {
507 DLLLOCAL
virtual void parseInit(QoreFunction* f) {
511 DLLLOCAL
virtual void parseCommit() {
516 class UserVariantExecHelper;
519 class UserVariantBase {
520 friend class UserVariantExecHelper;
523 UserSignature signature;
524 StatementBlock* statements;
542 DLLLOCAL UserVariantBase(StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params, RetTypeInfo* rv,
bool synced);
543 DLLLOCAL
virtual ~UserVariantBase();
544 DLLLOCAL UserSignature* getUserSignature()
const {
545 return const_cast<UserSignature*
>(&signature);
548 DLLLOCAL
bool isSynchronized()
const {
552 DLLLOCAL
void setInit() {
556 DLLLOCAL
bool getInit()
const {
560 DLLLOCAL
bool hasBody()
const {
561 return (
bool)statements;
563 DLLLOCAL StatementBlock* getStatementBlock()
const {
567 DLLLOCAL
int64 getParseOptions(
int64 po)
const;
569 DLLLOCAL
void parseInitPushLocalVars(
const QoreTypeInfo* classTypeInfo);
571 DLLLOCAL
void parseInitPopLocalVars();
573 DLLLOCAL
void setSelfId(LocalVar* selfid) {
574 signature.setSelfId(selfid);
577 DLLLOCAL
void parseCommit();
581 #define COMMON_USER_VARIANT_FUNCTIONS DLLLOCAL virtual int64 getFunctionality() const { return QDOM_DEFAULT; } \
582 using AbstractQoreFunctionVariant::getUserVariantBase; \
583 DLLLOCAL virtual UserVariantBase* getUserVariantBase() { return static_cast<UserVariantBase*>(this); } \
584 DLLLOCAL virtual AbstractFunctionSignature* getSignature() const { return const_cast<UserSignature*>(&signature); } \
585 DLLLOCAL virtual const QoreTypeInfo* parseGetReturnTypeInfo() const { return signature.parseGetReturnTypeInfo(); } \
586 DLLLOCAL virtual void setRecheck() { recheck = true; } \
587 DLLLOCAL virtual void parseCommit() { UserVariantBase::parseCommit(); }
590 class UserVariantExecHelper : ProgramThreadCountContextHelper, ThreadFrameBoundaryHelper {
592 const UserVariantBase* uvb;
597 DLLLOCAL UserVariantExecHelper(
const UserVariantBase* n_uvb, CodeEvaluationHelper* ceh,
ExceptionSink* n_xsink) :
598 ProgramThreadCountContextHelper(n_xsink, n_uvb->pgm, true),
599 ThreadFrameBoundaryHelper(!*n_xsink),
600 uvb(n_uvb), argv(n_xsink), xsink(n_xsink) {
602 if (*xsink || uvb->setupCall(ceh, argv, xsink))
606 DLLLOCAL ~UserVariantExecHelper();
608 DLLLOCAL
operator bool()
const {
617 class UserFunctionVariant :
public AbstractQoreFunctionVariant,
public UserVariantBase {
621 DLLLOCAL
virtual ~UserFunctionVariant() {
625 DLLLOCAL UserFunctionVariant(StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params, RetTypeInfo* rv,
bool synced,
int64 n_flags = QCF_NO_FLAGS) :
626 AbstractQoreFunctionVariant(n_flags, true), UserVariantBase(b, n_sig_first_line, n_sig_last_line, params, rv, synced), mod_pub(false) {
630 COMMON_USER_VARIANT_FUNCTIONS
632 DLLLOCAL
virtual QoreValue evalFunction(
const char* name, CodeEvaluationHelper& ceh,
ExceptionSink* xsink)
const {
633 return eval(name, &ceh, 0, xsink);
636 DLLLOCAL
virtual void parseInit(QoreFunction* f);
638 DLLLOCAL
virtual bool isModulePublic()
const {
642 DLLLOCAL
void setModulePublic() {
648 #define UFV(f) (reinterpret_cast<UserFunctionVariant*>(f))
649 #define UFV_const(f) (reinterpret_cast<const UserFunctionVariant*>(f))
653 typedef safe_dslist<AbstractQoreFunctionVariant*> vlist_t;
655 class VList :
public vlist_t {
660 DLLLOCAL
void del() {
662 for (vlist_t::iterator i = begin(), e = end(); i != e; ++i)
673 DLLLOCAL INode(QoreFunction* f, ClassAccess a) : func(f), access(a) {
678 typedef std::vector<INode> ilist_t;
680 hashdecl IList :
public ilist_t {
681 DLLLOCAL QoreFunction* getFunction(
const qore_class_private* class_ctx,
const qore_class_private*& last_class,
682 const_iterator aqfi,
bool& internal_access,
bool& stop)
const;
686 friend class QoreFunctionIterator;
687 friend class qore_external_function_iterator_private;
689 DLLLOCAL QoreFunction(
const char* n_name) : name(n_name),
690 same_return_type(true),
691 nn_same_return_type(true),
693 parse_init_done(true),
694 parse_init_in_progress(false),
702 ilist.push_back(INode(
this, Public));
707 DLLLOCAL QoreFunction(
const QoreFunction& old,
int64 po = 0,
bool copy_all =
false,
bool n_inject =
false)
709 unique_functionality(old.unique_functionality),
710 unique_flags(old.unique_flags),
711 nn_unique_functionality(old.nn_unique_functionality),
712 nn_unique_flags(old.nn_unique_flags),
713 nn_count(old.nn_count),
714 same_return_type(old.same_return_type),
715 nn_same_return_type(old.nn_same_return_type),
717 parse_init_done(true),
718 parse_init_in_progress(false),
719 has_user(old.has_user),
720 has_builtin(old.has_builtin),
724 has_priv(old.has_priv),
725 all_priv(old.all_priv),
726 nn_uniqueReturnType(old.nn_uniqueReturnType) {
728 bool no_builtin = po & PO_NO_SYSTEM_FUNC_VARIANTS;
731 for (vlist_t::const_iterator i = old.vlist.begin(), e = old.vlist.end(); i != e; ++i) {
733 if ((*i)->isUser()) {
734 if (no_user || !(*i)->isModulePublic())
742 vlist.push_back((*i)->ref());
745 if (no_user && has_user)
747 if (no_builtin && has_builtin)
751 assert(old.vlist.empty() || !vlist.empty());
753 assert(!old.ilist.empty());
754 assert(old.ilist.front().func == &old);
757 ilist.push_back(INode(
this, Public));
763 if (!old.from_module.empty()) {
764 from_module = old.from_module;
772 DLLLOCAL QoreFunction(
bool ignore,
const QoreFunction& old, qore_ns_private* nns)
773 : name(old.name), ns(nns), same_return_type(old.same_return_type),
774 unique_functionality(old.unique_functionality),
775 unique_flags(old.unique_flags),
776 nn_same_return_type(old.nn_same_return_type),
777 nn_unique_functionality(old.nn_unique_functionality),
778 nn_unique_flags(old.nn_unique_flags),
779 nn_count(old.nn_count),
780 parse_rt_done(true), parse_init_done(true),
781 has_user(true), has_builtin(false), has_mod_pub(false ), inject(false),
782 nn_uniqueReturnType(old.nn_uniqueReturnType) {
784 assert(old.has_mod_pub);
787 for (vlist_t::const_iterator i = old.vlist.begin(), e = old.vlist.end(); i != e; ++i) {
788 if (!(*i)->isModulePublic())
790 vlist.push_back((*i)->ref());
794 assert(old.vlist.empty() || !vlist.empty());
796 assert(!old.ilist.empty());
797 assert(old.ilist.front().func == &old);
800 ilist.push_back(INode(
this, Public));
809 DLLLOCAL
const AbstractQoreFunctionVariant* first()
const {
810 assert(!vlist.empty());
811 return *(vlist.begin());
815 DLLLOCAL AbstractQoreFunctionVariant* first() {
816 assert(!vlist.empty());
817 return *(vlist.begin());
820 DLLLOCAL
unsigned numVariants()
const {
827 DLLLOCAL
int parseCheckDuplicateSignatureCommitted(UserSignature* sig);
829 DLLLOCAL
const char* getName()
const {
833 DLLLOCAL
virtual const QoreClass* getClass()
const {
837 DLLLOCAL
void ref() {
841 DLLLOCAL
void deref() {
846 DLLLOCAL
const char* className()
const {
848 return qc ? qc->
getName() :
nullptr;
851 DLLLOCAL
void addAncestor(QoreFunction* ancestor, ClassAccess access) {
852 ilist.push_back(INode(ancestor, access));
855 DLLLOCAL
void addNewAncestor(QoreFunction* ancestor, ClassAccess access) {
856 for (ilist_t::iterator i = ilist.begin(), e = ilist.end(); i != e; ++i)
857 if ((*i).func == ancestor)
859 ilist.push_back(INode(ancestor, access));
863 DLLLOCAL
void resolvePendingSignatures();
865 DLLLOCAL AbstractFunctionSignature* getUniqueSignature()
const {
866 return vlist.singular() ? first()->getSignature() : 0;
869 DLLLOCAL AbstractFunctionSignature* parseGetUniqueSignature()
const;
871 DLLLOCAL
int64 parseGetUniqueFunctionality()
const {
873 return nn_unique_functionality;
874 return unique_functionality;
877 DLLLOCAL
int64 parseGetUniqueFlags()
const {
879 return nn_unique_flags;
884 DLLLOCAL
int addPendingVariant(AbstractQoreFunctionVariant* variant);
886 DLLLOCAL
void addBuiltinVariant(AbstractQoreFunctionVariant* variant);
888 DLLLOCAL
void parseInit(qore_ns_private* ns);
889 DLLLOCAL
void parseCommit();
890 DLLLOCAL
void parseRollback();
892 DLLLOCAL
const QoreTypeInfo* getUniqueReturnTypeInfo()
const {
894 return nn_uniqueReturnType;
896 return same_return_type && !vlist.empty() ? first()->getReturnTypeInfo() : 0;
899 DLLLOCAL
const QoreTypeInfo* parseGetUniqueReturnTypeInfo() {
900 parseCheckReturnType();
904 if (!same_return_type)
908 if (!nn_same_return_type)
911 return nn_count ? nn_uniqueReturnType : (!vlist.empty() ? first()->getReturnTypeInfo() :
nullptr);
915 return first()->getReturnTypeInfo();
932 DLLLOCAL
const AbstractQoreFunctionVariant* parseFindVariant(
const QoreProgramLocation* loc,
const type_vec_t& argTypeInfo,
const qore_class_private* class_ctx)
const;
935 DLLLOCAL
bool pendingEmpty()
const {
936 return vlist.empty() || !check_parse;
940 DLLLOCAL
bool committedEmpty()
const {
941 return vlist.empty() || check_parse;
944 DLLLOCAL
bool existsVariant(
const type_vec_t& paramTypeInfo)
const;
948 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindVariant(
ExceptionSink* xsink,
const QoreListNode* args,
bool only_user,
const qore_class_private* class_ctx)
const;
951 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindVariant(
ExceptionSink* xsink,
const type_vec_t& args,
const qore_class_private* class_ctx)
const;
953 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindExactVariant(
ExceptionSink* xsink,
const type_vec_t& args,
const qore_class_private* class_ctx)
const;
955 DLLLOCAL
void parseAssimilate(QoreFunction& other) {
956 while (!other.vlist.empty()) {
957 addPendingVariant(*(other.vlist.begin()));
958 other.vlist.pop_front();
962 DLLLOCAL
bool hasUser()
const {
966 DLLLOCAL
bool hasBuiltin()
const {
970 DLLLOCAL
bool hasPublic()
const {
974 DLLLOCAL
bool hasUserPublic()
const {
975 return has_pub && has_user;
978 DLLLOCAL
bool injected()
const {
982 DLLLOCAL
bool hasPrivate()
const {
986 DLLLOCAL
bool allPrivate()
const {
990 DLLLOCAL
const std::string& getNameStr()
const {
994 DLLLOCAL
const char* getModuleName()
const {
995 return from_module.empty() ? nullptr : from_module.c_str();
1008 int64 unique_flags = QCF_NO_FLAGS;
1012 int64 nn_unique_flags = QCF_NO_FLAGS;
1016 bool same_return_type : 1;
1017 bool nn_same_return_type : 1;
1018 bool parse_rt_done : 1;
1019 bool parse_init_done : 1;
1020 bool parse_init_in_progress : 1;
1022 bool has_builtin : 1;
1025 bool check_parse : 1;
1029 const QoreTypeInfo* nn_uniqueReturnType =
nullptr;
1031 std::string from_module;
1033 DLLLOCAL
void setModuleName() {
1034 assert(from_module.empty());
1035 const char* mod_name = get_module_context_name();
1037 from_module = mod_name;
1042 DLLLOCAL
void parseCheckReturnType() {
1046 parse_rt_done =
true;
1048 if (!same_return_type)
1051 for (vlist_t::iterator i = vlist.begin(), e = vlist.end(); i != e; ++i) {
1052 reinterpret_cast<UserSignature*
>((*i)->getUserVariantBase()->getUserSignature())->resolve();
1053 const QoreTypeInfo* rti = (*i)->getReturnTypeInfo();
1055 if (i == vlist.begin()) {
1059 if (!QoreTypeInfo::isOutputIdentical(rti, first()->getReturnTypeInfo())) {
1060 same_return_type =
false;
1068 DLLLOCAL
static int parseCompareResolvedSignature(
const VList& vlist,
const AbstractFunctionSignature* sig,
const AbstractFunctionSignature*& vs);
1071 DLLLOCAL
int parseCheckDuplicateSignature(AbstractQoreFunctionVariant* variant);
1074 DLLLOCAL
void addVariant(AbstractQoreFunctionVariant* variant) {
1075 const QoreTypeInfo* rti = variant->getReturnTypeInfo();
1076 if (same_return_type && !vlist.empty() && !QoreTypeInfo::isOutputIdentical(rti, first()->getReturnTypeInfo()))
1077 same_return_type =
false;
1079 int64 vf = variant->getFunctionality();
1080 int64 vflags = variant->getFlags();
1082 bool rtn = (bool)(vflags & QCF_RUNTIME_NOOP);
1084 if (vlist.empty()) {
1085 unique_functionality = vf;
1086 unique_flags = vflags;
1088 unique_functionality &= vf;
1089 unique_flags &= vflags;
1094 nn_unique_functionality = vf;
1095 nn_unique_flags = vflags;
1096 nn_uniqueReturnType = rti;
1099 nn_unique_functionality &= vf;
1100 nn_unique_flags &= vflags;
1101 if (nn_uniqueReturnType && !QoreTypeInfo::isOutputIdentical(rti, nn_uniqueReturnType))
1102 nn_uniqueReturnType = 0;
1107 vlist.push_back(variant);
1110 DLLLOCAL
virtual ~QoreFunction() {
1115 const qore_class_private* class_ctx,
const QoreFunction* aqf,
const qore_class_private* last_class,
1116 bool internal_access,
int64 ppo,
const AbstractQoreFunctionVariant* variant)
const;
1119 class QoreFunctionIterator {
1121 DLLLOCAL QoreFunctionIterator(
const QoreFunction& f) : f(f) {
1125 DLLLOCAL
bool next() {
1126 if (i == f.vlist.end()) {
1127 i = f.vlist.begin();
1133 return i != f.vlist.end();
1136 DLLLOCAL
const AbstractQoreFunctionVariant* getVariant()
const {
1141 const QoreFunction& f;
1142 VList::const_iterator i;
1145 class MethodVariantBase;
1146 class MethodFunctionBase;
1147 #define METHFB(f) (reinterpret_cast<MethodFunctionBase*>(f))
1148 #define METHFB_const(f) (reinterpret_cast<const MethodFunctionBase*>(f))
1150 class MethodFunctionBase :
public QoreFunction {
1151 friend hashdecl AbstractMethod;
1159 mutable MethodFunctionBase* new_copy =
nullptr;
1164 has_private_internal_variants =
false;
1168 DLLLOCAL
int checkFinalVariant(
const MethodFunctionBase* m,
const MethodVariantBase* v)
const;
1170 DLLLOCAL
void replaceAbstractVariantIntern(MethodVariantBase* variant);
1173 DLLLOCAL MethodFunctionBase(
const char* nme,
const QoreClass* n_qc,
bool n_is_static) : QoreFunction(nme),
1174 qc(n_qc), is_static(n_is_static), has_final(false), access(Internal) {
1178 DLLLOCAL MethodFunctionBase(
const MethodFunctionBase& old,
const QoreClass* n_qc)
1179 : QoreFunction(old, 0, true),
1181 is_static(old.is_static),
1182 has_final(old.has_final),
1183 is_abstract(old.is_abstract),
1184 has_private_internal_variants(old.has_private_internal_variants),
1185 access(old.access) {
1189 old.new_copy =
this;
1192 ilist.reserve(old.ilist.size());
1193 ilist_t::const_iterator i = old.ilist.begin(), e = old.ilist.end();
1195 for (; i != e; ++i) {
1196 ilist.push_back(*i);
1200 DLLLOCAL
void resolveCopy() {
1201 ilist_t::iterator i = ilist.begin(), e = ilist.end();
1203 for (; i != e; ++i) {
1204 MethodFunctionBase* mfb = METHFB((*i).func);
1207 printd(0,
"error resolving %p %s::%s() base method %p %s::%s() nas no new method pointer\n", qc, qc->
getName(), getName(), mfb->qc, mfb->qc->getName(), getName());
1208 assert(mfb->new_copy);
1211 (*i).func = mfb->new_copy;
1215 DLLLOCAL
void parseInit();
1216 DLLLOCAL
void parseCommit();
1217 DLLLOCAL
void parseRollback();
1220 DLLLOCAL
int parseAddUserMethodVariant(MethodVariantBase* variant);
1223 DLLLOCAL
void addBuiltinMethodVariant(MethodVariantBase* variant);
1226 DLLLOCAL
void parseCommitMethod(
QoreString& csig,
const char* mod);
1228 DLLLOCAL
void parseCommitMethod();
1230 DLLLOCAL
void parseSignatures(
QoreString& csig,
const char* mod)
const;
1233 DLLLOCAL MethodVariantBase* parseHasVariantWithSignature(MethodVariantBase* v)
const;
1235 DLLLOCAL
void replaceAbstractVariant(MethodVariantBase* variant);
1237 DLLLOCAL
void parseRollbackMethod();
1239 DLLLOCAL
bool isUniquelyPrivate()
const {
1240 return access > Public;
1243 DLLLOCAL
bool isAbstract()
const {
1247 DLLLOCAL ClassAccess getAccess()
const {
1251 DLLLOCAL
virtual const QoreClass* getClass()
const {
1255 DLLLOCAL
const char* getClassName()
const {
1259 DLLLOCAL
bool isStatic()
const {
1263 DLLLOCAL
bool hasPrivateInternalVariants()
const {
1264 return has_private_internal_variants;
1267 DLLLOCAL
void checkFinal()
const;
1270 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const = 0;
1273 class UserParamListLocalVarHelper {
1275 UserVariantBase* uvb;
1278 DLLLOCAL UserParamListLocalVarHelper(UserVariantBase* n_uvb,
const QoreTypeInfo* classTypeInfo = 0) : uvb(n_uvb) {
1279 uvb->parseInitPushLocalVars(classTypeInfo);
1282 DLLLOCAL ~UserParamListLocalVarHelper() {
1283 uvb->parseInitPopLocalVars();
1287 class UserClosureVariant :
public UserFunctionVariant {
1290 DLLLOCAL UserClosureVariant(StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params, RetTypeInfo* rv,
bool synced =
false,
int64 n_flags = QCF_NO_FLAGS) : UserFunctionVariant(b, n_sig_first_line, n_sig_last_line, params, rv, synced, n_flags) {
1293 DLLLOCAL
virtual void parseInit(QoreFunction* f);
1296 return eval(
"<anonymous closure>", &ceh,
self, xsink);
1300 #define UCLOV(f) (reinterpret_cast<UserClosureVariant*>(f))
1301 #define UCLOV_const(f) (reinterpret_cast<const UserClosureVariant*>(f))
1303 class UserClosureFunction :
public QoreFunction {
1306 const QoreTypeInfo* classTypeInfo;
1309 DLLLOCAL UserClosureFunction(StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params, RetTypeInfo* rv,
bool synced =
false,
int64 n_flags = QCF_NO_FLAGS) : QoreFunction(
"<anonymous closure>"), classTypeInfo(0) {
1310 addPendingVariant(
new UserClosureVariant(b, n_sig_first_line, n_sig_last_line, params, rv, synced, n_flags));
1315 DLLLOCAL
void setClassType(
const QoreTypeInfo* cti) {
1316 classTypeInfo = cti;
1319 DLLLOCAL
const QoreTypeInfo* getClassType()
const {
1320 return classTypeInfo;
1323 DLLLOCAL LVarSet* getVList() {
1328 DLLLOCAL
bool needsScan()
const {
1329 return varlist.needsScan();
1333 #endif // _QORE_FUNCTION_H