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() {
267 if (ROdereference()) {
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()), loc(old.loc), parseTypeInfo(old.parseTypeInfo ? new QoreParseTypeInfo(*old.parseTypeInfo) : nullptr) {
850 const QoreProgramLocation* loc;
851 QoreParseTypeInfo* parseTypeInfo;
853 DLLLOCAL QoreMemberInfoBase(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeinfo =
nullptr, QoreParseTypeInfo* n_parseTypeInfo =
nullptr,
QoreValue e =
QoreValue()) :
854 typeInfo(n_typeinfo), exp(e), loc(loc), parseTypeInfo(n_parseTypeInfo) {
857 DLLLOCAL ~QoreMemberInfoBase() {
861 DLLLOCAL
void del() {
864 delete parseTypeInfo;
865 parseTypeInfo =
nullptr;
869 DLLLOCAL
const QoreTypeInfo* getTypeInfo()
const {
873 DLLLOCAL
const QoreTypeInfo* parseGetTypeInfo()
const {
875 return QoreTypeInfo::isReference(typeInfo) ? anyTypeInfo : typeInfo;
879 DLLLOCAL
bool parseHasTypeInfo()
const {
880 return (typeInfo || parseTypeInfo);
884 class QoreMemberInfoBaseAccess :
public QoreMemberInfoBase {
888 DLLLOCAL QoreMemberInfoBaseAccess(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeinfo =
nullptr, QoreParseTypeInfo* n_parseTypeInfo =
nullptr,
QoreValue e =
QoreValue(), ClassAccess n_access = Public) :
889 QoreMemberInfoBase(loc, n_typeinfo, n_parseTypeInfo, e), access(n_access) {
892 DLLLOCAL ClassAccess getAccess()
const {
897 DLLLOCAL QoreMemberInfoBaseAccess(
const QoreMemberInfoBaseAccess& old, ClassAccess n_access) : QoreMemberInfoBase(old), access(old.access >= n_access ? old.access : n_access) {
904 typedef std::vector<const qore_class_private*> cls_vec_t;
907 typedef std::map<const qore_class_private*, const qore_class_private*> cls_context_map_t;
910 typedef std::deque<const QoreMemberInfo*> member_info_list_t;
915 class QoreMemberInfo :
public QoreMemberInfoBaseAccess {
916 friend class qore_class_private;
918 DLLLOCAL QoreMemberInfo(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeInfo =
nullptr, QoreParseTypeInfo* n_parseTypeInfo =
nullptr,
QoreValue e =
QoreValue(), ClassAccess n_access = Public,
const qore_class_private* qc =
nullptr) : QoreMemberInfoBaseAccess(loc, n_typeInfo, n_parseTypeInfo, e, n_access), is_local(true) {
920 cls_vec.push_back(qc);
925 DLLLOCAL QoreMemberInfo(
const QoreMemberInfo& old,
const qore_class_private* cls);
927 DLLLOCAL ~QoreMemberInfo() {
928 delete cls_context_map;
929 delete member_info_list;
932 DLLLOCAL
void setDeclaringClass(
const qore_class_private* qc) {
933 assert(cls_vec.empty());
934 cls_vec.push_back(qc);
939 DLLLOCAL
bool isLocalInternal()
const {
940 return is_local && access == Internal;
944 DLLLOCAL
bool local()
const {
949 DLLLOCAL
const qore_class_private* getClass()
const {
954 DLLLOCAL
const qore_class_private* getClassContext(
const qore_class_private* class_ctx)
const {
955 if (local() && class_ctx == getClass()) {
956 if (access == Internal) {
961 if (cls_context_map) {
962 cls_context_map_t::const_iterator i = cls_context_map->find(class_ctx);
963 if (i != cls_context_map->end()) {
971 DLLLOCAL
size_t getContextSize()
const {
972 return cls_context_map ? cls_context_map->size() : 0;
977 DLLLOCAL
void addContextAccess(
const QoreMemberInfo& mi);
981 DLLLOCAL
void addContextAccess(
const QoreMemberInfo& mi,
const qore_class_private* qc);
984 DLLLOCAL
size_t numParentMembers()
const {
985 return member_info_list ? member_info_list->size() : 0;
989 DLLLOCAL member_info_list_t::const_iterator initializationBegin()
const {
990 assert(member_info_list);
991 return member_info_list->begin();
995 DLLLOCAL member_info_list_t::const_iterator initializationEnd()
const {
996 assert(member_info_list);
997 return member_info_list->end();
1001 DLLLOCAL
void parseInit(
const char* name, LocalVar& selfid);
1004 DLLLOCAL
void setTransient() {
1005 assert(!is_transient);
1006 is_transient =
true;
1010 DLLLOCAL
bool getTransient()
const {
1011 return is_transient;
1018 cls_context_map_t* cls_context_map =
nullptr;
1020 member_info_list_t* member_info_list =
nullptr;
1025 is_transient =
false;
1037 DLLLOCAL QoreMemberInfo(
const QoreMemberInfo& old,
const qore_class_private* cls, ClassAccess cls_access);
1040 class QoreVarInfo :
public QoreMemberInfoBaseAccess {
1042 mutable QoreVarRWLock rwl;
1043 QoreLValueGeneric val;
1046 DLLLOCAL QoreVarInfo(
const QoreProgramLocation* loc,
const QoreTypeInfo* n_typeinfo =
nullptr, QoreParseTypeInfo* n_parseTypeInfo =
nullptr,
QoreValue e =
QoreValue(), ClassAccess n_access = Public) :
1047 QoreMemberInfoBaseAccess(loc, n_typeinfo, n_parseTypeInfo, e, n_access), finalized(false) {
1050 DLLLOCAL QoreVarInfo(
const QoreVarInfo& old, ClassAccess n_access = Public) : QoreMemberInfoBaseAccess(old, n_access), val(old.val), finalized(old.finalized) {
1053 DLLLOCAL ~QoreVarInfo() {
1054 assert(!val.hasValue());
1058 DLLLOCAL
void del() {
1059 assert(!val.hasValue());
1060 QoreMemberInfoBaseAccess::del();
1066 QoreAutoVarRWWriteLocker al(rwl);
1069 tmp = val.removeValue(
true);
1074 QoreMemberInfoBaseAccess::del();
1078 val.removeValue(
true).discard(xsink);
1083 val.set(getTypeInfo());
1084 return val.assignInitial(v);
1087 DLLLOCAL
void getLValue(LValueHelper& lvh) {
1088 lvh.setAndLock(rwl);
1089 if (checkFinalized(lvh.vl.xsink))
1091 lvh.setValue(val, getTypeInfo());
1094 DLLLOCAL
void init() {
1095 val.set(getTypeInfo());
1098 discard(val.assignInitial(QoreTypeInfo::getDefaultQoreValue(typeInfo)),
nullptr);
1102 DLLLOCAL
QoreValue getReferencedValue()
const {
1103 QoreAutoVarRWReadLocker al(rwl);
1104 return val.getReferencedValue();
1107 DLLLOCAL
int64 getAsBigInt()
const {
1108 QoreAutoVarRWReadLocker al(rwl);
1109 return val.getAsBigInt();
1112 DLLLOCAL
double getAsFloat()
const {
1113 QoreAutoVarRWReadLocker al(rwl);
1114 return val.getAsFloat();
1117 DLLLOCAL
bool getAsBool()
const {
1118 QoreAutoVarRWReadLocker al(rwl);
1119 return val.getAsBool();
1122 DLLLOCAL
void parseInit(
const char* name);
1127 xsink->
raiseException(
"DESTRUCTOR-ERROR",
"illegal class static variable assignment after second phase of variable destruction");
1134 template <
typename T>
1135 class QoreMemberMapBase {
1137 typedef std::pair<char*, std::unique_ptr<T>> member_list_element_t;
1138 typedef std::deque<member_list_element_t> member_list_t;
1139 typedef typename member_list_t::iterator iterator;
1140 typedef typename member_list_t::const_iterator const_iterator;
1141 member_list_t member_list;
1143 DLLLOCAL ~QoreMemberMapBase() {
1144 for (
auto& i : member_list) {
1149 member_list.clear();
1152 DLLLOCAL
bool inList(
const char* name)
const {
1153 return (
bool)find(name);
1156 DLLLOCAL T* find(
const char* name)
const {
1157 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); });
1158 return i == member_list.end() ? nullptr : i->second.get();
1161 DLLLOCAL
bool empty()
const {
1162 return member_list.empty();
1165 DLLLOCAL
void addNoCheck(
char* name, T* info) {
1168 assert(!inList(name));
1169 member_list.push_back(std::make_pair(name, std::unique_ptr<T>(info)));
1172 DLLLOCAL
void addNoCheck(std::pair<char*, T*> pair) {
1173 addNoCheck(pair.first, pair.second);
1176 DLLLOCAL
void moveAllTo(QoreMemberMapBase<T>& dest) {
1177 dest.member_list.insert(dest.member_list.end(), member_list.begin(), member_list.end());
1178 member_list.clear();
1181 DLLLOCAL
size_t size()
const {
1182 return member_list.size();
1186 class QoreMemberMap :
public QoreMemberMapBase<QoreMemberInfo> {
1188 using QoreMemberMapBase<QoreMemberInfo>::moveAllTo;
1189 DLLLOCAL
void moveAllTo(
QoreClass* qc, ClassAccess access);
1191 using QoreMemberMapBase<QoreMemberInfo>::addNoCheck;
1192 DLLLOCAL
void addNoCheck(
char* name, QoreMemberInfo* info) {
1193 assert(info->getClass());
1194 QoreMemberMapBase<QoreMemberInfo>::addNoCheck(name, info);
1197 DLLLOCAL
void addInheritedNoCheck(
char* name, QoreMemberInfo* info) {
1200 assert(!inList(name));
1201 member_list.insert(member_list.begin(), std::make_pair(name, std::unique_ptr<QoreMemberInfo>(info)));
1204 DLLLOCAL
void parseInit(LocalVar& selfid);
1210 class QoreVarMap :
public QoreMemberMapBase<QoreVarInfo> {
1213 for (member_list_t::reverse_iterator i = member_list.rbegin(), e = member_list.rend(); i != e; ++i) {
1214 i->second->clear(xsink);
1219 for (member_list_t::reverse_iterator i = member_list.rbegin(), e = member_list.rend(); i != e; ++i) {
1220 i->second->delVar(xsink);
1224 member_list.clear();
1227 DLLLOCAL
void del() {
1228 for (member_list_t::reverse_iterator i = member_list.rbegin(), e = member_list.rend(); i != e; ++i) {
1229 assert(!i->second->val.hasValue());
1237 member_list.clear();
1240 DLLLOCAL
void clearNoFree() {
1241 member_list.clear();
1244 DLLLOCAL
void moveAllTo(
QoreClass* qc, ClassAccess access);
1256 class BCANode :
public FunctionCallBase {
1259 const QoreProgramLocation* loc;
1266 DLLLOCAL BCANode(NamedScope* n, QoreParseListNode* n_args,
const QoreProgramLocation* loc) : FunctionCallBase(n_args), loc(loc), ns(n), name(nullptr) {
1267 assert(loc->start_line > 0);
1271 DLLLOCAL BCANode(
char* n, QoreParseListNode* n_args,
const QoreProgramLocation* loc) : FunctionCallBase(n_args), loc(loc), ns(nullptr), name(n) {
1272 assert(loc->start_line > 0);
1275 DLLLOCAL ~BCANode() {
1282 DLLLOCAL
void parseInit(BCList* bcl,
const char* classname);
1285 typedef std::vector<BCANode*> bcalist_t;
1291 class BCAList :
public bcalist_t {
1293 DLLLOCAL BCAList(BCANode* n) {
1297 DLLLOCAL ~BCAList() {
1298 for (bcalist_t::iterator i = begin(), e = end(); i != e; ++i)
1303 DLLLOCAL
int execBaseClassConstructorArgs(BCEAList* bceal,
ExceptionSink* xsink)
const;
1306 typedef std::pair<QoreClass*, bool> class_virt_pair_t;
1308 typedef std::vector<class_virt_pair_t> class_list_t;
1311 hashdecl member_init_entry_t {
1313 const QoreMemberInfo* info;
1314 const qore_class_private* member_class_ctx;
1316 DLLLOCAL member_init_entry_t(
const char* name,
const QoreMemberInfo* info,
const qore_class_private* member_class_ctx) :
1317 name(name), info(info), member_class_ctx(member_class_ctx) {
1322 typedef std::vector<member_init_entry_t> member_init_list_t;
1327 class BCSMList :
public class_list_t {
1329 DLLLOCAL BCSMList() {
1332 DLLLOCAL BCSMList(
const BCSMList &old);
1334 DLLLOCAL ~BCSMList();
1336 DLLLOCAL
void processMemberInitializationList(
const QoreMemberMap& members, member_init_list_t& member_init_list);
1339 DLLLOCAL
int addBaseClassesToSubclass(
QoreClass* thisclass,
QoreClass* sc,
bool is_virtual);
1341 DLLLOCAL
void alignBaseClassesInSubclass(
QoreClass* thisclass,
QoreClass* child,
bool is_virtual);
1353 DLLLOCAL
void resolveCopy();
1357 typedef vector_set_t<qore_class_private*> qcp_set_t;
1365 const QoreProgramLocation* loc;
1370 bool is_virtual : 1;
1372 DLLLOCAL BCNode(
const QoreProgramLocation* loc, NamedScope* c, ClassAccess a) : loc(loc), cname(c), cstr(nullptr), sclass(nullptr), access(a), is_virtual(false) {
1376 DLLLOCAL BCNode(
const QoreProgramLocation* loc,
char* str, ClassAccess a) : loc(loc), cname(0), cstr(str), sclass(nullptr), access(a), is_virtual(false) {
1380 DLLLOCAL BCNode(
const QoreProgramLocation* loc,
QoreClass* qc,
bool n_virtual =
false)
1381 : loc(loc), cname(nullptr), cstr(nullptr), sclass(qc), access(Public), is_virtual(n_virtual) {
1385 DLLLOCAL BCNode(
const BCNode &old) : loc(old.loc), cname(nullptr), cstr(nullptr), sclass(old.sclass), access(old.access), is_virtual(old.is_virtual) {
1391 DLLLOCAL ~BCNode() {
1397 DLLLOCAL ClassAccess getAccess()
const {
return access; }
1400 DLLLOCAL
int initializeHierarchy(
QoreClass* cls, qcp_set_t& qcp_set);
1402 DLLLOCAL
void initializeMembers(
QoreClass* cls);
1405 DLLLOCAL
int initialize(
QoreClass* cls,
bool& has_delete_blocker);
1407 DLLLOCAL
bool isBaseClass(
QoreClass* qc,
bool toplevel)
const;
1409 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethod(
const char* name, ClassAccess& n_access,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1410 DLLLOCAL
const QoreMethod* runtimeFindCommittedStaticMethod(
const char* name, ClassAccess& n_access,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1412 DLLLOCAL
bool runtimeIsPrivateMember(
const char* str,
bool toplevel)
const;
1416 DLLLOCAL
const QoreMemberInfo* parseFindMember(
const char* mem,
const qore_class_private*& qc, ClassAccess& n_access,
bool toplevel)
const;
1417 DLLLOCAL
const QoreVarInfo* parseFindVar(
const char* name,
const qore_class_private*& qc, ClassAccess& n_access,
bool toplevel)
const;
1419 DLLLOCAL
const QoreClass* findInHierarchy(
const qore_class_private& qc);
1422 DLLLOCAL
const QoreClass* getClass(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const;
1423 DLLLOCAL
const QoreClass* parseGetClass(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const;
1424 DLLLOCAL
bool inHierarchy(
const qore_class_private& qc, ClassAccess& n_access)
const;
1427 DLLLOCAL
const QoreMethod* parseFindNormalMethod(
const char* name,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1430 DLLLOCAL
const QoreMethod* parseFindStaticMethod(
const char* name,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1433 DLLLOCAL
const QoreMethod* parseResolveSelfMethod(
const QoreProgramLocation* loc,
const char* name,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1435 DLLLOCAL
bool parseCheckHierarchy(
const QoreClass* cls, ClassAccess& n_access,
bool toplevel)
const;
1437 DLLLOCAL QoreVarInfo* parseFindStaticVar(
const char* vname,
const QoreClass*& qc, ClassAccess& n_access,
bool check,
bool toplevel)
const;
1439 DLLLOCAL
QoreValue parseFindConstantValue(
const char* cname,
const QoreTypeInfo*& typeInfo,
bool &found,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1441 DLLLOCAL
int addBaseClassesToSubclass(
QoreClass* child,
bool is_virtual);
1443 DLLLOCAL
void initializeBuiltin();
1446 typedef std::vector<BCNode*> bclist_t;
1454 class BCList :
public bclist_t {
1460 bool rescanned =
false;
1462 DLLLOCAL BCList(BCNode* n) {
1469 DLLLOCAL BCList(
const BCList& old) : sml(old.sml) {
1471 reserve(old.size());
1472 for (bclist_t::const_iterator i = old.begin(), e = old.end(); i != e; ++i)
1473 push_back(
new BCNode(*(*i)));
1476 DLLLOCAL ~BCList() {
1477 for (bclist_t::iterator i = begin(), e = end(); i != e; ++i)
1481 DLLLOCAL
int initializeHierarchy(
QoreClass* thisclass, qcp_set_t& qcp_set);
1483 DLLLOCAL
void initializeMembers(
QoreClass* thisclass);
1485 DLLLOCAL
int initialize(
QoreClass* thisclass,
bool& has_delete_blocker);
1488 DLLLOCAL
const QoreMethod* parseResolveSelfMethod(
const QoreProgramLocation* loc,
const char* name,
const qore_class_private* class_ctx,
bool allow_internal);
1491 DLLLOCAL
const QoreMethod* parseFindNormalMethod(
const char* name,
const qore_class_private* class_ctx,
bool allow_internal);
1493 DLLLOCAL
const QoreMethod* parseFindStaticMethod(
const char* name,
const qore_class_private* class_ctx,
bool allow_internal);
1495 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethod(
const char* name, ClassAccess& access,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1496 DLLLOCAL
const QoreMethod* runtimeFindCommittedStaticMethod(
const char* name, ClassAccess& access,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1498 DLLLOCAL
bool match(
const QoreClass* cls);
1502 DLLLOCAL
bool runtimeIsPrivateMember(
const char* str,
bool toplevel)
const;
1504 DLLLOCAL
bool parseCheckHierarchy(
const QoreClass* cls, ClassAccess& access,
bool toplevel)
const;
1506 DLLLOCAL
const QoreMemberInfo* parseFindMember(
const char* mem,
const qore_class_private*& qc, ClassAccess& n_access,
bool toplevel)
const;
1508 DLLLOCAL
const QoreVarInfo* parseFindVar(
const char* vname,
const qore_class_private*& qc, ClassAccess& access,
bool toplevel)
const;
1510 DLLLOCAL
bool parseHasPublicMembersInHierarchy()
const;
1512 DLLLOCAL
const QoreClass* findInHierarchy(
const qore_class_private& qc);
1515 DLLLOCAL
const QoreClass* getClass(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const;
1517 DLLLOCAL
const QoreClass* parseGetClass(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const;
1518 DLLLOCAL
bool inHierarchy(
const qore_class_private& qc, ClassAccess& n_access)
const;
1520 DLLLOCAL
void addNewAncestors(
QoreMethod* m);
1522 DLLLOCAL
void addNewStaticAncestors(
QoreMethod* m);
1523 DLLLOCAL
void addStaticAncestors(
QoreMethod* m);
1524 DLLLOCAL
void parseAddAncestors(
QoreMethod* m);
1525 DLLLOCAL
void parseAddStaticAncestors(
QoreMethod* m);
1527 DLLLOCAL
void parseResolveAbstract();
1529 DLLLOCAL
QoreValue parseFindConstantValue(
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found,
const qore_class_private* class_ctx,
bool allow_internal)
const;
1531 DLLLOCAL QoreVarInfo* parseFindStaticVar(
const char* vname,
const QoreClass*& qc, ClassAccess& access,
bool check,
bool toplevel)
const;
1533 DLLLOCAL
void resolveCopy();
1535 DLLLOCAL MethodVariantBase* matchNonAbstractVariant(
const std::string& name, MethodVariantBase* v)
const;
1537 DLLLOCAL
bool isBaseClass(
QoreClass* qc,
bool toplevel)
const;
1539 DLLLOCAL
int addBaseClassesToSubclass(
QoreClass* thisparent,
QoreClass* child,
bool is_virtual) {
1540 for (
auto& i : *
this) {
1541 if ((*i).addBaseClassesToSubclass(child, is_virtual))
1544 return sml.addBaseClassesToSubclass(thisparent, child, is_virtual);
1547 DLLLOCAL
void rescanParents(
QoreClass* cls);
1549 DLLLOCAL
void initializeBuiltin() {
1550 for (
auto& i : *
this) {
1551 (*i).initializeBuiltin();
1560 const QoreProgramLocation* loc;
1562 const AbstractQoreFunctionVariant* variant =
nullptr;
1563 bool execed =
false;
1564 bool member_init_done =
false;
1566 DLLLOCAL BCEANode(
const QoreProgramLocation* loc,
QoreListNode* args,
const AbstractQoreFunctionVariant* variant) : loc(loc), args(args), variant(reinterpret_cast<const MethodVariant*>(variant)) {
1569 DLLLOCAL BCEANode(
bool n_execed =
true,
bool mid =
true) : execed(n_execed), member_init_done(mid) {
1582 typedef vector_map_t<qore_classid_t, BCEANode*> bceamap_t;
1588 class BCEAList :
public bceamap_t {
1590 DLLLOCAL ~BCEAList() {
1598 DLLLOCAL
QoreListNode* findArgs(
qore_classid_t classid,
bool* aexeced,
const AbstractQoreFunctionVariant*& variant,
const QoreProgramLocation*& loc);
1615 hashdecl SelfInstantiatorHelper {
1617 DLLLOCAL SelfInstantiatorHelper(LocalVar* n_selfid,
QoreObject*
self) : selfid(n_selfid) {
1618 selfid->instantiateSelf(
self);
1620 DLLLOCAL ~SelfInstantiatorHelper() {
1621 selfid->uninstantiateSelf();
1629 class SignatureHash {
1631 unsigned char buf[SH_SIZE];
1636 DLLLOCAL
void clearHash() {
1637 memset(buf, 0, SH_SIZE);
1640 DLLLOCAL
void copyHash(
const SignatureHash& other) {
1641 memcpy(buf, other.buf, SH_SIZE);
1645 DLLLOCAL SignatureHash() : is_set(false) {
1649 DLLLOCAL SignatureHash(
const SignatureHash& old) : is_set(old.is_set) {
1656 DLLLOCAL
void updateEmpty() {
1662 DLLLOCAL
bool operator==(
const SignatureHash& other)
const {
1664 if (!is_set || !other.is_set)
1666 return !memcmp(buf, other.buf, SH_SIZE);
1669 DLLLOCAL SignatureHash& operator=(
const SignatureHash& other) {
1670 if (!other.is_set) {
1682 DLLLOCAL
operator bool()
const {
1687 DLLLOCAL
void toString(
QoreString& str)
const {
1688 for (
unsigned i = 0; i < SH_SIZE; ++i)
1692 DLLLOCAL
char* getHash()
const {
1697 DLLLOCAL
void clear() {
1705 #define QCCM_NORMAL (1 << 0) 1706 #define QCCM_STATIC (1 << 1) 1709 typedef vector_set_t<QoreClass*> qc_set_t;
1714 class qore_class_private {
1716 const QoreProgramLocation* loc;
1719 qore_ns_private* ns =
nullptr;
1720 BCList* scl =
nullptr;
1723 mutable VRMutex gate;
1728 AbstractMethodMap ahm;
1730 ConstantList constlist;
1733 QoreMemberMap members;
1735 member_init_list_t member_init_list;
1740 const QoreMethod* system_constructor =
nullptr,
1741 * constructor =
nullptr,
1742 * destructor =
nullptr,
1743 * copyMethod =
nullptr,
1744 * methodGate =
nullptr,
1745 * memberGate =
nullptr,
1746 * deleteBlocker =
nullptr,
1747 * memberNotification =
nullptr;
1759 parse_init_called : 1,
1760 parse_init_partial_called : 1,
1761 has_delete_blocker : 1,
1762 has_public_memdecl : 1,
1763 pending_has_public_memdecl : 1,
1765 resolve_copy_done : 1,
1766 has_new_user_changes : 1,
1767 has_sig_changes : 1,
1768 owns_ornothingtypeinfo : 1,
1774 parse_resolve_hierarchy : 1,
1775 parse_resolve_class_members : 1,
1776 parse_resolve_abstract : 1,
1777 has_transient_member : 1
1785 unsigned num_methods, num_user_methods, num_static_methods, num_static_user_methods;
1789 QoreTypeInfo* typeInfo,
1792 const qore_class_private* injectedClass =
nullptr;
1795 mutable LocalVar selfid;
1801 const void* ptr =
nullptr;
1813 bool deref_source_program =
true;
1816 std::string from_module;
1818 DLLLOCAL qore_class_private(
QoreClass* n_cls, std::string&& nme,
int64 dom =
QDOM_DEFAULT, QoreTypeInfo* n_typeinfo =
nullptr);
1822 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);
1825 DLLLOCAL
const char* getModuleName()
const {
1826 return from_module.empty() ? nullptr : from_module.c_str();
1829 DLLLOCAL
void pgmRef()
const {
1835 DLLLOCAL
void ref()
const {
1839 DLLLOCAL
bool deref(
bool ns_const,
bool ns_vars,
bool in_del =
false) {
1842 if (!constlist.empty()) {
1843 constlist.deleteAll(
nullptr);
1848 if (!vars.empty()) {
1855 cls->priv =
nullptr;
1861 for (
auto& i : qcset) {
1872 DLLLOCAL
bool hasAbstract()
const {
1873 return !ahm.empty();
1876 DLLLOCAL
int runtimeCheckInstantiateClass(
ExceptionSink* xsink)
const {
1877 return ahm.runtimeCheckInstantiateClass(name.c_str(), xsink);
1880 DLLLOCAL
void parseCheckAbstractNew(
const QoreProgramLocation* loc)
const;
1882 DLLLOCAL
void parseDoCheckAbstractNew(
const QoreProgramLocation* loc)
const {
1883 ahm.parseCheckAbstractNew(loc, name.c_str());
1886 DLLLOCAL
void setNamespace(qore_ns_private* n) {
1892 DLLLOCAL
bool setNamespaceConditional(qore_ns_private* n) {
1902 DLLLOCAL
void updateNamespace(qore_ns_private* n) {
1907 DLLLOCAL
void resolveCopy();
1909 DLLLOCAL
void setUserData(
const void* n_ptr) {
1914 DLLLOCAL
const void* getUserData()
const {
1927 DLLLOCAL
const QoreTypeInfo* getTypeInfo()
const {
1931 DLLLOCAL
const QoreTypeInfo* getOrNothingTypeInfo()
const {
1932 return orNothingTypeInfo;
1935 DLLLOCAL
bool runtimeIsPrivateMemberIntern(
const char* str,
bool toplevel)
const;
1937 DLLLOCAL
void parseImportMembers(qore_class_private& qc, ClassAccess access);
1939 DLLLOCAL
bool parseHasMemberGate()
const {
1940 return memberGate || hm.find(
"memberGate") != hm.end();
1943 DLLLOCAL
bool parseHasMethodGate()
const {
1944 return methodGate || hm.find(
"methodGate") != hm.end();
1948 DLLLOCAL
bool checkAssignSpecialIntern(
const QoreMethod* m) {
1950 if (!methodGate && !strcmp(m->
getName(),
"methodGate")) {
1955 if (!memberGate && !strcmp(m->
getName(),
"memberGate")) {
1961 if (!memberNotification && !strcmp(m->
getName(),
"memberNotification")) {
1962 memberNotification = m;
1970 DLLLOCAL
bool checkSpecialStaticIntern(
const char* mname) {
1972 if ((!methodGate && !strcmp(mname,
"methodGate"))
1973 || (!memberGate && !strcmp(mname,
"memberGate"))
1974 || (!memberNotification && !strcmp(mname,
"memberNotification")))
1980 DLLLOCAL
bool checkSpecial(
const char* mname) {
1982 if ((!methodGate && !strcmp(mname,
"methodGate"))
1983 || (!memberGate && !strcmp(mname,
"memberGate"))
1984 || (!memberNotification && !strcmp(mname,
"memberNotification"))
1985 || (!constructor && !strcmp(mname,
"constructor"))
1986 || (!destructor && !strcmp(mname,
"destructor"))
1987 || (!copyMethod && !strcmp(mname,
"copy")))
1993 DLLLOCAL
bool checkAssignSpecial(
const QoreMethod* m) {
1995 if (!constructor && !strcmp(m->
getName(),
"constructor")) {
2000 if (!destructor && !strcmp(m->
getName(),
"destructor")) {
2005 if (!copyMethod && !strcmp(m->
getName(),
"copy")) {
2010 return checkAssignSpecialIntern(m);
2014 DLLLOCAL
void mergeAbstract();
2017 DLLLOCAL
int initializeIntern();
2018 DLLLOCAL
int initializeHierarchy(qcp_set_t& qcp_set);
2019 DLLLOCAL
void initializeMembers();
2020 DLLLOCAL
void initialize();
2022 DLLLOCAL
void parseInitPartial();
2023 DLLLOCAL
void parseInitPartialIntern();
2025 DLLLOCAL
int parseCheckMemberAccess(
const QoreProgramLocation* loc,
const char* mem,
const QoreTypeInfo*& memberTypeInfo,
int pflag)
const {
2026 const_cast<qore_class_private*
>(
this)->parseInitPartial();
2028 const qore_class_private* qc =
nullptr;
2030 const QoreMemberInfo* omi = parseFindMember(mem, qc, access);
2034 if (!parseHasMemberGate() || (pflag & PF_FOR_ASSIGNMENT)) {
2036 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",
2040 if (parseHasPublicMembersInHierarchy()) {
2042 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());
2049 memberTypeInfo = omi->getTypeInfo();
2052 if ((access > Public) && !parseHasMemberGate() && !parseCheckPrivateClassAccess()) {
2054 parse_error(*loc,
"illegal access to private member '%s' of class '%s'", mem, name.c_str());
2060 DLLLOCAL
int parseResolveInternalMemberAccess(
const char* mem,
const QoreTypeInfo*& memberTypeInfo)
const {
2061 const_cast<qore_class_private*
>(
this)->parseInitPartial();
2063 const qore_class_private* qc =
nullptr;
2065 const QoreMemberInfo* omi = parseFindMember(mem, qc, access);
2067 memberTypeInfo = omi->getTypeInfo();
2070 return omi ? 0 : -1;
2073 DLLLOCAL
int parseCheckInternalMemberAccess(
const char* mem,
const QoreTypeInfo*& memberTypeInfo,
const QoreProgramLocation* loc)
const {
2074 const_cast<qore_class_private*
>(
this)->parseInitPartial();
2077 const qore_class_private* qc =
nullptr;
2079 const QoreMemberInfo* omi = parseFindMember(mem, qc, access);
2084 const_cast<QoreMemberInfo*
>(omi)->parseInit(mem, selfid);
2085 memberTypeInfo = omi->parseGetTypeInfo();
2091 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());
2094 if (parseHasPublicMembersInHierarchy()) {
2095 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());
2102 DLLLOCAL
bool parseHasPublicMembersInHierarchy()
const {
2103 if (has_public_memdecl || pending_has_public_memdecl)
2106 return scl ? scl->parseHasPublicMembersInHierarchy() :
false;
2116 DLLLOCAL
const qore_class_private* runtimeGetMemberContext(
const char* mem,
const qore_class_private* class_ctx)
const {
2117 const QoreMemberInfo* info = runtimeGetMemberInfo(mem, class_ctx);
2119 return info ? info->getClassContext(class_ctx) :
nullptr;
2122 DLLLOCAL
bool runtimeIsMemberInternal(
const char* mem)
const {
2123 QoreMemberInfo* info = members.find(mem);
2124 return info && info->isLocalInternal() ? true :
false;
2137 DLLLOCAL
const QoreMemberInfo* runtimeGetMemberInfo(
const char* mem,
const qore_class_private* class_ctx)
const {
2138 QoreMemberInfo* info;
2140 info = class_ctx->members.find(mem);
2141 if (info && info->isLocalInternal()) {
2149 if (class_ctx !=
this) {
2150 info = members.find(mem);
2153 if (info && info->access == Inaccessible && !info->getClassContext(class_ctx)) {
2160 DLLLOCAL
const QoreMemberInfo* parseFindMember(
const char* mem,
const qore_class_private*& qc, ClassAccess& access)
const {
2162 const_cast<qore_class_private*
>(
this)->initialize();
2163 return parseFindMemberNoInit(mem, qc, access,
true);
2169 DLLLOCAL
const QoreMemberInfo* parseFindMemberNoInit(
const char* mem,
const qore_class_private*& qc, ClassAccess& access,
bool toplevel)
const {
2170 const QoreMemberInfo* mi = members.find(mem);
2172 ClassAccess ma = mi->getAccess();
2173 if (toplevel || ma != Internal) {
2177 qc = mi->getClass();
2182 return scl ? scl->parseFindMember(mem, qc, access,
true) : 0;
2185 DLLLOCAL
const QoreVarInfo* parseFindVar(
const char* vname,
const qore_class_private*& qc, ClassAccess& access,
bool toplevel)
const {
2188 QoreVarInfo* vi = vars.find(const_cast<char*>(vname));
2192 access = vi->getAccess();
2196 return scl ? scl->parseFindVar(vname, qc, access, toplevel) :
nullptr;
2199 DLLLOCAL
int parseCheckClassHierarchyMembers(
const char* mname,
const QoreMemberInfo& l_mi,
const QoreMemberInfo& b_mi)
const;
2201 DLLLOCAL
int checkExistingVarMember(
const char* dname,
const QoreMemberInfoBaseAccess* mi,
const QoreMemberInfoBaseAccess* omi,
const qore_class_private* qc, ClassAccess oaccess,
bool var =
false)
const;
2203 DLLLOCAL
int parseCheckVar(
const char* dname,
const QoreVarInfo* vi)
const {
2204 const qore_class_private* qc = 0;
2206 const QoreVarInfo* ovi = parseFindVar(dname, qc, access,
true);
2209 if (parseHasConstant(dname)) {
2210 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());
2216 return checkExistingVarMember(dname, vi, ovi, qc, access,
true);
2219 DLLLOCAL
int parseCheckMember(
const char* mem,
const QoreMemberInfo* mi)
const {
2220 const qore_class_private* qc =
nullptr;
2221 ClassAccess access = Public;
2222 const QoreMemberInfo* omi = parseFindMemberNoInit(mem, qc, access,
true);
2227 return checkExistingVarMember(mem, mi, omi, qc, omi->access);
2230 DLLLOCAL
int parseCheckMemberInBaseClasses(
const char* mem,
const QoreMemberInfo* mi)
const {
2231 const qore_class_private* qc =
nullptr;
2232 ClassAccess access = Public;
2235 const QoreMemberInfo* omi = scl ? scl->parseFindMember(mem, qc, access,
false) :
nullptr;
2236 if (!omi || (omi->getClass() == mi->getClass())) {
2240 return checkExistingVarMember(mem, mi, omi, qc, omi->access);
2243 DLLLOCAL
int parseCheckSystemCommitted(
const QoreProgramLocation* loc) {
2245 parse_error(*loc,
"cannot modify system class '%s'", name.c_str());
2249 parse_error(*loc,
"cannot modify user class '%s' once it's been committed", name.c_str());
2255 DLLLOCAL
void parseAddMember(
char* mem, ClassAccess access, QoreMemberInfo* memberInfo) {
2256 memberInfo->access = access;
2257 if (!parseCheckSystemCommitted(memberInfo->loc) && !parseCheckMember(mem, memberInfo)) {
2258 if (!has_new_user_changes) {
2259 has_new_user_changes =
true;
2261 if (!has_sig_changes) {
2262 has_sig_changes =
true;
2264 memberInfo->setDeclaringClass(
this);
2265 if (!has_transient_member && memberInfo->getTransient()) {
2266 has_transient_member =
true;
2269 members.addNoCheck(mem, memberInfo);
2277 DLLLOCAL
void parseAddStaticVar(
char* dname, ClassAccess access, QoreVarInfo* VarInfo) {
2278 VarInfo->access = access;
2279 if (!parseCheckSystemCommitted(VarInfo->loc) && !parseCheckVar(dname, VarInfo)) {
2280 if (!has_new_user_changes) {
2281 has_new_user_changes =
true;
2283 if (!has_sig_changes) {
2284 has_sig_changes =
true;
2288 vars.addNoCheck(dname, VarInfo);
2296 DLLLOCAL
void addBuiltinConstant(
const char* cname,
QoreValue value, ClassAccess access = Public,
const QoreTypeInfo* cTypeInfo =
nullptr) {
2297 assert(!constlist.inList(cname));
2299 sys = committed =
true;
2301 constlist.add(cname, value, cTypeInfo, access);
2304 DLLLOCAL
void addBuiltinStaticVar(
const char* vname,
QoreValue value, ClassAccess access = Public,
const QoreTypeInfo* vTypeInfo =
nullptr);
2306 DLLLOCAL
void parseAssimilateConstants(ConstantList &cmap, ClassAccess access) {
2307 assert(!sys && !committed);
2308 if (!has_new_user_changes)
2309 has_new_user_changes =
true;
2310 if (!has_sig_changes)
2311 has_sig_changes =
true;
2314 cmap.setAccess(access);
2315 constlist.assimilate(cmap,
"class", name.c_str());
2318 DLLLOCAL
void parseAddConstant(
const QoreProgramLocation* loc,
const std::string &cname,
QoreValue val, ClassAccess access) {
2320 if (parseCheckSystemCommitted(loc)) {
2323 if (parseHasVar(cname.c_str())) {
2324 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());
2327 if (!has_new_user_changes)
2328 has_new_user_changes =
true;
2329 if (!has_sig_changes)
2330 has_sig_changes =
true;
2334 constlist.parseAdd(loc, cname, val_holder.release(), access, name.c_str());
2337 DLLLOCAL
bool parseHasVar(
const char* vn) {
2338 return vars.inList(vn);
2341 DLLLOCAL
bool parseHasConstant(
const std::string &cname)
const {
2342 return constlist.inList(cname);
2345 DLLLOCAL
QoreValue parseFindLocalConstantValue(
const char* cname,
const QoreTypeInfo*& cTypeInfo,
bool& found) {
2349 ClassAccess access = Public;
2350 QoreValue rv = constlist.find(cname, cTypeInfo, access, found);
2353 if (found && (access > Public)) {
2354 qore_class_private* class_ctx = parse_get_class_priv();
2355 if ((access == Internal && class_ctx !=
this) || !parseCheckPrivateClassAccess(class_ctx)) {
2357 cTypeInfo =
nullptr;
2366 DLLLOCAL
QoreValue parseFindConstantValue(
const char* cname,
const QoreTypeInfo*& cTypeInfo,
bool& found,
const qore_class_private* class_ctx) {
2368 return parseFindConstantValueIntern(cname, cTypeInfo, found, class_ctx);
2371 DLLLOCAL
QoreValue parseFindConstantValueIntern(
const char* cname,
const QoreTypeInfo*& cTypeInfo,
bool& found,
const qore_class_private* class_ctx) {
2375 ClassAccess access = Public;
2376 QoreValue rv = constlist.find(cname, cTypeInfo, access, found);
2380 if (access == Internal) {
2381 if (class_ctx ==
this)
2384 cTypeInfo =
nullptr;
2388 else if (access == Private && !parseCheckPrivateClassAccess(class_ctx)) {
2389 cTypeInfo =
nullptr;
2397 return scl ? scl->parseFindConstantValue(cname, cTypeInfo, found, class_ctx, class_ctx ==
this) :
QoreValue();
2400 DLLLOCAL QoreVarInfo* parseFindLocalStaticVar(
const char* vname)
const {
2401 QoreVarInfo* vi = vars.find(vname);
2403 if (vi && (vi->access > Public) && !parseCheckPrivateClassAccess())
2409 DLLLOCAL QoreVarInfo* parseFindStaticVar(
const char* vname,
const QoreClass*& qc, ClassAccess& access,
bool check =
false)
const {
2411 return parseFindStaticVarIntern(vname, qc, access, check,
true);
2414 DLLLOCAL QoreVarInfo* parseFindStaticVarIntern(
const char* vname,
const QoreClass*& qc, ClassAccess& access,
bool check,
bool toplevel)
const {
2415 QoreVarInfo* vi = vars.find(vname);
2418 ClassAccess va = vi->getAccess();
2419 if (toplevel || va != Internal) {
2425 if (check && (access > Public) && !parseCheckPrivateClassAccess()) {
2434 return scl ? scl->parseFindStaticVar(vname, qc, access, check, toplevel) :
nullptr;
2437 DLLLOCAL
void addMember(
const char* mem, ClassAccess access,
const QoreTypeInfo* n_typeinfo,
QoreValue initial_value) {
2438 assert(!members.inList(mem));
2439 if (!has_sig_changes) {
2440 has_sig_changes =
true;
2442 members.addNoCheck(strdup(mem),
new QoreMemberInfo(&loc_builtin, n_typeinfo,
nullptr, initial_value, access,
this));
2443 if (access == Public && !has_public_memdecl) {
2444 has_public_memdecl =
true;
2448 DLLLOCAL
void insertBuiltinStaticMethod(
QoreMethod* m) {
2453 ++num_static_methods;
2455 sys = committed =
true;
2458 assert(!checkSpecialStaticIntern(m->
getName()));
2460 addStaticAncestors(m);
2463 DLLLOCAL
void insertBuiltinMethod(
QoreMethod* m,
bool special_method =
false) {
2470 sys = committed =
true;
2473 if (!special_method && !checkAssignSpecialIntern(m))
2478 DLLLOCAL
void recheckBuiltinMethodHierarchy();
2480 DLLLOCAL
void addNewAncestors(
QoreMethod* m) {
2484 scl->addNewAncestors(m);
2487 DLLLOCAL
void addNewStaticAncestors(
QoreMethod* m) {
2491 scl->addNewStaticAncestors(m);
2494 DLLLOCAL
void addStaticAncestors(
QoreMethod* m) {
2498 scl->addStaticAncestors(m);
2502 assert(strcmp(m->
getName(),
"constructor"));
2507 scl->addAncestors(m);
2510 DLLLOCAL
void parseAddStaticAncestors(
QoreMethod* m) {
2514 scl->parseAddStaticAncestors(m);
2517 DLLLOCAL
void parseAddAncestors(
QoreMethod* m) {
2519 assert(strcmp(m->
getName(),
"constructor"));
2524 scl->parseAddAncestors(m);
2529 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;
2539 constlist.deleteAll(xsink);
2552 DLLLOCAL
void deleteClassData(
bool deref_vars,
ExceptionSink* xsink) {
2568 if (deref_source_program) {
2596 const qore_class_private* class_ctx,
ExceptionSink* xsink)
const;
2600 DLLLOCAL
void addBuiltinMethod(
const char* mname, MethodVariantBase* variant);
2601 DLLLOCAL
void addBuiltinStaticMethod(
const char* mname, MethodVariantBase* variant);
2602 DLLLOCAL
void addBuiltinConstructor(BuiltinConstructorVariantBase* variant);
2603 DLLLOCAL
void addBuiltinDestructor(BuiltinDestructorVariantBase* variant);
2604 DLLLOCAL
void addBuiltinCopyMethod(BuiltinCopyVariantBase* variant);
2606 DLLLOCAL
void setBuiltinSystemConstructor(BuiltinSystemConstructorBase* m);
2614 DLLLOCAL
QoreMethod* parseFindLocalMethod(
const char* nme) {
2615 hm_method_t::iterator i = hm.find(nme);
2616 return (i != hm.end()) ? i->second :
nullptr;
2619 DLLLOCAL
const QoreMethod* parseFindLocalMethod(
const char* nme)
const {
2620 hm_method_t::const_iterator i = hm.find(nme);
2621 return (i != hm.end()) ? i->second :
nullptr;
2624 DLLLOCAL
QoreMethod* parseFindLocalMethod(
const std::string& nme) {
2625 hm_method_t::iterator i = hm.find(nme);
2626 return (i != hm.end()) ? i->second :
nullptr;
2629 DLLLOCAL
const QoreMethod* parseFindLocalMethod(
const std::string& nme)
const {
2630 hm_method_t::const_iterator i = hm.find(nme);
2631 return (i != hm.end()) ? i->second :
nullptr;
2635 DLLLOCAL
const QoreMethod* parseFindAnyLocalMethod(
const char* nme)
const {
2636 const QoreMethod* m = parseFindLocalMethod(nme);
2637 return m ? m : parseFindLocalStaticMethod(nme);
2641 DLLLOCAL
QoreMethod* parseFindLocalStaticMethod(
const char* nme) {
2642 hm_method_t::iterator i = shm.find(nme);
2643 return (i != shm.end()) ? i->second :
nullptr;
2646 DLLLOCAL
const QoreMethod* parseFindLocalStaticMethod(
const char* nme)
const {
2647 hm_method_t::const_iterator i = shm.find(nme);
2648 return (i != shm.end()) ? i->second :
nullptr;
2652 DLLLOCAL
QoreMethod* findLocalCommittedMethod(
const char* nme);
2654 DLLLOCAL
const QoreMethod* findLocalCommittedMethod(
const char* nme)
const;
2657 DLLLOCAL
QoreMethod* findLocalCommittedStaticMethod(
const char* nme);
2659 DLLLOCAL
const QoreMethod* findLocalCommittedStaticMethod(
const char* nme)
const;
2661 DLLLOCAL
void finalizeBuiltin(
const char* nspath);
2662 DLLLOCAL
void generateBuiltinSignature(
const char* nspath);
2663 DLLLOCAL
void initializeBuiltin();
2669 DLLLOCAL
static const QoreMethod* doParseMethodAccess(
const QoreMethod* m,
const qore_class_private* class_ctx);
2671 DLLLOCAL
static const QoreMethod* doMethodAccess(
const QoreMethod* m, ClassAccess ma,
const qore_class_private* class_ctx) {
2673 return ((ma == Public) || ((ma == Private && class_ctx))) ? m :
nullptr;
2676 DLLLOCAL
static const QoreMethod* doMethodAccess(
const QoreMethod* m, ClassAccess& access, ClassAccess ma) {
2681 else if (access < ma)
2687 DLLLOCAL
const QoreMethod* doRuntimeMethodAccess(
const QoreMethod* m, ClassAccess& access, ClassAccess ma,
const qore_class_private* class_ctx)
const {
2690 if (ma == Internal && (!class_ctx || !equal(*class_ctx)))
2692 else if (access < ma)
2699 DLLLOCAL
const QoreMethod* parseFindNormalMethod(
const char* mname,
const qore_class_private* class_ctx);
2702 DLLLOCAL
const QoreMethod* parseFindStaticMethod(
const char* mname,
const qore_class_private* class_ctx);
2705 DLLLOCAL
const QoreMethod* parseFindNormalMethodIntern(
const char* mname,
const qore_class_private* class_ctx);
2708 DLLLOCAL
const QoreMethod* parseFindStaticMethodIntern(
const char* mname,
const qore_class_private* class_ctx);
2710 DLLLOCAL
const QoreMethod* parseResolveSelfMethodIntern(
const QoreProgramLocation* loc,
const char* nme,
const qore_class_private* class_ctx);
2714 DLLLOCAL
const QoreMethod* runtimeFindCommittedStaticMethodIntern(
const char* nme, ClassAccess& access,
const qore_class_private* class_ctx)
const {
2715 const QoreMethod* m = findLocalCommittedStaticMethod(nme);
2717 (class_ctx ==
this || doRuntimeMethodAccess(m, access, m->
getAccess(), class_ctx))) {
2724 return scl->runtimeFindCommittedStaticMethod(nme, access, class_ctx, class_ctx ==
this);
2729 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethodIntern(
const char* nme, ClassAccess& access,
const qore_class_private* class_ctx)
const {
2730 const QoreMethod* m = findLocalCommittedMethod(nme);
2733 (class_ctx ==
this || doRuntimeMethodAccess(m, access, m->
getAccess(), class_ctx))) {
2740 return scl->runtimeFindCommittedMethod(nme, access, class_ctx, class_ctx ==
this);
2743 DLLLOCAL
const QoreMethod* runtimeFindCommittedStaticMethod(
const char* nme, ClassAccess& access,
2744 const qore_class_private* class_ctx)
const;
2746 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethod(
const char* nme, ClassAccess& access,
2747 const qore_class_private* class_ctx)
const;
2749 DLLLOCAL
const QoreMethod* runtimeFindCommittedMethodForEval(
const char* nme, ClassAccess& access,
2750 const qore_class_private* class_ctx)
const;
2752 DLLLOCAL
const QoreMethod* runtimeFindAnyCommittedMethod(
const char* nme)
const {
2753 ClassAccess access = Public;
2754 const qore_class_private* class_ctx =
this;
2755 const QoreMethod* m = runtimeFindCommittedMethodIntern(nme, access, class_ctx);
2758 if (!strcmp(nme,
"constructor"))
2760 if (!strcmp(nme,
"destructor"))
2762 if (!strcmp(nme,
"copy"))
2764 if (!strcmp(nme,
"methodGate"))
2766 if (!strcmp(nme,
"memberGate"))
2768 if (!strcmp(nme,
"memberNotification"))
2769 return memberNotification;
2774 DLLLOCAL
const QoreMethod* findMethod(
const char* nme, ClassAccess& access)
const {
2775 CurrentProgramRuntimeParseContextHelper pch;
2776 const qore_class_private* class_ctx = runtime_get_class();
2777 if (class_ctx && !runtimeCheckPrivateClassAccess(class_ctx))
2778 class_ctx =
nullptr;
2779 return runtimeFindCommittedMethod(nme, access, class_ctx);
2782 DLLLOCAL
bool runtimeHasCallableMethod(
const char* m,
int mask)
const;
2792 DLLLOCAL
void parseInit();
2793 DLLLOCAL
void parseResolveHierarchy();
2794 DLLLOCAL
void parseResolveClassMembers();
2795 DLLLOCAL
void parseResolveAbstract();
2796 DLLLOCAL
void parseCommit();
2798 DLLLOCAL
void parseRollback();
2799 DLLLOCAL
int addUserMethod(
const char* mname, MethodVariantBase* f,
bool n_static);
2800 DLLLOCAL
void addLocalMembersForInit();
2809 const qore_class_private* class_ctx = runtime_get_class();
2810 if (class_ctx && !runtimeCheckPrivateClassAccess(class_ctx))
2811 class_ctx =
nullptr;
2813 if (!(w = runtimeFindCommittedMethod(nme, access, class_ctx))) {
2817 const char* cname = n.get<
const QoreObject>()->getClassName();
2818 xsink->
raiseException(
"METHOD-DOES-NOT-EXIST",
"no method %s::%s() or pseudo-method %s::%s() is available", cname, nme, name.c_str(), nme);
2821 xsink->
raiseException(
"PSEUDO-METHOD-DOES-NOT-EXIST",
"no pseudo method <%s>::%s() has been defined", n.getTypeName(), nme);
2828 DLLLOCAL
bool parseCheckPrivateClassAccess(
const qore_class_private* qc = parse_get_class_priv())
const;
2829 DLLLOCAL
bool runtimeCheckPrivateClassAccess(
const qore_class_private* qc = runtime_get_class())
const;
2832 DLLLOCAL qore_type_result_e parseCheckCompatibleClass(
const qore_class_private& oc)
const {
2833 bool may_not_match =
false;
2834 qore_type_result_e rv = parseCheckCompatibleClass(oc, may_not_match);
2837 return QTI_NOT_EQUAL;
2841 DLLLOCAL qore_type_result_e parseCheckCompatibleClass(
const qore_class_private& oc,
bool& may_not_match)
const;
2842 DLLLOCAL qore_type_result_e parseCheckCompatibleClassIntern(
const qore_class_private& oc,
bool& may_not_match)
const;
2844 DLLLOCAL qore_type_result_e runtimeCheckCompatibleClass(
const qore_class_private& oc)
const;
2845 DLLLOCAL qore_type_result_e runtimeCheckCompatibleClassIntern(
const qore_class_private& oc)
const;
2848 DLLLOCAL
const QoreClass* findInHierarchy(
const qore_class_private& qc) {
2851 return scl ? scl->findInHierarchy(qc) :
nullptr;
2857 return scl ? scl->getClass(cid, n_access, toplevel) :
nullptr;
2860 DLLLOCAL
const QoreClass* getClass(
const qore_class_private& qc, ClassAccess& n_access)
const {
2862 return getClassIntern(qc, n_access,
true);
2865 DLLLOCAL
const QoreClass* getClassIntern(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const {
2870 if (qc.name == name) {
2873 qc.hash.toString(rh);
2874 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());
2878 return scl ? scl->getClass(qc, n_access, toplevel) :
nullptr;
2881 DLLLOCAL
const QoreClass* parseGetClassIntern(
const qore_class_private& qc, ClassAccess& n_access,
bool toplevel)
const {
2888 if (qc.name == name) {
2889 printd(5,
"qore_class_private::parseGetClassIntern() this: %p '%s' != '%s' scl: %p\n",
this, name.c_str(), qc.name.c_str(), scl);
2891 qc.parseShowHashes();
2895 return scl ? scl->parseGetClass(qc, n_access, toplevel) :
nullptr;
2898 DLLLOCAL
bool inHierarchy(
const qore_class_private& qc, ClassAccess& n_access)
const {
2903 return scl ? scl->inHierarchy(qc, n_access) :
false;
2907 DLLLOCAL
void parseShowHash()
const {
2910 printd(5,
" + %p %s committed: %s\n",
this, name.c_str(), ch.
getBuffer());
2914 DLLLOCAL
bool parseCheckEqualHash(
const qore_class_private& qc)
const {
2916 printd(5,
"qore_class_private::parseCheckEqualHash() %s == %s\n", name.c_str(), qc.name.c_str());
2920 return hash == qc.hash;
2923 DLLLOCAL
bool equal(
const qore_class_private& qc)
const {
2927 if (qc.classID == classID || (qc.name == name && qc.hash == hash))
2930 if (injectedClass && injectedClass->equal(qc))
2933 if (qc.injectedClass && equal(*qc.injectedClass))
2939 DLLLOCAL
bool parseEqual(
const qore_class_private& qc)
const {
2943 if (qc.classID == classID || (qc.name == name && parseCheckEqualHash(qc)))
2946 if (injectedClass && injectedClass->parseEqual(qc))
2949 if (qc.injectedClass && parseEqual(*qc.injectedClass))
2955 DLLLOCAL
const QoreClass* parseGetClass(
const qore_class_private& qc, ClassAccess& n_access)
const;
2957 DLLLOCAL
int addBaseClassesToSubclass(
QoreClass* sc,
bool is_virtual);
2959 DLLLOCAL
void setPublic();
2961 DLLLOCAL
void parseSetBaseClassList(BCList* bcl) {
2965 if (!has_new_user_changes)
2966 has_new_user_changes =
true;
2967 if (!has_sig_changes)
2968 has_sig_changes =
true;
2972 DLLLOCAL
bool parseHasPendingChanges()
const {
2973 return has_new_user_changes;
2976 DLLLOCAL
bool parseCheckHierarchy(
const QoreClass* n_cls, ClassAccess& access)
const {
2978 return parseCheckHierarchyIntern(n_cls, access,
true);
2981 DLLLOCAL
bool parseCheckHierarchyIntern(
const QoreClass* n_cls, ClassAccess& access,
bool toplevel)
const {
2982 if (parseEqual(*n_cls->priv))
2985 return scl ? scl->parseCheckHierarchy(n_cls, access, toplevel) :
false;
2988 DLLLOCAL VRMutex* getGate()
const {
2993 DLLLOCAL
const QoreMethod* parseFindAnyMethod(
const char* nme,
const qore_class_private* class_ctx);
2996 DLLLOCAL
const QoreMethod* parseFindAnyMethodStaticFirst(
const char* nme,
const qore_class_private* class_ctx);
2999 DLLLOCAL
const QoreMethod* parseResolveSelfMethod(
const QoreProgramLocation* loc,
const char* nme,
const qore_class_private* class_ctx);
3000 DLLLOCAL
const QoreMethod* parseResolveSelfMethod(
const QoreProgramLocation* loc, NamedScope* nme);
3003 DLLLOCAL
const QoreMethod* parseFindSelfMethod(
const char* nme);
3005 DLLLOCAL
char* getHash()
const {
3006 return hash.getHash();
3010 assert(!serializer);
3015 assert(!deserializer);
3022 DLLLOCAL
static char* getHash(
const QoreClass& qc) {
3023 return qc.priv->getHash();
3026 DLLLOCAL
static void parseAddConstant(
QoreClass& qc,
const QoreProgramLocation* loc,
const std::string &cname,
QoreValue val, ClassAccess access) {
3027 qc.priv->parseAddConstant(loc, cname, val, access);
3030 DLLLOCAL
static LocalVar* getSelfId(
const QoreClass& qc) {
3031 return &qc.priv->selfid;
3035 return qc.priv->execConstructor(variant, args, xsink);
3038 DLLLOCAL
static bool injected(
const QoreClass& qc) {
3039 return qc.priv->inject;
3042 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) {
3043 qore_class_private* priv =
new qore_class_private(*qc.priv, ns, spgm, nme, inject, injectedClass, set_pub);
3048 DLLLOCAL
static const QoreMethod* runtimeFindCommittedStaticMethod(
const QoreClass& qc,
const char* nme, ClassAccess& access,
const qore_class_private* class_ctx) {
3049 return qc.priv->runtimeFindCommittedStaticMethod(nme, access, class_ctx);
3052 DLLLOCAL
static const QoreMethod* parseFindLocalMethod(
const QoreClass& qc,
const char* mname) {
3053 return qc.priv->parseFindLocalMethod(mname);
3056 DLLLOCAL
static bool parseHasPendingChanges(
const QoreClass& qc) {
3057 return qc.priv->parseHasPendingChanges();
3060 DLLLOCAL
static int parseCheckMemberAccess(
const QoreClass& qc,
const QoreProgramLocation* loc,
const char* mem,
const QoreTypeInfo*& memberTypeInfo,
int pflag) {
3061 return qc.priv->parseCheckMemberAccess(loc, mem, memberTypeInfo, pflag);
3064 DLLLOCAL
static bool runtimeHasCallableMethod(
const QoreClass& qc,
const char* m) {
3065 return qc.priv->runtimeHasCallableMethod(m, QCCM_NORMAL | QCCM_STATIC);
3068 DLLLOCAL
static bool runtimeHasCallableNormalMethod(
const QoreClass& qc,
const char* m) {
3069 return qc.priv->runtimeHasCallableMethod(m, QCCM_NORMAL);
3072 DLLLOCAL
static bool runtimeHasCallableStaticMethod(
const QoreClass& qc,
const char* m) {
3073 return qc.priv->runtimeHasCallableMethod(m, QCCM_STATIC);
3077 return qc.priv->runtimeCheckInstantiateClass(xsink);
3080 DLLLOCAL
static void parseInit(
QoreClass& qc) {
3081 qc.priv->parseInit();
3084 DLLLOCAL
static void parseInitPartial(
QoreClass& qc) {
3085 qc.priv->parseInitPartial();
3088 DLLLOCAL
static void parseCommit(
QoreClass& qc) {
3089 qc.priv->parseCommit();
3093 qc.priv->parseCommitRuntimeInit(xsink);
3096 DLLLOCAL
static void parseRollback(
QoreClass& qc) {
3097 qc.priv->parseRollback();
3100 DLLLOCAL
static void resolveCopy(
QoreClass& qc) {
3101 qc.priv->resolveCopy();
3104 DLLLOCAL
static int addUserMethod(
QoreClass& qc,
const char* mname, MethodVariantBase* f,
bool n_static) {
3105 return qc.priv->addUserMethod(mname, f, n_static);
3108 DLLLOCAL
static void initialize(
QoreClass& qc) {
3109 qc.priv->initialize();
3112 DLLLOCAL
static void parseSetBaseClassList(
QoreClass& qc, BCList* bcl) {
3113 qc.priv->parseSetBaseClassList(bcl);
3116 DLLLOCAL
static BCList* getBaseClassList(
const QoreClass& qc) {
3117 return qc.priv->scl;
3120 DLLLOCAL
static void parseAddStaticVar(
QoreClass* qc,
char* dname, ClassAccess access, QoreVarInfo* VarInfo) {
3121 qc->priv->parseAddStaticVar(dname, access, VarInfo);
3125 DLLLOCAL
static QoreValue parseFindLocalConstantValue(
QoreClass* qc,
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found) {
3126 return qc->priv->parseFindLocalConstantValue(cname, typeInfo, found);
3130 DLLLOCAL
static QoreVarInfo* parseFindLocalStaticVar(
const QoreClass* qc,
const char* vname) {
3131 return qc->priv->parseFindLocalStaticVar(vname);
3135 DLLLOCAL
static QoreValue parseFindConstantValue(
QoreClass* qc,
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found,
const qore_class_private* class_ctx) {
3136 return qc->priv->parseFindConstantValue(cname, typeInfo, found, class_ctx);
3140 DLLLOCAL
static QoreVarInfo* parseFindStaticVar(
const QoreClass* qc,
const char* vname,
const QoreClass*& nqc, ClassAccess& access,
bool check =
false) {
3141 return qc->priv->parseFindStaticVar(vname, nqc, access, check);
3144 DLLLOCAL
static int parseCheckInternalMemberAccess(
const QoreClass* qc,
const char* mem,
const QoreTypeInfo*& memberTypeInfo,
const QoreProgramLocation* loc) {
3145 return qc->priv->parseCheckInternalMemberAccess(mem, memberTypeInfo, loc);
3148 DLLLOCAL
static int parseResolveInternalMemberAccess(
const QoreClass* qc,
const char* mem,
const QoreTypeInfo*& memberTypeInfo) {
3149 return qc->priv->parseResolveInternalMemberAccess(mem, memberTypeInfo);
3153 return qc->priv->parseFindSelfMethod(mname);
3156 DLLLOCAL
static void parseAddMember(
QoreClass& qc,
char* nme, ClassAccess access, QoreMemberInfo* mInfo) {
3157 qc.priv->parseAddMember(nme, access, mInfo);
3161 return qc->priv->evalPseudoMethod(n, name, args, xsink);
3165 return qc->priv->evalPseudoMethod(m, variant, n, args, xsink);
3168 DLLLOCAL
static bool parseCheckPrivateClassAccess(
const QoreClass& qc,
const qore_class_private* oqc = parse_get_class_priv()) {
3169 return qc.priv->parseCheckPrivateClassAccess(oqc);
3172 DLLLOCAL
static bool runtimeCheckPrivateClassAccess(
const QoreClass& qc,
const qore_class_private* oqc = runtime_get_class()) {
3173 return qc.priv->runtimeCheckPrivateClassAccess(oqc);
3176 DLLLOCAL
static qore_type_result_e parseCheckCompatibleClass(
const QoreClass* qc,
const QoreClass* oc) {
3178 return QTI_NOT_EQUAL;
3179 return qc->priv->parseCheckCompatibleClass(*(oc->priv));
3182 DLLLOCAL
static qore_type_result_e runtimeCheckCompatibleClass(
const QoreClass& qc,
const QoreClass& oc) {
3183 return qc.priv->runtimeCheckCompatibleClass(*oc.priv);
3186 DLLLOCAL
static qore_class_private*
get(
QoreClass& qc) {
3190 DLLLOCAL
static const qore_class_private*
get(
const QoreClass& qc) {
3194 DLLLOCAL
static bool isPublic(
const QoreClass& qc) {
3195 return qc.priv->pub;
3198 DLLLOCAL
static bool isUserPublic(
const QoreClass& qc) {
3199 return qc.priv->pub && !qc.priv->sys;
3202 DLLLOCAL
static bool isFinal(
const QoreClass& qc) {
3203 return qc.priv->final;
3206 DLLLOCAL
static void setPublic(
QoreClass& qc) {
3207 qc.priv->setPublic();
3210 DLLLOCAL
static void setFinal(
QoreClass& qc) {
3211 assert(!qc.priv->final);
3212 qc.priv->final =
true;
3216 DLLLOCAL ~qore_class_private();
3219 class qore_class_private_holder {
3220 qore_class_private* c;
3223 DLLLOCAL qore_class_private_holder(
QoreClass* n_c) : c(qore_class_private::get(*n_c)) {
3226 DLLLOCAL qore_class_private_holder(qore_class_private* n_c) : c(n_c) {
3229 DLLLOCAL ~qore_class_private_holder() {
3231 c->deref(
true,
true);
3235 DLLLOCAL qore_class_private* operator*() {
3249 class qore_method_private {
3252 MethodFunctionBase* func;
3253 bool static_flag, all_user;
3255 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) {
3256 assert(parent_class == n_func->
getClass());
3259 DLLLOCAL ~qore_method_private() {
3263 DLLLOCAL
void setBuiltin() {
3268 DLLLOCAL
bool isUniquelyUser()
const {
3272 DLLLOCAL
bool isAbstract()
const {
3273 return func->isAbstract();
3276 DLLLOCAL
int addUserVariant(MethodVariantBase* variant) {
3277 return func->parseAddUserMethodVariant(variant);
3280 DLLLOCAL
void addBuiltinVariant(MethodVariantBase* variant) {
3282 func->addBuiltinMethodVariant(variant);
3285 DLLLOCAL MethodFunctionBase* getFunction()
const {
3286 return const_cast<MethodFunctionBase*
>(func);
3289 DLLLOCAL
const char* getName()
const {
3290 return func->getName();
3293 DLLLOCAL
const std::string& getNameStr()
const {
3294 return func->getNameStr();
3297 DLLLOCAL
void parseInit();
3299 DLLLOCAL
void parseInitStatic() {
3300 assert(static_flag);
3306 DLLLOCAL
const QoreTypeInfo* getUniqueReturnTypeInfo()
const {
3307 return func->getUniqueReturnTypeInfo();
3311 CONMF(func)->evalConstructor(variant, *parent_class,
self, args, parent_class->priv->scl, bceal, xsink);
3315 COPYMF(func)->evalCopy(*parent_class,
self, old, parent_class->priv->scl, xsink);
3319 COPYMF(func)->evalCopy(*parent_class,
self, old,
nullptr, xsink);
3322 DLLLOCAL
bool evalDeleteBlocker(
QoreObject*
self)
const {
3324 return self->evalDeleteBlocker(parent_class->priv->methodID, reinterpret_cast<BuiltinDeleteBlocker*>(func));
3328 DESMF(func)->evalDestructor(*parent_class,
self, xsink);
3333 DESMF(func)->evalDestructor(*parent_class,
self, xsink);
3336 DLLLOCAL
void evalSystemConstructor(
QoreObject*
self,
int code, va_list args)
const {
3337 BSYSCONB(func)->eval(*parent_class,
self, code, args);
3343 return NMETHF(func)->evalMethod(xsink, 0,
self, args, cctx);
3345 return SMETHF(func)->evalMethod(xsink, 0, args, cctx);
3351 return NMETHF(func)->evalMethodTmpArgs(xsink,
nullptr,
self, args, cctx);
3353 return SMETHF(func)->evalMethodTmpArgs(xsink,
nullptr, args, cctx);
3357 QORE_TRACE(
"qore_method_private::evalPseudoMethod()");
3359 assert(!static_flag);
3361 QoreValue rv = NMETHF(func)->evalPseudoMethod(xsink, variant, n, args);
3362 printd(5,
"qore_method_private::evalPseudoMethod() %s::%s() returning type: %s\n", parent_class->
getName(), getName(), rv.getTypeName());
3369 DLLLOCAL ClassAccess getAccess()
const;
3372 DLLLOCAL
static ClassAccess getAccess(
const QoreMethod& m) {
3373 return m.priv->getAccess();
3377 return m.priv->evalNormalVariant(
self, ev, args, xsink);
3381 return m.priv->evalPseudoMethod(variant, n, args, xsink);
3385 return m.priv->eval(xsink,
self, args, cctx);
3389 return m.priv->evalTmpArgs(xsink,
self, args, cctx);
3392 DLLLOCAL
static qore_method_private*
get(
QoreMethod& m) {
3396 DLLLOCAL
static const qore_method_private*
get(
const QoreMethod& m) {
3402 class PrivateIteratorBase {
3404 DLLLOCAL PrivateIteratorBase(
const T& obj) : obj(obj), i(obj.end()) {
3407 DLLLOCAL
bool next() {
3408 if (i == obj.end()) {
3414 return (i != obj.end());
3418 DLLLOCAL
bool valid()
const {
3419 return i != obj.end();
3424 typename T::const_iterator i;
3427 template <
class T,
class U>
3428 class PrivateMemberIteratorBase :
public PrivateIteratorBase<typename T::member_list_t> {
3430 DLLLOCAL PrivateMemberIteratorBase(
const typename T::member_list_t& obj) : PrivateIteratorBase<typename T::member_list_t>(obj) {
3433 DLLLOCAL
const U& getMember()
const {
3434 assert(this->valid());
3435 return *
reinterpret_cast<const U*
>(this->i->second.get());
3438 DLLLOCAL
const char* getName()
const {
3439 assert(this->valid());
3440 return this->i->first;
DLLEXPORT QoreClass * getClass(qore_classid_t cid) const
returns a pointer to the QoreClass object representing the class ID passed if it exists in the class ...
DLLEXPORT int reference_count() const
gets the reference count
void(* q_external_constructor_t)(const QoreMethod &method, const void *ptr, QoreObject *self, const QoreListNode *args, q_rt_flags_t rtflags, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures
Definition: common.h:366
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
void(* q_destructor_t)(QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass destructor signatures
Definition: common.h:386
QoreValue(* q_external_static_method_t)(const QoreMethod &method, const void *ptr, const QoreListNode *args, q_rt_flags_t flags, ExceptionSink *xsink)
the type used for external static methods
Definition: common.h:346
void(* q_system_constructor_t)(QoreObject *self, int code, va_list args)
the type used for builtin QoreClass system constructor method signatures
Definition: common.h:378
virtual DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count of the object
an abstract class for class-specific external user data
Definition: QoreClass.h:223
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
DLLEXPORT const char * getName() const
returns the method's name
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
const qore_type_t NT_OBJECT
type value for QoreObject
Definition: node_types.h:52
static void discard(AbstractQoreNode *n, ExceptionSink *xsink)
to deref an AbstractQoreNode (when the pointer may be 0)
Definition: QoreLib.h:323
uint64_t q_rt_flags_t
runtime code execution flags
Definition: common.h:263
QoreHashNode *(* q_serializer_t)(const QoreObject &self, const AbstractPrivateData &data, QoreSerializationContext &context, ExceptionSink *xsink)
the type used for builtin QoreClass serializer method signatures
Definition: common.h:434
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
DLLEXPORT bool ROdereference() const
atomically decrements the reference count
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT const QoreClass * getClass() const
returns a pointer to the parent class
DLLEXPORT const char * getBuffer() const
returns the string's buffer; this data should not be changed
DLLEXPORT QoreProgram * getProgram()
returns the current QoreProgram
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:44
void(* q_external_copy_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass copy signatures with the new generic calling convention ...
Definition: common.h:416
defines a Qore-language class
Definition: QoreClass.h:239
void(* q_external_destructor_t)(const QoreClass &thisclass, const void *ptr, QoreObject *self, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass destructor signatures with the new generic calling convention and...
Definition: common.h:396
DLLEXPORT bool isStatic() const
returns true if the method is static
bool(* q_delete_blocker_t)(QoreObject *self, AbstractPrivateData *private_data)
the typed used for QoreClass deleteBlocker signatures
Definition: common.h:424
void(* q_deserializer_t)(QoreObject &self, const QoreHashNode *sdata, QoreDeserializationContext &context, ExceptionSink *xsink)
the type used for builtin QoreClass deserializer method signatures
Definition: common.h:446
#define PO_STRICT_TYPES
enforce strict type checking and setting default values
Definition: Restrictions.h:98
void(* q_constructor_n_t)(QoreObject *self, const QoreListNode *args, q_rt_flags_t rtflags, ExceptionSink *xsink)
the type used for builtin QoreClass constructor method signatures
Definition: common.h:354
QoreValue(* q_method_n_t)(QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, q_rt_flags_t flags, ExceptionSink *xsink)
the type used for builtin QoreClass method signatures
Definition: common.h:318
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:126
the implementation of Qore's object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:61
unsigned qore_classid_t
used for the unique class ID for QoreClass objects
Definition: common.h:79
external wrapper class for method variants
Definition: QoreReflection.h:90
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:257
DLLEXPORT ClassAccess getAccess() const
returns the lowest access code of all variants in the method
#define PO_REQUIRE_TYPES
require type information for all declarations
Definition: Restrictions.h:61
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
std::vector< QoreValue > arg_vec_t
vector of value information for default argument lists
Definition: common.h:254
DLLEXPORT void ROreference() const
atomically increments the reference count
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:70
void(* q_copy_t)(QoreObject *self, QoreObject *old, AbstractPrivateData *private_data, ExceptionSink *xsink)
the type used for builtin QoreClass copy signatures
Definition: common.h:405
QoreValue(* q_external_method_t)(const QoreMethod &method, const void *ptr, QoreObject *self, AbstractPrivateData *private_data, const QoreListNode *args, q_rt_flags_t flags, ExceptionSink *xsink)
the type used for builtin QoreClass method signatures
Definition: common.h:333
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:251
a method in a QoreClass
Definition: QoreClass.h:125
DLLEXPORT const char * getName() const
returns the class name
holds an object and dereferences it in the destructor
Definition: QoreValue.h:452
QoreValue(* q_func_n_t)(const QoreListNode *args, q_rt_flags_t flags, ExceptionSink *xsink)
the type used for builtin function signatures
Definition: common.h:307
DLLEXPORT void discard(ExceptionSink *xsink)
dereferences any contained AbstractQoreNode pointer and sets to 0; does not modify other values ...
#define QDOM_DEFAULT
the default domain (no domain)
Definition: Restrictions.h:155