clean ups, and work on error reporting in the CAst front end
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3461 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
31a8bf2575
commit
f6f7b92bfe
|
@ -106,25 +106,7 @@ public class JDTSourceModuleTranslator implements SourceModuleTranslator {
|
|||
cl = cl.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
// Map options= javaProject.getOptions(true);
|
||||
// // turn all errors and warnings into ignore. The customizable set of compiler
|
||||
// // options only contains additional Eclipse options. The standard JDK compiler
|
||||
// // options can't be changed anyway.
|
||||
// for (Iterator iter= options.keySet().iterator(); iter.hasNext();) {
|
||||
// String key= (String)iter.next();
|
||||
// String value= (String)options.get(key);
|
||||
// if ("error".equals(value) || "warning".equals(value)) { //$NON-NLS-1$//$NON-NLS-2$
|
||||
// // System.out.println("Ignoring - " + key);
|
||||
// options.put(key, "ignore"); //$NON-NLS-1$
|
||||
// } else if ("enabled".equals(value)) {
|
||||
// // System.out.println(" - disabling " + key);
|
||||
// options.put(key, "disabled");
|
||||
// }
|
||||
// }
|
||||
// options.put(JavaCore.COMPILER_TASK_TAGS, "");
|
||||
// parser.setCompilerOptions(options);
|
||||
|
||||
|
||||
/*
|
||||
* Project -> AST code from org.eclipse.jdt.core.tests.performance
|
||||
*/
|
||||
|
|
|
@ -13,15 +13,19 @@ package com.ibm.wala.cast.js.ipa.callgraph;
|
|||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
|
||||
import com.ibm.wala.cast.js.ipa.summaries.JavaScriptSummarizedFunction;
|
||||
import com.ibm.wala.cast.js.ipa.summaries.JavaScriptSummary;
|
||||
import com.ibm.wala.cast.js.loader.JSCallSiteReference;
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import com.ibm.wala.cast.js.ssa.JSInstructionFactory;
|
||||
import com.ibm.wala.cast.js.translator.JSAstTranslator;
|
||||
import com.ibm.wala.cast.js.types.JavaScriptMethods;
|
||||
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
||||
import com.ibm.wala.cast.tree.impl.CAstImpl;
|
||||
import com.ibm.wala.cast.types.AstMethodReference;
|
||||
import com.ibm.wala.classLoader.CallSiteReference;
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
|
@ -413,7 +417,10 @@ public class JavaScriptConstructTargetSelector implements MethodTargetSelector {
|
|||
FileWriter FO = new FileWriter(f);
|
||||
FO.write(fun.toString());
|
||||
FO.close();
|
||||
(Util.getTranslatorFactory().make(cl)).translate(new SourceFileModule(f, System.getProperty("java.io.tmpdir")), fileName);
|
||||
SourceFileModule M = new SourceFileModule(f, fileName);
|
||||
TranslatorToCAst toCAst = Util.getTranslatorFactory().make(new CAstImpl(), M, null, null);
|
||||
JSAstTranslator toIR = new JSAstTranslator(cl);
|
||||
toIR.translate(toCAst.translateToCAst(), fileName);
|
||||
f.delete();
|
||||
IClass fcls = cl.lookupClass("Lctor " + ctorCount + "/_fromctor", cha);
|
||||
cha.addClass(fcls);
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
package com.ibm.wala.cast.js.loader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -28,6 +30,8 @@ import com.ibm.wala.cast.ir.ssa.AstLexicalWrite;
|
|||
import com.ibm.wala.cast.ir.ssa.EachElementGetInstruction;
|
||||
import com.ibm.wala.cast.ir.ssa.EachElementHasNextInstruction;
|
||||
import com.ibm.wala.cast.ir.ssa.AstLexicalAccess.Access;
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToIR;
|
||||
import com.ibm.wala.cast.ir.translator.AstTranslator.AstLexicalInformation;
|
||||
import com.ibm.wala.cast.js.ssa.JSInstructionFactory;
|
||||
import com.ibm.wala.cast.js.ssa.JavaScriptCheckReference;
|
||||
|
@ -37,6 +41,7 @@ import com.ibm.wala.cast.js.ssa.JavaScriptPropertyRead;
|
|||
import com.ibm.wala.cast.js.ssa.JavaScriptPropertyWrite;
|
||||
import com.ibm.wala.cast.js.ssa.JavaScriptTypeOfInstruction;
|
||||
import com.ibm.wala.cast.js.ssa.JavaScriptWithRegion;
|
||||
import com.ibm.wala.cast.js.translator.JSAstTranslator;
|
||||
import com.ibm.wala.cast.js.translator.JavaScriptTranslatorFactory;
|
||||
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
||||
import com.ibm.wala.cast.loader.AstClass;
|
||||
|
@ -44,7 +49,10 @@ import com.ibm.wala.cast.loader.AstDynamicPropertyClass;
|
|||
import com.ibm.wala.cast.loader.AstFunctionClass;
|
||||
import com.ibm.wala.cast.loader.AstMethod;
|
||||
import com.ibm.wala.cast.loader.CAstAbstractLoader;
|
||||
import com.ibm.wala.cast.loader.CAstAbstractModuleLoader;
|
||||
import com.ibm.wala.cast.loader.AstMethod.DebuggingInformation;
|
||||
import com.ibm.wala.cast.tree.CAst;
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.CAstQualifier;
|
||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
|
||||
import com.ibm.wala.cast.types.AstMethodReference;
|
||||
|
@ -57,7 +65,9 @@ import com.ibm.wala.classLoader.IMethod;
|
|||
import com.ibm.wala.classLoader.Language;
|
||||
import com.ibm.wala.classLoader.LanguageImpl;
|
||||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.classLoader.NewSiteReference;
|
||||
import com.ibm.wala.classLoader.SourceURLModule;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.shrikeBT.IBinaryOpInstruction.IOperator;
|
||||
|
@ -99,7 +109,7 @@ import com.ibm.wala.util.collections.HashSetFactory;
|
|||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.strings.Atom;
|
||||
|
||||
public class JavaScriptLoader extends CAstAbstractLoader {
|
||||
public class JavaScriptLoader extends CAstAbstractModuleLoader {
|
||||
|
||||
public final static Language JS = new LanguageImpl() {
|
||||
|
||||
|
@ -559,9 +569,9 @@ public class JavaScriptLoader extends CAstAbstractLoader {
|
|||
}
|
||||
}
|
||||
|
||||
private final Set<CAstQualifier> functionQualifiers;
|
||||
private static final Set<CAstQualifier> functionQualifiers;
|
||||
|
||||
{
|
||||
static {
|
||||
functionQualifiers = HashSetFactory.make();
|
||||
functionQualifiers.add(CAstQualifier.PUBLIC);
|
||||
functionQualifiers.add(CAstQualifier.FINAL);
|
||||
|
@ -714,8 +724,57 @@ public class JavaScriptLoader extends CAstAbstractLoader {
|
|||
return JS.instructionFactory();
|
||||
}
|
||||
|
||||
public void init(List<Module> modules) throws IOException {
|
||||
translatorFactory.make(this).translate(modules);
|
||||
public static final Set<String> bootstrapFileNames;
|
||||
|
||||
private static String prologueFileName = "prologue.js";
|
||||
|
||||
public static void resetPrologueFile() {
|
||||
prologueFileName = "prologue.js";
|
||||
}
|
||||
|
||||
public static void setPrologueFile(String name) {
|
||||
prologueFileName = name;
|
||||
}
|
||||
|
||||
public static void addBootstrapFile(String fileName) {
|
||||
bootstrapFileNames.add(fileName);
|
||||
}
|
||||
|
||||
static {
|
||||
bootstrapFileNames = HashSetFactory.make();
|
||||
bootstrapFileNames.add(prologueFileName);
|
||||
}
|
||||
|
||||
public void init(List<Module> modules) {
|
||||
|
||||
List<Module> all = new LinkedList<Module>();
|
||||
|
||||
for(final String fn : bootstrapFileNames) {
|
||||
all.add(new SourceURLModule(getClass().getClassLoader().getResource(fn)) {
|
||||
public String getName() {
|
||||
return fn;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
all.addAll(modules);
|
||||
|
||||
super.init(all);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TranslatorToCAst getTranslatorToCAst(CAst ast, ModuleEntry module, URL sourceURL, String localFileName) {
|
||||
return translatorFactory.make(ast, module, sourceURL, localFileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TranslatorToIR initTranslator() {
|
||||
return new JSAstTranslator(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldTranslate(CAstEntity entity) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,23 +12,32 @@ package com.ibm.wala.cast.js.translator;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
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.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.classLoader.SourceFileModule;
|
||||
|
||||
public class CAstRhinoTranslator extends TranslatorBase {
|
||||
private final JSAstTranslator CAstToIR;
|
||||
public class CAstRhinoTranslator implements TranslatorToCAst {
|
||||
|
||||
public void translate(ModuleEntry M, String N) throws IOException {
|
||||
CAstImpl Ast = new CAstImpl();
|
||||
CAstToIR.translate(
|
||||
new PropertyReadExpander(Ast).rewrite(
|
||||
new RhinoToAstTranslator(Ast, M, N).translate()),
|
||||
N);
|
||||
private final CAstImpl Ast = new CAstImpl();
|
||||
|
||||
private final ModuleEntry M;
|
||||
|
||||
public CAstRhinoTranslator(ModuleEntry M) {
|
||||
this.M = M;
|
||||
}
|
||||
|
||||
public CAstEntity translateToCAst() throws IOException {
|
||||
String N;
|
||||
if (M instanceof SourceFileModule) {
|
||||
N = ((SourceFileModule) M).getClassName();
|
||||
} else {
|
||||
N = M.getName();
|
||||
}
|
||||
|
||||
public CAstRhinoTranslator(JavaScriptLoader loader) {
|
||||
this.CAstToIR = new JSAstTranslator(loader);
|
||||
return
|
||||
new PropertyReadExpander(Ast).rewrite(
|
||||
new RhinoToAstTranslator(Ast, M, N).translate());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,16 +10,20 @@
|
|||
*****************************************************************************/
|
||||
package com.ibm.wala.cast.js.translator;
|
||||
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import java.net.URL;
|
||||
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
|
||||
import com.ibm.wala.cast.tree.CAst;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
|
||||
public interface JavaScriptTranslatorFactory {
|
||||
|
||||
TranslatorBase make(JavaScriptLoader loader);
|
||||
TranslatorToCAst make(CAst ast, ModuleEntry M, URL sourceURL, String localFileName);
|
||||
|
||||
public static class CAstRhinoFactory implements JavaScriptTranslatorFactory {
|
||||
|
||||
public TranslatorBase make(JavaScriptLoader loader) {
|
||||
return new CAstRhinoTranslator(loader);
|
||||
public TranslatorToCAst make(CAst ast, ModuleEntry M, URL sourceURL, String localFileName) {
|
||||
return new CAstRhinoTranslator(M);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.mozilla.javascript.ScriptOrFnNode;
|
|||
import org.mozilla.javascript.Token;
|
||||
import org.mozilla.javascript.tools.ToolErrorReporter;
|
||||
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
||||
import com.ibm.wala.cast.tree.CAst;
|
||||
import com.ibm.wala.cast.tree.CAstControlFlowMap;
|
||||
|
@ -469,7 +470,7 @@ public class RhinoToAstTranslator {
|
|||
}
|
||||
|
||||
private boolean isPrologueScript(WalkContext context) {
|
||||
return TranslatorBase.bootstrapFileNames.contains(context.script());
|
||||
return JavaScriptLoader.bootstrapFileNames.contains(context.script());
|
||||
}
|
||||
|
||||
private boolean isPrimitiveCall(WalkContext context, Node n) {
|
||||
|
@ -1348,8 +1349,6 @@ public class RhinoToAstTranslator {
|
|||
|
||||
private int anonymousCounter = 0;
|
||||
|
||||
// private int receiverCounter = 0;
|
||||
|
||||
public RhinoToAstTranslator(CAst Ast, ModuleEntry M, String scriptName) {
|
||||
this.Ast = Ast;
|
||||
this.scriptName = scriptName;
|
||||
|
|
|
@ -22,31 +22,9 @@ import com.ibm.wala.util.collections.HashSetFactory;
|
|||
|
||||
public abstract class TranslatorBase {
|
||||
|
||||
protected static final Set<String> bootstrapFileNames;
|
||||
|
||||
private static String prologueFileName = "prologue.js";
|
||||
|
||||
public static void resetPrologueFile() {
|
||||
prologueFileName = "prologue.js";
|
||||
}
|
||||
|
||||
public static void setPrologueFile(String name) {
|
||||
prologueFileName = name;
|
||||
}
|
||||
|
||||
public static void addBootstrapFile(String fileName) {
|
||||
bootstrapFileNames.add(fileName);
|
||||
}
|
||||
|
||||
static {
|
||||
bootstrapFileNames = HashSetFactory.make();
|
||||
bootstrapFileNames.add(prologueFileName);
|
||||
}
|
||||
|
||||
public abstract void translate(ModuleEntry M, String N) throws IOException;
|
||||
|
||||
public void translate(List modules) throws IOException {
|
||||
translate(new SourceURLModule(getClass().getClassLoader().getResource(prologueFileName)), prologueFileName);
|
||||
Iterator MS = modules.iterator();
|
||||
while (MS.hasNext()) {
|
||||
ModuleEntry M = (ModuleEntry) MS.next();
|
||||
|
|
|
@ -223,7 +223,7 @@ public:
|
|||
|
||||
jobject makeFieldEntity(jobject, jobject, bool, list<jobject> *);
|
||||
|
||||
jobject makeGlobalEntity(char *, list<jobject> *);
|
||||
jobject makeGlobalEntity(char *, jobject, list<jobject> *);
|
||||
|
||||
jobject getEntityAst(jobject);
|
||||
|
||||
|
|
|
@ -675,13 +675,13 @@ jobject CAstWrapper::makeFieldEntity(jobject declaringClass, jobject name, bool
|
|||
return entity;
|
||||
}
|
||||
|
||||
jobject CAstWrapper::makeGlobalEntity(char *name, list<jobject> *modifiers) {
|
||||
jobject CAstWrapper::makeGlobalEntity(char *name, jobject type, list<jobject> *modifiers) {
|
||||
char *safeData = strdup(name);
|
||||
jobject val = env->NewStringUTF( safeData );
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
delete safeData;
|
||||
|
||||
jobject entity = env->NewObject(NativeGlobalEntity, globalEntityInit, val, makeSet(modifiers));
|
||||
jobject entity = env->NewObject(NativeGlobalEntity, globalEntityInit, val, type, makeSet(modifiers));
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
return entity;
|
||||
|
|
|
@ -9,23 +9,29 @@ import java.util.Set;
|
|||
|
||||
import com.ibm.wala.cast.tree.CAstQualifier;
|
||||
import com.ibm.wala.cast.tree.CAstType;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
public class AbstractGlobalEntity extends AbstractDataEntity {
|
||||
private final String name;
|
||||
|
||||
private final Set<CAstQualifier> modifiers;
|
||||
|
||||
public AbstractGlobalEntity(String name, Set<CAstQualifier> modifiers) {
|
||||
private final CAstType type;
|
||||
|
||||
public AbstractGlobalEntity(String name, CAstType type, Set<CAstQualifier> modifiers) {
|
||||
this.name = name;
|
||||
this.modifiers = new HashSet<CAstQualifier>();
|
||||
this.type = type;
|
||||
this.modifiers = new HashSet<CAstQualifier>();
|
||||
if (modifiers != null) {
|
||||
this.modifiers.addAll(modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "global " + name;
|
||||
if (type == null) {
|
||||
return "global " + name;
|
||||
} else {
|
||||
return "global " + name + ":" + type;
|
||||
}
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
|
@ -37,11 +43,10 @@ public class AbstractGlobalEntity extends AbstractDataEntity {
|
|||
}
|
||||
|
||||
public CAstType getType() {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
return type;
|
||||
}
|
||||
|
||||
public Collection<CAstQualifier> getQualifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
|
||||
public interface TranslatorToCAst {
|
||||
|
||||
public CAstEntity translateToCAst();
|
||||
public CAstEntity translateToCAst() throws IOException;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,18 +2,27 @@ package com.ibm.wala.cast.loader;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IClassLoader;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.util.collections.Filter;
|
||||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.MapIterator;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.functions.Function;
|
||||
import com.ibm.wala.util.strings.Atom;
|
||||
import com.ibm.wala.util.warnings.Warning;
|
||||
|
||||
public abstract class CAstAbstractLoader implements IClassLoader {
|
||||
|
||||
|
@ -23,6 +32,8 @@ public abstract class CAstAbstractLoader implements IClassLoader {
|
|||
|
||||
protected final IClassLoader parent;
|
||||
|
||||
private final Map<ModuleEntry, Set<Warning>> errors = new HashMap<ModuleEntry, Set<Warning>>();
|
||||
|
||||
public CAstAbstractLoader(IClassHierarchy cha, IClassLoader parent) {
|
||||
this.cha = cha;
|
||||
this.parent = parent;
|
||||
|
@ -32,6 +43,43 @@ public abstract class CAstAbstractLoader implements IClassLoader {
|
|||
this(cha, null);
|
||||
}
|
||||
|
||||
protected void addMessage(ModuleEntry module, Warning message) {
|
||||
if (! errors.containsKey(module)) {
|
||||
errors.put(module, new HashSet<Warning>());
|
||||
}
|
||||
|
||||
errors.get(module).add(message);
|
||||
}
|
||||
|
||||
private Iterator<ModuleEntry> getMessages(final byte severity) {
|
||||
return new MapIterator<Map.Entry<ModuleEntry,Set<Warning>>, ModuleEntry>(new FilterIterator<Map.Entry<ModuleEntry,Set<Warning>>>(errors.entrySet().iterator(), new Filter<Map.Entry<ModuleEntry,Set<Warning>>>() {
|
||||
public boolean accepts(Entry<ModuleEntry, Set<Warning>> o) {
|
||||
for(Warning w : o.getValue()) {
|
||||
if (w.getLevel() == severity) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}), new Function<Map.Entry<ModuleEntry,Set<Warning>>, ModuleEntry>() {
|
||||
public ModuleEntry apply(Entry<ModuleEntry, Set<Warning>> object) {
|
||||
return object.getKey();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Iterator<ModuleEntry> getModulesWithParseErrors() {
|
||||
return getMessages(Warning.SEVERE);
|
||||
}
|
||||
|
||||
public Iterator<ModuleEntry> getModulesWithWarnings() {
|
||||
return getMessages(Warning.MILD);
|
||||
}
|
||||
|
||||
public Set<Warning> getMessages(ModuleEntry m) {
|
||||
return errors.get(m);
|
||||
}
|
||||
|
||||
public IClass lookupClass(String className, IClassHierarchy cha) {
|
||||
Assertions._assert(this.cha == cha);
|
||||
return (IClass) types.get(TypeName.string2TypeName(className));
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
|
|||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.warnings.Warning;
|
||||
|
||||
public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
||||
|
||||
|
@ -48,7 +49,7 @@ public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
|||
this(cha, null);
|
||||
}
|
||||
|
||||
protected abstract TranslatorToCAst getTranslatorToCAst(CAst ast, URL sourceURL, String localFileName);
|
||||
protected abstract TranslatorToCAst getTranslatorToCAst(CAst ast, ModuleEntry M, URL sourceURL, String localFileName);
|
||||
|
||||
protected abstract boolean shouldTranslate(CAstEntity entity);
|
||||
|
||||
|
@ -68,40 +69,39 @@ public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
|||
class TranslatorNestingHack {
|
||||
|
||||
private void init(ModuleEntry moduleEntry) {
|
||||
if (moduleEntry.isModuleFile()) {
|
||||
init(moduleEntry.asModule());
|
||||
} else if (moduleEntry instanceof SourceFileModule) {
|
||||
File f = ((SourceFileModule) moduleEntry).getFile();
|
||||
String fn = f.toString();
|
||||
try {
|
||||
if (moduleEntry.isModuleFile()) {
|
||||
init(moduleEntry.asModule());
|
||||
} else if (moduleEntry instanceof SourceFileModule) {
|
||||
File f = ((SourceFileModule) moduleEntry).getFile();
|
||||
String fn = f.toString();
|
||||
|
||||
try {
|
||||
TranslatorToCAst xlatorToCAst = getTranslatorToCAst(ast, new URL("file://" + f), fn);
|
||||
TranslatorToCAst xlatorToCAst = getTranslatorToCAst(ast, moduleEntry, new URL("file://" + f), fn);
|
||||
|
||||
CAstEntity fileEntity = xlatorToCAst.translateToCAst();
|
||||
CAstEntity fileEntity = xlatorToCAst.translateToCAst();
|
||||
|
||||
if (fileEntity != null) {
|
||||
CAstPrinter.printTo(fileEntity, new PrintWriter(System.err));
|
||||
if (fileEntity != null) {
|
||||
CAstPrinter.printTo(fileEntity, new PrintWriter(System.err));
|
||||
|
||||
topLevelEntities.add(Pair.make(fileEntity, fn));
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
System.err.println(("unpected problems with " + f));
|
||||
e.printStackTrace(System.err);
|
||||
Assertions.UNREACHABLE();
|
||||
} catch (RuntimeException e) {
|
||||
System.err.println(("unpected problems with " + f));
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
topLevelEntities.add(Pair.make(fileEntity, fn));
|
||||
|
||||
} else {
|
||||
addMessage(moduleEntry, new Warning(Warning.SEVERE) {
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return "parse error";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else if (moduleEntry instanceof SourceURLModule) {
|
||||
java.net.URL url = ((SourceURLModule) moduleEntry).getURL();
|
||||
String fileName = ((SourceURLModule) moduleEntry).getName();
|
||||
String localFileName = fileName.replace('/', '_');
|
||||
} else if (moduleEntry instanceof SourceURLModule) {
|
||||
java.net.URL url = ((SourceURLModule) moduleEntry).getURL();
|
||||
String fileName = ((SourceURLModule) moduleEntry).getName();
|
||||
String localFileName = fileName.replace('/', '_');
|
||||
|
||||
try {
|
||||
File F = TemporaryFile.streamToFile(localFileName, ((SourceURLModule) moduleEntry).getInputStream());
|
||||
|
||||
final TranslatorToCAst xlatorToCAst = getTranslatorToCAst(ast, url, localFileName);
|
||||
final TranslatorToCAst xlatorToCAst = getTranslatorToCAst(ast, moduleEntry, url, localFileName);
|
||||
|
||||
CAstEntity fileEntity = xlatorToCAst.translateToCAst();
|
||||
|
||||
|
@ -109,17 +109,39 @@ public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
|||
System.err.println(CAstPrinter.print(fileEntity));
|
||||
|
||||
topLevelEntities.add(Pair.make(fileEntity, fileName));
|
||||
|
||||
} else {
|
||||
addMessage(moduleEntry, new Warning(Warning.SEVERE) {
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return "parse error";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
F.delete();
|
||||
} catch (IOException e) {
|
||||
System.err.println(("unexpected problems with " + fileName));
|
||||
e.printStackTrace(System.err);
|
||||
Assertions.UNREACHABLE();
|
||||
} catch (RuntimeException e) {
|
||||
System.err.println(("unexpected problems with " + fileName));
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
} catch (final MalformedURLException e) {
|
||||
addMessage(moduleEntry, new Warning(Warning.SEVERE) {
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return "Malformed URL issue: " + e.getMessage();
|
||||
}
|
||||
});
|
||||
} catch (final IOException e) {
|
||||
addMessage(moduleEntry, new Warning(Warning.SEVERE) {
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return "I/O issue: " + e.getMessage();
|
||||
}
|
||||
});
|
||||
} catch (final RuntimeException e) {
|
||||
addMessage(moduleEntry, new Warning(Warning.SEVERE) {
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return "Parsing issue: " + e.getMessage();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,12 @@ public interface CAstType {
|
|||
CAstType getDeclaringType();
|
||||
}
|
||||
|
||||
public interface Complex extends CAstType {
|
||||
|
||||
CAstType getType();
|
||||
|
||||
}
|
||||
|
||||
public static final CAstType DYNAMIC = new CAstType() {
|
||||
|
||||
public String getName() {
|
||||
|
|
Loading…
Reference in New Issue