@@ -12,87 +12,52 @@ import SsaInternalsCommon
1212private module SourceVariables {
1313 cached
1414 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 ]
2017 }
2118
22- abstract class SourceVariable extends TSourceVariable {
19+ class SourceVariable extends TSourceVariable {
20+ SsaInternals0:: SourceVariable base ;
2321 int ind ;
2422
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 }
2732
2833 /** 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+ }
3041
3142 /**
3243 * Gets the number of loads performed on the base source variable
3344 * to reach the value of this source variable.
3445 */
3546 int getIndirection ( ) { result = ind }
3647
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-
4348 /** Holds if this variable is a glvalue. */
44- predicate isGLValue ( ) { none ( ) }
49+ predicate isGLValue ( ) { ind = 0 }
4550
4651 /**
4752 * Gets the type of this source variable. If `isGLValue()` holds, then
4853 * the type of this source variable should be thought of as "pointer
4954 * to `getType()`".
5055 */
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 )
6960 }
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 ) }
9661 }
9762}
9863
0 commit comments