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

Re: Line number resolving



Eric Bodden wrote:
> internally and the one which are in the bytecode table. So is it
> possible to get a 1 to 1 mapping from let's say a method call "A.foo()"
> in the sourcecode to the appropriate Jimple line ? And is it then
> possible to change the type propagation algorithm in such a way that it
> will pass you the static type of an object for this line?

This should work. Some sample code that I've used to do this is below.

Of course the mapping is not 1:1 but 1:N as one source line can map to
any number of bytecodes or Jimple statements.

Cheers,
-Archie

__________________________________________________________________________
Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com

    // Attach line numbers to units
    HashMap lineNumberMap = new HashMap();
    Integer lastLineNumber = new Integer(0);
    for (Iterator i = body.getUnits().iterator(); i.hasNext(); ) {
	    Unit unit = (Unit)i.next();
	    for (Iterator j = unit.getTags().iterator(); j.hasNext(); ) {
		    Tag tag = (Tag)j.next();
		    if (tag instanceof LineNumberTag) {
			    byte[] value = tag.getValue();
			    int lineNumber = ((value[0] & 0xff) << 8)
				| (value[1] & 0xff);
			    if (lineNumber != lastLineNumber.intValue())
				    lastLineNumber = new Integer(lineNumber);
		    }
		    lineNumberMap.put(unit, lastLineNumber);
	    }
    }