[Soot-list] visitor for Jimple IR

Sergio Ferrero sferrero at ensoftcorp.com
Fri Jun 28 09:32:27 EDT 2013


Hello Marc-André,

Thanks for the reply.

Let me first tell you about my use case.
I'm working on a project ni which I'm extending the JimpleEditor to provide
some analysis based on the selection in the editor.
So, for a given position/range in the editor I need to get the
corresponding in-memory representation of the Jimple construct (e.g.
JGtExpr, StaticInvokeExpr, JAssignStmt, JIfStmt, etc)

Therefore, I'd like to associate specific source correspondence (SC) to
those objects in the format of offset and length.
First I looked at a few objects and I found they implemented Host (e.g.
JAssignStmt) so I thought I could add SC as a Tag.
However, I found some of them do not implement Host, e.g. JGtExpr.

So, on one side I have Host Jimple classes for which I can assign SC but
cannot use a walker, and on the other side I have Switchable Jimple
 classes for which I can use a walker but have no way to attach SC as a Tag.

I'm new to Soot and I think I'm not tackling the problem in the right way
so any comments you might have will be greatly appreciated.

It seems to me that I should use the classes specific to the Jimple
representation (Switchable). I could associate SC in some other way (could
be a HashMap where keys are Jimple objects). However, I thought I could use
SootClass and similar objects since that's what Parse.parse() returns.


Thanks in advance
Sergio

P.S. could you tell me where I can look to find more information about the
annotations that can give the source file and the line number (with
restrictions)

For that, I need to find a corresponding Jimple object (assignment,
variable, method call, etc)


On Thu, Jun 27, 2013 at 8:29 PM, Marc-André Laverdière-Papineau <
marc-andre.laverdiere-papineau at polymtl.ca> wrote:

> Hello,
>
> Two things
>
> 1) When it comes to source correspondence information, there are some
> annotations that can give the source file and the line number (with
> restrictions). So please make sure you are not reinventing the wheel :)
>
> 2) About the visitor, there are a few concerns to keep in mind
> a) SootClass, SootField, etc. are objects that do not depend on the IR
> that you are using. In some cases, they are even 'dandling', meaning
> that they don't have much information associated with them.
>
> b) If you are using Jimple, there is the Switch API. It looks like you
> already found it. You will quickly notice that the options are related
> to the Jimple statements in the method bodies. (see
> AbstractJimpleValueSwitch)
>
> That being said, I never had an issue with the lack of visitor in
> SootClass and its friends. Would you please tell us more about your use
> case?
>
>
> Marc-André Laverdière-Papineau
> Doctorant - PhD Candidate
>
> On 27/06/13 06:01 PM, Sergio Ferrero wrote:
> > Hello Al,
> >
> > Thanks for the reply.
> > I see Value and Stmt implement Switchable and thus they implement the
> > apply() method.
> > However, the Walker gives me a SootClass object which is the root of the
> > parsed Jimple file.
> > I was wondering whether there is a visitor that works for these objects:
> > SootClass, SootField, SootMethod, etc (that is all descendants of Host)
> >
> > Sergio
> >
> >
> >
> > On Thu, Jun 27, 2013 at 5:53 PM, Al <aaloanmiftah at yahoo.com
> > <mailto:aaloanmiftah at yahoo.com>> wrote:
> >
> >     Yes jimple does have a visitor pattern implementation. Look at the
> >     source tree and find value/statement visitor. Also each value and
> >     statement class has a apply method.
> >
> >     On Jun 27, 2013, at 3:05 PM, Sergio Ferrero <sferrero at ensoftcorp.com
> >     <mailto:sferrero at ensoftcorp.com>> wrote:
> >
> >     > Hello,
> >     >
> >     > I'd like to associate source correspondence information in the
> >     format of (offset, length) with an in-memory representation of a
> >     Jimple file.
> >     >
> >     > I'm using the Jimple parser to create a Jimple AST (classes in
> >     soot.jimple.parser.node) and then invoking Walker.java to create the
> >     in-memory representation of the jimple file (classes are in
> >     soot.jimple and soot.jimple.internal).
> >     >
> >     > It is to this in-memory representation I would like to attach
> >     source correspondence information.  I originally tried attaching the
> >     information to the Jimple AST generated by the Jimple parser, but
> >     this representation was missing some necessary information.
> >     >
> >     > Sable provides a visitor infrastructure to navigate the Jimple
> >     AST. Walker.java is based on this.
> >     > I'd like to know whether there is a similar visitor infrastructure
> >     for navigating the in-memory representation of the jimple file.
> >     >
> >     > Thanks in advance
> >     > -S
> >     >
> >     >
> >     > _______________________________________________
> >     > Soot-list mailing list
> >     > Soot-list at sable.mcgill.ca <mailto:Soot-list at sable.mcgill.ca>
> >     > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> >
> >
> >
> >
> > _______________________________________________
> > Soot-list mailing list
> > Soot-list at sable.mcgill.ca
> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> >
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20130628/fb497140/attachment.html 


More information about the Soot-list mailing list