Skip to content

Commit 65e150b

Browse files
committed
Add parameterized module for MaD model printing.
1 parent f04a85e commit 65e150b

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
signature module ModelPrintingLangSig {
2+
/**
3+
* A class of callables.
4+
*/
5+
class Callable;
6+
7+
/**
8+
* Holds if `container`, `type`, `name`, and `parameters` contain the type signature of `api`
9+
* and `extensible` is the string representation of a boolean that is true, if
10+
* `api` can be overridden (otherwise false).
11+
*/
12+
predicate partialModel(
13+
Callable api, string container, string type, string extensible, string name, string parameters
14+
);
15+
}
16+
17+
module ModelPrintingImpl<ModelPrintingLangSig Lang> {
18+
signature module ModelPrintingSig {
19+
/**
20+
* The class of APIs relevant for model generation.
21+
*/
22+
class Api extends Lang::Callable {
23+
Lang::Callable lift();
24+
}
25+
26+
/**
27+
* Gets the string representation of the provenance of the models.
28+
*/
29+
string getProvenance();
30+
}
31+
32+
module ModelPrinting<ModelPrintingSig Printing> {
33+
/**
34+
* Computes the first 6 columns for MaD rows used for summaries, sources and sinks.
35+
*/
36+
private string asPartialModel(Printing::Api api) {
37+
exists(string container, string type, string extensible, string name, string parameters |
38+
Lang::partialModel(api.lift(), container, type, extensible, name, parameters) and
39+
result =
40+
container + ";" //
41+
+ type + ";" //
42+
+ extensible + ";" //
43+
+ name + ";" //
44+
+ parameters + ";" //
45+
+ /* ext + */ ";" //
46+
)
47+
}
48+
49+
/**
50+
* Computes the first 4 columns for neutral MaD rows.
51+
*/
52+
private string asPartialNeutralModel(Printing::Api api) {
53+
exists(string container, string type, string name, string parameters |
54+
Lang::partialModel(api, container, type, _, name, parameters) and
55+
result =
56+
container + ";" //
57+
+ type + ";" //
58+
+ name + ";" //
59+
+ parameters + ";" //
60+
)
61+
}
62+
63+
/**
64+
* Gets the summary model for `api` with `input`, `output` and `kind`.
65+
*/
66+
bindingset[input, output, kind]
67+
private string asSummaryModel(Printing::Api api, string input, string output, string kind) {
68+
result =
69+
asPartialModel(api) + input + ";" //
70+
+ output + ";" //
71+
+ kind + ";" //
72+
+ Printing::getProvenance()
73+
}
74+
75+
string asNeutralSummaryModel(Printing::Api api) {
76+
result =
77+
asPartialNeutralModel(api) //
78+
+ "summary" + ";" //
79+
+ Printing::getProvenance()
80+
}
81+
82+
/**
83+
* Gets the value summary model for `api` with `input` and `output`.
84+
*/
85+
bindingset[input, output]
86+
string asValueModel(Printing::Api api, string input, string output) {
87+
result = asSummaryModel(api, input, output, "value")
88+
}
89+
90+
/**
91+
* Gets the taint summary model for `api` with `input` and `output`.
92+
*/
93+
bindingset[input, output]
94+
string asTaintModel(Printing::Api api, string input, string output) {
95+
result = asSummaryModel(api, input, output, "taint")
96+
}
97+
98+
/**
99+
* Gets the sink model for `api` with `input` and `kind`.
100+
*/
101+
bindingset[input, kind]
102+
string asSinkModel(Printing::Api api, string input, string kind) {
103+
result =
104+
asPartialModel(api) + input + ";" //
105+
+ kind + ";" //
106+
+ Printing::getProvenance()
107+
}
108+
109+
/**
110+
* Gets the source model for `api` with `output` and `kind`.
111+
*/
112+
bindingset[output, kind]
113+
string asSourceModel(Printing::Api api, string output, string kind) {
114+
result =
115+
asPartialModel(api) + output + ";" //
116+
+ kind + ";" //
117+
+ Printing::getProvenance()
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)