@@ -9,107 +9,6 @@ private import RangeAnalysisImpl
99private import ConstantAnalysis
1010
1111module RangeUtil< DeltaSig D, LangSig< Sem , D > Lang> implements UtilSig< Sem , D > {
12- /**
13- * Gets an expression that equals `v - d`.
14- */
15- private SemExpr semSsaRead ( SemSsaVariable v , D:: Delta delta ) {
16- // There are various language-specific extension points that can be removed once we no longer
17- // expect to match the original Java implementation's results exactly.
18- result = v .getAUse ( ) and delta = D:: fromInt ( 0 )
19- or
20- exists ( D:: Delta d1 , SemConstantIntegerExpr c |
21- result .( SemAddExpr ) .hasOperands ( semSsaRead ( v , d1 ) , c ) and
22- delta = D:: fromFloat ( D:: toFloat ( d1 ) - c .getIntValue ( ) )
23- )
24- or
25- exists ( SemSubExpr sub , D:: Delta d1 , SemConstantIntegerExpr c |
26- result = sub and
27- sub .getLeftOperand ( ) = semSsaRead ( v , d1 ) and
28- sub .getRightOperand ( ) = c and
29- delta = D:: fromFloat ( D:: toFloat ( d1 ) + c .getIntValue ( ) )
30- )
31- or
32- result = v .( SemSsaExplicitUpdate ) .getSourceExpr ( ) and
33- delta = D:: fromFloat ( 0 )
34- or
35- result .( SemCopyValueExpr ) .getOperand ( ) = semSsaRead ( v , delta )
36- or
37- result .( SemStoreExpr ) .getOperand ( ) = semSsaRead ( v , delta )
38- }
39-
40- /**
41- * Gets a condition that tests whether `v` equals `e + delta`.
42- *
43- * If the condition evaluates to `testIsTrue`:
44- * - `isEq = true` : `v == e + delta`
45- * - `isEq = false` : `v != e + delta`
46- */
47- pragma [ nomagic]
48- SemGuard semEqFlowCond (
49- SemSsaVariable v , SemExpr e , D:: Delta delta , boolean isEq , boolean testIsTrue
50- ) {
51- exists ( boolean eqpolarity |
52- result .isEquality ( semSsaRead ( v , delta ) , e , eqpolarity ) and
53- ( testIsTrue = true or testIsTrue = false ) and
54- eqpolarity .booleanXor ( testIsTrue ) .booleanNot ( ) = isEq
55- )
56- or
57- exists ( boolean testIsTrue0 |
58- semImplies_v2 ( result , testIsTrue , semEqFlowCond ( v , e , delta , isEq , testIsTrue0 ) , testIsTrue0 )
59- )
60- }
61-
62- /**
63- * Holds if `v` is an `SsaExplicitUpdate` that equals `e + delta`.
64- */
65- predicate semSsaUpdateStep ( SemSsaExplicitUpdate v , SemExpr e , D:: Delta delta ) {
66- exists ( SemExpr defExpr | defExpr = v .getSourceExpr ( ) |
67- defExpr .( SemCopyValueExpr ) .getOperand ( ) = e and delta = D:: fromFloat ( 0 )
68- or
69- defExpr .( SemStoreExpr ) .getOperand ( ) = e and delta = D:: fromFloat ( 0 )
70- or
71- defExpr .( SemAddOneExpr ) .getOperand ( ) = e and delta = D:: fromFloat ( 1 )
72- or
73- defExpr .( SemSubOneExpr ) .getOperand ( ) = e and delta = D:: fromFloat ( - 1 )
74- or
75- e = defExpr and
76- not (
77- defExpr instanceof SemCopyValueExpr or
78- defExpr instanceof SemStoreExpr or
79- defExpr instanceof SemAddOneExpr or
80- defExpr instanceof SemSubOneExpr
81- ) and
82- delta = D:: fromFloat ( 0 )
83- )
84- }
85-
86- /**
87- * Holds if `e1 + delta` equals `e2`.
88- */
89- predicate semValueFlowStep ( SemExpr e2 , SemExpr e1 , D:: Delta delta ) {
90- e2 .( SemCopyValueExpr ) .getOperand ( ) = e1 and delta = D:: fromFloat ( 0 )
91- or
92- e2 .( SemStoreExpr ) .getOperand ( ) = e1 and delta = D:: fromFloat ( 0 )
93- or
94- e2 .( SemAddOneExpr ) .getOperand ( ) = e1 and delta = D:: fromFloat ( 1 )
95- or
96- e2 .( SemSubOneExpr ) .getOperand ( ) = e1 and delta = D:: fromFloat ( - 1 )
97- or
98- Lang:: additionalValueFlowStep ( e2 , e1 , delta )
99- or
100- exists ( SemExpr x | e2 .( SemAddExpr ) .hasOperands ( e1 , x ) |
101- D:: fromInt ( x .( SemConstantIntegerExpr ) .getIntValue ( ) ) = delta
102- )
103- or
104- exists ( SemExpr x , SemSubExpr sub |
105- e2 = sub and
106- sub .getLeftOperand ( ) = e1 and
107- sub .getRightOperand ( ) = x
108- |
109- D:: fromInt ( - x .( SemConstantIntegerExpr ) .getIntValue ( ) ) = delta
110- )
111- }
112-
11312 /**
11413 * Gets the type used to track the specified expression's range information.
11514 *
0 commit comments