summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc
diff options
context:
space:
mode:
authorSean McDirmid <sean.mcdirmid@gmail.com>2006-02-09 15:03:35 +0000
committerSean McDirmid <sean.mcdirmid@gmail.com>2006-02-09 15:03:35 +0000
commit25eb10e214a35aa9f8c5a811a668e1fcfeed842c (patch)
tree3857ce17f503f6d4bf79c32437d50e94c7d7e324 /src/compiler/scala/tools/nsc
parent1d7dd9a70a0d47268e784a78460fe224c741426e (diff)
downloadscala-25eb10e214a35aa9f8c5a811a668e1fcfeed842c.tar.gz
scala-25eb10e214a35aa9f8c5a811a668e1fcfeed842c.tar.bz2
scala-25eb10e214a35aa9f8c5a811a668e1fcfeed842c.zip
Diffstat (limited to 'src/compiler/scala/tools/nsc')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala4
-rw-r--r--src/compiler/scala/tools/nsc/models/SemanticTokens.scala24
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala5
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Analyzer.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala17
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala18
-rw-r--r--src/compiler/scala/tools/nsc/util/ClassPath.scala2
-rw-r--r--src/compiler/scala/tools/nsc/util/Position.scala8
9 files changed, 60 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 27f3cabd7c..bfb136dd0c 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -26,7 +26,6 @@ import backend.icode.{ICodes, GenICode, Checkers};
import backend.ScalaPrimitives;
import backend.jvm.GenJVM;
-
class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
with Trees
with CompilationUnits
@@ -83,6 +82,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
if (onlyPresentation) new HashMap[Symbol,String];
else null;
+
// reporting -------------------------------------------------------
def error(msg: String) = reporter.error(null, msg);
@@ -99,6 +99,8 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
def log(msg: Object): unit =
if (settings.log contains phase.name) inform("[log " + phase + "] " + msg);
+ def logError(msg: String, t : Throwable): Unit = {};
+
def abort(msg: String) = throw new Error(msg);
// file interface -------------------------------------------------------
diff --git a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
index 42bc102208..3667b422c3 100644
--- a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
+++ b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
@@ -97,6 +97,7 @@ class SemanticTokens(val compiler: Global) {
}
def Process(unit : CompilationUnit) = new Process(unit);
class Process(val unit : CompilationUnit) {
+ private var doLog = true;
def source = unit.source;
def dbg(tree : Tree) = {(
@@ -160,7 +161,7 @@ class SemanticTokens(val compiler: Global) {
// ok start building....
def build[T <: Tree](trees : List[T]) : Unit = for (val tree : T <- trees) build(tree);
- def build(tree0 : Tree) : Unit = {
+ def build(tree0 : Tree) : Unit = try {
if (tree0.pos != Position.NOPOS) tree0 match {
case tree : ImplDef =>
val pos = tree.namePos(unit.source);
@@ -227,13 +228,15 @@ class SemanticTokens(val compiler: Global) {
}
build(tree.body);
case tree : TypeTree =>
+ val treex = tree;
val tree1 = if (tree.original != null) tree.original; else tree;
if (tree.tpe != null) buildT(tree1, tree.tpe);
def buildT( tree : Tree, tpe : Type) : Unit = if (tree.pos != Position.NOPOS) tpe match {
case tpe0 : TypeRef => tree match {
case apt : AppliedTypeTree =>
buildUse(tpe.symbol, apt.tpt.pos, tpe0);
- //System.err.println("APT: " + apt.tpt + " sym0=" + apt.tpt.symbol + " sym1=" + tpe0.sym + " " + " " + apt.args + " " + tpe0.args);
+ //System.err.println("APT: " + treex + " vs. " + treex.original);
+ //System.err.println("APT: " + apt.tpt + " sym0=" + apt.tpt.symbol + " sym1=" + tpe0.sym + " apt.args=" + apt.args + " tpe0.args=" + tpe0.args);
buildTs (apt.args, tpe0.args);
case ident : Ident => buildUse(tpe0.sym, ident.pos, tpe0);
@@ -294,10 +297,19 @@ class SemanticTokens(val compiler: Global) {
System.err.println("UNKNOWN TPE4: " + dbg(tree) + " vs. " + tpe + " " + (if (tpe != null) "" + tpe.getClass() + " " + tpe.getClass().getSuperclass() else null));
}
};
- def buildTs(trees : List[Tree], types : List[Type]): Unit = if (!trees.isEmpty || !types.isEmpty) {
+ def buildTs(trees : List[Tree], types : List[Type]): Unit = if (!trees.isEmpty && !types.isEmpty) {
buildT (trees.head, types.head);
buildTs(trees.tail, types.tail);
- };
+ } else if (trees.isEmpty != types.isEmpty) {
+ if (false && doLog) {
+ Console.println("" + treex + " vs. " + treex.original);
+ if (treex.original != null)
+ Console.println("" + treex.tpe + " vs. " + treex.original.tpe);
+ logError("Tree vs. Type mismatch: " + trees + " " + types + " " + unit.source.dbg(tree.pos), null);
+ doLog = false;
+ }
+ };
+
case tree : AbsTypeDef =>
//System.err.println("ABS: " + tree.symbol + " " + unit.source.dbg(tree.namePos) + " " + unit.source.dbg(tree.pos));
buildDef(tree.symbol, tree.namePos);
@@ -357,7 +369,9 @@ class SemanticTokens(val compiler: Global) {
case _ => ;
System.err.println("BAIL: " + unit.source.dbg(tree0.pos) + " " + tree0 + " " + tree0.getClass());
}
- }
+ } catch {
+ case t : Throwable => logError("Error occured at " + unit.source.dbg(tree0.pos), t);
+ }
def buildUse(term : Symbol, pos : Int, tpe : Type) = buildSym(term, pos, false, tpe);
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index 83286799bb..ce02b266e4 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -12,6 +12,8 @@ import Flags._;
mixin class Definitions requires SymbolTable {
object definitions {
+ def isDefinitionsInitialized = isInitialized;
+
// root packages and classes
var RootClass: Symbol = _;
@@ -294,7 +296,7 @@ mixin class Definitions requires SymbolTable {
.setFlag(FINAL | MODULE | PACKAGE | JAVA).setInfo(rootLoader);
EmptyPackage =
- RootClass.newPackage(Position.NOPOS, nme.EMPTY_PACKAGE_NAME).setFlag(FINAL);
+ RootClass.newPackage(Position.NOPOS, nme.EMPTY_PACKAGE_NAME).setFlag(FINAL);
EmptyPackageClass = EmptyPackage.moduleClass;
EmptyPackageClass.setInfo(ClassInfoType(List(), new Scope(), EmptyPackageClass));
@@ -304,6 +306,7 @@ mixin class Definitions requires SymbolTable {
JavaPackage = getModule("java");
JavaLangPackage = getModule("java.lang");
ScalaPackage = getModule("scala");
+ assert(ScalaPackage != null, "Scala package is null");
ScalaPackageClass = ScalaPackage.tpe.symbol;
AnyClass = newClass(ScalaPackageClass, "Any", List());
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 19059f12e0..749344c4e9 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -1318,6 +1318,7 @@ mixin class Types requires SymbolTable {
var result: Symbol = _;
def init = { result = NoSymbol }
def apply(tp: Type): Type = {
+ assert(tp != null);
tp match {
case ThisType(sym) =>
register(sym);
diff --git a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
index 0118dadbaf..ed7382dc8a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
@@ -36,7 +36,7 @@ mixin class Analyzer
def newPhase(_prev: Phase): StdPhase = new StdPhase(_prev) {
resetTyper;
def apply(unit: CompilationUnit): unit =
- unit.body = newTyper(startContext.make(unit)).typed(unit.body)
+ unit.body = newTyper(startContext.make(unit)).typed(unit.body)
}
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index c6aa1d8c8e..f2513bd789 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -19,22 +19,25 @@ mixin class Contexts requires Analyzer {
val startContext = {
import definitions._;
var sc = NoContext.make(
- Template(List(), List()) setSymbol NoSymbol setType NoType,
- definitions.RootClass,
- definitions.RootClass.info.decls);
+ Template(List(), List()) setSymbol NoSymbol setType NoType,
+ definitions.RootClass,
+ definitions.RootClass.info.decls);
def addImport(pkg: Symbol): unit = {
+ assert(pkg != null, "package is null");
val qual = gen.mkStableRef(pkg);
sc = sc.makeNewImport(
- Import(qual, List(Pair(nme.WILDCARD, null)))
- setSymbol NoSymbol.newImport(Position.NOPOS).setInfo(ImportType(qual))
- setType NoType);
+ Import(qual, List(Pair(nme.WILDCARD, null)))
+ setSymbol NoSymbol.newImport(Position.NOPOS).setInfo(ImportType(qual))
+ setType NoType);
sc.depth = sc.depth + 1
}
if (!settings.noimports.value) {
+ assert(isDefinitionsInitialized);
addImport(JavaLangPackage);
+ assert(ScalaPackage != null, "Scala package is null");
addImport(ScalaPackage);
if (!settings.nopredefs.value)
- addImport(PredefModule);
+ addImport(PredefModule);
}
sc
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 3fb8af5111..fd2a9239b9 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -380,10 +380,22 @@ mixin class Typers requires Analyzer {
val tree1 = TypeTree(clazz.primaryConstructor.tpe.asSeenFrom(tree.tpe.prefix, clazz.owner)) setPos tree.pos
// tree.tpe.prefix.memberType(clazz.primaryConstructor); //!!!
- inferConstructorInstance(tree1, clazz.unsafeTypeParams, pt)
- tree1
+ try {
+ inferConstructorInstance(tree1, clazz.unsafeTypeParams, pt)
+ } catch {
+ case npe : NullPointerException =>
+ logError("CONTEXT: " + context . unit . source .dbg(tree.pos), npe);
+ throw npe;
+ case fe : FatalError =>
+ logError("CONTEXT: " + context . unit . source .dbg(tree.pos), fe);
+ throw fe;
+ case t : Throwable =>
+ logError("CONTEXT: " + context . unit . source .dbg(tree.pos), t);
+ throw t;
+ }
+ tree1
} else if (clazz.isSubClass(SeqClass)) { // (5.2)
- pt.baseType(clazz).baseType(SeqClass) match {
+ pt.baseType(clazz).baseType(SeqClass) match {
case TypeRef(pre, seqClass, args) =>
tree.setType(MethodType(List(typeRef(pre, RepeatedParamClass, args)), pt))
case NoType =>
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala
index aff5a64916..c72bf3beb4 100644
--- a/src/compiler/scala/tools/nsc/util/ClassPath.scala
+++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala
@@ -35,9 +35,11 @@ class ClassPath(onlyPresentation : Boolean) {
def source : Source;
}
+
class Output(location0 : AbstractFile, val sourceFile : AbstractFile) extends Entry(location0) {
def source = if (sourceFile != null) new Source(sourceFile, true); else null;
}
+
class Library(location0: AbstractFile) extends Entry(location0) {
def doc : AbstractFile = null;
def sourceFile : AbstractFile = null;
diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala
index 290eb7e248..e900aa2553 100644
--- a/src/compiler/scala/tools/nsc/util/Position.scala
+++ b/src/compiler/scala/tools/nsc/util/Position.scala
@@ -65,8 +65,9 @@ class Position( val source : SourceFile, val offset: Int) {
} else 0;
- def dbgString =
- if (isLine) "line-" + line;
+ def dbgString = {
+ "source: " + (if (source == null) source else source . path) + " " +
+ (if (isLine) "line-" + line;
else if (!hasOffset) "NOP";
else if (offset >= source.content.length) "out-of-bounds-" + offset else {
val ret = "offset=" + offset + " line=" + line;
@@ -74,7 +75,8 @@ class Position( val source : SourceFile, val offset: Int) {
while (offset + add.length() < source.content.length &&
add.length() < 10) add = add + source.content(offset + add.length());
ret + " c[0..9]=\"" + add + "\"";
- }
+ })
+ }