11#pragma once
2- #include "utils .dl"
2+ #include "abstract-context-sensitive-pt .dl"
33
4- .comp OneTypeSensitivePT{
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 = Class
5+ .type Context = Class
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- SpecialMethodInvocation(insn, _, callee, base, caller),
74- VarPointsTo(baseHeap, _, base, callerCtx),
75- AssignHeapAllocation(_, _, baseHeap, _, inmethod, _),
76- MethodInfo(inmethod, _, _, inType, _, _, _),
77- calleeCtx = inType.
78-
79- Reachable(callee, calleeCtx, n+1),
80- CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
81- Reachable(caller, callerCtx, n),
82- n < MAXSTEP,
83- StaticMethodInvocation(insn, _, callee, caller),
84- calleeCtx = insn. // maybe have bug
85-
86- Reachable(callee, calleeCtx, n+1),
87- CallGraph(insn, caller, callerCtx, callee, calleeCtx) :-
88- Reachable(caller, callerCtx, n),
89- n < MAXSTEP,
90- VirtualMethodInvocation(insn, _, method, base, caller),
91- VarPointsTo(baseHeap, _, base, callerCtx),
92- NormalHeap(baseHeap, class),
93- MethodInfo(method, simplename, _, _, _, descriptor, _),
94- Dispatch(simplename, descriptor, class, callee),
7+ .comp OneTypeSensitivePT<HContext, Context> : AbstractContextSensitivePT<HContext, Context>{
8+ .override SelectInvocationContext
9+ SelectInvocationContext(callerCtx, insn, baseHeap, hctx, calleeCtx) :-
10+ Reachable(caller, callerCtx, _),
11+ (
12+ SpecialMethodInvocation(insn, _, _, base, caller);
13+ VirtualMethodInvocation(insn, _, _, base, caller)
14+ ),
15+ VarPointsTo(baseHeap, hctx, base, callerCtx),
9516 AssignHeapAllocation(_, _, baseHeap, _, inmethod, _),
9617 MethodInfo(inmethod, _, _, inType, _, _, _),
9718 calleeCtx = inType.
98-
99- // param
100- VarPointsTo(heap, hctx, param, calleeCtx) :-
101- CallGraph(insn, _, callerCtx, callee, calleeCtx),
102- ActualParam(n, insn, arg),
103- FormalParam(n, callee, param),
104- VarPointsTo(heap, hctx, arg, callerCtx),
105- NormalHeap(heap, _).
106-
107- // return
108- VarPointsTo(heap, hctx, return, callerCtx) :-
109- CallGraph(insn, _, callerCtx, callee, calleeCtx),
110- Return(_, _, var, callee),
111- AssignReturnValue(insn, return),
112- VarPointsTo(heap, hctx, var, calleeCtx).
113-
114- // this
115- VarPointsTo(heap, hctx, this, calleeCtx) :-
116- CallGraph(insn, _, callerCtx, callee, calleeCtx),
117- (
118- VirtualMethodInvocation(insn, _, _, base, _);
119- SpecialMethodInvocation(insn, _, _, base, _)
120- ),
121- ThisVar(callee, this),
122- VarPointsTo(heap, hctx, base, callerCtx).
12319}
0 commit comments