Two fixes for mapping source positions to IR
1: get the right position for methods from the JDT AST 2: more seriously, there was a nasty bug in how source positions got mapped in unwound code: mappings were wrong for instructions that were the result of duplicating code to replicate unwind handling in exceptional and non-local exits.
This commit is contained in:
parent
931e2b8b4b
commit
5f0b0ea956
|
@ -5,6 +5,7 @@ import java.util.Set;
|
|||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
|
||||
import com.ibm.wala.cast.tree.CAstSymbol;
|
||||
import com.ibm.wala.cast.tree.visit.CAstVisitor;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
|
@ -41,6 +42,10 @@ public class ExposedNamesCollector extends CAstVisitor<ExposedNamesCollector.Ent
|
|||
return top;
|
||||
}
|
||||
|
||||
public CAstSourcePositionMap getSourceMap() {
|
||||
return top.getSourceMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Map;
|
|||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
|
||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
||||
import com.ibm.wala.cast.util.CAstPrinter;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
|
@ -30,10 +31,14 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
|
|||
|
||||
private Position currentPosition;
|
||||
|
||||
protected Position getCurrentPosition() {
|
||||
public Position getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
||||
|
||||
protected CAstVisitor() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface represents a visitor-specific context. All
|
||||
* it knows is how to get its top-level entity. It is expected
|
||||
|
@ -43,7 +48,10 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
|
|||
* @author Igor Peshansky
|
||||
*/
|
||||
public interface Context {
|
||||
|
||||
CAstEntity top();
|
||||
|
||||
CAstSourcePositionMap getSourceMap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -406,8 +414,8 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
|
|||
*/
|
||||
public final void visit(final CAstNode n, C context, CAstVisitor<C> visitor) {
|
||||
Position restore = currentPosition;
|
||||
if (context.top().getSourceMap() != null) {
|
||||
Position p = context.top().getSourceMap().getPosition(n);
|
||||
if (context.getSourceMap() != null) {
|
||||
Position p = context.getSourceMap().getPosition(n);
|
||||
if (p != null) {
|
||||
currentPosition = p;
|
||||
}
|
||||
|
@ -939,7 +947,7 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
|
|||
System.err.println(("cannot handle assign to kind " + n.getKind()));
|
||||
throw new UnsupportedOperationException(
|
||||
"cannot handle assignment: " +
|
||||
CAstPrinter.print(a, context.top().getSourceMap()));
|
||||
CAstPrinter.print(a, context.getSourceMap()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
|
||||
import com.ibm.wala.cast.tree.visit.CAstVisitor;
|
||||
import com.ibm.wala.cast.tree.visit.CAstVisitor.Context;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
|
@ -394,6 +395,9 @@ public class CAstPattern {
|
|||
public CAstEntity top() {
|
||||
return e;
|
||||
}
|
||||
public CAstSourcePositionMap getSourceMap() {
|
||||
return e.getSourceMap();
|
||||
}
|
||||
}, v);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -914,7 +914,7 @@ public class JDTJava2CAstTranslator {
|
|||
}
|
||||
|
||||
public CAstSourcePositionMap.Position getPosition() {
|
||||
return getSourceMap().getPosition(fAst);
|
||||
return fDecl==null? getSourceMap().getPosition(fAst): makePosition(fDecl);
|
||||
}
|
||||
|
||||
public CAstNodeTypeMap getNodeTypeMap() {
|
||||
|
|
Loading…
Reference in New Issue