diff options
author | Frank Busse <bb0xfb@gmail.com> | 2019-09-11 21:27:11 +0100 |
---|---|---|
committer | MartinNowack <martin.nowack@gmail.com> | 2019-09-20 15:45:39 +0100 |
commit | 0aed7731210d0eb41c0ea767edb8067130cf6252 (patch) | |
tree | 61e6aa1241474e419568ac8b4d1a73c7c17c3f85 | |
parent | d773e3f762affd7189d34fbd6d1e7e0e5af3f712 (diff) | |
download | klee-0aed7731210d0eb41c0ea767edb8067130cf6252.tar.gz |
refactor PTree: use unique_ptr
-rw-r--r-- | lib/Core/PTree.cpp | 22 | ||||
-rw-r--r-- | lib/Core/PTree.h | 6 | ||||
-rw-r--r-- | lib/Core/Searcher.cpp | 8 |
3 files changed, 17 insertions, 19 deletions
diff --git a/lib/Core/PTree.cpp b/lib/Core/PTree.cpp index 9747e814..91a6d883 100644 --- a/lib/Core/PTree.cpp +++ b/lib/Core/PTree.cpp @@ -18,16 +18,15 @@ using namespace klee; PTree::PTree(ExecutionState *initialState) { - root = new PTreeNode(nullptr, initialState); - initialState->ptreeNode = root; + root = std::make_unique<PTreeNode>(nullptr, initialState); } void PTree::attach(PTreeNode *node, ExecutionState *leftState, ExecutionState *rightState) { assert(node && !node->left && !node->right); node->state = nullptr; - node->left = new PTreeNode(node, leftState); - node->right = new PTreeNode(node, rightState); + node->left = std::make_unique<PTreeNode>(node, leftState); + node->right = std::make_unique<PTreeNode>(node, rightState); } void PTree::remove(PTreeNode *n) { @@ -35,14 +34,13 @@ void PTree::remove(PTreeNode *n) { do { PTreeNode *p = n->parent; if (p) { - if (n == p->left) { + if (n == p->left.get()) { p->left = nullptr; } else { - assert(n == p->right); + assert(n == p->right.get()); p->right = nullptr; } } - delete n; n = p; } while (n && !n->left && !n->right); } @@ -58,7 +56,7 @@ void PTree::dump(llvm::raw_ostream &os) { os << "\tnode [style=\"filled\",width=.1,height=.1,fontname=\"Terminus\"]\n"; os << "\tedge [arrowsize=.3]\n"; std::vector<const PTreeNode*> stack; - stack.push_back(root); + stack.push_back(root.get()); while (!stack.empty()) { const PTreeNode *n = stack.back(); stack.pop_back(); @@ -67,12 +65,12 @@ void PTree::dump(llvm::raw_ostream &os) { os << ",fillcolor=green"; os << "];\n"; if (n->left) { - os << "\tn" << n << " -> n" << n->left << ";\n"; - stack.push_back(n->left); + os << "\tn" << n << " -> n" << n->left.get() << ";\n"; + stack.push_back(n->left.get()); } if (n->right) { - os << "\tn" << n << " -> n" << n->right << ";\n"; - stack.push_back(n->right); + os << "\tn" << n << " -> n" << n->right.get() << ";\n"; + stack.push_back(n->right.get()); } } os << "}\n"; diff --git a/lib/Core/PTree.h b/lib/Core/PTree.h index 6456b57f..01632ebf 100644 --- a/lib/Core/PTree.h +++ b/lib/Core/PTree.h @@ -18,8 +18,8 @@ namespace klee { class PTreeNode { public: PTreeNode *parent = nullptr; - PTreeNode *left = nullptr; - PTreeNode *right = nullptr; + std::unique_ptr<PTreeNode> left; + std::unique_ptr<PTreeNode> right; ExecutionState *state = nullptr; PTreeNode(const PTreeNode&) = delete; @@ -29,7 +29,7 @@ namespace klee { class PTree { public: - PTreeNode * root = nullptr; + std::unique_ptr<PTreeNode> root; explicit PTree(ExecutionState *initialState); ~PTree() = default; diff --git a/lib/Core/Searcher.cpp b/lib/Core/Searcher.cpp index 8d35b7ef..0d5d61e2 100644 --- a/lib/Core/Searcher.cpp +++ b/lib/Core/Searcher.cpp @@ -264,19 +264,19 @@ RandomPathSearcher::~RandomPathSearcher() { ExecutionState &RandomPathSearcher::selectState() { unsigned flips=0, bits=0; - PTreeNode *n = executor.processTree->root; + PTreeNode *n = executor.processTree->root.get(); while (!n->state) { if (!n->left) { - n = n->right; + n = n->right.get(); } else if (!n->right) { - n = n->left; + n = n->left.get(); } else { if (bits==0) { flips = theRNG.getInt32(); bits = 32; } --bits; - n = (flips&(1<<bits)) ? n->left : n->right; + n = (flips&(1<<bits)) ? n->left.get() : n->right.get(); } } |