Skip to content

Commit 1d828c4

Browse files
Implement CustomPathStateProblem support for all languages
Co-authored-by: MichaelRFairhurst <1627771+MichaelRFairhurst@users.noreply.github.com>
1 parent bebbfc3 commit 1d828c4

26 files changed

Lines changed: 449 additions & 0 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
private import qtil.locations.CustomPathStateProblem
2+
private import qtil.cpp.locations.Locatable
3+
private import cpp
4+
// Import the C++ specific configuration for making custom path state problems.
5+
import PathStateProblem<Location, CppLocatableConfig>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
edges
2+
nodes
3+
#select
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Minimal test to make sure CustomPathStateProblem works with C++ code.
2+
import cpp
3+
import qtil.cpp.graph.CustomPathStateProblem
4+
5+
module CallGraphPathStateProblemConfig implements CustomPathStateProblemConfigSig {
6+
class Node = Variable;
7+
8+
class State = int; // Track search depth
9+
10+
predicate start(Node n, int depth) { n.getName() = "start" and depth = 0 }
11+
12+
bindingset[depth]
13+
predicate end(Node n, int depth) { n.getName() = "end" }
14+
15+
bindingset[depth1]
16+
bindingset[depth2]
17+
predicate edge(Variable a, int depth1, Variable b, int depth2) {
18+
depth2 = depth1 + 1 and
19+
exists(Initializer initA |
20+
a.getInitializer() = initA and
21+
initA.getExpr().(VariableAccess).getTarget() = b
22+
)
23+
}
24+
}
25+
26+
import CustomPathStateProblem<CallGraphPathStateProblemConfig>
27+
28+
from Variable start, Variable end
29+
where problem(start, end)
30+
select start, end, "Path from $@ to $@.", start.getName(), start, end.getName(), end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
private import qtil.locations.CustomPathStateProblem
2+
private import qtil.csharp.locations.Locatable
3+
private import csharp
4+
// Import the C# specific configuration for making custom path state problems.
5+
import PathStateProblem<csharp::Location, CsharpLocatableConfig>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
edges
2+
nodes
3+
#select
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Minimal test to make sure CustomPathStateProblem works with C# code.
2+
import csharp
3+
import qtil.csharp.graph.CustomPathStateProblem
4+
5+
module CallGraphPathStateProblemConfig implements CustomPathStateProblemConfigSig {
6+
class Node = LocalVariable;
7+
8+
class State = int; // Track search depth
9+
10+
predicate start(Node n, int depth) { n.getName() = "start" and depth = 0 }
11+
12+
bindingset[depth]
13+
predicate end(Node n, int depth) { n.getName() = "end" }
14+
15+
bindingset[depth1]
16+
bindingset[depth2]
17+
predicate edge(LocalVariable a, int depth1, LocalVariable b, int depth2) {
18+
depth2 = depth1 + 1 and
19+
exists(LocalVariableDeclExpr declA, LocalVariableDeclExpr declB |
20+
declA.getVariable() = a and
21+
declB.getVariable() = b and
22+
declA.getInitializer().(VariableAccess).getTarget() = b
23+
)
24+
}
25+
}
26+
27+
import CustomPathStateProblem<CallGraphPathStateProblemConfig>
28+
29+
from LocalVariable start, LocalVariable end
30+
where problem(start, end)
31+
select start, end, "Path from $@ to $@.", start.getName(), start, end.getName(), end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
private import qtil.locations.CustomPathStateProblem
2+
private import qtil.go.locations.Locatable
3+
private import go
4+
// Import the Go specific configuration for making custom path state problems.
5+
import PathStateProblem<go::DbLocation, GoLocatableConfig>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
edges
2+
nodes
3+
#select
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Minimal test to make sure CustomPathStateProblem works with Go code.
2+
import go
3+
import qtil.go.graph.CustomPathStateProblem
4+
5+
module CallGraphPathStateProblemConfig implements CustomPathStateProblemConfigSig {
6+
class Node = Variable;
7+
8+
class State = int; // Track search depth
9+
10+
predicate start(Node n, int depth) { n.getName() = "start" and depth = 0 }
11+
12+
bindingset[depth]
13+
predicate end(Node n, int depth) { n.getName() = "end" }
14+
15+
bindingset[depth1]
16+
bindingset[depth2]
17+
predicate edge(Variable a, int depth1, Variable b, int depth2) {
18+
depth2 = depth1 + 1 and
19+
exists(ValueSpec specA, ValueSpec specB |
20+
specA.getNameExpr(0).(Ident).getName() = a.getName() and
21+
specB.getNameExpr(0).(Ident).getName() = b.getName() and
22+
specA.getValue(0).(Ident).getName() = b.getName()
23+
)
24+
}
25+
}
26+
27+
import CustomPathStateProblem<CallGraphPathStateProblemConfig>
28+
29+
from Variable start, Variable end
30+
where problem(start, end)
31+
select start, end, "Path from $@ to $@.", start.getName(), start, end.getName(), end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
private import qtil.locations.CustomPathStateProblem
2+
private import qtil.java.locations.Locatable
3+
private import java
4+
// Import the Java specific configuration for making custom path state problems.
5+
import PathStateProblem<Location, JavaLocatableConfig>

0 commit comments

Comments
 (0)