[Soot-list] Synthesizing a constructor

Eric Bodden eric.bodden at ec-spride.de
Fri Jul 27 03:59:02 EDT 2012


Hello.

> And I want it to become:
> private MyBean theBean = new MyBean();
>
> First question:
> Do I need to make this initialization inside a constructor? (I am
> guessing it is the case, and that the initialization part here is just
> syntactic sugar).

That is correct.

> Second question:
> If the constructor doesn't have a body yet, how do I create one? Which
> statements are required? (my guess: super() and then the initialization)

Jimple.v().newBody(..)

Then you create an "invokespecial" to <init> on the super class. This
amounts to the super-call. The rest is then normal Jimple code.

> Third question:
> Are there any utility methods in Soot to do this simply?

I am not sure. Search for <init>, that may help. Also you can look at
coffi or the JastAdd frontend to see how they generate the implicit
default constructors.

Cheers,
Eric


More information about the Soot-list mailing list