@@ -123,13 +123,9 @@ class TranslatedArrayListInitialization extends TranslatedListInitialization {
123123 */
124124class TranslatedDirectInitialization extends TranslatedInitialization {
125125 TranslatedDirectInitialization ( ) {
126- // TODO: Make sure this is complete and correct
127126 not expr instanceof ArrayInitializer and
128127 not expr instanceof ObjectInitializer and
129- not expr instanceof DelegateCreation and
130- not expr instanceof CollectionInitializer and
131- not expr instanceof ObjectCreation and
132- not expr instanceof StringLiteral
128+ not expr instanceof CollectionInitializer
133129 }
134130
135131 override TranslatedElement getChild ( int id ) { id = 0 and result = this .getInitializer ( ) }
@@ -145,64 +141,6 @@ class TranslatedDirectInitialization extends TranslatedInitialization {
145141 opcode instanceof Opcode:: Store and
146142 resultType = this .getContext ( ) .getTargetType ( ) and
147143 isLValue = false
148- }
149-
150- override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
151- tag = InitializerStoreTag ( ) and
152- result = this .getParent ( ) .getChildSuccessor ( this ) and
153- kind instanceof GotoEdge
154- }
155-
156- override Instruction getChildSuccessor ( TranslatedElement child ) {
157- child = this .getInitializer ( ) and result = this .getInstruction ( InitializerStoreTag ( ) )
158- }
159-
160- override Instruction getInstructionOperand ( InstructionTag tag , OperandTag operandTag ) {
161- tag = InitializerStoreTag ( ) and
162- (
163- operandTag instanceof AddressOperandTag and
164- result = this .getContext ( ) .getTargetAddress ( )
165- or
166- operandTag instanceof StoreValueOperandTag and
167- result = this .getInitializer ( ) .getResult ( )
168- )
169- }
170-
171- TranslatedExpr getInitializer ( ) { result = getTranslatedExpr ( expr ) }
172- }
173-
174- /**
175- * Represents the IR translation of an initialization from a constructor.
176- * The `NewObj` instruction denotes the fact that during initialization a new
177- * object of type `expr.getType()` is allocated, which is then initialized by the
178- * constructor.
179- */
180- class TranslatedObjectInitialization extends TranslatedInitialization , ConstructorCallContext {
181- override ObjectCreation expr ;
182-
183- override TranslatedElement getChild ( int id ) {
184- id = 0 and result = this .getConstructorCall ( )
185- or
186- id = 1 and result = this .getInitializerExpr ( )
187- }
188-
189- override predicate hasInstruction (
190- Opcode opcode , InstructionTag tag , Type resultType , boolean isLValue
191- ) {
192- // Instruction that allocated space for a new object,
193- // and returns its address
194- tag = NewObjTag ( ) and
195- opcode instanceof Opcode:: NewObj and
196- resultType = expr .getType ( ) and
197- isLValue = false
198- or
199- // Store op used to assign the variable that
200- // is initialized the address of the newly allocated
201- // object
202- tag = InitializerStoreTag ( ) and
203- opcode instanceof Opcode:: Store and
204- resultType = expr .getType ( ) and
205- isLValue = false
206144 or
207145 needsConversion ( ) and
208146 tag = AssignmentConvertRightTag ( ) and
@@ -214,39 +152,22 @@ class TranslatedObjectInitialization extends TranslatedInitialization, Construct
214152 isLValue = false
215153 }
216154
217- final override Instruction getFirstInstruction ( ) { result = this .getInstruction ( NewObjTag ( ) ) }
218-
219155 override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
220- kind instanceof GotoEdge and
221- (
222- tag = NewObjTag ( ) and
223- result = this .getConstructorCall ( ) .getFirstInstruction ( )
224- or
225- tag = InitializerStoreTag ( ) and
226- result = this .getParent ( ) .getChildSuccessor ( this )
227- or
228- tag = AssignmentConvertRightTag ( ) and
229- result = this .getInstruction ( InitializerStoreTag ( ) )
230- )
156+ tag = InitializerStoreTag ( ) and
157+ result = this .getParent ( ) .getChildSuccessor ( this ) and
158+ kind instanceof GotoEdge
159+ or
160+ needsConversion ( ) and
161+ tag = AssignmentConvertRightTag ( ) and
162+ result = getInstruction ( InitializerStoreTag ( ) ) and
163+ kind instanceof GotoEdge
231164 }
232165
233166 override Instruction getChildSuccessor ( TranslatedElement child ) {
234- (
235- child = this .getConstructorCall ( ) and
236- if exists ( this .getInitializerExpr ( ) )
237- then result = this .getInitializerExpr ( ) .getFirstInstruction ( )
238- else
239- if this .needsConversion ( )
240- then result = this .getInstruction ( AssignmentConvertRightTag ( ) )
241- else result = this .getInstruction ( InitializerStoreTag ( ) )
242- )
243- or
244- (
245- child = this .getInitializerExpr ( ) and
246- if this .needsConversion ( )
247- then result = this .getInstruction ( AssignmentConvertRightTag ( ) )
248- else result = this .getInstruction ( InitializerStoreTag ( ) )
249- )
167+ child = this .getInitializer ( ) and
168+ if this .needsConversion ( )
169+ then result = this .getInstruction ( AssignmentConvertRightTag ( ) )
170+ else result = this .getInstruction ( InitializerStoreTag ( ) )
250171 }
251172
252173 override Instruction getInstructionOperand ( InstructionTag tag , OperandTag operandTag ) {
@@ -256,33 +177,28 @@ class TranslatedObjectInitialization extends TranslatedInitialization, Construct
256177 result = this .getParent ( ) .( InitializationContext ) .getTargetAddress ( )
257178 or
258179 (
180+ operandTag instanceof AddressOperandTag and
181+ result = this .getContext ( ) .getTargetAddress ( )
182+ or
259183 operandTag instanceof StoreValueOperandTag and
260- if needsConversion ( )
261- then result = this .getInstruction ( AssignmentConvertRightTag ( ) )
262- else result = this .getInstruction ( NewObjTag ( ) )
184+ result = this .getInitializer ( ) .getResult ( )
263185 )
264186 )
265187 or
266188 tag = AssignmentConvertRightTag ( ) and
267189 operandTag instanceof UnaryOperandTag and
190+ result = this .getInitializer ( ) .getResult ( )
191+ or
192+ tag = AssignmentConvertRightTag ( ) and
193+ operandTag instanceof UnaryOperandTag and
268194 result = this .getInstruction ( NewObjTag ( ) )
269195 }
270196
271- private TranslatedExpr getConstructorCall ( ) { result = getTranslatedExpr ( expr ) }
272-
273- private TranslatedExpr getInitializerExpr ( ) { result = getTranslatedExpr ( expr .getInitializer ( ) ) }
274-
275- override Instruction getReceiver ( ) {
276- // The newly allocated object will be the target of the constructor call
277- result = this .getInstruction ( NewObjTag ( ) )
278- }
197+ TranslatedExpr getInitializer ( ) { result = getTranslatedExpr ( expr ) }
279198
280199 private predicate needsConversion ( ) { expr .getType ( ) != this .getContext ( ) .getTargetType ( ) }
281200}
282201
283- //private string getZeroValue(Type type) {
284- // if type instanceof FloatingPointType then result = "0.0" else result = "0"
285- //}
286202/**
287203 * Represents the IR translation of the initialization of an array element from
288204 * an element of an initializer list.
@@ -424,7 +340,7 @@ class TranslatedConstructorInitializer extends TranslatedConstructorCallFromCons
424340 TTranslatedConstructorInitializer {
425341 TranslatedConstructorInitializer ( ) { this = TTranslatedConstructorInitializer ( call ) }
426342
427- override string toString ( ) { result = "constuructor init: " + call .toString ( ) }
343+ override string toString ( ) { result = "constructor init: " + call .toString ( ) }
428344
429345 override Instruction getFirstInstruction ( ) {
430346 if needsConversion ( )
@@ -472,58 +388,3 @@ class TranslatedConstructorInitializer extends TranslatedConstructorCallFromCons
472388 derivedClass = this .getFunction ( ) .getDeclaringType ( )
473389 }
474390}
475-
476- /**
477- * Represents the IR translation of a delegate creation.
478- */
479- class TranslatedDelegateCreation extends TranslatedInitialization , ConstructorCallContext {
480- override DelegateCreation expr ;
481-
482- override TranslatedElement getChild ( int id ) { id = 0 and result = getConstructorCall ( ) }
483-
484- override predicate hasInstruction (
485- Opcode opcode , InstructionTag tag , Type resultType , boolean isLValue
486- ) {
487- tag = NewObjTag ( ) and
488- opcode instanceof Opcode:: NewObj and
489- resultType = expr .getType ( ) and
490- isLValue = false
491- or
492- tag = InitializerStoreTag ( ) and
493- opcode instanceof Opcode:: Store and
494- resultType = expr .getType ( ) and
495- isLValue = false
496- }
497-
498- final override Instruction getFirstInstruction ( ) { result = getInstruction ( NewObjTag ( ) ) }
499-
500- override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
501- tag = NewObjTag ( ) and
502- result = getConstructorCall ( ) .getFirstInstruction ( ) and
503- kind instanceof GotoEdge
504- or
505- tag = InitializerStoreTag ( ) and
506- result = getParent ( ) .getChildSuccessor ( this ) and
507- kind instanceof GotoEdge
508- }
509-
510- override Instruction getChildSuccessor ( TranslatedElement child ) {
511- child = getConstructorCall ( ) and
512- result = getInstruction ( InitializerStoreTag ( ) )
513- }
514-
515- override Instruction getInstructionOperand ( InstructionTag tag , OperandTag operandTag ) {
516- tag = InitializerStoreTag ( ) and
517- (
518- operandTag instanceof AddressOperandTag and
519- result = getParent ( ) .( InitializationContext ) .getTargetAddress ( )
520- or
521- operandTag instanceof StoreValueOperandTag and
522- result = getInstruction ( NewObjTag ( ) )
523- )
524- }
525-
526- private TranslatedElement getConstructorCall ( ) { result = DelegateElements:: getConstructor ( expr ) }
527-
528- override Instruction getReceiver ( ) { result = getInstruction ( NewObjTag ( ) ) }
529- }
0 commit comments