## Identification of the local "this"

alexandergreat524
Neuling
Beiträge: 8
Registriert: 6. Nov 2014 18:38

### Identification of the local "this"

Taking calling a constructor like public Foo (int a, int b) {this.a = a, this.b = b} into account, what could we do if we want to let our analysis know that "this" is really corresponding to what object with the certain class type? (InstanceFieldRef)(((AssignStmt) unit).getLeftOp()).getBase() does not help, does it? Because it shows that this = null after I have done that.

Andreas Wittmann
Neuling
Beiträge: 7
Registriert: 15. Okt 2014 23:52

### Re: Identification of the local "this"

What we are doing is first to check if the callee is static. Because in a static method we dont even have 'this'

Code: Alles auswählen

if (ie instanceof InstanceInvokeExpr) {
Value instance = ((InstanceInvokeExpr) ie).getBase();
FlowAbstraction thisLocalFA = new FlowAbstraction(calledMethod
.getActiveBody().getThisLocal());
Where instance is pythagoras for something like pythagoras.getSquaredSide and getThisLocal refers to "this" inside the method. After that we map everything to this, for example pyth.a, pyth.b, pyth.c have to get assigned to this.a, this.b, this.c where this. is the thisLocal from the calledMethod.

To get this for invoke

Code: Alles auswählen

if (!(calledMethod.isStatic())) {

InvokeExpr iv = ((Stmt) unit).getInvokeExpr();
if (iv instanceof SpecialInvokeExpr) {
SpecialInvokeExpr sexpr = (SpecialInvokeExpr) ((Stmt) unit)
.getInvokeExpr();
Local thisLocal = (Local) sexpr.getBase();

if (entry.getKey().getLocal() == calledMethod
.getActiveBody().getThisLocal()) {


Same for the exit