59 if (debugger.trace(
"memory") && obj != NULL) {
60 ostream& os = debugger.getOS();
67 os <<
"*** Warning: ~Scope(): found "<< n <<
" leaked objects "
68 <<
"in scope " << d_level <<
":" <<
endl;
69 if (debugger.flag(
"memory leaks")) {
72 os << tmp->name() <<
"\n";
84 unsigned long memSelf = 0;
85 unsigned long mem = 0;
87 mem += getCMM()->getMemory(verbosity - 1);
88 if (d_prevScope != NULL) {
89 mem += d_prevScope->getMemory(verbosity - 1);
95 cout <<
"Scope " << d_level <<
": " << memSelf <<
endl;
96 cout <<
" Children: " << mem <<
endl;
97 cout <<
" Total: " << mem+memSelf <<
endl;
100 return mem + memSelf;
116 DebugAssert(d_master != NULL,
"How did this happen");
128 d_master->restoreData(d_data);
129 d_master->d_scope = d_data->d_scope;
130 d_master->d_restore = d_restore;
131 next = d_restoreChainNext;
132 if (d_data != NULL)
delete d_data;
133 DebugAssert(d_master->d_restore !=
this,
"points to self");
139 #ifdef _CVC3_DEBUG_MODE
140 std::string ContextObjChain::name()
const
143 return d_master->name();
155 Scope* tmpScope = d_scope;
156 DebugAssert(scope < 0 || d_scope->level() <= scope,
158 +
"): scope < d_scope->level() = "
160 d_scope = d_scope->topScope();
163 for(
int i=level(); i>scope; --i) {
164 d_scope = d_scope->prevScope();
166 +name()+
"]: d_scope == NULL");
173 IF_DEBUG(data->setName(name()+
" [copy]");)
175 d_scope->addToChain(d_restore);
187 if(obj->d_restoreChainNext != NULL)
209 : d_cm(cm), d_name(name), d_id(id)
214 TRACE(
"context",
"*** [context] Creating new context: name = "
215 + name +
"id = ",
id,
"");
239 (*i)->d_context = NULL;
247 string indentStr(
level(),
' ');
248 TRACE(
"pushpop", indentStr,
"Push",
" {");
261 IF_DEBUG(DebugCounter maxLevel(debugger.counter(
"max scope level"));)
271 "Illegal to pop last scope off of stack.");
290 string indentStr(
level(),
' ');
291 TRACE(
"pushpop", indentStr,
"}",
" Pop");
314 unsigned long memSelf =
sizeof(
Context);
315 unsigned long mem = 0;
321 return mem + memSelf;
332 d_curContext = createContext(
"default");
338 while (d_contexts.size()) {
339 delete d_contexts.back();
340 d_contexts.pop_back();
347 d_contexts.push_back(
new Context(
this, name, d_contexts.size()));
348 return d_contexts.back();
354 FatalAssert(
false,
"Multiple contexts not yet implemented");
358 d_curContext = context;
367 unsigned long mem = 0;
373 for (
unsigned i = 0; i < d_contexts.size(); ++i) {
374 mem += d_contexts[i]->getMemory(verbosity - 1);
379 return mem + memSelf;
ContextObjChain ** d_restoreChainPrev
Pointer to the pointer of the previous object which points to us. This makes a doubly-linked list for...
Context * createContext(const std::string &name="")
ContextObjChain * d_restore
The list of values on previous scopes; our destructor should clean up those.
static unsigned long getVecAndDataP(int verbosity, const std::vector< T > &v)
static unsigned getStaticMemory(int verbosity)
std::string d_name
Name of context.
ContextObjChain * d_restore
Pointer to the previous copy which belongs to the same master.
static unsigned long getString(int verbosity, const std::string &s)
ContextObjChain * d_restoreChainNext
Next link in chain.
void update(int scope=-1)
Update on the given scope, on the current scope if 'scope' == -1.
unsigned long getMemory(int verbosity)
std::vector< ContextMemoryManager * > d_cmmStack
Stack of free ContextMemoryManager's.
#define DebugAssert(cond, str)
void deleteNotifyObj(ContextNotifyObj *obj)
unsigned long getMemory(int verbosity)
Compute memory used.
Context * switchContext(Context *context)
CVC3::ExprStream & endl(CVC3::ExprStream &os)
Print the end-of-line.
ContextMemoryManager * getCMM() const
#define FatalAssert(cond, msg)
If something goes horribly wrong, print a message and abort immediately with exit(1).
Scope * d_topScope
Pointer to top and bottom scopes of context.
unsigned long getMemory(int verbosity)
void restore(void)
Restore all the values.
std::vector< ContextNotifyObj * > d_notifyObjList
List of objects to notify with every pop.
std::string int2string(int n)
ContextObjChain * restore(void)
Restore from d_data to d_master.
static void print(std::string name, int verbosity, unsigned long memSelf, unsigned long mem)
void finalize(void)
Called by ~ContextManager.
Scope * d_scope
Last scope in which this object was modified.
ContextObj * d_master
Pointer to the master object.
Scope * prevScope() const
Access functions.
static std::vector< char * > s_freePages
static void garbageCollect(void)
Manager for multiple contexts. Also holds current context.
Context(ContextManager *cm, const std::string &name, int id)
const std::string & name() const
void check(void)
Check for memory leaks.