32 #ifndef _QORE_QORENAMESPACEINTERN_H
33 #define _QORE_QORENAMESPACEINTERN_H
35 #include "qore/intern/QoreClassList.h"
36 #include "qore/intern/HashDeclList.h"
37 #include "qore/intern/QoreNamespaceList.h"
38 #include "qore/intern/ConstantList.h"
39 #include "qore/intern/FunctionList.h"
40 #include "qore/intern/GlobalVariableList.h"
41 #include "qore/intern/typed_hash_decl_private.h"
42 #include "qore/vector_map"
48 class qore_root_ns_private;
49 class qore_ns_private;
51 typedef std::list<const qore_ns_private*> nslist_t;
53 class qore_ns_private {
55 const QoreProgramLocation* loc;
62 QoreClassList classList;
63 HashDeclList hashDeclList;
64 ConstantList constant;
65 QoreNamespaceList nsl;
66 FunctionList func_list;
67 GlobalVariableList var_list;
68 gvblist_t pend_gvblist;
79 const qore_ns_private* parent =
nullptr;
80 q_ns_class_handler_t class_handler =
nullptr;
84 typedef std::map<std::string, QoreValue> kvmap_t;
88 DLLLOCAL qore_ns_private(
QoreNamespace* n_ns,
const char* n) : name(n), ns(n_ns), constant(this), pub(true),
90 size_t i = name.rfind(
"::");
92 if (i == std::string::npos) {
101 path.insert(0,
"::");
104 const char* mod_name = get_module_context_name();
106 from_module = mod_name;
111 DLLLOCAL qore_ns_private(
const char* n,
const qore_ns_private& old)
115 constant(this), pub(old.pub),
116 builtin(false), from_module(old.from_module) {
120 DLLLOCAL qore_ns_private(
const QoreProgramLocation* loc);
126 classList(old.classList, po, this),
127 hashDeclList(old.hashDeclList, po, this),
128 constant(old.constant, po, this),
129 nsl(old.nsl, po, *this),
130 func_list(old.func_list, this, po),
131 var_list(old.var_list, po),
134 pub(old.builtin ? true : false),
135 builtin(old.builtin),
136 imported(old.imported),
137 class_handler(old.class_handler) {
138 if (!old.from_module.empty()) {
139 from_module = old.from_module;
143 DLLLOCAL ~qore_ns_private() {
147 DLLLOCAL
const char* getPath()
const {
148 assert(!path.empty());
152 DLLLOCAL
void getPath(std::string& str,
bool anchored =
false,
bool need_next =
false)
const {
157 if (need_next && !root) {
162 DLLLOCAL
const char* getModuleName()
const {
163 return from_module.empty() ? nullptr : from_module.c_str();
196 DLLLOCAL
bool setKeyValueIfNotSet(
const std::string& key,
const char* str);
205 DLLLOCAL
QoreValue getReferencedKeyValue(
const std::string& key)
const;
214 DLLLOCAL
QoreValue getReferencedKeyValue(
const char* key)
const;
216 DLLLOCAL
void getNsList(nslist_t& nsl)
const {
221 const qore_ns_private* w =
this;
222 while (w && w->parent) {
229 DLLLOCAL
void purge() {
234 hashDeclList.reset();
239 DLLLOCAL qore_root_ns_private* getRoot() {
240 qore_ns_private* w =
this;
242 w = (qore_ns_private*)w->parent;
245 return w->root ?
reinterpret_cast<qore_root_ns_private*
>(w) :
nullptr;
248 DLLLOCAL
const qore_root_ns_private* getRoot()
const {
249 const qore_ns_private* w =
this;
251 w = (qore_ns_private*)w->parent;
254 return w->root ?
reinterpret_cast<const qore_root_ns_private*
>(w) :
nullptr;
259 DLLLOCAL
void setClassHandler(q_ns_class_handler_t n_class_handler);
262 DLLLOCAL
QoreClass* findLoadClass(
const char* cname) {
266 if (!qc && class_handler)
267 qc = class_handler(ns, cname);
274 var_list.getGlobalVars(path, h);
275 nsl.getGlobalVars(h);
280 DLLLOCAL
void deleteData(
bool deref_vars,
ExceptionSink* xsink);
286 DLLLOCAL
void updateDepthRecursive(
unsigned ndepth);
288 DLLLOCAL
int parseAddPendingClass(
const QoreProgramLocation* loc,
const NamedScope& n,
QoreClass* oc);
289 DLLLOCAL
int parseAddPendingClass(
const QoreProgramLocation* loc,
QoreClass* oc);
291 DLLLOCAL
int parseAddPendingHashDecl(
const QoreProgramLocation* loc,
const NamedScope& n,
293 DLLLOCAL
int parseAddPendingHashDecl(
const QoreProgramLocation* loc,
TypedHashDecl* hashdecl);
295 DLLLOCAL
bool addGlobalVars(qore_root_ns_private& rns);
297 DLLLOCAL cnemap_t::iterator parseAddConstant(
const QoreProgramLocation* loc,
const char* name,
QoreValue value,
300 DLLLOCAL
void parseAddConstant(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreValue value,
303 DLLLOCAL
int parseAddMethodToClass(
const QoreProgramLocation* loc,
const NamedScope& name,
304 MethodVariantBase* qcmethod,
bool static_flag);
306 DLLLOCAL
int checkImportFunction(
const char* name,
ExceptionSink* xsink) {
309 if (func_list.findNode(name)) {
310 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"function '%s' already exists in this namespace", name);
317 DLLLOCAL FunctionEntry* runtimeImportFunction(
ExceptionSink* xsink, QoreFunction* u,
318 const char* new_name =
nullptr,
bool inject =
false) {
319 const char* fn = new_name ? new_name : u->getName();
320 if (checkImportFunction(fn, xsink))
323 return func_list.import(fn, u,
this, inject);
326 DLLLOCAL
int checkImportClass(
const char* cname,
ExceptionSink* xsink) {
329 if (classList.find(cname)) {
330 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"class '%s' already exists in namespace '%s'", cname,
334 if (hashDeclList.find(cname)) {
335 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"hashdecl '%s' already exists in namespace '%s'", cname,
339 if (nsl.find(cname)) {
340 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"a subnamespace named '%s' already exists in namespace '%s'",
341 cname, name.c_str());
348 DLLLOCAL
int checkImportHashDecl(
const char* hdname,
ExceptionSink* xsink) {
351 if (hashDeclList.find(hdname)) {
352 xsink->
raiseException(
"HASHDECL-IMPORT-ERROR",
"hashdecl '%s' already exists in namespace '%s'", hdname,
356 if (classList.find(hdname)) {
357 xsink->
raiseException(
"HASHDECL-IMPORT-ERROR",
"class '%s' already exists in namespace '%s'", hdname,
366 q_setpub_t set_pub,
const char* new_name =
nullptr,
bool inject =
false,
367 const qore_class_private* injectedClass =
nullptr);
370 q_setpub_t set_pub,
const char* new_name =
nullptr);
372 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntry(
const char* name) {
373 return func_list.findNode(name,
true);
376 DLLLOCAL
const QoreFunction* runtimeFindFunction(
const char* name) {
377 return func_list.find(name,
true);
380 DLLLOCAL
const QoreFunction* findAnyFunction(
const char* name) {
381 return func_list.find(name,
false);
384 DLLLOCAL
QoreNamespace* findCreateNamespace(
const char* nme,
bool user,
bool& is_new, qore_root_ns_private* rns);
385 DLLLOCAL
QoreNamespace* findCreateNamespacePath(
const nslist_t& nsl,
bool user,
bool& is_new);
386 DLLLOCAL
QoreNamespace* findCreateNamespacePath(
const NamedScope& nspath,
bool pub,
bool user,
bool& is_new,
389 DLLLOCAL
TypedHashDecl* parseFindLocalHashDecl(
const char* name) {
390 return hashDeclList.find(name);
393 DLLLOCAL
QoreValue getConstantValue(
const char* name,
const QoreTypeInfo*& typeInfo,
bool& found);
394 DLLLOCAL
QoreClass* parseFindLocalClass(
const char* name);
395 DLLLOCAL qore_ns_private* parseAddNamespace(
QoreNamespace* nns);
397 DLLLOCAL
void addModuleNamespace(qore_ns_private* nns, QoreModuleContext& qmc);
398 DLLLOCAL
void addCommitNamespaceIntern(qore_ns_private* nns);
399 DLLLOCAL
void addNamespace(qore_ns_private* nns);
401 DLLLOCAL
int parseInit();
402 DLLLOCAL
void parseResolveHierarchy();
403 DLLLOCAL
void parseResolveClassMembers();
404 DLLLOCAL
void parseResolveAbstract();
405 DLLLOCAL
int parseInitConstants();
407 DLLLOCAL
void parseCommit();
410 DLLLOCAL Var* runtimeMatchGlobalVar(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
411 DLLLOCAL
const ConstantEntry* runtimeMatchNamespaceConstant(
const NamedScope& nscope,
412 const qore_ns_private*& rns)
const;
413 DLLLOCAL
const QoreClass* runtimeMatchScopedClassWithMethod(
const NamedScope& nscope)
const;
414 DLLLOCAL
const QoreClass* runtimeMatchClass(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
415 DLLLOCAL
const qore_ns_private* runtimeMatchNamespace(
const NamedScope& nscope,
int offset = 0)
const;
416 DLLLOCAL
const qore_ns_private* runtimeMatchAddClass(
const NamedScope& nscope,
bool& fnd)
const;
418 DLLLOCAL
const TypedHashDecl* runtimeMatchHashDecl(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
420 DLLLOCAL
const FunctionEntry* runtimeMatchFunctionEntry(
const NamedScope& nscope)
const;
421 DLLLOCAL
const qore_ns_private* runtimeMatchAddFunction(
const NamedScope& nscope,
bool& fnd)
const;
425 DLLLOCAL
const FunctionEntry* parseMatchFunctionEntry(
const NamedScope& nscope,
unsigned& match)
const;
427 DLLLOCAL
QoreNamespace* resolveNameScope(
const QoreProgramLocation* loc,
const NamedScope& name)
const;
428 DLLLOCAL
QoreNamespace* parseMatchNamespace(
const NamedScope& nscope,
unsigned& matched)
const;
430 DLLLOCAL
TypedHashDecl* parseMatchScopedHashDecl(
const NamedScope& name,
unsigned& matched);
432 DLLLOCAL
QoreClass* parseMatchScopedClass(
const NamedScope& name,
unsigned& matched);
433 DLLLOCAL
QoreClass* parseMatchScopedClassWithMethod(
const NamedScope& nscope,
unsigned& matched);
435 DLLLOCAL
QoreValue parseCheckScopedReference(
const QoreProgramLocation* loc,
const NamedScope& ns,
unsigned& m,
436 const QoreTypeInfo*& typeInfo,
bool& found,
bool abr)
const;
438 DLLLOCAL
QoreValue parseFindLocalConstantValue(
const QoreProgramLocation* loc,
const NamedScope& ns,
unsigned& m,
439 const QoreTypeInfo*& typeInfo,
bool& found,
bool abr)
const;
441 DLLLOCAL
QoreValue parseFindLocalConstantValue(
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found);
442 DLLLOCAL
QoreNamespace* parseFindLocalNamespace(
const char* nname);
444 DLLLOCAL
QoreValue parseMatchScopedConstantValue(
const NamedScope& name,
unsigned& matched,
445 const QoreTypeInfo*& typeInfo,
bool& found);
447 DLLLOCAL FunctionEntry* addPendingVariantIntern(
const char* fname, AbstractQoreFunctionVariant* v,
bool& new_func);
449 DLLLOCAL
void addBuiltinVariant(
const char* name, AbstractQoreFunctionVariant* v);
450 DLLLOCAL
void addBuiltinModuleVariant(
const char* name, AbstractQoreFunctionVariant* v, QoreModuleContext& qmc);
451 DLLLOCAL
void addBuiltinVariantIntern(
const char* name, AbstractQoreFunctionVariant* v);
453 template <
typename T,
class B>
454 DLLLOCAL
void addBuiltinVariant(
const char* name, T f,
int64 flags,
int64 functional_domain,
455 const QoreTypeInfo* returnTypeInfo,
unsigned num_params, va_list args) {
461 qore_process_params(
num_params, typeList, defaultArgList, nameList, args);
465 addBuiltinVariant(name,
new B(f, flags, functional_domain, returnTypeInfo, typeList, defaultArgList,
469 template <
typename T,
class B>
470 DLLLOCAL
void addBuiltinVariant(
void* ptr,
const char* name, T f,
int64 flags,
int64 functional_domain,
471 const QoreTypeInfo* returnTypeInfo,
unsigned num_params, va_list args) {
477 qore_process_params(
num_params, typeList, defaultArgList, nameList, args);
481 addBuiltinVariant(name,
new B(ptr, f, flags, functional_domain, returnTypeInfo, typeList, defaultArgList,
485 DLLLOCAL
void scanMergeCommittedNamespace(
const qore_ns_private& mns, QoreModuleContext& qmc)
const;
486 DLLLOCAL
void copyMergeCommittedNamespace(
const qore_ns_private& mns);
488 DLLLOCAL
int parseInitGlobalVars();
490 DLLLOCAL
int checkGlobalVarDecl(Var* v,
const NamedScope& vname);
491 DLLLOCAL
void parseAddGlobalVarDecl(
const QoreProgramLocation* loc,
char* name,
const QoreTypeInfo* typeInfo,
492 QoreParseTypeInfo* parseTypeInfo,
bool pub, qore_var_t type);
494 DLLLOCAL
void setPublic();
496 DLLLOCAL
void runtimeImportSystemClasses(
const qore_ns_private& source, qore_root_ns_private& rns,
498 DLLLOCAL
void runtimeImportSystemHashDecls(
const qore_ns_private& source, qore_root_ns_private& rns,
500 DLLLOCAL
void runtimeImportSystemConstants(
const qore_ns_private& source, qore_root_ns_private& rns,
502 DLLLOCAL
void runtimeImportSystemFunctions(
const qore_ns_private& source, qore_root_ns_private& rns,
506 ns.priv->addNamespace(nns->priv);
509 DLLLOCAL
static QoreValue parseResolveReferencedClassConstant(
const QoreProgramLocation* loc,
QoreClass* qc,
510 const char* name,
const QoreTypeInfo*& typeInfo,
bool& found);
512 DLLLOCAL
static ConstantList& getConstantList(
const QoreNamespace* ns) {
513 return ns->priv->constant;
516 DLLLOCAL
static const QoreFunction* runtimeFindFunction(
QoreNamespace& ns,
const char* name) {
517 return ns.priv->runtimeFindFunction(name);
520 DLLLOCAL
static const FunctionEntry* runtimeFindFunctionEntry(
QoreNamespace& ns,
const char* name) {
521 return ns.priv->runtimeFindFunctionEntry(name);
525 return ns.priv->func_list.getList();
528 DLLLOCAL
static void parseAddPendingClass(
QoreNamespace& ns,
const QoreProgramLocation* loc,
const NamedScope& n,
530 ns.priv->parseAddPendingClass(loc, n, oc);
534 ns.priv->parseAddNamespace(nns);
537 DLLLOCAL
static void parseAddConstant(
QoreNamespace& ns,
const QoreProgramLocation* loc,
const NamedScope& name,
539 ns.priv->parseAddConstant(loc, name, value, pub);
543 ns.priv->parseCommit();
554 DLLLOCAL
static const qore_ns_private* get(
const QoreNamespace& ns) {
563 return ns.priv->pub && !ns.priv->builtin;
568 DLLLOCAL qore_ns_private(
const qore_ns_private&) =
delete;
570 DLLLOCAL qore_ns_private& operator=(
const qore_ns_private&) =
delete;
574 std::string from_module;
577 DLLLOCAL qore_ns_private(
QoreNamespace* n_ns) : ns(n_ns), constant(this), root(true), pub(true), builtin(true) {
580 DLLLOCAL
void setModuleName() {
581 assert(from_module.empty());
582 const char* mod_name = get_module_context_name();
584 from_module = mod_name;
590 hashdecl namespace_iterator_element {
594 DLLLOCAL namespace_iterator_element(qore_ns_private* ns) : ns(ns) {
597 i = ns->nsl.nsmap.begin();
600 DLLLOCAL
bool atEnd()
const {
601 return i == ns->nsl.nsmap.end();
613 class QorePrivateNamespaceIterator {
615 typedef std::vector<namespace_iterator_element> nsv_t;
617 qore_ns_private* root;
619 DLLLOCAL
void set(qore_ns_private* rns) {
620 nsv.push_back(namespace_iterator_element(rns));
623 while (!(rns->nsl.empty())) {
624 rns = qore_ns_private::get(*((rns->nsl.nsmap.begin()->second)));
627 nsv.push_back(namespace_iterator_element(rns));
632 DLLLOCAL QorePrivateNamespaceIterator(qore_ns_private* rns) : root(rns) {
636 DLLLOCAL
bool next() {
643 namespace_iterator_element* nie = &(nsv.back());
656 set(qore_ns_private::get(*next));
661 DLLLOCAL qore_ns_private* operator->() {
662 return nsv.back().ns;
665 DLLLOCAL qore_ns_private* operator*() {
666 return nsv.back().ns;
669 DLLLOCAL qore_ns_private* get() {
670 return nsv.back().ns;
674 hashdecl NSOInfoBase {
675 qore_ns_private* ns =
nullptr;
677 DLLLOCAL NSOInfoBase() {
680 DLLLOCAL NSOInfoBase(qore_ns_private* n_ns) : ns(n_ns) {
683 DLLLOCAL
unsigned depth()
const {
688 template <
typename T>
689 hashdecl NSOInfo :
public NSOInfoBase {
696 DLLLOCAL NSOInfo(qore_ns_private* n_ns, T* n_obj) : NSOInfoBase(n_ns), obj(n_obj) {
699 DLLLOCAL
void assign(qore_ns_private* n_ns, T* n_obj) {
706 template <
typename T>
707 class RootMap :
public std::map<const std::string, NSOInfo<T>> {
710 DLLLOCAL RootMap(
const RootMap& old);
712 DLLLOCAL RootMap& operator=(
const RootMap& m);
715 typedef NSOInfo<T> info_t;
716 typedef std::map<const std::string, NSOInfo<T>> map_t;
721 DLLLOCAL
void update(
const std::string& name, qore_ns_private* ns, T* obj) {
723 typename map_t::iterator i = this->lower_bound(name);
724 if (i == this->end() || i->first != name) {
725 this->insert(i,
typename map_t::value_type(name, info_t(ns, obj)));
727 if (i->second.depth() > ns->depth) {
728 i->second.assign(ns, obj);
733 DLLLOCAL
void update(
typename map_t::const_iterator ni) {
735 typename map_t::iterator i = this->lower_bound(ni->first);
736 if (i == this->end() || i->first != ni->first) {
738 this->insert(i,
typename map_t::value_type(ni->first, ni->second));
741 if (i->second.depth() > ni->second.depth()) {
744 i->second = ni->second;
752 T* findObj(
const std::string& name) {
753 typename map_t::iterator i = this->find(name);
754 return i == this->end() ? nullptr : i->second.obj;
758 hashdecl FunctionEntryInfo {
759 FunctionEntry* obj =
nullptr;
761 DLLLOCAL FunctionEntryInfo() {
764 DLLLOCAL FunctionEntryInfo(FunctionEntry* o) : obj(o) {
767 DLLLOCAL
unsigned depth()
const {
768 return getNamespace()->depth;
771 DLLLOCAL qore_ns_private* getNamespace()
const {
772 return obj->getNamespace();
775 DLLLOCAL
void assign(FunctionEntry* n_obj) {
781 typedef std::map<const char*, FunctionEntryInfo, ltstr> femap_t;
782 class FunctionEntryRootMap :
public femap_t {
785 DLLLOCAL FunctionEntryRootMap(
const FunctionEntryRootMap& old);
787 DLLLOCAL FunctionEntryRootMap& operator=(
const FunctionEntryRootMap& m);
790 DLLLOCAL FunctionEntryRootMap() {
793 DLLLOCAL
void update(
const char* name, FunctionEntry* obj) {
795 femap_t::iterator i = find(name);
797 insert(femap_t::value_type(name, FunctionEntryInfo(obj)));
799 if (i->second.depth() > obj->getNamespace()->depth)
800 i->second.assign(obj);
803 DLLLOCAL
void update(femap_t::const_iterator ni) {
805 femap_t::iterator i = find(ni->first);
809 insert(femap_t::value_type(ni->first, ni->second));
812 if (i->second.depth() > ni->second.depth()) {
815 i->second = ni->second;
823 FunctionEntry* findObj(
const char* name) {
824 femap_t::iterator i = find(name);
825 return i == end() ? 0 : i->second.obj;
829 class NamespaceDepthList {
830 friend class NamespaceDepthListIterator;
833 typedef std::multimap<unsigned, qore_ns_private*> nsdmap_t;
837 DLLLOCAL NamespaceDepthList() {
840 DLLLOCAL
void add(qore_ns_private* ns) {
841 nsdmap.insert(nsdmap_t::value_type(ns->depth, ns));
844 DLLLOCAL
void clear() {
849 class NamespaceDepthListIterator {
850 NamespaceDepthList::nsdmap_t::iterator i, e;
852 DLLLOCAL NamespaceDepthListIterator(NamespaceDepthList& m) : i(m.nsdmap.begin()), e(m.nsdmap.end()) {
855 DLLLOCAL
bool next() {
862 DLLLOCAL qore_ns_private* get()
const {
869 friend class NamespaceMapIterator;
870 friend class ConstNamespaceMapIterator;
871 friend class ConstAllNamespacesIterator;
875 typedef std::multimap<unsigned, qore_ns_private*> nsdmap_t;
878 typedef vector_map_t<const char*, nsdmap_t> nsmap_t;
881 typedef vector_map_t<qore_ns_private*, unsigned> nsrmap_t;
887 DLLLOCAL NamespaceMap(
const NamespaceMap& old);
889 DLLLOCAL NamespaceMap& operator=(
const NamespaceMap& m);
892 DLLLOCAL NamespaceMap() {
895 DLLLOCAL
void update(qore_ns_private* ns) {
897 nsrmap_t::iterator ri = nsrmap.find(ns);
898 if (ri != nsrmap.end()) {
900 if (ns->depth == ri->second)
904 nsmap_t::iterator i = nsmap.find(ns->name.c_str());
905 assert(i != nsmap.end());
908 nsdmap_t::iterator di = i->second.find(ri->second);
909 assert(di != i->second.end());
918 i->second.insert(nsdmap_t::value_type(ns->depth, ns));
924 nsmap_t::iterator i = nsmap.find(ns->name.c_str());
925 if (i == nsmap.end())
926 i = nsmap.insert(nsmap_t::value_type(ns->name.c_str(), nsdmap_t())).first;
928 i->second.insert(nsdmap_t::value_type(ns->depth, ns));
932 nsrmap.insert(nsrmap_t::value_type(ns, ns->depth));
935 DLLLOCAL
void commit(NamespaceMap& pend) {
937 for (nsrmap_t::iterator i = pend.nsrmap.begin(), e = pend.nsrmap.end(); i != e; ++i)
942 DLLLOCAL
void clear() {
949 nsmap_t::iterator mi = nsmap.find(name);
950 if (mi != nsmap.end()) {
951 nsdmap_t::iterator i = mi->second.begin();
952 if (i != mi->second.end()) {
953 return i->second->ns;
960 class NamespaceMapIterator {
962 NamespaceMap::nsmap_t::iterator mi;
963 NamespaceMap::nsdmap_t::iterator i;
967 DLLLOCAL NamespaceMapIterator(NamespaceMap& nsm,
const char* name) : mi(nsm.nsmap.find(name)),
968 valid(mi != nsm.nsmap.end()) {
970 i = mi->second.end();
973 DLLLOCAL
bool next() {
977 if (i == mi->second.end())
978 i = mi->second.begin();
982 return i != mi->second.end();
985 DLLLOCAL qore_ns_private* get() {
990 class ConstNamespaceMapIterator {
992 NamespaceMap::nsmap_t::const_iterator mi;
993 NamespaceMap::nsdmap_t::const_iterator i;
997 DLLLOCAL ConstNamespaceMapIterator(
const NamespaceMap& nsm,
const char* name) : mi(nsm.nsmap.find(name)),
998 valid(mi != nsm.nsmap.end()) {
1000 i = mi->second.end();
1003 DLLLOCAL
bool next() {
1007 if (i == mi->second.end())
1008 i = mi->second.begin();
1012 return i != mi->second.end();
1015 DLLLOCAL
const qore_ns_private* get() {
1020 class ConstAllNamespacesIterator {
1022 DLLLOCAL ConstAllNamespacesIterator(
const NamespaceMap& nsmap) : nsrmap(nsmap.nsrmap), i(nsmap.nsrmap.end()) {
1025 DLLLOCAL
bool next() {
1026 if (i == nsrmap.end()) {
1033 return i != nsrmap.end();
1037 assert(i != nsrmap.end());
1038 return i->first->ns;
1042 const NamespaceMap::nsrmap_t& nsrmap;
1043 NamespaceMap::nsrmap_t::const_iterator i;
1046 typedef FunctionEntryRootMap fmap_t;
1048 typedef RootMap<ConstantEntry> cnmap_t;
1050 typedef RootMap<QoreClass> clmap_t;
1052 typedef RootMap<TypedHashDecl> thdmap_t;
1054 typedef RootMap<Var> varmap_t;
1056 hashdecl deferred_new_check_t {
1057 const qore_class_private* qc;
1058 const QoreProgramLocation* loc;
1060 DLLLOCAL deferred_new_check_t(
const qore_class_private* qc,
const QoreProgramLocation* loc) : qc(qc), loc(loc) {
1064 class qore_root_ns_private :
public qore_ns_private {
1065 friend class qore_ns_private;
1069 typedef std::vector<deferred_new_check_t> deferred_new_check_vec_t;
1070 deferred_new_check_vec_t deferred_new_check_vec;
1072 DLLLOCAL
int addPendingVariantIntern(qore_ns_private& ns,
const char* name, AbstractQoreFunctionVariant* v) {
1074 bool new_func =
false;
1075 FunctionEntry* fe = ns.addPendingVariantIntern(name, v, new_func);
1079 assert(fe->getNamespace() == &ns);
1082 fmap_t::iterator i = fmap.find(fe->getName());
1084 if (i == fmap.end() || i->second.depth() > ns.depth)
1085 pend_fmap.update(fe->getName(), fe);
1091 DLLLOCAL
int addPendingVariantIntern(qore_ns_private& ns,
const NamedScope& nscope,
1092 AbstractQoreFunctionVariant* v) {
1093 assert(nscope.size() > 1);
1097 for (
unsigned i = 0; i < nscope.size() - 1; ++i) {
1098 fns = fns->priv->parseFindLocalNamespace(nscope[i]);
1100 parse_error(*v->getUserVariantBase()->getUserSignature()->getParseLocation(),
1101 "cannot find namespace '%s::' in '%s()' as a child of namespace '%s::'", nscope[i], nscope.ostr,
1107 return addPendingVariantIntern(*fns->priv, nscope.getIdentifier(), vh.release());
1112 q_setpub_t set_pub,
const char* new_name =
nullptr,
bool inject =
false,
1113 const qore_class_private* injectedClass =
nullptr) {
1114 QoreClass* nc = ns.runtimeImportClass(xsink, c, spgm, set_pub, new_name, inject, injectedClass);
1121 clmap.update(nc->
getName(), &ns, nc);
1127 QoreProgram* spgm, q_setpub_t set_pub,
const char* new_name =
nullptr) {
1128 TypedHashDecl* nhd = ns.runtimeImportHashDecl(xsink, hd, spgm, set_pub, new_name);
1135 thdmap.update(nhd->
getName(), &ns, nhd);
1140 DLLLOCAL
int runtimeImportFunction(
ExceptionSink* xsink, qore_ns_private& ns, QoreFunction* u,
1141 const char* new_name =
nullptr,
bool inject =
false) {
1142 FunctionEntry* fe = ns.runtimeImportFunction(xsink, u, new_name, inject);
1146 assert(fe->getNamespace() == &ns);
1151 fmap.update(fe->getName(), fe);
1155 DLLLOCAL
bool runtimeExistsFunctionIntern(
const char* name) {
1156 return fmap.find(name) != fmap.end();
1159 DLLLOCAL
const QoreClass* runtimeFindClassIntern(
const char* name,
const qore_ns_private*& ns)
const {
1160 clmap_t::const_iterator i = clmap.find(name);
1162 if (i != clmap.end()) {
1166 return i->second.obj;
1172 DLLLOCAL
const QoreClass* runtimeFindClassIntern(
const NamedScope& name,
const qore_ns_private*& ns)
const;
1174 DLLLOCAL
const TypedHashDecl* runtimeFindHashDeclIntern(
const char* name,
const qore_ns_private*& ns) {
1175 thdmap_t::iterator i = thdmap.find(name);
1177 if (i != thdmap.end()) {
1181 return i->second.obj;
1187 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntryIntern(
const char* name) {
1188 fmap_t::const_iterator i = fmap.find(name);
1189 return i != fmap.end() ? i->second.obj :
nullptr;
1192 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntryIntern(
const NamedScope& name);
1194 DLLLOCAL FunctionEntry* parseFindFunctionEntryIntern(
const char* name) {
1197 qore_ns_private* nscx = parse_get_ns();
1199 FunctionEntry* fe = nscx->func_list.findNode(name);
1205 fmap_t::iterator i = fmap.find(name);
1206 fmap_t::iterator ip = pend_fmap.find(name);
1208 if (i != fmap.end()) {
1209 if (ip != pend_fmap.end()) {
1210 if (i->second.depth() < ip->second.depth())
1211 return i->second.obj;
1213 return ip->second.obj;
1216 return i->second.obj;
1219 if (ip != pend_fmap.end())
1220 return ip->second.obj;
1225 DLLLOCAL QoreFunction* parseFindFunctionIntern(
const char* name) {
1226 FunctionEntry* fe = parseFindFunctionEntryIntern(name);
1227 return !fe ? 0 : fe->getFunction();
1230 DLLLOCAL
const FunctionEntry* parseResolveFunctionEntryIntern(
const QoreProgramLocation* loc,
const char* fname) {
1231 QORE_TRACE(
"qore_root_ns_private::parseResolveFunctionEntryIntern()");
1233 const FunctionEntry* f = parseFindFunctionEntryIntern(fname);
1236 parse_error(*loc,
"function '%s()' cannot be found", fname);
1245 DLLLOCAL
void parseCommit() {
1247 for (fmap_t::iterator i = pend_fmap.begin(), e = pend_fmap.end(); i != e; ++i) {
1252 qore_ns_private::parseCommit();
1254 qore_ns_private::parseCommitRuntimeInit(
getProgram()->getParseExceptionSink());
1257 DLLLOCAL ConstantEntry* parseFindOnlyConstantEntryIntern(
const char* cname, qore_ns_private*& ns) {
1260 qore_ns_private* nscx = parse_get_ns();
1262 ConstantEntry* ce = nscx->constant.findEntry(cname);
1271 cnmap_t::iterator i = cnmap.find(cname);
1273 if (i != cnmap.end()) {
1275 return i->second.obj;;
1281 DLLLOCAL
QoreValue parseFindOnlyConstantValueIntern(
const QoreProgramLocation* loc,
const char* cname,
1282 const QoreTypeInfo*& typeInfo,
bool& found) {
1284 qore_ns_private* ns;
1285 ConstantEntry* ce = parseFindOnlyConstantEntryIntern(cname, ns);
1293 NamespaceParseContextHelper nspch(ns);
1294 return ce->get(loc, typeInfo, ns);
1297 DLLLOCAL
QoreValue parseFindConstantValueIntern(
const QoreProgramLocation* loc,
const char* cname,
1298 const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
1303 QoreValue rv = qore_class_private::parseFindConstantValue(pc, cname, typeInfo, found,
1304 pc ? qore_class_private::get(*pc) :
nullptr);
1310 QoreValue rv = parseFindOnlyConstantValueIntern(loc, cname, typeInfo, found);
1316 parse_error(*loc,
"constant '%s' cannot be resolved in any namespace", cname);
1323 fmap_t::iterator i = fmap.find(fname);
1324 if (i == fmap.end()) {
1325 xsink->
raiseException(
"NO-SUCH-FUNCTION",
"callback function '%s()' does not exist", fname);
1329 return i->second.obj->makeCallReference(get_runtime_location());
1332 DLLLOCAL
TypedHashDecl* parseFindScopedHashDeclIntern(
const NamedScope& nscope,
unsigned& matched);
1334 DLLLOCAL
TypedHashDecl* parseFindHashDeclIntern(
const char* hdname) {
1337 qore_ns_private* nscx = parse_get_ns();
1345 thdmap_t::iterator i = thdmap.find(hdname);
1347 if (i != thdmap.end()) {
1348 return i->second.obj;
1355 DLLLOCAL
QoreClass* parseFindScopedClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
1357 DLLLOCAL
QoreClass* parseFindScopedClassIntern(
const NamedScope& name,
unsigned& matched);
1358 DLLLOCAL
QoreClass* parseFindScopedClassWithMethodInternError(
const QoreProgramLocation* loc,
1359 const NamedScope& name,
bool error);
1360 DLLLOCAL
QoreClass* parseFindScopedClassWithMethodIntern(
const NamedScope& name,
unsigned& matched);
1362 DLLLOCAL
QoreClass* parseFindClassIntern(
const char* cname) {
1366 qore_ns_private* nscx = parse_get_ns();
1368 QoreClass* qc = nscx->parseFindLocalClass(cname);
1374 clmap_t::iterator i = clmap.find(cname);
1376 if (i != clmap.end()) {
1377 return i->second.obj;
1381 NamespaceDepthListIterator nhi(nshlist);
1382 while (nhi.next()) {
1383 QoreClass* qc = nhi.get()->findLoadClass(cname);
1392 DLLLOCAL
const QoreClass* runtimeFindClass(
const char* name)
const {
1393 clmap_t::const_iterator i = clmap.find(name);
1394 return i != clmap.end() ? i->second.obj :
nullptr;
1403 NamespaceMapIterator nmi(nsmap, name[0]);
1404 while (nmi.next()) {
1405 const qore_ns_private* rv = nmi.get()->runtimeMatchAddFunction(name, fnd);
1413 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"target function '%s' already exists in the given "
1414 "namespace", name.ostr);
1416 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"target namespace in '%s' does not exist", name.ostr);
1425 NamespaceMapIterator nmi(nsmap, name.get(0));
1426 while (nmi.next()) {
1427 const qore_ns_private* rv = nmi.get()->runtimeMatchAddClass(name, fnd);
1433 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"target class '%s' already exists in the given namespace",
1436 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"target namespace in '%s' does not exist", name.ostr);
1441 DLLLOCAL
void addConstant(qore_ns_private& ns,
const char* cname,
QoreValue value,
const QoreTypeInfo* typeInfo);
1443 DLLLOCAL
QoreValue parseFindReferencedConstantValueIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
1444 const QoreTypeInfo*& typeInfo,
bool& found,
bool error);
1446 DLLLOCAL
QoreValue parseResolveBarewordIntern(
const QoreProgramLocation* loc,
const char* bword,
1447 const QoreTypeInfo*& typeInfo,
bool& found);
1449 DLLLOCAL
QoreValue parseResolveReferencedScopedReferenceIntern(
const QoreProgramLocation* loc,
1450 const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found);
1452 DLLLOCAL
void parseAddConstantIntern(
const QoreProgramLocation* loc,
QoreNamespace& ns,
const NamedScope& name,
1455 DLLLOCAL
void parseAddClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreClass* oc);
1457 DLLLOCAL
void parseAddHashDeclIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
TypedHashDecl* hd);
1459 DLLLOCAL qore_ns_private* parseResolveNamespaceIntern(
const QoreProgramLocation* loc,
const NamedScope& nscope,
1460 qore_ns_private* sns);
1461 DLLLOCAL qore_ns_private* parseResolveNamespace(
const QoreProgramLocation* loc,
const NamedScope& nscope,
1462 qore_ns_private* sns);
1463 DLLLOCAL qore_ns_private* parseResolveNamespace(
const QoreProgramLocation* loc,
const NamedScope& nscope);
1465 DLLLOCAL
const FunctionEntry* parseResolveFunctionEntryIntern(
const NamedScope& nscope);
1467 DLLLOCAL Var* parseAddResolvedGlobalVarDefIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
1468 const QoreTypeInfo* typeInfo, qore_var_t type = VT_GLOBAL);
1469 DLLLOCAL Var* parseAddGlobalVarDefIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
1470 QoreParseTypeInfo* typeInfo, qore_var_t type = VT_GLOBAL);
1472 DLLLOCAL Var* parseCheckImplicitGlobalVarIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
1473 const QoreTypeInfo* typeInfo);
1475 DLLLOCAL Var* parseFindGlobalVarIntern(
const NamedScope& vname) {
1476 assert(vname.size() > 1);
1483 qore_ns_private* nscx = parse_get_ns();
1484 if (nscx && nscx->name == vname[0]) {
1485 QoreNamespace* vns = nscx->parseMatchNamespace(vname, match);
1486 if (vns && (rv = vns->priv->var_list.parseFindVar(vname.getIdentifier())))
1493 NamespaceMapIterator nmi(nsmap, vname[0]);
1494 while (nmi.next()) {
1495 QoreNamespace* vns = nmi.get()->parseMatchNamespace(vname, match);
1496 if (vns && (rv = vns->priv->var_list.parseFindVar(vname.getIdentifier())))
1504 DLLLOCAL Var* parseFindGlobalVarIntern(
const char* vname) {
1507 qore_ns_private* nscx = parse_get_ns();
1509 Var* v = nscx->var_list.parseFindVar(vname);
1519 varmap_t::iterator i = varmap.find(vname);
1521 if (i != varmap.end()) {
1522 return i->second.obj;
1528 DLLLOCAL Var* runtimeFindGlobalVar(
const NamedScope& nscope,
const qore_ns_private*& vns)
const;
1530 DLLLOCAL Var* runtimeFindGlobalVar(
const char* vname,
const qore_ns_private*& vns)
const {
1531 if (strstr(vname,
"::")) {
1532 NamedScope nscope(vname);
1533 return runtimeFindGlobalVar(nscope, vns);
1536 varmap_t::const_iterator i = varmap.find(vname);
1537 if (i != varmap.end()) {
1538 assert(i->second.ns);
1540 return i->second.obj;
1545 DLLLOCAL
const ConstantEntry* runtimeFindNamespaceConstant(
const NamedScope& nscope,
1546 const qore_ns_private*& cns)
const;
1548 DLLLOCAL
const ConstantEntry* runtimeFindNamespaceConstant(
const char* cname,
const qore_ns_private*& cns)
const {
1549 if (strstr(cname,
"::")) {
1550 NamedScope nscope(cname);
1551 return runtimeFindNamespaceConstant(nscope, cns);
1554 cnmap_t::const_iterator i = cnmap.find(cname);
1555 if (i != cnmap.end()) {
1556 assert(i->second.ns);
1558 return i->second.obj;
1563 DLLLOCAL
void runtimeImportGlobalVariable(qore_ns_private& tns, Var* v,
bool readonly,
ExceptionSink* xsink) {
1564 Var* var = tns.var_list.import(v, xsink, readonly);
1568 varmap.update(var->getName(), &tns, var);
1571 DLLLOCAL Var* runtimeCreateVar(qore_ns_private& vns,
const char* vname,
const QoreTypeInfo* typeInfo,
1573 Var* v = vns.var_list.runtimeCreateVar(vname, typeInfo, builtin);
1576 varmap.update(v->getName(), &vns, v);
1580 DLLLOCAL
bool parseResolveGlobalVarsAndClassHierarchiesIntern();
1583 DLLLOCAL
int parseAddMethodToClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
1584 MethodVariantBase* qcmethod,
bool static_flag);
1586 DLLLOCAL
static void rebuildConstantIndexes(cnmap_t& cnmap, ConstantList& cl, qore_ns_private* ns) {
1587 ConstantListIterator cli(cl);
1589 cnmap.update(cli.getName().c_str(), ns, cli.getEntry());
1592 DLLLOCAL
static void rebuildClassIndexes(clmap_t& clmap, QoreClassList& cl, qore_ns_private* ns) {
1593 ClassListIterator cli(cl);
1595 clmap.update(cli.getName(), ns, cli.get());
1598 DLLLOCAL
static void rebuildHashDeclIndexes(thdmap_t& thdmap, HashDeclList& hdl, qore_ns_private* ns) {
1599 HashDeclListIterator hdli(hdl);
1601 thdmap.update(hdli.getName(), ns, hdli.get());
1604 DLLLOCAL
static void rebuildFunctionIndexes(fmap_t& fmap, fl_map_t& flmap, qore_ns_private* ns) {
1605 for (fl_map_t::iterator i = flmap.begin(), e = flmap.end(); i != e; ++i) {
1606 assert(i->second->getNamespace() == ns);
1607 fmap.update(i->first, i->second);
1613 DLLLOCAL
void rebuildIndexes(qore_ns_private* ns) {
1615 rebuildFunctionIndexes(fmap, ns->func_list, ns);
1618 for (map_var_t::iterator i = ns->var_list.vmap.begin(), e = ns->var_list.vmap.end(); i != e; ++i)
1619 varmap.update(i->first, ns, i->second);
1622 rebuildConstantIndexes(cnmap, ns->constant, ns);
1625 rebuildClassIndexes(clmap, ns->classList, ns);
1628 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1637 DLLLOCAL
void parseRebuildIndexes(qore_ns_private* ns) {
1642 for (fl_map_t::iterator i = ns->func_list.begin(), e = ns->func_list.end(); i != e; ++i) {
1643 assert(i->second->getNamespace() == ns);
1644 pend_fmap.update(i->first, i->second);
1648 for (map_var_t::iterator i = ns->var_list.vmap.begin(), e = ns->var_list.vmap.end(); i != e; ++i)
1649 varmap.update(i->first, ns, i->second);
1652 rebuildConstantIndexes(cnmap, ns->constant, ns);
1655 rebuildClassIndexes(clmap, ns->classList, ns);
1658 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1687 NamespaceDepthList nshlist;
1690 gvlist_t pend_gvlist;
1692 DLLLOCAL qore_root_ns_private(
RootQoreNamespace* n_rns) : qore_ns_private(n_rns), rns(n_rns), qoreNS(nullptr) {
1700 : qore_ns_private(old, po, ns), pgm(pgm) {
1705 nsl.nsmap.insert(nsmap_t::value_type(
"Qore", qoreNS));
1706 qoreNS->priv->nsl.nsmap.insert(nsmap_t::value_type(
"Option",
new QoreNamespace(
"Option")));
1708 qoreNS = nsl.find(
"Qore");
1715 rebuildAllIndexes();
1718 DLLLOCAL ~qore_root_ns_private() {
1723 qore_root_ns_private* rpriv =
new qore_root_ns_private(*
this, po, pgm, rv);
1724 rv->priv = rv->rpriv = rpriv;
1729 DLLLOCAL
void rebuildAllIndexes() {
1734 QorePrivateNamespaceIterator qpni(
this);
1736 rebuildIndexes(qpni.get());
1739 DLLLOCAL
void deferParseCheckAbstractNew(
const qore_class_private* qc,
const QoreProgramLocation* loc) {
1740 deferred_new_check_vec.push_back(deferred_new_check_t(qc, loc));
1743 DLLLOCAL
QoreNamespace* runtimeFindNamespace(
const NamedScope& name) {
1745 NamespaceMapIterator nmi(nsmap, name[0]);
1746 while (nmi.next()) {
1747 const qore_ns_private* rv = nmi.get()->runtimeMatchNamespace(name);
1757 if (name.
bindex(
"::", 0) != -1) {
1758 NamedScope scope(name.
c_str());
1759 return runtimeFindNamespace(scope);
1762 return nsmap.findFirst(name.
c_str());
1765 DLLLOCAL
const QoreClass* runtimeFindScopedClassWithMethod(
const NamedScope& name)
const;
1766 DLLLOCAL
const QoreClass* runtimeFindScopedClassWithMethodIntern(
const NamedScope& name)
const;
1773 DLLLOCAL qore_ns_private* getQore() {
1774 return qoreNS->priv;
1777 DLLLOCAL
const qore_ns_private* getQore()
const {
1778 return qoreNS->priv;
1783 qore_ns_private::getGlobalVars(*rv);
1787 DLLLOCAL
void commitModule(QoreModuleContext& qmc) {
1788 for (
unsigned j = 0; j < qmc.mcnl.size(); ++j) {
1789 ModuleContextNamespaceCommit& mc = qmc.mcnl[j];
1790 mc.parent->addCommitNamespaceIntern(mc.nns);
1793 for (
unsigned j = 0; j < qmc.mcfl.size(); ++j) {
1794 ModuleContextFunctionCommit& mc = qmc.mcfl[j];
1795 mc.parent->addBuiltinVariantIntern(mc.name, mc.v);
1799 if (qmc.mcnl.size() || qmc.mcfl.size()) {
1800 rebuildAllIndexes();
1813 pend_gvlist.clear();
1819 deferred_new_check_vec.clear();
1821 qore_ns_private::parseRollback(xsink);
1824 DLLLOCAL
TypedHashDecl* parseFindHashDecl(
const QoreProgramLocation* loc,
const NamedScope& name);
1826 DLLLOCAL
const TypedHashDecl* runtimeFindHashDeclIntern(
const NamedScope& name,
const qore_ns_private*& ns);
1828 DLLLOCAL
QoreNamespace* runtimeFindCreateNamespacePath(
const NamedScope& nspath,
bool pub,
bool user) {
1829 assert(nspath.size());
1830 bool is_new =
false;
1833 nsmap.update(nns->priv);
1837 DLLLOCAL
QoreNamespace* runtimeFindCreateNamespacePath(
const qore_ns_private& ns,
bool user) {
1842 printd(5,
"qore_root_ns_private::runtimeFindCreateNamespacePath() this: %p ns: '%s'\n",
this,
1845 bool is_new =
false;
1847 assert(ns.name == nns->
getName());
1849 nsmap.update(nns->priv);
1853 DLLLOCAL
void runtimeRebuildConstantIndexes(qore_ns_private* ns) {
1854 rebuildConstantIndexes(cnmap, ns->constant, ns);
1857 DLLLOCAL
void runtimeRebuildClassIndexes(qore_ns_private* ns) {
1858 rebuildClassIndexes(clmap, ns->classList, ns);
1861 DLLLOCAL
void runtimeRebuildHashDeclIndexes(qore_ns_private* ns) {
1862 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1865 DLLLOCAL
void runtimeRebuildFunctionIndexes(qore_ns_private* ns) {
1866 rebuildFunctionIndexes(fmap, ns->func_list, ns);
1869 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindCall(
const char* name,
const QoreListNode* params,
1874 DLLLOCAL
int parseInit();
1876 DLLLOCAL class_vec_t runtimeFindAllClassesRegex(
const QoreString& pattern,
int re_opts,
1879 DLLLOCAL hashdecl_vec_t runtimeFindAllHashDeclsRegex(
const QoreString& pattern,
int re_opts,
1882 DLLLOCAL func_vec_t runtimeFindAllFunctionsRegex(
const QoreString& pattern,
int re_opts,
1885 DLLLOCAL ns_vec_t runtimeFindAllNamespacesRegex(
const QoreString& pattern,
int re_opts,
1888 DLLLOCAL gvar_vec_t runtimeFindAllGlobalVarsRegex(
const QoreString& pattern,
int re_opts,
1891 DLLLOCAL const_vec_t runtimeFindAllNamespaceConstantsRegex(
const QoreString& pattern,
int re_opts,
1895 return rns.rpriv->getGlobalVars();
1900 rns.priv->runtimeImportSystemClasses(*source.priv, *rns.rpriv, xsink);
1905 rns.priv->runtimeImportSystemHashDecls(*source.priv, *rns.rpriv, xsink);
1910 rns.priv->runtimeImportSystemConstants(*source.priv, *rns.rpriv, xsink);
1915 rns.priv->runtimeImportSystemFunctions(*source.priv, *rns.rpriv, xsink);
1919 const qore_ns_private& ns,
bool user) {
1920 return rns.rpriv->runtimeFindCreateNamespacePath(ns, user);
1924 const NamedScope& nspath,
bool pub,
bool user) {
1925 return rns.rpriv->runtimeFindCreateNamespacePath(nspath, pub, user);
1929 return rns.rpriv->copy(po, pgm);
1932 DLLLOCAL
static int addPendingVariant(qore_ns_private& nsp,
const char* name, AbstractQoreFunctionVariant* v) {
1933 return getRootNS()->rpriv->addPendingVariantIntern(nsp, name, v);
1936 DLLLOCAL
static int addPendingVariant(qore_ns_private& nsp,
const NamedScope& name,
1937 AbstractQoreFunctionVariant* v) {
1938 return getRootNS()->rpriv->addPendingVariantIntern(nsp, name, v);
1942 QoreFunction* u,
const char* new_name =
nullptr,
bool inject =
false) {
1943 return rns.rpriv->runtimeImportFunction(xsink, *ns.priv, u, new_name, inject);
1947 const QoreClass* c,
QoreProgram* spgm, q_setpub_t set_pub,
const char* new_name = 0,
bool inject =
false,
1948 const qore_class_private* injectedClass =
nullptr) {
1949 return rns.rpriv->runtimeImportClass(xsink, *ns.priv, c, spgm, set_pub, new_name, inject, injectedClass);
1954 return rns.rpriv->runtimeImportHashDecl(xsink, *ns.priv, c, spgm, set_pub, new_name);
1958 const qore_ns_private*& ns) {
1959 if (strstr(name,
"::")) {
1960 NamedScope nscope(name);
1961 return rns.rpriv->runtimeFindClassIntern(nscope, ns);
1963 return rns.rpriv->runtimeFindClassIntern(name, ns);
1967 const qore_ns_private*& ns) {
1968 if (strstr(name,
"::")) {
1969 NamedScope nscope(name);
1970 return rns.rpriv->runtimeFindHashDeclIntern(nscope, ns);
1972 return rns.rpriv->runtimeFindHashDeclIntern(name, ns);
1975 DLLLOCAL
static const QoreFunction* runtimeFindFunction(
RootQoreNamespace& rns,
const char* name,
1976 const qore_ns_private*& ns) {
1977 const FunctionEntry* fe = runtimeFindFunctionEntry(rns, name);
1979 ns = fe->getNamespace();
1980 return fe->getFunction();
1985 DLLLOCAL
static const FunctionEntry* runtimeFindFunctionEntry(
RootQoreNamespace& rns,
const char* name) {
1986 if (strstr(name,
"::")) {
1987 NamedScope nscope(name);
1988 return rns.rpriv->runtimeFindFunctionEntryIntern(nscope);
1990 return rns.rpriv->runtimeFindFunctionEntryIntern(name);
1993 DLLLOCAL
static bool runtimeExistsFunction(
RootQoreNamespace& rns,
const char* name) {
1994 return rns.rpriv->runtimeExistsFunctionIntern(name);
1997 DLLLOCAL
static void addConstant(qore_root_ns_private& rns, qore_ns_private& ns,
const char* cname,
1998 QoreValue value,
const QoreTypeInfo* typeInfo) {
1999 rns.addConstant(ns, cname, value, typeInfo);
2002 DLLLOCAL
static const QoreFunction* parseResolveFunction(
const QoreProgramLocation* loc,
const char* fname) {
2003 const FunctionEntry* fe = getRootNS()->rpriv->parseResolveFunctionEntryIntern(loc, fname);
2004 return fe ? fe->getFunction() :
nullptr;
2007 DLLLOCAL
static const FunctionEntry* parseResolveFunctionEntry(
const QoreProgramLocation* loc,
const char* fname) {
2008 return getRootNS()->rpriv->parseResolveFunctionEntryIntern(loc, fname);
2013 return getRootNS()->rpriv->parseResolveCallReferenceIntern(fr);
2016 DLLLOCAL
static bool parseResolveGlobalVarsAndClassHierarchies() {
2017 return getRootNS()->rpriv->parseResolveGlobalVarsAndClassHierarchiesIntern();
2021 rns.rpriv->parseCommit();
2024 DLLLOCAL
static QoreValue parseFindConstantValue(
const QoreProgramLocation* loc,
const char* name,
2025 const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
2027 return getRootNS()->rpriv->parseFindConstantValueIntern(loc, name, typeInfo, found, error);
2030 DLLLOCAL
static QoreValue parseFindReferencedConstantValue(
const QoreProgramLocation* loc,
const NamedScope& name,
2031 const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
2033 return getRootNS()->rpriv->parseFindReferencedConstantValueIntern(loc, name, typeInfo, found, error);
2036 DLLLOCAL
static QoreValue parseResolveBareword(
const QoreProgramLocation* loc,
const char* bword,
2037 const QoreTypeInfo*& typeInfo,
bool& found) {
2039 return getRootNS()->rpriv->parseResolveBarewordIntern(loc, bword, typeInfo, found);
2042 DLLLOCAL
static QoreValue parseResolveReferencedScopedReference(
const QoreProgramLocation* loc,
2043 const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found) {
2045 return getRootNS()->rpriv->parseResolveReferencedScopedReferenceIntern(loc, name, typeInfo, found);
2048 DLLLOCAL
static QoreClass* parseFindClass(
const QoreProgramLocation* loc,
const char* name,
2049 bool raise_error =
true) {
2050 QoreClass* qc = getRootNS()->rpriv->parseFindClassIntern(name);
2051 if (!qc && raise_error) {
2052 parse_error(*loc,
"reference to undefined class '%s'", name);
2057 DLLLOCAL
static QoreClass* parseFindScopedClass(
const QoreProgramLocation* loc,
const NamedScope& name,
2058 bool raise_error =
true) {
2059 return getRootNS()->rpriv->parseFindScopedClassIntern(loc, name, raise_error);
2062 DLLLOCAL
static QoreClass* parseFindScopedClassWithMethod(
const QoreProgramLocation* loc,
const NamedScope& name,
2064 return getRootNS()->rpriv->parseFindScopedClassWithMethodInternError(loc, name, error);
2067 DLLLOCAL
static void parseAddConstant(
const QoreProgramLocation* loc,
QoreNamespace& ns,
const NamedScope& name,
2069 getRootNS()->rpriv->parseAddConstantIntern(loc, ns, name, value, pub);
2073 DLLLOCAL
static int parseAddMethodToClass(
const QoreProgramLocation* loc,
const NamedScope& name,
2074 MethodVariantBase* qcmethod,
bool static_flag) {
2075 return getRootNS()->rpriv->parseAddMethodToClassIntern(loc, name, qcmethod, static_flag);
2078 DLLLOCAL
static void parseAddClass(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreClass* oc) {
2079 getRootNS()->rpriv->parseAddClassIntern(loc, name, oc);
2082 DLLLOCAL
static void parseAddHashDecl(
const QoreProgramLocation* loc,
const NamedScope& name,
TypedHashDecl* hd) {
2083 getRootNS()->rpriv->parseAddHashDeclIntern(loc, name, hd);
2086 DLLLOCAL
static void parseAddNamespace(
QoreNamespace* nns) {
2087 getRootNS()->rpriv->parseAddNamespaceIntern(nns);
2090 DLLLOCAL
static const QoreFunction* parseResolveFunction(
const NamedScope& nscope) {
2091 const FunctionEntry* fe = getRootNS()->rpriv->parseResolveFunctionEntryIntern(nscope);
2092 return fe ? fe->getFunction() :
nullptr;
2095 DLLLOCAL
static const FunctionEntry* parseResolveFunctionEntry(
const NamedScope& nscope) {
2096 return getRootNS()->rpriv->parseResolveFunctionEntryIntern(nscope);
2099 DLLLOCAL
const QoreClass* runtimeFindScopedClass(
const NamedScope& name)
const;
2103 return rns.rpriv->runtimeGetCallReference(name, xsink);
2106 DLLLOCAL
static Var* parseAddResolvedGlobalVarDef(
const QoreProgramLocation* loc,
const NamedScope& vname,
2107 const QoreTypeInfo* typeInfo, qore_var_t type = VT_GLOBAL) {
2108 return getRootNS()->rpriv->parseAddResolvedGlobalVarDefIntern(loc, vname, typeInfo, type);
2111 DLLLOCAL
static Var* parseAddGlobalVarDef(
const QoreProgramLocation* loc,
const NamedScope& vname,
2112 QoreParseTypeInfo* typeInfo, qore_var_t type = VT_GLOBAL) {
2113 return getRootNS()->rpriv->parseAddGlobalVarDefIntern(loc, vname, typeInfo, type);
2116 DLLLOCAL
static Var* parseCheckImplicitGlobalVar(
const QoreProgramLocation* loc,
const NamedScope& name,
2117 const QoreTypeInfo* typeInfo) {
2118 return getRootNS()->rpriv->parseCheckImplicitGlobalVarIntern(loc, name, typeInfo);
2121 DLLLOCAL
static Var* parseFindGlobalVar(
const char* vname) {
2122 return getRootNS()->rpriv->parseFindGlobalVarIntern(vname);
2125 DLLLOCAL
static Var* parseFindGlobalVar(
const NamedScope& nscope) {
2126 return getRootNS()->rpriv->parseFindGlobalVarIntern(nscope);
2130 ns.priv->scanMergeCommittedNamespace(*(mns.priv), qmc);
2134 ns.priv->copyMergeCommittedNamespace(*(mns.priv));
2137 ns.rpriv->rebuildAllIndexes();
2140 DLLLOCAL
static Var* runtimeFindGlobalVar(
const RootQoreNamespace& rns,
const char* vname,
const qore_ns_private*& vns) {
2141 return rns.rpriv->runtimeFindGlobalVar(vname, vns);
2144 DLLLOCAL
static Var* runtimeCreateVar(
RootQoreNamespace& rns,
QoreNamespace& vns,
const char* vname,
const QoreTypeInfo* typeInfo,
bool builtin =
false) {
2145 return rns.rpriv->runtimeCreateVar(*vns.priv, vname, typeInfo, builtin);
2149 return rns.rpriv->runtimeImportGlobalVariable(*tns.priv, v, readonly, xsink);
2162 return rns.rpriv->runtimeFindClass(name);
2165 DLLLOCAL
static const ConstantEntry* runtimeFindNamespaceConstant(
const RootQoreNamespace& rns,
const char* cname,
const qore_ns_private*& cns) {
2166 return rns.rpriv->runtimeFindNamespaceConstant(cname, cns);
2170 return rns.rpriv->runtimeFindNamespaceForAddFunction(name, xsink);
2174 return rns.rpriv->runtimeFindNamespaceForAddClass(name, xsink);
2186 return rns.rpriv->qoreNS->priv;
2190 return rns.rpriv->qoreNS->priv;
2194 ns.priv->clearConstants(l);
2195 ns.rpriv->cnmap.clear();
2199 ns.priv->clearData(xsink);
#define PO_NO_API
an alias of PO_INHERITANCE_OPTIONS
Definition: Restrictions.h:157
base class for call references, reference-counted, dynamically allocated only
Definition: CallReferenceNode.h:39
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
defines a Qore-language class
Definition: QoreClass.h:249
DLLEXPORT const char * getName() const
returns the class name
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:65
DLLEXPORT QoreNamespace * copy(int64 po=PO_DEFAULT) const
returns a deep copy of the namespace
DLLEXPORT void addConstant(const char *name, QoreValue value)
adds a constant definition to the namespace
DLLEXPORT const char * getName() const
returns the name of the namespace
DLLEXPORT QoreNamespace * findCreateNamespacePath(const char *nspath)
finds a Namespace based on the argument; creates it (or the whole path) if necessary
DLLEXPORT QoreNamespace(const char *n)
creates a namespace with the given name
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:127
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
DLLEXPORT qore_offset_t bindex(const QoreString &needle, qore_offset_t pos=0) const
returns the byte position of a substring within the string or -1 if not found
DLLEXPORT const char * c_str() const
returns the string's buffer; this data should not be changed
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
base class for resolved call references
Definition: CallReferenceNode.h:109
the root namespace of a QoreProgram object
Definition: QoreNamespace.h:397
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:118
typed hash declaration
Definition: TypedHashDecl.h:44
DLLEXPORT const char * getName() const
returns the name of the typed hash
an unresolved call reference, only present temporarily in the parse tree
Definition: CallReferenceNode.h:68
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:251
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:257
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
std::vector< QoreValue > arg_vec_t
vector of value information for default argument lists
Definition: common.h:254
static unsigned num_params(const QoreListNode *n)
returns the number of arguments passed to the function
Definition: params.h:54
DLLEXPORT QoreProgram * getProgram()
returns the current QoreProgram
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275