augment hashtable with keyset
[c11tester.git] / funcnode.cc
1 #include "funcnode.h"
2
3 FuncNode::FuncNode() :
4         func_insts(),
5         inst_list(),
6         entry_insts()
7 {}
8
9 FuncInst * FuncNode::get_or_add_action(ModelAction *act)
10 {
11         ASSERT(act);
12
13         const char * position = act->get_position();
14
15         /* Actions THREAD_CREATE, THREAD_START, THREAD_YIELD, THREAD_JOIN,
16          * THREAD_FINISH, PTHREAD_CREATE, PTHREAD_JOIN,
17          * ATOMIC_LOCK, ATOMIC_TRYLOCK, and ATOMIC_UNLOCK are not tagged with their
18          * source line numbers
19          */
20         if (position == NULL)
21                 return NULL;
22
23         if ( func_insts.contains(position) ) {
24                 FuncInst * inst = func_insts.get(position);
25
26                 if (inst->get_type() != act->get_type() ) {
27                         // model_print("action with a different type occurs at line number %s\n", position);
28                         FuncInst * func_inst = inst->search_in_collision(act);
29
30                         if (func_inst != NULL) {
31                                 // return the FuncInst found in the collision list
32                                 return func_inst;
33                         }
34
35                         func_inst = new FuncInst(act, this);
36                         inst->get_collisions()->push_back(func_inst);
37                         inst_list.push_back(func_inst);         // delete?
38                         // model_print("collision added\n");
39                         
40                         return func_inst;
41                 }
42
43                 return inst;
44         }
45
46         FuncInst * func_inst = new FuncInst(act, this);
47         func_insts.put(position, func_inst);
48
49         inst_list.push_back(func_inst);
50         return func_inst;
51 }
52
53 void FuncNode::add_entry_inst(FuncInst * inst)
54 {
55         if (inst == NULL)
56                 return;
57
58         func_inst_list_mt::iterator it;
59         for (it = entry_insts.begin(); it != entry_insts.end(); it++) {
60                 if (inst == *it)
61                         return;
62         }
63
64         entry_insts.push_back(inst);
65 }