40 #ifndef QORE_NAMEDSCOPE_H
42 #define QORE_NAMEDSCOPE_H
50 typedef std::vector<std::string> nslist_t;
52 nslist_t* strlist =
nullptr;
60 DLLLOCAL NamedScope(
char *str) : del(true), ostr(str) {
65 DLLLOCAL NamedScope(
const char *str) : del(false), ostr((char *)str) {
71 DLLLOCAL NamedScope(NamedScope* ns) : strlist(ns->strlist), del(ns->del), ostr(ns->ostr) {
72 ns->strlist =
nullptr;
77 DLLLOCAL NamedScope(
const NamedScope& old) : del(true), ostr(strdup(old.ostr)) {
79 strlist =
new nslist_t(*old.strlist);
86 DLLLOCAL ~NamedScope() {
90 DLLLOCAL
void clear() {
101 DLLLOCAL
const char* getIdentifier()
const {
102 return strlist ? (*strlist)[strlist->size() - 1].c_str() : ostr;
105 DLLLOCAL
const char* get(
unsigned i)
const {
106 if (!i && !strlist) {
110 assert(i < strlist->size());
111 return (*strlist)[i].c_str();
114 DLLLOCAL
const char* operator[](
unsigned i)
const {
115 if (!i && !strlist) {
119 assert(i < strlist->size());
120 return (*strlist)[i].c_str();
123 DLLLOCAL
unsigned size()
const {
124 return strlist ? strlist->size() : 1;
127 DLLLOCAL NamedScope* copy()
const;
128 DLLLOCAL
void fixBCCall();
130 DLLLOCAL
char* takeName() {
131 char *rv = del ? ostr : strdup(ostr);
137 DLLLOCAL
void optimize() {
142 while (strlist->size() > 1) {
143 strlist->erase(strlist->begin());
148 ostr = (
char*)strlist->back().c_str();
155 DLLLOCAL
bool operator()(
const NamedScope& s1,
const NamedScope& s2)
const {
156 return strcmp(s1.ostr, s2.ostr) < 0;