@@ -73,15 +73,15 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
73
73
final override Function getFunction ( ) { result = func }
74
74
75
75
final override TranslatedElement getChild ( int id ) {
76
- id = - 4 and result = getReadEffects ( )
76
+ id = - 5 and result = getReadEffects ( )
77
77
or
78
- id = - 3 and result = getConstructorInitList ( )
78
+ id = - 4 and result = getConstructorInitList ( )
79
79
or
80
- id = - 2 and result = getBody ( )
80
+ id = - 3 and result = getBody ( )
81
81
or
82
- id = - 1 and result = getDestructorDestructionList ( )
82
+ id = - 2 and result = getDestructorDestructionList ( )
83
83
or
84
- id >= 0 and result = getParameter ( id )
84
+ id >= - 1 and result = getParameter ( id )
85
85
}
86
86
87
87
final private TranslatedConstructorInitList getConstructorInitList ( ) {
@@ -97,6 +97,9 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
97
97
final private TranslatedReadEffects getReadEffects ( ) { result = getTranslatedReadEffects ( func ) }
98
98
99
99
final private TranslatedParameter getParameter ( int index ) {
100
+ result = getTranslatedThisParameter ( func ) and
101
+ index = - 1
102
+ or
100
103
result = getTranslatedParameter ( func .getParameter ( index ) )
101
104
or
102
105
index = getEllipsisParameterIndexForFunction ( func ) and
@@ -117,20 +120,13 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
117
120
(
118
121
tag = InitializeNonLocalTag ( ) and
119
122
if exists ( getThisType ( ) )
120
- then result = getInstruction ( InitializeThisTag ( ) )
123
+ then result = getParameter ( - 1 ) . getFirstInstruction ( )
121
124
else
122
125
if exists ( getParameter ( 0 ) )
123
126
then result = getParameter ( 0 ) .getFirstInstruction ( )
124
127
else result = getBody ( ) .getFirstInstruction ( )
125
128
)
126
129
or
127
- (
128
- tag = InitializeThisTag ( ) and
129
- if exists ( getParameter ( 0 ) )
130
- then result = getParameter ( 0 ) .getFirstInstruction ( )
131
- else result = getConstructorInitList ( ) .getFirstInstruction ( )
132
- )
133
- or
134
130
tag = ReturnValueAddressTag ( ) and
135
131
result = getInstruction ( ReturnTag ( ) )
136
132
or
@@ -184,10 +180,6 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
184
180
opcode instanceof Opcode:: InitializeNonLocal and
185
181
resultType = getUnknownType ( )
186
182
or
187
- tag = InitializeThisTag ( ) and
188
- opcode instanceof Opcode:: InitializeThis and
189
- resultType = getTypeForGLValue ( getThisType ( ) )
190
- or
191
183
tag = ReturnValueAddressTag ( ) and
192
184
opcode instanceof Opcode:: VariableAddress and
193
185
resultType = getTypeForGLValue ( getReturnType ( ) ) and
@@ -228,10 +220,8 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
228
220
final override Instruction getInstructionRegisterOperand ( InstructionTag tag , OperandTag operandTag ) {
229
221
tag = ReturnTag ( ) and
230
222
hasReturnValue ( ) and
231
- (
232
- operandTag instanceof AddressOperandTag and
233
- result = getInstruction ( ReturnValueAddressTag ( ) )
234
- )
223
+ operandTag instanceof AddressOperandTag and
224
+ result = getInstruction ( ReturnValueAddressTag ( ) )
235
225
}
236
226
237
227
final override CppType getInstructionMemoryOperandType (
@@ -264,6 +254,9 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
264
254
tag = EllipsisTempVar ( ) and
265
255
func .isVarargs ( ) and
266
256
type = getEllipsisVariablePRValueType ( )
257
+ or
258
+ tag = ThisTempVar ( ) and
259
+ type = getTypeForGLValue ( getThisType ( ) )
267
260
}
268
261
269
262
/**
@@ -286,6 +279,11 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
286
279
*/
287
280
final IREllipsisVariable getEllipsisVariable ( ) { result .getEnclosingFunction ( ) = func }
288
281
282
+ /**
283
+ * Gets the variable that represents the `this` pointer for this function, if any.
284
+ */
285
+ final IRThisVariable getThisVariable ( ) { result = getIRTempVariable ( func , ThisTempVar ( ) ) }
286
+
289
287
/**
290
288
* Holds if the function has a non-`void` return type.
291
289
*/
@@ -295,7 +293,9 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
295
293
* Gets the single `InitializeThis` instruction for this function. Holds only
296
294
* if the function is an instance member function, constructor, or destructor.
297
295
*/
298
- final Instruction getInitializeThisInstruction ( ) { result = getInstruction ( InitializeThisTag ( ) ) }
296
+ final Instruction getInitializeThisInstruction ( ) {
297
+ result = getTranslatedThisParameter ( func ) .getInstruction ( InitializerStoreTag ( ) )
298
+ }
299
299
300
300
/**
301
301
* Gets the type pointed to by the `this` pointer for this function (i.e. `*this`).
@@ -336,6 +336,11 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
336
336
final Type getReturnType ( ) { result = func .getType ( ) }
337
337
}
338
338
339
+ /**
340
+ * Gets the `TranslatedThisParameter` for function `func`, if one exists.
341
+ */
342
+ TranslatedThisParameter getTranslatedThisParameter ( Function func ) { result .getFunction ( ) = func }
343
+
339
344
/**
340
345
* Gets the `TranslatedPositionalParameter` that represents parameter `param`.
341
346
*/
@@ -350,8 +355,9 @@ TranslatedEllipsisParameter getTranslatedEllipsisParameter(Function func) {
350
355
351
356
/**
352
357
* The IR translation of a parameter to a function. This can be either a user-declared parameter
353
- * (`TranslatedPositionParameter`) or the synthesized parameter used to represent a `...` in a
354
- * varargs function (`TranslatedEllipsisParameter`).
358
+ * (`TranslatedPositionParameter`), the synthesized parameter used to represent `this`, or the
359
+ * synthesized parameter used to represent a `...` in a varargs function
360
+ * (`TranslatedEllipsisParameter`).
355
361
*/
356
362
abstract class TranslatedParameter extends TranslatedElement {
357
363
final override TranslatedElement getChild ( int id ) { none ( ) }
@@ -398,7 +404,7 @@ abstract class TranslatedParameter extends TranslatedElement {
398
404
hasIndirection ( ) and
399
405
tag = InitializerIndirectStoreTag ( ) and
400
406
opcode instanceof Opcode:: InitializeIndirection and
401
- resultType = getUnknownType ( )
407
+ resultType = getInitializationResultType ( )
402
408
}
403
409
404
410
final override IRVariable getInstructionVariable ( InstructionTag tag ) {
@@ -435,9 +441,43 @@ abstract class TranslatedParameter extends TranslatedElement {
435
441
436
442
abstract CppType getPRValueType ( ) ;
437
443
444
+ abstract CppType getInitializationResultType ( ) ;
445
+
438
446
abstract IRAutomaticVariable getIRVariable ( ) ;
439
447
}
440
448
449
+ /**
450
+ * The IR translation of the synthesized parameter used to represent the `...` in a varargs
451
+ * function.
452
+ */
453
+ class TranslatedThisParameter extends TranslatedParameter , TTranslatedThisParameter {
454
+ Function func ;
455
+
456
+ TranslatedThisParameter ( ) { this = TTranslatedThisParameter ( func ) }
457
+
458
+ final override string toString ( ) { result = "this" }
459
+
460
+ final override Locatable getAST ( ) { result = func }
461
+
462
+ final override Function getFunction ( ) { result = func }
463
+
464
+ final override predicate hasIndirection ( ) { any ( ) }
465
+
466
+ final override CppType getGLValueType ( ) { result = getTypeForGLValue ( any ( UnknownType t ) ) }
467
+
468
+ final override CppType getPRValueType ( ) {
469
+ result = getTypeForGLValue ( getTranslatedFunction ( func ) .getThisType ( ) )
470
+ }
471
+
472
+ final override CppType getInitializationResultType ( ) {
473
+ result = getTypeForPRValue ( getTranslatedFunction ( func ) .getThisType ( ) )
474
+ }
475
+
476
+ final override IRThisVariable getIRVariable ( ) {
477
+ result = getTranslatedFunction ( func ) .getThisVariable ( )
478
+ }
479
+ }
480
+
441
481
/**
442
482
* Represents the IR translation of a function parameter, including the
443
483
* initialization of that parameter with the incoming argument.
@@ -468,6 +508,8 @@ class TranslatedPositionalParameter extends TranslatedParameter, TTranslatedPara
468
508
469
509
final override CppType getPRValueType ( ) { result = getTypeForPRValue ( getVariableType ( param ) ) }
470
510
511
+ final override CppType getInitializationResultType ( ) { result = getUnknownType ( ) }
512
+
471
513
final override IRAutomaticUserVariable getIRVariable ( ) {
472
514
result = getIRUserVariable ( getFunction ( ) , param )
473
515
}
@@ -494,6 +536,8 @@ class TranslatedEllipsisParameter extends TranslatedParameter, TTranslatedEllips
494
536
495
537
final override CppType getPRValueType ( ) { result = getEllipsisVariablePRValueType ( ) }
496
538
539
+ final override CppType getInitializationResultType ( ) { result = getUnknownType ( ) }
540
+
497
541
final override IREllipsisVariable getIRVariable ( ) {
498
542
result = getTranslatedFunction ( func ) .getEllipsisVariable ( )
499
543
}
0 commit comments