allow IR translator to give warnings and errors via the loader
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4125 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
1fa8b9b3cd
commit
67d26e74c5
|
@ -38,10 +38,10 @@
|
|||
package com.ibm.wala.cast.java.translator.jdt;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -59,6 +59,7 @@ import com.ibm.wala.cast.java.translator.SourceModuleTranslator;
|
|||
import com.ibm.wala.classLoader.DirectoryTreeModule;
|
||||
import com.ibm.wala.classLoader.JarFileModule;
|
||||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.ide.classloader.EclipseSourceFileModule;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
|
@ -111,7 +112,7 @@ public class JDTSourceModuleTranslator implements SourceModuleTranslator {
|
|||
* Project -> AST code from org.eclipse.jdt.core.tests.performance
|
||||
*/
|
||||
|
||||
public void loadAllSources(Set modules) {
|
||||
public void loadAllSources(Set<ModuleEntry> modules) {
|
||||
// TODO: we might need one AST (-> "Object" class) for all files.
|
||||
// TODO: group by project and send 'em in
|
||||
JDTJava2CAstTranslator jdt2cast = makeCAstTranslator();
|
||||
|
@ -120,27 +121,29 @@ public class JDTSourceModuleTranslator implements SourceModuleTranslator {
|
|||
System.out.println(modules);
|
||||
|
||||
// sort files into projects
|
||||
HashMap<IProject, ArrayList<ICompilationUnit>> projectsFiles = new HashMap<IProject, ArrayList<ICompilationUnit>>();
|
||||
for (Object m : modules) {
|
||||
assert m instanceof EclipseSourceFileModule : "Expecing EclipseSourceFileModule";
|
||||
Map<IProject, Map<ICompilationUnit,EclipseSourceFileModule>> projectsFiles = new HashMap<IProject, Map<ICompilationUnit,EclipseSourceFileModule>>();
|
||||
for (ModuleEntry m : modules) {
|
||||
assert m instanceof EclipseSourceFileModule : "Expecing EclipseSourceFileModule, not " + m.getClass();
|
||||
EclipseSourceFileModule entry = (EclipseSourceFileModule) m;
|
||||
IProject proj = entry.getIFile().getProject();
|
||||
if (!projectsFiles.containsKey(proj))
|
||||
projectsFiles.put(proj, new ArrayList<ICompilationUnit>());
|
||||
projectsFiles.get(proj).add(JavaCore.createCompilationUnitFrom(entry.getIFile()));
|
||||
if (!projectsFiles.containsKey(proj)) {
|
||||
projectsFiles.put(proj, new HashMap<ICompilationUnit,EclipseSourceFileModule>());
|
||||
}
|
||||
projectsFiles.get(proj).put(JavaCore.createCompilationUnitFrom(entry.getIFile()), entry);
|
||||
}
|
||||
|
||||
final ASTParser parser = ASTParser.newParser(AST.JLS3);
|
||||
|
||||
for (IProject proj : projectsFiles.keySet()) {
|
||||
parser.setProject(JavaCore.create(proj));
|
||||
for (final Map.Entry<IProject,Map<ICompilationUnit,EclipseSourceFileModule>> proj : projectsFiles.entrySet()) {
|
||||
parser.setProject(JavaCore.create(proj.getKey()));
|
||||
parser.setResolveBindings(true);
|
||||
ArrayList<ICompilationUnit> files = projectsFiles.get(proj);
|
||||
parser.createASTs(files.toArray(new ICompilationUnit[files.size()]), new String[0], new ASTRequestor() {
|
||||
|
||||
Set<ICompilationUnit> units = proj.getValue().keySet();
|
||||
parser.createASTs(units.toArray(new ICompilationUnit[units.size()]), new String[0], new ASTRequestor() {
|
||||
public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
|
||||
|
||||
try {
|
||||
java2ir.translate(ast, source.getUnderlyingResource().getLocation().toOSString());
|
||||
java2ir.translate(proj.getValue().get(source), ast, source.getUnderlyingResource().getLocation().toOSString());
|
||||
} catch (JavaModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.ibm.wala.cast.tree.impl.CAstImpl;
|
|||
import com.ibm.wala.cast.tree.impl.CAstRewriter;
|
||||
import com.ibm.wala.cast.tree.impl.CAstRewriterFactory;
|
||||
import com.ibm.wala.cast.util.CAstPrinter;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
|
||||
public class Java2IRTranslator {
|
||||
private final boolean DEBUG;
|
||||
|
@ -53,7 +54,7 @@ public class Java2IRTranslator {
|
|||
this.castRewriterFactory = castRewriterFactory;
|
||||
}
|
||||
|
||||
public void translate(Object ast, String N) {
|
||||
public void translate(ModuleEntry module, Object ast, String N) {
|
||||
CAstEntity ce = fSourceTranslator.translate(ast, N);
|
||||
|
||||
if (DEBUG) {
|
||||
|
@ -73,6 +74,6 @@ public class Java2IRTranslator {
|
|||
}
|
||||
}
|
||||
|
||||
new JavaCAst2IRTranslator(ce, fLoader).translate();
|
||||
new JavaCAst2IRTranslator(module, ce, fLoader).translate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.ibm.wala.cast.tree.visit.CAstVisitor;
|
|||
import com.ibm.wala.cfg.AbstractCFG;
|
||||
import com.ibm.wala.classLoader.CallSiteReference;
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.classLoader.NewSiteReference;
|
||||
import com.ibm.wala.ssa.SymbolTable;
|
||||
import com.ibm.wala.types.FieldReference;
|
||||
|
@ -41,14 +42,16 @@ import com.ibm.wala.util.debug.Assertions;
|
|||
|
||||
public class JavaCAst2IRTranslator extends AstTranslator {
|
||||
private final CAstEntity fSourceEntity;
|
||||
|
||||
public JavaCAst2IRTranslator(CAstEntity sourceFileEntity, JavaSourceLoaderImpl loader) {
|
||||
private final ModuleEntry module;
|
||||
|
||||
public JavaCAst2IRTranslator(ModuleEntry module, CAstEntity sourceFileEntity, JavaSourceLoaderImpl loader) {
|
||||
super(loader);
|
||||
fSourceEntity= sourceFileEntity;
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
public void translate() {
|
||||
translate(fSourceEntity, fSourceEntity.getName());
|
||||
translate(fSourceEntity, module);
|
||||
}
|
||||
|
||||
public CAstEntity sourceFileEntity() { return fSourceEntity; }
|
||||
|
|
|
@ -15,11 +15,13 @@ package com.ibm.wala.cast.java.translator;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
|
||||
/**
|
||||
* An interface used by the JavaSourceLoaderImpl to encapsulate the loading of source
|
||||
* entities on the compile-time classpath into the DOMO analysis infrastructure.
|
||||
* @author rfuhrer
|
||||
*/
|
||||
public interface SourceModuleTranslator {
|
||||
void loadAllSources(Set/*<ModuleEntry>*/ modules);
|
||||
void loadAllSources(Set<ModuleEntry> modules);
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ public class Util extends com.ibm.wala.cast.ipa.callgraph.Util {
|
|||
if (DEBUG){
|
||||
CAstPrinter.printTo(tree, new PrintWriter(System.err));
|
||||
}
|
||||
toIR.translate(tree, fileName);
|
||||
toIR.translate(tree, M);
|
||||
for(String name : names) {
|
||||
IClass fcls = cl.lookupClass(name, cha);
|
||||
cha.addClass(fcls);
|
||||
|
|
|
@ -27,11 +27,13 @@ public class Util {
|
|||
message.append("error in ").append(errorModule.getName()).append(":\n");
|
||||
message.append(w.toString()).append("\n");
|
||||
}
|
||||
message.append("end of front end errors\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message != null) {
|
||||
message.append("end of front end errors\n");
|
||||
}
|
||||
Assert.assertTrue(String.valueOf(message), message == null);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.ibm.wala.cast.ir.ssa.EachElementGetInstruction;
|
|||
import com.ibm.wala.cast.ir.ssa.EachElementHasNextInstruction;
|
||||
import com.ibm.wala.cast.loader.AstMethod.DebuggingInformation;
|
||||
import com.ibm.wala.cast.loader.AstMethod.LexicalInformation;
|
||||
import com.ibm.wala.cast.loader.CAstAbstractLoader;
|
||||
import com.ibm.wala.cast.tree.CAstControlFlowMap;
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
|
@ -56,6 +57,7 @@ import com.ibm.wala.cfg.AbstractCFG;
|
|||
import com.ibm.wala.cfg.IBasicBlock;
|
||||
import com.ibm.wala.classLoader.IClassLoader;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.shrikeBT.BinaryOpInstruction;
|
||||
import com.ibm.wala.shrikeBT.ConditionalBranchInstruction;
|
||||
import com.ibm.wala.shrikeBT.IBinaryOpInstruction;
|
||||
|
@ -80,6 +82,7 @@ import com.ibm.wala.util.intset.IntSet;
|
|||
import com.ibm.wala.util.intset.IntSetUtil;
|
||||
import com.ibm.wala.util.intset.MutableIntSet;
|
||||
import com.ibm.wala.util.strings.Atom;
|
||||
import com.ibm.wala.util.warnings.Warning;
|
||||
|
||||
/**
|
||||
* @author Julian Dolby TODO: document me.
|
||||
|
@ -1713,6 +1716,8 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
|
||||
public interface WalkContext extends Context {
|
||||
|
||||
ModuleEntry getModule();
|
||||
|
||||
String getName();
|
||||
|
||||
String file();
|
||||
|
@ -1743,6 +1748,11 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
DelegatingContext(WalkContext parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public ModuleEntry getModule() {
|
||||
return parent.getModule();
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return parent.getName();
|
||||
|
@ -3419,14 +3429,23 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean visitTry(CAstNode n, Context c, CAstVisitor visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
protected boolean visitTry(final CAstNode n, Context c, CAstVisitor visitor) {
|
||||
final WalkContext context = (WalkContext) c;
|
||||
boolean addSkipCatchGoto = false;
|
||||
visitor.visit(n.getChild(0), context, visitor);
|
||||
PreBasicBlock endOfTry = context.cfg().getCurrentBlock();
|
||||
|
||||
if (! hasIncomingEdges(n.getChild(1), context)) {
|
||||
System.err.println("note: dead catch block at " + getPosition(context.getSourceMap(), n.getChild(1)));
|
||||
if (loader instanceof CAstAbstractLoader) {
|
||||
((CAstAbstractLoader)loader).addMessage(
|
||||
context.getModule(),
|
||||
new Warning(Warning.MILD) {
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return "Dead catch block at " + getPosition(context.getSourceMap(), n.getChild(1));
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3654,16 +3673,20 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
|
||||
private final CAstEntity N;
|
||||
|
||||
private final String nm;
|
||||
private final ModuleEntry module;
|
||||
|
||||
public DefaultContext(AstTranslator t, CAstEntity N, String nm) {
|
||||
public DefaultContext(AstTranslator t, CAstEntity N, ModuleEntry module) {
|
||||
this.t = t;
|
||||
this.N = N;
|
||||
this.nm = nm;
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
public ModuleEntry getModule() {
|
||||
return module;
|
||||
}
|
||||
|
||||
public String file() {
|
||||
return nm;
|
||||
return module.getName();
|
||||
}
|
||||
|
||||
public CAstEntity top() {
|
||||
|
@ -3713,11 +3736,11 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
}
|
||||
};
|
||||
|
||||
public void translate(final CAstEntity N, final String nm) {
|
||||
public void translate(final CAstEntity N, final ModuleEntry module) {
|
||||
if (DEBUG_TOP)
|
||||
System.err.println(("translating " + nm));
|
||||
System.err.println(("translating " + module.getName()));
|
||||
// this.inlinedSourceMap = inlinedSourceMap;
|
||||
walkEntities(N, new DefaultContext(this, N, nm));
|
||||
walkEntities(N, new DefaultContext(this, N, module));
|
||||
}
|
||||
|
||||
private CAstSourcePositionMap inlinedSourceMap;
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
|
||||
public interface TranslatorToIR {
|
||||
|
||||
void translate(CAstEntity S, String N);
|
||||
void translate(CAstEntity S, ModuleEntry N);
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class CAstAbstractLoader implements IClassLoader {
|
|||
this(cha, null);
|
||||
}
|
||||
|
||||
protected void addMessage(ModuleEntry module, Warning message) {
|
||||
public void addMessage(ModuleEntry module, Warning message) {
|
||||
if (! errors.containsKey(module)) {
|
||||
errors.put(module, new HashSet<Warning>());
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
|||
public void init(final List<Module> modules) {
|
||||
final CAst ast = new CAstImpl();
|
||||
|
||||
final Set<Pair> topLevelEntities = new LinkedHashSet<Pair>();
|
||||
final Set<Pair<CAstEntity,ModuleEntry>> topLevelEntities = new LinkedHashSet<Pair<CAstEntity,ModuleEntry>>();
|
||||
|
||||
final TranslatorToIR xlatorToIR = initTranslator();
|
||||
|
||||
|
@ -94,7 +94,7 @@ public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
|||
if(DEBUG){
|
||||
CAstPrinter.printTo(fileEntity, new PrintWriter(System.err));
|
||||
}
|
||||
topLevelEntities.add(Pair.make(fileEntity, moduleEntry.getName()));
|
||||
topLevelEntities.add(Pair.make(fileEntity, moduleEntry));
|
||||
|
||||
} else {
|
||||
addMessage(moduleEntry, new Warning(Warning.SEVERE) {
|
||||
|
@ -139,14 +139,14 @@ public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
|||
}
|
||||
|
||||
private void init() {
|
||||
for (Iterator mes = modules.iterator(); mes.hasNext();) {
|
||||
init((Module) mes.next());
|
||||
for (Iterator<Module> mes = modules.iterator(); mes.hasNext();) {
|
||||
init(mes.next());
|
||||
}
|
||||
|
||||
for (Iterator tles = topLevelEntities.iterator(); tles.hasNext();) {
|
||||
Pair p = (Pair) tles.next();
|
||||
if (shouldTranslate((CAstEntity) p.fst)) {
|
||||
xlatorToIR.translate((CAstEntity) p.fst, (String) p.snd);
|
||||
for (Iterator<Pair<CAstEntity,ModuleEntry>> tles = topLevelEntities.iterator(); tles.hasNext();) {
|
||||
Pair<CAstEntity,ModuleEntry> p = tles.next();
|
||||
if (shouldTranslate(p.fst)) {
|
||||
xlatorToIR.translate(p.fst, p.snd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue