factor out codes for FuncInst class
[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
24         if ( func_insts.contains(position) ) {
25                 FuncInst * inst = func_insts.get(position);
26
27                 if (inst->get_type() != act->get_type() ) {
28                         // model_print("action with a different type occurs at line number %s\n", position);
29                         FuncInst * func_inst = inst->search_in_collision(act);
30
31                         if (func_inst != NULL) {
32                                 // return the FuncInst found in the collision list
33                                 return func_inst;
34                         }
35
36                         func_inst = new FuncInst(act);
37                         inst->get_collisions()->push_back(func_inst);
38                         inst_list.push_back(func_inst);         // delete?
39                         // model_print("collision added\n");
40                         
41                         return func_inst;
42                 }
43
44                 return inst;
45         }
46
47         FuncInst * func_inst = new FuncInst(act);
48         func_insts.put(position, func_inst);
49
50         inst_list.push_back(func_inst);
51         return func_inst;
52 }