Skip to content

Commit

Permalink
finally (!) added some methods to easily access line and column numbe…
Browse files Browse the repository at this point in the history
…rs (only took 12 years)
  • Loading branch information
Eric Bodden committed Oct 31, 2013
1 parent 7bce809 commit 42b4ef1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/soot/SootMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -824,4 +824,23 @@ public final void setNumber(int number) {
public SootMethodRef makeRef() {
return Scene.v().makeMethodRef( declaringClass, name, parameterTypes, returnType, isStatic() );
}

@Override
public int getJavaSourceStartLineNumber() {
super.getJavaSourceStartLineNumber();
//search statements for first line number
if(line==-1 && hasActiveBody()) {
PatchingChain<Unit> unit = getActiveBody().getUnits();
for (Unit u : unit) {
int l = u.getJavaSourceStartLineNumber();
if(l>-1) {
//store l-1, as method header is usually one line before 1st statement
line = l-1;
break;
}
}
}
return line;
}

}
32 changes: 32 additions & 0 deletions src/soot/tagkit/AbstractHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
*/
public class AbstractHost implements Host
{

protected int line, col;

// avoid creating an empty list for each element, when it is not used
// use lazy instantiation (in addTag) instead
private final static List<Tag> emptyList = Collections.emptyList();
Expand Down Expand Up @@ -110,6 +113,35 @@ public void addAllTagsOf( Host h ) {
addTag( t );
}
}
public int getJavaSourceStartLineNumber() {
if(line==0) {
//get line from source
SourceLnPosTag tag = (SourceLnPosTag) getTag("SourceLnPosTag");
if(tag!=null) {
line = tag.startLn();
} else {
//get line from bytecode
LineNumberTag tag2 = (LineNumberTag) getTag("LineNumberTag");
if(tag2!=null) {
line = tag2.getLineNumber();
}
else line = -1;
}
}
return line;
}

public int getJavaSourceStartColumnNumber() {
if(col==0) {
//get line from source
SourceLnPosTag tag = (SourceLnPosTag) getTag("SourceLnPosTag");
if(tag!=null) {
col = tag.startPos();
}
else col = -1;
}
return col;
}
}


Expand Down
12 changes: 12 additions & 0 deletions src/soot/tagkit/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ public interface Host

/** Adds all the tags from h to this host. */
public void addAllTagsOf( Host h );

/**
* Returns the Java source line number if available.
* Returns -1 if not.
*/
public int getJavaSourceStartLineNumber();

/**
* Returns the Java source line column if available.
* Returns -1 if not.
*/
public int getJavaSourceStartColumnNumber();
}


Expand Down

0 comments on commit 42b4ef1

Please sign in to comment.