@@ -10,98 +10,55 @@ private import ssa0.SsaInternals as SsaInternals0
10
10
import SsaInternalsCommon
11
11
12
12
private module SourceVariables {
13
- int getMaxIndirectionForIRVariable ( IRVariable var ) {
14
- exists ( Type type , boolean isGLValue |
15
- var .getLanguageType ( ) .hasType ( type , isGLValue ) and
16
- if isGLValue = true
17
- then result = 1 + getMaxIndirectionsForType ( type )
18
- else result = getMaxIndirectionsForType ( type )
19
- )
20
- }
21
-
22
13
cached
23
14
private newtype TSourceVariable =
24
- TSourceIRVariable ( BaseIRVariable baseVar , int ind ) {
25
- ind = [ 0 .. getMaxIndirectionForIRVariable ( baseVar .getIRVariable ( ) ) ]
26
- } or
27
- TCallVariable ( AllocationInstruction call , int ind ) {
28
- ind = [ 0 .. countIndirectionsForCppType ( getResultLanguageType ( call ) ) ]
15
+ TMkSourceVariable ( SsaInternals0:: SourceVariable base , int ind ) {
16
+ ind = [ 0 .. countIndirectionsForCppType ( base .getLanguageType ( ) ) + 1 ]
29
17
}
30
18
31
- abstract class SourceVariable extends TSourceVariable {
19
+ class SourceVariable extends TSourceVariable {
20
+ SsaInternals0:: SourceVariable base ;
32
21
int ind ;
33
22
34
- bindingset [ ind]
35
- SourceVariable ( ) { any ( ) }
23
+ SourceVariable ( ) { this = TMkSourceVariable ( base , ind ) }
24
+
25
+ /** Gets the IR variable associated with this `SourceVariable`, if any. */
26
+ IRVariable getIRVariable ( ) { result = base .( BaseIRVariable ) .getIRVariable ( ) }
27
+
28
+ /**
29
+ * Gets the base source variable (i.e., the variable without any
30
+ * indirections) of this source variable.
31
+ */
32
+ SsaInternals0:: SourceVariable getBaseVariable ( ) { result = base }
36
33
37
34
/** Gets a textual representation of this element. */
38
- abstract string toString ( ) ;
35
+ string toString ( ) {
36
+ ind = 0 and
37
+ result = this .getBaseVariable ( ) .toString ( )
38
+ or
39
+ ind > 0 and
40
+ result = this .getBaseVariable ( ) .toString ( ) + " indirection"
41
+ }
39
42
40
43
/**
41
44
* Gets the number of loads performed on the base source variable
42
45
* to reach the value of this source variable.
43
46
*/
44
47
int getIndirection ( ) { result = ind }
45
48
46
- /**
47
- * Gets the base source variable (i.e., the variable without any
48
- * indirections) of this source variable.
49
- */
50
- abstract BaseSourceVariable getBaseVariable ( ) ;
51
-
52
49
/** Holds if this variable is a glvalue. */
53
- predicate isGLValue ( ) { none ( ) }
50
+ predicate isGLValue ( ) { ind = 0 }
54
51
55
52
/**
56
53
* Gets the type of this source variable. If `isGLValue()` holds, then
57
54
* the type of this source variable should be thought of as "pointer
58
55
* to `getType()`".
59
56
*/
60
- abstract DataFlowType getType ( ) ;
61
- }
62
-
63
- class SourceIRVariable extends SourceVariable , TSourceIRVariable {
64
- BaseIRVariable var ;
65
-
66
- SourceIRVariable ( ) { this = TSourceIRVariable ( var , ind ) }
67
-
68
- IRVariable getIRVariable ( ) { result = var .getIRVariable ( ) }
69
-
70
- override BaseIRVariable getBaseVariable ( ) { result .getIRVariable ( ) = this .getIRVariable ( ) }
71
-
72
- override string toString ( ) {
73
- ind = 0 and
74
- result = this .getIRVariable ( ) .toString ( )
75
- or
76
- ind > 0 and
77
- result = this .getIRVariable ( ) .toString ( ) + " indirection"
78
- }
79
-
80
- override predicate isGLValue ( ) { ind = 0 }
81
-
82
- override DataFlowType getType ( ) {
83
- if ind = 0 then result = var .getType ( ) else result = getTypeImpl ( var .getType ( ) , ind - 1 )
84
- }
85
- }
86
-
87
- class CallVariable extends SourceVariable , TCallVariable {
88
- AllocationInstruction call ;
89
-
90
- CallVariable ( ) { this = TCallVariable ( call , ind ) }
91
-
92
- AllocationInstruction getCall ( ) { result = call }
93
-
94
- override BaseCallVariable getBaseVariable ( ) { result .getCallInstruction ( ) = call }
95
-
96
- override string toString ( ) {
97
- ind = 0 and
98
- result = "Call"
99
- or
100
- ind > 0 and
101
- result = "Call indirection"
57
+ DataFlowType getType ( ) {
58
+ if this .isGLValue ( )
59
+ then result = base .getType ( )
60
+ else result = getTypeImpl ( base .getType ( ) , ind - 1 )
102
61
}
103
-
104
- override DataFlowType getType ( ) { result = getTypeImpl ( call .getResultType ( ) , ind ) }
105
62
}
106
63
}
107
64
0 commit comments