32 #ifndef _QORE_QORECLASSINTERN_H
34 #define _QORE_QORECLASSINTERN_H
36 #include "qore/safe_dslist"
37 #include "qore/intern/ConstantList.h"
38 #include "qore/intern/QoreLValue.h"
39 #include "qore/intern/qore_var_rwlock_priv.h"
40 #include "qore/intern/VRMutex.h"
41 #include "qore/vector_map"
42 #include "qore/vector_set"
54 #define OTF_USER CT_USER
55 #define OTF_BUILTIN CT_BUILTIN
58 #ifdef HAVE_QORE_HASH_MAP
59 #include <qore/hash_map_include.h>
60 #include "qore/intern/xxhash.h"
62 typedef HASH_MAP<std::string, QoreMethod*> hm_method_t;
64 typedef std::map<std::string, QoreMethod*> hm_method_t;
68 class qore_class_private;
73 typedef std::map<const char*, MethodVariantBase*, ltstr> vmap_t;
75 hashdecl AbstractMethod {
81 bool check_parse =
false;
83 DLLLOCAL AbstractMethod() {
86 DLLLOCAL AbstractMethod(
const AbstractMethod& old);
88 DLLLOCAL ~AbstractMethod();
91 DLLLOCAL
void parseMergeBase(AbstractMethod& m,
bool committed =
false);
94 DLLLOCAL
void parseMergeBase(AbstractMethod& m, MethodFunctionBase* f,
bool committed =
false);
96 DLLLOCAL
void parseAdd(MethodVariantBase* v);
98 DLLLOCAL
void parseOverride(MethodVariantBase* v);
100 DLLLOCAL
void parseInit(
const char* cname,
const char* mname);
103 DLLLOCAL
int parseCommit();
106 DLLLOCAL
void parseRollback() {
109 DLLLOCAL
static void checkAbstract(
const char* cname,
const char* mname, vmap_t& vlist,
QoreStringNode*& desc);
111 DLLLOCAL
void add(MethodVariantBase* v);
112 DLLLOCAL
void override(MethodVariantBase* v);
114 DLLLOCAL
bool empty()
const {
115 return vlist.empty();
120 #ifdef HAVE_QORE_HASH_MAP
121 typedef HASH_MAP<std::string, AbstractMethod*> amap_t;
123 typedef std::map<std::string, AbstractMethod*> amap_t;
126 hashdecl AbstractMethodMap : amap_t {
127 DLLLOCAL AbstractMethodMap(
const AbstractMethodMap& old) {
128 for (
auto& i : old) {
129 assert(!i.second->vlist.empty());
130 insert(amap_t::value_type(i.first,
new AbstractMethod(*(i.second))));
134 DLLLOCAL AbstractMethodMap() {
137 DLLLOCAL ~AbstractMethodMap() {
138 for (
auto& i : *
this) {
143 DLLLOCAL AbstractMethod* findMethod(
const std::string& name) {
144 amap_t::iterator i = find(name);
145 return i == end() ? nullptr : i->second;
149 DLLLOCAL
void parseAddAbstractVariant(
const char* name, MethodVariantBase* f);
151 DLLLOCAL
void parseOverrideAbstractVariant(
const char* name, MethodVariantBase* f);
154 DLLLOCAL
void addAbstractVariant(
const char* name, MethodVariantBase* f);
157 DLLLOCAL
void overrideAbstractVariant(
const char* name, MethodVariantBase* f);
159 DLLLOCAL
void parseCommit() {
160 for (amap_t::iterator i = begin(), e = end(); i != e;) {
161 if (i->second->parseCommit()) {
171 DLLLOCAL
void parseRollback() {
172 for (
auto& i : *
this)
173 i.second->parseRollback();
176 DLLLOCAL
void parseInit(qore_class_private& qc, BCList* scl);
181 DLLLOCAL
void parseCheckAbstractNew(
const QoreProgramLocation* loc,
const char* name)
const;
184 DLLLOCAL
int runtimeCheckInstantiateClass(
const char* name,
ExceptionSink* xsink)
const;
189 static inline const char* privpub(ClassAccess access) {
190 return access == Public
194 : (access == Internal ?
"private:internal" :
"inaccessible"));
204 class MethodVariantBase :
public AbstractQoreFunctionVariant {
214 DLLLOCAL MethodVariantBase(ClassAccess n_access,
bool n_final,
int64 n_flags,
bool n_is_user =
false,
bool n_is_abstract =
false) :
215 AbstractQoreFunctionVariant(n_flags | (n_is_abstract ? QCF_USES_EXTRA_ARGS : 0), n_is_user), access(n_access), final(n_final), abstract(n_is_abstract) {
218 DLLLOCAL
bool isAbstract()
const {
222 DLLLOCAL
bool isPrivate()
const {
223 return access > Public;
226 DLLLOCAL ClassAccess getAccess()
const {
230 DLLLOCAL
bool isFinal()
const {
234 DLLLOCAL
void clearAbstract() {
243 DLLLOCAL
void setNormalUserMethod(
QoreMethod* n_qm, LocalVar* selfid) {
245 getUserVariantBase()->setSelfId(selfid);
253 DLLLOCAL
const QoreClass* getClass()
const {
257 DLLLOCAL
const char* getAbstractSignature();
259 DLLLOCAL
const qore_class_private* getClassPriv()
const;
261 DLLLOCAL MethodVariantBase* ref() {
266 DLLLOCAL
void deref() {
273 #define METHVB(f) (reinterpret_cast<MethodVariantBase*>(f))
274 #define METHVB_const(f) (reinterpret_cast<const MethodVariantBase*>(f))
276 class MethodVariant :
public MethodVariantBase {
278 DLLLOCAL MethodVariant(ClassAccess n_access,
bool n_final,
int64 n_flags,
bool n_is_user =
false,
bool is_abstract =
false) : MethodVariantBase(n_access, n_final, n_flags, n_is_user, is_abstract) {
287 #define METHV(f) (reinterpret_cast<MethodVariant*>(f))
288 #define METHV_const(f) (reinterpret_cast<const MethodVariant*>(f))
290 class ConstructorMethodVariant :
public MethodVariantBase {
293 DLLLOCAL
int constructorPrelude(
const QoreClass &thisclass, CodeEvaluationHelper& ceh,
QoreObject*
self, BCList* bcl, BCEAList* bceal,
ExceptionSink* xsink)
const;
296 DLLLOCAL ConstructorMethodVariant(ClassAccess n_access,
int64 n_flags,
bool n_is_user =
false) : MethodVariantBase(n_access, false, n_flags, n_is_user) {
298 DLLLOCAL
virtual const BCAList* getBaseClassArgumentList()
const = 0;
299 DLLLOCAL
virtual void evalConstructor(
const QoreClass &thisclass,
QoreObject*
self, CodeEvaluationHelper& ceh, BCList* bcl, BCEAList* bceal,
ExceptionSink* xsink)
const = 0;
302 #define CONMV(f) (reinterpret_cast<ConstructorMethodVariant*>(f))
303 #define CONMV_const(f) (reinterpret_cast<const ConstructorMethodVariant*>(f))
305 class DestructorMethodVariant :
public MethodVariantBase {
308 DLLLOCAL DestructorMethodVariant(
bool n_is_user =
false) : MethodVariantBase(Public, false, QCF_NO_FLAGS, n_is_user) {
314 #define DESMV(f) (reinterpret_cast<DestructorMethodVariant*>(f))
315 #define DESMV_const(f) (reinterpret_cast<const DestructorMethodVariant*>(f))
317 class CopyMethodVariant :
public MethodVariantBase {
320 DLLLOCAL CopyMethodVariant(ClassAccess n_access,
bool n_is_user =
false) : MethodVariantBase(n_access, false, QCF_NO_FLAGS, n_is_user) {
326 #define COPYMV(f) (reinterpret_cast<CopyMethodVariant*>(f))
327 #define COPYMV_const(f) (reinterpret_cast<const CopyMethodVariant*>(f))
329 class UserMethodVariant :
public MethodVariant,
public UserVariantBase {
334 DLLLOCAL UserMethodVariant(ClassAccess n_access,
bool n_final, StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params, RetTypeInfo* rv,
bool synced,
int64 n_flags,
bool is_abstract) : MethodVariant(n_access, n_final, n_flags, true, is_abstract), UserVariantBase(b, n_sig_first_line, n_sig_last_line, params, rv, false), synchronized(synced) {
337 DLLLOCAL ~UserMethodVariant() {
341 COMMON_USER_VARIANT_FUNCTIONS
343 DLLLOCAL
virtual void parseInit(QoreFunction* f) {
344 MethodFunctionBase* mf =
static_cast<MethodFunctionBase*
>(f);
348 ParseCodeInfoHelper rtih(mf->getName(), signature.getReturnTypeInfo());
351 if (!mf->isStatic()) {
353 statements->parseInitMethod(mf->MethodFunctionBase::getClass()->getTypeInfo(),
this);
356 statements->parseInit(
this);
360 f->parseCheckDuplicateSignatureCommitted(&signature);
366 #define UMV(f) (reinterpret_cast<UserMethodVariant*>(f))
367 #define UMV_const(f) (reinterpret_cast<const UserMethodVariant*>(f))
369 class UserConstructorVariant :
public ConstructorMethodVariant,
public UserVariantBase {
374 DLLLOCAL
virtual ~UserConstructorVariant();
377 DLLLOCAL UserConstructorVariant(ClassAccess n_access, StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params, BCAList* n_bcal,
int64 n_flags = QCF_NO_FLAGS) : ConstructorMethodVariant(n_access, n_flags, true), UserVariantBase(b, n_sig_first_line, n_sig_last_line, params, nullptr, false), bcal(n_bcal) {
381 COMMON_USER_VARIANT_FUNCTIONS
383 DLLLOCAL
virtual const BCAList* getBaseClassArgumentList()
const {
387 DLLLOCAL
virtual void evalConstructor(
const QoreClass& thisclass,
QoreObject*
self, CodeEvaluationHelper& ceh, BCList* bcl, BCEAList* bceal,
ExceptionSink* xsink)
const;
389 DLLLOCAL
virtual void parseInit(QoreFunction* f);
392 #define UCONV(f) (reinterpret_cast<UserConstructorVariant*>(f))
393 #define UCONV_const(f) (reinterpret_cast<const UserConstructorVariant*>(f))
395 class UserDestructorVariant :
public DestructorMethodVariant,
public UserVariantBase {
398 DLLLOCAL UserDestructorVariant(StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line) : DestructorMethodVariant(true), UserVariantBase(b, n_sig_first_line, n_sig_last_line,
QoreValue(), nullptr, false) {
402 COMMON_USER_VARIANT_FUNCTIONS
404 DLLLOCAL
virtual void parseInit(QoreFunction* f) {
405 MethodFunctionBase* mf =
static_cast<MethodFunctionBase*
>(f);
408 assert(!signature.getReturnTypeInfo() || signature.getReturnTypeInfo() == nothingTypeInfo);
411 ParseCodeInfoHelper rtih(
"destructor", nothingTypeInfo);
414 statements->parseInitMethod(mf->MethodFunctionBase::getClass()->getTypeInfo(),
this);
421 assert(!signature.numParams());
422 assert(!signature.getReturnTypeInfo() || signature.getReturnTypeInfo() == nothingTypeInfo);
423 eval(
"destructor", 0,
self, xsink, getClassPriv()).discard(xsink);
427 #define UDESV(f) (reinterpret_cast<UserDestructorVariant*>(f))
428 #define UDESV_const(f) (reinterpret_cast<const UserDestructorVariant*>(f))
430 class UserCopyVariant :
public CopyMethodVariant,
public UserVariantBase {
433 DLLLOCAL UserCopyVariant(ClassAccess n_access, StatementBlock* b,
int n_sig_first_line,
int n_sig_last_line,
QoreValue params, RetTypeInfo* rv,
bool synced) : CopyMethodVariant(n_access, true), UserVariantBase(b, n_sig_first_line, n_sig_last_line, params, rv, synced) {
437 COMMON_USER_VARIANT_FUNCTIONS
439 DLLLOCAL
virtual void parseInit(QoreFunction* f);
444 #define UCOPYV(f) (reinterpret_cast<UserCopyVariant*>(f))
446 class BuiltinMethodVariant :
public MethodVariant,
public BuiltinFunctionVariantBase {
448 DLLLOCAL BuiltinMethodVariant(ClassAccess n_access,
bool n_final,
int64 n_flags,
int64 n_functionality,
const QoreTypeInfo* n_returnTypeInfo,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : MethodVariant(n_access, n_final, n_flags), BuiltinFunctionVariantBase(n_functionality, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names) {}
451 COMMON_BUILTIN_VARIANT_FUNCTIONS
454 class BuiltinAbstractMethodVariant :
public BuiltinMethodVariant {
456 DLLLOCAL BuiltinAbstractMethodVariant(ClassAccess n_access,
int64 n_flags,
const QoreTypeInfo* n_returnTypeInfo,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : BuiltinMethodVariant(n_access, false, n_flags,
QDOM_DEFAULT, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names) {
466 class BuiltinNormalMethodVariantBase :
public BuiltinMethodVariant {
468 DLLLOCAL BuiltinNormalMethodVariantBase(ClassAccess n_access,
bool n_final,
int64 n_flags,
int64 n_functionality,
const QoreTypeInfo* n_returnTypeInfo,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : BuiltinMethodVariant(n_access, n_final, n_flags, n_functionality, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names) {}
477 class BuiltinNormalMethodValueVariant :
public BuiltinNormalMethodVariantBase {
482 DLLLOCAL BuiltinNormalMethodValueVariant(
q_method_n_t m, ClassAccess n_access,
bool n_final =
false,
int64 n_flags = QCF_USES_EXTRA_ARGS,
int64 n_functionality =
QDOM_DEFAULT,
const QoreTypeInfo* n_returnTypeInfo = 0,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : BuiltinNormalMethodVariantBase(n_access, n_final, n_flags, n_functionality, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names), method(m) {
485 return method(
self, private_data, args, rtflags, xsink);
489 class BuiltinExternalNormalMethodValueVariant :
public BuiltinNormalMethodVariantBase {
495 DLLLOCAL BuiltinExternalNormalMethodValueVariant(
const void* n_ptr,
q_external_method_t m, ClassAccess n_access,
bool n_final =
false,
int64 n_flags = QCF_USES_EXTRA_ARGS,
int64 n_functionality =
QDOM_DEFAULT,
const QoreTypeInfo* n_returnTypeInfo = 0,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : BuiltinNormalMethodVariantBase(n_access, n_final, n_flags, n_functionality, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names), method(m), ptr(n_ptr) {
498 return method(*qmethod, ptr,
self, private_data, args, rtflags, xsink);
502 class BuiltinStaticMethodValueVariant :
public BuiltinMethodVariant {
507 DLLLOCAL BuiltinStaticMethodValueVariant(
q_func_n_t m, ClassAccess n_access,
bool n_final =
false,
int64 n_flags = QCF_USES_EXTRA_ARGS,
int64 n_functionality =
QDOM_DEFAULT,
const QoreTypeInfo* n_returnTypeInfo = 0,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : BuiltinMethodVariant(n_access, n_final, n_flags, n_functionality, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names), static_method(m) {
511 CodeContextHelper cch(xsink, CT_BUILTIN, qmethod->
getName(), 0, getClassPriv());
513 return static_method(ceh.getArgs(), ceh.getRuntimeFlags(), xsink);
517 class BuiltinExternalStaticMethodValueVariant :
public BuiltinMethodVariant {
523 DLLLOCAL BuiltinExternalStaticMethodValueVariant(
const void* n_ptr,
q_external_static_method_t m, ClassAccess n_access,
bool n_final =
false,
int64 n_flags = QCF_USES_EXTRA_ARGS,
int64 n_functionality =
QDOM_DEFAULT,
const QoreTypeInfo* n_returnTypeInfo = 0,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : BuiltinMethodVariant(n_access, n_final, n_flags, n_functionality, n_returnTypeInfo, n_typeList, n_defaultArgList, n_names), static_method(m), ptr(n_ptr) {
527 CodeContextHelper cch(xsink, CT_BUILTIN, qmethod->
getName(), 0, getClassPriv());
529 return static_method(*qmethod, ptr, ceh.getArgs(), ceh.getRuntimeFlags(), xsink);
533 class BuiltinConstructorVariantBase :
public ConstructorMethodVariant,
public BuiltinFunctionVariantBase {
536 DLLLOCAL BuiltinConstructorVariantBase(ClassAccess n_access,
int64 n_flags = QCF_USES_EXTRA_ARGS,
int64 n_functionality =
QDOM_DEFAULT,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : ConstructorMethodVariant(n_access, n_flags), BuiltinFunctionVariantBase(n_functionality, 0, n_typeList, n_defaultArgList, n_names) {
540 COMMON_BUILTIN_VARIANT_FUNCTIONS
542 DLLLOCAL
virtual const BCAList* getBaseClassArgumentList()
const {
547 class BuiltinConstructorValueVariant :
public BuiltinConstructorVariantBase {
552 DLLLOCAL BuiltinConstructorValueVariant(
q_constructor_n_t m, ClassAccess n_access,
int64 n_flags = QCF_USES_EXTRA_ARGS,
int64 n_functionality =
QDOM_DEFAULT,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : BuiltinConstructorVariantBase(n_access, n_flags, n_functionality, n_typeList, n_defaultArgList, n_names), constructor(m) {
555 DLLLOCAL
virtual void evalConstructor(
const QoreClass& thisclass,
QoreObject*
self, CodeEvaluationHelper& ceh, BCList* bcl, BCEAList* bceal,
ExceptionSink* xsink)
const;
558 class BuiltinExternalConstructorValueVariant :
public BuiltinConstructorVariantBase {
564 DLLLOCAL BuiltinExternalConstructorValueVariant(
const void* n_ptr,
q_external_constructor_t m, ClassAccess n_access,
int64 n_flags = QCF_USES_EXTRA_ARGS,
int64 n_functionality =
QDOM_DEFAULT,
const type_vec_t &n_typeList =
type_vec_t(),
const arg_vec_t &n_defaultArgList =
arg_vec_t(),
const name_vec_t& n_names =
name_vec_t()) : BuiltinConstructorVariantBase(n_access, n_flags, n_functionality, n_typeList, n_defaultArgList, n_names), constructor(m), ptr(n_ptr) {
567 DLLLOCAL
virtual void evalConstructor(
const QoreClass& thisclass,
QoreObject*
self, CodeEvaluationHelper& ceh, BCList* bcl, BCEAList* bceal,
ExceptionSink* xsink)
const;
570 class BuiltinDestructorVariantBase :
public DestructorMethodVariant,
public BuiltinFunctionVariantBase {
573 COMMON_BUILTIN_VARIANT_FUNCTIONS
576 class BuiltinDestructorVariant :
public BuiltinDestructorVariantBase {
581 DLLLOCAL BuiltinDestructorVariant(
q_destructor_t n_destructor) : destructor(n_destructor) {
587 class BuiltinExternalDestructorVariant :
public BuiltinDestructorVariantBase {
593 DLLLOCAL BuiltinExternalDestructorVariant(
const void* ptr,
q_external_destructor_t destructor) : destructor(destructor), ptr(ptr) {
599 class BuiltinCopyVariantBase :
public CopyMethodVariant,
public BuiltinFunctionVariantBase {
602 DLLLOCAL BuiltinCopyVariantBase(
const QoreClass* c) : CopyMethodVariant(Public), BuiltinFunctionVariantBase(
QDOM_DEFAULT, c->getTypeInfo()) {
606 COMMON_BUILTIN_VARIANT_FUNCTIONS
612 class BuiltinCopyVariant :
public BuiltinCopyVariantBase {
617 DLLLOCAL BuiltinCopyVariant(
QoreClass* c,
q_copy_t m) : BuiltinCopyVariantBase(c), copy(m) {
620 copy(
self, old, private_data, xsink);
624 class BuiltinExternalCopyVariant :
public BuiltinCopyVariantBase {
630 DLLLOCAL BuiltinExternalCopyVariant(
const void* n_ptr,
QoreClass* c,
q_external_copy_t m) : BuiltinCopyVariantBase(c), copy(m), ptr(n_ptr) {
634 copy(thisclass, ptr,
self, old, private_data, xsink);
639 class NormalMethodFunction :
public MethodFunctionBase {
641 DLLLOCAL NormalMethodFunction(
const char* nme,
const QoreClass* n_qc) : MethodFunctionBase(nme, n_qc, false) {
644 DLLLOCAL NormalMethodFunction(
const NormalMethodFunction &old,
const QoreClass* n_qc) : MethodFunctionBase(old, n_qc) {
647 DLLLOCAL
virtual ~NormalMethodFunction() {
658 const QoreValue n,
const QoreListNode* args,
const qore_class_private* cctx = runtime_get_class())
const;
661 #define NMETHF(f) (reinterpret_cast<NormalMethodFunction*>(f))
664 class StaticMethodFunction :
public MethodFunctionBase {
666 DLLLOCAL StaticMethodFunction(
const char* nme,
const QoreClass* n_qc) : MethodFunctionBase(nme, n_qc, true) {
668 DLLLOCAL StaticMethodFunction(
const StaticMethodFunction &old,
const QoreClass* n_qc) : MethodFunctionBase(old, n_qc) {
670 DLLLOCAL
virtual ~StaticMethodFunction() {
674 DLLLOCAL
QoreValue evalMethod(
ExceptionSink* xsink,
const AbstractQoreFunctionVariant* variant,
const QoreListNode* args,
const qore_class_private* cctx =
nullptr)
const;
677 DLLLOCAL
QoreValue evalMethodTmpArgs(
ExceptionSink* xsink,
const AbstractQoreFunctionVariant* variant,
QoreListNode* args,
const qore_class_private* cctx =
nullptr)
const;
680 #define SMETHF(f) (reinterpret_cast<StaticMethodFunction*>(f))
683 class ConstructorMethodFunction :
public MethodFunctionBase {
685 DLLLOCAL ConstructorMethodFunction(
const QoreClass* n_qc) : MethodFunctionBase(
"constructor", n_qc, false) {
687 DLLLOCAL ConstructorMethodFunction(
const ConstructorMethodFunction &old,
const QoreClass* n_qc) : MethodFunctionBase(old, n_qc) {
693 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
694 return new ConstructorMethodFunction(*
this, n_qc);
698 #define CONMF(f) (reinterpret_cast<ConstructorMethodFunction*>(f))
701 class DestructorMethodFunction :
public MethodFunctionBase {
703 DLLLOCAL DestructorMethodFunction(
const QoreClass* n_qc) : MethodFunctionBase(
"destructor", n_qc, false) {
705 DLLLOCAL DestructorMethodFunction(
const DestructorMethodFunction &old,
const QoreClass* n_qc) : MethodFunctionBase(old, n_qc) {
709 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
710 return new DestructorMethodFunction(*
this, n_qc);
714 #define DESMF(f) (reinterpret_cast<DestructorMethodFunction*>(f))
717 class CopyMethodFunction :
public MethodFunctionBase {
719 DLLLOCAL CopyMethodFunction(
const QoreClass* n_qc) : MethodFunctionBase(
"copy", n_qc, false) {
721 DLLLOCAL CopyMethodFunction(
const CopyMethodFunction &old,
const QoreClass* n_qc) : MethodFunctionBase(old, n_qc) {
725 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
726 return new CopyMethodFunction(*
this, n_qc);
730 #define COPYMF(f) (reinterpret_cast<CopyMethodFunction*>(f))
732 class BuiltinSystemConstructorBase :
public MethodFunctionBase {
734 DLLLOCAL BuiltinSystemConstructorBase(
const QoreClass* n_qc) : MethodFunctionBase(
"constructor", n_qc, false) {
736 DLLLOCAL BuiltinSystemConstructorBase(
const BuiltinSystemConstructorBase &old,
const QoreClass* n_qc) : MethodFunctionBase(old, n_qc) {
738 DLLLOCAL
virtual void eval(
const QoreClass &thisclass,
QoreObject*
self,
int code, va_list args)
const = 0;
740 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const = 0;
743 #define BSYSCONB(f) (reinterpret_cast<BuiltinSystemConstructorBase* >(f))
747 class BuiltinSystemConstructor :
public BuiltinSystemConstructorBase {
755 DLLLOCAL BuiltinSystemConstructor(
const BuiltinSystemConstructor &old,
const QoreClass* n_qc) : BuiltinSystemConstructorBase(old, n_qc), system_constructor(old.system_constructor) {
758 DLLLOCAL
virtual void eval(
const QoreClass &thisclass,
QoreObject*
self,
int code, va_list args)
const {
759 system_constructor(
self, code, args);
762 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
763 return new BuiltinSystemConstructor(*
this, n_qc);
767 class BuiltinNormalMethod :
public NormalMethodFunction {
769 DLLLOCAL BuiltinNormalMethod(
const QoreClass* n_qc,
const char* mname) : NormalMethodFunction(mname, n_qc) {
772 DLLLOCAL BuiltinNormalMethod(
const BuiltinNormalMethod &old,
const QoreClass* n_qc) : NormalMethodFunction(old, n_qc) {
775 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
776 return new BuiltinNormalMethod(*
this, n_qc);
780 class BuiltinStaticMethod :
public StaticMethodFunction {
782 DLLLOCAL BuiltinStaticMethod(
const QoreClass* n_qc,
const char* mname) : StaticMethodFunction(mname, n_qc) {
785 DLLLOCAL BuiltinStaticMethod(
const BuiltinStaticMethod &old,
const QoreClass* n_qc) : StaticMethodFunction(old, n_qc) {
788 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
789 return new BuiltinStaticMethod(*
this, n_qc);
794 class BuiltinDeleteBlocker :
public BuiltinNormalMethod {
799 DLLLOCAL BuiltinDeleteBlocker(
q_delete_blocker_t m) : BuiltinNormalMethod(0,
"<delete_blocker>"), delete_blocker(m) {
802 DLLLOCAL BuiltinDeleteBlocker(
const BuiltinDeleteBlocker& old,
const QoreClass* n_qc) : BuiltinNormalMethod(old, n_qc), delete_blocker(old.delete_blocker) {
806 return delete_blocker(
self, private_data);
809 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
810 return new BuiltinDeleteBlocker(*
this, n_qc);
814 #define BDELB(f) (reinterpret_cast<BuiltinDeleteBlocker*>(f))
816 class NormalUserMethod :
public NormalMethodFunction {
818 DLLLOCAL NormalUserMethod(
const QoreClass* n_qc,
const char* mname) : NormalMethodFunction(mname, n_qc) {
820 DLLLOCAL NormalUserMethod(
const NormalUserMethod &old,
const QoreClass* n_qc) : NormalMethodFunction(old, n_qc) {
822 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
823 return new NormalUserMethod(*
this, n_qc);
827 class StaticUserMethod :
public StaticMethodFunction {
829 DLLLOCAL StaticUserMethod(
const QoreClass* n_qc,
const char* mname) : StaticMethodFunction(mname, n_qc) {
831 DLLLOCAL StaticUserMethod(
const StaticUserMethod &old,
const QoreClass* n_qc) : StaticMethodFunction(old, n_qc) {
833 DLLLOCAL
virtual MethodFunctionBase* copy(
const QoreClass* n_qc)
const {
834 return new StaticUserMethod(*
this, n_qc);
838 class QoreMemberInfoBase {
840 const QoreTypeInfo* typeInfo;
842 DLLLOCAL QoreMemberInfoBase(
const QoreMemberInfoBase& old) : typeInfo(old.typeInfo), exp(old.exp.refSelf()),
843 loc(old.loc), parseTypeInfo(old.parseTypeInfo ? new QoreParseTypeInfo(*old.parseTypeInfo) : nullptr) {
851 const QoreProgramLocation* loc;
852 QoreParseTypeInfo* parseTypeInfo;
854 DLLLOCAL QoreMemberInfoBase(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeinfo =
nullptr,
856 : typeInfo(n_typeinfo), exp(e), loc(loc), parseTypeInfo(n_parseTypeInfo) {
859 DLLLOCAL ~QoreMemberInfoBase() {
863 DLLLOCAL
void del() {
866 delete parseTypeInfo;
867 parseTypeInfo =
nullptr;
871 DLLLOCAL
const QoreTypeInfo* getTypeInfo()
const {
875 DLLLOCAL
const QoreTypeInfo* parseGetTypeInfo()
const {
877 return QoreTypeInfo::isReference(typeInfo) ? anyTypeInfo : typeInfo;
881 DLLLOCAL
bool parseHasTypeInfo()
const {
882 return (typeInfo || parseTypeInfo);
886 class QoreMemberInfoBaseAccess :
public QoreMemberInfoBase {
890 DLLLOCAL QoreMemberInfoBaseAccess(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeinfo =
nullptr,
891 QoreParseTypeInfo* n_parseTypeInfo =
nullptr,
QoreValue e =
QoreValue(), ClassAccess n_access = Public) :
892 QoreMemberInfoBase(loc, n_typeinfo, n_parseTypeInfo, e), access(n_access) {
895 DLLLOCAL ClassAccess getAccess()
const {
900 DLLLOCAL QoreMemberInfoBaseAccess(
const QoreMemberInfoBaseAccess& old, ClassAccess n_access)
901 : QoreMemberInfoBase(old), access(old.access >= n_access ? old.access : n_access) {
908 typedef std::vector<const qore_class_private*> cls_vec_t;
911 typedef std::map<const qore_class_private*, const qore_class_private*> cls_context_map_t;
914 typedef std::deque<const QoreMemberInfo*> member_info_list_t;
919 class QoreMemberInfo :
public QoreMemberInfoBaseAccess {
920 friend class qore_class_private;
922 DLLLOCAL QoreMemberInfo(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeInfo =
nullptr,
923 QoreParseTypeInfo* n_parseTypeInfo =
nullptr,
QoreValue e =
QoreValue(), ClassAccess n_access = Public,
924 const qore_class_private* qc =
nullptr)
925 : QoreMemberInfoBaseAccess(loc, n_typeInfo, n_parseTypeInfo, e, n_access), is_local(true) {
927 cls_vec.push_back(qc);
932 DLLLOCAL QoreMemberInfo(
const QoreMemberInfo& old,
const qore_class_private* cls);
934 DLLLOCAL ~QoreMemberInfo() {
935 delete cls_context_map;
936 delete member_info_list;
939 DLLLOCAL
void setDeclaringClass(
const qore_class_private* qc) {
940 assert(cls_vec.empty());
941 cls_vec.push_back(qc);
946 DLLLOCAL
bool isLocalInternal()
const {
947 return is_local && access == Internal;
951 DLLLOCAL
bool local()
const {
956 DLLLOCAL
const qore_class_private* getClass()
const {
961 DLLLOCAL
const qore_class_private* getClassContext(
const qore_class_private* class_ctx)
const {
962 if (local() && class_ctx == getClass()) {
963 if (access == Internal) {
968 if (cls_context_map) {
969 cls_context_map_t::const_iterator i = cls_context_map->find(class_ctx);
970 if (i != cls_context_map->end()) {
978 DLLLOCAL
size_t getContextSize()
const {
979 return cls_context_map ? cls_context_map->size() : 0;
984 DLLLOCAL
void addContextAccess(
const QoreMemberInfo& mi);
988 DLLLOCAL
void addContextAccess(
const QoreMemberInfo& mi,
const qore_class_private* qc);
991 DLLLOCAL
size_t numParentMembers()
const {
992 return member_info_list ? member_info_list->size() : 0;
996 DLLLOCAL member_info_list_t::const_iterator initializationBegin()
const {
997 assert(member_info_list);
998 return member_info_list->begin();
1002 DLLLOCAL member_info_list_t::const_iterator initializationEnd()
const {
1003 assert(member_info_list);
1004 return member_info_list->end();
1008 DLLLOCAL
void parseInit(
const char* name, LocalVar& selfid);
1011 DLLLOCAL
void setTransient() {
1012 assert(!is_transient);
1013 is_transient =
true;
1017 DLLLOCAL
bool getTransient()
const {
1018 return is_transient;
1025 cls_context_map_t* cls_context_map =
nullptr;
1027 member_info_list_t* member_info_list =
nullptr;
1032 is_transient =
false;
1044 DLLLOCAL QoreMemberInfo(
const QoreMemberInfo& old,
const qore_class_private* cls, ClassAccess cls_access);
1047 class QoreVarInfo :
public QoreMemberInfoBaseAccess {
1049 mutable QoreVarRWLock rwl;
1050 QoreLValueGeneric val;
1053 bool eval_init =
false;
1055 DLLLOCAL QoreVarInfo(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeinfo =
nullptr,
1056 QoreParseTypeInfo* n_parseTypeInfo =
nullptr,
QoreValue e =
QoreValue(), ClassAccess n_access = Public) :
1057 QoreMemberInfoBaseAccess(loc, n_typeinfo, n_parseTypeInfo, e, n_access), finalized(false) {
1060 DLLLOCAL QoreVarInfo(
const QoreVarInfo& old, ClassAccess n_access = Public)
1061 : QoreMemberInfoBaseAccess(old, n_access), val(old.val), finalized(old.finalized) {
1064 DLLLOCAL ~QoreVarInfo() {
1065 assert(!val.hasValue());
1068 DLLLOCAL
int evalInit(
const char* name,
ExceptionSink* xsink);
1071 DLLLOCAL
void del() {
1072 assert(!val.hasValue());
1073 QoreMemberInfoBaseAccess::del();
1079 QoreAutoVarRWWriteLocker al(rwl);
1082 tmp = val.removeValue(
true);
1087 QoreMemberInfoBaseAccess::del();
1091 val.removeValue(
true).discard(xsink);
1096 val.set(getTypeInfo());
1097 return val.assignInitial(v);
1100 DLLLOCAL
void getLValue(LValueHelper& lvh) {
1101 lvh.setAndLock(rwl);
1102 if (checkFinalized(lvh.vl.xsink))
1104 lvh.setValue(val, getTypeInfo());
1107 DLLLOCAL
void init() {
1108 val.set(getTypeInfo());
1111 discard(val.assignInitial(QoreTypeInfo::getDefaultQoreValue(typeInfo)),
nullptr);
1117 if (!eval_init && evalInit(name, xsink)) {
1120 return getRuntimeReferencedValue();
1123 DLLLOCAL
QoreValue getRuntimeReferencedValue()
const {
1124 QoreAutoVarRWReadLocker al(rwl);
1125 return val.getReferencedValue();
1128 DLLLOCAL
int64 getAsBigInt()
const {
1129 QoreAutoVarRWReadLocker al(rwl);
1130 return val.getAsBigInt();
1133 DLLLOCAL
double getAsFloat()
const {
1134 QoreAutoVarRWReadLocker al(rwl);
1135 return val.getAsFloat();
1138 DLLLOCAL
bool getAsBool()
const {
1139 QoreAutoVarRWReadLocker al(rwl);
1140 return val.getAsBool();
1143 DLLLOCAL
void parseInit(
const char* name);
1148 xsink->
raiseException(
"DESTRUCTOR-ERROR",
"illegal class static variable assignment after second phase of variable destruction");
1155 template <
typename T>
1156 class QoreMemberMapBase {
1158 typedef std::pair<char*, std::unique_ptr<T>> member_list_element_t;
1159 typedef std::deque<member_list_element_t> member_list_t;
1160 typedef typename member_list_t::iterator iterator;
1161 typedef typename member_list_t::const_iterator const_iterator;
1162 member_list_t member_list;
1164 DLLLOCAL ~QoreMemberMapBase() {
1165 for (
auto& i : member_list) {
1170 member_list.clear();
1173 DLLLOCAL
bool inList(
const char* name)
const {
1174 return (
bool)find(name);
1177 DLLLOCAL T* find(
const char* name)
const {
1178 typename member_list_t::const_iterator i = std::find_if(member_list.begin(), member_list.end(), [name](
const member_list_element_t& e) ->
bool {return !strcmp(e.first, name); });
1179 return i == member_list.end() ? nullptr : i->second.get();
1182 DLLLOCAL
bool empty()
const {
1183 return member_list.empty();
1186 DLLLOCAL
void addNoCheck(
char* name, T* info) {
1189 assert(!inList(name));
1190 member_list.push_back(std::make_pair(name, std::unique_ptr<T>(info)));
1193 DLLLOCAL
void addNoCheck(std::pair<char*, T*> pair) {
1194 addNoCheck(pair.first, pair.second);
1197 DLLLOCAL
void moveAllTo(QoreMemberMapBase<T>& dest) {
1198 dest.member_list.insert(dest.member_list.end(), member_list.begin(), member_list.end());
1199 member_list.clear();
1202 DLLLOCAL
size_t size()
const {
1203 return member_list.size();
1207 class QoreMemberMap :
public QoreMemberMapBase<QoreMemberInfo> {
1209 using QoreMemberMapBase<QoreMemberInfo>::moveAllTo;
1210 DLLLOCAL
void moveAllTo(
QoreClass* qc, ClassAccess access);
1212 using QoreMemberMapBase<QoreMemberInfo>::addNoCheck;
1213 DLLLOCAL
void addNoCheck(
char* name, QoreMemberInfo* info) {
1214 assert(info->getClass());
1215 QoreMemberMapBase<QoreMemberInfo>::addNoCheck(name, info);
1218 DLLLOCAL
void addInheritedNoCheck(
char* name, QoreMemberInfo* info) {
1221 assert(!inList(name));
1222 member_list.insert(member_list.begin(), std::make_pair(name, std::unique_ptr<QoreMemberInfo>(info)));
1225 DLLLOCAL
void parseInit(LocalVar& selfid);
1231 class QoreVarMap :
public QoreMemberMapBase<QoreVarInfo> {
1234 for (member_list_t::reverse_iterator i = member_list.rbegin(), e = member_list.rend(); i != e; ++i) {
1235 i->second->clear(xsink);
1240 for (member_list_t::reverse_iterator i = member_list.rbegin(), e = member_list.rend(); i != e; ++i) {
1241 i->second->delVar(xsink);
1245 member_list.clear();
1248 DLLLOCAL
void del() {
1249 for (member_list_t::reverse_iterator i = member_list.rbegin(), e = member_list.rend(); i != e; ++i) {
1250 assert(!i->second->val.hasValue());
1258 member_list.clear();
1261 DLLLOCAL
void clearNoFree() {
1262 member_list.clear();
1265 DLLLOCAL
void moveAllTo(
QoreClass* qc, ClassAccess access);
1277 class BCANode :
public FunctionCallBase {
1280 const QoreProgramLocation* loc;
1287 DLLLOCAL BCANode(NamedScope* n, QoreParseListNode* n_args,
const QoreProgramLocation* loc) : FunctionCallBase(n_args), loc(loc), ns(n), name(nullptr) {
1288 assert(loc->start_line > 0);
1292 DLLLOCAL BCANode(
char* n, QoreParseListNode* n_args,
const QoreProgramLocation* loc) : FunctionCallBase(n_args), loc(loc), ns(nullptr), name(n) {
1293 assert(loc->start_line > 0);
1296 DLLLOCAL ~BCANode() {
1303 DLLLOCAL
void parseInit(BCList* bcl,
const char* classname);
1306 typedef std::vector<BCANode*> bcalist_t;
1312 class BCAList :
public bcalist_t {
1314 DLLLOCAL BCAList(BCANode* n) {
1318 DLLLOCAL ~BCAList() {
1319 for (bcalist_t::iterator i = begin(), e = end(); i != e; ++i)
1324 DLLLOCAL
int execBaseClassConstructorArgs(BCEAList* bceal,
ExceptionSink* xsink)
const;
1327 typedef std::pair<QoreClass*, bool> class_virt_pair_t;
1329 typedef std::vector<class_virt_pair_t> class_list_t;
1332 hashdecl member_init_entry_t {
1334 const QoreMemberInfo* info;
1335 const qore_class_private* member_class_ctx;
1337 DLLLOCAL member_init_entry_t(
const char* name,
const QoreMemberInfo* info,
const qore_class_private* member_class_ctx) :
1338 name(name), info(info), member_class_ctx(member_class_ctx) {
1343 typedef std::vector<member_init_entry_t> member_init_list_t;
1348 class BCSMList :
public class_list_t {
1350 DLLLOCAL BCSMList() {
1353 DLLLOCAL BCSMList(
const BCSMList &old);
1355 DLLLOCAL ~BCSMList();
1357 DLLLOCAL
void processMemberInitializationList(
const QoreMemberMap& members, member_init_list_t& member_init_list);
1360 DLLLOCAL
int addBaseClassesToSubclass(
QoreClass* thisclass,
QoreClass* sc,
bool is_virtual);
1362 DLLLOCAL
void alignBaseClassesInSubclass(
QoreClass* thisclass,
QoreClass* child,
bool is_virtual);
1374 DLLLOCAL
void resolveCopy();
1378 typedef vector_set_t<qore_class_private*> qcp_set_t;
1386 const QoreProgramLocation* loc;
1387 NamedScope* cname =
nullptr;
1388 char* cstr =
nullptr;
1391 bool is_virtual : 1;
1393 DLLLOCAL BCNode(
const QoreProgramLocation* loc, NamedScope* c, ClassAccess a) : loc(loc), cname(c), access(a),
1398 DLLLOCAL BCNode(
const QoreProgramLocation* loc,
char* str, ClassAccess a) : loc(loc), cstr(str), access(a),
1403 DLLLOCAL BCNode(
const QoreProgramLocation* loc,
QoreClass* qc,
bool n_virtual =
false) : loc(loc), sclass(qc),
1404 access(Public), is_virtual(n_virtual) {
1408 DLLLOCAL BCNode(
const BCNode &old) : loc(old.loc), sclass(old.sclass), access(old.access),
1409 is_virtual(old.is_virtual) {
1415 DLLLOCAL ~BCNode() {
1421 DLLLOCAL
int tryResolveClass(
QoreClass* cls,
bool raise_error);
1423 DLLLOCAL ClassAccess getAccess()
const {
return access; }
1426 DLLLOCAL
int initializeHierarchy(
QoreClass* cls, qcp_set_t& qcp_set);
1428 DLLLOCAL
void initializeMembers(
QoreClass* cls);
1431 DLLLOCAL
int initialize(
QoreClass* cls,
bool& has_delete_blocker);
1433 DLLLOCAL
bool isBaseClass(
QoreClass* qc,
bool toplevel)
const;
1435 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethod(
const char* name, ClassAccess& n_access,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1436 DLLLOCAL
const QoreMethod* runtimeFindCommittedStaticMethod(
const char* name, ClassAccess& n_access,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1438 DLLLOCAL
bool runtimeIsPrivateMember(
const char* str,
bool toplevel)
const;
1442 DLLLOCAL
const QoreMemberInfo* parseFindMember(
const char* mem,
const qore_class_private*& qc, ClassAccess& n_access,
bool toplevel)
const;
1443 DLLLOCAL
const QoreVarInfo* parseFindVar(
const char* name,
const qore_class_private*& qc, ClassAccess& n_access,
bool toplevel)
const;
1445 DLLLOCAL
const QoreClass* findInHierarchy(
const qore_class_private& qc);
1448 DLLLOCAL
const QoreClass* getClass(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const;
1449 DLLLOCAL
const QoreClass* parseGetClass(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const;
1450 DLLLOCAL
bool inHierarchy(
const qore_class_private& qc, ClassAccess& n_access)
const;
1453 DLLLOCAL
const QoreMethod* parseFindNormalMethod(
const char* name,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1456 DLLLOCAL
const QoreMethod* parseFindStaticMethod(
const char* name,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1459 DLLLOCAL
const QoreMethod* parseResolveSelfMethod(
const QoreProgramLocation* loc,
const char* name,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1461 DLLLOCAL
bool parseCheckHierarchy(
const QoreClass* cls, ClassAccess& n_access,
bool toplevel)
const;
1463 DLLLOCAL QoreVarInfo* parseFindStaticVar(
const char* vname,
const QoreClass*& qc, ClassAccess& n_access,
bool check,
bool toplevel)
const;
1465 DLLLOCAL
QoreValue parseFindConstantValue(
const char* cname,
const QoreTypeInfo*& typeInfo,
bool &found,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1467 DLLLOCAL
int addBaseClassesToSubclass(
QoreClass* child,
bool is_virtual);
1469 DLLLOCAL
void initializeBuiltin();
1472 typedef std::vector<BCNode*> bclist_t;
1480 class BCList :
public bclist_t {
1486 bool rescanned =
false;
1488 DLLLOCAL BCList(BCNode* n) {
1495 DLLLOCAL BCList(
const BCList& old) : sml(old.sml) {
1497 reserve(old.size());
1498 for (bclist_t::const_iterator i = old.begin(), e = old.end(); i != e; ++i)
1499 push_back(
new BCNode(*(*i)));
1502 DLLLOCAL ~BCList() {
1503 for (bclist_t::iterator i = begin(), e = end(); i != e; ++i)
1507 DLLLOCAL
int initializeHierarchy(
QoreClass* thisclass, qcp_set_t& qcp_set);
1509 DLLLOCAL
void initializeMembers(
QoreClass* thisclass);
1511 DLLLOCAL
int initialize(
QoreClass* thisclass,
bool& has_delete_blocker);
1514 DLLLOCAL
const QoreMethod* parseResolveSelfMethod(
const QoreProgramLocation* loc,
const char* name,
const qore_class_private* class_ctx,
bool allow_internal);
1517 DLLLOCAL
const QoreMethod* parseFindNormalMethod(
const char* name,
const qore_class_private* class_ctx,
bool allow_internal);
1519 DLLLOCAL
const QoreMethod* parseFindStaticMethod(
const char* name,
const qore_class_private* class_ctx,
bool allow_internal);
1521 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethod(
const char* name, ClassAccess& access,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1522 DLLLOCAL
const QoreMethod* runtimeFindCommittedStaticMethod(
const char* name, ClassAccess& access,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1524 DLLLOCAL
bool match(
const QoreClass* cls);
1528 DLLLOCAL
bool runtimeIsPrivateMember(
const char* str,
bool toplevel)
const;
1530 DLLLOCAL
bool parseCheckHierarchy(
const QoreClass* cls, ClassAccess& access,
bool toplevel)
const;
1532 DLLLOCAL
const QoreMemberInfo* parseFindMember(
const char* mem,
const qore_class_private*& qc, ClassAccess& n_access,
bool toplevel)
const;
1534 DLLLOCAL
const QoreVarInfo* parseFindVar(
const char* vname,
const qore_class_private*& qc, ClassAccess& access,
bool toplevel)
const;
1536 DLLLOCAL
bool parseHasPublicMembersInHierarchy()
const;
1538 DLLLOCAL
const QoreClass* findInHierarchy(
const qore_class_private& qc);
1541 DLLLOCAL
const QoreClass* getClass(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const;
1543 DLLLOCAL
const QoreClass* parseGetClass(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const;
1544 DLLLOCAL
bool inHierarchy(
const qore_class_private& qc, ClassAccess& n_access)
const;
1546 DLLLOCAL
void addNewAncestors(
QoreMethod* m);
1548 DLLLOCAL
void addNewStaticAncestors(
QoreMethod* m);
1549 DLLLOCAL
void addStaticAncestors(
QoreMethod* m);
1550 DLLLOCAL
void parseAddAncestors(
QoreMethod* m);
1551 DLLLOCAL
void parseAddStaticAncestors(
QoreMethod* m);
1553 DLLLOCAL
void parseResolveAbstract();
1555 DLLLOCAL
QoreValue parseFindConstantValue(
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1557 DLLLOCAL QoreVarInfo* parseFindStaticVar(
const char* vname,
const QoreClass*& qc, ClassAccess& access,
bool check,
bool toplevel)
const;
1559 DLLLOCAL
void resolveCopy();
1561 DLLLOCAL MethodVariantBase* matchNonAbstractVariant(
const std::string& name, MethodVariantBase* v)
const;
1563 DLLLOCAL
bool isBaseClass(
QoreClass* qc,
bool toplevel)
const;
1565 DLLLOCAL
int addBaseClassesToSubclass(
QoreClass* thisparent,
QoreClass* child,
bool is_virtual) {
1566 for (
auto& i : *
this) {
1567 if ((*i).addBaseClassesToSubclass(child, is_virtual))
1570 return sml.addBaseClassesToSubclass(thisparent, child, is_virtual);
1573 DLLLOCAL
void rescanParents(
QoreClass* cls);
1575 DLLLOCAL
void initializeBuiltin() {
1576 for (
auto& i : *
this) {
1577 (*i).initializeBuiltin();
1586 const QoreProgramLocation* loc;
1588 const AbstractQoreFunctionVariant* variant =
nullptr;
1589 bool execed =
false;
1590 bool member_init_done =
false;
1592 DLLLOCAL BCEANode(
const QoreProgramLocation* loc,
QoreListNode* args,
const AbstractQoreFunctionVariant* variant) : loc(loc), args(args), variant(reinterpret_cast<const MethodVariant*>(variant)) {
1595 DLLLOCAL BCEANode(
bool n_execed =
true,
bool mid =
true) : execed(n_execed), member_init_done(mid) {
1608 typedef vector_map_t<qore_classid_t, BCEANode*> bceamap_t;
1614 class BCEAList :
public bceamap_t {
1616 DLLLOCAL ~BCEAList() {
1624 DLLLOCAL
QoreListNode* findArgs(
qore_classid_t classid,
bool* aexeced,
const AbstractQoreFunctionVariant*& variant,
const QoreProgramLocation*& loc);
1641 hashdecl SelfInstantiatorHelper {
1643 DLLLOCAL SelfInstantiatorHelper(LocalVar* n_selfid,
QoreObject*
self) : selfid(n_selfid) {
1644 selfid->instantiateSelf(
self);
1646 DLLLOCAL ~SelfInstantiatorHelper() {
1647 selfid->uninstantiateSelf();
1655 class SignatureHash {
1657 unsigned char buf[SH_SIZE];
1662 DLLLOCAL
void clearHash() {
1663 memset(buf, 0, SH_SIZE);
1666 DLLLOCAL
void copyHash(
const SignatureHash& other) {
1667 memcpy(buf, other.buf, SH_SIZE);
1671 DLLLOCAL SignatureHash() : is_set(false) {
1675 DLLLOCAL SignatureHash(
const SignatureHash& old) : is_set(old.is_set) {
1682 DLLLOCAL
void updateEmpty() {
1688 DLLLOCAL
bool operator==(
const SignatureHash& other)
const {
1690 if (!is_set || !other.is_set)
1692 return !memcmp(buf, other.buf, SH_SIZE);
1695 DLLLOCAL SignatureHash& operator=(
const SignatureHash& other) {
1696 if (!other.is_set) {
1708 DLLLOCAL
operator bool()
const {
1713 DLLLOCAL
void toString(
QoreString& str)
const {
1714 for (
unsigned i = 0; i < SH_SIZE; ++i)
1718 DLLLOCAL
char* getHash()
const {
1723 DLLLOCAL
void clear() {
1731 #define QCCM_NORMAL (1 << 0)
1732 #define QCCM_STATIC (1 << 1)
1735 typedef vector_set_t<QoreClass*> qc_set_t;
1740 class qore_class_private {
1742 const QoreProgramLocation* loc;
1745 qore_ns_private* ns =
nullptr;
1746 BCList* scl =
nullptr;
1749 mutable VRMutex gate;
1754 AbstractMethodMap ahm;
1756 ConstantList constlist;
1759 QoreMemberMap members;
1761 member_init_list_t member_init_list;
1766 const QoreMethod* system_constructor =
nullptr,
1767 * constructor =
nullptr,
1768 * destructor =
nullptr,
1769 * copyMethod =
nullptr,
1770 * methodGate =
nullptr,
1771 * memberGate =
nullptr,
1772 * deleteBlocker =
nullptr,
1773 * memberNotification =
nullptr;
1785 parse_init_called : 1,
1786 parse_init_partial_called : 1,
1787 has_delete_blocker : 1,
1788 has_public_memdecl : 1,
1789 pending_has_public_memdecl : 1,
1791 resolve_copy_done : 1,
1792 has_new_user_changes : 1,
1793 has_sig_changes : 1,
1794 owns_ornothingtypeinfo : 1,
1800 parse_resolve_hierarchy : 1,
1801 parse_resolve_class_members : 1,
1802 parse_resolve_abstract : 1,
1803 has_transient_member : 1
1811 unsigned num_methods, num_user_methods, num_static_methods, num_static_user_methods;
1815 QoreTypeInfo* typeInfo,
1818 const qore_class_private* injectedClass =
nullptr;
1821 mutable LocalVar selfid;
1827 const void* ptr =
nullptr;
1839 bool deref_source_program =
true;
1842 std::string from_module;
1844 DLLLOCAL qore_class_private(
QoreClass* n_cls, std::string&& nme,
int64 dom =
QDOM_DEFAULT, QoreTypeInfo* n_typeinfo =
nullptr);
1848 DLLLOCAL qore_class_private(
const qore_class_private& old, qore_ns_private* ns,
QoreProgram* spgm,
const char* nme,
bool inject,
const qore_class_private* injectedClass, q_setpub_t set_pub);
1852 DLLLOCAL
void addBaseClass(
QoreClass* qc,
bool virt);
1857 DLLLOCAL
const char* getModuleName()
const {
1858 return from_module.empty() ? nullptr : from_module.c_str();
1861 DLLLOCAL
void pgmRef()
const {
1867 DLLLOCAL
void ref()
const {
1871 DLLLOCAL
bool deref(
bool ns_const,
bool ns_vars,
bool in_del =
false) {
1874 if (!constlist.empty()) {
1875 constlist.deleteAll(
nullptr);
1880 if (!vars.empty()) {
1887 cls->priv =
nullptr;
1893 for (
auto& i : qcset) {
1904 DLLLOCAL
bool hasAbstract()
const {
1905 return !ahm.empty();
1908 DLLLOCAL
int runtimeCheckInstantiateClass(
ExceptionSink* xsink)
const {
1909 return ahm.runtimeCheckInstantiateClass(name.c_str(), xsink);
1912 DLLLOCAL
void parseCheckAbstractNew(
const QoreProgramLocation* loc)
const;
1914 DLLLOCAL
void parseDoCheckAbstractNew(
const QoreProgramLocation* loc)
const {
1915 ahm.parseCheckAbstractNew(loc, name.c_str());
1918 DLLLOCAL
void setNamespace(qore_ns_private* n) {
1924 DLLLOCAL
bool setNamespaceConditional(qore_ns_private* n) {
1934 DLLLOCAL
void updateNamespace(qore_ns_private* n) {
1939 DLLLOCAL
void resolveCopy();
1941 DLLLOCAL
void setUserData(
const void* n_ptr) {
1946 DLLLOCAL
const void* getUserData()
const {
1959 DLLLOCAL
const QoreTypeInfo* getTypeInfo()
const {
1963 DLLLOCAL
const QoreTypeInfo* getOrNothingTypeInfo()
const {
1964 return orNothingTypeInfo;
1967 DLLLOCAL
bool runtimeIsPrivateMemberIntern(
const char* str,
bool toplevel)
const;
1969 DLLLOCAL
void parseImportMembers(qore_class_private& qc, ClassAccess access);
1971 DLLLOCAL
bool parseHasMemberGate()
const {
1972 return memberGate || hm.find(
"memberGate") != hm.end();
1975 DLLLOCAL
bool parseHasMethodGate()
const {
1976 return methodGate || hm.find(
"methodGate") != hm.end();
1980 DLLLOCAL
bool checkAssignSpecialIntern(
const QoreMethod* m) {
1982 if (!methodGate && !strcmp(m->
getName(),
"methodGate")) {
1987 if (!memberGate && !strcmp(m->
getName(),
"memberGate")) {
1993 if (!memberNotification && !strcmp(m->
getName(),
"memberNotification")) {
1994 memberNotification = m;
2002 DLLLOCAL
bool checkSpecialStaticIntern(
const char* mname) {
2004 if ((!methodGate && !strcmp(mname,
"methodGate"))
2005 || (!memberGate && !strcmp(mname,
"memberGate"))
2006 || (!memberNotification && !strcmp(mname,
"memberNotification")))
2012 DLLLOCAL
bool checkSpecial(
const char* mname) {
2014 if ((!methodGate && !strcmp(mname,
"methodGate"))
2015 || (!memberGate && !strcmp(mname,
"memberGate"))
2016 || (!memberNotification && !strcmp(mname,
"memberNotification"))
2017 || (!constructor && !strcmp(mname,
"constructor"))
2018 || (!destructor && !strcmp(mname,
"destructor"))
2019 || (!copyMethod && !strcmp(mname,
"copy")))
2025 DLLLOCAL
bool checkAssignSpecial(
const QoreMethod* m) {
2027 if (!constructor && !strcmp(m->
getName(),
"constructor")) {
2032 if (!destructor && !strcmp(m->
getName(),
"destructor")) {
2037 if (!copyMethod && !strcmp(m->
getName(),
"copy")) {
2042 return checkAssignSpecialIntern(m);
2046 DLLLOCAL
void mergeAbstract();
2049 DLLLOCAL
int initializeIntern();
2050 DLLLOCAL
int initializeHierarchy(qcp_set_t& qcp_set);
2051 DLLLOCAL
void initializeMembers();
2052 DLLLOCAL
void initialize();
2054 DLLLOCAL
void parseInitPartial();
2055 DLLLOCAL
void parseInitPartialIntern();
2057 DLLLOCAL
int parseCheckMemberAccess(
const QoreProgramLocation* loc,
const char* mem,
const QoreTypeInfo*& memberTypeInfo,
int pflag)
const {
2058 const_cast<qore_class_private*
>(
this)->parseInitPartial();
2060 const qore_class_private* qc =
nullptr;
2062 const QoreMemberInfo* omi = parseFindMember(mem, qc, access);
2066 if (!parseHasMemberGate() || (pflag & PF_FOR_ASSIGNMENT)) {
2068 parse_error(*loc,
"member '%s' of class '%s' referenced has no type information because it was not declared in a public or private member list, but parse options require type information for all declarations",
2072 if (parseHasPublicMembersInHierarchy()) {
2074 parse_error(*loc,
"illegal access to unknown member '%s' in class '%s' which has a public member list (or inherited public member list)", mem, name.c_str());
2081 memberTypeInfo = omi->getTypeInfo();
2084 if ((access > Public) && !parseHasMemberGate() && !parseCheckPrivateClassAccess()) {
2086 parse_error(*loc,
"illegal access to private member '%s' of class '%s'", mem, name.c_str());
2092 DLLLOCAL
int parseResolveInternalMemberAccess(
const char* mem,
const QoreTypeInfo*& memberTypeInfo)
const {
2093 const_cast<qore_class_private*
>(
this)->parseInitPartial();
2095 const qore_class_private* qc =
nullptr;
2097 const QoreMemberInfo* omi = parseFindMember(mem, qc, access);
2099 memberTypeInfo = omi->getTypeInfo();
2102 return omi ? 0 : -1;
2105 DLLLOCAL
int parseCheckInternalMemberAccess(
const char* mem,
const QoreTypeInfo*& memberTypeInfo,
const QoreProgramLocation* loc)
const {
2106 const_cast<qore_class_private*
>(
this)->parseInitPartial();
2109 const qore_class_private* qc =
nullptr;
2111 const QoreMemberInfo* omi = parseFindMember(mem, qc, access);
2116 const_cast<QoreMemberInfo*
>(omi)->parseInit(mem, selfid);
2117 memberTypeInfo = omi->parseGetTypeInfo();
2123 parse_error(*loc,
"member '%s' of class '%s' referenced has no type information because it was not declared in a public or private member list, but parse options require type information for all declarations", mem, name.c_str());
2126 if (parseHasPublicMembersInHierarchy()) {
2127 parse_error(*loc,
"illegal access to unknown member '%s' in class '%s' which has a public member list (or inherited public member list)", mem, name.c_str());
2134 DLLLOCAL
bool parseHasPublicMembersInHierarchy()
const {
2135 if (has_public_memdecl || pending_has_public_memdecl)
2138 return scl ? scl->parseHasPublicMembersInHierarchy() :
false;
2148 DLLLOCAL
const qore_class_private* runtimeGetMemberContext(
const char* mem,
const qore_class_private* class_ctx)
const {
2149 const QoreMemberInfo* info = runtimeGetMemberInfo(mem, class_ctx);
2151 return info ? info->getClassContext(class_ctx) :
nullptr;
2154 DLLLOCAL
bool runtimeIsMemberInternal(
const char* mem)
const {
2155 QoreMemberInfo* info = members.find(mem);
2156 return info && info->isLocalInternal() ? true :
false;
2169 DLLLOCAL
const QoreMemberInfo* runtimeGetMemberInfo(
const char* mem,
const qore_class_private* class_ctx)
const {
2170 QoreMemberInfo* info;
2172 info = class_ctx->members.find(mem);
2173 if (info && info->isLocalInternal()) {
2180 if (class_ctx !=
this) {
2181 info = members.find(mem);
2184 if (info && info->access == Inaccessible && !info->getClassContext(class_ctx)) {
2191 DLLLOCAL
const QoreMemberInfo* parseFindMember(
const char* mem,
const qore_class_private*& qc, ClassAccess& access)
const {
2193 const_cast<qore_class_private*
>(
this)->initialize();
2194 return parseFindMemberNoInit(mem, qc, access,
true);
2200 DLLLOCAL
const QoreMemberInfo* parseFindMemberNoInit(
const char* mem,
const qore_class_private*& qc, ClassAccess& access,
bool toplevel)
const {
2201 const QoreMemberInfo* mi = members.find(mem);
2203 ClassAccess ma = mi->getAccess();
2204 if (toplevel || ma != Internal) {
2208 qc = mi->getClass();
2213 return scl ? scl->parseFindMember(mem, qc, access,
true) : 0;
2216 DLLLOCAL
const QoreVarInfo* parseFindVar(
const char* vname,
const qore_class_private*& qc, ClassAccess& access,
bool toplevel)
const {
2219 QoreVarInfo* vi = vars.find(
const_cast<char*
>(vname));
2223 access = vi->getAccess();
2227 return scl ? scl->parseFindVar(vname, qc, access, toplevel) :
nullptr;
2230 DLLLOCAL
int parseCheckClassHierarchyMembers(
const char* mname,
const QoreMemberInfo& l_mi,
const QoreMemberInfo& b_mi)
const;
2232 DLLLOCAL
int checkExistingVarMember(
const char* dname,
const QoreMemberInfoBaseAccess* mi,
const QoreMemberInfoBaseAccess* omi,
const qore_class_private* qc, ClassAccess oaccess,
bool var =
false)
const;
2234 DLLLOCAL
int parseCheckVar(
const char* dname,
const QoreVarInfo* vi)
const {
2235 const qore_class_private* qc = 0;
2237 const QoreVarInfo* ovi = parseFindVar(dname, qc, access,
true);
2240 if (parseHasConstant(dname)) {
2241 parse_error(*vi->loc,
"'%s' has already been declared as a constant in class '%s' and therefore cannot be also declared as a static class variable in the same class with the same name", dname, name.c_str());
2247 return checkExistingVarMember(dname, vi, ovi, qc, access,
true);
2250 DLLLOCAL
int parseCheckMember(
const char* mem,
const QoreMemberInfo* mi)
const {
2251 const qore_class_private* qc =
nullptr;
2252 ClassAccess access = Public;
2253 const QoreMemberInfo* omi = parseFindMemberNoInit(mem, qc, access,
true);
2258 return checkExistingVarMember(mem, mi, omi, qc, omi->access);
2261 DLLLOCAL
int parseCheckMemberInBaseClasses(
const char* mem,
const QoreMemberInfo* mi)
const {
2262 const qore_class_private* qc =
nullptr;
2263 ClassAccess access = Public;
2266 const QoreMemberInfo* omi = scl ? scl->parseFindMember(mem, qc, access,
false) :
nullptr;
2267 if (!omi || (omi->getClass() == mi->getClass())) {
2271 return checkExistingVarMember(mem, mi, omi, qc, omi->access);
2274 DLLLOCAL
int parseCheckSystemCommitted(
const QoreProgramLocation* loc) {
2276 parse_error(*loc,
"cannot modify system class '%s'", name.c_str());
2280 parse_error(*loc,
"cannot modify user class '%s' once it's been committed", name.c_str());
2286 DLLLOCAL
void parseAddMember(
char* mem, ClassAccess access, QoreMemberInfo* memberInfo) {
2287 memberInfo->access = access;
2288 if (!parseCheckSystemCommitted(memberInfo->loc) && !parseCheckMember(mem, memberInfo)) {
2289 if (!has_new_user_changes) {
2290 has_new_user_changes =
true;
2292 if (!has_sig_changes) {
2293 has_sig_changes =
true;
2295 memberInfo->setDeclaringClass(
this);
2296 if (!has_transient_member && memberInfo->getTransient()) {
2297 has_transient_member =
true;
2300 members.addNoCheck(mem, memberInfo);
2308 DLLLOCAL
void parseAddStaticVar(
char* dname, ClassAccess access, QoreVarInfo* VarInfo) {
2309 VarInfo->access = access;
2310 if (!parseCheckSystemCommitted(VarInfo->loc) && !parseCheckVar(dname, VarInfo)) {
2311 if (!has_new_user_changes) {
2312 has_new_user_changes =
true;
2314 if (!has_sig_changes) {
2315 has_sig_changes =
true;
2319 vars.addNoCheck(dname, VarInfo);
2327 DLLLOCAL
void addBuiltinConstant(
const char* cname,
QoreValue value, ClassAccess access = Public,
const QoreTypeInfo* cTypeInfo =
nullptr) {
2328 assert(!constlist.inList(cname));
2330 sys = committed =
true;
2332 constlist.add(cname, value, cTypeInfo, access);
2335 DLLLOCAL
void addBuiltinStaticVar(
const char* vname,
QoreValue value, ClassAccess access = Public,
const QoreTypeInfo* vTypeInfo =
nullptr);
2337 DLLLOCAL
void parseAssimilateConstants(ConstantList &cmap, ClassAccess access) {
2338 assert(!sys && !committed);
2339 if (!has_new_user_changes)
2340 has_new_user_changes =
true;
2341 if (!has_sig_changes)
2342 has_sig_changes =
true;
2345 cmap.setAccess(access);
2346 constlist.assimilate(cmap,
"class", name.c_str());
2349 DLLLOCAL
void parseAddConstant(
const QoreProgramLocation* loc,
const std::string &cname,
QoreValue val, ClassAccess access) {
2351 if (parseCheckSystemCommitted(loc)) {
2354 if (parseHasVar(cname.c_str())) {
2355 parse_error(*loc,
"'%s' has already been declared as a static variable in class '%s' and therefore cannot be also declared as a constant in the same class with the same name", cname.c_str(), name.c_str());
2358 if (!has_new_user_changes)
2359 has_new_user_changes =
true;
2360 if (!has_sig_changes)
2361 has_sig_changes =
true;
2365 constlist.parseAdd(loc, cname, val_holder.release(), access, name.c_str());
2368 DLLLOCAL
bool parseHasVar(
const char* vn) {
2369 return vars.inList(vn);
2372 DLLLOCAL
bool parseHasConstant(
const std::string &cname)
const {
2373 return constlist.inList(cname);
2376 DLLLOCAL
QoreValue parseFindLocalConstantValue(
const char* cname,
const QoreTypeInfo*& cTypeInfo,
bool& found) {
2380 ClassAccess access = Public;
2381 QoreValue rv = constlist.find(cname, cTypeInfo, access, found);
2384 if (found && (access > Public)) {
2385 qore_class_private* class_ctx = parse_get_class_priv();
2386 if ((access == Internal && class_ctx !=
this) || !parseCheckPrivateClassAccess(class_ctx)) {
2388 cTypeInfo =
nullptr;
2397 DLLLOCAL
QoreValue parseFindConstantValue(
const char* cname,
const QoreTypeInfo*& cTypeInfo,
bool& found,
const qore_class_private* class_ctx) {
2399 return parseFindConstantValueIntern(cname, cTypeInfo, found, class_ctx);
2402 DLLLOCAL
QoreValue parseFindConstantValueIntern(
const char* cname,
const QoreTypeInfo*& cTypeInfo,
bool& found,
const qore_class_private* class_ctx) {
2406 ClassAccess access = Public;
2407 QoreValue rv = constlist.find(cname, cTypeInfo, access, found);
2411 if (access == Internal) {
2412 if (class_ctx ==
this)
2415 cTypeInfo =
nullptr;
2418 }
else if (access == Private && !parseCheckPrivateClassAccess(class_ctx)) {
2419 cTypeInfo =
nullptr;
2426 return scl ? scl->parseFindConstantValue(cname, cTypeInfo, found, class_ctx, class_ctx ==
this) :
QoreValue();
2429 DLLLOCAL QoreVarInfo* parseFindLocalStaticVar(
const char* vname)
const {
2430 QoreVarInfo* vi = vars.find(vname);
2432 if (vi && (vi->access > Public) && !parseCheckPrivateClassAccess())
2438 DLLLOCAL QoreVarInfo* parseFindStaticVar(
const char* vname,
const QoreClass*& qc, ClassAccess& access,
bool check =
false)
const {
2440 return parseFindStaticVarIntern(vname, qc, access, check,
true);
2443 DLLLOCAL QoreVarInfo* parseFindStaticVarIntern(
const char* vname,
const QoreClass*& qc, ClassAccess& access,
bool check,
bool toplevel)
const {
2444 QoreVarInfo* vi = vars.find(vname);
2447 ClassAccess va = vi->getAccess();
2448 if (toplevel || va != Internal) {
2454 if (check && (access > Public) && !parseCheckPrivateClassAccess()) {
2463 return scl ? scl->parseFindStaticVar(vname, qc, access, check, toplevel) :
nullptr;
2466 DLLLOCAL
void addMember(
const char* mem, ClassAccess access,
const QoreTypeInfo* n_typeinfo,
QoreValue initial_value) {
2467 assert(!members.inList(mem));
2468 if (!has_sig_changes) {
2469 has_sig_changes =
true;
2471 members.addNoCheck(strdup(mem),
new QoreMemberInfo(&loc_builtin, n_typeinfo,
nullptr, initial_value, access,
this));
2472 if (access == Public && !has_public_memdecl) {
2473 has_public_memdecl =
true;
2477 DLLLOCAL
void insertBuiltinStaticMethod(
QoreMethod* m) {
2482 ++num_static_methods;
2484 sys = committed =
true;
2487 assert(!checkSpecialStaticIntern(m->
getName()));
2489 addStaticAncestors(m);
2492 DLLLOCAL
void insertBuiltinMethod(
QoreMethod* m,
bool special_method =
false) {
2499 sys = committed =
true;
2502 if (!special_method && !checkAssignSpecialIntern(m))
2507 DLLLOCAL
void recheckBuiltinMethodHierarchy();
2509 DLLLOCAL
void addNewAncestors(
QoreMethod* m) {
2513 scl->addNewAncestors(m);
2516 DLLLOCAL
void addNewStaticAncestors(
QoreMethod* m) {
2520 scl->addNewStaticAncestors(m);
2523 DLLLOCAL
void addStaticAncestors(
QoreMethod* m) {
2527 scl->addStaticAncestors(m);
2531 assert(strcmp(m->
getName(),
"constructor"));
2536 scl->addAncestors(m);
2539 DLLLOCAL
void parseAddStaticAncestors(
QoreMethod* m) {
2543 scl->parseAddStaticAncestors(m);
2546 DLLLOCAL
void parseAddAncestors(
QoreMethod* m) {
2548 assert(strcmp(m->
getName(),
"constructor"));
2553 scl->parseAddAncestors(m);
2558 DLLLOCAL
int initMember(
QoreObject& o,
bool& need_scan,
const char* member_name,
const QoreMemberInfo& info,
const qore_class_private* member_class_ctx,
ExceptionSink* xsink)
const;
2568 constlist.deleteAll(xsink);
2581 DLLLOCAL
void deleteClassData(
bool deref_vars,
ExceptionSink* xsink) {
2596 if (deref_source_program) {
2624 const qore_class_private* class_ctx,
ExceptionSink* xsink)
const;
2631 DLLLOCAL
void addBuiltinMethod(
const char* mname, MethodVariantBase* variant);
2632 DLLLOCAL
void addBuiltinStaticMethod(
const char* mname, MethodVariantBase* variant);
2633 DLLLOCAL
void addBuiltinConstructor(BuiltinConstructorVariantBase* variant);
2634 DLLLOCAL
void addBuiltinDestructor(BuiltinDestructorVariantBase* variant);
2635 DLLLOCAL
void addBuiltinCopyMethod(BuiltinCopyVariantBase* variant);
2637 DLLLOCAL
void setBuiltinSystemConstructor(BuiltinSystemConstructorBase* m);
2645 DLLLOCAL
QoreMethod* parseFindLocalMethod(
const char* nme) {
2646 hm_method_t::iterator i = hm.find(nme);
2647 return (i != hm.end()) ? i->second :
nullptr;
2650 DLLLOCAL
const QoreMethod* parseFindLocalMethod(
const char* nme)
const {
2651 hm_method_t::const_iterator i = hm.find(nme);
2652 return (i != hm.end()) ? i->second :
nullptr;
2655 DLLLOCAL
QoreMethod* parseFindLocalMethod(
const std::string& nme) {
2656 hm_method_t::iterator i = hm.find(nme);
2657 return (i != hm.end()) ? i->second :
nullptr;
2660 DLLLOCAL
const QoreMethod* parseFindLocalMethod(
const std::string& nme)
const {
2661 hm_method_t::const_iterator i = hm.find(nme);
2662 return (i != hm.end()) ? i->second :
nullptr;
2666 DLLLOCAL
const QoreMethod* parseFindAnyLocalMethod(
const char* nme)
const {
2667 const QoreMethod* m = parseFindLocalMethod(nme);
2668 return m ? m : parseFindLocalStaticMethod(nme);
2672 DLLLOCAL
QoreMethod* parseFindLocalStaticMethod(
const char* nme) {
2673 hm_method_t::iterator i = shm.find(nme);
2674 return (i != shm.end()) ? i->second :
nullptr;
2677 DLLLOCAL
const QoreMethod* parseFindLocalStaticMethod(
const char* nme)
const {
2678 hm_method_t::const_iterator i = shm.find(nme);
2679 return (i != shm.end()) ? i->second :
nullptr;
2683 DLLLOCAL
QoreMethod* findLocalCommittedMethod(
const char* nme);
2685 DLLLOCAL
const QoreMethod* findLocalCommittedMethod(
const char* nme)
const;
2688 DLLLOCAL
QoreMethod* findLocalCommittedStaticMethod(
const char* nme);
2690 DLLLOCAL
const QoreMethod* findLocalCommittedStaticMethod(
const char* nme)
const;
2692 DLLLOCAL
void finalizeBuiltin(
const char* nspath);
2693 DLLLOCAL
void generateBuiltinSignature(
const char* nspath);
2694 DLLLOCAL
void initializeBuiltin();
2700 DLLLOCAL
static const QoreMethod* doParseMethodAccess(
const QoreMethod* m,
const qore_class_private* class_ctx);
2702 DLLLOCAL
static const QoreMethod* doMethodAccess(
const QoreMethod* m, ClassAccess ma,
const qore_class_private* class_ctx) {
2704 return ((ma == Public) || ((ma == Private && class_ctx))) ? m :
nullptr;
2707 DLLLOCAL
static const QoreMethod* doMethodAccess(
const QoreMethod* m, ClassAccess& access, ClassAccess ma) {
2712 else if (access < ma)
2718 DLLLOCAL
const QoreMethod* doRuntimeMethodAccess(
const QoreMethod* m, ClassAccess& access, ClassAccess ma,
const qore_class_private* class_ctx)
const {
2721 if (ma == Internal && (!class_ctx || !equal(*class_ctx)))
2723 else if (access < ma)
2730 DLLLOCAL
const QoreMethod* parseFindNormalMethod(
const char* mname,
const qore_class_private* class_ctx);
2733 DLLLOCAL
const QoreMethod* parseFindStaticMethod(
const char* mname,
const qore_class_private* class_ctx);
2736 DLLLOCAL
const QoreMethod* parseFindNormalMethodIntern(
const char* mname,
const qore_class_private* class_ctx);
2739 DLLLOCAL
const QoreMethod* parseFindStaticMethodIntern(
const char* mname,
const qore_class_private* class_ctx);
2741 DLLLOCAL
const QoreMethod* parseResolveSelfMethodIntern(
const QoreProgramLocation* loc,
const char* nme,
const qore_class_private* class_ctx);
2745 DLLLOCAL
const QoreMethod* runtimeFindCommittedStaticMethodIntern(
const char* nme, ClassAccess& access,
const qore_class_private* class_ctx)
const {
2746 const QoreMethod* m = findLocalCommittedStaticMethod(nme);
2748 (class_ctx ==
this || doRuntimeMethodAccess(m, access, m->
getAccess(), class_ctx))) {
2755 return scl->runtimeFindCommittedStaticMethod(nme, access, class_ctx, class_ctx ==
this);
2760 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethodIntern(
const char* nme, ClassAccess& access,
const qore_class_private* class_ctx)
const {
2761 const QoreMethod* m = findLocalCommittedMethod(nme);
2764 (class_ctx ==
this || doRuntimeMethodAccess(m, access, m->
getAccess(), class_ctx))) {
2771 return scl->runtimeFindCommittedMethod(nme, access, class_ctx, class_ctx ==
this);
2774 DLLLOCAL
const QoreMethod* runtimeFindCommittedStaticMethod(
const char* nme, ClassAccess& access,
2775 const qore_class_private* class_ctx)
const;
2777 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethod(
const char* nme, ClassAccess& access,
2778 const qore_class_private* class_ctx)
const;
2780 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethodForEval(
const char* nme, ClassAccess& access,
2781 const qore_class_private* class_ctx)
const;
2783 DLLLOCAL
const QoreMethod* runtimeFindAnyCommittedMethod(
const char* nme)
const {
2784 ClassAccess access = Public;
2785 const qore_class_private* class_ctx =
this;
2786 const QoreMethod* m = runtimeFindCommittedMethodIntern(nme, access, class_ctx);
2789 if (!strcmp(nme,
"constructor"))
2791 if (!strcmp(nme,
"destructor"))
2793 if (!strcmp(nme,
"copy"))
2795 if (!strcmp(nme,
"methodGate"))
2797 if (!strcmp(nme,
"memberGate"))
2799 if (!strcmp(nme,
"memberNotification"))
2800 return memberNotification;
2805 DLLLOCAL
const QoreMethod* findMethod(
const char* nme, ClassAccess& access)
const {
2806 CurrentProgramRuntimeParseContextHelper pch;
2807 const qore_class_private* class_ctx = runtime_get_class();
2808 if (class_ctx && !runtimeCheckPrivateClassAccess(class_ctx))
2809 class_ctx =
nullptr;
2810 return runtimeFindCommittedMethod(nme, access, class_ctx);
2813 DLLLOCAL
bool runtimeHasCallableMethod(
const char* m,
int mask)
const;
2823 DLLLOCAL
void parseInit();
2824 DLLLOCAL
void parseResolveHierarchy();
2825 DLLLOCAL
void parseResolveClassMembers();
2826 DLLLOCAL
void parseResolveAbstract();
2827 DLLLOCAL
void parseCommit();
2829 DLLLOCAL
void parseRollback();
2830 DLLLOCAL
int addUserMethod(
const char* mname, MethodVariantBase* f,
bool n_static);
2831 DLLLOCAL
void addLocalMembersForInit();
2840 const qore_class_private* class_ctx = runtime_get_class();
2841 if (class_ctx && !runtimeCheckPrivateClassAccess(class_ctx))
2842 class_ctx =
nullptr;
2844 if (!(w = runtimeFindCommittedMethod(nme, access, class_ctx))) {
2848 const char* cname = n.get<
const QoreObject>()->getClassName();
2849 xsink->
raiseException(
"METHOD-DOES-NOT-EXIST",
"no method %s::%s() or pseudo-method %s::%s() is available", cname, nme, name.c_str(), nme);
2852 xsink->
raiseException(
"PSEUDO-METHOD-DOES-NOT-EXIST",
"no pseudo method <%s>::%s() has been defined", n.getTypeName(), nme);
2859 DLLLOCAL
bool parseCheckPrivateClassAccess(
const qore_class_private* qc = parse_get_class_priv())
const;
2860 DLLLOCAL
bool runtimeCheckPrivateClassAccess(
const qore_class_private* qc = runtime_get_class())
const;
2863 DLLLOCAL qore_type_result_e parseCheckCompatibleClass(
const qore_class_private& oc)
const {
2864 bool may_not_match =
false;
2865 qore_type_result_e rv = parseCheckCompatibleClass(oc, may_not_match);
2868 return QTI_NOT_EQUAL;
2872 DLLLOCAL qore_type_result_e parseCheckCompatibleClass(
const qore_class_private& oc,
bool& may_not_match)
const;
2873 DLLLOCAL qore_type_result_e parseCheckCompatibleClassIntern(
const qore_class_private& oc,
bool& may_not_match)
const;
2875 DLLLOCAL qore_type_result_e runtimeCheckCompatibleClass(
const qore_class_private& oc)
const;
2876 DLLLOCAL qore_type_result_e runtimeCheckCompatibleClassIntern(
const qore_class_private& oc)
const;
2879 DLLLOCAL
const QoreClass* findInHierarchy(
const qore_class_private& qc) {
2882 return scl ? scl->findInHierarchy(qc) :
nullptr;
2888 return scl ? scl->getClass(cid, n_access, toplevel) :
nullptr;
2891 DLLLOCAL
const QoreClass* getClass(
const qore_class_private& qc, ClassAccess& n_access)
const {
2893 return getClassIntern(qc, n_access,
true);
2896 DLLLOCAL
const QoreClass* getClassIntern(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const {
2901 if (qc.name == name) {
2904 qc.hash.toString(rh);
2905 printd(0,
"qore_class_private::getClassIntern() this: %p '%s' != '%s' scl: %p (hash: %s qc.hash: %s)\n",
this, name.c_str(), qc.name.c_str(), scl, lh.
getBuffer(), rh.
getBuffer());
2909 return scl ? scl->getClass(qc, n_access, toplevel) :
nullptr;
2912 DLLLOCAL
const QoreClass* parseGetClassIntern(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const {
2919 if (qc.name == name) {
2920 printd(5,
"qore_class_private::parseGetClassIntern() this: %p '%s' != '%s' scl: %p\n",
this, name.c_str(), qc.name.c_str(), scl);
2922 qc.parseShowHashes();
2926 return scl ? scl->parseGetClass(qc, n_access, toplevel) :
nullptr;
2929 DLLLOCAL
bool inHierarchy(
const qore_class_private& qc, ClassAccess& n_access)
const {
2934 return scl ? scl->inHierarchy(qc, n_access) :
false;
2938 DLLLOCAL
void parseShowHash()
const {
2941 printd(5,
" + %p %s committed: %s\n",
this, name.c_str(), ch.
getBuffer());
2945 DLLLOCAL
bool parseCheckEqualHash(
const qore_class_private& qc)
const {
2947 printd(5,
"qore_class_private::parseCheckEqualHash() %s == %s\n", name.c_str(), qc.name.c_str());
2951 return hash == qc.hash;
2954 DLLLOCAL
bool equal(
const qore_class_private& qc)
const {
2958 if (qc.classID == classID || (qc.name == name && qc.hash == hash))
2961 if (injectedClass && injectedClass->equal(qc))
2964 if (qc.injectedClass && equal(*qc.injectedClass))
2970 DLLLOCAL
bool parseEqual(
const qore_class_private& qc)
const {
2974 if (qc.classID == classID || (qc.name == name && parseCheckEqualHash(qc)))
2977 if (injectedClass && injectedClass->parseEqual(qc))
2980 if (qc.injectedClass && parseEqual(*qc.injectedClass))
2986 DLLLOCAL
const QoreClass* parseGetClass(
const qore_class_private& qc, ClassAccess& n_access)
const;
2988 DLLLOCAL
int addBaseClassesToSubclass(
QoreClass* sc,
bool is_virtual);
2990 DLLLOCAL
void setPublic();
2992 DLLLOCAL
void parseSetBaseClassList(BCList* bcl) {
2996 if (!has_new_user_changes)
2997 has_new_user_changes =
true;
2998 if (!has_sig_changes)
2999 has_sig_changes =
true;
3003 DLLLOCAL
bool parseHasPendingChanges()
const {
3004 return has_new_user_changes;
3007 DLLLOCAL
bool parseCheckHierarchy(
const QoreClass* n_cls, ClassAccess& access)
const {
3009 return parseCheckHierarchyIntern(n_cls, access,
true);
3012 DLLLOCAL
bool parseCheckHierarchyIntern(
const QoreClass* n_cls, ClassAccess& access,
bool toplevel)
const {
3013 if (parseEqual(*n_cls->priv))
3016 return scl ? scl->parseCheckHierarchy(n_cls, access, toplevel) :
false;
3019 DLLLOCAL VRMutex* getGate()
const {
3024 DLLLOCAL
const QoreMethod* parseFindAnyMethod(
const char* nme,
const qore_class_private* class_ctx);
3027 DLLLOCAL
const QoreMethod* parseFindAnyMethodStaticFirst(
const char* nme,
const qore_class_private* class_ctx);
3030 DLLLOCAL
const QoreMethod* parseResolveSelfMethod(
const QoreProgramLocation* loc,
const char* nme,
const qore_class_private* class_ctx);
3031 DLLLOCAL
const QoreMethod* parseResolveSelfMethod(
const QoreProgramLocation* loc, NamedScope* nme);
3034 DLLLOCAL
const QoreMethod* parseFindSelfMethod(
const char* nme);
3036 DLLLOCAL
char* getHash()
const {
3037 return hash.getHash();
3041 assert(!serializer);
3046 assert(!deserializer);
3053 DLLLOCAL
static char* getHash(
const QoreClass& qc) {
3054 return qc.priv->getHash();
3057 DLLLOCAL
static void parseAddConstant(
QoreClass& qc,
const QoreProgramLocation* loc,
const std::string &cname,
QoreValue val, ClassAccess access) {
3058 qc.priv->parseAddConstant(loc, cname, val, access);
3061 DLLLOCAL
static LocalVar* getSelfId(
const QoreClass& qc) {
3062 return &qc.priv->selfid;
3065 DLLLOCAL
static QoreObject* execConstructor(
const QoreClass& qc,
const AbstractQoreFunctionVariant* variant,
3067 return qc.priv->execConstructor(xsink, variant, args);
3070 DLLLOCAL
static bool injected(
const QoreClass& qc) {
3071 return qc.priv->inject;
3074 DLLLOCAL
static QoreClass* makeImportClass(
const QoreClass& qc,
QoreProgram* spgm,
const char* nme,
bool inject,
const qore_class_private* injectedClass, qore_ns_private* ns, q_setpub_t set_pub) {
3075 qore_class_private* priv =
new qore_class_private(*qc.priv, ns, spgm, nme, inject, injectedClass, set_pub);
3080 DLLLOCAL
static const QoreMethod* runtimeFindCommittedStaticMethod(
const QoreClass& qc,
const char* nme, ClassAccess& access,
const qore_class_private* class_ctx) {
3081 return qc.priv->runtimeFindCommittedStaticMethod(nme, access, class_ctx);
3084 DLLLOCAL
static const QoreMethod* parseFindLocalMethod(
const QoreClass& qc,
const char* mname) {
3085 return qc.priv->parseFindLocalMethod(mname);
3088 DLLLOCAL
static bool parseHasPendingChanges(
const QoreClass& qc) {
3089 return qc.priv->parseHasPendingChanges();
3092 DLLLOCAL
static int parseCheckMemberAccess(
const QoreClass& qc,
const QoreProgramLocation* loc,
const char* mem,
const QoreTypeInfo*& memberTypeInfo,
int pflag) {
3093 return qc.priv->parseCheckMemberAccess(loc, mem, memberTypeInfo, pflag);
3096 DLLLOCAL
static bool runtimeHasCallableMethod(
const QoreClass& qc,
const char* m) {
3097 return qc.priv->runtimeHasCallableMethod(m, QCCM_NORMAL | QCCM_STATIC);
3100 DLLLOCAL
static bool runtimeHasCallableNormalMethod(
const QoreClass& qc,
const char* m) {
3101 return qc.priv->runtimeHasCallableMethod(m, QCCM_NORMAL);
3104 DLLLOCAL
static bool runtimeHasCallableStaticMethod(
const QoreClass& qc,
const char* m) {
3105 return qc.priv->runtimeHasCallableMethod(m, QCCM_STATIC);
3109 return qc.priv->runtimeCheckInstantiateClass(xsink);
3112 DLLLOCAL
static void parseInit(
QoreClass& qc) {
3113 qc.priv->parseInit();
3116 DLLLOCAL
static void parseInitPartial(
QoreClass& qc) {
3117 qc.priv->parseInitPartial();
3120 DLLLOCAL
static void parseCommit(
QoreClass& qc) {
3121 qc.priv->parseCommit();
3125 qc.priv->parseCommitRuntimeInit(xsink);
3128 DLLLOCAL
static void parseRollback(
QoreClass& qc) {
3129 qc.priv->parseRollback();
3132 DLLLOCAL
static void resolveCopy(
QoreClass& qc) {
3133 qc.priv->resolveCopy();
3136 DLLLOCAL
static int addUserMethod(
QoreClass& qc,
const char* mname, MethodVariantBase* f,
bool n_static) {
3137 return qc.priv->addUserMethod(mname, f, n_static);
3140 DLLLOCAL
static void initialize(
QoreClass& qc) {
3141 qc.priv->initialize();
3144 DLLLOCAL
static void parseSetBaseClassList(
QoreClass& qc, BCList* bcl) {
3145 qc.priv->parseSetBaseClassList(bcl);
3148 DLLLOCAL
static BCList* getBaseClassList(
const QoreClass& qc) {
3149 return qc.priv->scl;
3152 DLLLOCAL
static void parseAddStaticVar(
QoreClass* qc,
char* dname, ClassAccess access, QoreVarInfo* VarInfo) {
3153 qc->priv->parseAddStaticVar(dname, access, VarInfo);
3157 DLLLOCAL
static QoreValue parseFindLocalConstantValue(
QoreClass* qc,
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found) {
3158 return qc->priv->parseFindLocalConstantValue(cname, typeInfo, found);
3162 DLLLOCAL
static QoreVarInfo* parseFindLocalStaticVar(
const QoreClass* qc,
const char* vname) {
3163 return qc->priv->parseFindLocalStaticVar(vname);
3167 DLLLOCAL
static QoreValue parseFindConstantValue(
QoreClass* qc,
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found,
const qore_class_private* class_ctx) {
3168 return qc->priv->parseFindConstantValue(cname, typeInfo, found, class_ctx);
3172 DLLLOCAL
static QoreVarInfo* parseFindStaticVar(
const QoreClass* qc,
const char* vname,
const QoreClass*& nqc, ClassAccess& access,
bool check =
false) {
3173 return qc->priv->parseFindStaticVar(vname, nqc, access, check);
3176 DLLLOCAL
static int parseCheckInternalMemberAccess(
const QoreClass* qc,
const char* mem,
const QoreTypeInfo*& memberTypeInfo,
const QoreProgramLocation* loc) {
3177 return qc->priv->parseCheckInternalMemberAccess(mem, memberTypeInfo, loc);
3180 DLLLOCAL
static int parseResolveInternalMemberAccess(
const QoreClass* qc,
const char* mem,
const QoreTypeInfo*& memberTypeInfo) {
3181 return qc->priv->parseResolveInternalMemberAccess(mem, memberTypeInfo);
3185 return qc->priv->parseFindSelfMethod(mname);
3188 DLLLOCAL
static void parseAddMember(
QoreClass& qc,
char* nme, ClassAccess access, QoreMemberInfo* mInfo) {
3189 qc.priv->parseAddMember(nme, access, mInfo);
3193 return qc->priv->evalPseudoMethod(n, name, args, xsink);
3197 return qc->priv->evalPseudoMethod(m, variant, n, args, xsink);
3200 DLLLOCAL
static bool parseCheckPrivateClassAccess(
const QoreClass& qc,
const qore_class_private* oqc = parse_get_class_priv()) {
3201 return qc.priv->parseCheckPrivateClassAccess(oqc);
3204 DLLLOCAL
static bool runtimeCheckPrivateClassAccess(
const QoreClass& qc,
const qore_class_private* oqc = runtime_get_class()) {
3205 return qc.priv->runtimeCheckPrivateClassAccess(oqc);
3208 DLLLOCAL
static qore_type_result_e parseCheckCompatibleClass(
const QoreClass* qc,
const QoreClass* oc) {
3210 return QTI_NOT_EQUAL;
3211 return qc->priv->parseCheckCompatibleClass(*(oc->priv));
3214 DLLLOCAL
static qore_type_result_e runtimeCheckCompatibleClass(
const QoreClass& qc,
const QoreClass& oc) {
3215 return qc.priv->runtimeCheckCompatibleClass(*oc.priv);
3218 DLLLOCAL
static qore_class_private* get(
QoreClass& qc) {
3222 DLLLOCAL
static const qore_class_private* get(
const QoreClass& qc) {
3226 DLLLOCAL
static bool isPublic(
const QoreClass& qc) {
3227 return qc.priv->pub;
3230 DLLLOCAL
static bool isUserPublic(
const QoreClass& qc) {
3231 return qc.priv->pub && !qc.priv->sys;
3234 DLLLOCAL
static bool isFinal(
const QoreClass& qc) {
3235 return qc.priv->final;
3238 DLLLOCAL
static void setPublic(
QoreClass& qc) {
3239 qc.priv->setPublic();
3242 DLLLOCAL
static void setFinal(
QoreClass& qc) {
3243 assert(!qc.priv->final);
3244 qc.priv->final =
true;
3248 DLLLOCAL ~qore_class_private();
3251 class qore_class_private_holder {
3252 qore_class_private* c;
3255 DLLLOCAL qore_class_private_holder(
QoreClass* n_c) : c(qore_class_private::get(*n_c)) {
3258 DLLLOCAL qore_class_private_holder(qore_class_private* n_c) : c(n_c) {
3261 DLLLOCAL ~qore_class_private_holder() {
3263 c->deref(
true,
true);
3267 DLLLOCAL qore_class_private* operator*() {
3281 class qore_method_private {
3284 MethodFunctionBase* func;
3285 bool static_flag, all_user;
3287 DLLLOCAL qore_method_private(
const QoreClass* n_parent_class, MethodFunctionBase* n_func,
bool n_static) : parent_class(n_parent_class), func(n_func), static_flag(n_static), all_user(true) {
3288 assert(parent_class == n_func->getClass());
3291 DLLLOCAL ~qore_method_private() {
3295 DLLLOCAL
void setBuiltin() {
3300 DLLLOCAL
bool isUniquelyUser()
const {
3304 DLLLOCAL
bool isAbstract()
const {
3305 return func->isAbstract();
3308 DLLLOCAL
int addUserVariant(MethodVariantBase* variant) {
3309 return func->parseAddUserMethodVariant(variant);
3312 DLLLOCAL
void addBuiltinVariant(MethodVariantBase* variant) {
3314 func->addBuiltinMethodVariant(variant);
3317 DLLLOCAL MethodFunctionBase* getFunction()
const {
3318 return const_cast<MethodFunctionBase*
>(func);
3321 DLLLOCAL
const char* getName()
const {
3322 return func->getName();
3325 DLLLOCAL
const std::string& getNameStr()
const {
3326 return func->getNameStr();
3329 DLLLOCAL
void parseInit();
3331 DLLLOCAL
void parseInitStatic() {
3332 assert(static_flag);
3338 DLLLOCAL
const QoreTypeInfo* getUniqueReturnTypeInfo()
const {
3339 return func->getUniqueReturnTypeInfo();
3343 CONMF(func)->evalConstructor(variant, *parent_class,
self, args, parent_class->priv->scl, bceal, xsink);
3347 COPYMF(func)->evalCopy(*parent_class,
self, old, parent_class->priv->scl, xsink);
3351 COPYMF(func)->evalCopy(*parent_class,
self, old,
nullptr, xsink);
3354 DLLLOCAL
bool evalDeleteBlocker(
QoreObject*
self)
const {
3356 return self->evalDeleteBlocker(parent_class->priv->methodID,
reinterpret_cast<BuiltinDeleteBlocker*
>(func));
3360 DESMF(func)->evalDestructor(*parent_class,
self, xsink);
3365 DESMF(func)->evalDestructor(*parent_class,
self, xsink);
3368 DLLLOCAL
void evalSystemConstructor(
QoreObject*
self,
int code, va_list args)
const {
3369 BSYSCONB(func)->eval(*parent_class,
self, code, args);
3375 return NMETHF(func)->evalMethod(xsink, 0,
self, args, cctx);
3377 return SMETHF(func)->evalMethod(xsink, 0, args, cctx);
3383 return NMETHF(func)->evalMethodTmpArgs(xsink,
nullptr,
self, args, cctx);
3385 return SMETHF(func)->evalMethodTmpArgs(xsink,
nullptr, args, cctx);
3389 QORE_TRACE(
"qore_method_private::evalPseudoMethod()");
3391 assert(!static_flag);
3393 QoreValue rv = NMETHF(func)->evalPseudoMethod(xsink, variant, n, args);
3394 printd(5,
"qore_method_private::evalPseudoMethod() %s::%s() returning type: %s\n", parent_class->
getName(), getName(), rv.getTypeName());
3401 DLLLOCAL ClassAccess getAccess()
const;
3404 DLLLOCAL
static ClassAccess getAccess(
const QoreMethod& m) {
3405 return m.priv->getAccess();
3409 return m.priv->evalNormalVariant(
self, ev, args, xsink);
3413 return m.priv->evalPseudoMethod(variant, n, args, xsink);
3417 return m.priv->eval(xsink,
self, args, cctx);
3421 return m.priv->evalTmpArgs(xsink,
self, args, cctx);
3424 DLLLOCAL
static qore_method_private* get(
QoreMethod& m) {
3428 DLLLOCAL
static const qore_method_private* get(
const QoreMethod& m) {
3434 class PrivateIteratorBase {
3436 DLLLOCAL PrivateIteratorBase(
const T& obj) : obj(obj), i(obj.end()) {
3439 DLLLOCAL
bool next() {
3440 if (i == obj.end()) {
3446 return (i != obj.end());
3450 DLLLOCAL
bool valid()
const {
3451 return i != obj.end();
3456 typename T::const_iterator i;
3459 template <
class T,
class U>
3460 class PrivateMemberIteratorBase :
public PrivateIteratorBase<typename T::member_list_t> {
3462 DLLLOCAL PrivateMemberIteratorBase(
const typename T::member_list_t& obj) : PrivateIteratorBase<typename T::member_list_t>(obj) {
3465 DLLLOCAL
const U& getMember()
const {
3466 assert(this->valid());
3467 return *
reinterpret_cast<const U*
>(this->i->second.get());
3470 DLLLOCAL
const char* getName()
const {
3471 assert(this->valid());
3472 return this->i->first;