From 88a3cc9b2f5b6910b812d188a52e9e5c6abd5295 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 10 Jan 2012 11:19:05 -0800 Subject: Rescued some import-related code. So I can get at it from the repl. --- src/compiler/scala/tools/nsc/ast/TreeGen.scala | 19 ++++++++++++++++ .../scala/tools/nsc/typechecker/Contexts.scala | 25 +++++++++------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index e69c463e71..144322e4f5 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -30,6 +30,25 @@ abstract class TreeGen extends reflect.internal.TreeGen { else tree } + + /** Builds a fully attributed wildcard import node. + */ + def mkWildcardImport(pkg: Symbol): Import = { + assert(pkg ne null, this) + val qual = gen.mkAttributedStableRef(pkg) + val importSym = ( + NoSymbol + newImport NoPosition + setFlag SYNTHETIC + setInfo analyzer.ImportType(qual) + ) + val importTree = ( + Import(qual, List(ImportSelector(nme.WILDCARD, -1, null, -1))) + setSymbol importSym + setType NoType + ) + importTree + } // wrap the given expression in a SoftReference so it can be gc-ed def mkSoftRef(expr: Tree): Tree = atPos(expr.pos) { diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 1d9eb9c292..f199195b81 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -42,11 +42,11 @@ trait Contexts { self: Analyzer => * * - if option `-Yno-imports` is given, nothing is imported * - if the unit is java defined, only `java.lang` is imported - * - if option `-Yno-predef` is given, if the unit has an import of Predef - * among its leading imports, or if the unit is [[scala.ScalaObject]] + * - if option `-Yno-predef` is given, if the unit body has an import of Predef + * among its leading imports, or if the tree is [[scala.ScalaObject]] * or [[scala.Predef]], `Predef` is not imported. */ - protected def rootImports(unit: CompilationUnit, tree: Tree): List[Symbol] = { + protected def rootImports(unit: CompilationUnit): List[Symbol] = { import definitions._ assert(isDefinitionsInitialized, "definitions uninitialized") @@ -56,23 +56,15 @@ trait Contexts { self: Analyzer => else List(JavaLangPackage, ScalaPackage, PredefModule) } - def rootContext(unit: CompilationUnit): Context = - rootContext(unit, EmptyTree, false) - + def rootContext(unit: CompilationUnit): Context = rootContext(unit, EmptyTree, false) + def rootContext(unit: CompilationUnit, tree: Tree): Context = rootContext(unit, tree, false) def rootContext(unit: CompilationUnit, tree: Tree, erasedTypes: Boolean): Context = { import definitions._ var sc = startContext - def addImport(pkg: Symbol) { - assert(pkg ne null) - val qual = gen.mkAttributedStableRef(pkg) - sc = sc.makeNewImport( - Import(qual, List(ImportSelector(nme.WILDCARD, -1, null, -1))) - .setSymbol(NoSymbol.newImport(NoPosition).setFlag(SYNTHETIC).setInfo(ImportType(qual))) - .setType(NoType)) + for (sym <- rootImports(unit)) { + sc = sc.makeNewImport(sym) sc.depth += 1 } - for (imp <- rootImports(unit, tree)) - addImport(imp) val c = sc.make(unit, tree, sc.owner, sc.scope, sc.imports) c.reportAmbiguousErrors = !erasedTypes c.reportGeneralErrors = !erasedTypes @@ -207,6 +199,9 @@ trait Contexts { self: Analyzer => c.implicitsEnabled = true c } + + def makeNewImport(sym: Symbol): Context = + makeNewImport(gen.mkWildcardImport(sym)) def makeNewImport(imp: Import): Context = make(unit, imp, owner, scope, new ImportInfo(imp, depth) :: imports) -- cgit v1.2.3