4458e8b9733c8954db417a7944daa2cc0c50620c
[c11tester.git] / predicate.cc
1 #include "predicate.h"
2
3 Predicate::Predicate(FuncInst * func_inst) :
4         func_inst(func_inst),
5         predicates(),
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         predicates.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("self: %p ", this);
40         func_inst->print();
41         PredSetIter * it = predicates.iterator();
42
43         if (predicates.getSize() == 0)
44                 model_print("no predicate\n");
45
46         while (it->hasNext()) {
47                 struct pred_expr * expr = it->next();
48                 model_print("token: %d, location: %p, value: %d\n", expr->token, expr->location, expr->value);
49         }
50 }
51
52 void Predicate::print_pred_subtree()
53 {
54         print_predicate();
55         for (uint i = 0; i < children.size(); i++) {
56                 Predicate * child = children[i];
57 //              model_print("parent: %p - ", this);
58                 child->print_pred_subtree();
59         }
60 }