37#ifndef _QORE_CONSTANTLIST_H
39#define _QORE_CONSTANTLIST_H
42#include "qore/intern/ParseNode.h"
47class qore_class_private;
55 DLLLOCAL ClassNs(qore_class_private* qc) : ptr((size_t)qc) {
58 DLLLOCAL ClassNs(qore_ns_private* ns) {
59 ptr = ((size_t)ns) | (size_t)1;
62 DLLLOCAL ClassNs(
const ClassNs& old) : ptr(old.ptr) {
65 DLLLOCAL qore_class_private* getClass()
const {
66 return (!(ptr & (
size_t)1)) ? (qore_class_private*)ptr :
nullptr;
69 DLLLOCAL qore_ns_private* getNs()
const {
70 return (ptr & (
size_t)1) ? (qore_ns_private*)(ptr & ~(
size_t)1) :
nullptr;
73 DLLLOCAL
bool isNs()
const {
74 return (
bool)(ptr & (size_t)1);
78 DLLLOCAL
const char* getType()
const {
79 return isNs() ?
"namespace" :
"class";
82 DLLLOCAL
const char* getName()
const;
86class RuntimeConstantRefNode;
89 friend class ConstantEntryInitHelper;
90 friend class RuntimeConstantRefNode;
91 friend class ConstantList;
94 const QoreProgramLocation* loc;
97 const QoreTypeInfo* typeInfo;
106 DLLLOCAL ConstantEntry(
const QoreProgramLocation* loc,
const char* n,
QoreValue v,
107 const QoreTypeInfo* ti =
nullptr,
bool n_pub =
false,
bool n_init =
false,
bool n_builtin =
false,
108 ClassAccess n_access = Public);
110 DLLLOCAL ConstantEntry(
const ConstantEntry& old);
126 DLLLOCAL
void ref()
const {
130 DLLLOCAL ConstantEntry* refSelf()
const {
132 return const_cast<ConstantEntry*
>(
this);
135 DLLLOCAL
QoreValue getReferencedValue()
const;
137 DLLLOCAL
int parseInit(ClassNs ptr);
139 DLLLOCAL
int parseCommitRuntimeInit();
141 DLLLOCAL
QoreValue get(
const QoreProgramLocation* loc,
const QoreTypeInfo*& constantTypeInfo, ClassNs ptr) {
143 parse_error(*loc,
"recursive constant reference found to constant '%s'", name.c_str());
144 constantTypeInfo = nothingTypeInfo;
148 if (!init && parseInit(ptr)) {
149 constantTypeInfo = nothingTypeInfo;
153 constantTypeInfo = typeInfo;
157 DLLLOCAL
const char* getName()
const {
161 DLLLOCAL
const std::string& getNameStr()
const {
165 DLLLOCAL
bool isPublic()
const {
169 DLLLOCAL
bool isUserPublic()
const {
170 return pub && !builtin;
173 DLLLOCAL
bool isSystem()
const {
177 DLLLOCAL
bool isUser()
const {
181 DLLLOCAL ClassAccess getAccess()
const {
185 DLLLOCAL
const char* getModuleName()
const {
186 return from_module.empty() ? nullptr : from_module.c_str();
192 std::string from_module;
194 DLLLOCAL ~ConstantEntry() {
203class ConstantEntryInitHelper {
208 DLLLOCAL ConstantEntryInitHelper(ConstantEntry& n_ce) : ce(n_ce) {
215 DLLLOCAL ~ConstantEntryInitHelper() {
224#include <qore/vector_map>
225typedef vector_map_t<const char*, ConstantEntry*> cnemap_t;
240 friend class ConstantListIterator;
241 friend class ConstConstantListIterator;
245 DLLLOCAL ConstantList& operator=(
const ConstantList&);
254 vector_map_t<std::string, ConstantEntry*> new_cnemap;
257 DLLLOCAL ~ConstantList();
259 DLLLOCAL ConstantList(ClassNs p) : ptr(p) {
263 DLLLOCAL ConstantList(
const ConstantList& old,
int64 po, ClassNs p);
266 DLLLOCAL cnemap_t::iterator add(
const char* name,
QoreValue val,
const QoreTypeInfo* typeInfo =
nullptr,
267 ClassAccess access = Public);
269 DLLLOCAL cnemap_t::iterator parseAdd(
const QoreProgramLocation* loc,
const char* name,
QoreValue val,
270 const QoreTypeInfo* typeInfo =
nullptr,
bool pub =
false, ClassAccess access = Public);
272 DLLLOCAL ConstantEntry* findEntry(
const char* name);
274 DLLLOCAL
const ConstantEntry* findEntry(
const char* name)
const;
276 DLLLOCAL
QoreValue find(
const char* name,
const QoreTypeInfo*& constantTypeInfo, ClassAccess& access,
279 DLLLOCAL
QoreValue find(
const char* name,
const QoreTypeInfo*& constantTypeInfo,
bool& found) {
281 return find(name, constantTypeInfo, access, found);
284 DLLLOCAL
bool inList(
const char* name)
const;
285 DLLLOCAL
bool inList(
const std::string& name)
const;
289 DLLLOCAL
void assimilate(ConstantList& n);
292 DLLLOCAL
void assimilate(ConstantList& n,
const char* type,
const char* name);
295 DLLLOCAL
void mergeUserPublic(
const ConstantList& src);
297 DLLLOCAL
int importSystemConstants(
const ConstantList& src,
ExceptionSink* xsink);
300 DLLLOCAL
void parseAdd(
const QoreProgramLocation* loc,
const std::string& name,
QoreValue val, ClassAccess access,
303 DLLLOCAL
int parseInit();
304 DLLLOCAL
int parseCommitRuntimeInit();
307 DLLLOCAL
void parseDeleteAll();
310 DLLLOCAL
void reset();
312 DLLLOCAL
bool empty()
const {
313 return cnemap.empty();
316 DLLLOCAL cnemap_t::iterator end() {
320 DLLLOCAL cnemap_t::const_iterator end()
const {
324 DLLLOCAL
void setAccess(ClassAccess access) {
325 for (
auto& i : cnemap)
326 i.second->access = access;
330class ConstantListIterator {
333 cnemap_t::iterator i;
336 DLLLOCAL ConstantListIterator(ConstantList& n_cl) : cl(n_cl.cnemap), i(cl.end()) {
339 DLLLOCAL
bool next() {
344 return i != cl.end();
347 DLLLOCAL
const std::string& getName()
const {
348 return i->second->getNameStr();
352 return i->second->val;
355 DLLLOCAL ConstantEntry* getEntry()
const {
359 DLLLOCAL ClassAccess getAccess()
const {
360 return i->second->getAccess();
363 DLLLOCAL
bool isPublic()
const {
364 return i->second->isPublic();
367 DLLLOCAL
bool isUserPublic()
const {
368 return i->second->isUserPublic();
372class ConstConstantListIterator {
375 cnemap_t::const_iterator i;
378 DLLLOCAL ConstConstantListIterator(
const ConstantList& n_cl) : cl(n_cl.cnemap), i(cl.end()) {
381 DLLLOCAL
bool next() {
386 return i != cl.end();
389 DLLLOCAL
const std::string& getName()
const {
390 return i->second->getNameStr();
393 DLLLOCAL
const QoreValue getValue()
const {
394 return i->second->val;
397 DLLLOCAL
const ConstantEntry* getEntry()
const {
401 DLLLOCAL
bool isPublic()
const {
402 return i->second->isPublic();
405 DLLLOCAL
bool isUserPublic()
const {
406 return i->second->isUserPublic();
410class RuntimeConstantRefNode :
public ParseNode {
414 DLLLOCAL
virtual int parseInitImpl(
QoreValue& val, QoreParseContext& parse_context) {
415 parse_context.typeInfo = ce->typeInfo;
419 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
424 return ce->saved_val.
eval(needs_deref, xsink);
427 DLLLOCAL ~RuntimeConstantRefNode() {
431 DLLLOCAL RuntimeConstantRefNode(
const QoreProgramLocation* loc, ConstantEntry* n_ce) : ParseNode(loc,
433 assert(ce->saved_val);
436 DLLLOCAL ConstantEntry* getConstantEntry()
const {
441 assert(ce->saved_val);
442 return ce->saved_val.getAsString(str, foff, xsink);
446 assert(ce->saved_val);
447 return ce->saved_val.getAsString(del, foff, xsink);
450 DLLLOCAL
virtual const char* getTypeName()
const {
451 return ce->saved_val.getTypeName();
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:44
DLLEXPORT void ROreference() const
atomically increments the reference count
DLLEXPORT bool ROdereference() const
atomically decrements the reference count
DLLEXPORT bool isNothing() const
returns true if the object contains NOTHING
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
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
const qore_type_t NT_RTCONSTREF
type value for RuntimeConstantRefNode
Definition: node_types.h:82
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276
DLLEXPORT QoreValue eval(ExceptionSink *xsink) const
evaluates the node and returns the result