[Soot-list] A BUG about JimpleConstructorFolder and Line number or any options I did not turn on?

Chris Pickett chris.pickett at mail.mcgill.ca
Mon Apr 9 20:37:58 EDT 2007


Hi Peng,

Please try again---you need to use the "attach" button with a .patch 
file, not copy and paste the contents of the diff output.  Line wraps 
are problematic for people that want to handle patches.

Thanks a lot,
Chris

Peng Li wrote:
> HI Chris,
> This is the diff result,
> 
> Cheers
> Peng
> 
> ------------------
> $ diff -u JimpleConstructorFolder.java  
> ModifiedJimpleConstructorFolder.java
> --- JimpleConstructorFolder.java        Mon Apr  9 17:28:49 2007
> +++ ModifiedJimpleConstructorFolder.java        Mon Apr  9 17:28:40 2007
> @@ -1,16 +1,17 @@
> -package soot.jimple.toolkits.base;
> import soot.options.*;
> 
> import soot.*;
> import soot.toolkits.scalar.*;
> import soot.jimple.*;
> +import soot.jimple.internal.JNewExpr;
> import soot.toolkits.graph.*;
> import soot.grimp.*;
> import soot.util.*;
> import java.util.*;
> +
> import soot.tagkit.*;
> 
> -public class JimpleConstructorFolder extends BodyTransformer
> +public class ModifiedJimpleConstructorFolder extends BodyTransformer
> {
>     //public JimpleConstructorFolder( Singletons.Global g ) {}
>     //public static JimpleConstructorFolder v() { return
> G.v().JimpleConstructorFolder(); }
> @@ -17,13 +18,15 @@
> 
>     /** This method pushes all newExpr down to be the stmt directly
> before every
>      * invoke of the init */
> +       static Vector NewOldHashCode = new Vector();
> +
>     public void internalTransform(Body b, String phaseName, Map options)
>     {
>         JimpleBody body = (JimpleBody)b;
> -
> -        if(Options.v().verbose())
> +        ClassMember cm = body.getMethod();
> +        /*if(Options.v().verbose())
>             G.v().out.println("[" + body.getMethod().getName() +
> -                "] Folding Jimple constructors...");
> +                "] Folding Jimple constructors...");*/
> 
>         Chain units = body.getUnits();
>         List stmtList = new ArrayList();
> @@ -61,15 +64,25 @@
>             //check if very next statement is invoke -->
>             //this indicates there is no control flow between
>             //new and invoke and should do nothing
> +
>             if (nextStmtIt.hasNext()){
>                 Stmt next = (Stmt)nextStmtIt.next();
> -                if (next instanceof InvokeStmt){
> +                if (next instanceof InvokeStmt)
> +                {
>                     InvokeStmt invoke = (InvokeStmt)next;
> 
>                     if (invoke.getInvokeExpr() instanceof 
> SpecialInvokeExpr &&
> -
> invoke.getInvokeExpr().getMethodRef().name().equals(SootMethod.constructorName)) 
> 
> {
> +
> invoke.getInvokeExpr().getMethodRef().name().equals(SootMethod.constructorName)) 
> 
> +                    {
>                         SpecialInvokeExpr invokeExpr =
> (SpecialInvokeExpr)invoke.getInvokeExpr();
> -                        if (invokeExpr.getBase() == lhs){
> +                        if (invokeExpr.getBase() == lhs)
> +                        {
> +                            NewExprWithHashCode exprcode = new
> NewExprWithHashCode();
> +                            JNewExpr newexpr=(JNewExpr)
> ((AssignStmt)s).getRightOp();
> +
> exprcode.SetNewExprWithHashCode((AssignStmt)s, newexpr.hashCode(),
> newexpr.hashCode(), invoke, cm.getDeclaringClass().toString(),
> body.getMethod(), getLineNumber(s));
> +
> +                            // System.out.println
> ("******"+newexpr.hashCode()+"  "+newexpr +"*****"+s.hashCode()+"
> "+s);
> +                            NewOldHashCode.add(exprcode);
>                             continue;
>                         }
>                     }
> @@ -91,18 +104,29 @@
>                   lhs != ((SpecialInvokeExpr)is.getInvokeExpr()).getBase())
>                     continue;
> 
> -             //make a new one here
> -              AssignStmt constructStmt = Jimple.v().newAssignStmt
> -                (((DefinitionStmt)s).getLeftOp(),
> ((DefinitionStmt)s).getRightOp());
> -              constructStmt.setRightOp
> -                (Jimple.v().newNewExpr
> -                 (((NewExpr)rhs).getBaseType()));
> +             //make a new stmt here
> +              AssignStmt constructStmt =
> Jimple.v().newAssignStmt(((DefinitionStmt)s).getLeftOp(),
> ((DefinitionStmt)s).getRightOp());
> +              LineNumberTag tag =
> (LineNumberTag)s.getTag("LineNumberTag");  // add
> +              constructStmt.addTag(tag);
> +              
> constructStmt.setRightOp(Jimple.v().newNewExpr(((NewExpr)rhs).getBaseType())); 
> 
>               MadeNewInvokeExpr = true;
> 
> +
>               // redirect jumps
>               use.redirectJumpsToThisTo(constructStmt);
>               // insert new one here
>               units.insertBefore(constructStmt, use);
> +
> +              NewExprWithHashCode exprcode1 = new NewExprWithHashCode();
> +              JNewExpr newexpr1 = (JNewExpr) constructStmt.getRightOp();
> +
> +              JNewExpr newexpr2=(JNewExpr) ((AssignStmt)s).getRightOp();
> +              exprcode1.SetNewExprWithHashCode(constructStmt,
> newexpr2.hashCode(), newexpr1.hashCode(), is,
> cm.getDeclaringClass().toString(), body.getMethod(),
> getLineNumber(constructStmt));
> +              System.out.println(getLineNumber(constructStmt));
> +              //System.out.println ("******"+jjj.hashCode()+"  "+jjj
> +"*****"+constructStmt.hashCode()+"  "+constructStmt);
> +              NewOldHashCode.add(exprcode1);
> +
> +
>               if (s.hasTag("SourceLnPosTag")){
> 
> constructStmt.addTag((SourceLnPosTag)s.getTag("SourceLnPosTag"));
>               }
> @@ -113,4 +137,17 @@
>             }
>         }
>     }
> +
> +       private static int getLineNumber(Stmt s) {
> +               Iterator ti = s.getTags().iterator();
> +               while (ti.hasNext()) {
> +                       Object o = ti.next();
> +                       if (o instanceof LineNumberTag)
> +                       {
> +                               LineNumberTag linetag = (LineNumberTag) o;
> +                               return linetag.getLineNumber();
> +                       }
> +               }
> +               return -1;
> +       }
> }


More information about the Soot-list mailing list