summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-06-24 12:20:22 +0000
committerpaltherr <paltherr@epfl.ch>2003-06-24 12:20:22 +0000
commitc2c93468eb67bdaaef1b4e3d831b526660510f82 (patch)
treeb8f5cce45df81c8020d230822ea4fed262722667 /sources
parentd8d2c7f502baebab1f1994dfaec843139eded747 (diff)
downloadscala-c2c93468eb67bdaaef1b4e3d831b526660510f82.tar.gz
scala-c2c93468eb67bdaaef1b4e3d831b526660510f82.tar.bz2
scala-c2c93468eb67bdaaef1b4e3d831b526660510f82.zip
- Added sourcefile tracking for stack traces
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/scalai/CodeContainer.java8
-rw-r--r--sources/scala/tools/scalai/Compiler.java53
-rw-r--r--sources/scala/tools/scalai/Evaluator.java7
-rw-r--r--sources/scala/tools/scalai/EvaluatorException.java9
-rw-r--r--sources/scala/tools/scalai/ExpressionCompiler.java6
-rw-r--r--sources/scala/tools/scalai/ExpressionContext.java14
-rw-r--r--sources/scala/tools/scalai/ScalaFunction.java8
7 files changed, 76 insertions, 29 deletions
diff --git a/sources/scala/tools/scalai/CodeContainer.java b/sources/scala/tools/scalai/CodeContainer.java
index e1f717cf6f..269e1c03a2 100644
--- a/sources/scala/tools/scalai/CodeContainer.java
+++ b/sources/scala/tools/scalai/CodeContainer.java
@@ -9,6 +9,8 @@
package scalai;
+import ch.epfl.lamp.util.SourceFile;
+
import scalac.symtab.Symbol;
public class CodeContainer {
@@ -16,7 +18,10 @@ public class CodeContainer {
//########################################################################
// Public Constructors
- public CodeContainer(Symbol symbol, Code code, int stacksize) {
+ public CodeContainer(
+ SourceFile source, Symbol symbol, Code code, int stacksize)
+ {
+ this.source = source;
this.symbol = symbol;
this.code = code;
this.stacksize = stacksize;
@@ -25,6 +30,7 @@ public class CodeContainer {
//########################################################################
// Public Fields
+ public final SourceFile source;
public final Symbol symbol;
public final Code code;
public final int stacksize;
diff --git a/sources/scala/tools/scalai/Compiler.java b/sources/scala/tools/scalai/Compiler.java
index 4398903fc6..768b335734 100644
--- a/sources/scala/tools/scalai/Compiler.java
+++ b/sources/scala/tools/scalai/Compiler.java
@@ -19,6 +19,8 @@ import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
+import ch.epfl.lamp.util.SourceFile;
+
import scalac.Unit;
import scalac.Global;
import scalac.ast.Tree;
@@ -45,6 +47,7 @@ public class Compiler {
private final Environment environment;
private final Evaluator evaluator; // !!! remove
private final Map any_methods;
+ private final Map sources;
public Compiler(Global global, Evaluator evaluator) {
this.global = global;
@@ -56,6 +59,9 @@ public class Compiler {
this.environment = new Environment(this, mirror);
this.evaluator = evaluator;
this.any_methods = new HashMap();
+ this.sources = new HashMap();
+
+ SourceFile compiled = new SourceFile("<<compiled code>>", new byte[0]);
environment.insertFunction(definitions.STRING_PLUS_ANY, Function.StringPlus); // !!!
// !!! ANY_PLUS_STRING is commented out in definitions
@@ -89,6 +95,7 @@ public class Compiler {
assert equals_symbol != Symbol.NONE;
CodePromise equals_code = new CodePromise(
new CodeContainer(
+ compiled,
equals_symbol,
Code.Invoke(
Code.Invoke(
@@ -123,6 +130,7 @@ public class Compiler {
}
CodePromise hashCode_code = new CodePromise(
new CodeContainer(
+ compiled,
definitions.HASHCODE,
Code.Invoke(
Code.Self, Function.HashCode, new Code[0],
@@ -147,6 +155,7 @@ public class Compiler {
}
CodePromise toString_code = new CodePromise(
new CodeContainer(
+ compiled,
definitions.TOSTRING,
Code.Invoke(
Code.Self, Function.ToString, new Code[0],
@@ -176,13 +185,19 @@ public class Compiler {
//########################################################################
public ScalaTemplate load(Symbol symbol, Tree.ClassDef tree) {
+ SourceFile source = (SourceFile)sources.remove(tree);
+ assert tree != null : Debug.show(symbol);
+ return load(source, symbol, tree);
+ }
+
+ public ScalaTemplate load(SourceFile source, Symbol symbol, Tree.ClassDef tree) {
assert tree.tparams .length == 0 : Debug.show(tree);
assert tree.vparams .length == 1 : Debug.show(tree);
assert tree.vparams[0].length == 0 : Debug.show(tree);
- return compileTemplate(symbol, tree.impl.body);
+ return compileTemplate(source, symbol, tree.impl.body);
}
- public ScalaTemplate compileTemplate(Symbol symbol, Tree[] body) {
+ public ScalaTemplate compileTemplate(SourceFile source, Symbol symbol, Tree[] body) {
Set supertypes = new HashSet();
List interfaces = new ArrayList();
getTypes(supertypes, interfaces, symbol);
@@ -215,7 +230,7 @@ public class Compiler {
}
}
for (int i = 0; i < body.length; i++) {
- addTemplateMember(methods, fields, body[i]);
+ addTemplateMember(source, methods, fields, body[i]);
}
return new ScalaTemplate(evaluator, symbol, constructor, methods, fields.toArray());
}
@@ -230,21 +245,21 @@ public class Compiler {
return environment.lookupFunction(symbol);
}
- public CodePromise compile(Symbol symbol, Tree.DefDef tree) {
+ public CodePromise compile(SourceFile source, Symbol symbol, Tree.DefDef tree) {
assert tree.tparams.length == 0 : Debug.show(tree);
assert tree.vparams.length == 1 : Debug.show(tree);
- return new CodePromise(new ScalaFunction(this, symbol, tree.vparams[0],tree.rhs));
+ return new CodePromise(new ScalaFunction(this, source, symbol, tree.vparams[0],tree.rhs));
}
//########################################################################
//
public void compile(Unit[] units) {
- for (int i = 0; i < units.length; i++) declare(units[i].body);
+ for (int i = 0; i < units.length; i++) declare(units[i].source, units[i].body);
}
- public CodeContainer compile(Symbol owner, Tree tree, Symbol[] params) {
- ExpressionContext context = new ExpressionContext(environment, owner);
+ public CodeContainer compile(SourceFile source, Symbol owner, Tree tree, Symbol[] params) {
+ ExpressionContext context = new ExpressionContext(environment, source, owner);
ExpressionCompiler worker = new ExpressionCompiler(definitions, constants, context, params);
return worker.compile(tree);
}
@@ -252,11 +267,11 @@ public class Compiler {
//########################################################################
// Private Methods -
- private void declare(Tree[] trees) {
- for (int i = 0; i < trees.length; i++) declare(trees[i]);
+ private void declare(SourceFile source, Tree[] trees) {
+ for (int i = 0; i < trees.length; i++) declare(source, trees[i]);
}
- private void declare(Tree tree) {
+ private void declare(SourceFile source, Tree tree) {
Symbol symbol = tree.symbol();
switch (tree) {
@@ -264,6 +279,7 @@ public class Compiler {
return;
case ClassDef(_, _, _, _, _, _):
+ sources.put(tree, source);
environment.insertClassDef(symbol, (Tree.ClassDef)tree);
return;
@@ -271,12 +287,12 @@ public class Compiler {
case PackageDef(Tree packaged, Tree.Template(Tree[] bases, Tree[] body)):
assert packaged.symbol().isPackage() : Debug.show(tree); // !!! was isJavaPackage
assert bases.length == 0 : Debug.show(tree);
- declare(body);
+ declare(source, body);
return;
case ValDef(_, _, _, Tree body):
assert symbol.isModule() : Debug.show(symbol);
- environment.insertVariable(symbol, Variable.Module(new CodePromise(new ModuleBuilder(this, symbol, body)), null));
+ environment.insertVariable(symbol, Variable.Module(new CodePromise(new ModuleBuilder(this, source, symbol, body)), null));
return;
default:
@@ -349,7 +365,7 @@ public class Compiler {
//########################################################################
// Private Methods - template members
- private void addTemplateMember(Map methods, List fields, Tree tree) {
+ private void addTemplateMember(SourceFile source, Map methods, List fields, Tree tree) {
Symbol symbol = tree.symbol();
switch (tree) {
@@ -357,6 +373,7 @@ public class Compiler {
return;
case ClassDef(_, _, _, _, _, _):
+ sources.put(tree, source);
environment.insertClassDef(symbol, (Tree.ClassDef)tree);
return;
@@ -370,7 +387,7 @@ public class Compiler {
case DefDef(_, _, _, _, _, _):
assert !methods.containsKey(symbol) : Debug.show(symbol);
- CodePromise function = compile(symbol, (Tree.DefDef)tree);
+ CodePromise function = compile(source, symbol, (Tree.DefDef)tree);
Override override = environment.lookupOverride(symbol);
for (Iterator i = override.iterator(); i.hasNext(); ) {
methods.put(i.next(), function);
@@ -389,17 +406,19 @@ public class Compiler {
public static class ModuleBuilder extends CodeGenerator {
private final Compiler compiler;
+ private final SourceFile source;
private final Symbol symbol;
private final Tree body;
- public ModuleBuilder(Compiler compiler, Symbol symbol, Tree body) {
+ public ModuleBuilder(Compiler compiler, SourceFile source, Symbol symbol, Tree body) {
this.compiler = compiler;
+ this.source = source;
this.symbol = symbol;
this.body = body;
}
public CodeContainer generate() {
- return compiler.compile(symbol, body, Symbol.EMPTY_ARRAY);
+ return compiler.compile(source, symbol, body, Symbol.EMPTY_ARRAY);
}
}
diff --git a/sources/scala/tools/scalai/Evaluator.java b/sources/scala/tools/scalai/Evaluator.java
index 6ee618f252..d418d7aa7a 100644
--- a/sources/scala/tools/scalai/Evaluator.java
+++ b/sources/scala/tools/scalai/Evaluator.java
@@ -16,6 +16,8 @@ import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
+import ch.epfl.lamp.util.SourceFile;
+
import scala.runtime.RunTime;
import scalac.symtab.Symbol;
@@ -42,6 +44,7 @@ public class Evaluator {
public static class EvaluationStack {
public final EvaluationStack stack;
+ public final SourceFile source;
public final Symbol symbol;
public final Object self;
public final Object[] args;
@@ -51,6 +54,7 @@ public class Evaluator {
Object self, Object[] args)
{
this.stack = stack;
+ this.source = code.source;
this.symbol = code.symbol;
this.self = self;
this.args = args;
@@ -156,7 +160,8 @@ public class Evaluator {
} catch (StackOverflowError exception) {
return throw_(exception);
} catch (EvaluatorException exception) {
- exception.addScalaCall(stack.symbol, pos);
+ if (stack != null)
+ exception.addScalaCall(stack.symbol, stack.source, pos);
throw exception;
}
diff --git a/sources/scala/tools/scalai/EvaluatorException.java b/sources/scala/tools/scalai/EvaluatorException.java
index 8b5eb76e6b..dc8c1fa905 100644
--- a/sources/scala/tools/scalai/EvaluatorException.java
+++ b/sources/scala/tools/scalai/EvaluatorException.java
@@ -12,6 +12,7 @@ import java.util.List;
import java.util.ArrayList;
import ch.epfl.lamp.util.Position;
+import ch.epfl.lamp.util.SourceFile;
import scalac.Global;
import scalac.symtab.Symbol;
@@ -48,15 +49,15 @@ public class EvaluatorException extends RuntimeException {
return cause;
}
- public void addScalaCall(Symbol method, int pos) {
+ public void addScalaCall(Symbol method, SourceFile source, int pos) {
StringBuffer buffer = new StringBuffer();
buffer.append(method.owner().fullNameString());
buffer.append('.');
buffer.append(method.nameString());
buffer.append('(');
- // !!! buffer.append(Position.file(pos));
- buffer.append(':');
- buffer.append(Position.line(pos));
+ buffer.append(source.getShortName());
+ int line = Position.line(pos);
+ if (line != 0) buffer.append(':').append(line);
buffer.append(")");
stack.add(buffer);
}
diff --git a/sources/scala/tools/scalai/ExpressionCompiler.java b/sources/scala/tools/scalai/ExpressionCompiler.java
index e77e94a5d1..e1fc523bc4 100644
--- a/sources/scala/tools/scalai/ExpressionCompiler.java
+++ b/sources/scala/tools/scalai/ExpressionCompiler.java
@@ -43,7 +43,8 @@ public class ExpressionCompiler {
public CodeContainer compile(Tree tree) {
Code code = compute(tree);
- return new CodeContainer(context.owner(), code, context.stackmax());
+ return new CodeContainer(
+ context.source(), context.owner(), code, context.stackmax());
}
public CodeContainer compile(ArrayList items) {
@@ -55,7 +56,8 @@ public class ExpressionCompiler {
value = compute((Tree)item);
}
Code code = buffer.code(value);
- return new CodeContainer(context.owner(), code, context.stackmax());
+ return new CodeContainer(
+ context.source(), context.owner(), code, context.stackmax());
}
//########################################################################
diff --git a/sources/scala/tools/scalai/ExpressionContext.java b/sources/scala/tools/scalai/ExpressionContext.java
index 54c60e29e8..0a184cf011 100644
--- a/sources/scala/tools/scalai/ExpressionContext.java
+++ b/sources/scala/tools/scalai/ExpressionContext.java
@@ -12,6 +12,8 @@ package scalai;
import java.util.Map;
import java.util.HashMap;
+import ch.epfl.lamp.util.SourceFile;
+
import scalac.symtab.Symbol;
import scalac.util.Debug;
@@ -23,6 +25,7 @@ public class ExpressionContext {
private final Environment environment;
private final Map functions;
private final Map variables;
+ private final SourceFile source;
private final Symbol owner;
private int current;
@@ -31,10 +34,13 @@ public class ExpressionContext {
//########################################################################
// Public Constructors
- public ExpressionContext(Environment environment, Symbol owner) {
+ public ExpressionContext(
+ Environment environment, SourceFile source, Symbol owner)
+ {
this.environment = environment;
this.functions = new HashMap();
this.variables = new HashMap();
+ this.source = source;
this.owner = owner;
this.current = 0;
this.maximum = 0;
@@ -78,7 +84,11 @@ public class ExpressionContext {
}
//########################################################################
- // Public Methods - owner
+ // Public Methods - origin
+
+ public SourceFile source() {
+ return source;
+ }
public Symbol owner() {
return owner;
diff --git a/sources/scala/tools/scalai/ScalaFunction.java b/sources/scala/tools/scalai/ScalaFunction.java
index b4a215cb5a..1cb76d4dcb 100644
--- a/sources/scala/tools/scalai/ScalaFunction.java
+++ b/sources/scala/tools/scalai/ScalaFunction.java
@@ -9,6 +9,8 @@
package scalai;
+import ch.epfl.lamp.util.SourceFile;
+
import scalac.ast.Tree;
import scalac.ast.Tree.ValDef;
import scalac.symtab.Symbol;
@@ -20,6 +22,7 @@ public class ScalaFunction extends CodeGenerator {
// Private Fields
private final Compiler compiler;
+ private final SourceFile source;
private final Symbol symbol;
private final ValDef[] params;
private final Tree body;
@@ -27,8 +30,9 @@ public class ScalaFunction extends CodeGenerator {
//########################################################################
// Public Constructors
- public ScalaFunction(Compiler compiler, Symbol symbol, ValDef[] params, Tree body) {
+ public ScalaFunction(Compiler compiler, SourceFile source, Symbol symbol, ValDef[] params, Tree body) {
this.compiler = compiler;
+ this.source = source;
this.symbol = symbol;
this.params = params;
this.body = body;
@@ -38,7 +42,7 @@ public class ScalaFunction extends CodeGenerator {
// Public Methods - CodeGenerator interface
public CodeContainer generate() {
- return compiler.compile(symbol, body, Tree.symbolOf(params));
+ return compiler.compile(source, symbol, body, Tree.symbolOf(params));
}
//########################################################################