@@ -8,6 +8,16 @@ private newtype TOverlap =
8
8
*/
9
9
abstract class Overlap extends TOverlap {
10
10
abstract string toString ( ) ;
11
+
12
+ /**
13
+ * Gets a value representing how precise this overlap is. The higher the value, the more precise
14
+ * the overlap. The precision values are ordered as
15
+ * follows, from most to least precise:
16
+ * `MustExactlyOverlap`
17
+ * `MustTotallyOverlap`
18
+ * `MayPartiallyOverlap`
19
+ */
20
+ abstract int getPrecision ( ) ;
11
21
}
12
22
13
23
/**
@@ -16,6 +26,8 @@ abstract class Overlap extends TOverlap {
16
26
*/
17
27
class MayPartiallyOverlap extends Overlap , TMayPartiallyOverlap {
18
28
final override string toString ( ) { result = "MayPartiallyOverlap" }
29
+
30
+ final override int getPrecision ( ) { result = 0 }
19
31
}
20
32
21
33
/**
@@ -24,6 +36,8 @@ class MayPartiallyOverlap extends Overlap, TMayPartiallyOverlap {
24
36
*/
25
37
class MustTotallyOverlap extends Overlap , TMustTotallyOverlap {
26
38
final override string toString ( ) { result = "MustTotallyOverlap" }
39
+
40
+ final override int getPrecision ( ) { result = 1 }
27
41
}
28
42
29
43
/**
@@ -32,4 +46,25 @@ class MustTotallyOverlap extends Overlap, TMustTotallyOverlap {
32
46
*/
33
47
class MustExactlyOverlap extends Overlap , TMustExactlyOverlap {
34
48
final override string toString ( ) { result = "MustExactlyOverlap" }
49
+
50
+ final override int getPrecision ( ) { result = 2 }
51
+ }
52
+
53
+ /**
54
+ * Gets the `Overlap` that best represents the relationship between two memory locations `a` and
55
+ * `c`, where `getOverlap(a, b) = previousOverlap` and `getOverlap(b, c) = newOverlap`, for some
56
+ * intermediate memory location `b`.
57
+ */
58
+ Overlap combineOverlap ( Overlap previousOverlap , Overlap newOverlap ) {
59
+ // Note that it's possible that two less precise overlaps could combine to result in a more
60
+ // precise overlap. For example, both `previousOverlap` and `newOverlap` could be
61
+ // `MustTotallyOverlap` even though the actual relationship between `a` and `c` is
62
+ // `MustExactlyOverlap`. We will still return `MustTotallyOverlap` as the best conservative
63
+ // approximation we can make without additional input information.
64
+ result =
65
+ min ( Overlap overlap |
66
+ overlap = [ previousOverlap , newOverlap ]
67
+ |
68
+ overlap order by overlap .getPrecision ( )
69
+ )
35
70
}
0 commit comments