Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: java - soot issue...counting the jimple line numbers??

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java - soot issue...counting the jimple line numbers??

    Hello everybody,

    I am trying to write a program that takes a java class file...converts it into corresponding jimple code and prints out the jimple statements along with their line numbers. Then I would like to pick out those lines from the jimple code which have a "virtual invoke". The code that I have written looks like below:

    import soot.*;
    import java.util.*;
    import soot.util.*;
    import soot.jimple.Stmt;
    import soot.tagkit.LineNumberTag;
    import soot.baf.*;
    import java.io.*;
     
    public class GetStmts4 extends BodyTransformer implements RetInst
    {
        private static GetStmts4 instance = new GetStmts4();
     
        private GetStmts4() {};
     
        public static GetStmts4 v()
        {
        return instance;
        }
     
        public static void main(String args[])
        {
        soot.options.Options.v().set_keep_line_number(true);
        //soot.options.Options.v().set_whole_program(true);
        //soot.options.Options.v().setPhaseOption("cg","verbose:true");
            PackManager.v().getPack("jtp").add(new Transform ("jtp.annotexample",GetStmts4.v()));
        soot.Main.main(args);
     
        }
     
        protected void internalTransform(Body b, String phaseName, Map options)
        {
        int linenum = 0;
        int count = 0;
        int array[] = new int[20];
        PatchingChain units = b.getUnits();
        Iterator unitsIt = units.iterator();
     
        while(unitsIt.hasNext())
            {
            Unit unit = (Unit)unitsIt.next();
            LineNumberTag tag = (LineNumberTag) unit.getTag("LineNumberTag");
            int index = rt.getIndex();  //to get the index of the jimple line??is this correct??
            System.out.println("Index is :" + index);
           System.out.println(unit);
            if (tag != null)
     
    //wrote the following piece of code but it gives me the line number in the source code...and not the jimple line number
                {
                System.out.println("java line number:"+tag.getLineNumber());
                //System.out.println("tag name:"+tag.getName());
                String string = unit.toString();
                if(string.matches("\\s*.*virtualinvoke.*"))
                    {
                    count++;
                    System.out.println("line number with virtualinvoke:"+tag.getLineNumber());
                    array[count] = tag.getLineNumber();
                    System.out.println("the " +count+ " element in array is : " +array[count]);
                    }
                }
            }
        for(int k = 1;k <= count; k++)
            {
            System.out.println(array[k]);
            }
          }
       }

    I am getting the following error:
    GetStmts4.java:9: GetStmts4 is not abstract and does not override abstract method setIndex(int) in soot.baf.RetInst
    public class GetStmts4 extends BodyTransformer implements RetInst
    ^

    Would be really grateful if somebody could help me out with this.
    Thanks!!!


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: java - soot issue...counting the jimple line numbers??

    Cross posted
    Java Programming - java-soot issue - jimple line numbers??

    db

Similar Threads

  1. How To: Add line numbers to your JTextArea
    By Freaky Chris in forum Java Swing Tutorials
    Replies: 11
    Last Post: October 15th, 2013, 10:22 PM
  2. counting words of a text file
    By maybach230 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: May 6th, 2010, 03:40 PM
  3. Replies: 2
    Last Post: February 19th, 2010, 08:10 AM
  4. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM