37 #ifndef _QORE_CONSTANTLIST_H 39 #define _QORE_CONSTANTLIST_H 42 #include "qore/intern/ParseNode.h" 46 class qore_ns_private;
47 class 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;
86 class RuntimeConstantRefNode;
89 friend class ConstantEntryInitHelper;
90 friend class RuntimeConstantRefNode;
91 friend class ConstantList;
94 const QoreProgramLocation* loc;
97 const QoreTypeInfo* typeInfo;
105 DLLLOCAL ConstantEntry(
const QoreProgramLocation* loc,
const char* n,
QoreValue v,
const QoreTypeInfo* ti = 0,
bool n_pub =
false,
bool n_init =
false,
bool n_builtin =
false, ClassAccess n_access = Public);
106 DLLLOCAL ConstantEntry(
const ConstantEntry& old);
109 if (ROdereference()) {
116 if (ROdereference()) {
122 DLLLOCAL
void ref() {
126 DLLLOCAL ConstantEntry* refSelf() {
131 DLLLOCAL
int parseInit(ClassNs ptr);
133 DLLLOCAL
QoreValue get(
const QoreProgramLocation* loc,
const QoreTypeInfo*& constantTypeInfo, ClassNs ptr) {
135 parse_error(*loc,
"recursive constant reference found to constant '%s'", name.c_str());
136 constantTypeInfo = nothingTypeInfo;
140 if (!init && parseInit(ptr)) {
141 constantTypeInfo = nothingTypeInfo;
145 constantTypeInfo = typeInfo;
149 DLLLOCAL
const char* getName()
const {
153 DLLLOCAL
const std::string& getNameStr()
const {
157 DLLLOCAL
bool isPublic()
const {
161 DLLLOCAL
bool isUserPublic()
const {
162 return pub && !builtin;
165 DLLLOCAL
bool isSystem()
const {
169 DLLLOCAL
bool isUser()
const {
173 DLLLOCAL ClassAccess getAccess()
const {
181 DLLLOCAL
int scanValue(
const QoreValue& n)
const;
186 DLLLOCAL ~ConstantEntry() {
188 assert(val.isNothing());
192 class ConstantEntryInitHelper {
197 DLLLOCAL ConstantEntryInitHelper(ConstantEntry& n_ce) : ce(n_ce) {
204 DLLLOCAL ~ConstantEntryInitHelper() {
213 #include <qore/vector_map> 214 typedef vector_map_t<const char*, ConstantEntry*> cnemap_t;
229 friend class ConstantListIterator;
230 friend class ConstConstantListIterator;
234 DLLLOCAL ConstantList& operator=(
const ConstantList&);
243 vector_map_t<std::string, ConstantEntry*> new_cnemap;
246 DLLLOCAL ~ConstantList();
248 DLLLOCAL ConstantList(ClassNs p) : ptr(p) {
252 DLLLOCAL ConstantList(
const ConstantList& old,
int64 po, ClassNs p);
255 DLLLOCAL cnemap_t::iterator add(
const char* name,
QoreValue val,
const QoreTypeInfo* typeInfo =
nullptr, ClassAccess access = Public);
257 DLLLOCAL cnemap_t::iterator parseAdd(
const QoreProgramLocation* loc,
const char* name,
QoreValue val,
const QoreTypeInfo* typeInfo =
nullptr,
bool pub =
false, ClassAccess access = Public);
259 DLLLOCAL ConstantEntry* findEntry(
const char* name);
261 DLLLOCAL
const ConstantEntry* findEntry(
const char* name)
const;
263 DLLLOCAL
QoreValue find(
const char* name,
const QoreTypeInfo*& constantTypeInfo, ClassAccess& access,
bool& found);
265 DLLLOCAL
QoreValue find(
const char* name,
const QoreTypeInfo*& constantTypeInfo,
bool& found) {
267 return find(name, constantTypeInfo, access, found);
270 DLLLOCAL
bool inList(
const char* name)
const;
271 DLLLOCAL
bool inList(
const std::string& name)
const;
275 DLLLOCAL
void assimilate(ConstantList& n);
278 DLLLOCAL
void assimilate(ConstantList& n,
const char* type,
const char* name);
281 DLLLOCAL
void mergeUserPublic(
const ConstantList& src);
283 DLLLOCAL
int importSystemConstants(
const ConstantList& src,
ExceptionSink* xsink);
286 DLLLOCAL
void parseAdd(
const QoreProgramLocation* loc,
const std::string& name,
QoreValue val, ClassAccess access,
const char* cname);
288 DLLLOCAL
void parseInit();
290 DLLLOCAL
void parseDeleteAll();
293 DLLLOCAL
void reset();
295 DLLLOCAL
bool empty()
const {
296 return cnemap.empty();
299 DLLLOCAL cnemap_t::iterator end() {
303 DLLLOCAL cnemap_t::const_iterator end()
const {
307 DLLLOCAL
void setAccess(ClassAccess access) {
308 for (
auto& i : cnemap)
309 i.second->access = access;
313 class ConstantListIterator {
316 cnemap_t::iterator i;
319 DLLLOCAL ConstantListIterator(ConstantList& n_cl) : cl(n_cl.cnemap), i(cl.end()) {
322 DLLLOCAL
bool next() {
327 return i != cl.end();
330 DLLLOCAL
const std::string& getName()
const {
331 return i->second->getNameStr();
335 return i->second->val;
338 DLLLOCAL ConstantEntry* getEntry()
const {
342 DLLLOCAL ClassAccess getAccess()
const {
343 return i->second->getAccess();
346 DLLLOCAL
bool isPublic()
const {
347 return i->second->isPublic();
350 DLLLOCAL
bool isUserPublic()
const {
351 return i->second->isUserPublic();
355 class ConstConstantListIterator {
358 cnemap_t::const_iterator i;
361 DLLLOCAL ConstConstantListIterator(
const ConstantList& n_cl) : cl(n_cl.cnemap), i(cl.end()) {
364 DLLLOCAL
bool next() {
369 return i != cl.end();
372 DLLLOCAL
const std::string& getName()
const {
373 return i->second->getNameStr();
376 DLLLOCAL
const QoreValue getValue()
const {
377 return i->second->val;
380 DLLLOCAL
const ConstantEntry* getEntry()
const {
384 DLLLOCAL
bool isPublic()
const {
385 return i->second->isPublic();
388 DLLLOCAL
bool isUserPublic()
const {
389 return i->second->isUserPublic();
393 class RuntimeConstantRefNode :
public ParseNode {
397 DLLLOCAL
virtual void parseInitImpl(
QoreValue& val, LocalVar* oflag,
int pflag,
int& lvids,
const QoreTypeInfo*& typeInfo) {
400 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
401 assert(ce->saved_node);
402 return getTypeInfoForValue(ce->saved_node);
406 assert(ce->saved_node);
407 return ce->saved_node->eval(needs_deref, xsink);
410 DLLLOCAL ~RuntimeConstantRefNode() {
414 DLLLOCAL RuntimeConstantRefNode(
const QoreProgramLocation* loc, ConstantEntry* n_ce) : ParseNode(loc,
NT_RTCONSTREF, true, false), ce(n_ce) {
415 assert(ce->saved_node);
419 assert(ce->saved_node);
420 return ce->saved_node->getAsString(str, foff, xsink);
424 assert(ce->saved_node);
425 return ce->saved_node->getAsString(del, foff, xsink);
428 DLLLOCAL
virtual const char* getTypeName()
const {
429 return ce->saved_node ? ce->saved_node->getTypeName() :
"nothing";
433 #endif // _QORE_CONSTANTLIST_H This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
const qore_type_t NT_RTCONSTREF
type value for RuntimeConstantRefNode
Definition: node_types.h:82
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
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
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
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