@@ -10,98 +10,55 @@ private import ssa0.SsaInternals as SsaInternals0
1010import SsaInternalsCommon
1111
1212private 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-
2213 cached
2314 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 ]
2917 }
3018
31- abstract class SourceVariable extends TSourceVariable {
19+ class SourceVariable extends TSourceVariable {
20+ SsaInternals0:: SourceVariable base ;
3221 int ind ;
3322
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 }
3633
3734 /** 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+ }
3942
4043 /**
4144 * Gets the number of loads performed on the base source variable
4245 * to reach the value of this source variable.
4346 */
4447 int getIndirection ( ) { result = ind }
4548
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-
5249 /** Holds if this variable is a glvalue. */
53- predicate isGLValue ( ) { none ( ) }
50+ predicate isGLValue ( ) { ind = 0 }
5451
5552 /**
5653 * Gets the type of this source variable. If `isGLValue()` holds, then
5754 * the type of this source variable should be thought of as "pointer
5855 * to `getType()`".
5956 */
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 )
10261 }
103-
104- override DataFlowType getType ( ) { result = getTypeImpl ( call .getResultType ( ) , ind ) }
10562 }
10663}
10764
0 commit comments