11#pragma once
2- #include "utils .dl"
2+ #include "abstract-context-sensitive-pt .dl"
33
4- .comp OneCallsiteSensitivePT{
5- .decl VarPointsTo(heap:Heap, hctx:Context, var:Var, vCtx:Context)
6- .decl InstanceFieldPointsTo(heap:Heap, hctx:Context, baseHeap:Heap, bhCtx:Context, field:Field)
7- .decl StaticFieldPointsTo(heap:Heap, hctx:Context, field:Field)
8- .decl ArrayIndexPointsTo(heap:Heap, hctx:Context, baseHeap:Heap, bhCtx:Context)
9- .decl Reachable(method:Method, ctx:Context, n:number)
10- .decl CallGraph(insn:Insn, caller:Method, callerCtx:Context, callee:Method, calleeCtx:Context)
4+ .type HContext = Insn
5+ .type Context = Insn
116
12- // new
13- VarPointsTo(heap, ctx, var, ctx) :-
14- Reachable(method, ctx, _),
15- AssignHeapAllocation(_, _, heap, var, method, _).
16-
17- // assign
18- VarPointsTo(heap, hctx, to, ctx) :-
19- Reachable(method, ctx, _),
20- VarPointsTo(heap, hctx, from, ctx),
21- AssignLocal(_, _, from, to, method).
22-
23- // cast
24- VarPointsTo(heap, hctx, to, ctx) :-
25- Reachable(method, ctx, _),
26- AssignCast(_, _, from, to, _, method),
27- VarPointsTo(heap, hctx, from, ctx).
28-
29- // load field
30- VarPointsTo(heap, hctx, to, ctx) :-
31- Reachable(method, ctx, _),
32- LoadInstanceField(_, _, to, base, field, method),
33- VarPointsTo(baseHeap, bhCtx, base, ctx),
34- InstanceFieldPointsTo(heap, hctx, baseHeap, bhCtx, field).
35-
36- // store field
37- InstanceFieldPointsTo(heap, hctx, baseHeap, bhCtx, field) :-
38- Reachable(method, ctx, _),
39- StoreInstanceField(_, _, from, base, field, method),
40- VarPointsTo(heap, hctx, from, ctx),
41- VarPointsTo(baseHeap, bhCtx, base, ctx).
42-
43- // load staic field
44- VarPointsTo(heap, hctx, to, ctx) :-
45- Reachable(method, ctx, _),
46- LoadStaticField(_, _, to, field, method),
47- StaticFieldPointsTo(heap, hctx, field).
48-
49- // store static field
50- StaticFieldPointsTo(heap, hctx, field) :-
51- Reachable(method, ctx, _),
52- StoreStaticField(_, _, from, field, method),
53- VarPointsTo(heap, hctx, from, ctx).
54-
55- // load from array
56- VarPointsTo(heap, hctx, to, ctx) :-
57- Reachable(method, ctx, _),
58- LoadArrayIndex(_, _, to, base, method),
59- VarPointsTo(baseHeap, bhCtx, base, ctx),
60- ArrayIndexPointsTo(heap, hctx, baseHeap, bhCtx).
61-
62- // store into array
63- ArrayIndexPointsTo(heap, hctx, baseHeap, bhCtx) :-
64- Reachable(method, ctx, _),
65- StoreArrayIndex(_, _, from, base, method),
66- VarPointsTo(heap, hctx, from, ctx),
67- VarPointsTo(baseHeap, bhCtx, base, ctx).
68-
69- Reachable(callee, calleeCtx, n+1),
70- CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
71- Reachable(caller, callerCtx, n),
72- n < MAXSTEP,
73- calleeCtx = insn,
74- SpecialMethodInvocation(insn, _, callee, _, caller).
75-
76- Reachable(callee, calleeCtx, n+1),
77- CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
78- Reachable(caller, callerCtx, n),
79- n < MAXSTEP,
80- calleeCtx = insn,
81- StaticMethodInvocation(insn, _, callee, caller).
82-
83- Reachable(callee, calleeCtx, n+1),
84- CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
85- Reachable(caller, callerCtx, n),
86- n < MAXSTEP,
87- VirtualMethodInvocation(insn, _, method, base, caller),
88- calleeCtx = insn,
89- VarPointsTo(baseHeap, _, base, callerCtx),
90- NormalHeap(baseHeap, class),
91- MethodInfo(method, simplename, _, _, _, descriptor, _),
92- Dispatch(simplename, descriptor, class, callee).
93-
94- // param
95- VarPointsTo(heap, hctx, param, calleeCtx) :-
96- CallGraph(insn, _, callerCtx, callee, calleeCtx),
97- ActualParam(n, insn, arg),
98- FormalParam(n, callee, param),
99- VarPointsTo(heap, hctx, arg, callerCtx),
100- NormalHeap(heap, _).
101-
102- // return
103- VarPointsTo(heap, hctx, return, callerCtx) :-
104- CallGraph(insn, _, callerCtx, callee, calleeCtx),
105- Return(_, _, var, callee),
106- AssignReturnValue(insn, return),
107- VarPointsTo(heap, hctx, var, calleeCtx).
108-
109- // this
110- VarPointsTo(heap, hctx, this, calleeCtx) :-
111- CallGraph(insn, _, callerCtx, callee, calleeCtx),
7+ .comp OneCallsiteSensitivePT<HContext, Context> : AbstractContextSensitivePT<HContext, Context>{
8+ .override SelectInvocationContext
9+ SelectInvocationContext(callerCtx, insn, baseHeap, hctx, calleeCtx) :-
10+ Reachable(caller, callerCtx, _),
11211 (
113- VirtualMethodInvocation (insn, _, _, base, _ );
114- SpecialMethodInvocation (insn, _, _, base, _ )
12+ SpecialMethodInvocation (insn, _, _, base, caller );
13+ VirtualMethodInvocation (insn, _, _, base, caller )
11514 ),
116- ThisVar(callee, this),
117- VarPointsTo(heap, hctx, base, callerCtx).
15+ VarPointsTo(baseHeap, hctx, base, callerCtx),
16+ calleeCtx = insn.
17+
18+ SelectStaticInvocationContext(callerCtx, insn, calleeCtx) :-
19+ Reachable(caller, callerCtx, _),
20+ StaticMethodInvocation(insn, _, _, caller),
21+ calleeCtx = insn.
11822}
0 commit comments