10 typedef struct MethodCall {
11 string interfaceName; // The interface label name
12 void *value; // The pointer that points to the struct that have the return
13 // value and the arguments
14 void *localState; // The pointer that points to the struct that represents
16 vector<MethodCall*> *prev; // Method calls that are hb right before me
17 vector<MethodCall*> *next; // Method calls that are hb right after me
18 vector<MethodCall*> *concurrent; // Method calls that are concurrent with me
21 typedef MethodCall *Method;
22 typedef vector<Method> *MethodSet;
24 typedef vector<int> IntList;
26 #define NewSet new vector<Method>
28 #define CAT(a, b) CAT_HELPER(a, b) /* Concatenate two symbols for macros! */
29 #define CAT_HELPER(a, b) a ## b
30 #define X(name) CAT(__##name, __LINE__) /* unique variable */
33 The set here is a vector<MethodCall*>* type, or the MethodSet type. And the
34 item would become the MethodCall* type, or the Method type
36 #define ForEach(item, set) \
38 for (Method item = (set)->size() > 0 ? (*(set))[0] : NULL; \
39 X(i) < (set)->size(); X(i)++, item = X(i) < (set)->size() ? (*(set))[X(i)] : NULL)
41 inline MethodSet Subset(MethodSet set, string name) {
42 MethodSet _subset = NewSet;
44 if (_m->interfaceName == name)
45 _subset->push_back(_m);
50 #define Size(set) (set->size())
52 #define Belong(set, method) (std::find(set->begin(), set->end(), method) \
55 inline MethodSet Intersect(MethodSet set1, MethodSet set2) {
56 MethodSet res = NewSet;
64 inline MethodSet Union(MethodSet set1, MethodSet set2) {
65 MethodSet res = NewSet(*set1);
73 inline MethodSet Subtract(MethodSet set1, MethodSet set2) {
74 MethodSet res = NewSet;
82 inline bool Insert(MethodSet set, Method m) {
91 inline MethodSet MakeSet(int count, ...) {
97 for (int i = 0; i < count; i++) {
98 Method m = va_arg (ap, Method);
107 #define Local(method, field) ((StateStruct*) method->localState)->field
109 #define Value(method, type, field) ((type*) method->value)->field
111 #define Label(method) method->interfaceName
113 #define Prev(method) method->prev
114 #define PREV ME->prev
116 #define Next(method) method->next
117 #define NEXT ME->next
119 #define Concurrent(method) method->concurrent
120 #define CONCURRENT ME->concurrent
122 // This auto-generated struct can have different fields according to the read
123 // state declaration. Here it's just a test example
124 typedef struct StateStruct {
128 // These auto-generated struct can have different fields according to the return
129 // value and arguments of the corresponding interface. The struct will have the
130 // same name as the interface name. Here it's just a test example
131 typedef struct Store {
136 typedef struct Load {
143 MethodSet set = NewSet;
144 ForEach (m, Subset(set, "Store")) {
145 IntList *l = Local(m, list);
146 int ret = Value(m, Load, RET);
147 string name = Label(m);
149 ForEach (m, Prev(ME)) {
153 int size = Size(PREV);
154 bool flag = Belong(CONCURRENT, ME);
155 flag = Belong(MakeSet(3, ME, ME, ME), ME);