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