[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JAssignStmt with reference to a class field as right-hand-side



You need an InstanceFieldRef.

To create this, you need the receiver Local that you say you have, and
the SootField.

You can get the SootField from the SootClass for MyType using the
getFieldByName() method or by searching the chain of fields yourself.

In general, a good place to start looking for how to create chunks of
Jimple is in the API doc for soot.jimple.Jimple, since it contains the
factory methods of all the various chunks of Jimple.
http://www.sable.mcgill.ca/soot/doc/soot/jimple/Jimple.html

Ondrej

On Fri, Feb 20, 2004 at 04:38:07PM +0100, Emil Slusanschi wrote:
> Hi,
> 
> I want to know how can I generate a JAssignStmt that contains a 
> reference to a class field as the right-hand-side.
> 
> I have a class:
> 
> class MyType{
>      public double value;
>      public double stress;
> 
>      public MyType(){
>           super();
>           return;
>      }
> }
> 
> and I want to generate in Jimple something like
> 
> $d0 = r0.<MyType: double value>
> $d1 = r0.<MyType: double stress>
> 
> where $d0 and $d1 are locals (doubles) and r0 is of type MyType. I have 
> all the locals in hand, that is $d0, $d1 and r0 but how do I get from r0 
> the reference to his fields?
> 
> I have something like this in my Body Transformer:
> 
> 
> derivUnits.insertAfter(Jimple.v().newAssignStmt(local_for_$d0,local_for_r0.???,stmt);
> 
> derivUnits.insertAfter(Jimple.v().newAssignStmt(local_for_$d1,local_for_r0.???,stmt);
> 
> and the problems are obvious the ??? ;-)
> 
> Any ideeas? And yes, where in the docs should I look in the future to 
> find these kind of infos?
> 
> Thanks,
> 
> Emil
> 
>