32#ifndef _QORE_FUNCTION_H
34#define _QORE_FUNCTION_H
42#include "qore/intern/QoreListNodeEvalOptionalRefHolder.h"
44class qore_class_private;
51class QoreOperatorNode;
54class qore_class_private;
57typedef std::vector<QoreParseTypeInfo*> ptype_vec_t;
58typedef std::vector<LocalVar*> lvar_vec_t;
60class AbstractFunctionSignature {
62 DLLLOCAL AbstractFunctionSignature(
const QoreTypeInfo* n_returnTypeInfo =
nullptr)
63 : returnTypeInfo(n_returnTypeInfo) {
66 DLLLOCAL AbstractFunctionSignature(
const QoreTypeInfo* n_returnTypeInfo,
const type_vec_t& n_typeList,
68 : returnTypeInfo(n_returnTypeInfo), typeList(n_typeList), defaultArgList(n_defaultArgList),
69 names(n_names), varargs(varargs) {
72 DLLLOCAL
virtual ~AbstractFunctionSignature() {
74 for (arg_vec_t::iterator i = defaultArgList.begin(), e = defaultArgList.end(); i != e; ++i) {
75 (*i).discard(
nullptr);
80 DLLLOCAL
const QoreTypeInfo* parseGetReturnTypeInfo()
const {
82 return parseGetReturnTypeInfo(err);
86 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo(
int& err)
const = 0;
88 DLLLOCAL
virtual const QoreParseTypeInfo* getParseParamTypeInfo(
unsigned num)
const = 0;
90 DLLLOCAL
const QoreTypeInfo* getReturnTypeInfo()
const {
91 return returnTypeInfo;
94 DLLLOCAL
const arg_vec_t& getDefaultArgList()
const {
95 return defaultArgList;
98 DLLLOCAL
const type_vec_t& getTypeList()
const {
102 DLLLOCAL
const name_vec_t& getParamNames()
const {
107 assert(i < defaultArgList.size());
108 return defaultArgList[i].eval(xsink);
111 DLLLOCAL
const char* getSignatureText()
const {
115 DLLLOCAL
virtual void addAbstractParameterSignature(std::string& str)
const {
116 for (
unsigned i = 0; i < typeList.size(); ++i) {
117 str.append(QoreTypeInfo::getPath(typeList[i]));
118 const char* vname = getName(i);
123 if (hasDefaultArg(i)) {
124 addDefaultArgument(str, defaultArgList[i]);
126 if (i != typeList.size() - 1) {
131 if (!typeList.empty()) {
138 DLLLOCAL
unsigned numParams()
const {
139 return (
unsigned)typeList.size();
143 DLLLOCAL
unsigned getParamTypes()
const {
144 return num_param_types;
147 DLLLOCAL
unsigned getMinParamTypes()
const {
148 return min_param_types;
151 DLLLOCAL
const QoreTypeInfo* getParamTypeInfo(
unsigned num)
const {
152 return num >= typeList.size() ? 0 : typeList[num];
155 DLLLOCAL
bool hasDefaultArg(
unsigned i)
const {
156 return i >= defaultArgList.size() || !defaultArgList[i] ? false :
true;
160 DLLLOCAL
static void addDefaultArgument(std::string& str,
QoreValue arg);
162 DLLLOCAL
const char* getName(
unsigned i)
const {
163 return i < names.size() ? names[i].c_str() : 0;
166 DLLLOCAL
bool compare(
const AbstractFunctionSignature& sig,
bool relaxed_match =
false)
const;
168 DLLLOCAL
bool hasVarargs()
const {
173 unsigned short num_param_types = 0,
176 const QoreTypeInfo* returnTypeInfo;
185 bool varargs =
false;
190 QoreParseTypeInfo* parseTypeInfo;
191 const QoreTypeInfo* typeInfo;
194 DLLLOCAL RetTypeInfo(QoreParseTypeInfo* n_parseTypeInfo,
const QoreTypeInfo* n_typeInfo)
195 : parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
197 DLLLOCAL ~RetTypeInfo() {
198 delete parseTypeInfo;
200 DLLLOCAL
const QoreTypeInfo* getTypeInfo()
const {
203 DLLLOCAL QoreParseTypeInfo* takeParseTypeInfo() {
204 QoreParseTypeInfo* rv = parseTypeInfo;
210class UserSignature :
public AbstractFunctionSignature {
212 ptype_vec_t parseTypeList;
213 QoreParseTypeInfo* parseReturnTypeInfo;
215 const QoreProgramLocation* loc;
217 DLLLOCAL
int pushParam(BarewordNode* b,
bool needs_types,
bool bare_refs);
218 DLLLOCAL
int pushParam(QoreOperatorNode* t,
bool needs_types);
219 DLLLOCAL
int pushParam(VarRefNode* v,
QoreValue defArg,
bool needs_types);
221 DLLLOCAL
void param_error() {
222 parse_error(*loc,
"parameter list contains non-variable reference expressions");
232 DLLLOCAL UserSignature(
int n_first_line,
int n_last_line,
QoreValue params, RetTypeInfo* retTypeInfo,
int64 po);
234 DLLLOCAL
virtual ~UserSignature() {
235 for (ptype_vec_t::iterator i = parseTypeList.begin(), e = parseTypeList.end(); i != e; ++i)
237 delete parseReturnTypeInfo;
240 DLLLOCAL
void setFirstParamType(
const QoreTypeInfo* typeInfo) {
241 assert(!typeList.empty());
242 typeList[0] = typeInfo;
245 DLLLOCAL
void setSelfId(LocalVar* n_selfid) {
250 DLLLOCAL LocalVar* getSelfId()
const {
254 DLLLOCAL
virtual const QoreParseTypeInfo* getParseParamTypeInfo(
unsigned num)
const {
255 return num < parseTypeList.size() ? parseTypeList[num] :
nullptr;
259 DLLLOCAL
virtual int resolve();
261 DLLLOCAL
virtual void addAbstractParameterSignature(std::string& str)
const {
263 AbstractFunctionSignature::addAbstractParameterSignature(str);
267 for (
unsigned i = 0; i < parseTypeList.size(); ++i) {
268 if (!parseTypeList[i] && typeList.size() > i && typeList[i])
269 str.append(QoreTypeInfo::getPath(typeList[i]));
271 str.append(QoreParseTypeInfo::getName(parseTypeList[i]));
272 if (i != parseTypeList.size() - 1)
278 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo(
int& err)
const {
279 if (
const_cast<UserSignature*
>(
this)->resolve() && !err) {
282 return returnTypeInfo;
285 DLLLOCAL
const QoreProgramLocation* getParseLocation()
const {
289 DLLLOCAL
bool hasReturnTypeInfo()
const {
290 return parseReturnTypeInfo || returnTypeInfo;
293 DLLLOCAL
void parseInitPushLocalVars(
const QoreTypeInfo* classTypeInfo);
296 DLLLOCAL
void parseInitPopLocalVars();
299class AbstractQoreFunctionVariant;
316 DLLLOCAL CodeEvaluationHelper(
ExceptionSink* n_xsink,
const QoreFunction* func,
317 const AbstractQoreFunctionVariant*& variant,
const char* n_name,
const QoreListNode* args =
nullptr,
318 QoreObject* self =
nullptr,
const qore_class_private* n_qc =
nullptr, qore_call_t n_ct = CT_UNUSED,
319 bool is_copy =
false,
const qore_class_private* cctx =
nullptr);
335 DLLLOCAL CodeEvaluationHelper(
ExceptionSink* n_xsink,
const QoreFunction* func,
336 const AbstractQoreFunctionVariant*& variant,
const char* n_name,
QoreListNode* args,
337 QoreObject* self =
nullptr,
const qore_class_private* n_qc =
nullptr, qore_call_t n_ct = CT_UNUSED,
338 bool is_copy =
false,
const qore_class_private* cctx =
nullptr);
340 DLLLOCAL ~CodeEvaluationHelper();
342 DLLLOCAL
void setReturnTypeInfo(
const QoreTypeInfo* n_returnTypeInfo) {
343 returnTypeInfo = saveReturnTypeInfo(n_returnTypeInfo);
347 DLLLOCAL
void setCallType(qore_call_t n_ct) {
363 DLLLOCAL
int processDefaultArgs(
const QoreFunction* func,
const AbstractQoreFunctionVariant* variant,
364 bool check_args,
bool is_copy,
QoreObject* self);
368 tmp.assign(
true, n_args);
388 DLLLOCAL
const qore_class_private* getClass()
const {
393 DLLLOCAL
virtual const QoreProgramLocation&
getLocation()
const {
399 DLLLOCAL
virtual const std::string&
getCallName()
const {
412 DLLLOCAL
virtual const AbstractStatement*
getStatement()
const {
417 DLLLOCAL
const char* getName()
const {
426 const qore_class_private* qc;
427 const QoreProgramLocation* loc;
429 const QoreTypeInfo* returnTypeInfo;
431 const AbstractStatement* stmt =
nullptr;
433 std::string callName;
435 const QoreProgramLocation* old_runtime_loc =
nullptr;
436 bool restore_stack =
false;
438 DLLLOCAL
void init(
const QoreFunction* func,
const AbstractQoreFunctionVariant*& variant,
bool is_copy,
439 const qore_class_private* cctx,
QoreObject* self);
441 DLLLOCAL
void setCallName(
const QoreFunction* func);
444class UserVariantBase;
449 DLLLOCAL AbstractQoreFunctionVariant(
int64 n_flags,
bool n_is_user =
false) : flags(n_flags), is_user(n_is_user) {
452 DLLLOCAL
const QoreTypeInfo* parseGetReturnTypeInfo()
const {
454 return parseGetReturnTypeInfo(err);
457 DLLLOCAL
virtual AbstractFunctionSignature* getSignature()
const = 0;
458 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo(
int& err)
const = 0;
460 DLLLOCAL
const QoreTypeInfo* getReturnTypeInfo()
const {
461 return getSignature()->getReturnTypeInfo();
464 DLLLOCAL
unsigned numParams()
const {
465 AbstractFunctionSignature* sig = getSignature();
466 return sig ? sig->numParams() : 0;
469 DLLLOCAL qore_call_t getCallType()
const {
470 return is_user ? CT_USER : CT_BUILTIN;
473 DLLLOCAL
int64 getParseOptions(
int64 po)
const;
475 DLLLOCAL
int64 getFlags()
const {
479 DLLLOCAL
virtual int64 getFunctionality()
const = 0;
483 DLLLOCAL
virtual void setRecheck() {
487 DLLLOCAL
void parseResolveUserSignature();
489 DLLLOCAL
virtual UserVariantBase* getUserVariantBase() {
493 DLLLOCAL
const UserVariantBase* getUserVariantBase()
const {
495 return is_user ?
const_cast<AbstractQoreFunctionVariant*
>(
this)->getUserVariantBase() : nullptr;
498 DLLLOCAL
virtual QoreValue evalFunction(
const char* name, CodeEvaluationHelper& ceh,
ExceptionSink* xsink)
const {
503 DLLLOCAL
virtual const QoreClass* getClass()
const {
507 DLLLOCAL
const char* className()
const {
509 return qc ? qc->
getName() :
nullptr;
512 DLLLOCAL std::string classPath()
const {
515 return std::string();
520 DLLLOCAL
bool isSignatureIdentical(
const AbstractFunctionSignature& sig,
bool relaxed_match =
false)
const {
523 return getSignature()->compare(sig, relaxed_match);
527 DLLLOCAL LocalVar* getSelfId()
const;
529 DLLLOCAL AbstractQoreFunctionVariant* ref() {
534 DLLLOCAL
void deref() {
540 DLLLOCAL
bool isUser()
const {
544 DLLLOCAL
bool hasBody()
const;
546 DLLLOCAL
virtual bool isModulePublic()
const {
551 DLLLOCAL
virtual int parseInit(QoreFunction* f) {
556 DLLLOCAL
virtual void parseCommit() {
559 DLLLOCAL
virtual bool hasVarargs()
const {
560 return flags & QCF_USES_EXTRA_ARGS;
568 DLLLOCAL
virtual ~AbstractQoreFunctionVariant() {}
572 DLLLOCAL AbstractQoreFunctionVariant(
const AbstractQoreFunctionVariant& old) =
delete;
573 DLLLOCAL AbstractQoreFunctionVariant& operator=(AbstractQoreFunctionVariant& orig) =
delete;
577class UserVariantExecHelper;
580class UserVariantBase {
581 friend class UserVariantExecHelper;
584 UserSignature signature;
585 StatementBlock* statements;
600 const qore_class_private* qc =
nullptr)
const;
604 DLLLOCAL UserVariantBase(StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params,
605 RetTypeInfo* rv,
bool synced);
606 DLLLOCAL
virtual ~UserVariantBase();
607 DLLLOCAL UserSignature* getUserSignature()
const {
608 return const_cast<UserSignature*
>(&signature);
611 DLLLOCAL
bool isSynchronized()
const {
615 DLLLOCAL
void setInit() {
619 DLLLOCAL
bool getInit()
const {
623 DLLLOCAL
bool hasBody()
const {
624 return (
bool)statements;
626 DLLLOCAL StatementBlock* getStatementBlock()
const {
630 DLLLOCAL
int64 getParseOptions(
int64 po)
const;
632 DLLLOCAL
void parseInitPushLocalVars(
const QoreTypeInfo* classTypeInfo);
634 DLLLOCAL
void parseInitPopLocalVars();
636 DLLLOCAL
void setSelfId(LocalVar* selfid) {
637 signature.setSelfId(selfid);
640 DLLLOCAL
void parseCommit();
644#define COMMON_USER_VARIANT_FUNCTIONS DLLLOCAL virtual int64 getFunctionality() const { return QDOM_DEFAULT; } \
645 using AbstractQoreFunctionVariant::getUserVariantBase; \
646 DLLLOCAL virtual UserVariantBase* getUserVariantBase() { return static_cast<UserVariantBase*>(this); } \
647 DLLLOCAL virtual AbstractFunctionSignature* getSignature() const { return const_cast<UserSignature*>(&signature); } \
648 DLLLOCAL virtual const QoreTypeInfo* parseGetReturnTypeInfo(int& err) const { return signature.parseGetReturnTypeInfo(err); } \
649 DLLLOCAL virtual void setRecheck() { recheck = true; } \
650 DLLLOCAL virtual void parseCommit() { UserVariantBase::parseCommit(); } \
651 DLLLOCAL virtual bool hasVarargs() const { if (signature.hasVarargs()) return true; return AbstractQoreFunctionVariant::hasVarargs(); }
655class UserVariantExecHelper : ProgramThreadCountContextHelper, ThreadFrameBoundaryHelper {
657 const UserVariantBase* uvb;
662 DLLLOCAL UserVariantExecHelper(
const UserVariantBase* n_uvb, CodeEvaluationHelper* ceh,
ExceptionSink* n_xsink) :
663 ProgramThreadCountContextHelper(n_xsink, n_uvb->pgm, true),
664 ThreadFrameBoundaryHelper(!*n_xsink),
665 uvb(n_uvb), argv(n_xsink), xsink(n_xsink) {
667 if (*xsink || uvb->setupCall(ceh, argv, xsink))
671 DLLLOCAL ~UserVariantExecHelper();
673 DLLLOCAL
operator bool()
const {
682class UserFunctionVariant :
public AbstractQoreFunctionVariant,
public UserVariantBase {
686 DLLLOCAL
virtual ~UserFunctionVariant() {
690 DLLLOCAL UserFunctionVariant(StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params,
691 RetTypeInfo* rv,
bool synced,
int64 n_flags = QCF_NO_FLAGS) :
692 AbstractQoreFunctionVariant(n_flags, true),
693 UserVariantBase(b, n_sig_first_line, n_sig_last_line, params, rv, synced), mod_pub(false) {
694 if (signature.hasVarargs()) {
695 flags |= QCF_USES_EXTRA_ARGS;
700 COMMON_USER_VARIANT_FUNCTIONS
702 DLLLOCAL
virtual QoreValue evalFunction(
const char* name, CodeEvaluationHelper& ceh,
ExceptionSink* xsink)
const {
703 return eval(name, &ceh, 0, xsink);
706 DLLLOCAL
virtual int parseInit(QoreFunction* f);
708 DLLLOCAL
virtual bool isModulePublic()
const {
712 DLLLOCAL
void setModulePublic() {
718#define UFV(f) (reinterpret_cast<UserFunctionVariant*>(f))
719#define UFV_const(f) (reinterpret_cast<const UserFunctionVariant*>(f))
723typedef safe_dslist<AbstractQoreFunctionVariant*> vlist_t;
725class VList :
public vlist_t {
730 DLLLOCAL
void del() {
732 for (vlist_t::iterator i = begin(), e = end(); i != e; ++i)
743 DLLLOCAL INode(QoreFunction* f, ClassAccess a) : func(f), access(a) {
748typedef std::vector<INode> ilist_t;
750hashdecl IList :
public ilist_t {
751 DLLLOCAL QoreFunction* getFunction(
const qore_class_private* class_ctx,
const qore_class_private*& last_class,
752 const_iterator aqfi,
bool& internal_access,
bool& stop)
const;
756friend class QoreFunctionIterator;
757friend class qore_external_function_iterator_private;
759 DLLLOCAL QoreFunction(
const char* n_name) : name(n_name),
760 same_return_type(true),
761 nn_same_return_type(true),
763 parse_init_done(true),
764 parse_init_in_progress(false),
772 ilist.push_back(INode(
this, Public));
774 const char* mod_name = get_module_context_name();
776 from_module = mod_name;
781 DLLLOCAL QoreFunction(
const QoreFunction& old,
int64 po = 0,
bool copy_all =
false,
bool n_inject =
false)
783 unique_functionality(old.unique_functionality),
784 unique_flags(old.unique_flags),
785 nn_unique_functionality(old.nn_unique_functionality),
786 nn_unique_flags(old.nn_unique_flags),
787 nn_count(old.nn_count),
788 same_return_type(old.same_return_type),
789 nn_same_return_type(old.nn_same_return_type),
791 parse_init_done(true),
792 parse_init_in_progress(false),
793 has_user(old.has_user),
794 has_builtin(old.has_builtin),
798 has_priv(old.has_priv),
799 all_priv(old.all_priv),
800 nn_uniqueReturnType(old.nn_uniqueReturnType),
801 from_module(old.from_module) {
803 bool no_builtin = po & PO_NO_SYSTEM_FUNC_VARIANTS;
806 for (vlist_t::const_iterator i = old.vlist.begin(), e = old.vlist.end(); i != e; ++i) {
808 if ((*i)->isUser()) {
809 if (no_user || !(*i)->isModulePublic())
817 vlist.push_back((*i)->ref());
820 if (no_user && has_user)
822 if (no_builtin && has_builtin)
826 assert(old.vlist.empty() || !vlist.empty());
828 assert(!old.ilist.empty());
829 assert(old.ilist.front().func == &old);
832 ilist.push_back(INode(
this, Public));
841 DLLLOCAL QoreFunction(
bool ignore,
const QoreFunction& old, qore_ns_private* nns)
842 : name(old.name), ns(nns), same_return_type(old.same_return_type),
843 unique_functionality(old.unique_functionality),
844 unique_flags(old.unique_flags),
845 nn_same_return_type(old.nn_same_return_type),
846 nn_unique_functionality(old.nn_unique_functionality),
847 nn_unique_flags(old.nn_unique_flags),
848 nn_count(old.nn_count),
849 parse_rt_done(true), parse_init_done(true),
850 has_user(true), has_builtin(false), has_mod_pub(false ), inject(false),
851 nn_uniqueReturnType(old.nn_uniqueReturnType) {
853 assert(old.has_mod_pub);
856 for (vlist_t::const_iterator i = old.vlist.begin(), e = old.vlist.end(); i != e; ++i) {
857 if (!(*i)->isModulePublic())
859 vlist.push_back((*i)->ref());
863 assert(old.vlist.empty() || !vlist.empty());
865 assert(!old.ilist.empty());
866 assert(old.ilist.front().func == &old);
869 ilist.push_back(INode(
this, Public));
878 DLLLOCAL
const AbstractQoreFunctionVariant* first()
const {
879 assert(!vlist.empty());
880 return *(vlist.begin());
884 DLLLOCAL AbstractQoreFunctionVariant* first() {
885 assert(!vlist.empty());
886 return *(vlist.begin());
889 DLLLOCAL
unsigned numVariants()
const {
896 DLLLOCAL
int parseCheckDuplicateSignatureCommitted(UserSignature* sig);
898 DLLLOCAL
const char* getName()
const {
902 DLLLOCAL
virtual const QoreClass* getClass()
const {
906 DLLLOCAL
void ref() {
910 DLLLOCAL
void deref() {
915 DLLLOCAL
const char* className()
const {
917 return qc ? qc->
getName() :
nullptr;
920 DLLLOCAL std::string classPath()
const {
923 return std::string();
928 DLLLOCAL
void addAncestor(QoreFunction* ancestor, ClassAccess access) {
929 ilist.push_back(INode(ancestor, access));
932 DLLLOCAL
void addNewAncestor(QoreFunction* ancestor, ClassAccess access) {
933 for (ilist_t::iterator i = ilist.begin(), e = ilist.end(); i != e; ++i)
934 if ((*i).func == ancestor)
936 ilist.push_back(INode(ancestor, access));
940 DLLLOCAL
void resolvePendingSignatures();
942 DLLLOCAL AbstractFunctionSignature* getUniqueSignature()
const {
943 return vlist.singular() ? first()->getSignature() : 0;
946 DLLLOCAL AbstractFunctionSignature* parseGetUniqueSignature()
const;
948 DLLLOCAL
int64 parseGetUniqueFunctionality()
const {
950 return nn_unique_functionality;
951 return unique_functionality;
954 DLLLOCAL
int64 parseGetUniqueFlags()
const {
956 return nn_unique_flags;
961 DLLLOCAL
int addPendingVariant(AbstractQoreFunctionVariant* variant);
963 DLLLOCAL
void addBuiltinVariant(AbstractQoreFunctionVariant* variant);
965 DLLLOCAL
int parseInit(qore_ns_private* ns);
966 DLLLOCAL
void parseCommit();
967 DLLLOCAL
void parseRollback();
969 DLLLOCAL
const QoreTypeInfo* getUniqueReturnTypeInfo()
const {
971 return nn_uniqueReturnType;
973 return same_return_type && !vlist.empty() ? first()->getReturnTypeInfo() : 0;
976 DLLLOCAL
const QoreTypeInfo* parseGetUniqueReturnTypeInfo() {
977 parseCheckReturnType();
981 if (!same_return_type)
985 if (!nn_same_return_type)
988 return nn_count ? nn_uniqueReturnType : (!vlist.empty() ? first()->getReturnTypeInfo() :
nullptr);
992 return first()->getReturnTypeInfo();
1010 DLLLOCAL
const AbstractQoreFunctionVariant* parseFindVariant(
const QoreProgramLocation* loc,
1011 const type_vec_t& argTypeInfo,
const qore_class_private* class_ctx,
int& err)
const;
1014 DLLLOCAL
bool pendingEmpty()
const {
1015 return vlist.empty() || !check_parse;
1019 DLLLOCAL
bool committedEmpty()
const {
1020 return vlist.empty() || check_parse;
1023 DLLLOCAL
bool existsVariant(
const type_vec_t& paramTypeInfo)
const;
1027 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindVariant(
ExceptionSink* xsink,
const QoreListNode* args,
bool only_user,
const qore_class_private* class_ctx)
const;
1030 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindVariant(
ExceptionSink* xsink,
const type_vec_t& args,
const qore_class_private* class_ctx)
const;
1032 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindExactVariant(
ExceptionSink* xsink,
const type_vec_t& args,
const qore_class_private* class_ctx)
const;
1034 DLLLOCAL
void parseAssimilate(QoreFunction& other) {
1035 while (!other.vlist.empty()) {
1036 addPendingVariant(*(other.vlist.begin()));
1037 other.vlist.pop_front();
1041 DLLLOCAL
bool hasUser()
const {
1045 DLLLOCAL
bool hasBuiltin()
const {
1049 DLLLOCAL
bool hasPublic()
const {
1053 DLLLOCAL
bool hasUserPublic()
const {
1054 return has_pub && has_user;
1057 DLLLOCAL
bool injected()
const {
1061 DLLLOCAL
bool hasPrivate()
const {
1065 DLLLOCAL
bool allPrivate()
const {
1069 DLLLOCAL
const std::string& getNameStr()
const {
1073 DLLLOCAL
const char* getModuleName()
const {
1074 return from_module.empty() ? nullptr : from_module.c_str();
1087 int64 unique_flags = QCF_NO_FLAGS;
1091 int64 nn_unique_flags = QCF_NO_FLAGS;
1095 bool same_return_type : 1;
1096 bool nn_same_return_type : 1;
1097 bool parse_rt_done : 1;
1098 bool parse_init_done : 1;
1099 bool parse_init_in_progress : 1;
1101 bool has_builtin : 1;
1104 bool check_parse : 1;
1108 const QoreTypeInfo* nn_uniqueReturnType =
nullptr;
1110 std::string from_module;
1112 DLLLOCAL
int parseCheckReturnType() {
1116 parse_rt_done =
true;
1118 if (!same_return_type)
1123 for (vlist_t::iterator i = vlist.begin(), e = vlist.end(); i != e; ++i) {
1124 if (
reinterpret_cast<UserSignature*
>((*i)->getUserVariantBase()->getUserSignature())->resolve() && !err) {
1127 const QoreTypeInfo* rti = (*i)->getReturnTypeInfo();
1129 if (i == vlist.begin()) {
1133 if (!QoreTypeInfo::isOutputIdentical(rti, first()->getReturnTypeInfo())) {
1134 same_return_type =
false;
1143 DLLLOCAL
static int parseCompareResolvedSignature(
const VList& vlist,
const AbstractFunctionSignature* sig,
1144 const AbstractFunctionSignature*& vs);
1147 DLLLOCAL
int parseCheckDuplicateSignature(AbstractQoreFunctionVariant* variant);
1150 DLLLOCAL
void addVariant(AbstractQoreFunctionVariant* variant) {
1151 const QoreTypeInfo* rti = variant->getReturnTypeInfo();
1152 if (same_return_type && !vlist.empty() && !QoreTypeInfo::isOutputIdentical(rti, first()->getReturnTypeInfo()))
1153 same_return_type =
false;
1155 int64 vf = variant->getFunctionality();
1156 int64 vflags = variant->getFlags();
1158 bool rtn = (bool)(vflags & QCF_RUNTIME_NOOP);
1160 if (vlist.empty()) {
1161 unique_functionality = vf;
1162 unique_flags = vflags;
1164 unique_functionality &= vf;
1165 unique_flags &= vflags;
1170 nn_unique_functionality = vf;
1171 nn_unique_flags = vflags;
1172 nn_uniqueReturnType = rti;
1175 nn_unique_functionality &= vf;
1176 nn_unique_flags &= vflags;
1177 if (nn_uniqueReturnType && !QoreTypeInfo::isOutputIdentical(rti, nn_uniqueReturnType))
1178 nn_uniqueReturnType = 0;
1183 vlist.push_back(variant);
1186 DLLLOCAL
virtual ~QoreFunction() {
1191 const qore_class_private* class_ctx,
const QoreFunction* aqf,
const qore_class_private* last_class,
1192 bool internal_access,
int64 ppo,
const AbstractQoreFunctionVariant* variant)
const;
1195class QoreFunctionIterator {
1197 DLLLOCAL QoreFunctionIterator(
const QoreFunction& f) : f(f) {
1201 DLLLOCAL
bool next() {
1202 if (i == f.vlist.end()) {
1203 i = f.vlist.begin();
1209 return i != f.vlist.end();
1212 DLLLOCAL
const AbstractQoreFunctionVariant* getVariant()
const {
1217 const QoreFunction& f;
1218 VList::const_iterator i;
1221class MethodVariantBase;
1222class MethodFunctionBase;
1223#define METHFB(f) (reinterpret_cast<MethodFunctionBase*>(f))
1224#define METHFB_const(f) (reinterpret_cast<const MethodFunctionBase*>(f))
1226class MethodFunctionBase :
public QoreFunction {
1227friend hashdecl AbstractMethod;
1235 mutable MethodFunctionBase* new_copy =
nullptr;
1240 has_private_internal_variants =
false;
1244 DLLLOCAL
int checkFinalVariant(
const MethodFunctionBase* m,
const MethodVariantBase* v)
const;
1246 DLLLOCAL
void replaceAbstractVariantIntern(MethodVariantBase* variant);
1249 DLLLOCAL MethodFunctionBase(
const char* nme,
const QoreClass* n_qc,
bool n_is_static) : QoreFunction(nme),
1250 qc(n_qc), is_static(n_is_static), has_final(false), access(Internal) {
1254 DLLLOCAL MethodFunctionBase(
const MethodFunctionBase& old,
const QoreClass* n_qc)
1255 : QoreFunction(old, 0, true),
1257 is_static(old.is_static),
1258 has_final(old.has_final),
1259 is_abstract(old.is_abstract),
1260 has_private_internal_variants(old.has_private_internal_variants),
1261 access(old.access) {
1265 old.new_copy =
this;
1268 ilist.reserve(old.ilist.size());
1269 ilist_t::const_iterator i = old.ilist.begin(), e = old.ilist.end();
1271 for (; i != e; ++i) {
1272 ilist.push_back(*i);
1276 DLLLOCAL
void resolveCopy() {
1277 ilist_t::iterator i = ilist.begin(), e = ilist.end();
1279 for (; i != e; ++i) {
1280 MethodFunctionBase* mfb = METHFB((*i).func);
1283 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());
1284 assert(mfb->new_copy);
1287 (*i).func = mfb->new_copy;
1291 DLLLOCAL
int parseInit();
1292 DLLLOCAL
void parseCommit();
1293 DLLLOCAL
void parseRollback();
1296 DLLLOCAL
int parseAddUserMethodVariant(MethodVariantBase* variant);
1299 DLLLOCAL
void addBuiltinMethodVariant(MethodVariantBase* variant);
1302 DLLLOCAL
void parseCommitMethod(
QoreString& csig,
const char* mod);
1304 DLLLOCAL
void parseCommitMethod();
1306 DLLLOCAL
void parseSignatures(
QoreString& csig,
const char* mod)
const;
1309 DLLLOCAL MethodVariantBase* parseHasVariantWithSignature(MethodVariantBase* v,
bool relaxed_match =
false)
const;
1311 DLLLOCAL
void replaceAbstractVariant(MethodVariantBase* variant);
1313 DLLLOCAL
void parseRollbackMethod();
1315 DLLLOCAL
bool isUniquelyPrivate()
const {
1316 return access > Public;
1319 DLLLOCAL
bool isAbstract()
const {
1323 DLLLOCAL ClassAccess getAccess()
const {
1327 DLLLOCAL
virtual const QoreClass* getClass()
const {
1331 DLLLOCAL
const char* getClassName()
const {
1335 DLLLOCAL std::string classPath()
const {
1337 return std::string();
1342 DLLLOCAL
bool isStatic()
const {
1346 DLLLOCAL
bool hasPrivateInternalVariants()
const {
1347 return has_private_internal_variants;
1350 DLLLOCAL
int checkFinal()
const;
1353 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const = 0;
1356class UserParamListLocalVarHelper {
1358 UserVariantBase* uvb;
1361 DLLLOCAL UserParamListLocalVarHelper(UserVariantBase* n_uvb,
const QoreTypeInfo* classTypeInfo = 0) : uvb(n_uvb) {
1362 uvb->parseInitPushLocalVars(classTypeInfo);
1365 DLLLOCAL ~UserParamListLocalVarHelper() {
1366 uvb->parseInitPopLocalVars();
1370class UserClosureVariant :
public UserFunctionVariant {
1373 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) {
1376 DLLLOCAL
virtual int parseInit(QoreFunction* f);
1379 return eval(
"<anonymous closure>", &ceh, self, xsink);
1383#define UCLOV(f) (reinterpret_cast<UserClosureVariant*>(f))
1384#define UCLOV_const(f) (reinterpret_cast<const UserClosureVariant*>(f))
1386class UserClosureFunction :
public QoreFunction {
1389 const QoreTypeInfo* classTypeInfo;
1392 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) {
1393 addPendingVariant(
new UserClosureVariant(b, n_sig_first_line, n_sig_last_line, params, rv, synced, n_flags));
1398 DLLLOCAL
void setClassType(
const QoreTypeInfo* cti) {
1399 classTypeInfo = cti;
1402 DLLLOCAL
const QoreTypeInfo* getClassType()
const {
1403 return classTypeInfo;
1406 DLLLOCAL LVarSet* getVList() {
1411 DLLLOCAL
bool needsScan()
const {
1412 return varlist.needsScan();
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:170
#define PO_REQUIRE_TYPES
require type information for all declarations
Definition: Restrictions.h:61
#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
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
defines a Qore-language class
Definition: QoreClass.h:253
DLLEXPORT const char * getName() const
returns the class name
DLLEXPORT std::string getNamespacePath(bool anchored=false) const
returns the full namespace path of the class
For use on the stack only: manages result of the optional evaluation of a QoreListNode.
Definition: QoreListNodeEvalOptionalRefHolder.h:37
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:60
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:128
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:44
DLLEXPORT void ROreference() const
atomically increments the reference count
DLLEXPORT bool ROdereference() const
atomically decrements the reference count
Stack location element abstract class.
Definition: ExceptionSink.h:418
virtual DLLLOCAL const QoreProgramLocation & getLocation() const =0
returns the source location of the element
virtual DLLLOCAL const std::string & getCallName() const =0
returns the name of the function or method call
virtual DLLLOCAL QoreProgram * getProgram() const =0
returns the QoreProgram container
virtual DLLLOCAL const AbstractStatement * getStatement() const =0
returns the statement for the call for internal Qore code
virtual DLLLOCAL qore_call_t getCallType() const =0
returns the call type
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
a templated class to manage a reference count of an object that can throw a Qore-language exception w...
Definition: ReferenceHolder.h:52
uint64_t q_rt_flags_t
runtime code execution flags
Definition: common.h:263
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:251
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:257
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
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276