Y. Padioleau, J. L. Lawall, and G. Muller. SmPL: A domain-specific language for specifying collateral evolutions in linux device drivers. Electr. Notes Theor. Comput. Sci, 166:47–62, 2007.

例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@ rule1 @
struct SHT ops;
identifier proc_info_func;
@@
ops.proc_info = proc_info_func;

@ rule2 @
identifier rule1.proc_info_func;
identifier buffer, start, offset, inout, hostno;
identifier hostptr;
@@

  proc_info_func (
+   struct Scsi_Host * hostptr,
    char * buffer, char ** start, off_t offset,
-   int hostno,
    int inout) { ... }

其中 rule1.proc_info_func 就是继承 (后面的 rule 想继承前面的 metavar, 需要重新显式声明一遍). rule1 里面的变换模式没有 + 和 -, 只有一个上下文用来施加限制. 要是没有这个限制, 任何一个函数, 只要参数数目类型和 rule2 匹配, 就会按照 rule2 被变换. 然而我们希望, 只有当这个函数是某一个 SHTproc_info 域的时候才做这个变换.

SCSI 最终例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@ rule1 @
struct SHT ops;
identifier proc_info_func;
@@
  ops.proc_info = proc_info_func;

@ rule2 @
identifier rule1.proc_info_func;
identifier buffer, start, offset, inout, hostno;
identifier hostptr;
@@
  proc_info_func (
+     struct Scsi_Host * hostptr,
      char * buffer, char ** start, off_t offset,
-     int hostno,
      int inout) {
    ...
-   struct Scsi_Host * hostptr;
    ...
-   hostptr = scsi_host_hn_get(hostno);
    ...
?-  if (!hostptr) { ... return ...; }
    ...
?-  scsi_host_put(hostptr);
    ...
  }

@ rule3 @
identifier rule1.proc_info_func;
identifier rule2.hostno;
identifier rule2.hostptr;
@@
  proc_info_func(...) {
    <...
-   hostno
+   hostptr->host_no
    ...>
  }

@ rule4 @
identifier rule1.proc_info_func;
identifier func;
expression buffer, start, offset, inout, hostno;
identifier hostptr;
@@
  func(..., struct Scsi_Host * hostptr, ...) {
    <...
    proc_info_func(
+   hostptr,
    buffer, start, offset,,
-   hostno,
    inout)
    ...>
  }

省略号的区别

TODO: ...<... ...> 具体的区别? 用例子表达.