Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
commiting some more automatic source patching stuff, and renamed some of the
[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 as one whose declaration is encased in brackets
22 @localvardecl@
23 type T;
24 identifier var;
25 position p;
26 expression E;
27 @@
28 {
29 <...
30 (
31 T@p
32 var
33 ;
34 |
35 T@p
36 var = E
37 ;
38 )
39 ...>
40 }
41
42 // global variable is one whose declaration is neither local nor a function
43 // prototype
44 @globalvardecl@
45 type T;
46 identifier var;
47 position p != { localvardecl.p, funcproto.p };
48 expression value;
49 expression size;
50 @@
51 (
52 T@p 
53 - var
54 + *var = SMPI_VARINIT_GLOBAL(var, T)
55 ;
56 |
57 T@p
58 - var = value 
59 + *var = SMPI_VARINIT_GLOBAL_AND_SET(var, T, value)
60 ;
61 //|
62 //T@p // FIXME: matches, but complains if more than one decl on a line...
63 //- var[size]
64 //+ *var[size] = SMPI_VARINIT_GLOBAL_ARRAY(T, size)
65 //;
66 //|
67 //T@p // FIXME: how to match initializer?
68 //- var[size] = { ... }
69 //+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... })
70 //;
71 //|
72 //T@p // FIXME: how to match initializer? how to figure out size?
73 //- var[] = { ... }
74 //+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... }) // size = ?
75 //;
76 )
77
78 @rewritelocalaccess@
79 local idexpression lvar;
80 identifier globalvardecl.var;
81 @@
82 {
83 <...
84 (
85 lvar
86 |
87 +SMPI_VARGET_GLOBAL(
88 var
89 +)
90 )
91 ...>
92 }