Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Code refactor: move the functions associated to the request enabledness to mc_request.c
[simgrid.git] / src / smpi / replace_globals.cocci
1 // FIXME: seems like cocci has problems manipulating the declarations, at least
2 // when there is more than one on the same line. We already need perl to split
3 // up the declarations after the fact, is there another tool we can use to patch
4 // up and match the declarations? In that case we could consider dropping cocci,
5 // or just using it to alter global variable accesses.
6 //
7 // FIXME: problems
8 //   - array declarations not properly matched...can fix, but then can't have
9 //   multiple declarations on one line
10 //   - does not match array initializers
11 //   - probably won't fix structure declarations with initialization either
12
13 // Function prototype looks like variable dec, but has parentheses
14 @funcproto@
15 type T;
16 identifier func;
17 position p;
18 @@
19 T@p func(...);
20
21 // define a local variable declaration as one at some level of nesting
22 @localvardecl@
23 type T;
24 identifier var;
25 position p;
26 expression E;
27 @@
28 <...
29 ( // default case
30 T@p
31 var
32 ;
33 | // variable has initializer
34 T@p
35 var = E
36 ;
37 )
38 ...>
39
40 // define a global variable declaration as one that is neither a function
41 // prototype nor a local variable declaration
42 @globalvardecl@
43 type T;
44 identifier var;
45 position p != { funcproto.p, localvardecl.p };
46 expression value;
47 // expression size;
48 @@
49 ( // default case
50 T@p 
51 - var
52 + *var = SMPI_VARINIT_GLOBAL(var, T)
53 ;
54 | // variable has initializer (not a struct or array)
55 T@p
56 - var = value 
57 + *var = SMPI_VARINIT_GLOBAL_AND_SET(var, T, value)
58 ;
59 //| // array of specified size
60 //T@p // FIXME: matches, but complains if more than one decl on a line...
61 //- var[size]
62 //+ *var[size] = SMPI_VARINIT_GLOBAL_ARRAY(T, size)
63 //;
64 //| // array of specified size with initializer
65 //T@p // FIXME: how to match initializer?
66 //- var[size] = { ... }
67 //+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... })
68 //;
69 //| // array without specified size, but with initializer
70 //T@p // FIXME: how to match initializer? how to figure out size?
71 //- var[] = { ... }
72 //+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... }) // size = ?
73 //;
74 //| struct with initializer?
75 )
76
77 // rewrite access to global variables based on name, but avoid the declaration
78 // and local variables that might have the same name
79 @rewriteglobalaccess@
80 type T;
81 local idexpression lvar;
82 identifier globalvardecl.var;
83 @@
84 <...
85 ( // local variable
86 lvar
87 | // rewrite access
88 +SMPI_VARGET_GLOBAL(
89 var
90 +)
91 )
92 ...>
93
94 // define a local static variable declaration as one at some level of nesting
95 // starting with the word static (exceptions?)
96 @staticvardecl@
97 type T;
98 identifier var;
99 expression value;
100 @@
101 <...
102 ( // default case
103 static T
104 - var
105 + *var = SMPI_VARINIT_STATIC(T, var)
106 ;
107 | // variable has initializer (not a struct or array)
108 T
109 - var = value 
110 + *var = SMPI_VARINIT_STATIC_AND_SET(var, T, value)
111 ;
112 )
113 ...>
114
115 // 
116 @rewritestaticaccess@
117 type T;
118 identifier staticvardecl.var;
119 @@
120 ( // declaration
121 T
122 var
123 ;
124 | // rewrite access
125 +SMPI_VARGET_STATIC(
126 var
127 +)
128 )