toward updating predicate trees every time a function exits
[c11tester.git] / predicate.cc
1 #include "predicate.h"
2
3 Predicate::Predicate(FuncInst * func_inst) :
4         func_inst(func_inst),
5         pred_expressions(),
6         children()
7 {}
8
9 unsigned int pred_expr_hash(struct pred_expr * expr)
10 {
11         return (unsigned int)((uintptr_t)expr);
12 }
13
14 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
15 {
16         if (p1->token != p2->token)
17                 return false;
18         if (p1->token == EQUALITY && p1->location != p2->location)
19                 return false;
20         if (p1->value != p2->value)
21                 return false;
22         return true;
23 }
24
25 void Predicate::add_predicate(token_t token, void * location, bool value)
26 {
27         struct pred_expr *ptr = new pred_expr(token, location, value);
28         pred_expressions.add(ptr);
29 }
30
31 void Predicate::add_child(Predicate * child)
32 {
33         /* check duplication? */
34         children.push_back(child);
35 }
36
37 void Predicate::print_predicate()
38 {
39         model_print("\"%p\" [shape=box, label=\"%p\n", this, this);
40         func_inst->print();
41         PredExprSetIter * it = pred_expressions.iterator();
42
43         if (pred_expressions.getSize() == 0)
44                 model_print("no predicate\n");
45
46         while (it->hasNext()) {
47                 struct pred_expr * expr = it->next();
48                 model_print("predicate: token: %d, location: %p, value: %d\n", expr->token, expr->location, expr->value);
49         }
50         model_print("\"];\n");
51 }
52
53 void Predicate::print_pred_subtree()
54 {
55         print_predicate();
56         for (uint i = 0; i < children.size(); i++) {
57                 Predicate * child = children[i];
58                 child->print_pred_subtree();
59                 model_print("\"%p\" -> \"%p\"\n", this, child);
60         }
61 }