namespace context {
-Context::Context() : d_pContextNotifyObj(NULL) {
+Context::Context() : d_pCNOpre(NULL), d_pCNOpost(NULL) {
// Create new memory manager
d_pCMM = new ContextMemoryManager();
// Create initial Scope
- d_pScopeTop = new(cmm) Scope(this, cmm);
+ d_pScopeTop = new(d_pCMM) Scope(this, d_pCMM);
d_pScopeBottom = d_pScopeTop;
}
while (d_pCNOpre != NULL) {
pCNO = d_pCNOpre;
pCNO->d_ppCNOprev = NULL;
- d_pContextNotifyObj = pCNO->d_pCNOnext;
+ d_pCNOpre = pCNO->d_pCNOnext;
pCNO->d_pCNOnext = NULL;
}
while (d_pCNOpost != NULL) {
pCNO = d_pCNOpost;
pCNO->d_ppCNOprev = NULL;
- d_pContextNotifyObj = pCNO->d_pCNOnext;
+ d_pCNOpost = pCNO->d_pCNOnext;
pCNO->d_pCNOnext = NULL;
}
}
void Context::pop() {
// Notify the (pre-pop) ContextNotifyObj objects
- ContextNotifyObj* pCNO = d_pCNOPre;
+ ContextNotifyObj* pCNO = d_pCNOpre;
while (pCNO != NULL) {
pCNO->notify();
pCNO = pCNO->d_pCNOnext;
d_pScopeTop = pScope->getScopePrev();
// Restore all objects in the top Scope
- delete(d_pCMM) pScope;
+ delete pScope;
// Pop the memory region
d_pCMM->pop();
// Notify the (post-pop) ContextNotifyObj objects
- ContextNotifyObj* pCNO = d_pCNOPost;
+ pCNO = d_pCNOpost;
while (pCNO != NULL) {
pCNO->notify();
pCNO = pCNO->d_pCNOnext;
void Context::popto(int toLevel) {
// Pop scopes until there are none left or toLevel is reached
- while (d_pScopeTop != NULL && toLevel < d_pScopeTop()->getLevel()) pop();
+ while (d_pScopeTop != NULL && toLevel < d_pScopeTop->getLevel()) pop();
}
// Restore the base class data
d_pScope = d_pContextObjRestore->d_pScope;
next() = d_pContextObjRestore->d_pContextObjNext;
- prev() = d_pContextObjRestore->d_pContextObjPrev;
+ prev() = d_pContextObjRestore->d_ppContextObjPrev;
d_pContextObjRestore = d_pContextObjRestore->d_pContextObjRestore;
}
// Return the next object in the list
}
-ContextNotifyObj::ContextNotifyObj(Context* pContext, bool preNotify = false) {
+ContextNotifyObj::ContextNotifyObj(Context* pContext, bool preNotify) {
if (preNotify) {
pContext->addNotifyObjPre(this);
}
ContextNotifyObj::~ContextNotifyObj()
{
if (d_pCNOnext != NULL) {
- d_pCNOnext->d_pCNOprev = d_pCNOprev;
+ d_pCNOnext->d_ppCNOprev = d_ppCNOprev;
}
- if (d_pCNOprev != NULL) {
- *(d_pCNOprev) = d_pCNOnext;
+ if (d_ppCNOprev != NULL) {
+ *(d_ppCNOprev) = d_pCNOnext;
}
}
#ifndef __CVC4__CONTEXT__CONTEXT_H
#define __CVC4__CONTEXT__CONTEXT_H
+#include "context/context_mm.h"
+
namespace CVC4 {
namespace context {
*/
Scope(Context* pContext, ContextMemoryManager* pCMM,
Scope* pScopePrev = NULL)
- : d_pContext(context), d_pCMM(pCMM), d_pScopePrev(pScopePrev),
+ : d_pContext(pContext), d_pCMM(pCMM), d_pScopePrev(pScopePrev),
d_level(0), d_pContextObjList(NULL)
{ if (pScopePrev != NULL) d_level = pScopePrev->getLevel() + 1; }
* ContextMemoryManager. No need to do anything because memory is freed
* automatically when the ContextMemoryManager pop() method is called.
*/
- void operator delete(void* pMem, ContextMemoryManager* pCMM) {}
+ void operator delete(void* pMem) {}
//FIXME: //! Check for memory leaks
// void check(void);
* Context is our friend so that when the Context is deleted, any remaining
* ContextNotifyObj can be removed from the Context list.
*/
- friend Context;
+ friend class Context;
/**
* Pointer to next ContextNotifyObject in this List
*/
ContextNotifyObj** d_ppCNOprev;
+ /**
+ * Return reference to next link in ContextNotifyObj list. Used by
+ * Context::addNotifyObj methods.
+ */
+ ContextNotifyObj*& next() { return d_pCNOnext; }
+
+ /**
+ * Return reference to prev link in ContextNotifyObj list. Used by
+ * Context::addNotifyObj methods.
+ */
+ ContextNotifyObj**& prev() { return d_ppCNOprev; }
+
public:
/**
* Constructor for ContextNotifyObj. Parameters are the context to which
inline int Context::getLevel() const { return getTopScope()->getLevel(); }
-inline void Scope::~Scope() {
+inline Scope::~Scope() {
// Call restore() method on each ContextObj object in the list.
// Note that it is the responsibility of restore() to return the next item in
// the list.
}
}
-inline void Scope::addToChain(ContextObjChain* pContextObj) {
+inline void Scope::addToChain(ContextObj* pContextObj) {
if(d_pContextObjList != NULL)
d_pContextObjList->prev() = &(pContextObj->next());
pContextObj->next() = d_pContextObjList;