Browse Source

This is an example spatch which was used to remove the global Mach usage

It's no longer needed but it's useful to keep around.

It finds usages of waserror, ! waserror, or variables of type M
and inserts
Mach *m = machp();
in functions using those things.

Note for the variable case we assume it's named m; we were lucky in that
the Plan 9 source was consistent this way, due to the global declaration
in dat.h.

Note that there needs to be a
extern Mach *m;
somewhere in the file or spatch will not find variables of type Mach, hence
the Go program that finds files using m and inserts the declaration.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 4 years ago
parent
commit
99cf95c843
1 changed files with 60 additions and 0 deletions
  1. 60 0
      util/mach8.cocci

+ 60 - 0
util/mach8.cocci

@@ -0,0 +1,63 @@
+@mr exists@
+typedef Mach; // only needed once per semantic patch
+idexpression Mach *m;
+function f;
+position p;
+identifier d;
+@@
+f@p(...){
+<+...
+m->d
+...+>
+}
+
+@@
+function mr.f;
+position mr.p;
+@@
+
+f@p(...) {
+...
+}
+
+@r exists@
+function f;
+position p;
+@@
+f@p(...){
+<+...
+ if (waserror()) {...}
+...+>
+}
+
+@@
+function r.f;
+position r.p;
+@@
+
+f@p(...) {
+...
+}
+
+@nr exists@
+function f;
+position p;
+@@
+f@p(...){
+<+...
+ if (!waserror()) {...}
+...+>
+}
+
+@@
+function nr.f;
+position nr.p;
+@@
+
+f@p(...) {
+...
+}
+