From 89de2927954407224dbe51c03bb8cbbd0229519b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 9 Mar 2005 18:11:33 +0000 Subject: *** empty log message *** --- sources/scala/tools/nsc/Global.scala | 18 ++- sources/scala/tools/nsc/Phase.scala | 4 +- sources/scala/tools/nsc/Settings.scala | 2 +- sources/scala/tools/nsc/ast/TreePrinters.scala | 7 +- sources/scala/tools/nsc/ast/Trees.scala | 83 ++++++----- sources/scala/tools/nsc/ast/parser/Syntactic.scala | 2 + sources/scala/tools/nsc/symtab/Definitions.scala | 1 + sources/scala/tools/nsc/symtab/Flags.scala | 69 +++++++-- sources/scala/tools/nsc/symtab/SymbolLoaders.scala | 7 +- sources/scala/tools/nsc/symtab/Symbols.scala | 22 +-- sources/scala/tools/nsc/symtab/Types.scala | 55 ++++--- sources/scala/tools/nsc/typechecker/Namers.scala | 8 +- .../scala/tools/nsc/typechecker/TypeCheckers.scala | 158 +++++++++++---------- sources/scala/tools/nsc/typechecker/Typers.scala | 4 +- 14 files changed, 266 insertions(+), 174 deletions(-) diff --git a/sources/scala/tools/nsc/Global.scala b/sources/scala/tools/nsc/Global.scala index 7ec16edf65..36b250fbc3 100755 --- a/sources/scala/tools/nsc/Global.scala +++ b/sources/scala/tools/nsc/Global.scala @@ -134,7 +134,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable val typeCheckPhase = new analyzer.TypeCheckPhase(namerPhase); val picklePhase = new pickles.PicklePhase(typeCheckPhase); - val terminalPhase = new StdPhase(typeCheckPhase) { + val terminalPhase = new StdPhase(picklePhase) { def name = "terminal"; val global: Global.this.type = Global.this; def apply(unit: CompilationUnit): unit = {} @@ -183,8 +183,12 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable if (settings.Xshowobj.value != "") showDef(newTermName(settings.Xshowobj.value), true); if (reporter.errors() == 0) { - for (val Pair(sym, pickled) <- symData.elements) - writeSymblFile(sym, pickled) + for (val Pair(sym, pickled) <- symData.elements.toList) + if (symData contains sym) { + symData -= sym; + symData -= sym.linkedSym; + writeSymblFile(sym, pickled) + } } else { for (val Pair(sym, file) <- symSource.elements) sym.reset(loaders.sourcefileLoader(file)); @@ -237,10 +241,12 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable } /** Returns the file with the given suffix for the given class. */ - private def getFile(clazz: Symbol, suffix: String) = + private def getFile(clazz: Symbol, suffix: String) = { + val outdir = settings.outdir.value; new File( - settings.outdir.value + File.separatorChar + - clazz.fullNameString(File.separatorChar) + suffix); + if (outdir == "") clazz.simpleName.toString() + suffix + else outdir + File.separatorChar + clazz.fullNameString(File.separatorChar) + suffix); + } private def writeSymblFile(clazz: Symbol, pickled: PickleBuffer) = { val file = getFile(clazz, ".symbl"); diff --git a/sources/scala/tools/nsc/Phase.scala b/sources/scala/tools/nsc/Phase.scala index c110b54134..e4c8bf3f0e 100644 --- a/sources/scala/tools/nsc/Phase.scala +++ b/sources/scala/tools/nsc/Phase.scala @@ -5,6 +5,8 @@ // $Id$ package scala.tools.nsc; +import symtab.Flags.INITIALFLAGS; + abstract class Phase(val prev: Phase) { val id: int = if (prev == null) 0 else prev.id + 1; @@ -16,7 +18,7 @@ abstract class Phase(val prev: Phase) { def name: String; def description: String = name; - val flagMask: long = if (prev == null) 0L else prev.flagMask; + val flagMask: long = if (prev == null) INITIALFLAGS else prev.flagMask; def exactMatch: boolean = false; def run: unit; diff --git a/sources/scala/tools/nsc/Settings.scala b/sources/scala/tools/nsc/Settings.scala index 409655560f..2b57cc3ebd 100644 --- a/sources/scala/tools/nsc/Settings.scala +++ b/sources/scala/tools/nsc/Settings.scala @@ -22,7 +22,7 @@ class Settings(error: String => unit) { System.getProperty("sun.boot.class.path", "")); val extdirs = StringSetting ("-extdirs", "dirs", "Override location of installed extensions", System.getProperty("java.ext.dirs", "")); - val outdir = StringSetting ("-d", "directory", "Specify where to place generated class files", "."); + val outdir = StringSetting ("-d", "directory", "Specify where to place generated class files", ""); val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", "ISO-8859-1"); val separate = ChoiceSetting ("-separate", "Read symbol files for separate compilation", List("yes","no"), "default"); val target = ChoiceSetting ("-target", "Specify which backend to use", List("jvm", "msil"), "jvm"); diff --git a/sources/scala/tools/nsc/ast/TreePrinters.scala b/sources/scala/tools/nsc/ast/TreePrinters.scala index 4f82d4a742..acc96bedfc 100644 --- a/sources/scala/tools/nsc/ast/TreePrinters.scala +++ b/sources/scala/tools/nsc/ast/TreePrinters.scala @@ -67,7 +67,7 @@ abstract class TreePrinters { } case AbsTypeDef(mods, name, lo, hi) => print(symName(tree, name)); - printOpt(">: ", lo); printOpt("<: ", hi); + printOpt(" >: ", lo); printOpt(" <: ", hi); } def printBlock(tree: Tree): unit = tree match { @@ -148,7 +148,7 @@ abstract class TreePrinters { case Template(parents, body) => printRow(parents, " with "); - if (!body.isEmpty) printColumn(body, "{", ";", "}") + if (!body.isEmpty) printColumn(body, " {", ";", "}") case Block(stats, expr) => printColumn(stats ::: List(expr), "{", ";", "}") @@ -215,7 +215,8 @@ abstract class TreePrinters { print("this"); case Select(qualifier, name) => - if (global.settings.debug.value || qualifier.symbol == null || !qualifier.symbol.isRoot) { + if (global.settings.debug.value || qualifier.symbol == null || + (!qualifier.symbol.isRoot && !qualifier.symbol.isEmptyPackageClass)) { print(qualifier); print("."); } print(symName(tree, name)) diff --git a/sources/scala/tools/nsc/ast/Trees.scala b/sources/scala/tools/nsc/ast/Trees.scala index b9a86b9bc8..7e314683be 100644 --- a/sources/scala/tools/nsc/ast/Trees.scala +++ b/sources/scala/tools/nsc/ast/Trees.scala @@ -44,6 +44,13 @@ class Trees: Global { def duplicate: Tree = new Transformer(new StrictTreeCopier) transform this; + + def copyAttrs(tree: Tree): this.type = { + pos = tree.pos; + tpe = tree.tpe; + if (hasSymbol) symbol = tree.symbol; + this + } } abstract class SymTree extends Tree { @@ -317,81 +324,81 @@ class Trees: Global { class StrictTreeCopier extends TreeCopier { def ClassDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], tpt: Tree, impl: Template) = - new ClassDef(mods, name, tparams, tpt, impl).setPos(tree.pos); + new ClassDef(mods, name, tparams, tpt, impl).copyAttrs(tree); def PackageDef(tree: Tree, name: Name, stats: List[Tree]) = - new PackageDef(name, stats).setPos(tree.pos); + new PackageDef(name, stats).copyAttrs(tree); def ModuleDef(tree: Tree, mods: int, name: Name, impl: Template) = - new ModuleDef(mods, name, impl).setPos(tree.pos); + new ModuleDef(mods, name, impl).copyAttrs(tree); def ValDef(tree: Tree, mods: int, name: Name, tpt: Tree, rhs: Tree) = - new ValDef(mods, name, tpt, rhs).setPos(tree.pos); + new ValDef(mods, name, tpt, rhs).copyAttrs(tree); def DefDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) = - new DefDef(mods, name, tparams, vparamss, tpt, rhs).setPos(tree.pos); + new DefDef(mods, name, tparams, vparamss, tpt, rhs).copyAttrs(tree); def AbsTypeDef(tree: Tree, mods: int, name: Name, lo: Tree, hi: Tree) = - new AbsTypeDef(mods, name, lo, hi).setPos(tree.pos); + new AbsTypeDef(mods, name, lo, hi).copyAttrs(tree); def AliasTypeDef(tree: Tree, mods: int, name: Name, tparams: List[AbsTypeDef], rhs: Tree) = - new AliasTypeDef(mods, name, tparams, rhs).setPos(tree.pos); + new AliasTypeDef(mods, name, tparams, rhs).copyAttrs(tree); def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree) = - new LabelDef(name, params, rhs).setPos(tree.pos); + new LabelDef(name, params, rhs).copyAttrs(tree); def Import(tree: Tree, expr: Tree, selectors: List[Pair[Name, Name]]) = - new Import(expr, selectors).setPos(tree.pos); + new Import(expr, selectors).copyAttrs(tree); def Attributed(tree: Tree, attribute: Tree, definition: Tree) = - new Attributed(attribute, definition).setPos(tree.pos); + new Attributed(attribute, definition).copyAttrs(tree); def DocDef(tree: Tree, comment: String, definition: Tree) = - new DocDef(comment, definition).setPos(tree.pos); + new DocDef(comment, definition).copyAttrs(tree); def Template(tree: Tree, parents: List[Tree], body: List[Tree]) = - new Template(parents, body).setPos(tree.pos); + new Template(parents, body).copyAttrs(tree); def Block(tree: Tree, stats: List[Tree], expr: Tree) = - new Block(stats, expr).setPos(tree.pos); + new Block(stats, expr).copyAttrs(tree); def CaseDef(tree: Tree, pat: Tree, guard: Tree, body: Tree) = - new CaseDef(pat, guard, body).setPos(tree.pos); + new CaseDef(pat, guard, body).copyAttrs(tree); def Sequence(tree: Tree, trees: List[Tree]) = - new Sequence(trees).setPos(tree.pos); + new Sequence(trees).copyAttrs(tree); def Alternative(tree: Tree, trees: List[Tree]) = - new Alternative(trees).setPos(tree.pos); + new Alternative(trees).copyAttrs(tree); def Bind(tree: Tree, name: Name, body: Tree) = - new Bind(name, body).setPos(tree.pos); + new Bind(name, body).copyAttrs(tree); def Function(tree: Tree, vparams: List[ValDef], body: Tree) = - new Function(vparams, body).setPos(tree.pos); + new Function(vparams, body).copyAttrs(tree); def Assign(tree: Tree, lhs: Tree, rhs: Tree) = - new Assign(lhs, rhs).setPos(tree.pos); + new Assign(lhs, rhs).copyAttrs(tree); def If(tree: Tree, cond: Tree, thenp: Tree, elsep: Tree) = - new If(cond, thenp, elsep).setPos(tree.pos); + new If(cond, thenp, elsep).copyAttrs(tree); def Match(tree: Tree, selector: Tree, cases: List[CaseDef]) = - new Match(selector, cases).setPos(tree.pos); + new Match(selector, cases).copyAttrs(tree); def Return(tree: Tree, expr: Tree) = - new Return(expr).setPos(tree.pos); + new Return(expr).copyAttrs(tree); def Try(tree: Tree, block: Tree, catches: List[CaseDef], finalizer: Tree) = - new Try(block, catches, finalizer).setPos(tree.pos); + new Try(block, catches, finalizer).copyAttrs(tree); def Throw(tree: Tree, expr: Tree) = - new Throw(expr).setPos(tree.pos); + new Throw(expr).copyAttrs(tree); def New(tree: Tree, tpt: Tree) = - new New(tpt).setPos(tree.pos); + new New(tpt).copyAttrs(tree); def Typed(tree: Tree, expr: Tree, tpt: Tree) = - new Typed(expr, tpt).setPos(tree.pos); + new Typed(expr, tpt).copyAttrs(tree); def TypeApply(tree: Tree, fun: Tree, args: List[Tree]) = - new TypeApply(fun, args).setPos(tree.pos); + new TypeApply(fun, args).copyAttrs(tree); def Apply(tree: Tree, fun: Tree, args: List[Tree]) = - new Apply(fun, args).setPos(tree.pos); + new Apply(fun, args).copyAttrs(tree); def Super(tree: Tree, qual: Name, mixin: Name) = - new Super(qual, mixin).setPos(tree.pos); + new Super(qual, mixin).copyAttrs(tree); def This(tree: Tree, qual: Name) = - new This(qual).setPos(tree.pos); + new This(qual).copyAttrs(tree); def Select(tree: Tree, qualifier: Tree, selector: Name) = - new Select(qualifier, selector).setPos(tree.pos); + new Select(qualifier, selector).copyAttrs(tree); def Ident(tree: Tree, name: Name) = - new Ident(name).setPos(tree.pos); + new Ident(name).copyAttrs(tree); def Literal(tree: Tree, value: Any) = - new Literal(value).setPos(tree.pos); + new Literal(value).copyAttrs(tree); def TypeTree(tree: Tree) = - new TypeTree().setPos(tree.pos); + new TypeTree().copyAttrs(tree); def SingletonTypeTree(tree: Tree, ref: Tree) = - new SingletonTypeTree(ref).setPos(tree.pos); + new SingletonTypeTree(ref).copyAttrs(tree); def SelectFromTypeTree(tree: Tree, qualifier: Tree, selector: Name) = - new SelectFromTypeTree(qualifier, selector).setPos(tree.pos); + new SelectFromTypeTree(qualifier, selector).copyAttrs(tree); def CompoundTypeTree(tree: Tree, templ: Template) = - new CompoundTypeTree(templ).setPos(tree.pos); + new CompoundTypeTree(templ).copyAttrs(tree); def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree]) = - new AppliedTypeTree(tpt, args).setPos(tree.pos) + new AppliedTypeTree(tpt, args).copyAttrs(tree) } class LazyTreeCopier(copy: TreeCopier) extends TreeCopier { diff --git a/sources/scala/tools/nsc/ast/parser/Syntactic.scala b/sources/scala/tools/nsc/ast/parser/Syntactic.scala index 1384ae1ed7..ac369fa790 100755 --- a/sources/scala/tools/nsc/ast/parser/Syntactic.scala +++ b/sources/scala/tools/nsc/ast/parser/Syntactic.scala @@ -1514,6 +1514,8 @@ abstract class Syntactic: ParserPhase { in.nextToken(); parents += simpleType(); if (in.token == LPAREN) args = argumentExprs(); + } else { + parents += scalaAnyRefConstr } parents += scalaScalaObjectConstr; if ((mods & Flags.CASE)!= 0) parents += caseClassConstr; diff --git a/sources/scala/tools/nsc/symtab/Definitions.scala b/sources/scala/tools/nsc/symtab/Definitions.scala index 33f4075b48..c3a3254cc9 100755 --- a/sources/scala/tools/nsc/symtab/Definitions.scala +++ b/sources/scala/tools/nsc/symtab/Definitions.scala @@ -15,6 +15,7 @@ abstract class Definitions: SymbolTable { var RootClass: Symbol = _; var EmptyPackage: Symbol = _; var EmptyPackageClass: Symbol = _; + var emptypackagescope: Scope = null; //debug var JavaPackage: Symbol = _; var JavaLangPackage: Symbol = _; diff --git a/sources/scala/tools/nsc/symtab/Flags.scala b/sources/scala/tools/nsc/symtab/Flags.scala index de46342a5d..fcaae4e8cf 100644 --- a/sources/scala/tools/nsc/symtab/Flags.scala +++ b/sources/scala/tools/nsc/symtab/Flags.scala @@ -60,12 +60,16 @@ object Flags { val IS_ERROR = 0x200000000l; // symbol is an error symbol val OVERLOADED = 0x400000000l; // symbol is overloaded - val TRANS_FLAG = 0x1000000000l; // transient flag guaranteed to be reset after each phase. + val TRANS_FLAG = 0x800000000l; // transient flag guaranteed to be reset after each phase. val LIFTED = TRANS_FLAG; // transient flag for lambdalift val INCONSTRUCTOR = TRANS_FLAG; // transient flag for analyzer + val INITIALFLAGS = 0x777777777l; // masks val SOURCEFLAGS = 0x00077777; // these modifiers can be set in source programs. + val EXPLICITFLAGS = // these modifiers can be explcitly in source programs. + PRIVATE | PROTECTED | ABSTRACT | FINAL | SEALED | OVERRIDE | CASE; + val ACCESSFLAGS = PRIVATE | PROTECTED; val VARIANCES = COVARIANT | CONTRAVARIANT; val CONSTRFLAGS = JAVA; @@ -74,7 +78,7 @@ object Flags { /** Flags already set by object creation and never set afterwards */ val CREATIONFLAGS = ACCESSFLAGS | METHOD | MODULE | MUTABLE | PARAM | PACKAGE | COVARIANT | CONTRAVARIANT | SYNTHETIC | STABLE | ACCESSOR | PARAMACCESSOR | LOCAL | - IS_ERROR | OVERLOADED; + IS_ERROR | OVERLOADED | INCONSTRUCTOR; /** Module flags inherited by their module-class */ val MODULE2CLASSFLAGS = ACCESSFLAGS | PACKAGE; @@ -84,17 +88,54 @@ object Flags { .map(i => flagToString(flags & (1L << i))) .filter("" !=).mkString("", " ", ""); - private def flagToString(flag: long): String = flag.asInstanceOf[int] match { - case PRIVATE => "private" - case PROTECTED => "protected" - case ABSTRACT => "abstract" - case FINAL => "final" - case SEALED => "sealed" - case TRAIT => "trait" - case OVERRIDE => "override" - case CASE => "case" - case SYNTHETIC => "" - case LOCAL => "" - case _ => "" + private def flagToString(flag: long): String = { + if (flag == INTERFACE) "" + else if (flag == IS_ERROR) "" + else if (flag == OVERLOADED) "" + else if (flag == TRANS_FLAG) "" + else flag.asInstanceOf[int] match { + case DEFERRED => "" + case FINAL => "final" + case PRIVATE => "private" + case PROTECTED => "protected" + + case SEALED => "sealed" + case OVERRIDE => "override" + case CASE => "case" + case ABSTRACT => "abstract" + + case METHOD => "" + case TRAIT => "" + case JAVA => "" + case MODULE => "" + + case MUTABLE => "" + case PARAM => "" + case PACKAGE => "" + case DEPRECATED => "" + + case COVARIANT => "" + case CONTRAVARIANT => "" + case ABSOVERRIDE => "" + case LOCAL => "" + + case SYNTHETIC => "" + case STABLE => "" + case INITIALIZED => "" + case LOCKED => "" + + case ACCESSED => "" + case SELECTOR => "" + + case CAPTURED => "" + case ACCESSOR => "" + + case ACCESS_METHOD => "" + case PARAMACCESSOR => "" + case LABEL => "