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;
58 QoreClassList classList;
59 HashDeclList hashDeclList;
60 ConstantList constant;
61 QoreNamespaceList nsl;
62 FunctionList func_list;
63 GlobalVariableList var_list;
64 gvblist_t pend_gvblist;
74 const qore_ns_private* parent =
nullptr;
75 q_ns_class_handler_t class_handler =
nullptr;
79 DLLLOCAL qore_ns_private(
QoreNamespace* n_ns,
const char* n) : name(n), constant(this), pub(true), builtin(true), ns(n_ns) {
83 DLLLOCAL qore_ns_private(
const char* n,
const qore_ns_private& old) : name(n), constant(this), pub(old.pub),
84 builtin(false), ns(new
QoreNamespace(this)), from_module(old.from_module) {
88 DLLLOCAL qore_ns_private(
const QoreProgramLocation* loc);
90 DLLLOCAL qore_ns_private(
const qore_ns_private& old,
int64 po)
92 classList(old.classList, po, this),
93 hashDeclList(old.hashDeclList, po, this),
94 constant(old.constant, po, this),
95 nsl(old.nsl, po, *this),
96 func_list(old.func_list, this, po),
97 var_list(old.var_list, po),
100 pub(old.builtin ? true : false),
101 builtin(old.builtin),
102 imported(old.imported),
103 class_handler(old.class_handler), ns(nullptr) {
104 if (!old.from_module.empty()) {
105 from_module = old.from_module;
111 DLLLOCAL ~qore_ns_private() {
114 DLLLOCAL
void getPath(std::string& str,
bool anchored =
false)
const {
115 const qore_ns_private* w = parent;
116 while (w && (anchored || w->parent)) {
119 str.insert(0, w->name);
127 DLLLOCAL
const char* getModuleName()
const {
128 return from_module.empty() ? nullptr : from_module.c_str();
131 DLLLOCAL
void getNsList(nslist_t& nsl)
const {
136 const qore_ns_private* w =
this;
137 while (w && w->parent) {
144 qore_ns_private* p =
new qore_ns_private(old, po);
149 DLLLOCAL
void purge() {
154 hashDeclList.reset();
159 DLLLOCAL qore_root_ns_private* getRoot() {
160 qore_ns_private* w =
this;
162 w = (qore_ns_private*)w->parent;
165 return w->root ?
reinterpret_cast<qore_root_ns_private*
>(w) :
nullptr;
168 DLLLOCAL
const qore_root_ns_private* getRoot()
const {
169 const qore_ns_private* w =
this;
171 w = (qore_ns_private*)w->parent;
174 return w->root ?
reinterpret_cast<const qore_root_ns_private*
>(w) :
nullptr;
179 DLLLOCAL
void setClassHandler(q_ns_class_handler_t n_class_handler);
182 DLLLOCAL
QoreClass* findLoadClass(
const char* cname) {
185 if (!qc && class_handler)
186 qc = class_handler(ns, cname);
193 var_list.getGlobalVars(path, h);
194 nsl.getGlobalVars(h);
199 DLLLOCAL
void deleteData(
bool deref_vars,
ExceptionSink* xsink);
205 DLLLOCAL
void updateDepthRecursive(
unsigned ndepth);
207 DLLLOCAL
int parseAddPendingClass(
const QoreProgramLocation* loc,
const NamedScope& n,
QoreClass* oc);
208 DLLLOCAL
int parseAddPendingClass(
const QoreProgramLocation* loc,
QoreClass* oc);
210 DLLLOCAL
int parseAddPendingHashDecl(
const QoreProgramLocation* loc,
const NamedScope& n,
TypedHashDecl* hashdecl);
211 DLLLOCAL
int parseAddPendingHashDecl(
const QoreProgramLocation* loc,
TypedHashDecl* hashdecl);
213 DLLLOCAL
bool addGlobalVars(qore_root_ns_private& rns);
215 DLLLOCAL cnemap_t::iterator parseAddConstant(
const QoreProgramLocation* loc,
const char* name,
QoreValue value,
bool pub);
217 DLLLOCAL
void parseAddConstant(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreValue value,
bool pub);
219 DLLLOCAL
int parseAddMethodToClass(
const QoreProgramLocation* loc,
const NamedScope& name, MethodVariantBase* qcmethod,
bool static_flag);
221 DLLLOCAL
int checkImportFunction(
const char* name,
ExceptionSink* xsink) {
224 if (func_list.findNode(name)) {
225 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"function '%s' already exists in this namespace", name);
232 DLLLOCAL FunctionEntry* runtimeImportFunction(
ExceptionSink* xsink, QoreFunction* u,
const char* new_name =
nullptr,
bool inject =
false) {
233 const char* fn = new_name ? new_name : u->getName();
234 if (checkImportFunction(fn, xsink))
237 return func_list.import(fn, u,
this, inject);
240 DLLLOCAL
int checkImportClass(
const char* cname,
ExceptionSink* xsink) {
243 if (classList.find(cname)) {
244 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"class '%s' already exists in namespace '%s'", cname, name.c_str());
247 if (hashDeclList.find(cname)) {
248 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"hashdecl '%s' already exists in namespace '%s'", cname, name.c_str());
251 if (nsl.find(cname)) {
252 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"a subnamespace named '%s' already exists in namespace '%s'", cname, name.c_str());
259 DLLLOCAL
int checkImportHashDecl(
const char* hdname,
ExceptionSink* xsink) {
262 if (hashDeclList.find(hdname)) {
263 xsink->
raiseException(
"HASHDECL-IMPORT-ERROR",
"hashdecl '%s' already exists in namespace '%s'", hdname, name.c_str());
266 if (classList.find(hdname)) {
267 xsink->
raiseException(
"HASHDECL-IMPORT-ERROR",
"class '%s' already exists in namespace '%s'", hdname, name.c_str());
274 DLLLOCAL
QoreClass* runtimeImportClass(
ExceptionSink* xsink,
const QoreClass* c,
QoreProgram* spgm, q_setpub_t set_pub,
const char* new_name =
nullptr,
bool inject =
false,
const qore_class_private* injectedClass =
nullptr);
278 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntry(
const char* name) {
279 return func_list.findNode(name,
true);
282 DLLLOCAL
const QoreFunction* runtimeFindFunction(
const char* name) {
283 return func_list.find(name,
true);
286 DLLLOCAL
const QoreFunction* findAnyFunction(
const char* name) {
287 return func_list.find(name,
false);
290 DLLLOCAL
QoreNamespace* findCreateNamespace(
const char* nme,
bool user,
bool& is_new, qore_root_ns_private* rns);
291 DLLLOCAL
QoreNamespace* findCreateNamespacePath(
const nslist_t& nsl,
bool user,
bool& is_new);
292 DLLLOCAL
QoreNamespace* findCreateNamespacePath(
const NamedScope& nspath,
bool pub,
bool user,
bool& is_new,
int ignore_end = 1);
294 DLLLOCAL
TypedHashDecl* parseFindLocalHashDecl(
const char* name) {
295 return hashDeclList.find(name);
298 DLLLOCAL
QoreValue getConstantValue(
const char* name,
const QoreTypeInfo*& typeInfo,
bool& found);
299 DLLLOCAL
QoreClass* parseFindLocalClass(
const char* name);
300 DLLLOCAL qore_ns_private* parseAddNamespace(
QoreNamespace* nns);
302 DLLLOCAL
void addModuleNamespace(qore_ns_private* nns, QoreModuleContext& qmc);
303 DLLLOCAL
void addCommitNamespaceIntern(qore_ns_private* nns);
304 DLLLOCAL
void addNamespace(qore_ns_private* nns);
306 DLLLOCAL
void parseInit();
307 DLLLOCAL
void parseResolveHierarchy();
308 DLLLOCAL
void parseResolveClassMembers();
309 DLLLOCAL
void parseResolveAbstract();
310 DLLLOCAL
void parseInitConstants();
312 DLLLOCAL
void parseCommit();
315 DLLLOCAL Var* runtimeMatchGlobalVar(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
316 DLLLOCAL
const ConstantEntry* runtimeMatchNamespaceConstant(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
317 DLLLOCAL
const QoreClass* runtimeMatchScopedClassWithMethod(
const NamedScope& nscope)
const;
318 DLLLOCAL
const QoreClass* runtimeMatchClass(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
319 DLLLOCAL
const qore_ns_private* runtimeMatchNamespace(
const NamedScope& nscope,
int offset = 0)
const;
320 DLLLOCAL
const qore_ns_private* runtimeMatchAddClass(
const NamedScope& nscope,
bool& fnd)
const;
322 DLLLOCAL
const TypedHashDecl* runtimeMatchHashDecl(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
324 DLLLOCAL
const FunctionEntry* runtimeMatchFunctionEntry(
const NamedScope& nscope)
const;
325 DLLLOCAL
const qore_ns_private* runtimeMatchAddFunction(
const NamedScope& nscope,
bool& fnd)
const;
329 DLLLOCAL
const FunctionEntry* parseMatchFunctionEntry(
const NamedScope& nscope,
unsigned& match)
const;
331 DLLLOCAL
QoreNamespace* resolveNameScope(
const QoreProgramLocation* loc,
const NamedScope& name)
const;
332 DLLLOCAL
QoreNamespace* parseMatchNamespace(
const NamedScope& nscope,
unsigned& matched)
const;
334 DLLLOCAL
TypedHashDecl* parseMatchScopedHashDecl(
const NamedScope& name,
unsigned& matched);
336 DLLLOCAL
QoreClass* parseMatchScopedClass(
const NamedScope& name,
unsigned& matched);
337 DLLLOCAL
QoreClass* parseMatchScopedClassWithMethod(
const NamedScope& nscope,
unsigned& matched);
339 DLLLOCAL
QoreValue parseCheckScopedReference(
const QoreProgramLocation* loc,
const NamedScope& ns,
unsigned& m,
const QoreTypeInfo*& typeInfo,
bool& found,
bool abr)
const;
341 DLLLOCAL
QoreValue parseFindLocalConstantValue(
const QoreProgramLocation* loc,
const NamedScope& ns,
unsigned& m,
const QoreTypeInfo*& typeInfo,
bool& found,
bool abr)
const;
343 DLLLOCAL
QoreValue parseFindLocalConstantValue(
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found);
344 DLLLOCAL
QoreNamespace* parseFindLocalNamespace(
const char* nname);
346 DLLLOCAL
QoreValue parseMatchScopedConstantValue(
const NamedScope& name,
unsigned& matched,
const QoreTypeInfo*& typeInfo,
bool& found);
348 DLLLOCAL FunctionEntry* addPendingVariantIntern(
const char* fname, AbstractQoreFunctionVariant* v,
bool& new_func);
350 DLLLOCAL
void addBuiltinVariant(
const char* name, AbstractQoreFunctionVariant* v);
351 DLLLOCAL
void addBuiltinModuleVariant(
const char* name, AbstractQoreFunctionVariant* v, QoreModuleContext& qmc);
352 DLLLOCAL
void addBuiltinVariantIntern(
const char* name, AbstractQoreFunctionVariant* v);
354 template <
typename T,
class B>
355 DLLLOCAL
void addBuiltinVariant(
const char* name, T f,
int64 flags,
int64 functional_domain,
const QoreTypeInfo* returnTypeInfo,
unsigned num_params, va_list args) {
361 qore_process_params(
num_params, typeList, defaultArgList, nameList, args);
364 addBuiltinVariant(name,
new B(f, flags, functional_domain, returnTypeInfo, typeList, defaultArgList, nameList));
367 template <
typename T,
class B>
368 DLLLOCAL
void addBuiltinVariant(
void* ptr,
const char* name, T f,
int64 flags,
int64 functional_domain,
const QoreTypeInfo* returnTypeInfo,
unsigned num_params, va_list args) {
374 qore_process_params(
num_params, typeList, defaultArgList, nameList, args);
377 addBuiltinVariant(name,
new B(ptr, f, flags, functional_domain, returnTypeInfo, typeList, defaultArgList, nameList));
380 DLLLOCAL
void scanMergeCommittedNamespace(
const qore_ns_private& mns, QoreModuleContext& qmc)
const;
381 DLLLOCAL
void copyMergeCommittedNamespace(
const qore_ns_private& mns);
383 DLLLOCAL
void parseInitGlobalVars();
385 DLLLOCAL
void checkGlobalVarDecl(Var* v,
const NamedScope& vname);
386 DLLLOCAL
void parseAddGlobalVarDecl(
const QoreProgramLocation* loc,
char* name,
const QoreTypeInfo* typeInfo, QoreParseTypeInfo* parseTypeInfo,
bool pub);
388 DLLLOCAL
void setPublic();
390 DLLLOCAL
void runtimeImportSystemClasses(
const qore_ns_private& source, qore_root_ns_private& rns,
ExceptionSink* xsink);
391 DLLLOCAL
void runtimeImportSystemHashDecls(
const qore_ns_private& source, qore_root_ns_private& rns,
ExceptionSink* xsink);
392 DLLLOCAL
void runtimeImportSystemConstants(
const qore_ns_private& source, qore_root_ns_private& rns,
ExceptionSink* xsink);
393 DLLLOCAL
void runtimeImportSystemFunctions(
const qore_ns_private& source, qore_root_ns_private& rns,
ExceptionSink* xsink);
396 ns.priv->addNamespace(nns->priv);
399 DLLLOCAL
static QoreValue parseResolveReferencedClassConstant(
const QoreProgramLocation* loc,
QoreClass* qc,
const char* name,
const QoreTypeInfo*& typeInfo,
bool& found);
401 DLLLOCAL
static ConstantList& getConstantList(
const QoreNamespace* ns) {
402 return ns->priv->constant;
405 DLLLOCAL
static const QoreFunction* runtimeFindFunction(
QoreNamespace& ns,
const char* name) {
406 return ns.priv->runtimeFindFunction(name);
409 DLLLOCAL
static const FunctionEntry* runtimeFindFunctionEntry(
QoreNamespace& ns,
const char* name) {
410 return ns.priv->runtimeFindFunctionEntry(name);
414 return ns.priv->func_list.getList();
417 DLLLOCAL
static void parseAddPendingClass(
QoreNamespace& ns,
const QoreProgramLocation* loc,
const NamedScope& n,
QoreClass* oc) {
418 ns.priv->parseAddPendingClass(loc, n, oc);
422 ns.priv->parseAddNamespace(nns);
425 DLLLOCAL
static void parseAddConstant(
QoreNamespace& ns,
const QoreProgramLocation* loc,
const NamedScope& name,
QoreValue value,
bool pub) {
426 ns.priv->parseAddConstant(loc, name, value, pub);
430 ns.priv->parseCommit();
441 DLLLOCAL
static const qore_ns_private* get(
const QoreNamespace& ns) {
450 return ns.priv->pub && !ns.priv->builtin;
455 DLLLOCAL qore_ns_private(
const qore_ns_private&) =
delete;
457 DLLLOCAL qore_ns_private& operator=(
const qore_ns_private&) =
delete;
461 std::string from_module;
464 DLLLOCAL qore_ns_private(
QoreNamespace* n_ns) : constant(this), root(true), pub(true), builtin(true),
468 DLLLOCAL
void setModuleName() {
469 assert(from_module.empty());
470 const char* mod_name = get_module_context_name();
472 from_module = mod_name;
478 hashdecl namespace_iterator_element {
482 DLLLOCAL namespace_iterator_element(qore_ns_private* ns) : ns(ns) {
485 i = ns->nsl.nsmap.begin();
488 DLLLOCAL
bool atEnd()
const {
489 return i == ns->nsl.nsmap.end();
501 class QorePrivateNamespaceIterator {
503 typedef std::vector<namespace_iterator_element> nsv_t;
505 qore_ns_private* root;
507 DLLLOCAL
void set(qore_ns_private* rns) {
508 nsv.push_back(namespace_iterator_element(rns));
511 while (!(rns->nsl.empty())) {
512 rns = qore_ns_private::get(*((rns->nsl.nsmap.begin()->second)));
514 nsv.push_back(namespace_iterator_element(rns));
519 DLLLOCAL QorePrivateNamespaceIterator(qore_ns_private* rns) : root(rns) {
523 DLLLOCAL
bool next() {
530 namespace_iterator_element* nie = &(nsv.back());
543 set(qore_ns_private::get(*next));
548 DLLLOCAL qore_ns_private* operator->() {
549 return nsv.back().ns;
552 DLLLOCAL qore_ns_private* operator*() {
553 return nsv.back().ns;
556 DLLLOCAL qore_ns_private* get() {
557 return nsv.back().ns;
561 hashdecl NSOInfoBase {
562 qore_ns_private* ns =
nullptr;
564 DLLLOCAL NSOInfoBase() {
567 DLLLOCAL NSOInfoBase(qore_ns_private* n_ns) : ns(n_ns) {
570 DLLLOCAL
unsigned depth()
const {
575 template <
typename T>
576 hashdecl NSOInfo :
public NSOInfoBase {
583 DLLLOCAL NSOInfo(qore_ns_private* n_ns, T* n_obj) : NSOInfoBase(n_ns), obj(n_obj) {
586 DLLLOCAL
void assign(qore_ns_private* n_ns, T* n_obj) {
593 template <
typename T>
594 class RootMap :
public std::map<const std::string, NSOInfo<T>> {
597 DLLLOCAL RootMap(
const RootMap& old);
599 DLLLOCAL RootMap& operator=(
const RootMap& m);
602 typedef NSOInfo<T> info_t;
603 typedef std::map<const std::string, NSOInfo<T>> map_t;
608 DLLLOCAL
void update(
const std::string& name, qore_ns_private* ns, T* obj) {
610 typename map_t::iterator i = this->lower_bound(name);
611 if (i == this->end() || i->first != name) {
612 this->insert(i,
typename map_t::value_type(name, info_t(ns, obj)));
614 if (i->second.depth() > ns->depth) {
615 i->second.assign(ns, obj);
620 DLLLOCAL
void update(
typename map_t::const_iterator ni) {
622 typename map_t::iterator i = this->lower_bound(ni->first);
623 if (i == this->end() || i->first != ni->first) {
625 this->insert(i,
typename map_t::value_type(ni->first, ni->second));
628 if (i->second.depth() > ni->second.depth()) {
630 i->second = ni->second;
637 T* findObj(
const std::string& name) {
638 typename map_t::iterator i = this->find(name);
639 return i == this->end() ? nullptr : i->second.obj;
643 hashdecl FunctionEntryInfo {
644 FunctionEntry* obj =
nullptr;
646 DLLLOCAL FunctionEntryInfo() {
649 DLLLOCAL FunctionEntryInfo(FunctionEntry* o) : obj(o) {
652 DLLLOCAL
unsigned depth()
const {
653 return getNamespace()->depth;
656 DLLLOCAL qore_ns_private* getNamespace()
const {
657 return obj->getNamespace();
660 DLLLOCAL
void assign(FunctionEntry* n_obj) {
666 typedef std::map<const char*, FunctionEntryInfo, ltstr> femap_t;
667 class FunctionEntryRootMap :
public femap_t {
670 DLLLOCAL FunctionEntryRootMap(
const FunctionEntryRootMap& old);
672 DLLLOCAL FunctionEntryRootMap& operator=(
const FunctionEntryRootMap& m);
675 DLLLOCAL FunctionEntryRootMap() {
678 DLLLOCAL
void update(
const char* name, FunctionEntry* obj) {
680 femap_t::iterator i = find(name);
682 insert(femap_t::value_type(name, FunctionEntryInfo(obj)));
684 if (i->second.depth() > obj->getNamespace()->depth)
685 i->second.assign(obj);
688 DLLLOCAL
void update(femap_t::const_iterator ni) {
690 femap_t::iterator i = find(ni->first);
693 insert(femap_t::value_type(ni->first, ni->second));
697 if (i->second.depth() > ni->second.depth()) {
699 i->second = ni->second;
706 FunctionEntry* findObj(
const char* name) {
707 femap_t::iterator i = find(name);
708 return i == end() ? 0 : i->second.obj;
712 class NamespaceDepthList {
713 friend class NamespaceDepthListIterator;
716 typedef std::multimap<unsigned, qore_ns_private*> nsdmap_t;
720 DLLLOCAL NamespaceDepthList() {
723 DLLLOCAL
void add(qore_ns_private* ns) {
724 nsdmap.insert(nsdmap_t::value_type(ns->depth, ns));
727 DLLLOCAL
void clear() {
732 class NamespaceDepthListIterator {
733 NamespaceDepthList::nsdmap_t::iterator i, e;
735 DLLLOCAL NamespaceDepthListIterator(NamespaceDepthList& m) : i(m.nsdmap.begin()), e(m.nsdmap.end()) {
738 DLLLOCAL
bool next() {
745 DLLLOCAL qore_ns_private* get()
const {
752 friend class NamespaceMapIterator;
753 friend class ConstNamespaceMapIterator;
754 friend class ConstAllNamespacesIterator;
758 typedef std::multimap<unsigned, qore_ns_private*> nsdmap_t;
761 typedef vector_map_t<const char*, nsdmap_t> nsmap_t;
764 typedef vector_map_t<qore_ns_private*, unsigned> nsrmap_t;
770 DLLLOCAL NamespaceMap(
const NamespaceMap& old);
772 DLLLOCAL NamespaceMap& operator=(
const NamespaceMap& m);
775 DLLLOCAL NamespaceMap() {
778 DLLLOCAL
void update(qore_ns_private* ns) {
780 nsrmap_t::iterator ri = nsrmap.find(ns);
781 if (ri != nsrmap.end()) {
783 if (ns->depth == ri->second)
787 nsmap_t::iterator i = nsmap.find(ns->name.c_str());
788 assert(i != nsmap.end());
791 nsdmap_t::iterator di = i->second.find(ri->second);
792 assert(di != i->second.end());
801 i->second.insert(nsdmap_t::value_type(ns->depth, ns));
807 nsmap_t::iterator i = nsmap.find(ns->name.c_str());
808 if (i == nsmap.end())
809 i = nsmap.insert(nsmap_t::value_type(ns->name.c_str(), nsdmap_t())).first;
811 i->second.insert(nsdmap_t::value_type(ns->depth, ns));
815 nsrmap.insert(nsrmap_t::value_type(ns, ns->depth));
818 DLLLOCAL
void commit(NamespaceMap& pend) {
820 for (nsrmap_t::iterator i = pend.nsrmap.begin(), e = pend.nsrmap.end(); i != e; ++i)
825 DLLLOCAL
void clear() {
832 nsmap_t::iterator mi = nsmap.find(name);
833 if (mi != nsmap.end()) {
834 nsdmap_t::iterator i = mi->second.begin();
835 if (i != mi->second.end()) {
836 return i->second->ns;
843 class NamespaceMapIterator {
845 NamespaceMap::nsmap_t::iterator mi;
846 NamespaceMap::nsdmap_t::iterator i;
850 DLLLOCAL NamespaceMapIterator(NamespaceMap& nsm,
const char* name) : mi(nsm.nsmap.find(name)), valid(mi != nsm.nsmap.end()) {
852 i = mi->second.end();
855 DLLLOCAL
bool next() {
859 if (i == mi->second.end())
860 i = mi->second.begin();
864 return i != mi->second.end();
867 DLLLOCAL qore_ns_private* get() {
872 class ConstNamespaceMapIterator {
874 NamespaceMap::nsmap_t::const_iterator mi;
875 NamespaceMap::nsdmap_t::const_iterator i;
879 DLLLOCAL ConstNamespaceMapIterator(
const NamespaceMap& nsm,
const char* name) : mi(nsm.nsmap.find(name)), valid(mi != nsm.nsmap.end()) {
881 i = mi->second.end();
884 DLLLOCAL
bool next() {
888 if (i == mi->second.end())
889 i = mi->second.begin();
893 return i != mi->second.end();
896 DLLLOCAL
const qore_ns_private* get() {
901 class ConstAllNamespacesIterator {
903 DLLLOCAL ConstAllNamespacesIterator(
const NamespaceMap& nsmap) : nsrmap(nsmap.nsrmap), i(nsmap.nsrmap.end()) {
906 DLLLOCAL
bool next() {
907 if (i == nsrmap.end()) {
914 return i != nsrmap.end();
918 assert(i != nsrmap.end());
923 const NamespaceMap::nsrmap_t& nsrmap;
924 NamespaceMap::nsrmap_t::const_iterator i;
927 typedef FunctionEntryRootMap fmap_t;
929 typedef RootMap<ConstantEntry> cnmap_t;
931 typedef RootMap<QoreClass> clmap_t;
933 typedef RootMap<TypedHashDecl> thdmap_t;
935 typedef RootMap<Var> varmap_t;
937 hashdecl deferred_new_check_t {
938 const qore_class_private* qc;
939 const QoreProgramLocation* loc;
941 DLLLOCAL deferred_new_check_t(
const qore_class_private* qc,
const QoreProgramLocation* loc) : qc(qc), loc(loc) {
945 class qore_root_ns_private :
public qore_ns_private {
946 friend class qore_ns_private;
950 typedef std::vector<deferred_new_check_t> deferred_new_check_vec_t;
951 deferred_new_check_vec_t deferred_new_check_vec;
953 DLLLOCAL
int addPendingVariantIntern(qore_ns_private& ns,
const char* name, AbstractQoreFunctionVariant* v) {
955 bool new_func =
false;
956 FunctionEntry* fe = ns.addPendingVariantIntern(name, v, new_func);
960 assert(fe->getNamespace() == &ns);
963 fmap_t::iterator i = fmap.find(fe->getName());
965 if (i == fmap.end() || i->second.depth() > ns.depth)
966 pend_fmap.update(fe->getName(), fe);
972 DLLLOCAL
int addPendingVariantIntern(qore_ns_private& ns,
const NamedScope& nscope, AbstractQoreFunctionVariant* v) {
973 assert(nscope.size() > 1);
977 for (
unsigned i = 0; i < nscope.size() - 1; ++i) {
978 fns = fns->priv->parseFindLocalNamespace(nscope[i]);
980 parse_error(*v->getUserVariantBase()->getUserSignature()->getParseLocation(),
"cannot find namespace '%s::' in '%s()' as a child of namespace '%s::'", nscope[i], nscope.ostr, ns.name.c_str());
985 return addPendingVariantIntern(*fns->priv, nscope.getIdentifier(), vh.release());
989 DLLLOCAL
int runtimeImportClass(
ExceptionSink* xsink, qore_ns_private& ns,
const QoreClass* c,
QoreProgram* spgm, q_setpub_t set_pub,
const char* new_name =
nullptr,
bool inject =
false,
const qore_class_private* injectedClass =
nullptr) {
990 QoreClass* nc = ns.runtimeImportClass(xsink, c, spgm, set_pub, new_name, inject, injectedClass);
996 clmap.update(nc->
getName(), &ns, nc);
1002 TypedHashDecl* nhd = ns.runtimeImportHashDecl(xsink, hd, spgm, set_pub, new_name);
1008 thdmap.update(nhd->
getName(), &ns, nhd);
1013 DLLLOCAL
int runtimeImportFunction(
ExceptionSink* xsink, qore_ns_private& ns, QoreFunction* u,
const char* new_name =
nullptr,
bool inject =
false) {
1014 FunctionEntry* fe = ns.runtimeImportFunction(xsink, u, new_name, inject);
1018 assert(fe->getNamespace() == &ns);
1022 fmap.update(fe->getName(), fe);
1026 DLLLOCAL
bool runtimeExistsFunctionIntern(
const char* name) {
1027 return fmap.find(name) != fmap.end();
1030 DLLLOCAL
const QoreClass* runtimeFindClassIntern(
const char* name,
const qore_ns_private*& ns)
const {
1031 clmap_t::const_iterator i = clmap.find(name);
1033 if (i != clmap.end()) {
1036 return i->second.obj;
1042 DLLLOCAL
const QoreClass* runtimeFindClassIntern(
const NamedScope& name,
const qore_ns_private*& ns)
const;
1044 DLLLOCAL
const TypedHashDecl* runtimeFindHashDeclIntern(
const char* name,
const qore_ns_private*& ns) {
1045 thdmap_t::iterator i = thdmap.find(name);
1047 if (i != thdmap.end()) {
1050 return i->second.obj;
1056 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntryIntern(
const char* name) {
1057 fmap_t::const_iterator i = fmap.find(name);
1058 return i != fmap.end() ? i->second.obj :
nullptr;
1061 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntryIntern(
const NamedScope& name);
1063 DLLLOCAL FunctionEntry* parseFindFunctionEntryIntern(
const char* name) {
1066 qore_ns_private* nscx = parse_get_ns();
1068 FunctionEntry* fe = nscx->func_list.findNode(name);
1074 fmap_t::iterator i = fmap.find(name);
1075 fmap_t::iterator ip = pend_fmap.find(name);
1077 if (i != fmap.end()) {
1078 if (ip != pend_fmap.end()) {
1079 if (i->second.depth() < ip->second.depth())
1080 return i->second.obj;
1082 return ip->second.obj;
1085 return i->second.obj;
1088 if (ip != pend_fmap.end())
1089 return ip->second.obj;
1094 DLLLOCAL QoreFunction* parseFindFunctionIntern(
const char* name) {
1095 FunctionEntry* fe = parseFindFunctionEntryIntern(name);
1096 return !fe ? 0 : fe->getFunction();
1099 DLLLOCAL
const FunctionEntry* parseResolveFunctionEntryIntern(
const QoreProgramLocation* loc,
const char* fname) {
1100 QORE_TRACE(
"qore_root_ns_private::parseResolveFunctionEntryIntern()");
1102 const FunctionEntry* f = parseFindFunctionEntryIntern(fname);
1105 parse_error(*loc,
"function '%s()' cannot be found", fname);
1113 DLLLOCAL
void parseCommit() {
1115 for (fmap_t::iterator i = pend_fmap.begin(), e = pend_fmap.end(); i != e; ++i)
1119 qore_ns_private::parseCommit();
1121 qore_ns_private::parseCommitRuntimeInit(
getProgram()->getParseExceptionSink());
1124 DLLLOCAL ConstantEntry* parseFindOnlyConstantEntryIntern(
const char* cname, qore_ns_private*& ns) {
1127 qore_ns_private* nscx = parse_get_ns();
1129 ConstantEntry* ce = nscx->constant.findEntry(cname);
1138 cnmap_t::iterator i = cnmap.find(cname);
1140 if (i != cnmap.end()) {
1142 return i->second.obj;;
1148 DLLLOCAL
QoreValue parseFindOnlyConstantValueIntern(
const QoreProgramLocation* loc,
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found) {
1150 qore_ns_private* ns;
1151 ConstantEntry* ce = parseFindOnlyConstantEntryIntern(cname, ns);
1158 NamespaceParseContextHelper nspch(ns);
1159 return ce->get(loc, typeInfo, ns);
1162 DLLLOCAL
QoreValue parseFindConstantValueIntern(
const QoreProgramLocation* loc,
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
1167 QoreValue rv = qore_class_private::parseFindConstantValue(pc, cname, typeInfo, found, pc ? qore_class_private::get(*pc) :
nullptr);
1173 QoreValue rv = parseFindOnlyConstantValueIntern(loc, cname, typeInfo, found);
1179 parse_error(*loc,
"constant '%s' cannot be resolved in any namespace", cname);
1186 fmap_t::iterator i = fmap.find(fname);
1187 if (i == fmap.end()) {
1188 xsink->
raiseException(
"NO-SUCH-FUNCTION",
"callback function '%s()' does not exist", fname);
1192 return i->second.obj->makeCallReference(get_runtime_location());
1195 DLLLOCAL
TypedHashDecl* parseFindScopedHashDeclIntern(
const NamedScope& nscope,
unsigned& matched);
1197 DLLLOCAL
TypedHashDecl* parseFindHashDeclIntern(
const char* hdname) {
1200 qore_ns_private* nscx = parse_get_ns();
1208 thdmap_t::iterator i = thdmap.find(hdname);
1210 if (i != thdmap.end()) {
1211 return i->second.obj;
1218 DLLLOCAL
QoreClass* parseFindScopedClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
bool raise_error);
1219 DLLLOCAL
QoreClass* parseFindScopedClassIntern(
const NamedScope& name,
unsigned& matched);
1220 DLLLOCAL
QoreClass* parseFindScopedClassWithMethodInternError(
const QoreProgramLocation* loc,
const NamedScope& name,
bool error);
1221 DLLLOCAL
QoreClass* parseFindScopedClassWithMethodIntern(
const NamedScope& name,
unsigned& matched);
1223 DLLLOCAL
QoreClass* parseFindClassIntern(
const char* cname) {
1227 qore_ns_private* nscx = parse_get_ns();
1229 QoreClass* qc = nscx->parseFindLocalClass(cname);
1235 clmap_t::iterator i = clmap.find(cname);
1237 if (i != clmap.end()) {
1238 return i->second.obj;
1242 NamespaceDepthListIterator nhi(nshlist);
1243 while (nhi.next()) {
1244 QoreClass* qc = nhi.get()->findLoadClass(cname);
1253 DLLLOCAL
const QoreClass* runtimeFindClass(
const char* name)
const {
1254 clmap_t::const_iterator i = clmap.find(name);
1255 return i != clmap.end() ? i->second.obj :
nullptr;
1263 NamespaceMapIterator nmi(nsmap, name[0]);
1264 while (nmi.next()) {
1265 const qore_ns_private* rv = nmi.get()->runtimeMatchAddFunction(name, fnd);
1272 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"target function '%s' already exists in the given namespace", name.ostr);
1274 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"target namespace in '%s' does not exist", name.ostr);
1282 NamespaceMapIterator nmi(nsmap, name.get(0));
1283 while (nmi.next()) {
1284 const qore_ns_private* rv = nmi.get()->runtimeMatchAddClass(name, fnd);
1290 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"target class '%s' already exists in the given namespace", name.ostr);
1292 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"target namespace in '%s' does not exist", name.ostr);
1296 DLLLOCAL
void addConstant(qore_ns_private& ns,
const char* cname,
QoreValue value,
const QoreTypeInfo* typeInfo);
1298 DLLLOCAL
QoreValue parseFindReferencedConstantValueIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found,
bool error);
1300 DLLLOCAL
QoreValue parseResolveBarewordIntern(
const QoreProgramLocation* loc,
const char* bword,
const QoreTypeInfo*& typeInfo,
bool& found);
1302 DLLLOCAL
QoreValue parseResolveReferencedScopedReferenceIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found);
1304 DLLLOCAL
void parseAddConstantIntern(
const QoreProgramLocation* loc,
QoreNamespace& ns,
const NamedScope& name,
QoreValue value,
bool pub);
1306 DLLLOCAL
void parseAddClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreClass* oc);
1308 DLLLOCAL
void parseAddHashDeclIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
TypedHashDecl* hd);
1310 DLLLOCAL qore_ns_private* parseResolveNamespaceIntern(
const QoreProgramLocation* loc,
const NamedScope& nscope, qore_ns_private* sns);
1311 DLLLOCAL qore_ns_private* parseResolveNamespace(
const QoreProgramLocation* loc,
const NamedScope& nscope, qore_ns_private* sns);
1312 DLLLOCAL qore_ns_private* parseResolveNamespace(
const QoreProgramLocation* loc,
const NamedScope& nscope);
1314 DLLLOCAL
const FunctionEntry* parseResolveFunctionEntryIntern(
const NamedScope& nscope);
1316 DLLLOCAL Var* parseAddResolvedGlobalVarDefIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo* typeInfo);
1317 DLLLOCAL Var* parseAddGlobalVarDefIntern(
const QoreProgramLocation* loc,
const NamedScope& name, QoreParseTypeInfo* typeInfo);
1319 DLLLOCAL Var* parseCheckImplicitGlobalVarIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo* typeInfo);
1321 DLLLOCAL Var* parseFindGlobalVarIntern(
const NamedScope& vname) {
1322 assert(vname.size() > 1);
1329 qore_ns_private* nscx = parse_get_ns();
1330 if (nscx && nscx->name == vname[0]) {
1331 QoreNamespace* vns = nscx->parseMatchNamespace(vname, match);
1332 if (vns && (rv = vns->priv->var_list.parseFindVar(vname.getIdentifier())))
1339 NamespaceMapIterator nmi(nsmap, vname[0]);
1340 while (nmi.next()) {
1341 QoreNamespace* vns = nmi.get()->parseMatchNamespace(vname, match);
1342 if (vns && (rv = vns->priv->var_list.parseFindVar(vname.getIdentifier())))
1350 DLLLOCAL Var* parseFindGlobalVarIntern(
const char* vname) {
1353 qore_ns_private* nscx = parse_get_ns();
1355 Var* v = nscx->var_list.parseFindVar(vname);
1363 varmap_t::iterator i = varmap.find(vname);
1365 if (i != varmap.end()) {
1366 return i->second.obj;
1372 DLLLOCAL Var* runtimeFindGlobalVar(
const NamedScope& nscope,
const qore_ns_private*& vns)
const;
1374 DLLLOCAL Var* runtimeFindGlobalVar(
const char* vname,
const qore_ns_private*& vns)
const {
1375 if (strstr(vname,
"::")) {
1376 NamedScope nscope(vname);
1377 return runtimeFindGlobalVar(nscope, vns);
1380 varmap_t::const_iterator i = varmap.find(vname);
1381 if (i != varmap.end()) {
1382 assert(i->second.ns);
1384 return i->second.obj;
1389 DLLLOCAL
const ConstantEntry* runtimeFindNamespaceConstant(
const NamedScope& nscope,
const qore_ns_private*& cns)
const;
1391 DLLLOCAL
const ConstantEntry* runtimeFindNamespaceConstant(
const char* cname,
const qore_ns_private*& cns)
const {
1392 if (strstr(cname,
"::")) {
1393 NamedScope nscope(cname);
1394 return runtimeFindNamespaceConstant(nscope, cns);
1397 cnmap_t::const_iterator i = cnmap.find(cname);
1398 if (i != cnmap.end()) {
1399 assert(i->second.ns);
1401 return i->second.obj;
1406 DLLLOCAL
void runtimeImportGlobalVariable(qore_ns_private& tns, Var* v,
bool readonly,
ExceptionSink* xsink) {
1407 Var* var = tns.var_list.import(v, xsink, readonly);
1411 varmap.update(var->getName(), &tns, var);
1414 DLLLOCAL Var* runtimeCreateVar(qore_ns_private& vns,
const char* vname,
const QoreTypeInfo* typeInfo,
bool builtin) {
1415 Var* v = vns.var_list.runtimeCreateVar(vname, typeInfo, builtin);
1418 varmap.update(v->getName(), &vns, v);
1422 DLLLOCAL
bool parseResolveGlobalVarsAndClassHierarchiesIntern();
1425 DLLLOCAL
int parseAddMethodToClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name, MethodVariantBase* qcmethod,
bool static_flag);
1427 DLLLOCAL
static void rebuildConstantIndexes(cnmap_t& cnmap, ConstantList& cl, qore_ns_private* ns) {
1428 ConstantListIterator cli(cl);
1430 cnmap.update(cli.getName().c_str(), ns, cli.getEntry());
1433 DLLLOCAL
static void rebuildClassIndexes(clmap_t& clmap, QoreClassList& cl, qore_ns_private* ns) {
1434 ClassListIterator cli(cl);
1436 clmap.update(cli.getName(), ns, cli.get());
1439 DLLLOCAL
static void rebuildHashDeclIndexes(thdmap_t& thdmap, HashDeclList& hdl, qore_ns_private* ns) {
1440 HashDeclListIterator hdli(hdl);
1442 thdmap.update(hdli.getName(), ns, hdli.get());
1445 DLLLOCAL
static void rebuildFunctionIndexes(fmap_t& fmap, fl_map_t& flmap, qore_ns_private* ns) {
1446 for (fl_map_t::iterator i = flmap.begin(), e = flmap.end(); i != e; ++i) {
1447 assert(i->second->getNamespace() == ns);
1448 fmap.update(i->first, i->second);
1453 DLLLOCAL
void rebuildIndexes(qore_ns_private* ns) {
1455 rebuildFunctionIndexes(fmap, ns->func_list, ns);
1458 for (map_var_t::iterator i = ns->var_list.vmap.begin(), e = ns->var_list.vmap.end(); i != e; ++i)
1459 varmap.update(i->first, ns, i->second);
1462 rebuildConstantIndexes(cnmap, ns->constant, ns);
1465 rebuildClassIndexes(clmap, ns->classList, ns);
1468 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1477 DLLLOCAL
void parseRebuildIndexes(qore_ns_private* ns) {
1481 for (fl_map_t::iterator i = ns->func_list.begin(), e = ns->func_list.end(); i != e; ++i) {
1482 assert(i->second->getNamespace() == ns);
1483 pend_fmap.update(i->first, i->second);
1487 for (map_var_t::iterator i = ns->var_list.vmap.begin(), e = ns->var_list.vmap.end(); i != e; ++i)
1488 varmap.update(i->first, ns, i->second);
1491 rebuildConstantIndexes(cnmap, ns->constant, ns);
1494 rebuildClassIndexes(clmap, ns->classList, ns);
1497 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1526 NamespaceDepthList nshlist;
1529 gvlist_t pend_gvlist;
1531 DLLLOCAL qore_root_ns_private(
RootQoreNamespace* n_rns) : qore_ns_private(n_rns), rns(n_rns), qoreNS(nullptr) {
1538 DLLLOCAL qore_root_ns_private(
const qore_root_ns_private& old,
int64 po,
QoreProgram* pgm)
1539 : qore_ns_private(old, po), pgm(pgm) {
1544 nsl.nsmap.insert(nsmap_t::value_type(
"Qore", qoreNS));
1545 qoreNS->priv->nsl.nsmap.insert(nsmap_t::value_type(
"Option",
new QoreNamespace(
"Option")));
1547 qoreNS = nsl.find(
"Qore");
1554 rebuildAllIndexes();
1557 DLLLOCAL ~qore_root_ns_private() {
1561 qore_root_ns_private* p =
new qore_root_ns_private(*
this, po, pgm);
1566 DLLLOCAL
void rebuildAllIndexes() {
1571 QorePrivateNamespaceIterator qpni(
this);
1573 rebuildIndexes(qpni.get());
1576 DLLLOCAL
void deferParseCheckAbstractNew(
const qore_class_private* qc,
const QoreProgramLocation* loc) {
1577 deferred_new_check_vec.push_back(deferred_new_check_t(qc, loc));
1580 DLLLOCAL
QoreNamespace* runtimeFindNamespace(
const NamedScope& name) {
1582 NamespaceMapIterator nmi(nsmap, name[0]);
1583 while (nmi.next()) {
1584 const qore_ns_private* rv = nmi.get()->runtimeMatchNamespace(name);
1594 if (name.
bindex(
"::", 0) != -1) {
1595 NamedScope scope(name.
c_str());
1596 return runtimeFindNamespace(scope);
1599 return nsmap.findFirst(name.
c_str());
1602 DLLLOCAL
const QoreClass* runtimeFindScopedClassWithMethod(
const NamedScope& name)
const;
1603 DLLLOCAL
const QoreClass* runtimeFindScopedClassWithMethodIntern(
const NamedScope& name)
const;
1610 DLLLOCAL qore_ns_private* getQore() {
1611 return qoreNS->priv;
1614 DLLLOCAL
const qore_ns_private* getQore()
const {
1615 return qoreNS->priv;
1620 qore_ns_private::getGlobalVars(*rv);
1624 DLLLOCAL
void commitModule(QoreModuleContext& qmc) {
1625 for (
unsigned j = 0; j < qmc.mcnl.size(); ++j) {
1626 ModuleContextNamespaceCommit& mc = qmc.mcnl[j];
1627 mc.parent->addCommitNamespaceIntern(mc.nns);
1630 for (
unsigned j = 0; j < qmc.mcfl.size(); ++j) {
1631 ModuleContextFunctionCommit& mc = qmc.mcfl[j];
1632 mc.parent->addBuiltinVariantIntern(mc.name, mc.v);
1636 if (qmc.mcnl.size() || qmc.mcfl.size()) {
1637 rebuildAllIndexes();
1650 pend_gvlist.clear();
1656 deferred_new_check_vec.clear();
1658 qore_ns_private::parseRollback(xsink);
1661 DLLLOCAL
TypedHashDecl* parseFindHashDecl(
const QoreProgramLocation* loc,
const NamedScope& name);
1663 DLLLOCAL
const TypedHashDecl* runtimeFindHashDeclIntern(
const NamedScope& name,
const qore_ns_private*& ns);
1665 DLLLOCAL
QoreNamespace* runtimeFindCreateNamespacePath(
const NamedScope& nspath,
bool pub,
bool user) {
1666 assert(nspath.size());
1667 bool is_new =
false;
1670 nsmap.update(nns->priv);
1674 DLLLOCAL
QoreNamespace* runtimeFindCreateNamespacePath(
const qore_ns_private& ns,
bool user) {
1679 printd(5,
"qore_root_ns_private::runtimeFindCreateNamespacePath() this: %p ns: '%s'\n",
this, ns.name.c_str());
1681 bool is_new =
false;
1683 assert(ns.name == nns->
getName());
1685 nsmap.update(nns->priv);
1689 DLLLOCAL
void runtimeRebuildConstantIndexes(qore_ns_private* ns) {
1690 rebuildConstantIndexes(cnmap, ns->constant, ns);
1693 DLLLOCAL
void runtimeRebuildClassIndexes(qore_ns_private* ns) {
1694 rebuildClassIndexes(clmap, ns->classList, ns);
1697 DLLLOCAL
void runtimeRebuildHashDeclIndexes(qore_ns_private* ns) {
1698 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1701 DLLLOCAL
void runtimeRebuildFunctionIndexes(qore_ns_private* ns) {
1702 rebuildFunctionIndexes(fmap, ns->func_list, ns);
1705 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindCall(
const char* name,
const QoreListNode* params,
ExceptionSink* xsink);
1709 DLLLOCAL
void parseInit();
1711 DLLLOCAL class_vec_t runtimeFindAllClassesRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1713 DLLLOCAL hashdecl_vec_t runtimeFindAllHashDeclsRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1715 DLLLOCAL func_vec_t runtimeFindAllFunctionsRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1717 DLLLOCAL ns_vec_t runtimeFindAllNamespacesRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1719 DLLLOCAL gvar_vec_t runtimeFindAllGlobalVarsRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1721 DLLLOCAL const_vec_t runtimeFindAllNamespaceConstantsRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1724 return rns.rpriv->getGlobalVars();
1728 rns.priv->runtimeImportSystemClasses(*source.priv, *rns.rpriv, xsink);
1732 rns.priv->runtimeImportSystemHashDecls(*source.priv, *rns.rpriv, xsink);
1736 rns.priv->runtimeImportSystemConstants(*source.priv, *rns.rpriv, xsink);
1740 rns.priv->runtimeImportSystemFunctions(*source.priv, *rns.rpriv, xsink);
1744 return rns.rpriv->runtimeFindCreateNamespacePath(ns, user);
1748 return rns.rpriv->runtimeFindCreateNamespacePath(nspath, pub, user);
1752 return rns.rpriv->copy(po, pgm);
1755 DLLLOCAL
static int addPendingVariant(qore_ns_private& nsp,
const char* name, AbstractQoreFunctionVariant* v) {
1756 return getRootNS()->rpriv->addPendingVariantIntern(nsp, name, v);
1759 DLLLOCAL
static int addPendingVariant(qore_ns_private& nsp,
const NamedScope& name, AbstractQoreFunctionVariant* v) {
1760 return getRootNS()->rpriv->addPendingVariantIntern(nsp, name, v);
1764 return rns.rpriv->runtimeImportFunction(xsink, *ns.priv, u, new_name, inject);
1768 return rns.rpriv->runtimeImportClass(xsink, *ns.priv, c, spgm, set_pub, new_name, inject, injectedClass);
1772 return rns.rpriv->runtimeImportHashDecl(xsink, *ns.priv, c, spgm, set_pub, new_name);
1776 if (strstr(name,
"::")) {
1777 NamedScope nscope(name);
1778 return rns.rpriv->runtimeFindClassIntern(nscope, ns);
1780 return rns.rpriv->runtimeFindClassIntern(name, ns);
1784 if (strstr(name,
"::")) {
1785 NamedScope nscope(name);
1786 return rns.rpriv->runtimeFindHashDeclIntern(nscope, ns);
1788 return rns.rpriv->runtimeFindHashDeclIntern(name, ns);
1791 DLLLOCAL
static const QoreFunction* runtimeFindFunction(
RootQoreNamespace& rns,
const char* name,
const qore_ns_private*& ns) {
1792 const FunctionEntry* fe = runtimeFindFunctionEntry(rns, name);
1794 ns = fe->getNamespace();
1795 return fe->getFunction();
1800 DLLLOCAL
static const FunctionEntry* runtimeFindFunctionEntry(
RootQoreNamespace& rns,
const char* name) {
1801 if (strstr(name,
"::")) {
1802 NamedScope nscope(name);
1803 return rns.rpriv->runtimeFindFunctionEntryIntern(nscope);
1805 return rns.rpriv->runtimeFindFunctionEntryIntern(name);
1808 DLLLOCAL
static bool runtimeExistsFunction(
RootQoreNamespace& rns,
const char* name) {
1809 return rns.rpriv->runtimeExistsFunctionIntern(name);
1812 DLLLOCAL
static void addConstant(qore_root_ns_private& rns, qore_ns_private& ns,
const char* cname,
QoreValue value,
const QoreTypeInfo* typeInfo) {
1813 rns.addConstant(ns, cname, value, typeInfo);
1816 DLLLOCAL
static const QoreFunction* parseResolveFunction(
const QoreProgramLocation* loc,
const char* fname) {
1817 const FunctionEntry* fe = getRootNS()->rpriv->parseResolveFunctionEntryIntern(loc, fname);
1818 return fe ? fe->getFunction() :
nullptr;
1821 DLLLOCAL
static const FunctionEntry* parseResolveFunctionEntry(
const QoreProgramLocation* loc,
const char* fname) {
1822 return getRootNS()->rpriv->parseResolveFunctionEntryIntern(loc, fname);
1827 return getRootNS()->rpriv->parseResolveCallReferenceIntern(fr);
1830 DLLLOCAL
static bool parseResolveGlobalVarsAndClassHierarchies() {
1831 return getRootNS()->rpriv->parseResolveGlobalVarsAndClassHierarchiesIntern();
1835 rns.rpriv->parseCommit();
1838 DLLLOCAL
static QoreValue parseFindConstantValue(
const QoreProgramLocation* loc,
const char* name,
const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
1840 return getRootNS()->rpriv->parseFindConstantValueIntern(loc, name, typeInfo, found, error);
1843 DLLLOCAL
static QoreValue parseFindReferencedConstantValue(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
1845 return getRootNS()->rpriv->parseFindReferencedConstantValueIntern(loc, name, typeInfo, found, error);
1848 DLLLOCAL
static QoreValue parseResolveBareword(
const QoreProgramLocation* loc,
const char* bword,
const QoreTypeInfo*& typeInfo,
bool& found) {
1850 return getRootNS()->rpriv->parseResolveBarewordIntern(loc, bword, typeInfo, found);
1853 DLLLOCAL
static QoreValue parseResolveReferencedScopedReference(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found) {
1855 return getRootNS()->rpriv->parseResolveReferencedScopedReferenceIntern(loc, name, typeInfo, found);
1858 DLLLOCAL
static QoreClass* parseFindClass(
const QoreProgramLocation* loc,
const char* name,
bool raise_error =
true) {
1859 QoreClass* qc = getRootNS()->rpriv->parseFindClassIntern(name);
1860 if (!qc && raise_error) {
1861 parse_error(*loc,
"reference to undefined class '%s'", name);
1866 DLLLOCAL
static QoreClass* parseFindScopedClass(
const QoreProgramLocation* loc,
const NamedScope& name,
bool raise_error =
true) {
1867 return getRootNS()->rpriv->parseFindScopedClassIntern(loc, name, raise_error);
1870 DLLLOCAL
static QoreClass* parseFindScopedClassWithMethod(
const QoreProgramLocation* loc,
const NamedScope& name,
bool error) {
1871 return getRootNS()->rpriv->parseFindScopedClassWithMethodInternError(loc, name, error);
1874 DLLLOCAL
static void parseAddConstant(
const QoreProgramLocation* loc,
QoreNamespace& ns,
const NamedScope& name,
QoreValue value,
bool pub) {
1875 getRootNS()->rpriv->parseAddConstantIntern(loc, ns, name, value, pub);
1879 DLLLOCAL
static int parseAddMethodToClass(
const QoreProgramLocation* loc,
const NamedScope& name, MethodVariantBase* qcmethod,
bool static_flag) {
1880 return getRootNS()->rpriv->parseAddMethodToClassIntern(loc, name, qcmethod, static_flag);
1883 DLLLOCAL
static void parseAddClass(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreClass* oc) {
1884 getRootNS()->rpriv->parseAddClassIntern(loc, name, oc);
1887 DLLLOCAL
static void parseAddHashDecl(
const QoreProgramLocation* loc,
const NamedScope& name,
TypedHashDecl* hd) {
1888 getRootNS()->rpriv->parseAddHashDeclIntern(loc, name, hd);
1891 DLLLOCAL
static void parseAddNamespace(
QoreNamespace* nns) {
1892 getRootNS()->rpriv->parseAddNamespaceIntern(nns);
1895 DLLLOCAL
static const QoreFunction* parseResolveFunction(
const NamedScope& nscope) {
1896 const FunctionEntry* fe = getRootNS()->rpriv->parseResolveFunctionEntryIntern(nscope);
1897 return fe ? fe->getFunction() :
nullptr;
1900 DLLLOCAL
static const FunctionEntry* parseResolveFunctionEntry(
const NamedScope& nscope) {
1901 return getRootNS()->rpriv->parseResolveFunctionEntryIntern(nscope);
1904 DLLLOCAL
const QoreClass* runtimeFindScopedClass(
const NamedScope& name)
const;
1907 return rns.rpriv->runtimeGetCallReference(name, xsink);
1910 DLLLOCAL
static Var* parseAddResolvedGlobalVarDef(
const QoreProgramLocation* loc,
const NamedScope& vname,
const QoreTypeInfo* typeInfo) {
1911 return getRootNS()->rpriv->parseAddResolvedGlobalVarDefIntern(loc, vname, typeInfo);
1914 DLLLOCAL
static Var* parseAddGlobalVarDef(
const QoreProgramLocation* loc,
const NamedScope& vname, QoreParseTypeInfo* typeInfo) {
1915 return getRootNS()->rpriv->parseAddGlobalVarDefIntern(loc, vname, typeInfo);
1918 DLLLOCAL
static Var* parseCheckImplicitGlobalVar(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo* typeInfo) {
1919 return getRootNS()->rpriv->parseCheckImplicitGlobalVarIntern(loc, name, typeInfo);
1922 DLLLOCAL
static Var* parseFindGlobalVar(
const char* vname) {
1923 return getRootNS()->rpriv->parseFindGlobalVarIntern(vname);
1926 DLLLOCAL
static Var* parseFindGlobalVar(
const NamedScope& nscope) {
1927 return getRootNS()->rpriv->parseFindGlobalVarIntern(nscope);
1931 ns.priv->scanMergeCommittedNamespace(*(mns.priv), qmc);
1935 ns.priv->copyMergeCommittedNamespace(*(mns.priv));
1938 ns.rpriv->rebuildAllIndexes();
1941 DLLLOCAL
static Var* runtimeFindGlobalVar(
const RootQoreNamespace& rns,
const char* vname,
const qore_ns_private*& vns) {
1942 return rns.rpriv->runtimeFindGlobalVar(vname, vns);
1945 DLLLOCAL
static Var* runtimeCreateVar(
RootQoreNamespace& rns,
QoreNamespace& vns,
const char* vname,
const QoreTypeInfo* typeInfo,
bool builtin =
false) {
1946 return rns.rpriv->runtimeCreateVar(*vns.priv, vname, typeInfo, builtin);
1950 return rns.rpriv->runtimeImportGlobalVariable(*tns.priv, v, readonly, xsink);
1963 return rns.rpriv->runtimeFindClass(name);
1966 DLLLOCAL
static const ConstantEntry* runtimeFindNamespaceConstant(
const RootQoreNamespace& rns,
const char* cname,
const qore_ns_private*& cns) {
1967 return rns.rpriv->runtimeFindNamespaceConstant(cname, cns);
1971 return rns.rpriv->runtimeFindNamespaceForAddFunction(name, xsink);
1975 return rns.rpriv->runtimeFindNamespaceForAddClass(name, xsink);
1987 return rns.rpriv->qoreNS->priv;
1991 return rns.rpriv->qoreNS->priv;
1995 ns.priv->clearConstants(l);
1996 ns.rpriv->cnmap.clear();
2000 ns.priv->clearData(xsink);