summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-01-10 11:19:05 -0800
committerPaul Phillips <paulp@improving.org>2012-01-10 11:19:05 -0800
commit88a3cc9b2f5b6910b812d188a52e9e5c6abd5295 (patch)
treeef6e1aeb7818e7276dcde145bee840cc6700fcd9 /src
parent25fcbd7021cad1e3c7b50c2b8f5c586008579bf9 (diff)
downloadscala-88a3cc9b2f5b6910b812d188a52e9e5c6abd5295.tar.gz
scala-88a3cc9b2f5b6910b812d188a52e9e5c6abd5295.tar.bz2
scala-88a3cc9b2f5b6910b812d188a52e9e5c6abd5295.zip
Rescued some import-related code.
So I can get at it from the repl.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala19
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala25
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)