@@ -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,29 +120,13 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
117
120
(
118
121
tag = InitializeNonLocalTag ( ) and
119
122
if exists ( getThisType ( ) )
120
- then result = getInstruction ( InitializeThisAddressTag ( ) )
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
- tag = InitializeThisAddressTag ( ) and
128
- result = getInstruction ( InitializeThisTag ( ) )
129
- or
130
- tag = InitializeThisTag ( ) and
131
- result = getInstruction ( InitializeThisIndirectionAddressTag ( ) )
132
- or
133
- tag = InitializeThisIndirectionAddressTag ( ) and
134
- result = getInstruction ( InitializeThisIndirectionTag ( ) )
135
- or
136
- (
137
- tag = InitializeThisIndirectionTag ( ) and
138
- if exists ( getParameter ( 0 ) )
139
- then result = getParameter ( 0 ) .getFirstInstruction ( )
140
- else result = getConstructorInitList ( ) .getFirstInstruction ( )
141
- )
142
- or
143
130
tag = ReturnValueAddressTag ( ) and
144
131
result = getInstruction ( ReturnTag ( ) )
145
132
or
@@ -193,23 +180,6 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
193
180
opcode instanceof Opcode:: InitializeNonLocal and
194
181
resultType = getUnknownType ( )
195
182
or
196
- tag = InitializeThisAddressTag ( ) and
197
- opcode instanceof Opcode:: VariableAddress and
198
- resultType = getTypeForGLValue ( any ( UnknownType t ) ) and
199
- exists ( getThisType ( ) )
200
- or
201
- tag = InitializeThisTag ( ) and
202
- opcode instanceof Opcode:: InitializeParameter and
203
- resultType = getTypeForGLValue ( getThisType ( ) )
204
- or
205
- tag = InitializeThisIndirectionAddressTag ( ) and
206
- opcode instanceof Opcode:: Load and
207
- resultType = getTypeForGLValue ( getThisType ( ) )
208
- or
209
- tag = InitializeThisIndirectionTag ( ) and
210
- opcode instanceof Opcode:: InitializeIndirection and
211
- resultType = getTypeForPRValue ( getThisType ( ) )
212
- or
213
183
tag = ReturnValueAddressTag ( ) and
214
184
opcode instanceof Opcode:: VariableAddress and
215
185
resultType = getTypeForGLValue ( getReturnType ( ) ) and
@@ -252,21 +222,6 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
252
222
hasReturnValue ( ) and
253
223
operandTag instanceof AddressOperandTag and
254
224
result = getInstruction ( ReturnValueAddressTag ( ) )
255
- or
256
- tag = InitializeThisTag ( ) and
257
- exists ( getThisType ( ) ) and
258
- operandTag instanceof AddressOperandTag and
259
- result = getInstruction ( InitializeThisAddressTag ( ) )
260
- or
261
- tag = InitializeThisIndirectionAddressTag ( ) and
262
- exists ( getThisType ( ) ) and
263
- operandTag instanceof AddressOperandTag and
264
- result = getInstruction ( InitializeThisAddressTag ( ) )
265
- or
266
- tag = InitializeThisIndirectionTag ( ) and
267
- exists ( getThisType ( ) ) and
268
- operandTag instanceof AddressOperandTag and
269
- result = getInstruction ( InitializeThisIndirectionAddressTag ( ) )
270
225
}
271
226
272
227
final override CppType getInstructionMemoryOperandType (
@@ -280,23 +235,9 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
280
235
tag = AliasedUseTag ( ) and
281
236
operandTag instanceof SideEffectOperandTag and
282
237
result = getUnknownType ( )
283
- or
284
- tag = InitializeThisIndirectionAddressTag ( ) and
285
- exists ( getThisType ( ) ) and
286
- operandTag instanceof LoadOperandTag and
287
- result = getTypeForGLValue ( getThisType ( ) )
288
238
}
289
239
290
240
final override IRVariable getInstructionVariable ( InstructionTag tag ) {
291
- tag = InitializeThisAddressTag ( ) and
292
- result = getThisVariable ( )
293
- or
294
- tag = InitializeThisTag ( ) and
295
- result = getThisVariable ( )
296
- or
297
- tag = InitializeThisIndirectionTag ( ) and
298
- result = getThisVariable ( )
299
- or
300
241
tag = ReturnValueAddressTag ( ) and
301
242
result = getReturnVariable ( )
302
243
}
@@ -352,7 +293,9 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
352
293
* Gets the single `InitializeThis` instruction for this function. Holds only
353
294
* if the function is an instance member function, constructor, or destructor.
354
295
*/
355
- final Instruction getInitializeThisInstruction ( ) { result = getInstruction ( InitializeThisTag ( ) ) }
296
+ final Instruction getInitializeThisInstruction ( ) {
297
+ result = getTranslatedThisParameter ( func ) .getInstruction ( InitializerStoreTag ( ) )
298
+ }
356
299
357
300
/**
358
301
* Gets the type pointed to by the `this` pointer for this function (i.e. `*this`).
@@ -393,6 +336,11 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
393
336
final Type getReturnType ( ) { result = func .getType ( ) }
394
337
}
395
338
339
+ /**
340
+ * Gets the `TranslatedThisParameter` for function `func`, if one exists.
341
+ */
342
+ TranslatedThisParameter getTranslatedThisParameter ( Function func ) { result .getFunction ( ) = func }
343
+
396
344
/**
397
345
* Gets the `TranslatedPositionalParameter` that represents parameter `param`.
398
346
*/
@@ -407,8 +355,9 @@ TranslatedEllipsisParameter getTranslatedEllipsisParameter(Function func) {
407
355
408
356
/**
409
357
* The IR translation of a parameter to a function. This can be either a user-declared parameter
410
- * (`TranslatedPositionParameter`) or the synthesized parameter used to represent a `...` in a
411
- * 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`).
412
361
*/
413
362
abstract class TranslatedParameter extends TranslatedElement {
414
363
final override TranslatedElement getChild ( int id ) { none ( ) }
@@ -455,7 +404,7 @@ abstract class TranslatedParameter extends TranslatedElement {
455
404
hasIndirection ( ) and
456
405
tag = InitializerIndirectStoreTag ( ) and
457
406
opcode instanceof Opcode:: InitializeIndirection and
458
- resultType = getUnknownType ( )
407
+ resultType = getInitializationResultType ( )
459
408
}
460
409
461
410
final override IRVariable getInstructionVariable ( InstructionTag tag ) {
@@ -492,9 +441,43 @@ abstract class TranslatedParameter extends TranslatedElement {
492
441
493
442
abstract CppType getPRValueType ( ) ;
494
443
444
+ abstract CppType getInitializationResultType ( ) ;
445
+
495
446
abstract IRAutomaticVariable getIRVariable ( ) ;
496
447
}
497
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
+
498
481
/**
499
482
* Represents the IR translation of a function parameter, including the
500
483
* initialization of that parameter with the incoming argument.
@@ -525,6 +508,8 @@ class TranslatedPositionalParameter extends TranslatedParameter, TTranslatedPara
525
508
526
509
final override CppType getPRValueType ( ) { result = getTypeForPRValue ( getVariableType ( param ) ) }
527
510
511
+ final override CppType getInitializationResultType ( ) { result = getUnknownType ( ) }
512
+
528
513
final override IRAutomaticUserVariable getIRVariable ( ) {
529
514
result = getIRUserVariable ( getFunction ( ) , param )
530
515
}
@@ -551,6 +536,8 @@ class TranslatedEllipsisParameter extends TranslatedParameter, TTranslatedEllips
551
536
552
537
final override CppType getPRValueType ( ) { result = getEllipsisVariablePRValueType ( ) }
553
538
539
+ final override CppType getInitializationResultType ( ) { result = getUnknownType ( ) }
540
+
554
541
final override IREllipsisVariable getIRVariable ( ) {
555
542
result = getTranslatedFunction ( func ) .getEllipsisVariable ( )
556
543
}
0 commit comments