summaryrefslogtreecommitdiff
path: root/src/context/context.cpp
diff options
context:
space:
mode:
authorClark Barrett <barrett@cs.nyu.edu>2010-02-02 02:04:39 +0000
committerClark Barrett <barrett@cs.nyu.edu>2010-02-02 02:04:39 +0000
commit21dec26be1ecc86a0c73df26e2397b7674df50a7 (patch)
treebd64e8a7d11b29f46b721323715f68daf1a78373 /src/context/context.cpp
parent595eb7e203d27a9b24a2b71808bc79dab76fa7ba (diff)
Updates to context:
Use vector instead of linked list for Scopes Added CDO and CDList templates
Diffstat (limited to 'src/context/context.cpp')
-rw-r--r--src/context/context.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/context/context.cpp b/src/context/context.cpp
index b83260835..8083f2cc7 100644
--- a/src/context/context.cpp
+++ b/src/context/context.cpp
@@ -26,8 +26,7 @@ Context::Context() : d_pCNOpre(NULL), d_pCNOpost(NULL) {
d_pCMM = new ContextMemoryManager();
// Create initial Scope
- d_pScopeTop = new(d_pCMM) Scope(this, d_pCMM);
- d_pScopeBottom = d_pScopeTop;
+ d_scopeList.push_back(new(d_pCMM) Scope(this, d_pCMM, 0));
}
@@ -62,7 +61,7 @@ void Context::push() {
d_pCMM->push();
// Create a new top Scope
- d_pScopeTop = new(d_pCMM) Scope(this, d_pCMM, d_pScopeTop);
+ d_scopeList.push_back(new(d_pCMM) Scope(this, d_pCMM, getLevel()+1));
}
@@ -75,10 +74,10 @@ void Context::pop() {
}
// Grab the top Scope
- Scope* pScope = d_pScopeTop;
+ Scope* pScope = d_scopeList.back();
// Restore the previous Scope
- d_pScopeTop = pScope->getScopePrev();
+ d_scopeList.pop_back();
// Restore all objects in the top Scope
delete pScope;
@@ -99,7 +98,8 @@ void Context::pop() {
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();
+ if (toLevel < -1) toLevel = -1;
+ while (toLevel < getLevel()) pop();
}
@@ -219,6 +219,27 @@ ContextNotifyObj::~ContextNotifyObj()
}
+template<class T>
+void CDList<T>::grow() {
+ if (d_list == NULL) {
+ // Allocate an initial list if one does not yet exist
+ d_sizeAlloc = 10;
+ d_list = malloc(sizeof(T)*d_sizeAlloc);
+ }
+ else {
+ // Allocate a new array with double the size
+ d_sizeAlloc *= 2;
+ T* newList = malloc(sizeof(T)*d_sizeAlloc);
+
+ // Copy the old data
+ memcpy(d_list, newList, sizeof(T)*d_size);
+
+ // Free the old list
+ free(d_list);
+ }
+}
+
+
} /* CVC4::context namespace */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback