Determining the Object on which a Method is Invoked

Moderator: Automated Code Analysis for Large Software Systems

dschneid
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 271
Registriert: 14. Dez 2009 00:56

Determining the Object on which a Method is Invoked

Beitrag von dschneid »

Hi all,

we encountered a problem while trying to implement the translation of flow abstractions from the caller to the callee: We were unable to find a way to determine which object a method is being invoked on, i.e., what will be the this pointer during the execution of the called method. Our first idea was that it may be the zeroth argument of the call, but this doesn't seem to be the case.

Any ideas?

Benutzeravatar
mmi1991
Computerversteher
Computerversteher
Beiträge: 349
Registriert: 20. Okt 2011 18:46
Wohnort: Hattersheim

Re: Determining the Object on which a Method is Invoked

Beitrag von mmi1991 »

Hi there,
you will have to determine whether your Invoke Expression is static or not. If the expression is a JVirtualInvokeExpr, you can cast it to JVirtualInvokeExpr and call the getBase()-Method to get your class instance. Similar to JSpecialInvokeExpr and JInterfaceInvokeExpr.

Good luck ;)
Ophasentutor SoSe 2014, WiSe 2015/16
Alle Angaben wie immer ohne Gewähr

Benutzeravatar
ericbodden
Moderator
Moderator
Beiträge: 243
Registriert: 5. Apr 2010 19:06

Re: Determining the Object on which a Method is Invoked

Beitrag von ericbodden »

Thanks mmi1991 for responding to this. Yes, this is indeed the right way. But actually it's even a bit simple: all of JVirtualInvokeExpr, JSpecialInvokeExpr and JInterfaceInvokeExpr implement the InstanceInvokeExpr interface, which has a getBase() method. This returns the base variable, which at runtime will point to the receiver, i.e., the "this" object.

dschneid does that solve your problem?

Cheers,
Eric
-- Eric

dschneid
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 271
Registriert: 14. Dez 2009 00:56

Re: Determining the Object on which a Method is Invoked

Beitrag von dschneid »

Yes, it does. Thanks!

Antworten

Zurück zu „Automated Code Analysis for Large Software Systems“