Identification of the local "this"

Moderator: Implementing code analyses for large software systems

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

Identification of the local "this"

Beitrag von alexandergreat524 »

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
Beiträge: 7
Registriert: 15. Okt 2014 23:52

Re: Identification of the local "this"

Beitrag von Andreas Wittmann »

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
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)
				Local thisLocal = (Local) sexpr.getBase();

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

Same for the exit


Zurück zu „Implementing code analyses for large software systems (ICA)“