PTree.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "PTree.h"
00011
00012 #include <klee/Expr.h>
00013 #include <klee/util/ExprPPrinter.h>
00014
00015 #include <vector>
00016 #include <iostream>
00017
00018 using namespace klee;
00019
00020
00021
00022 PTree::PTree(const data_type &_root) : root(new Node(0,_root)) {
00023 }
00024
00025 PTree::~PTree() {}
00026
00027 std::pair<PTreeNode*, PTreeNode*>
00028 PTree::split(Node *n,
00029 const data_type &leftData,
00030 const data_type &rightData) {
00031 assert(n && !n->left && !n->right);
00032 n->left = new Node(n, leftData);
00033 n->right = new Node(n, rightData);
00034 return std::make_pair(n->left, n->right);
00035 }
00036
00037 void PTree::remove(Node *n) {
00038 assert(!n->left && !n->right);
00039 do {
00040 Node *p = n->parent;
00041 delete n;
00042 if (p) {
00043 if (n == p->left) {
00044 p->left = 0;
00045 } else {
00046 assert(n == p->right);
00047 p->right = 0;
00048 }
00049 }
00050 n = p;
00051 } while (n && !n->left && !n->right);
00052 }
00053
00054 void PTree::dump(std::ostream &os) {
00055 ExprPPrinter *pp = ExprPPrinter::create(os);
00056 pp->setNewline("\\l");
00057 os << "digraph G {\n";
00058 os << "\tsize=\"10,7.5\";\n";
00059 os << "\tratio=fill;\n";
00060 os << "\trotate=90;\n";
00061 os << "\tcenter = \"true\";\n";
00062 os << "\tnode [style=\"filled\",width=.1,height=.1,fontname=\"Terminus\"]\n";
00063 os << "\tedge [arrowsize=.3]\n";
00064 std::vector<PTree::Node*> stack;
00065 stack.push_back(root);
00066 while (!stack.empty()) {
00067 PTree::Node *n = stack.back();
00068 stack.pop_back();
00069 if (n->condition.isNull()) {
00070 os << "\tn" << n << " [label=\"\"";
00071 } else {
00072 os << "\tn" << n << " [label=\"";
00073 pp->print(n->condition);
00074 os << "\",shape=diamond";
00075 }
00076 if (n->data)
00077 os << ",fillcolor=green";
00078 os << "];\n";
00079 if (n->left) {
00080 os << "\tn" << n << " -> n" << n->left << ";\n";
00081 stack.push_back(n->left);
00082 }
00083 if (n->right) {
00084 os << "\tn" << n << " -> n" << n->right << ";\n";
00085 stack.push_back(n->right);
00086 }
00087 }
00088 os << "}\n";
00089 delete pp;
00090 }
00091
00092 PTreeNode::PTreeNode(PTreeNode *_parent,
00093 ExecutionState *_data)
00094 : parent(_parent),
00095 left(0),
00096 right(0),
00097 data(_data),
00098 condition(0) {
00099 }
00100
00101 PTreeNode::~PTreeNode() {
00102 }
00103