Revert "fixes to getting source positions from JVML"
This reverts commit 9e35099326
.
This commit is contained in:
parent
9e35099326
commit
619df0a83d
|
@ -10,31 +10,27 @@
|
|||
*****************************************************************************/
|
||||
package com.ibm.wala.cast.js.translator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.ibm.wala.cast.ir.translator.RewritingTranslatorToCAst;
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.impl.CAstImpl;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.CopyKey;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.RewriteContext;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
|
||||
import com.ibm.wala.classLoader.SourceFileModule;
|
||||
import com.ibm.wala.classLoader.SourceModule;
|
||||
|
||||
public class CAstRhinoTranslator extends RewritingTranslatorToCAst implements TranslatorToCAst {
|
||||
public class CAstRhinoTranslator implements TranslatorToCAst {
|
||||
private final List<CAstRewriterFactory> rewriters = new LinkedList<CAstRewriterFactory>();
|
||||
private final SourceModule M;
|
||||
private final boolean replicateForDoLoops;
|
||||
|
||||
private static String getName(SourceModule M) {
|
||||
if (M instanceof SourceFileModule) {
|
||||
return ((SourceFileModule) M).getClassName();
|
||||
} else {
|
||||
return M.getName();
|
||||
}
|
||||
}
|
||||
|
||||
public CAstRhinoTranslator(SourceModule M, boolean replicateForDoLoops) {
|
||||
super(M, new RhinoToAstTranslator(new CAstImpl(), M, getName(M), replicateForDoLoops));
|
||||
this.M = M;
|
||||
this.replicateForDoLoops = replicateForDoLoops;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,4 +41,20 @@ public class CAstRhinoTranslator extends RewritingTranslatorToCAst implements Tr
|
|||
rewriters.add(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CAstEntity translateToCAst() throws IOException, Error {
|
||||
String N;
|
||||
if (M instanceof SourceFileModule) {
|
||||
N = ((SourceFileModule) M).getClassName();
|
||||
} else {
|
||||
N = M.getName();
|
||||
}
|
||||
|
||||
CAstImpl Ast = new CAstImpl();
|
||||
CAstEntity entity = new RhinoToAstTranslator(Ast, M, N, replicateForDoLoops).translateToCAst();
|
||||
for(CAstRewriterFactory rwf : rewriters)
|
||||
entity = rwf.createCAstRewriter(Ast).rewrite(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -108,9 +108,6 @@ import com.ibm.wala.cast.tree.CAstType;
|
|||
import com.ibm.wala.cast.tree.impl.CAstOperator;
|
||||
import com.ibm.wala.cast.tree.impl.CAstSymbolImpl;
|
||||
import com.ibm.wala.cast.tree.impl.RangePosition;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.CopyKey;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.RewriteContext;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
|
||||
import com.ibm.wala.cast.tree.visit.CAstVisitor;
|
||||
import com.ibm.wala.cast.util.CAstPattern;
|
||||
import com.ibm.wala.classLoader.SourceModule;
|
||||
|
@ -120,7 +117,7 @@ import com.ibm.wala.util.collections.HashSetFactory;
|
|||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.warnings.Warning;
|
||||
|
||||
public class RhinoToAstTranslator implements TranslatorToCAst {
|
||||
public class RhinoToAstTranslator {
|
||||
|
||||
/**
|
||||
* a dummy name to use for standard function calls, only used to distinguish
|
||||
|
@ -2442,9 +2439,4 @@ private CAstNode[] walkChildren(final Node n, WalkContext context) {
|
|||
this.doLoopTranslator = new DoLoopTranslator(replicateForDoLoops, Ast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <C extends RewriteContext<K>, K extends CopyKey<K>> void addRewriter(CAstRewriterFactory<C, K> factory, boolean prepend) {
|
||||
assert false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.impl.CAstImpl;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.CopyKey;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.RewriteContext;
|
||||
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
|
||||
public class RewritingTranslatorToCAst implements TranslatorToCAst {
|
||||
private final List<CAstRewriterFactory> rewriters = new LinkedList<CAstRewriterFactory>();
|
||||
protected final ModuleEntry M;
|
||||
private final TranslatorToCAst base;
|
||||
|
||||
public RewritingTranslatorToCAst(ModuleEntry m2, TranslatorToCAst base) {
|
||||
this.M = m2;
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <C extends RewriteContext<K>, K extends CopyKey<K>> void addRewriter(CAstRewriterFactory<C, K> factory, boolean prepend) {
|
||||
if(prepend)
|
||||
rewriters.add(0, factory);
|
||||
else
|
||||
rewriters.add(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CAstEntity translateToCAst() throws IOException, Error {
|
||||
CAstImpl Ast = new CAstImpl();
|
||||
CAstEntity entity = base.translateToCAst();
|
||||
for(CAstRewriterFactory rwf : rewriters)
|
||||
entity = rwf.createCAstRewriter(Ast).rewrite(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
|
@ -372,7 +372,7 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
|
|||
|
||||
@Override
|
||||
public CAstSourcePositionMap newPos() {
|
||||
if (theSource == null && pos != null)
|
||||
if (theSource == null)
|
||||
theSource = copySource(nodes, pos);
|
||||
return theSource;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.classLoader;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import com.ibm.wala.ipa.callgraph.ContextItem;
|
||||
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
||||
import com.ibm.wala.types.Descriptor;
|
||||
|
|
|
@ -11,11 +11,8 @@
|
|||
package com.ibm.wala.classLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.ibm.wala.classLoader.ShrikeClass.GetReader;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.shrikeBT.Decoder;
|
||||
import com.ibm.wala.shrikeBT.IndirectionData;
|
||||
|
@ -30,7 +27,6 @@ import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
|||
import com.ibm.wala.shrikeCT.LineNumberTableReader;
|
||||
import com.ibm.wala.shrikeCT.LocalVariableTableReader;
|
||||
import com.ibm.wala.shrikeCT.SignatureReader;
|
||||
import com.ibm.wala.shrikeCT.SourceFileReader;
|
||||
import com.ibm.wala.shrikeCT.SourcePositionTableReader;
|
||||
import com.ibm.wala.shrikeCT.SourcePositionTableReader.Position;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
|
@ -153,18 +149,17 @@ public final class ShrikeCTMethod extends ShrikeBTMethod implements IBytecodeMet
|
|||
/** BEGIN Custom change: precise positions */
|
||||
|
||||
private static final class SPos implements SourcePosition {
|
||||
String fileName;
|
||||
|
||||
final int firstLine;
|
||||
final int lastLine;
|
||||
final int firstCol;
|
||||
final int lastCol;
|
||||
|
||||
private SPos(String fileName, int firstLine, int lastLine, int firstCol, int lastCol) {
|
||||
private SPos(int firstLine, int lastLine, int firstCol, int lastCol) {
|
||||
this.firstLine = firstLine;
|
||||
this.lastLine = lastLine;
|
||||
this.firstCol = firstCol;
|
||||
this.lastCol = lastCol;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
|
||||
|
@ -220,8 +215,9 @@ public final class ShrikeCTMethod extends ShrikeBTMethod implements IBytecodeMet
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fileName + "(" + firstLine + "," + firstCol + "-" + lastLine + "," + lastCol + ")";
|
||||
return "(" + firstLine + "," + firstCol + "-" + lastLine + "," + lastCol + ")";
|
||||
}
|
||||
|
||||
}
|
||||
/** END Custom change: precise positions */
|
||||
|
||||
|
@ -241,8 +237,7 @@ public final class ShrikeCTMethod extends ShrikeBTMethod implements IBytecodeMet
|
|||
|
||||
bcInfo.paramPositionMap = new SPos[getNumberOfParameters()];
|
||||
if (param != null) {
|
||||
String fileName = ((ShrikeClass)getDeclaringClass()).getSourceFileReader().getSourceFile();
|
||||
SPos paramPos = new SPos(fileName, param.firstLine, param.lastLine, param.firstCol, param.lastCol);
|
||||
SPos paramPos = new SPos(param.firstLine, param.lastLine, param.firstCol, param.lastCol);
|
||||
for (int i = 0; i < getNumberOfParameters(); i++) {
|
||||
bcInfo.paramPositionMap[i] = paramPos;
|
||||
}
|
||||
|
@ -260,15 +255,10 @@ public final class ShrikeCTMethod extends ShrikeBTMethod implements IBytecodeMet
|
|||
}
|
||||
|
||||
if (pos != null) {
|
||||
String sourceFile = null;
|
||||
SourceFileReader reader = ((ShrikeClass)getDeclaringClass()).getSourceFileReader();
|
||||
if (reader != null) {
|
||||
sourceFile = reader.getSourceFile();
|
||||
}
|
||||
bcInfo.positionMap = new SPos[pos.length];
|
||||
for (int i = 0; i < pos.length; i++) {
|
||||
Position p = pos[i];
|
||||
bcInfo.positionMap[i] = new SPos(sourceFile, p.firstLine, p.lastLine, p.firstCol, p.lastCol);
|
||||
bcInfo.positionMap[i] = new SPos(p.firstLine, p.lastLine, p.firstCol, p.lastCol);
|
||||
}
|
||||
}
|
||||
/** END Custom change: : precise bytecode positions */
|
||||
|
@ -339,38 +329,61 @@ public final class ShrikeCTMethod extends ShrikeBTMethod implements IBytecodeMet
|
|||
return ((ShrikeClass) getDeclaringClass()).getReader();
|
||||
}
|
||||
|
||||
private <T> T getReader(String attrName, GetReader<T> reader) {
|
||||
private CodeReader getCodeReader() {
|
||||
ClassReader.AttrIterator iter = new AttrIterator();
|
||||
getClassReader().initMethodAttributeIterator(shrikeMethodIndex, iter);
|
||||
|
||||
return ((ShrikeClass)getDeclaringClass()).getReader(iter, attrName, reader);
|
||||
// search for the code attribute
|
||||
CodeReader code = null;
|
||||
try {
|
||||
for (; iter.isValid(); iter.advance()) {
|
||||
if (iter.getName().equals("Code")) {
|
||||
code = new CodeReader(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (InvalidClassFileException e) {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
private CodeReader getCodeReader() {
|
||||
return getReader("Code", new GetReader<CodeReader>() {
|
||||
@Override
|
||||
public CodeReader getReader(AttrIterator iter) throws InvalidClassFileException {
|
||||
return new CodeReader(iter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ExceptionsReader getExceptionReader() {
|
||||
return getReader("Exceptions", new GetReader<ExceptionsReader>() {
|
||||
@Override
|
||||
public ExceptionsReader getReader(AttrIterator iter) throws InvalidClassFileException {
|
||||
return new ExceptionsReader(iter);
|
||||
ClassReader.AttrIterator iter = new AttrIterator();
|
||||
getClassReader().initMethodAttributeIterator(shrikeMethodIndex, iter);
|
||||
|
||||
// search for the desired attribute
|
||||
ExceptionsReader result = null;
|
||||
try {
|
||||
for (; iter.isValid(); iter.advance()) {
|
||||
if (iter.getName().equals("Exceptions")) {
|
||||
result = new ExceptionsReader(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (InvalidClassFileException e) {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private SignatureReader getSignatureReader() {
|
||||
return getReader("Signature", new GetReader<SignatureReader>() {
|
||||
@Override
|
||||
public SignatureReader getReader(AttrIterator iter) throws InvalidClassFileException {
|
||||
return new SignatureReader(iter);
|
||||
ClassReader.AttrIterator iter = new AttrIterator();
|
||||
getClassReader().initMethodAttributeIterator(shrikeMethodIndex, iter);
|
||||
|
||||
// search for the desired attribute
|
||||
SignatureReader result = null;
|
||||
try {
|
||||
for (; iter.isValid(); iter.advance()) {
|
||||
if (iter.getName().equals("Signature")) {
|
||||
result = new SignatureReader(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (InvalidClassFileException e) {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private AnnotationsReader getAnnotationsReader(AnnotationType type) {
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.ibm.wala.shrikeCT.ClassReader.AttrIterator;
|
|||
import com.ibm.wala.shrikeCT.InnerClassesReader;
|
||||
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
||||
import com.ibm.wala.shrikeCT.SignatureReader;
|
||||
import com.ibm.wala.shrikeCT.SourceFileReader;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.types.annotations.Annotation;
|
||||
|
@ -270,24 +269,6 @@ public final class ShrikeClass extends JVMClass<IClassLoader> {
|
|||
: AnnotationType.RuntimeVisibleAnnotations, attrs);
|
||||
}
|
||||
|
||||
interface GetReader<T> {
|
||||
T getReader(ClassReader.AttrIterator iter) throws InvalidClassFileException;
|
||||
}
|
||||
|
||||
<T> T getReader(ClassReader.AttrIterator iter, String attrName, GetReader<T> reader) {
|
||||
// search for the attribute
|
||||
try {
|
||||
for (; iter.isValid(); iter.advance()) {
|
||||
if (iter.getName().equals(attrName)) {
|
||||
return reader.getReader(iter);
|
||||
}
|
||||
}
|
||||
} catch (InvalidClassFileException e) {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private InnerClassesReader getInnerClassesReader() throws InvalidClassFileException {
|
||||
ClassReader r = reader.get();
|
||||
ClassReader.AttrIterator attrs = new ClassReader.AttrIterator();
|
||||
|
@ -308,18 +289,6 @@ public final class ShrikeClass extends JVMClass<IClassLoader> {
|
|||
return result;
|
||||
}
|
||||
|
||||
SourceFileReader getSourceFileReader() {
|
||||
ClassReader.AttrIterator attrs = new ClassReader.AttrIterator();
|
||||
getReader().initClassAttributeIterator(attrs);
|
||||
|
||||
return getReader(attrs, "SourceFile", new GetReader<SourceFileReader>() {
|
||||
@Override
|
||||
public SourceFileReader getReader(AttrIterator iter) throws InvalidClassFileException {
|
||||
return new SourceFileReader(iter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private AnnotationsReader getFieldAnnotationsReader(boolean runtimeInvisible, int fieldIndex) throws InvalidClassFileException {
|
||||
ClassReader.AttrIterator iter = new AttrIterator();
|
||||
reader.get().initFieldAttributeIterator(fieldIndex, iter);
|
||||
|
|
|
@ -29,8 +29,4 @@ public final class SourceFileReader extends AttributeReader {
|
|||
public int getSourceFileCPIndex() {
|
||||
return cr.getUShort(attr + 6);
|
||||
}
|
||||
|
||||
public String getSourceFile() throws IllegalArgumentException, InvalidClassFileException {
|
||||
return cr.getCP().getCPUtf8(getSourceFileCPIndex());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue