Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[DOC] Fixed even more errors.
[simgrid.git] / src / smpi / replace_globals.cocci
index d23bacf..00a6ca5 100644 (file)
@@ -1,6 +1,14 @@
+// FIXME: seems like cocci has problems manipulating the declarations, at least
+// when there is more than one on the same line. We already need perl to split
+// up the declarations after the fact, is there another tool we can use to patch
+// up and match the declarations? In that case we could consider dropping cocci,
+// or just using it to alter global variable accesses.
+//
 // FIXME: problems
-//   - does not want to match dynamic arrays...
+//   - array declarations not properly matched...can fix, but then can't have
+//   multiple declarations on one line
 //   - does not match array initializers
+//   - probably won't fix structure declarations with initialization either
 
 // Function prototype looks like variable dec, but has parentheses
 @funcproto@
@@ -10,73 +18,115 @@ position p;
 @@
 T@p func(...);
 
-// Define a local variable as one whose declaration is encased in brackets
+// define a local variable declaration as one at some level of nesting
 @localvardecl@
 type T;
 identifier var;
 position p;
 expression E;
 @@
-{
 <...
-(
+( // default case
 T@p
 var
 ;
-|
+| // variable has initializer
 T@p
 var = E
 ;
 )
 ...>
-}
 
-// global variable is one whose declaration is neither local nor a function
-// prototype
+// define a global variable declaration as one that is neither a function
+// prototype nor a local variable declaration
 @globalvardecl@
 type T;
 identifier var;
-position p != { localvardecl.p, funcproto.p };
+position p != { funcproto.p, localvardecl.p };
 expression value;
-constant size;
+// expression size;
 @@
-(
+( // default case
 T@p 
 - var
-+ *var = SMPI_INITIALIZE_GLOBAL(T)
++ *var = SMPI_VARINIT_GLOBAL(var, T)
 ;
-|
+| // variable has initializer (not a struct or array)
 T@p
 - var = value 
-+ *var = SMPI_INITIALIZE_AND_SET_GLOBAL(T, value)
-;
-|
-T@p
-- var[]
-+ *var[] = SMPI_INITIALIZE_GLOBAL_ARRAY(T, size)
-;
-|
-T@p
-- var[size]
-+ *var[] = SMPI_INITIALIZE_GLOBAL_STATIC_ARRAY(T, size)
-;
-|
-T@p
-- var[size] = { ... }
-+ *var[] = SMPI_INITIALIZE_AND_SET_GLOBAL_STATIC_ARRAY(T, size)
++ *var = SMPI_VARINIT_GLOBAL_AND_SET(var, T, value)
 ;
+//| // array of specified size
+//T@p // FIXME: matches, but complains if more than one decl on a line...
+//- var[size]
+//+ *var[size] = SMPI_VARINIT_GLOBAL_ARRAY(T, size)
+//;
+//| // array of specified size with initializer
+//T@p // FIXME: how to match initializer?
+//- var[size] = { ... }
+//+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... })
+//;
+//| // array without specified size, but with initializer
+//T@p // FIXME: how to match initializer? how to figure out size?
+//- var[] = { ... }
+//+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... }) // size = ?
+//;
+//| struct with initializer?
 )
 
-@rewritelocalaccess@
+// rewrite access to global variables based on name, but avoid the declaration
+// and local variables that might have the same name
+@rewriteglobalaccess@
+type T;
 local idexpression lvar;
 identifier globalvardecl.var;
 @@
-{
 <...
-(
+( // local variable
 lvar
-|
-+SMPI_GLOBAL_VAR_LOCAL_ACCESS(
+| // rewrite access
++SMPI_VARGET_GLOBAL(
+var
++)
+)
+...>
+
+// define a local static variable declaration as one at some level of nesting
+// starting with the word static (exceptions?)
+@staticvardecl@
+type T;
+identifier func, var;
+expression value;
+@@
+func(...) {
+...
+( // default case
+static T
+- var
++ *var = SMPI_VARINIT_STATIC(T, var)
+;
+| // variable has initializer (not a struct or array)
+T
+- var = value 
++ *var = SMPI_VARINIT_STATIC_AND_SET(var, T, value)
+;
+)
+...
+}
+
+// 
+@rewritestaticaccess@
+type T;
+identifier staticvardecl.func, staticvardecl.var;
+@@
+func(...) {
+<...
+( // declaration
+T
+var
+;
+| // rewrite access
++SMPI_VARGET_STATIC(
 var
 +)
 )