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)
75 : returnTypeInfo(n_returnTypeInfo) {
78 DLLLOCAL AbstractFunctionSignature(
const QoreTypeInfo* n_returnTypeInfo,
const type_vec_t& n_typeList,
80 : returnTypeInfo(n_returnTypeInfo), typeList(n_typeList), defaultArgList(n_defaultArgList),
84 DLLLOCAL
virtual ~AbstractFunctionSignature() {
86 for (arg_vec_t::iterator i = defaultArgList.begin(), e = defaultArgList.end(); i != e; ++i) {
87 (*i).discard(
nullptr);
92 DLLLOCAL
const QoreTypeInfo* parseGetReturnTypeInfo()
const {
94 return parseGetReturnTypeInfo(err);
98 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo(
int& err)
const = 0;
100 DLLLOCAL
virtual const QoreParseTypeInfo* getParseParamTypeInfo(
unsigned num)
const = 0;
102 DLLLOCAL
const QoreTypeInfo* getReturnTypeInfo()
const {
103 return returnTypeInfo;
106 DLLLOCAL
const arg_vec_t& getDefaultArgList()
const {
107 return defaultArgList;
110 DLLLOCAL
const type_vec_t& getTypeList()
const {
114 DLLLOCAL
const name_vec_t& getParamNames()
const {
119 assert(i < defaultArgList.size());
120 return defaultArgList[i].eval(xsink);
123 DLLLOCAL
const char* getSignatureText()
const {
127 DLLLOCAL
virtual void addAbstractParameterSignature(std::string& str)
const {
128 for (
unsigned i = 0; i < typeList.size(); ++i) {
129 str.append(QoreTypeInfo::getPath(typeList[i]));
130 const char* vname = getName(i);
135 if (hasDefaultArg(i)) {
136 addDefaultArgument(str, defaultArgList[i]);
138 if (i != typeList.size() - 1) {
144 DLLLOCAL
unsigned numParams()
const {
145 return (
unsigned)typeList.size();
149 DLLLOCAL
unsigned getParamTypes()
const {
150 return num_param_types;
153 DLLLOCAL
unsigned getMinParamTypes()
const {
154 return min_param_types;
157 DLLLOCAL
const QoreTypeInfo* getParamTypeInfo(
unsigned num)
const {
158 return num >= typeList.size() ? 0 : typeList[num];
161 DLLLOCAL
bool hasDefaultArg(
unsigned i)
const {
162 return i >= defaultArgList.size() || !defaultArgList[i] ? false :
true;
166 DLLLOCAL
static void addDefaultArgument(std::string& str,
QoreValue arg);
168 DLLLOCAL
const char* getName(
unsigned i)
const {
169 return i < names.size() ? names[i].c_str() : 0;
172 DLLLOCAL
bool compare(
const AbstractFunctionSignature& sig,
bool relaxed_match =
false)
const;
177 QoreParseTypeInfo* parseTypeInfo;
178 const QoreTypeInfo* typeInfo;
181 DLLLOCAL RetTypeInfo(QoreParseTypeInfo* n_parseTypeInfo,
const QoreTypeInfo* n_typeInfo) : parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
183 DLLLOCAL ~RetTypeInfo() {
184 delete parseTypeInfo;
186 DLLLOCAL
const QoreTypeInfo* getTypeInfo()
const {
189 DLLLOCAL QoreParseTypeInfo* takeParseTypeInfo() {
190 QoreParseTypeInfo* rv = parseTypeInfo;
196 class UserSignature :
public AbstractFunctionSignature {
198 ptype_vec_t parseTypeList;
199 QoreParseTypeInfo* parseReturnTypeInfo;
201 const QoreProgramLocation* loc;
203 DLLLOCAL
int pushParam(BarewordNode* b,
bool needs_types,
bool bare_refs);
204 DLLLOCAL
int pushParam(QoreOperatorNode* t,
bool needs_types);
205 DLLLOCAL
int pushParam(VarRefNode* v,
QoreValue defArg,
bool needs_types);
207 DLLLOCAL
void param_error() {
208 parse_error(*loc,
"parameter list contains non-variable reference expressions");
218 DLLLOCAL UserSignature(
int n_first_line,
int n_last_line,
QoreValue params, RetTypeInfo* retTypeInfo,
int64 po);
220 DLLLOCAL
virtual ~UserSignature() {
221 for (ptype_vec_t::iterator i = parseTypeList.begin(), e = parseTypeList.end(); i != e; ++i)
223 delete parseReturnTypeInfo;
226 DLLLOCAL
void setFirstParamType(
const QoreTypeInfo* typeInfo) {
227 assert(!typeList.empty());
228 typeList[0] = typeInfo;
231 DLLLOCAL
void setSelfId(LocalVar* n_selfid) {
236 DLLLOCAL LocalVar* getSelfId()
const {
240 DLLLOCAL
virtual const QoreParseTypeInfo* getParseParamTypeInfo(
unsigned num)
const {
241 return num < parseTypeList.size() ? parseTypeList[num] :
nullptr;
245 DLLLOCAL
virtual int resolve();
247 DLLLOCAL
virtual void addAbstractParameterSignature(std::string& str)
const {
249 AbstractFunctionSignature::addAbstractParameterSignature(str);
253 for (
unsigned i = 0; i < parseTypeList.size(); ++i) {
254 if (!parseTypeList[i] && typeList.size() > i && typeList[i])
255 str.append(QoreTypeInfo::getPath(typeList[i]));
257 str.append(QoreParseTypeInfo::getName(parseTypeList[i]));
258 if (i != parseTypeList.size() - 1)
264 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo(
int& err)
const {
265 if (
const_cast<UserSignature*
>(
this)->resolve() && !err) {
268 return returnTypeInfo;
271 DLLLOCAL
const QoreProgramLocation* getParseLocation()
const {
275 DLLLOCAL
bool hasReturnTypeInfo()
const {
276 return parseReturnTypeInfo || returnTypeInfo;
279 DLLLOCAL
void parseInitPushLocalVars(
const QoreTypeInfo* classTypeInfo);
282 DLLLOCAL
void parseInitPopLocalVars();
285 class AbstractQoreFunctionVariant;
302 DLLLOCAL CodeEvaluationHelper(
ExceptionSink* n_xsink,
const QoreFunction* func,
303 const AbstractQoreFunctionVariant*& variant,
const char* n_name,
const QoreListNode* args =
nullptr,
304 QoreObject*
self =
nullptr,
const qore_class_private* n_qc =
nullptr, qore_call_t n_ct = CT_UNUSED,
305 bool is_copy =
false,
const qore_class_private* cctx =
nullptr);
321 DLLLOCAL CodeEvaluationHelper(
ExceptionSink* n_xsink,
const QoreFunction* func,
322 const AbstractQoreFunctionVariant*& variant,
const char* n_name,
QoreListNode* args,
323 QoreObject*
self =
nullptr,
const qore_class_private* n_qc =
nullptr, qore_call_t n_ct = CT_UNUSED,
324 bool is_copy =
false,
const qore_class_private* cctx =
nullptr);
326 DLLLOCAL ~CodeEvaluationHelper();
328 DLLLOCAL
void setReturnTypeInfo(
const QoreTypeInfo* n_returnTypeInfo) {
329 returnTypeInfo = saveReturnTypeInfo(n_returnTypeInfo);
333 DLLLOCAL
void setCallType(qore_call_t n_ct) {
349 DLLLOCAL
int processDefaultArgs(
const QoreFunction* func,
const AbstractQoreFunctionVariant* variant,
350 bool check_args,
bool is_copy,
QoreObject*
self);
354 tmp.assign(
true, n_args);
374 DLLLOCAL
const qore_class_private* getClass()
const {
379 DLLLOCAL
virtual const QoreProgramLocation&
getLocation()
const {
385 DLLLOCAL
virtual const std::string&
getCallName()
const {
398 DLLLOCAL
virtual const AbstractStatement*
getStatement()
const {
407 const qore_class_private* qc;
408 const QoreProgramLocation* loc;
410 const QoreTypeInfo* returnTypeInfo;
412 const AbstractStatement* stmt =
nullptr;
414 std::string callName;
416 const QoreProgramLocation* old_runtime_loc =
nullptr;
417 bool restore_stack =
false;
419 DLLLOCAL
void init(
const QoreFunction* func,
const AbstractQoreFunctionVariant*& variant,
bool is_copy,
420 const qore_class_private* cctx,
QoreObject*
self);
422 DLLLOCAL
void setCallName(
const QoreFunction* func);
425 class UserVariantBase;
431 DLLLOCAL AbstractQoreFunctionVariant(
const AbstractQoreFunctionVariant& old) =
delete;
432 DLLLOCAL AbstractQoreFunctionVariant& operator=(AbstractQoreFunctionVariant& orig) =
delete;
439 DLLLOCAL
virtual ~AbstractQoreFunctionVariant() {}
442 DLLLOCAL AbstractQoreFunctionVariant(
int64 n_flags,
bool n_is_user =
false) : flags(n_flags), is_user(n_is_user) {
445 DLLLOCAL
const QoreTypeInfo* parseGetReturnTypeInfo()
const {
447 return parseGetReturnTypeInfo(err);
450 DLLLOCAL
virtual AbstractFunctionSignature* getSignature()
const = 0;
451 DLLLOCAL
virtual const QoreTypeInfo* parseGetReturnTypeInfo(
int& err)
const = 0;
453 DLLLOCAL
const QoreTypeInfo* getReturnTypeInfo()
const {
454 return getSignature()->getReturnTypeInfo();
457 DLLLOCAL
unsigned numParams()
const {
458 AbstractFunctionSignature* sig = getSignature();
459 return sig ? sig->numParams() : 0;
462 DLLLOCAL qore_call_t getCallType()
const {
463 return is_user ? CT_USER : CT_BUILTIN;
466 DLLLOCAL
int64 getParseOptions(
int64 po)
const;
468 DLLLOCAL
int64 getFlags()
const {
472 DLLLOCAL
virtual int64 getFunctionality()
const = 0;
476 DLLLOCAL
virtual void setRecheck() {
480 DLLLOCAL
void parseResolveUserSignature();
482 DLLLOCAL
virtual UserVariantBase* getUserVariantBase() {
486 DLLLOCAL
const UserVariantBase* getUserVariantBase()
const {
488 return is_user ?
const_cast<AbstractQoreFunctionVariant*
>(
this)->getUserVariantBase() : nullptr;
491 DLLLOCAL
virtual QoreValue evalFunction(
const char* name, CodeEvaluationHelper& ceh,
ExceptionSink* xsink)
const {
496 DLLLOCAL
virtual const QoreClass* getClass()
const {
500 DLLLOCAL
const char* className()
const {
502 return qc ? qc->
getName() :
nullptr;
505 DLLLOCAL std::string classPath()
const {
508 return std::string();
513 DLLLOCAL
bool isSignatureIdentical(
const AbstractFunctionSignature& sig,
bool relaxed_match =
false)
const {
516 return getSignature()->compare(sig, relaxed_match);
520 DLLLOCAL LocalVar* getSelfId()
const;
522 DLLLOCAL AbstractQoreFunctionVariant* ref() {
527 DLLLOCAL
void deref() {
533 DLLLOCAL
bool isUser()
const {
537 DLLLOCAL
bool hasBody()
const;
539 DLLLOCAL
virtual bool isModulePublic()
const {
544 DLLLOCAL
virtual int parseInit(QoreFunction* f) {
549 DLLLOCAL
virtual void parseCommit() {
554 class UserVariantExecHelper;
557 class UserVariantBase {
558 friend class UserVariantExecHelper;
561 UserSignature signature;
562 StatementBlock* statements;
577 const qore_class_private* qc =
nullptr)
const;
581 DLLLOCAL UserVariantBase(StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params,
582 RetTypeInfo* rv,
bool synced);
583 DLLLOCAL
virtual ~UserVariantBase();
584 DLLLOCAL UserSignature* getUserSignature()
const {
585 return const_cast<UserSignature*
>(&signature);
588 DLLLOCAL
bool isSynchronized()
const {
592 DLLLOCAL
void setInit() {
596 DLLLOCAL
bool getInit()
const {
600 DLLLOCAL
bool hasBody()
const {
601 return (
bool)statements;
603 DLLLOCAL StatementBlock* getStatementBlock()
const {
607 DLLLOCAL
int64 getParseOptions(
int64 po)
const;
609 DLLLOCAL
void parseInitPushLocalVars(
const QoreTypeInfo* classTypeInfo);
611 DLLLOCAL
void parseInitPopLocalVars();
613 DLLLOCAL
void setSelfId(LocalVar* selfid) {
614 signature.setSelfId(selfid);
617 DLLLOCAL
void parseCommit();
621 #define COMMON_USER_VARIANT_FUNCTIONS DLLLOCAL virtual int64 getFunctionality() const { return QDOM_DEFAULT; } \
622 using AbstractQoreFunctionVariant::getUserVariantBase; \
623 DLLLOCAL virtual UserVariantBase* getUserVariantBase() { return static_cast<UserVariantBase*>(this); } \
624 DLLLOCAL virtual AbstractFunctionSignature* getSignature() const { return const_cast<UserSignature*>(&signature); } \
625 DLLLOCAL virtual const QoreTypeInfo* parseGetReturnTypeInfo(int& err) const { return signature.parseGetReturnTypeInfo(err); } \
626 DLLLOCAL virtual void setRecheck() { recheck = true; } \
627 DLLLOCAL virtual void parseCommit() { UserVariantBase::parseCommit(); }
630 class UserVariantExecHelper : ProgramThreadCountContextHelper, ThreadFrameBoundaryHelper {
632 const UserVariantBase* uvb;
637 DLLLOCAL UserVariantExecHelper(
const UserVariantBase* n_uvb, CodeEvaluationHelper* ceh,
ExceptionSink* n_xsink) :
638 ProgramThreadCountContextHelper(n_xsink, n_uvb->pgm, true),
639 ThreadFrameBoundaryHelper(!*n_xsink),
640 uvb(n_uvb), argv(n_xsink), xsink(n_xsink) {
642 if (*xsink || uvb->setupCall(ceh, argv, xsink))
646 DLLLOCAL ~UserVariantExecHelper();
648 DLLLOCAL
operator bool()
const {
657 class UserFunctionVariant :
public AbstractQoreFunctionVariant,
public UserVariantBase {
661 DLLLOCAL
virtual ~UserFunctionVariant() {
665 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) :
666 AbstractQoreFunctionVariant(n_flags, true), UserVariantBase(b, n_sig_first_line, n_sig_last_line, params, rv, synced), mod_pub(false) {
670 COMMON_USER_VARIANT_FUNCTIONS
672 DLLLOCAL
virtual QoreValue evalFunction(
const char* name, CodeEvaluationHelper& ceh,
ExceptionSink* xsink)
const {
673 return eval(name, &ceh, 0, xsink);
676 DLLLOCAL
virtual int parseInit(QoreFunction* f);
678 DLLLOCAL
virtual bool isModulePublic()
const {
682 DLLLOCAL
void setModulePublic() {
688 #define UFV(f) (reinterpret_cast<UserFunctionVariant*>(f))
689 #define UFV_const(f) (reinterpret_cast<const UserFunctionVariant*>(f))
693 typedef safe_dslist<AbstractQoreFunctionVariant*> vlist_t;
695 class VList :
public vlist_t {
700 DLLLOCAL
void del() {
702 for (vlist_t::iterator i = begin(), e = end(); i != e; ++i)
713 DLLLOCAL INode(QoreFunction* f, ClassAccess a) : func(f), access(a) {
718 typedef std::vector<INode> ilist_t;
720 hashdecl IList :
public ilist_t {
721 DLLLOCAL QoreFunction* getFunction(
const qore_class_private* class_ctx,
const qore_class_private*& last_class,
722 const_iterator aqfi,
bool& internal_access,
bool& stop)
const;
726 friend class QoreFunctionIterator;
727 friend class qore_external_function_iterator_private;
729 DLLLOCAL QoreFunction(
const char* n_name) : name(n_name),
730 same_return_type(true),
731 nn_same_return_type(true),
733 parse_init_done(true),
734 parse_init_in_progress(false),
742 ilist.push_back(INode(
this, Public));
744 const char* mod_name = get_module_context_name();
746 from_module = mod_name;
751 DLLLOCAL QoreFunction(
const QoreFunction& old,
int64 po = 0,
bool copy_all =
false,
bool n_inject =
false)
753 unique_functionality(old.unique_functionality),
754 unique_flags(old.unique_flags),
755 nn_unique_functionality(old.nn_unique_functionality),
756 nn_unique_flags(old.nn_unique_flags),
757 nn_count(old.nn_count),
758 same_return_type(old.same_return_type),
759 nn_same_return_type(old.nn_same_return_type),
761 parse_init_done(true),
762 parse_init_in_progress(false),
763 has_user(old.has_user),
764 has_builtin(old.has_builtin),
768 has_priv(old.has_priv),
769 all_priv(old.all_priv),
770 nn_uniqueReturnType(old.nn_uniqueReturnType),
771 from_module(old.from_module) {
773 bool no_builtin = po & PO_NO_SYSTEM_FUNC_VARIANTS;
776 for (vlist_t::const_iterator i = old.vlist.begin(), e = old.vlist.end(); i != e; ++i) {
778 if ((*i)->isUser()) {
779 if (no_user || !(*i)->isModulePublic())
787 vlist.push_back((*i)->ref());
790 if (no_user && has_user)
792 if (no_builtin && has_builtin)
796 assert(old.vlist.empty() || !vlist.empty());
798 assert(!old.ilist.empty());
799 assert(old.ilist.front().func == &old);
802 ilist.push_back(INode(
this, Public));
811 DLLLOCAL QoreFunction(
bool ignore,
const QoreFunction& old, qore_ns_private* nns)
812 : name(old.name), ns(nns), same_return_type(old.same_return_type),
813 unique_functionality(old.unique_functionality),
814 unique_flags(old.unique_flags),
815 nn_same_return_type(old.nn_same_return_type),
816 nn_unique_functionality(old.nn_unique_functionality),
817 nn_unique_flags(old.nn_unique_flags),
818 nn_count(old.nn_count),
819 parse_rt_done(true), parse_init_done(true),
820 has_user(true), has_builtin(false), has_mod_pub(false ), inject(false),
821 nn_uniqueReturnType(old.nn_uniqueReturnType) {
823 assert(old.has_mod_pub);
826 for (vlist_t::const_iterator i = old.vlist.begin(), e = old.vlist.end(); i != e; ++i) {
827 if (!(*i)->isModulePublic())
829 vlist.push_back((*i)->ref());
833 assert(old.vlist.empty() || !vlist.empty());
835 assert(!old.ilist.empty());
836 assert(old.ilist.front().func == &old);
839 ilist.push_back(INode(
this, Public));
848 DLLLOCAL
const AbstractQoreFunctionVariant* first()
const {
849 assert(!vlist.empty());
850 return *(vlist.begin());
854 DLLLOCAL AbstractQoreFunctionVariant* first() {
855 assert(!vlist.empty());
856 return *(vlist.begin());
859 DLLLOCAL
unsigned numVariants()
const {
866 DLLLOCAL
int parseCheckDuplicateSignatureCommitted(UserSignature* sig);
868 DLLLOCAL
const char* getName()
const {
872 DLLLOCAL
virtual const QoreClass* getClass()
const {
876 DLLLOCAL
void ref() {
880 DLLLOCAL
void deref() {
885 DLLLOCAL
const char* className()
const {
887 return qc ? qc->
getName() :
nullptr;
890 DLLLOCAL std::string classPath()
const {
893 return std::string();
898 DLLLOCAL
void addAncestor(QoreFunction* ancestor, ClassAccess access) {
899 ilist.push_back(INode(ancestor, access));
902 DLLLOCAL
void addNewAncestor(QoreFunction* ancestor, ClassAccess access) {
903 for (ilist_t::iterator i = ilist.begin(), e = ilist.end(); i != e; ++i)
904 if ((*i).func == ancestor)
906 ilist.push_back(INode(ancestor, access));
910 DLLLOCAL
void resolvePendingSignatures();
912 DLLLOCAL AbstractFunctionSignature* getUniqueSignature()
const {
913 return vlist.singular() ? first()->getSignature() : 0;
916 DLLLOCAL AbstractFunctionSignature* parseGetUniqueSignature()
const;
918 DLLLOCAL
int64 parseGetUniqueFunctionality()
const {
920 return nn_unique_functionality;
921 return unique_functionality;
924 DLLLOCAL
int64 parseGetUniqueFlags()
const {
926 return nn_unique_flags;
931 DLLLOCAL
int addPendingVariant(AbstractQoreFunctionVariant* variant);
933 DLLLOCAL
void addBuiltinVariant(AbstractQoreFunctionVariant* variant);
935 DLLLOCAL
int parseInit(qore_ns_private* ns);
936 DLLLOCAL
void parseCommit();
937 DLLLOCAL
void parseRollback();
939 DLLLOCAL
const QoreTypeInfo* getUniqueReturnTypeInfo()
const {
941 return nn_uniqueReturnType;
943 return same_return_type && !vlist.empty() ? first()->getReturnTypeInfo() : 0;
946 DLLLOCAL
const QoreTypeInfo* parseGetUniqueReturnTypeInfo() {
947 parseCheckReturnType();
951 if (!same_return_type)
955 if (!nn_same_return_type)
958 return nn_count ? nn_uniqueReturnType : (!vlist.empty() ? first()->getReturnTypeInfo() :
nullptr);
962 return first()->getReturnTypeInfo();
980 DLLLOCAL
const AbstractQoreFunctionVariant* parseFindVariant(
const QoreProgramLocation* loc,
981 const type_vec_t& argTypeInfo,
const qore_class_private* class_ctx,
int& err)
const;
984 DLLLOCAL
bool pendingEmpty()
const {
985 return vlist.empty() || !check_parse;
989 DLLLOCAL
bool committedEmpty()
const {
990 return vlist.empty() || check_parse;
993 DLLLOCAL
bool existsVariant(
const type_vec_t& paramTypeInfo)
const;
997 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindVariant(
ExceptionSink* xsink,
const QoreListNode* args,
bool only_user,
const qore_class_private* class_ctx)
const;
1000 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindVariant(
ExceptionSink* xsink,
const type_vec_t& args,
const qore_class_private* class_ctx)
const;
1002 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindExactVariant(
ExceptionSink* xsink,
const type_vec_t& args,
const qore_class_private* class_ctx)
const;
1004 DLLLOCAL
void parseAssimilate(QoreFunction& other) {
1005 while (!other.vlist.empty()) {
1006 addPendingVariant(*(other.vlist.begin()));
1007 other.vlist.pop_front();
1011 DLLLOCAL
bool hasUser()
const {
1015 DLLLOCAL
bool hasBuiltin()
const {
1019 DLLLOCAL
bool hasPublic()
const {
1023 DLLLOCAL
bool hasUserPublic()
const {
1024 return has_pub && has_user;
1027 DLLLOCAL
bool injected()
const {
1031 DLLLOCAL
bool hasPrivate()
const {
1035 DLLLOCAL
bool allPrivate()
const {
1039 DLLLOCAL
const std::string& getNameStr()
const {
1043 DLLLOCAL
const char* getModuleName()
const {
1044 return from_module.empty() ? nullptr : from_module.c_str();
1057 int64 unique_flags = QCF_NO_FLAGS;
1061 int64 nn_unique_flags = QCF_NO_FLAGS;
1065 bool same_return_type : 1;
1066 bool nn_same_return_type : 1;
1067 bool parse_rt_done : 1;
1068 bool parse_init_done : 1;
1069 bool parse_init_in_progress : 1;
1071 bool has_builtin : 1;
1074 bool check_parse : 1;
1078 const QoreTypeInfo* nn_uniqueReturnType =
nullptr;
1080 std::string from_module;
1082 DLLLOCAL
int parseCheckReturnType() {
1086 parse_rt_done =
true;
1088 if (!same_return_type)
1093 for (vlist_t::iterator i = vlist.begin(), e = vlist.end(); i != e; ++i) {
1094 if (
reinterpret_cast<UserSignature*
>((*i)->getUserVariantBase()->getUserSignature())->resolve() && !err) {
1097 const QoreTypeInfo* rti = (*i)->getReturnTypeInfo();
1099 if (i == vlist.begin()) {
1103 if (!QoreTypeInfo::isOutputIdentical(rti, first()->getReturnTypeInfo())) {
1104 same_return_type =
false;
1113 DLLLOCAL
static int parseCompareResolvedSignature(
const VList& vlist,
const AbstractFunctionSignature* sig,
1114 const AbstractFunctionSignature*& vs);
1117 DLLLOCAL
int parseCheckDuplicateSignature(AbstractQoreFunctionVariant* variant);
1120 DLLLOCAL
void addVariant(AbstractQoreFunctionVariant* variant) {
1121 const QoreTypeInfo* rti = variant->getReturnTypeInfo();
1122 if (same_return_type && !vlist.empty() && !QoreTypeInfo::isOutputIdentical(rti, first()->getReturnTypeInfo()))
1123 same_return_type =
false;
1125 int64 vf = variant->getFunctionality();
1126 int64 vflags = variant->getFlags();
1128 bool rtn = (bool)(vflags & QCF_RUNTIME_NOOP);
1130 if (vlist.empty()) {
1131 unique_functionality = vf;
1132 unique_flags = vflags;
1134 unique_functionality &= vf;
1135 unique_flags &= vflags;
1140 nn_unique_functionality = vf;
1141 nn_unique_flags = vflags;
1142 nn_uniqueReturnType = rti;
1145 nn_unique_functionality &= vf;
1146 nn_unique_flags &= vflags;
1147 if (nn_uniqueReturnType && !QoreTypeInfo::isOutputIdentical(rti, nn_uniqueReturnType))
1148 nn_uniqueReturnType = 0;
1153 vlist.push_back(variant);
1156 DLLLOCAL
virtual ~QoreFunction() {
1161 const qore_class_private* class_ctx,
const QoreFunction* aqf,
const qore_class_private* last_class,
1162 bool internal_access,
int64 ppo,
const AbstractQoreFunctionVariant* variant)
const;
1165 class QoreFunctionIterator {
1167 DLLLOCAL QoreFunctionIterator(
const QoreFunction& f) : f(f) {
1171 DLLLOCAL
bool next() {
1172 if (i == f.vlist.end()) {
1173 i = f.vlist.begin();
1179 return i != f.vlist.end();
1182 DLLLOCAL
const AbstractQoreFunctionVariant* getVariant()
const {
1187 const QoreFunction& f;
1188 VList::const_iterator i;
1191 class MethodVariantBase;
1192 class MethodFunctionBase;
1193 #define METHFB(f) (reinterpret_cast<MethodFunctionBase*>(f))
1194 #define METHFB_const(f) (reinterpret_cast<const MethodFunctionBase*>(f))
1196 class MethodFunctionBase :
public QoreFunction {
1197 friend hashdecl AbstractMethod;
1205 mutable MethodFunctionBase* new_copy =
nullptr;
1210 has_private_internal_variants =
false;
1214 DLLLOCAL
int checkFinalVariant(
const MethodFunctionBase* m,
const MethodVariantBase* v)
const;
1216 DLLLOCAL
void replaceAbstractVariantIntern(MethodVariantBase* variant);
1219 DLLLOCAL MethodFunctionBase(
const char* nme,
const QoreClass* n_qc,
bool n_is_static) : QoreFunction(nme),
1220 qc(n_qc), is_static(n_is_static), has_final(false), access(Internal) {
1224 DLLLOCAL MethodFunctionBase(
const MethodFunctionBase& old,
const QoreClass* n_qc)
1225 : QoreFunction(old, 0, true),
1227 is_static(old.is_static),
1228 has_final(old.has_final),
1229 is_abstract(old.is_abstract),
1230 has_private_internal_variants(old.has_private_internal_variants),
1231 access(old.access) {
1235 old.new_copy =
this;
1238 ilist.reserve(old.ilist.size());
1239 ilist_t::const_iterator i = old.ilist.begin(), e = old.ilist.end();
1241 for (; i != e; ++i) {
1242 ilist.push_back(*i);
1246 DLLLOCAL
void resolveCopy() {
1247 ilist_t::iterator i = ilist.begin(), e = ilist.end();
1249 for (; i != e; ++i) {
1250 MethodFunctionBase* mfb = METHFB((*i).func);
1253 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());
1254 assert(mfb->new_copy);
1257 (*i).func = mfb->new_copy;
1261 DLLLOCAL
int parseInit();
1262 DLLLOCAL
void parseCommit();
1263 DLLLOCAL
void parseRollback();
1266 DLLLOCAL
int parseAddUserMethodVariant(MethodVariantBase* variant);
1269 DLLLOCAL
void addBuiltinMethodVariant(MethodVariantBase* variant);
1272 DLLLOCAL
void parseCommitMethod(
QoreString& csig,
const char* mod);
1274 DLLLOCAL
void parseCommitMethod();
1276 DLLLOCAL
void parseSignatures(
QoreString& csig,
const char* mod)
const;
1279 DLLLOCAL MethodVariantBase* parseHasVariantWithSignature(MethodVariantBase* v,
bool relaxed_match =
false)
const;
1281 DLLLOCAL
void replaceAbstractVariant(MethodVariantBase* variant);
1283 DLLLOCAL
void parseRollbackMethod();
1285 DLLLOCAL
bool isUniquelyPrivate()
const {
1286 return access > Public;
1289 DLLLOCAL
bool isAbstract()
const {
1293 DLLLOCAL ClassAccess getAccess()
const {
1297 DLLLOCAL
virtual const QoreClass* getClass()
const {
1301 DLLLOCAL
const char* getClassName()
const {
1305 DLLLOCAL std::string classPath()
const {
1307 return std::string();
1312 DLLLOCAL
bool isStatic()
const {
1316 DLLLOCAL
bool hasPrivateInternalVariants()
const {
1317 return has_private_internal_variants;
1320 DLLLOCAL
int checkFinal()
const;
1323 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const = 0;
1326 class UserParamListLocalVarHelper {
1328 UserVariantBase* uvb;
1331 DLLLOCAL UserParamListLocalVarHelper(UserVariantBase* n_uvb,
const QoreTypeInfo* classTypeInfo = 0) : uvb(n_uvb) {
1332 uvb->parseInitPushLocalVars(classTypeInfo);
1335 DLLLOCAL ~UserParamListLocalVarHelper() {
1336 uvb->parseInitPopLocalVars();
1340 class UserClosureVariant :
public UserFunctionVariant {
1343 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) {
1346 DLLLOCAL
virtual int parseInit(QoreFunction* f);
1349 return eval(
"<anonymous closure>", &ceh,
self, xsink);
1353 #define UCLOV(f) (reinterpret_cast<UserClosureVariant*>(f))
1354 #define UCLOV_const(f) (reinterpret_cast<const UserClosureVariant*>(f))
1356 class UserClosureFunction :
public QoreFunction {
1359 const QoreTypeInfo* classTypeInfo;
1362 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) {
1363 addPendingVariant(
new UserClosureVariant(b, n_sig_first_line, n_sig_last_line, params, rv, synced, n_flags));
1368 DLLLOCAL
void setClassType(
const QoreTypeInfo* cti) {
1369 classTypeInfo = cti;
1372 DLLLOCAL
const QoreTypeInfo* getClassType()
const {
1373 return classTypeInfo;
1376 DLLLOCAL LVarSet* getVList() {
1381 DLLLOCAL
bool needsScan()
const {
1382 return varlist.needsScan();
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:159
#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:48
defines a Qore-language class
Definition: QoreClass.h:249
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:127
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:409
virtual DLLLOCAL const QoreProgramLocation & getLocation() const =0
returns the source location of the element
virtual DLLLOCAL const AbstractStatement * getStatement() const =0
returns the statement for the call for internal Qore code
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 qore_call_t getCallType() const =0
returns the call type
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
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:275