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 {
367 DLLLOCAL
virtual qore_call_t getCallType()
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() {
491 if (ROdereference()) {
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;
699 int64 unique_flags = QCF_NO_FLAGS;
703 int64 nn_unique_flags = QCF_NO_FLAGS;
706 bool same_return_type : 1;
707 bool nn_same_return_type : 1;
708 bool parse_rt_done : 1;
709 bool parse_init_done : 1;
710 bool parse_init_in_progress : 1;
712 bool has_builtin : 1;
715 bool check_parse : 1;
719 const QoreTypeInfo* nn_uniqueReturnType =
nullptr;
721 DLLLOCAL
void parseCheckReturnType() {
725 parse_rt_done =
true;
727 if (!same_return_type)
730 for (vlist_t::iterator i = vlist.begin(), e = vlist.end(); i != e; ++i) {
731 reinterpret_cast<UserSignature*
>((*i)->getUserVariantBase()->getUserSignature())->resolve();
732 const QoreTypeInfo* rti = (*i)->getReturnTypeInfo();
734 if (i == vlist.begin()) {
738 if (!QoreTypeInfo::isOutputIdentical(rti, first()->getReturnTypeInfo())) {
739 same_return_type =
false;
747 DLLLOCAL
static int parseCompareResolvedSignature(
const VList& vlist,
const AbstractFunctionSignature* sig,
const AbstractFunctionSignature*& vs);
750 DLLLOCAL
int parseCheckDuplicateSignature(AbstractQoreFunctionVariant* variant);
753 DLLLOCAL
void addVariant(AbstractQoreFunctionVariant* variant) {
754 const QoreTypeInfo* rti = variant->getReturnTypeInfo();
755 if (same_return_type && !vlist.empty() && !QoreTypeInfo::isOutputIdentical(rti, first()->getReturnTypeInfo()))
756 same_return_type =
false;
758 int64 vf = variant->getFunctionality();
759 int64 vflags = variant->getFlags();
761 bool rtn = (bool)(vflags & QCF_RUNTIME_NOOP);
764 unique_functionality = vf;
765 unique_flags = vflags;
768 unique_functionality &= vf;
769 unique_flags &= vflags;
774 nn_unique_functionality = vf;
775 nn_unique_flags = vflags;
776 nn_uniqueReturnType = rti;
780 nn_unique_functionality &= vf;
781 nn_unique_flags &= vflags;
782 if (nn_uniqueReturnType && !QoreTypeInfo::isOutputIdentical(rti, nn_uniqueReturnType))
783 nn_uniqueReturnType = 0;
788 vlist.push_back(variant);
791 DLLLOCAL
virtual ~QoreFunction() {
796 const qore_class_private* class_ctx,
const QoreFunction* aqf,
const qore_class_private* last_class,
797 bool internal_access,
int64 ppo,
const AbstractQoreFunctionVariant* variant)
const;
800 DLLLOCAL QoreFunction(
const char* n_name) : name(n_name),
801 same_return_type(true),
802 nn_same_return_type(true),
804 parse_init_done(true),
805 parse_init_in_progress(false),
813 ilist.push_back(INode(
this, Public));
818 DLLLOCAL QoreFunction(
const QoreFunction& old,
int64 po = 0,
bool copy_all =
false,
bool n_inject =
false)
820 unique_functionality(old.unique_functionality),
821 unique_flags(old.unique_flags),
822 nn_unique_functionality(old.nn_unique_functionality),
823 nn_unique_flags(old.nn_unique_flags),
824 nn_count(old.nn_count),
825 same_return_type(old.same_return_type),
826 nn_same_return_type(old.nn_same_return_type),
828 parse_init_done(true),
829 parse_init_in_progress(false),
830 has_user(old.has_user),
831 has_builtin(old.has_builtin),
835 has_priv(old.has_priv),
836 all_priv(old.all_priv),
837 nn_uniqueReturnType(old.nn_uniqueReturnType) {
839 bool no_builtin = po & PO_NO_SYSTEM_FUNC_VARIANTS;
842 for (vlist_t::const_iterator i = old.vlist.begin(), e = old.vlist.end(); i != e; ++i) {
844 if ((*i)->isUser()) {
845 if (no_user || !(*i)->isModulePublic())
853 vlist.push_back((*i)->ref());
856 if (no_user && has_user)
858 if (no_builtin && has_builtin)
862 assert(old.vlist.empty() || !vlist.empty());
864 assert(!old.ilist.empty());
865 assert(old.ilist.front().func == &old);
868 ilist.push_back(INode(
this, Public));
877 DLLLOCAL QoreFunction(
bool ignore,
const QoreFunction& old, qore_ns_private* nns)
878 : name(old.name), ns(nns), same_return_type(old.same_return_type),
879 unique_functionality(old.unique_functionality),
880 unique_flags(old.unique_flags),
881 nn_same_return_type(old.nn_same_return_type),
882 nn_unique_functionality(old.nn_unique_functionality),
883 nn_unique_flags(old.nn_unique_flags),
884 nn_count(old.nn_count),
885 parse_rt_done(true), parse_init_done(true),
886 has_user(true), has_builtin(false), has_mod_pub(false ), inject(false),
887 nn_uniqueReturnType(old.nn_uniqueReturnType) {
889 assert(old.has_mod_pub);
892 for (vlist_t::const_iterator i = old.vlist.begin(), e = old.vlist.end(); i != e; ++i) {
893 if (!(*i)->isModulePublic())
895 vlist.push_back((*i)->ref());
899 assert(old.vlist.empty() || !vlist.empty());
901 assert(!old.ilist.empty());
902 assert(old.ilist.front().func == &old);
905 ilist.push_back(INode(
this, Public));
914 DLLLOCAL
const AbstractQoreFunctionVariant* first()
const {
915 assert(!vlist.empty());
916 return *(vlist.begin());
920 DLLLOCAL AbstractQoreFunctionVariant* first() {
921 assert(!vlist.empty());
922 return *(vlist.begin());
925 DLLLOCAL
unsigned numVariants()
const {
932 DLLLOCAL
int parseCheckDuplicateSignatureCommitted(UserSignature* sig);
934 DLLLOCAL
const char* getName()
const {
938 DLLLOCAL
virtual const QoreClass* getClass()
const {
942 DLLLOCAL
void ref() {
946 DLLLOCAL
void deref() {
951 DLLLOCAL
const char* className()
const {
953 return qc ? qc->
getName() :
nullptr;
956 DLLLOCAL
void addAncestor(QoreFunction* ancestor, ClassAccess access) {
957 ilist.push_back(INode(ancestor, access));
960 DLLLOCAL
void addNewAncestor(QoreFunction* ancestor, ClassAccess access) {
961 for (ilist_t::iterator i = ilist.begin(), e = ilist.end(); i != e; ++i)
962 if ((*i).func == ancestor)
964 ilist.push_back(INode(ancestor, access));
968 DLLLOCAL
void resolvePendingSignatures();
970 DLLLOCAL AbstractFunctionSignature* getUniqueSignature()
const {
971 return vlist.singular() ? first()->getSignature() : 0;
974 DLLLOCAL AbstractFunctionSignature* parseGetUniqueSignature()
const;
976 DLLLOCAL
int64 parseGetUniqueFunctionality()
const {
978 return nn_unique_functionality;
979 return unique_functionality;
982 DLLLOCAL
int64 parseGetUniqueFlags()
const {
984 return nn_unique_flags;
989 DLLLOCAL
int addPendingVariant(AbstractQoreFunctionVariant* variant);
991 DLLLOCAL
void addBuiltinVariant(AbstractQoreFunctionVariant* variant);
993 DLLLOCAL
void parseInit(qore_ns_private* ns);
994 DLLLOCAL
void parseCommit();
995 DLLLOCAL
void parseRollback();
997 DLLLOCAL
const QoreTypeInfo* getUniqueReturnTypeInfo()
const {
999 return nn_uniqueReturnType;
1001 return same_return_type && !vlist.empty() ? first()->getReturnTypeInfo() : 0;
1004 DLLLOCAL
const QoreTypeInfo* parseGetUniqueReturnTypeInfo() {
1005 parseCheckReturnType();
1009 if (!same_return_type)
1013 if (!nn_same_return_type)
1016 return nn_count ? nn_uniqueReturnType : (!vlist.empty() ? first()->getReturnTypeInfo() :
nullptr);
1020 return first()->getReturnTypeInfo();
1037 DLLLOCAL
const AbstractQoreFunctionVariant* parseFindVariant(
const QoreProgramLocation* loc,
const type_vec_t& argTypeInfo,
const qore_class_private* class_ctx)
const;
1040 DLLLOCAL
bool pendingEmpty()
const {
1041 return vlist.empty() || !check_parse;
1045 DLLLOCAL
bool committedEmpty()
const {
1046 return vlist.empty() || check_parse;
1049 DLLLOCAL
bool existsVariant(
const type_vec_t& paramTypeInfo)
const;
1053 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindVariant(
ExceptionSink* xsink,
const QoreListNode* args,
bool only_user,
const qore_class_private* class_ctx)
const;
1056 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindVariant(
ExceptionSink* xsink,
const type_vec_t& args,
const qore_class_private* class_ctx)
const;
1058 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindExactVariant(
ExceptionSink* xsink,
const type_vec_t& args,
const qore_class_private* class_ctx)
const;
1060 DLLLOCAL
void parseAssimilate(QoreFunction& other) {
1061 while (!other.vlist.empty()) {
1062 addPendingVariant(*(other.vlist.begin()));
1063 other.vlist.pop_front();
1067 DLLLOCAL
bool hasUser()
const {
1071 DLLLOCAL
bool hasBuiltin()
const {
1075 DLLLOCAL
bool hasPublic()
const {
1079 DLLLOCAL
bool hasUserPublic()
const {
1080 return has_pub && has_user;
1083 DLLLOCAL
bool injected()
const {
1087 DLLLOCAL
bool hasPrivate()
const {
1091 DLLLOCAL
bool allPrivate()
const {
1095 DLLLOCAL
const std::string& getNameStr()
const {
1100 class QoreFunctionIterator {
1102 DLLLOCAL QoreFunctionIterator(
const QoreFunction& f) : f(f) {
1106 DLLLOCAL
bool next() {
1107 if (i == f.vlist.end()) {
1108 i = f.vlist.begin();
1114 return i != f.vlist.end();
1117 DLLLOCAL
const AbstractQoreFunctionVariant* getVariant()
const {
1122 const QoreFunction& f;
1123 VList::const_iterator i;
1126 class MethodVariantBase;
1127 class MethodFunctionBase;
1128 #define METHFB(f) (reinterpret_cast<MethodFunctionBase*>(f)) 1129 #define METHFB_const(f) (reinterpret_cast<const MethodFunctionBase*>(f)) 1131 class MethodFunctionBase :
public QoreFunction {
1132 friend hashdecl AbstractMethod;
1140 mutable MethodFunctionBase* new_copy =
nullptr;
1145 has_private_internal_variants =
false;
1149 DLLLOCAL
int checkFinalVariant(
const MethodFunctionBase* m,
const MethodVariantBase* v)
const;
1151 DLLLOCAL
void replaceAbstractVariantIntern(MethodVariantBase* variant);
1154 DLLLOCAL MethodFunctionBase(
const char* nme,
const QoreClass* n_qc,
bool n_is_static) : QoreFunction(nme),
1155 qc(n_qc), is_static(n_is_static), has_final(false), access(Internal) {
1159 DLLLOCAL MethodFunctionBase(
const MethodFunctionBase& old,
const QoreClass* n_qc)
1160 : QoreFunction(old, 0, true),
1162 is_static(old.is_static),
1163 has_final(old.has_final),
1164 is_abstract(old.is_abstract),
1165 has_private_internal_variants(old.has_private_internal_variants),
1166 access(old.access) {
1170 old.new_copy =
this;
1173 ilist.reserve(old.ilist.size());
1174 ilist_t::const_iterator i = old.ilist.begin(), e = old.ilist.end();
1176 for (; i != e; ++i) {
1177 ilist.push_back(*i);
1181 DLLLOCAL
void resolveCopy() {
1182 ilist_t::iterator i = ilist.begin(), e = ilist.end();
1184 for (; i != e; ++i) {
1185 MethodFunctionBase* mfb = METHFB((*i).func);
1188 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());
1189 assert(mfb->new_copy);
1192 (*i).func = mfb->new_copy;
1196 DLLLOCAL
void parseInit();
1197 DLLLOCAL
void parseCommit();
1198 DLLLOCAL
void parseRollback();
1201 DLLLOCAL
int parseAddUserMethodVariant(MethodVariantBase* variant);
1204 DLLLOCAL
void addBuiltinMethodVariant(MethodVariantBase* variant);
1207 DLLLOCAL
void parseCommitMethod(
QoreString& csig,
const char* mod);
1209 DLLLOCAL
void parseCommitMethod();
1211 DLLLOCAL
void parseSignatures(
QoreString& csig,
const char* mod)
const;
1214 DLLLOCAL MethodVariantBase* parseHasVariantWithSignature(MethodVariantBase* v)
const;
1216 DLLLOCAL
void replaceAbstractVariant(MethodVariantBase* variant);
1218 DLLLOCAL
void parseRollbackMethod();
1220 DLLLOCAL
bool isUniquelyPrivate()
const {
1221 return access > Public;
1224 DLLLOCAL
bool isAbstract()
const {
1228 DLLLOCAL ClassAccess getAccess()
const {
1232 DLLLOCAL
virtual const QoreClass* getClass()
const {
1236 DLLLOCAL
const char* getClassName()
const {
1240 DLLLOCAL
bool isStatic()
const {
1244 DLLLOCAL
bool hasPrivateInternalVariants()
const {
1245 return has_private_internal_variants;
1248 DLLLOCAL
void checkFinal()
const;
1251 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const = 0;
1254 class UserParamListLocalVarHelper {
1256 UserVariantBase* uvb;
1259 DLLLOCAL UserParamListLocalVarHelper(UserVariantBase* n_uvb,
const QoreTypeInfo* classTypeInfo = 0) : uvb(n_uvb) {
1260 uvb->parseInitPushLocalVars(classTypeInfo);
1263 DLLLOCAL ~UserParamListLocalVarHelper() {
1264 uvb->parseInitPopLocalVars();
1268 class UserClosureVariant :
public UserFunctionVariant {
1271 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) {
1274 DLLLOCAL
virtual void parseInit(QoreFunction* f);
1277 return eval(
"<anonymous closure>", &ceh,
self, xsink);
1281 #define UCLOV(f) (reinterpret_cast<UserClosureVariant*>(f)) 1282 #define UCLOV_const(f) (reinterpret_cast<const UserClosureVariant*>(f)) 1284 class UserClosureFunction :
public QoreFunction {
1287 const QoreTypeInfo* classTypeInfo;
1290 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) {
1291 addPendingVariant(
new UserClosureVariant(b, n_sig_first_line, n_sig_last_line, params, rv, synced, n_flags));
1296 DLLLOCAL
void setClassType(
const QoreTypeInfo* cti) {
1297 classTypeInfo = cti;
1300 DLLLOCAL
const QoreTypeInfo* getClassType()
const {
1301 return classTypeInfo;
1304 DLLLOCAL LVarSet* getVList() {
1309 DLLLOCAL
bool needsScan()
const {
1310 return varlist.needsScan();
1314 #endif // _QORE_FUNCTION_H Stack location element abstract class.
Definition: ExceptionSink.h:396
#define PO_NO_INHERIT_USER_FUNC_VARIANTS
do not inherit public user function variants from the parent into the new program's space ...
Definition: Restrictions.h:70
uint64_t q_rt_flags_t
runtime code execution flags
Definition: common.h:263
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
DLLEXPORT QoreProgram * getProgram()
returns the current QoreProgram
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:44
defines a Qore-language class
Definition: QoreClass.h:239
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:126
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:61
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:257
#define PO_REQUIRE_TYPES
require type information for all declarations
Definition: Restrictions.h:61
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
std::vector< QoreValue > arg_vec_t
vector of value information for default argument lists
Definition: common.h:254
DLLEXPORT QoreValue eval(ExceptionSink *xsink) const
evaluates the node and returns the result
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:251
DLLEXPORT const char * getName() const
returns the class name
For use on the stack only: manages result of the optional evaluation of a QoreListNode.
Definition: QoreListNodeEvalOptionalRefHolder.h:37
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:155