diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2017-02-18 23:58:49 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2017-02-19 00:00:19 +0100 |
commit | 5b330f1fea7a4c7ad3a33c237e99cc31fabfba59 (patch) | |
tree | 73a88e3b385f850fa108e7a4099979336c78513d | |
parent | 42e112b92a526bb9352febb14d8af48138bcfb87 (diff) | |
download | dotty-5b330f1fea7a4c7ad3a33c237e99cc31fabfba59.tar.gz dotty-5b330f1fea7a4c7ad3a33c237e99cc31fabfba59.tar.bz2 dotty-5b330f1fea7a4c7ad3a33c237e99cc31fabfba59.zip |
ImportInfo: removed ctx parameter from constructor
ImportInfo#toString required the ctx parameter,so it was replaced by
ImportInfo#toText.
4 files changed, 34 insertions, 19 deletions
diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index ac25f7cfd..b6d595b9c 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -7,6 +7,7 @@ import Contexts.Context, Scopes.Scope, Denotations.Denotation, Annotations.Annot import StdNames.{nme, tpnme} import ast.Trees._, ast._ import typer.Implicits._ +import typer.ImportInfo import config.Config import java.lang.Integer.toOctalString import config.Config.summarizeDepth @@ -502,6 +503,17 @@ class PlainPrinter(_ctx: Context) extends Printer { "?Unknown Implicit Result?" } + def toText(importInfo: ImportInfo): Text = { + val siteStr = importInfo.site.show + val exprStr = if (siteStr endsWith ".type") siteStr dropRight 5 else siteStr + val selectorStr = importInfo.selectors match { + case Ident(name) :: Nil => name.show + case _ => "{...}" + } + s"import $exprStr.$selectorStr" + } + + private var maxSummarized = Int.MaxValue def summarized[T](depth: Int)(op: => T): T = { diff --git a/compiler/src/dotty/tools/dotc/printing/Printer.scala b/compiler/src/dotty/tools/dotc/printing/Printer.scala index 506773a4b..e163a83f3 100644 --- a/compiler/src/dotty/tools/dotc/printing/Printer.scala +++ b/compiler/src/dotty/tools/dotc/printing/Printer.scala @@ -6,6 +6,7 @@ import Texts._, ast.Trees._ import Types.Type, Symbols.Symbol, Contexts.Context, Scopes.Scope, Constants.Constant, Names.Name, Denotations._, Annotations.Annotation import typer.Implicits.SearchResult +import typer.ImportInfo /** The base class of all printers */ @@ -98,6 +99,9 @@ abstract class Printer { /** Textual representation of implicit search result */ def toText(result: SearchResult): Text + /** Textual representation of info relating to an import clause */ + def toText(result: ImportInfo): Text + /** Perform string or text-producing operation `op` so that only a * summarized text with given recursion depth is shown */ diff --git a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala index 3ba610ef2..3bee0bbe8 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -5,6 +5,7 @@ package typer import ast.{tpd, untpd} import ast.Trees._ import core._ +import printing.{Printer, Showable} import util.SimpleMap import Symbols._, Names._, Denotations._, Types._, Contexts._, StdNames._, Flags._ import Decorators.StringInterpolators @@ -28,7 +29,7 @@ object ImportInfo { * scala.Predef or dotty.DottyPredef in the start context, false otherwise. */ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree], - symNameOpt: Option[TermName], val isRootImport: Boolean = false)(implicit ctx: Context) { + symNameOpt: Option[TermName], val isRootImport: Boolean = false) extends Showable { // Dotty deviation: we cannot use a lazy val here for the same reason // that we cannot use one for `DottyPredefModuleRef`. @@ -91,7 +92,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree], } /** The implicit references imported by this import clause */ - def importedImplicits: List[TermRef] = { + def importedImplicits(implicit ctx: Context): List[TermRef] = { val pre = site if (isWildcardImport) { val refs = pre.implicitMembers @@ -115,23 +116,21 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree], * override import Predef.{any2stringAdd => _, StringAdd => _, _} // disables String + * override import java.lang.{} // disables all imports */ - lazy val unimported: Symbol = { - lazy val sym = site.termSymbol - def maybeShadowsRoot = symNameOpt match { - case Some(symName) => defn.ShadowableImportNames.contains(symName) - case None => false + def unimported(implicit ctx: Context): Symbol = { + if (myUnimported == null) { + lazy val sym = site.termSymbol + def maybeShadowsRoot = symNameOpt match { + case Some(symName) => defn.ShadowableImportNames.contains(symName) + case None => false + } + myUnimported = + if (maybeShadowsRoot && defn.RootImportTypes.exists(_.symbol == sym)) sym + else NoSymbol + assert(myUnimported != null) } - if (maybeShadowsRoot && defn.RootImportTypes.exists(_.symbol == sym)) sym - else NoSymbol + myUnimported } + private[this] var myUnimported: Symbol = _ - override def toString = { - val siteStr = site.show - val exprStr = if (siteStr endsWith ".type") siteStr dropRight 5 else siteStr - val selectorStr = selectors match { - case Ident(name) :: Nil => name.show - case _ => "{...}" - } - i"import $exprStr.$selectorStr" - } + def toText(printer: Printer) = printer.toText(this) } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 498fd001b..f97bb5a78 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -145,7 +145,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit */ def bindingString(prec: Int, whereFound: Context, qualifier: String = "") = if (prec == wildImport || prec == namedImport) { - ex"""imported$qualifier by ${hl"${whereFound.importInfo.toString}"}""" + ex"""imported$qualifier by ${hl"${whereFound.importInfo}"}""" } else ex"""defined$qualifier in ${hl"${whereFound.owner.toString}"}""" |