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 {
56 DLLLOCAL qore_ns_private(
const qore_ns_private&) =
delete;
58 DLLLOCAL qore_ns_private& operator=(
const qore_ns_private&) =
delete;
62 DLLLOCAL qore_ns_private(
QoreNamespace* n_ns) : constant(this), depth(0), root(true), pub(true), builtin(true), parent(0), class_handler(0), ns(n_ns) {
66 const QoreProgramLocation* loc;
69 QoreClassList classList;
70 HashDeclList hashDeclList;
71 ConstantList constant;
72 QoreNamespaceList nsl;
73 FunctionList func_list;
74 GlobalVariableList var_list;
75 gvblist_t pend_gvblist;
85 const qore_ns_private* parent =
nullptr;
86 q_ns_class_handler_t class_handler =
nullptr;
90 DLLLOCAL qore_ns_private(
QoreNamespace* n_ns,
const char* n) : name(n), constant(this), pub(true), builtin(true), ns(n_ns) {
94 DLLLOCAL qore_ns_private(
const char* n,
bool pub) : name(n), constant(this), pub(pub), builtin(false), ns(new
QoreNamespace(this)) {
98 DLLLOCAL qore_ns_private(
const QoreProgramLocation* loc);
100 DLLLOCAL qore_ns_private(
const qore_ns_private& old,
int64 po)
102 classList(old.classList, po, this),
103 hashDeclList(old.hashDeclList, po, this),
104 constant(old.constant, po, this),
105 nsl(old.nsl, po, *this),
106 func_list(old.func_list, this, po),
107 var_list(old.var_list, po),
110 pub(old.builtin ? true : false),
111 builtin(old.builtin),
112 imported(old.imported),
113 parent(nullptr), class_handler(old.class_handler), ns(nullptr) {
116 DLLLOCAL ~qore_ns_private() {
119 DLLLOCAL
void getPath(std::string& str,
bool anchored =
false)
const {
120 const qore_ns_private* w = parent;
121 while (w && (anchored || w->parent)) {
124 str.insert(0, w->name);
132 DLLLOCAL
void getNsList(nslist_t& nsl)
const {
137 const qore_ns_private* w =
this;
138 while (w && w->parent) {
145 qore_ns_private* p =
new qore_ns_private(old, po);
150 DLLLOCAL
void purge() {
155 hashDeclList.reset();
160 DLLLOCAL qore_root_ns_private* getRoot() {
161 qore_ns_private* w =
this;
163 w = (qore_ns_private*)w->parent;
165 return w->root ? reinterpret_cast<qore_root_ns_private*>(w) : 0;
168 DLLLOCAL
void setClassHandler(q_ns_class_handler_t n_class_handler);
171 DLLLOCAL
QoreClass* findLoadClass(
const char* cname) {
174 if (!qc && class_handler)
175 qc = class_handler(ns, cname);
182 var_list.getGlobalVars(path, h);
183 nsl.getGlobalVars(h);
188 DLLLOCAL
void deleteData(
bool deref_vars,
ExceptionSink* xsink);
194 DLLLOCAL
void updateDepthRecursive(
unsigned ndepth);
196 DLLLOCAL
int parseAddPendingClass(
const QoreProgramLocation* loc,
const NamedScope& n,
QoreClass* oc);
197 DLLLOCAL
int parseAddPendingClass(
const QoreProgramLocation* loc,
QoreClass* oc);
199 DLLLOCAL
int parseAddPendingHashDecl(
const QoreProgramLocation* loc,
const NamedScope& n,
TypedHashDecl* hashdecl);
200 DLLLOCAL
int parseAddPendingHashDecl(
const QoreProgramLocation* loc,
TypedHashDecl* hashdecl);
202 DLLLOCAL
bool addGlobalVars(qore_root_ns_private& rns);
204 DLLLOCAL cnemap_t::iterator parseAddConstant(
const QoreProgramLocation* loc,
const char* name,
QoreValue value,
bool pub);
206 DLLLOCAL
void parseAddConstant(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreValue value,
bool pub);
208 DLLLOCAL
int parseAddMethodToClass(
const QoreProgramLocation* loc,
const NamedScope& name, MethodVariantBase* qcmethod,
bool static_flag);
210 DLLLOCAL
int checkImportFunction(
const char* name,
ExceptionSink* xsink) {
213 if (func_list.findNode(name)) {
214 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"function '%s' already exists in this namespace", name);
221 DLLLOCAL FunctionEntry* runtimeImportFunction(
ExceptionSink* xsink, QoreFunction* u,
const char* new_name =
nullptr,
bool inject =
false) {
222 const char* fn = new_name ? new_name : u->getName();
223 if (checkImportFunction(fn, xsink))
226 return func_list.import(fn, u,
this, inject);
229 DLLLOCAL
int checkImportClass(
const char* cname,
ExceptionSink* xsink) {
232 if (classList.find(cname)) {
233 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"class '%s' already exists in namespace '%s'", cname, name.c_str());
236 if (hashDeclList.find(cname)) {
237 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"hashdecl '%s' already exists in namespace '%s'", cname, name.c_str());
240 if (nsl.find(cname)) {
241 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"a subnamespace named '%s' already exists in namespace '%s'", cname, name.c_str());
248 DLLLOCAL
int checkImportHashDecl(
const char* hdname,
ExceptionSink* xsink) {
251 if (hashDeclList.find(hdname)) {
252 xsink->
raiseException(
"HASHDECL-IMPORT-ERROR",
"hashdecl '%s' already exists in namespace '%s'", hdname, name.c_str());
255 if (classList.find(hdname)) {
256 xsink->
raiseException(
"HASHDECL-IMPORT-ERROR",
"class '%s' already exists in namespace '%s'", hdname, name.c_str());
263 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);
267 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntry(
const char* name) {
268 return func_list.findNode(name,
true);
271 DLLLOCAL
const QoreFunction* runtimeFindFunction(
const char* name) {
272 return func_list.find(name,
true);
275 DLLLOCAL
const QoreFunction* findAnyFunction(
const char* name) {
276 return func_list.find(name,
false);
279 DLLLOCAL
QoreNamespace* findCreateNamespace(
const char* nme,
bool user,
bool& is_new, qore_root_ns_private* rns);
280 DLLLOCAL
QoreNamespace* findCreateNamespacePath(
const nslist_t& nsl,
bool user,
bool& is_new);
281 DLLLOCAL
QoreNamespace* findCreateNamespacePath(
const NamedScope& nspath,
bool pub,
bool user,
bool& is_new);
283 DLLLOCAL
TypedHashDecl* parseFindLocalHashDecl(
const char* name) {
284 return hashDeclList.find(name);
287 DLLLOCAL
QoreValue getConstantValue(
const char* name,
const QoreTypeInfo*& typeInfo,
bool& found);
288 DLLLOCAL
QoreClass* parseFindLocalClass(
const char* name);
289 DLLLOCAL qore_ns_private* parseAddNamespace(
QoreNamespace* nns);
291 DLLLOCAL
void addModuleNamespace(qore_ns_private* nns, QoreModuleContext& qmc);
292 DLLLOCAL
void addCommitNamespaceIntern(qore_ns_private* nns);
293 DLLLOCAL
void addNamespace(qore_ns_private* nns);
295 DLLLOCAL
void parseInit();
296 DLLLOCAL
void parseResolveHierarchy();
297 DLLLOCAL
void parseResolveClassMembers();
298 DLLLOCAL
void parseResolveAbstract();
299 DLLLOCAL
void parseInitConstants();
301 DLLLOCAL
void parseCommit();
304 DLLLOCAL Var* runtimeMatchGlobalVar(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
305 DLLLOCAL
const ConstantEntry* runtimeMatchNamespaceConstant(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
306 DLLLOCAL
const QoreClass* runtimeMatchScopedClassWithMethod(
const NamedScope& nscope)
const;
307 DLLLOCAL
const QoreClass* runtimeMatchClass(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
308 DLLLOCAL
const qore_ns_private* runtimeMatchNamespace(
const NamedScope& nscope,
int offset = 0)
const;
309 DLLLOCAL
const qore_ns_private* runtimeMatchAddClass(
const NamedScope& nscope,
bool& fnd)
const;
311 DLLLOCAL
const TypedHashDecl* runtimeMatchHashDecl(
const NamedScope& nscope,
const qore_ns_private*& rns)
const;
313 DLLLOCAL
const FunctionEntry* runtimeMatchFunctionEntry(
const NamedScope& nscope)
const;
314 DLLLOCAL
const qore_ns_private* runtimeMatchAddFunction(
const NamedScope& nscope,
bool& fnd)
const;
318 DLLLOCAL
const FunctionEntry* parseMatchFunctionEntry(
const NamedScope& nscope,
unsigned& match)
const;
320 DLLLOCAL
QoreNamespace* resolveNameScope(
const QoreProgramLocation* loc,
const NamedScope& name)
const;
321 DLLLOCAL
QoreNamespace* parseMatchNamespace(
const NamedScope& nscope,
unsigned& matched)
const;
323 DLLLOCAL
TypedHashDecl* parseMatchScopedHashDecl(
const NamedScope& name,
unsigned& matched);
325 DLLLOCAL
QoreClass* parseMatchScopedClass(
const NamedScope& name,
unsigned& matched);
326 DLLLOCAL
QoreClass* parseMatchScopedClassWithMethod(
const NamedScope& nscope,
unsigned& matched);
328 DLLLOCAL
QoreValue parseCheckScopedReference(
const QoreProgramLocation* loc,
const NamedScope& ns,
unsigned& m,
const QoreTypeInfo*& typeInfo,
bool& found,
bool abr)
const;
330 DLLLOCAL
QoreValue parseFindLocalConstantValue(
const QoreProgramLocation* loc,
const NamedScope& ns,
unsigned& m,
const QoreTypeInfo*& typeInfo,
bool& found,
bool abr)
const;
332 DLLLOCAL
QoreValue parseFindLocalConstantValue(
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found);
333 DLLLOCAL
QoreNamespace* parseFindLocalNamespace(
const char* nname);
335 DLLLOCAL
QoreValue parseMatchScopedConstantValue(
const NamedScope& name,
unsigned& matched,
const QoreTypeInfo*& typeInfo,
bool& found);
337 DLLLOCAL FunctionEntry* addPendingVariantIntern(
const char* fname, AbstractQoreFunctionVariant* v,
bool& new_func);
339 DLLLOCAL
void addBuiltinVariant(
const char* name, AbstractQoreFunctionVariant* v);
340 DLLLOCAL
void addBuiltinModuleVariant(
const char* name, AbstractQoreFunctionVariant* v, QoreModuleContext& qmc);
341 DLLLOCAL
void addBuiltinVariantIntern(
const char* name, AbstractQoreFunctionVariant* v);
343 template <
typename T,
class B>
344 DLLLOCAL
void addBuiltinVariant(
const char* name, T f,
int64 flags,
int64 functional_domain,
const QoreTypeInfo* returnTypeInfo,
unsigned num_params, va_list args) {
350 qore_process_params(num_params, typeList, defaultArgList, nameList, args);
353 addBuiltinVariant(name,
new B(f, flags, functional_domain, returnTypeInfo, typeList, defaultArgList, nameList));
356 DLLLOCAL
void scanMergeCommittedNamespace(
const qore_ns_private& mns, QoreModuleContext& qmc)
const;
357 DLLLOCAL
void copyMergeCommittedNamespace(
const qore_ns_private& mns);
359 DLLLOCAL
void parseInitGlobalVars();
361 DLLLOCAL
void checkGlobalVarDecl(Var* v,
const NamedScope& vname);
362 DLLLOCAL
void parseAddGlobalVarDecl(
const QoreProgramLocation* loc,
char* name,
const QoreTypeInfo* typeInfo, QoreParseTypeInfo* parseTypeInfo,
bool pub);
364 DLLLOCAL
void setPublic();
366 DLLLOCAL
void runtimeImportSystemClasses(
const qore_ns_private& source, qore_root_ns_private& rns,
ExceptionSink* xsink);
367 DLLLOCAL
void runtimeImportSystemHashDecls(
const qore_ns_private& source, qore_root_ns_private& rns,
ExceptionSink* xsink);
368 DLLLOCAL
void runtimeImportSystemConstants(
const qore_ns_private& source, qore_root_ns_private& rns,
ExceptionSink* xsink);
369 DLLLOCAL
void runtimeImportSystemFunctions(
const qore_ns_private& source, qore_root_ns_private& rns,
ExceptionSink* xsink);
372 ns.priv->addNamespace(nns->priv);
375 DLLLOCAL
static QoreValue parseResolveReferencedClassConstant(
const QoreProgramLocation* loc,
QoreClass* qc,
const char* name,
const QoreTypeInfo*& typeInfo,
bool& found);
377 DLLLOCAL
static ConstantList& getConstantList(
const QoreNamespace* ns) {
378 return ns->priv->constant;
381 DLLLOCAL
static const QoreFunction* runtimeFindFunction(
QoreNamespace& ns,
const char* name) {
382 return ns.priv->runtimeFindFunction(name);
385 DLLLOCAL
static const FunctionEntry* runtimeFindFunctionEntry(
QoreNamespace& ns,
const char* name) {
386 return ns.priv->runtimeFindFunctionEntry(name);
390 return ns.priv->func_list.getList();
393 DLLLOCAL
static void parseAddPendingClass(
QoreNamespace& ns,
const QoreProgramLocation* loc,
const NamedScope& n,
QoreClass* oc) {
394 ns.priv->parseAddPendingClass(loc, n, oc);
398 ns.priv->parseAddNamespace(nns);
401 DLLLOCAL
static void parseAddConstant(
QoreNamespace& ns,
const QoreProgramLocation* loc,
const NamedScope& name,
QoreValue value,
bool pub) {
402 ns.priv->parseAddConstant(loc, name, value, pub);
406 ns.priv->parseCommit();
417 DLLLOCAL
static const qore_ns_private*
get(
const QoreNamespace& ns) {
426 return ns.priv->pub && !ns.priv->builtin;
430 hashdecl namespace_iterator_element {
434 DLLLOCAL namespace_iterator_element(qore_ns_private* ns) : ns(ns) {
437 i = ns->nsl.nsmap.begin();
440 DLLLOCAL
bool atEnd()
const {
441 return i == ns->nsl.nsmap.end();
453 class QorePrivateNamespaceIterator {
455 typedef std::vector<namespace_iterator_element> nsv_t;
457 qore_ns_private* root;
459 DLLLOCAL
void set(qore_ns_private* rns) {
460 nsv.push_back(namespace_iterator_element(rns));
463 while (!(rns->nsl.empty())) {
464 rns = qore_ns_private::get(*((rns->nsl.nsmap.begin()->second)));
466 nsv.push_back(namespace_iterator_element(rns));
471 DLLLOCAL QorePrivateNamespaceIterator(qore_ns_private* rns) : root(rns) {
475 DLLLOCAL
bool next() {
482 namespace_iterator_element* nie = &(nsv.back());
495 set(qore_ns_private::get(*next));
500 DLLLOCAL qore_ns_private* operator->() {
501 return nsv.back().ns;
504 DLLLOCAL qore_ns_private* operator*() {
505 return nsv.back().ns;
508 DLLLOCAL qore_ns_private*
get() {
509 return nsv.back().ns;
513 hashdecl NSOInfoBase {
514 qore_ns_private* ns =
nullptr;
516 DLLLOCAL NSOInfoBase() {
519 DLLLOCAL NSOInfoBase(qore_ns_private* n_ns) : ns(n_ns) {
522 DLLLOCAL
unsigned depth()
const {
527 template <
typename T>
528 hashdecl NSOInfo :
public NSOInfoBase {
535 DLLLOCAL NSOInfo(qore_ns_private* n_ns, T* n_obj) : NSOInfoBase(n_ns), obj(n_obj) {
538 DLLLOCAL
void assign(qore_ns_private* n_ns, T* n_obj) {
545 template <
typename T>
546 class RootMap :
public std::map<const std::string, NSOInfo<T>> {
549 DLLLOCAL RootMap(
const RootMap& old);
551 DLLLOCAL RootMap& operator=(
const RootMap& m);
554 typedef NSOInfo<T> info_t;
555 typedef std::map<const std::string, NSOInfo<T>> map_t;
560 DLLLOCAL
void update(
const std::string& name, qore_ns_private* ns, T* obj) {
562 typename map_t::iterator i = this->lower_bound(name);
563 if (i == this->end() || i->first != name) {
564 this->insert(i,
typename map_t::value_type(name, info_t(ns, obj)));
566 if (i->second.depth() > ns->depth) {
567 i->second.assign(ns, obj);
572 DLLLOCAL
void update(
typename map_t::const_iterator ni) {
574 typename map_t::iterator i = this->lower_bound(ni->first);
575 if (i == this->end() || i->first != ni->first) {
577 this->insert(i,
typename map_t::value_type(ni->first, ni->second));
580 if (i->second.depth() > ni->second.depth()) {
582 i->second = ni->second;
589 T* findObj(
const std::string& name) {
590 typename map_t::iterator i = this->find(name);
591 return i == this->end() ? nullptr : i->second.obj;
595 hashdecl FunctionEntryInfo {
596 FunctionEntry* obj =
nullptr;
598 DLLLOCAL FunctionEntryInfo() {
601 DLLLOCAL FunctionEntryInfo(FunctionEntry* o) : obj(o) {
604 DLLLOCAL
unsigned depth()
const {
605 return getNamespace()->depth;
608 DLLLOCAL qore_ns_private* getNamespace()
const {
609 return obj->getNamespace();
612 DLLLOCAL
void assign(FunctionEntry* n_obj) {
618 typedef std::map<const char*, FunctionEntryInfo, ltstr> femap_t;
619 class FunctionEntryRootMap :
public femap_t {
622 DLLLOCAL FunctionEntryRootMap(
const FunctionEntryRootMap& old);
624 DLLLOCAL FunctionEntryRootMap& operator=(
const FunctionEntryRootMap& m);
627 DLLLOCAL FunctionEntryRootMap() {
630 DLLLOCAL
void update(
const char* name, FunctionEntry* obj) {
632 femap_t::iterator i = find(name);
634 insert(femap_t::value_type(name, FunctionEntryInfo(obj)));
636 if (i->second.depth() > obj->getNamespace()->depth)
637 i->second.assign(obj);
640 DLLLOCAL
void update(femap_t::const_iterator ni) {
642 femap_t::iterator i = find(ni->first);
645 insert(femap_t::value_type(ni->first, ni->second));
649 if (i->second.depth() > ni->second.depth()) {
651 i->second = ni->second;
658 FunctionEntry* findObj(
const char* name) {
659 femap_t::iterator i = find(name);
660 return i == end() ? 0 : i->second.obj;
664 class NamespaceDepthList {
665 friend class NamespaceDepthListIterator;
668 typedef std::multimap<unsigned, qore_ns_private*> nsdmap_t;
672 DLLLOCAL NamespaceDepthList() {
675 DLLLOCAL
void add(qore_ns_private* ns) {
676 nsdmap.insert(nsdmap_t::value_type(ns->depth, ns));
679 DLLLOCAL
void clear() {
684 class NamespaceDepthListIterator {
685 NamespaceDepthList::nsdmap_t::iterator i, e;
687 DLLLOCAL NamespaceDepthListIterator(NamespaceDepthList& m) : i(m.nsdmap.begin()), e(m.nsdmap.end()) {
690 DLLLOCAL
bool next() {
697 DLLLOCAL qore_ns_private*
get()
const {
704 friend class NamespaceMapIterator;
705 friend class ConstNamespaceMapIterator;
706 friend class ConstAllNamespacesIterator;
710 typedef std::multimap<unsigned, qore_ns_private*> nsdmap_t;
713 typedef vector_map_t<const char*, nsdmap_t> nsmap_t;
716 typedef vector_map_t<qore_ns_private*, unsigned> nsrmap_t;
722 DLLLOCAL NamespaceMap(
const NamespaceMap& old);
724 DLLLOCAL NamespaceMap& operator=(
const NamespaceMap& m);
727 DLLLOCAL NamespaceMap() {
730 DLLLOCAL
void update(qore_ns_private* ns) {
732 nsrmap_t::iterator ri = nsrmap.find(ns);
733 if (ri != nsrmap.end()) {
735 if (ns->depth == ri->second)
739 nsmap_t::iterator i = nsmap.find(ns->name.c_str());
740 assert(i != nsmap.end());
743 nsdmap_t::iterator di = i->second.find(ri->second);
744 assert(di != i->second.end());
753 i->second.insert(nsdmap_t::value_type(ns->depth, ns));
759 nsmap_t::iterator i = nsmap.find(ns->name.c_str());
760 if (i == nsmap.end())
761 i = nsmap.insert(nsmap_t::value_type(ns->name.c_str(), nsdmap_t())).first;
763 i->second.insert(nsdmap_t::value_type(ns->depth, ns));
767 nsrmap.insert(nsrmap_t::value_type(ns, ns->depth));
770 DLLLOCAL
void commit(NamespaceMap& pend) {
772 for (nsrmap_t::iterator i = pend.nsrmap.begin(), e = pend.nsrmap.end(); i != e; ++i)
777 DLLLOCAL
void clear() {
784 nsmap_t::iterator mi = nsmap.find(name);
785 if (mi != nsmap.end()) {
786 nsdmap_t::iterator i = mi->second.begin();
787 if (i != mi->second.end()) {
788 return i->second->ns;
795 class NamespaceMapIterator {
797 NamespaceMap::nsmap_t::iterator mi;
798 NamespaceMap::nsdmap_t::iterator i;
802 DLLLOCAL NamespaceMapIterator(NamespaceMap& nsm,
const char* name) : mi(nsm.nsmap.find(name)), valid(mi != nsm.nsmap.end()) {
804 i = mi->second.end();
807 DLLLOCAL
bool next() {
811 if (i == mi->second.end())
812 i = mi->second.begin();
816 return i != mi->second.end();
819 DLLLOCAL qore_ns_private*
get() {
824 class ConstNamespaceMapIterator {
826 NamespaceMap::nsmap_t::const_iterator mi;
827 NamespaceMap::nsdmap_t::const_iterator i;
831 DLLLOCAL ConstNamespaceMapIterator(
const NamespaceMap& nsm,
const char* name) : mi(nsm.nsmap.find(name)), valid(mi != nsm.nsmap.end()) {
833 i = mi->second.end();
836 DLLLOCAL
bool next() {
840 if (i == mi->second.end())
841 i = mi->second.begin();
845 return i != mi->second.end();
848 DLLLOCAL
const qore_ns_private*
get() {
853 class ConstAllNamespacesIterator {
855 DLLLOCAL ConstAllNamespacesIterator(
const NamespaceMap& nsmap) : nsrmap(nsmap.nsrmap), i(nsmap.nsrmap.end()) {
858 DLLLOCAL
bool next() {
859 if (i == nsrmap.end()) {
866 return i != nsrmap.end();
870 assert(i != nsrmap.end());
875 const NamespaceMap::nsrmap_t& nsrmap;
876 NamespaceMap::nsrmap_t::const_iterator i;
879 typedef FunctionEntryRootMap fmap_t;
881 typedef RootMap<ConstantEntry> cnmap_t;
883 typedef RootMap<QoreClass> clmap_t;
885 typedef RootMap<TypedHashDecl> thdmap_t;
887 typedef RootMap<Var> varmap_t;
889 hashdecl deferred_new_check_t {
890 const qore_class_private* qc;
891 const QoreProgramLocation* loc;
893 DLLLOCAL deferred_new_check_t(
const qore_class_private* qc,
const QoreProgramLocation* loc) : qc(qc), loc(loc) {
897 class qore_root_ns_private :
public qore_ns_private {
898 friend class qore_ns_private;
902 typedef std::vector<deferred_new_check_t> deferred_new_check_vec_t;
903 deferred_new_check_vec_t deferred_new_check_vec;
905 DLLLOCAL
int addPendingVariantIntern(qore_ns_private& ns,
const char* name, AbstractQoreFunctionVariant* v) {
907 bool new_func =
false;
908 FunctionEntry* fe = ns.addPendingVariantIntern(name, v, new_func);
912 assert(fe->getNamespace() == &ns);
915 fmap_t::iterator i = fmap.find(fe->getName());
917 if (i == fmap.end() || i->second.depth() > ns.depth)
918 pend_fmap.update(fe->getName(), fe);
924 DLLLOCAL
int addPendingVariantIntern(qore_ns_private& ns,
const NamedScope& nscope, AbstractQoreFunctionVariant* v) {
925 assert(nscope.size() > 1);
929 for (
unsigned i = 0; i < nscope.size() - 1; ++i) {
930 fns = fns->priv->parseFindLocalNamespace(nscope[i]);
932 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());
937 return addPendingVariantIntern(*fns->priv, nscope.getIdentifier(), vh.release());
941 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) {
942 QoreClass* nc = ns.runtimeImportClass(xsink, c, spgm, set_pub, new_name, inject, injectedClass);
948 clmap.update(nc->
getName(), &ns, nc);
954 TypedHashDecl* nhd = ns.runtimeImportHashDecl(xsink, hd, spgm, set_pub, new_name);
960 thdmap.update(nhd->
getName(), &ns, nhd);
965 DLLLOCAL
int runtimeImportFunction(
ExceptionSink* xsink, qore_ns_private& ns, QoreFunction* u,
const char* new_name =
nullptr,
bool inject =
false) {
966 FunctionEntry* fe = ns.runtimeImportFunction(xsink, u, new_name, inject);
970 assert(fe->getNamespace() == &ns);
974 fmap.update(fe->getName(), fe);
978 DLLLOCAL
bool runtimeExistsFunctionIntern(
const char* name) {
979 return fmap.find(name) != fmap.end();
982 DLLLOCAL
const QoreClass* runtimeFindClassIntern(
const char* name,
const qore_ns_private*& ns)
const {
983 clmap_t::const_iterator i = clmap.find(name);
985 if (i != clmap.end()) {
988 return i->second.obj;
994 DLLLOCAL
const QoreClass* runtimeFindClassIntern(
const NamedScope& name,
const qore_ns_private*& ns)
const;
996 DLLLOCAL
const TypedHashDecl* runtimeFindHashDeclIntern(
const char* name,
const qore_ns_private*& ns) {
997 thdmap_t::iterator i = thdmap.find(name);
999 if (i != thdmap.end()) {
1002 return i->second.obj;
1008 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntryIntern(
const char* name) {
1009 fmap_t::const_iterator i = fmap.find(name);
1010 return i != fmap.end() ? i->second.obj :
nullptr;
1013 DLLLOCAL
const FunctionEntry* runtimeFindFunctionEntryIntern(
const NamedScope& name);
1015 DLLLOCAL FunctionEntry* parseFindFunctionEntryIntern(
const char* name) {
1018 qore_ns_private* nscx = parse_get_ns();
1020 FunctionEntry* fe = nscx->func_list.findNode(name);
1026 fmap_t::iterator i = fmap.find(name);
1027 fmap_t::iterator ip = pend_fmap.find(name);
1029 if (i != fmap.end()) {
1030 if (ip != pend_fmap.end()) {
1031 if (i->second.depth() < ip->second.depth())
1032 return i->second.obj;
1034 return ip->second.obj;
1037 return i->second.obj;
1040 if (ip != pend_fmap.end())
1041 return ip->second.obj;
1046 DLLLOCAL QoreFunction* parseFindFunctionIntern(
const char* name) {
1047 FunctionEntry* fe = parseFindFunctionEntryIntern(name);
1048 return !fe ? 0 : fe->getFunction();
1051 DLLLOCAL
const FunctionEntry* parseResolveFunctionEntryIntern(
const QoreProgramLocation* loc,
const char* fname) {
1052 QORE_TRACE(
"qore_root_ns_private::parseResolveFunctionEntryIntern()");
1054 const FunctionEntry* f = parseFindFunctionEntryIntern(fname);
1057 parse_error(*loc,
"function '%s()' cannot be found", fname);
1065 DLLLOCAL
void parseCommit() {
1067 for (fmap_t::iterator i = pend_fmap.begin(), e = pend_fmap.end(); i != e; ++i)
1071 qore_ns_private::parseCommit();
1073 qore_ns_private::parseCommitRuntimeInit(
getProgram()->getParseExceptionSink());
1076 DLLLOCAL ConstantEntry* parseFindOnlyConstantEntryIntern(
const char* cname, qore_ns_private*& ns) {
1079 qore_ns_private* nscx = parse_get_ns();
1081 ConstantEntry* ce = nscx->constant.findEntry(cname);
1090 cnmap_t::iterator i = cnmap.find(cname);
1092 if (i != cnmap.end()) {
1094 return i->second.obj;;
1100 DLLLOCAL
QoreValue parseFindOnlyConstantValueIntern(
const QoreProgramLocation* loc,
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found) {
1102 qore_ns_private* ns;
1103 ConstantEntry* ce = parseFindOnlyConstantEntryIntern(cname, ns);
1110 NamespaceParseContextHelper nspch(ns);
1111 return ce->get(loc, typeInfo, ns);
1114 DLLLOCAL
QoreValue parseFindConstantValueIntern(
const QoreProgramLocation* loc,
const char* cname,
const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
1119 QoreValue rv = qore_class_private::parseFindConstantValue(pc, cname, typeInfo, found, pc ? qore_class_private::get(*pc) :
nullptr);
1125 QoreValue rv = parseFindOnlyConstantValueIntern(loc, cname, typeInfo, found);
1131 parse_error(*loc,
"constant '%s' cannot be resolved in any namespace", cname);
1138 fmap_t::iterator i = fmap.find(fname);
1139 if (i == fmap.end()) {
1140 xsink->
raiseException(
"NO-SUCH-FUNCTION",
"callback function '%s()' does not exist", fname);
1144 return i->second.obj->makeCallReference(get_runtime_location());
1147 DLLLOCAL
TypedHashDecl* parseFindScopedHashDeclIntern(
const NamedScope& nscope,
unsigned& matched);
1149 DLLLOCAL
TypedHashDecl* parseFindHashDeclIntern(
const char* hdname) {
1152 qore_ns_private* nscx = parse_get_ns();
1160 thdmap_t::iterator i = thdmap.find(hdname);
1162 if (i != thdmap.end()) {
1163 return i->second.obj;
1170 DLLLOCAL
QoreClass* parseFindScopedClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name);
1171 DLLLOCAL
QoreClass* parseFindScopedClassIntern(
const NamedScope& name,
unsigned& matched);
1172 DLLLOCAL
QoreClass* parseFindScopedClassWithMethodInternError(
const QoreProgramLocation* loc,
const NamedScope& name,
bool error);
1173 DLLLOCAL
QoreClass* parseFindScopedClassWithMethodIntern(
const NamedScope& name,
unsigned& matched);
1175 DLLLOCAL
QoreClass* parseFindClassIntern(
const char* cname) {
1179 qore_ns_private* nscx = parse_get_ns();
1181 QoreClass* qc = nscx->parseFindLocalClass(cname);
1187 clmap_t::iterator i = clmap.find(cname);
1189 if (i != clmap.end()) {
1190 return i->second.obj;
1194 NamespaceDepthListIterator nhi(nshlist);
1195 while (nhi.next()) {
1196 QoreClass* qc = nhi.get()->findLoadClass(cname);
1205 DLLLOCAL
const QoreClass* runtimeFindClass(
const char* name)
const {
1206 clmap_t::const_iterator i = clmap.find(name);
1207 return i != clmap.end() ? i->second.obj :
nullptr;
1215 NamespaceMapIterator nmi(nsmap, name[0]);
1216 while (nmi.next()) {
1217 const qore_ns_private* rv = nmi.get()->runtimeMatchAddFunction(name, fnd);
1224 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"target function '%s' already exists in the given namespace", name.ostr);
1226 xsink->
raiseException(
"FUNCTION-IMPORT-ERROR",
"target namespace in '%s' does not exist", name.ostr);
1234 NamespaceMapIterator nmi(nsmap, name.get(0));
1235 while (nmi.next()) {
1236 const qore_ns_private* rv = nmi.get()->runtimeMatchAddClass(name, fnd);
1242 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"target class '%s' already exists in the given namespace", name.ostr);
1244 xsink->
raiseException(
"CLASS-IMPORT-ERROR",
"target namespace in '%s' does not exist", name.ostr);
1248 DLLLOCAL
void addConstant(qore_ns_private& ns,
const char* cname,
QoreValue value,
const QoreTypeInfo* typeInfo);
1250 DLLLOCAL
QoreValue parseFindReferencedConstantValueIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found,
bool error);
1252 DLLLOCAL
QoreValue parseResolveBarewordIntern(
const QoreProgramLocation* loc,
const char* bword,
const QoreTypeInfo*& typeInfo,
bool& found);
1254 DLLLOCAL
QoreValue parseResolveReferencedScopedReferenceIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found);
1256 DLLLOCAL
void parseAddConstantIntern(
const QoreProgramLocation* loc,
QoreNamespace& ns,
const NamedScope& name,
QoreValue value,
bool pub);
1258 DLLLOCAL
void parseAddClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreClass* oc);
1260 DLLLOCAL
void parseAddHashDeclIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
TypedHashDecl* hd);
1262 DLLLOCAL qore_ns_private* parseResolveNamespaceIntern(
const QoreProgramLocation* loc,
const NamedScope& nscope, qore_ns_private* sns);
1263 DLLLOCAL qore_ns_private* parseResolveNamespace(
const QoreProgramLocation* loc,
const NamedScope& nscope, qore_ns_private* sns);
1264 DLLLOCAL qore_ns_private* parseResolveNamespace(
const QoreProgramLocation* loc,
const NamedScope& nscope);
1266 DLLLOCAL
const FunctionEntry* parseResolveFunctionEntryIntern(
const NamedScope& nscope);
1268 DLLLOCAL Var* parseAddResolvedGlobalVarDefIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo* typeInfo);
1269 DLLLOCAL Var* parseAddGlobalVarDefIntern(
const QoreProgramLocation* loc,
const NamedScope& name, QoreParseTypeInfo* typeInfo);
1271 DLLLOCAL Var* parseCheckImplicitGlobalVarIntern(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo* typeInfo);
1273 DLLLOCAL Var* parseFindGlobalVarIntern(
const NamedScope& vname) {
1274 assert(vname.size() > 1);
1281 qore_ns_private* nscx = parse_get_ns();
1282 if (nscx && nscx->name == vname[0]) {
1283 QoreNamespace* vns = nscx->parseMatchNamespace(vname, match);
1284 if (vns && (rv = vns->priv->var_list.parseFindVar(vname.getIdentifier())))
1291 NamespaceMapIterator nmi(nsmap, vname[0]);
1292 while (nmi.next()) {
1293 QoreNamespace* vns = nmi.get()->parseMatchNamespace(vname, match);
1294 if (vns && (rv = vns->priv->var_list.parseFindVar(vname.getIdentifier())))
1302 DLLLOCAL Var* parseFindGlobalVarIntern(
const char* vname) {
1305 qore_ns_private* nscx = parse_get_ns();
1307 Var* v = nscx->var_list.parseFindVar(vname);
1315 varmap_t::iterator i = varmap.find(vname);
1317 if (i != varmap.end()) {
1318 return i->second.obj;
1324 DLLLOCAL Var* runtimeFindGlobalVar(
const NamedScope& nscope,
const qore_ns_private*& vns)
const;
1326 DLLLOCAL Var* runtimeFindGlobalVar(
const char* vname,
const qore_ns_private*& vns)
const {
1327 if (strstr(vname,
"::")) {
1328 NamedScope nscope(vname);
1329 return runtimeFindGlobalVar(nscope, vns);
1332 varmap_t::const_iterator i = varmap.find(vname);
1333 if (i != varmap.end()) {
1334 assert(i->second.ns);
1336 return i->second.obj;
1341 DLLLOCAL
const ConstantEntry* runtimeFindNamespaceConstant(
const NamedScope& nscope,
const qore_ns_private*& cns)
const;
1343 DLLLOCAL
const ConstantEntry* runtimeFindNamespaceConstant(
const char* cname,
const qore_ns_private*& cns)
const {
1344 if (strstr(cname,
"::")) {
1345 NamedScope nscope(cname);
1346 return runtimeFindNamespaceConstant(nscope, cns);
1349 cnmap_t::const_iterator i = cnmap.find(cname);
1350 if (i != cnmap.end()) {
1351 assert(i->second.ns);
1353 return i->second.obj;
1358 DLLLOCAL
void runtimeImportGlobalVariable(qore_ns_private& tns, Var* v,
bool readonly,
ExceptionSink* xsink) {
1359 Var* var = tns.var_list.import(v, xsink, readonly);
1363 varmap.update(var->getName(), &tns, var);
1366 DLLLOCAL Var* runtimeCreateVar(qore_ns_private& vns,
const char* vname,
const QoreTypeInfo* typeInfo,
bool builtin) {
1367 Var* v = vns.var_list.runtimeCreateVar(vname, typeInfo, builtin);
1370 varmap.update(v->getName(), &vns, v);
1374 DLLLOCAL
bool parseResolveGlobalVarsAndClassHierarchiesIntern();
1377 DLLLOCAL
int parseAddMethodToClassIntern(
const QoreProgramLocation* loc,
const NamedScope& name, MethodVariantBase* qcmethod,
bool static_flag);
1379 DLLLOCAL
static void rebuildConstantIndexes(cnmap_t& cnmap, ConstantList& cl, qore_ns_private* ns) {
1380 ConstantListIterator cli(cl);
1382 cnmap.update(cli.getName().c_str(), ns, cli.getEntry());
1385 DLLLOCAL
static void rebuildClassIndexes(clmap_t& clmap, QoreClassList& cl, qore_ns_private* ns) {
1386 ClassListIterator cli(cl);
1388 clmap.update(cli.getName(), ns, cli.get());
1391 DLLLOCAL
static void rebuildHashDeclIndexes(thdmap_t& thdmap, HashDeclList& hdl, qore_ns_private* ns) {
1392 HashDeclListIterator hdli(hdl);
1394 thdmap.update(hdli.getName(), ns, hdli.get());
1397 DLLLOCAL
static void rebuildFunctionIndexes(fmap_t& fmap, fl_map_t& flmap, qore_ns_private* ns) {
1398 for (fl_map_t::iterator i = flmap.begin(), e = flmap.end(); i != e; ++i) {
1399 assert(i->second->getNamespace() == ns);
1400 fmap.update(i->first, i->second);
1405 DLLLOCAL
void rebuildIndexes(qore_ns_private* ns) {
1407 rebuildFunctionIndexes(fmap, ns->func_list, ns);
1410 for (map_var_t::iterator i = ns->var_list.vmap.begin(), e = ns->var_list.vmap.end(); i != e; ++i)
1411 varmap.update(i->first, ns, i->second);
1414 rebuildConstantIndexes(cnmap, ns->constant, ns);
1417 rebuildClassIndexes(clmap, ns->classList, ns);
1420 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1429 DLLLOCAL
void parseRebuildIndexes(qore_ns_private* ns) {
1433 for (fl_map_t::iterator i = ns->func_list.begin(), e = ns->func_list.end(); i != e; ++i) {
1434 assert(i->second->getNamespace() == ns);
1435 pend_fmap.update(i->first, i->second);
1439 for (map_var_t::iterator i = ns->var_list.vmap.begin(), e = ns->var_list.vmap.end(); i != e; ++i)
1440 varmap.update(i->first, ns, i->second);
1443 rebuildConstantIndexes(cnmap, ns->constant, ns);
1446 rebuildClassIndexes(clmap, ns->classList, ns);
1449 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1474 NamespaceDepthList nshlist;
1477 gvlist_t pend_gvlist;
1479 DLLLOCAL qore_root_ns_private(
RootQoreNamespace* n_rns) : qore_ns_private(n_rns), rns(n_rns), qoreNS(0) {
1486 DLLLOCAL qore_root_ns_private(
const qore_root_ns_private& old,
int64 po) : qore_ns_private(old, po) {
1490 nsl.nsmap.insert(nsmap_t::value_type(
"Qore", qoreNS));
1491 qoreNS->priv->nsl.nsmap.insert(nsmap_t::value_type(
"Option",
new QoreNamespace(
"Option")));
1493 qoreNS = nsl.find(
"Qore");
1500 rebuildAllIndexes();
1503 DLLLOCAL ~qore_root_ns_private() {
1507 qore_root_ns_private* p =
new qore_root_ns_private(*
this, po);
1512 DLLLOCAL
void rebuildAllIndexes() {
1517 QorePrivateNamespaceIterator qpni(
this);
1519 rebuildIndexes(qpni.get());
1522 DLLLOCAL
void deferParseCheckAbstractNew(
const qore_class_private* qc,
const QoreProgramLocation* loc) {
1523 deferred_new_check_vec.push_back(deferred_new_check_t(qc, loc));
1526 DLLLOCAL
QoreNamespace* runtimeFindNamespace(
const NamedScope& name) {
1528 NamespaceMapIterator nmi(nsmap, name[0]);
1529 while (nmi.next()) {
1530 const qore_ns_private* rv = nmi.get()->runtimeMatchNamespace(name);
1540 if (name.
bindex(
"::", 0) != -1) {
1541 NamedScope scope(name.
c_str());
1542 return runtimeFindNamespace(scope);
1545 return nsmap.findFirst(name.
c_str());
1548 DLLLOCAL
const QoreClass* runtimeFindScopedClassWithMethod(
const NamedScope& name)
const;
1549 DLLLOCAL
const QoreClass* runtimeFindScopedClassWithMethodIntern(
const NamedScope& name)
const;
1556 DLLLOCAL qore_ns_private* getQore() {
1557 return qoreNS->priv;
1560 DLLLOCAL
const qore_ns_private* getQore()
const {
1561 return qoreNS->priv;
1566 qore_ns_private::getGlobalVars(*rv);
1570 DLLLOCAL
void commitModule(QoreModuleContext& qmc) {
1571 for (
unsigned j = 0; j < qmc.mcnl.size(); ++j) {
1572 ModuleContextNamespaceCommit& mc = qmc.mcnl[j];
1573 mc.parent->addCommitNamespaceIntern(mc.nns);
1576 for (
unsigned j = 0; j < qmc.mcfl.size(); ++j) {
1577 ModuleContextFunctionCommit& mc = qmc.mcfl[j];
1578 mc.parent->addBuiltinVariantIntern(mc.name, mc.v);
1582 if (qmc.mcnl.size() || qmc.mcfl.size()) {
1583 rebuildAllIndexes();
1596 pend_gvlist.clear();
1602 deferred_new_check_vec.clear();
1604 qore_ns_private::parseRollback(xsink);
1607 DLLLOCAL
TypedHashDecl* parseFindHashDecl(
const QoreProgramLocation* loc,
const NamedScope& name);
1609 DLLLOCAL
const TypedHashDecl* runtimeFindHashDeclIntern(
const NamedScope& name,
const qore_ns_private*& ns);
1611 DLLLOCAL
QoreNamespace* runtimeFindCreateNamespacePath(
const NamedScope& nspath,
bool pub,
bool user) {
1612 assert(nspath.size());
1613 bool is_new =
false;
1616 nsmap.update(nns->priv);
1620 DLLLOCAL
QoreNamespace* runtimeFindCreateNamespacePath(
const qore_ns_private& ns,
bool user) {
1625 printd(5,
"qore_root_ns_private::runtimeFindCreateNamespacePath() this: %p ns: '%s'\n",
this, ns.name.c_str());
1627 bool is_new =
false;
1629 assert(ns.name == nns->
getName());
1631 nsmap.update(nns->priv);
1635 DLLLOCAL
void runtimeRebuildConstantIndexes(qore_ns_private* ns) {
1636 rebuildConstantIndexes(cnmap, ns->constant, ns);
1639 DLLLOCAL
void runtimeRebuildClassIndexes(qore_ns_private* ns) {
1640 rebuildClassIndexes(clmap, ns->classList, ns);
1643 DLLLOCAL
void runtimeRebuildHashDeclIndexes(qore_ns_private* ns) {
1644 rebuildHashDeclIndexes(thdmap, ns->hashDeclList, ns);
1647 DLLLOCAL
void runtimeRebuildFunctionIndexes(qore_ns_private* ns) {
1648 rebuildFunctionIndexes(fmap, ns->func_list, ns);
1651 DLLLOCAL
const AbstractQoreFunctionVariant* runtimeFindCall(
const char* name,
const QoreListNode* params,
ExceptionSink* xsink);
1655 DLLLOCAL
void parseInit();
1657 DLLLOCAL class_vec_t runtimeFindAllClassesRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1659 DLLLOCAL hashdecl_vec_t runtimeFindAllHashDeclsRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1661 DLLLOCAL func_vec_t runtimeFindAllFunctionsRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1663 DLLLOCAL ns_vec_t runtimeFindAllNamespacesRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1665 DLLLOCAL gvar_vec_t runtimeFindAllGlobalVarsRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1667 DLLLOCAL const_vec_t runtimeFindAllNamespaceConstantsRegex(
const QoreString& pattern,
int re_opts,
ExceptionSink* xsink)
const;
1670 return rns.rpriv->getGlobalVars();
1674 rns.priv->runtimeImportSystemClasses(*source.priv, *rns.rpriv, xsink);
1678 rns.priv->runtimeImportSystemHashDecls(*source.priv, *rns.rpriv, xsink);
1682 rns.priv->runtimeImportSystemConstants(*source.priv, *rns.rpriv, xsink);
1686 rns.priv->runtimeImportSystemFunctions(*source.priv, *rns.rpriv, xsink);
1690 return rns.rpriv->runtimeFindCreateNamespacePath(ns, user);
1694 return rns.rpriv->runtimeFindCreateNamespacePath(nspath, pub, user);
1698 return rns.rpriv->copy(po);
1701 DLLLOCAL
static int addPendingVariant(qore_ns_private& nsp,
const char* name, AbstractQoreFunctionVariant* v) {
1702 return getRootNS()->rpriv->addPendingVariantIntern(nsp, name, v);
1705 DLLLOCAL
static int addPendingVariant(qore_ns_private& nsp,
const NamedScope& name, AbstractQoreFunctionVariant* v) {
1706 return getRootNS()->rpriv->addPendingVariantIntern(nsp, name, v);
1710 return rns.rpriv->runtimeImportFunction(xsink, *ns.priv, u, new_name, inject);
1714 return rns.rpriv->runtimeImportClass(xsink, *ns.priv, c, spgm, set_pub, new_name, inject, injectedClass);
1718 return rns.rpriv->runtimeImportHashDecl(xsink, *ns.priv, c, spgm, set_pub, new_name);
1722 if (strstr(name,
"::")) {
1723 NamedScope nscope(name);
1724 return rns.rpriv->runtimeFindClassIntern(nscope, ns);
1726 return rns.rpriv->runtimeFindClassIntern(name, ns);
1730 if (strstr(name,
"::")) {
1731 NamedScope nscope(name);
1732 return rns.rpriv->runtimeFindHashDeclIntern(nscope, ns);
1734 return rns.rpriv->runtimeFindHashDeclIntern(name, ns);
1737 DLLLOCAL
static const QoreFunction* runtimeFindFunction(
RootQoreNamespace& rns,
const char* name,
const qore_ns_private*& ns) {
1738 const FunctionEntry* fe = runtimeFindFunctionEntry(rns, name);
1740 ns = fe->getNamespace();
1741 return fe->getFunction();
1746 DLLLOCAL
static const FunctionEntry* runtimeFindFunctionEntry(
RootQoreNamespace& rns,
const char* name) {
1747 if (strstr(name,
"::")) {
1748 NamedScope nscope(name);
1749 return rns.rpriv->runtimeFindFunctionEntryIntern(nscope);
1751 return rns.rpriv->runtimeFindFunctionEntryIntern(name);
1754 DLLLOCAL
static bool runtimeExistsFunction(
RootQoreNamespace& rns,
const char* name) {
1755 return rns.rpriv->runtimeExistsFunctionIntern(name);
1758 DLLLOCAL
static void addConstant(qore_root_ns_private& rns, qore_ns_private& ns,
const char* cname,
QoreValue value,
const QoreTypeInfo* typeInfo) {
1759 rns.addConstant(ns, cname, value, typeInfo);
1762 DLLLOCAL
static const QoreFunction* parseResolveFunction(
const QoreProgramLocation* loc,
const char* fname) {
1763 const FunctionEntry* fe = getRootNS()->rpriv->parseResolveFunctionEntryIntern(loc, fname);
1764 return fe ? fe->getFunction() :
nullptr;
1767 DLLLOCAL
static const FunctionEntry* parseResolveFunctionEntry(
const QoreProgramLocation* loc,
const char* fname) {
1768 return getRootNS()->rpriv->parseResolveFunctionEntryIntern(loc, fname);
1773 return getRootNS()->rpriv->parseResolveCallReferenceIntern(fr);
1776 DLLLOCAL
static bool parseResolveGlobalVarsAndClassHierarchies() {
1777 return getRootNS()->rpriv->parseResolveGlobalVarsAndClassHierarchiesIntern();
1781 rns.rpriv->parseCommit();
1784 DLLLOCAL
static QoreValue parseFindConstantValue(
const QoreProgramLocation* loc,
const char* name,
const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
1786 return getRootNS()->rpriv->parseFindConstantValueIntern(loc, name, typeInfo, found, error);
1789 DLLLOCAL
static QoreValue parseFindReferencedConstantValue(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found,
bool error) {
1791 return getRootNS()->rpriv->parseFindReferencedConstantValueIntern(loc, name, typeInfo, found, error);
1794 DLLLOCAL
static QoreValue parseResolveBareword(
const QoreProgramLocation* loc,
const char* bword,
const QoreTypeInfo*& typeInfo,
bool& found) {
1796 return getRootNS()->rpriv->parseResolveBarewordIntern(loc, bword, typeInfo, found);
1799 DLLLOCAL
static QoreValue parseResolveReferencedScopedReference(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo*& typeInfo,
bool& found) {
1801 return getRootNS()->rpriv->parseResolveReferencedScopedReferenceIntern(loc, name, typeInfo, found);
1804 DLLLOCAL
static QoreClass* parseFindClass(
const QoreProgramLocation* loc,
const char* name) {
1805 QoreClass* qc = getRootNS()->rpriv->parseFindClassIntern(name);
1807 parse_error(*loc,
"reference to undefined class '%s'", name);
1811 DLLLOCAL
static QoreClass* parseFindScopedClass(
const QoreProgramLocation* loc,
const NamedScope& name) {
1812 return getRootNS()->rpriv->parseFindScopedClassIntern(loc, name);
1815 DLLLOCAL
static QoreClass* parseFindScopedClassWithMethod(
const QoreProgramLocation* loc,
const NamedScope& name,
bool error) {
1816 return getRootNS()->rpriv->parseFindScopedClassWithMethodInternError(loc, name, error);
1819 DLLLOCAL
static void parseAddConstant(
const QoreProgramLocation* loc,
QoreNamespace& ns,
const NamedScope& name,
QoreValue value,
bool pub) {
1820 getRootNS()->rpriv->parseAddConstantIntern(loc, ns, name, value, pub);
1824 DLLLOCAL
static int parseAddMethodToClass(
const QoreProgramLocation* loc,
const NamedScope& name, MethodVariantBase* qcmethod,
bool static_flag) {
1825 return getRootNS()->rpriv->parseAddMethodToClassIntern(loc, name, qcmethod, static_flag);
1828 DLLLOCAL
static void parseAddClass(
const QoreProgramLocation* loc,
const NamedScope& name,
QoreClass* oc) {
1829 getRootNS()->rpriv->parseAddClassIntern(loc, name, oc);
1832 DLLLOCAL
static void parseAddHashDecl(
const QoreProgramLocation* loc,
const NamedScope& name,
TypedHashDecl* hd) {
1833 getRootNS()->rpriv->parseAddHashDeclIntern(loc, name, hd);
1836 DLLLOCAL
static void parseAddNamespace(
QoreNamespace* nns) {
1837 getRootNS()->rpriv->parseAddNamespaceIntern(nns);
1840 DLLLOCAL
static const QoreFunction* parseResolveFunction(
const NamedScope& nscope) {
1841 const FunctionEntry* fe = getRootNS()->rpriv->parseResolveFunctionEntryIntern(nscope);
1842 return fe ? fe->getFunction() :
nullptr;
1845 DLLLOCAL
static const FunctionEntry* parseResolveFunctionEntry(
const NamedScope& nscope) {
1846 return getRootNS()->rpriv->parseResolveFunctionEntryIntern(nscope);
1849 DLLLOCAL
const QoreClass* runtimeFindScopedClass(
const NamedScope& name)
const;
1852 return rns.rpriv->runtimeGetCallReference(name, xsink);
1855 DLLLOCAL
static Var* parseAddResolvedGlobalVarDef(
const QoreProgramLocation* loc,
const NamedScope& vname,
const QoreTypeInfo* typeInfo) {
1856 return getRootNS()->rpriv->parseAddResolvedGlobalVarDefIntern(loc, vname, typeInfo);
1859 DLLLOCAL
static Var* parseAddGlobalVarDef(
const QoreProgramLocation* loc,
const NamedScope& vname, QoreParseTypeInfo* typeInfo) {
1860 return getRootNS()->rpriv->parseAddGlobalVarDefIntern(loc, vname, typeInfo);
1863 DLLLOCAL
static Var* parseCheckImplicitGlobalVar(
const QoreProgramLocation* loc,
const NamedScope& name,
const QoreTypeInfo* typeInfo) {
1864 return getRootNS()->rpriv->parseCheckImplicitGlobalVarIntern(loc, name, typeInfo);
1867 DLLLOCAL
static Var* parseFindGlobalVar(
const char* vname) {
1868 return getRootNS()->rpriv->parseFindGlobalVarIntern(vname);
1871 DLLLOCAL
static Var* parseFindGlobalVar(
const NamedScope& nscope) {
1872 return getRootNS()->rpriv->parseFindGlobalVarIntern(nscope);
1876 ns.priv->scanMergeCommittedNamespace(*(mns.priv), qmc);
1880 ns.priv->copyMergeCommittedNamespace(*(mns.priv));
1883 ns.rpriv->rebuildAllIndexes();
1886 DLLLOCAL
static Var* runtimeFindGlobalVar(
const RootQoreNamespace& rns,
const char* vname,
const qore_ns_private*& vns) {
1887 return rns.rpriv->runtimeFindGlobalVar(vname, vns);
1890 DLLLOCAL
static Var* runtimeCreateVar(
RootQoreNamespace& rns,
QoreNamespace& vns,
const char* vname,
const QoreTypeInfo* typeInfo,
bool builtin =
false) {
1891 return rns.rpriv->runtimeCreateVar(*vns.priv, vname, typeInfo, builtin);
1895 return rns.rpriv->runtimeImportGlobalVariable(*tns.priv, v, readonly, xsink);
1908 return rns.rpriv->runtimeFindClass(name);
1911 DLLLOCAL
static const ConstantEntry* runtimeFindNamespaceConstant(
const RootQoreNamespace& rns,
const char* cname,
const qore_ns_private*& cns) {
1912 return rns.rpriv->runtimeFindNamespaceConstant(cname, cns);
1916 return rns.rpriv->runtimeFindNamespaceForAddFunction(name, xsink);
1920 return rns.rpriv->runtimeFindNamespaceForAddClass(name, xsink);
1932 return rns.rpriv->qoreNS->priv;
1936 return rns.rpriv->qoreNS->priv;
1940 ns.priv->clearConstants(l);
1941 ns.rpriv->cnmap.clear();
1945 ns.priv->clearData(xsink);
DLLEXPORT const char * c_str() const
returns the string's buffer; this data should not be changed
DLLEXPORT qore_offset_t bindex(const QoreString &needle, qore_offset_t pos) const
returns the byte position of a substring within the string or -1 if not found
DLLEXPORT const char * getName() const
returns the name of the typed hash
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
#define PO_NO_API
an alias of PO_INHERITANCE_OPTIONS
Definition: Restrictions.h:153
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:64
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
base class for call references, reference-counted, dynamically allocated only
Definition: CallReferenceNode.h:39
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
DLLEXPORT QoreProgram * getProgram()
returns the current QoreProgram
the root namespace of a QoreProgram object
Definition: QoreNamespace.h:286
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
DLLEXPORT QoreNamespace(const char *n)
creates a namespace with the given name
defines a Qore-language class
Definition: QoreClass.h:239
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:126
DLLEXPORT QoreNamespace * findCreateNamespacePath(const char *nspath)
finds a Namespace based on the argument; creates it (or the whole path) if necessary ...
static unsigned num_params(const QoreListNode *n)
returns the number of arguments passed to the function
Definition: params.h:54
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
DLLEXPORT const char * getName() const
returns the name of the namespace
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:257
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:118
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
std::vector< QoreValue > arg_vec_t
vector of value information for default argument lists
Definition: common.h:254
DLLEXPORT void addConstant(const char *name, QoreValue value)
adds a constant definition to the namespace
an unresolved call reference, only present temporarily in the parse tree
Definition: CallReferenceNode.h:68
typed hash declaration
Definition: TypedHashDecl.h:44
base class for resolved call references
Definition: CallReferenceNode.h:105
DLLEXPORT QoreNamespace * copy(int po) const
returns a deep copy of the namespace; DEPRECATED: use copy(int64) instead
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:251
DLLEXPORT const char * getName() const
returns the class name