From dd8c18716aa6923d3b27ed4301478ba851fdfcf7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 17 Apr 2007 17:31:28 +0000 Subject: switched to explicit self ref syntax for some f... switched to explicit self ref syntax for some files. --- src/compiler/scala/tools/nsc/Global.scala | 37 +++++++++++----------- src/compiler/scala/tools/nsc/ast/Trees.scala | 20 ++++++------ .../scala/tools/nsc/ast/parser/Parsers.scala | 4 +-- .../scala/tools/nsc/symtab/Constants.scala | 3 +- .../scala/tools/nsc/symtab/Definitions.scala | 3 +- .../scala/tools/nsc/symtab/InfoTransformers.scala | 3 +- src/compiler/scala/tools/nsc/symtab/Scopes.scala | 3 +- src/compiler/scala/tools/nsc/symtab/StdNames.scala | 3 +- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 3 +- src/compiler/scala/tools/nsc/symtab/Types.scala | 21 ++++++++---- 10 files changed, 58 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index b78bcb9edc..811f9ae6e0 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -359,26 +359,27 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable def phaseDescriptors: List[SubComponent] = List( analyzer.namerFactory: SubComponent, // note: types are there because otherwise analyzer.typerFactory: SubComponent, // consistency check after refchecks would fail. - superAccessors, - pickler, - refchecks, - liftcode, - uncurry, - tailCalls, - explicitOuter, + superAccessors, // add super accessors + pickler, // serializes symbol tables + refchecks, // perform reference and override checking, translate nested objects + liftcode, // generate reified trees + uncurry, // uncurry, translate function values to anonymous classes + tailCalls, // replace tail calls by jumps + explicitOuter, // replace C.this by explicit outer pointers, eliminate pattern matching // checkDefined, - erasure, - lambdaLift, + erasure, // erase generic types to Java 1.4 types, add interfaces for traits + lambdaLift, // move nested functions to top level // detach, - constructors, - flatten, - mixer, - cleanup, - genicode, - inliner, - closureElimination, - deadCode, - if (forMSIL) genMSIL else genJVM, + constructors, // move field definitions into constructors + flatten, // get rid of inner classes + mixer, // do mixin composition + cleanup, // some platform-specific cleanups + + genicode, // generate portable intermediate code + inliner, // optimization: do inlining + closureElimination, // optimization: get rid of uncalled closures + deadCode, // optimization: get rid of dead cpde + if (forMSIL) genMSIL else genJVM, // generate .class files sampleTransform) protected def insertBefore(c: SubComponent, cs: List[SubComponent], before: SubComponent): List[SubComponent] = cs match { diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 42ca16ef42..cd13db5e5a 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -13,8 +13,10 @@ import scala.tools.nsc.symtab.Flags._ import scala.tools.nsc.util.{HashSet, Position, SourceFile} -trait Trees requires Global { +trait Trees { + self: Global => //statistics + var nodeCount = 0 case class Modifiers(flags: long, privateWithin: Name, annotations: List[Annotation]) { @@ -719,23 +721,23 @@ trait Trees requires Global { case EmptyTree => case PackageDef(name, stats) => case ClassDef(mods, name, tparams, self, impl) => - case ModuleDef(mods, name, impl) => (eliminated by refcheck) + case ModuleDef(mods, name, impl) => (eliminated by refcheck) case ValDef(mods, name, tpt, rhs) => case DefDef(mods, name, tparams, vparamss, tpt, rhs) => case AbsTypeDef(mods, name, tparams, lo, hi) => (eliminated by erasure) case AliasTypeDef(mods, name, tparams, rhs) => (eliminated by erasure) case LabelDef(name, params, rhs) => case Import(expr, selectors) => (eliminated by typecheck) - case Annotation(constr, elements) => (eliminated by typecheck) + case Annotation(constr, elements) => (eliminated by typecheck) case DocDef(comment, definition) => (eliminated by typecheck) case Template(parents, body) => case Block(stats, expr) => - case CaseDef(pat, guard, body) => (eliminated by transmatch) - case Sequence(trees) => (eliminated by transmatch) - case Alternative(trees) => (eliminated by transmatch) - case Star(elem) => (eliminated by transmatch) - case Bind(name, body) => (eliminated by transmatch) - case UnApply(fun: Tree, args) (introduced by typer, eliminated by transmatch) + case CaseDef(pat, guard, body) => (eliminated by transmatch/explicitouter) + case Sequence(trees) => (eliminated by transmatch/explicitouter) + case Alternative(trees) => (eliminated by transmatch/explicitouter) + case Star(elem) => (eliminated by transmatch/explicitouter) + case Bind(name, body) => (eliminated by transmatch/explicitouter) + case UnApply(fun: Tree, args) (introduced by typer, eliminated by transmatch/explicitouter) case ArrayValue(elemtpt, trees) => (introduced by uncurry) case Function(vparams, body) => (eliminated by lambdaLift) case Assign(lhs, rhs) => diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index aba8527f3b..ccb932bf0c 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2060,8 +2060,8 @@ trait Parsers requires SyntaxAnalyzer { } } - /** ClassTemplateOpt ::= [extends ClassTemplate | TemplateBody] - * TraitTemplateOpt ::= [extends TraitTemplate | TemplateBody] + /** ClassTemplateOpt ::= extends ClassTemplate | [[extends] TemplateBody] + * TraitTemplateOpt ::= extends TraitTemplate | [[extends] TemplateBody] */ def templateOpt(mods: Modifiers, name: Name, constrMods: Modifiers, vparamss: List[List[ValDef]]): (ValDef, Template) = { val pos = in.currentPos; diff --git a/src/compiler/scala/tools/nsc/symtab/Constants.scala b/src/compiler/scala/tools/nsc/symtab/Constants.scala index 8dbc4c90cb..1bc5ddc489 100644 --- a/src/compiler/scala/tools/nsc/symtab/Constants.scala +++ b/src/compiler/scala/tools/nsc/symtab/Constants.scala @@ -12,7 +12,8 @@ import compat.StringBuilder import classfile.PickleFormat._ -trait Constants requires SymbolTable { +trait Constants { + self: SymbolTable => import definitions._ diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index a2051c5acc..a16837eae9 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -10,7 +10,8 @@ import scala.collection.mutable.{HashMap, HashSet} import scala.tools.nsc.util.Position import Flags._ -trait Definitions requires SymbolTable { +trait Definitions { + self: SymbolTable => object definitions { def isDefinitionsInitialized = isInitialized diff --git a/src/compiler/scala/tools/nsc/symtab/InfoTransformers.scala b/src/compiler/scala/tools/nsc/symtab/InfoTransformers.scala index c5147f9cbb..c6d5c0891a 100644 --- a/src/compiler/scala/tools/nsc/symtab/InfoTransformers.scala +++ b/src/compiler/scala/tools/nsc/symtab/InfoTransformers.scala @@ -6,7 +6,8 @@ package scala.tools.nsc.symtab -trait InfoTransformers requires SymbolTable { +trait InfoTransformers { + self: SymbolTable => abstract class InfoTransformer { var prev: InfoTransformer = this diff --git a/src/compiler/scala/tools/nsc/symtab/Scopes.scala b/src/compiler/scala/tools/nsc/symtab/Scopes.scala index 6d66875474..33d8407c16 100644 --- a/src/compiler/scala/tools/nsc/symtab/Scopes.scala +++ b/src/compiler/scala/tools/nsc/symtab/Scopes.scala @@ -6,7 +6,8 @@ package scala.tools.nsc.symtab -trait Scopes requires SymbolTable { +trait Scopes { + self: SymbolTable => class ScopeEntry(val sym: Symbol, val owner: Scope) { /** hook to notify IDE that new symbol has been added to this scope */ diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala index 2407ba28eb..6c1398b6fe 100644 --- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala +++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala @@ -8,7 +8,8 @@ package scala.tools.nsc.symtab import scala.tools.nsc.util.NameTransformer -trait StdNames requires SymbolTable { +trait StdNames { + self: SymbolTable => object nme { diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index e9b62f1b99..9c93de816a 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -10,7 +10,8 @@ import scala.tools.nsc.io.AbstractFile import scala.tools.nsc.util.{Position, SourceFile} import Flags._ -trait Symbols requires SymbolTable { +trait Symbols { + self: SymbolTable => import definitions._ private var ids = 0 diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 71c97bef15..de4c8c3fbb 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -32,7 +32,8 @@ import Flags._ case AnnotatedType(attribs, tp) => */ -trait Types requires SymbolTable { +trait Types { + self: SymbolTable => import definitions._ //statistics @@ -2723,17 +2724,23 @@ trait Types requires SymbolTable { case ts => try { val glbOwner = commonOwner(ts) - val glbBase = intersectionType(ts, glbOwner) + def refinedToParents(t: Type): List[Type] = t match { + case RefinedType(ps, _) => ps flatMap refinedToParents + case _ => List(t) + } + val ts1 = ts flatMap refinedToParents + val glbBase = intersectionType(ts1, glbOwner) if (phase.erasedTypes || depth == 0) glbBase else { - val glbType = refinedType(ts, glbOwner) + val glbType = refinedType(ts1, glbOwner) val glbThisType = glbType.symbol.thisType def glbsym(proto: Symbol): Symbol = try { val prototp = glbThisType.memberInfo(proto) - val syms = for ( - val t <- ts; - val alt <- t.nonPrivateMember(proto.name).alternatives; - glbThisType.memberInfo(alt) matches prototp) yield alt; + val syms = for { + val t <- ts + val alt <- t.nonPrivateMember(proto.name).alternatives + glbThisType.memberInfo(alt) matches prototp + } yield alt val symtypes = syms map glbThisType.memberInfo assert(!symtypes.isEmpty) proto.cloneSymbol(glbType.symbol).setInfo( -- cgit v1.2.3