From 866ee8665147f91bee617465d04a08ff7b874baf Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 9 Feb 2014 18:44:41 +0100 Subject: Symbol loaders no longer complete with creation context Instead current ctx is passed through everywhere. Question: can we factor out ctx better? --- src/dotty/tools/dotc/core/SymbolLoaders.scala | 51 +++++++++++++-------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'src/dotty/tools/dotc/core/SymbolLoaders.scala') diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index d1eb2872c..6161d0e57 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -46,7 +46,7 @@ class SymbolLoaders { */ def enterModule( owner: Symbol, name: PreName, completer: SymbolLoader, - modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(implicit ctx: CondensedContext): Symbol = { + modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(implicit ctx: Context): Symbol = { val module = ctx.newModuleSymbol( owner, name.toTermName, modFlags, clsFlags, (modul, _) => completer.proxy withDecls newScope withSourceModule modul, @@ -58,7 +58,7 @@ class SymbolLoaders { /** Enter package with given `name` into scope of `owner` * and give them `completer` as type. */ - def enterPackage(owner: Symbol, pkg: ClassPath)(implicit ctx: CondensedContext): Symbol = { + def enterPackage(owner: Symbol, pkg: ClassPath)(implicit ctx: Context): Symbol = { val pname = pkg.name.toTermName val preExisting = owner.info.decls lookup pname if (preExisting != NoSymbol) { @@ -90,7 +90,7 @@ class SymbolLoaders { */ def enterClassAndModule( owner: Symbol, name: PreName, completer: SymbolLoader, - flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(implicit ctx: CondensedContext): Unit = { + flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(implicit ctx: Context): Unit = { val clazz = enterClass(owner, name, completer, flags, scope) val module = enterModule( owner, name, completer, @@ -107,8 +107,8 @@ class SymbolLoaders { */ def enterToplevelsFromSource( owner: Symbol, name: PreName, src: AbstractFile, - scope: Scope = EmptyScope)(implicit ctx: CondensedContext): Unit = { - enterClassAndModule(owner, name, new SourcefileLoader(src)(ctx.condensed), scope = scope) + scope: Scope = EmptyScope)(implicit ctx: Context): Unit = { + enterClassAndModule(owner, name, new SourcefileLoader(src), scope = scope) } /** The package objects of scala and scala.reflect should always @@ -124,7 +124,7 @@ class SymbolLoaders { /** Initialize toplevel class and module symbols in `owner` from class path representation `classRep` */ - def initializeFromClassPath(owner: Symbol, classRep: ClassPath#ClassRep)(implicit ctx: CondensedContext): Unit = { + def initializeFromClassPath(owner: Symbol, classRep: ClassPath#ClassRep)(implicit ctx: Context): Unit = { ((classRep.binary, classRep.source): @unchecked) match { case (Some(bin), Some(src)) if needCompile(bin, src) && !binaryOnly(owner, classRep.name) => if (ctx.settings.verbose.value) ctx.inform("[symloader] picked up newer source file for " + src.path) @@ -142,15 +142,15 @@ class SymbolLoaders { /** Load contents of a package */ - class PackageLoader(override val sourceModule: TermSymbol, classpath: ClassPath)(implicit val cctx: CondensedContext) + class PackageLoader(override val sourceModule: TermSymbol, classpath: ClassPath) extends SymbolLoader { def description = "package loader " + classpath.name private[core] val preDecls: MutableScope = newScope - def doComplete(root: SymDenotation): Unit = { + def doComplete(root: SymDenotation)(implicit ctx: Context): Unit = { assert(root is PackageClass, root) - def maybeModuleClass(classRep: ClassPath#ClassRep) = classRep.name.last == '$' + def maybeModuleClass(classRep: ClassPath#ClassRep) = classRep.name.last == '$' val pre = root.owner.thisType root.info = ClassInfo(pre, root.symbol.asClass, Nil, preDecls, pre select sourceModule) if (!sourceModule.isCompleted) @@ -173,11 +173,10 @@ class SymbolLoaders { /** A lazy type that completes itself by calling parameter doComplete. * Any linked modules/classes or module classes are also initialized. */ -abstract class SymbolLoader extends LazyType with CompleteInCreationContext { - implicit val cctx: CondensedContext +abstract class SymbolLoader extends LazyType { /** Load source or class file for `root`, return */ - def doComplete(root: SymDenotation): Unit + def doComplete(root: SymDenotation)(implicit ctx: Context): Unit def sourceFileOrNull: AbstractFile = null @@ -186,23 +185,23 @@ abstract class SymbolLoader extends LazyType with CompleteInCreationContext { */ def description: String - override def completeInCreationContext(root: SymDenotation): Unit = { + override def complete(root: SymDenotation)(implicit ctx: Context): Unit = { def signalError(ex: Exception): Unit = { - if (cctx.debug) ex.printStackTrace() + if (ctx.debug) ex.printStackTrace() val msg = ex.getMessage() - cctx.error( + ctx.error( if (msg eq null) "i/o error while loading " + root.name else "error while loading " + root.name + ",\n " + msg) } try { val start = currentTime - if (cctx.settings.debugTrace.value) - cctx.traceIndented(s">>>> loading ${root.debugString}", _ => s"<<<< loaded ${root.debugString}") { + if (ctx.settings.debugTrace.value) + ctx.traceIndented(s">>>> loading ${root.debugString}", _ => s"<<<< loaded ${root.debugString}") { doComplete(root) } else doComplete(root) - cctx.informTime("loaded " + description, start) + ctx.informTime("loaded " + description, start) } catch { case ex: IOException => signalError(ex) @@ -221,13 +220,13 @@ abstract class SymbolLoader extends LazyType with CompleteInCreationContext { } } -class ClassfileLoader(val classfile: AbstractFile)(implicit val cctx: CondensedContext) extends SymbolLoader { +class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader { override def sourceFileOrNull: AbstractFile = classfile def description = "class file "+ classfile.toString - def rootDenots(rootDenot: ClassDenotation): (ClassDenotation, ClassDenotation) = { + def rootDenots(rootDenot: ClassDenotation)(implicit ctx: Context): (ClassDenotation, ClassDenotation) = { val linkedDenot = rootDenot.linkedClass.denot match { case d: ClassDenotation => d case d => @@ -237,11 +236,11 @@ class ClassfileLoader(val classfile: AbstractFile)(implicit val cctx: CondensedC // An example for this situation is scala.reflect.Manifest, which exists // as a class in scala.reflect and as a val in scala.reflect.package. if (rootDenot is ModuleClass) - cctx.newClassSymbol( + ctx.newClassSymbol( rootDenot.owner, rootDenot.name.stripModuleClassSuffix.asTypeName, Synthetic, _ => NoType).classDenot else - cctx.newModuleSymbol( + ctx.newModuleSymbol( rootDenot.owner, rootDenot.name.toTermName, Synthetic, Synthetic, (module, _) => new NoCompleter() withDecls newScope withSourceModule module) .moduleClass.denot.asClass @@ -250,14 +249,14 @@ class ClassfileLoader(val classfile: AbstractFile)(implicit val cctx: CondensedC else (rootDenot, linkedDenot) } - def doComplete(root: SymDenotation): Unit = { + def doComplete(root: SymDenotation)(implicit ctx: Context): Unit = { val (classRoot, moduleRoot) = rootDenots(root.asClass) - new ClassfileParser(classfile, classRoot, moduleRoot)(cctx).run() + new ClassfileParser(classfile, classRoot, moduleRoot)(ctx).run() } } -class SourcefileLoader(val srcfile: AbstractFile)(implicit val cctx: CondensedContext) extends SymbolLoader { +class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader { def description = "source file "+ srcfile.toString override def sourceFileOrNull = srcfile - def doComplete(root: SymDenotation): Unit = unsupported("doComplete") + def doComplete(root: SymDenotation)(implicit ctx: Context): Unit = unsupported("doComplete") } -- cgit v1.2.3