@@ -13,14 +13,20 @@ IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var
1313}
1414
1515/**
16- * Represents a variable referenced by the IR for a function. The variable may
17- * be a user-declared variable (`IRUserVariable`) or a temporary variable
18- * generated by the AST-to-IR translation (`IRTempVariable`).
16+ * A variable referenced by the IR for a function. The variable may be a user-declared variable
17+ * (`IRUserVariable`) or a temporary variable generated by the AST-to-IR translation
18+ * (`IRTempVariable`).
1919 */
20- abstract class IRVariable extends TIRVariable {
20+ class IRVariable extends TIRVariable {
2121 Language:: Function func ;
2222
23- abstract string toString ( ) ;
23+ IRVariable ( ) {
24+ this = TIRUserVariable ( _, _, func ) or
25+ this = TIRTempVariable ( func , _, _, _) or
26+ this = TIRStringLiteral ( func , _, _, _)
27+ }
28+
29+ string toString ( ) { none ( ) }
2430
2531 /**
2632 * Holds if this variable's value cannot be changed within a function. Currently used for string
@@ -41,19 +47,19 @@ abstract class IRVariable extends TIRVariable {
4147 /**
4248 * Gets the type of the variable.
4349 */
44- abstract Language:: LanguageType getLanguageType ( ) ;
50+ Language:: LanguageType getLanguageType ( ) { none ( ) }
4551
4652 /**
4753 * Gets the AST node that declared this variable, or that introduced this
4854 * variable as part of the AST-to-IR translation.
4955 */
50- abstract Language:: AST getAST ( ) ;
56+ Language:: AST getAST ( ) { none ( ) }
5157
5258 /**
5359 * Gets an identifier string for the variable. This identifier is unique
5460 * within the function.
5561 */
56- abstract string getUniqueId ( ) ;
62+ string getUniqueId ( ) { none ( ) }
5763
5864 /**
5965 * Gets the source location of this variable.
@@ -72,7 +78,7 @@ abstract class IRVariable extends TIRVariable {
7278}
7379
7480/**
75- * Represents a user-declared variable referenced by the IR for a function.
81+ * A user-declared variable referenced by the IR for a function.
7682 */
7783class IRUserVariable extends IRVariable , TIRUserVariable {
7884 Language:: Variable var ;
@@ -97,20 +103,34 @@ class IRUserVariable extends IRVariable, TIRUserVariable {
97103}
98104
99105/**
100- * Represents a variable (user-declared or temporary) that is allocated on the
101- * stack. This includes all parameters, non-static local variables, and
102- * temporary variables.
106+ * A variable (user-declared or temporary) that is allocated on the stack. This includes all
107+ * parameters, non-static local variables, and temporary variables.
103108 */
104- abstract class IRAutomaticVariable extends IRVariable { }
109+ class IRAutomaticVariable extends IRVariable {
110+ IRAutomaticVariable ( ) {
111+ exists ( Language:: Variable var |
112+ this = TIRUserVariable ( var , _, func ) and
113+ Language:: isVariableAutomatic ( var )
114+ )
115+ or
116+ this = TIRTempVariable ( func , _, _, _)
117+ }
118+ }
105119
120+ /**
121+ * A user-declared variable that is allocated on the stack. This includes all parameters and
122+ * non-static local variables.
123+ */
106124class IRAutomaticUserVariable extends IRUserVariable , IRAutomaticVariable {
107125 override Language:: AutomaticVariable var ;
108126
109- IRAutomaticUserVariable ( ) { Language:: isVariableAutomatic ( var ) }
110-
111127 final override Language:: AutomaticVariable getVariable ( ) { result = var }
112128}
113129
130+ /**
131+ * A user-declared variable that is not allocated on the stack. This includes all global variables,
132+ * namespace-scope variables, static fields, and static local variables.
133+ */
114134class IRStaticUserVariable extends IRUserVariable {
115135 override Language:: StaticVariable var ;
116136
@@ -119,10 +139,19 @@ class IRStaticUserVariable extends IRUserVariable {
119139 final override Language:: StaticVariable getVariable ( ) { result = var }
120140}
121141
122- abstract class IRGeneratedVariable extends IRVariable {
142+ /**
143+ * A variable that is not user-declared. This includes temporary variables generated as part of IR
144+ * construction, as well as string literals.
145+ */
146+ class IRGeneratedVariable extends IRVariable {
123147 Language:: AST ast ;
124148 Language:: LanguageType type ;
125149
150+ IRGeneratedVariable ( ) {
151+ this = TIRTempVariable ( func , ast , _, type ) or
152+ this = TIRStringLiteral ( func , ast , type , _)
153+ }
154+
126155 final override Language:: LanguageType getLanguageType ( ) { result = type }
127156
128157 final override Language:: AST getAST ( ) { result = ast }
@@ -144,6 +173,11 @@ IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
144173 result .getTag ( ) = tag
145174}
146175
176+ /**
177+ * A temporary variable introduced by IR construction. The most common examples are the variable
178+ * generated to hold the return value of afunction, or the variable generated to hold the result of
179+ * a condition operator (`a ? b : c`).
180+ */
147181class IRTempVariable extends IRGeneratedVariable , IRAutomaticVariable , TIRTempVariable {
148182 TempVariableTag tag ;
149183
@@ -158,18 +192,28 @@ class IRTempVariable extends IRGeneratedVariable, IRAutomaticVariable, TIRTempVa
158192 override string getBaseString ( ) { result = "#temp" }
159193}
160194
195+ /**
196+ * A temporary variable generated to hold the return value of a function.
197+ */
161198class IRReturnVariable extends IRTempVariable {
162199 IRReturnVariable ( ) { tag = ReturnValueTempVar ( ) }
163200
164201 final override string toString ( ) { result = "#return" }
165202}
166203
204+ /**
205+ * A temporary variable generated to hold the exception thrown by a `ThrowValue` instruction.
206+ */
167207class IRThrowVariable extends IRTempVariable {
168208 IRThrowVariable ( ) { tag = ThrowTempVar ( ) }
169209
170210 override string getBaseString ( ) { result = "#throw" }
171211}
172212
213+ /**
214+ * A variable generated to represent the contents of a string literal. This variable acts much like
215+ * a read-only global variable.
216+ */
173217class IRStringLiteral extends IRGeneratedVariable , TIRStringLiteral {
174218 Language:: StringLiteral literal ;
175219
0 commit comments