aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-02-06 21:37:01 +0100
committerMartin Odersky <odersky@gmail.com>2013-02-06 21:37:01 +0100
commit401fae7d1ccd6bcd523dccd28f2e29090eaec1ef (patch)
treec3fe8453ee1c1fb526f89e05d4f7881726da5594 /src/dotty
parent831abc1fd1bbebfdfdec1a5693cbfc0bac613c62 (diff)
downloaddotty-401fae7d1ccd6bcd523dccd28f2e29090eaec1ef.tar.gz
dotty-401fae7d1ccd6bcd523dccd28f2e29090eaec1ef.tar.bz2
dotty-401fae7d1ccd6bcd523dccd28f2e29090eaec1ef.zip
Some progress in printing things.
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala27
-rw-r--r--src/dotty/tools/dotc/core/Flags.scala3
-rw-r--r--src/dotty/tools/dotc/core/Printers.scala95
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala3
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala11
5 files changed, 113 insertions, 26 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index b1b047847..36ac8d7af 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -48,9 +48,15 @@ object Contexts {
_typeComparer
}
- private[this] var _printer: Context => Printer = _
- protected def printer_=(printer: Context => Printer) = _printer = printer
- def printer: Context => Printer = _printer
+ private[this] var _plainPrinter: Context => Printer = _
+ protected def plainPrinter_=(plainPrinter: Context => Printer) = _plainPrinter = plainPrinter
+ def plainPrinter: Context => Printer = _plainPrinter
+
+ private[this] var _refinedPrinter: Context => Printer = _
+ protected def refinedPrinter_=(refinedPrinter: Context => Printer) = _refinedPrinter = refinedPrinter
+ def refinedPrinter: Context => Printer = _refinedPrinter
+
+ def printer = if (base.settings.debug.value) plainPrinter else refinedPrinter
private[this] var _owner: Symbol = _
protected def owner_=(owner: Symbol) = _owner = owner
@@ -75,7 +81,8 @@ object Contexts {
if (_condensed == null)
_condensed = base.initialCtx.fresh
.withPeriod(period)
- .withPrinter(printer)
+ .withPlainPrinter(plainPrinter)
+ .withRefinedPrinter(refinedPrinter)
.withSettings(sstate)
_condensed
}
@@ -94,7 +101,8 @@ object Contexts {
def withPeriod(period: Period): this.type = { this.period = period; this }
def withPhase(pid: PhaseId): this.type = withPeriod(Period(runId, pid))
def withConstraints(constraints: Constraints): this.type = { this.constraints = constraints; this }
- def withPrinter(printer: Context => Printer): this.type = { this.printer = printer; this }
+ def withPlainPrinter(printer: Context => Printer): this.type = { this.plainPrinter = printer; this }
+ def withRefinedPrinter(printer: Context => Printer): this.type = { this.refinedPrinter = printer; this }
def withOwner(owner: Symbol): this.type = { this.owner = owner; this }
def withSettings(sstate: SettingsState): this.type = { this.sstate = sstate; this }
def withDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this }
@@ -104,7 +112,8 @@ object Contexts {
underlying = NoContext
period = Nowhere
constraints = Map()
- printer = new StdPrinter()(_)
+ plainPrinter = new PlainPrinter(_)
+ refinedPrinter = new RefinedPrinter(_)
owner = NoSymbol
}
@@ -134,6 +143,12 @@ object Contexts {
class ContextState {
// Symbols state
+
+ /** A counter for unique ids */
+ private[core] var _nextId = 0
+
+ def nextId = { _nextId += 1; _nextId }
+
/** A map from a superclass id to the class that has it */
private[core] var classOfId = new Array[ClassSymbol](InitialSuperIdsSize)
diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala
index a2158a46a..36c29ccf0 100644
--- a/src/dotty/tools/dotc/core/Flags.scala
+++ b/src/dotty/tools/dotc/core/Flags.scala
@@ -316,6 +316,9 @@ object Flags {
/** Symbol is a method which should be marked ACC_SYNCHRONIZED */
final val Synchronized = termFlag(???, "<synchronized>")
+ /** Symbol's name is expanded */
+ final val ExpandedName = commonFlag(???, "<expandedname>")
+
/** Symbol should be ignored when typechecking; will be marked ACC_SYNTHETIC in bytecode */
final val Artifact = commonFlag(???, "<artifact>")
diff --git a/src/dotty/tools/dotc/core/Printers.scala b/src/dotty/tools/dotc/core/Printers.scala
index a35b0b797..e956a3a53 100644
--- a/src/dotty/tools/dotc/core/Printers.scala
+++ b/src/dotty/tools/dotc/core/Printers.scala
@@ -1,7 +1,7 @@
package dotty.tools.dotc
package core
-import Types._, Symbols._, Contexts._, Scopes._, Names._
+import Types._, Symbols._, Contexts._, Scopes._, Names._, NameOps._, Flags._
trait Printers { this: Context =>
@@ -40,10 +40,19 @@ object Printers {
def show(sc: Scope): String
def show(syms: List[Symbol], sep: String): String
def showNameDetailed(name: Name): String
+ def showFullName(sym: Symbol): String
+
+ /** String representation of symbol's simple name.
+ * If !settings.debug translates expansions of operators back to operator symbol.
+ * E.g. $eq => =.
+ * If settings.uniqid, adds id.
+ * If settings.Yshowsymkinds, adds abbreviated symbol kind.
+ */
+ def showName(sym: Symbol): String
}
- class StdPrinter(implicit ctx: Context) extends Printer {
-
+ class PlainPrinter(_ctx: Context) extends Printer {
+ protected[this] implicit val ctx = _ctx
def controlled(op: => String): String =
if (ctx.showRecursions < maxShowRecursions)
try {
@@ -53,22 +62,25 @@ object Printers {
ctx.showRecursions -= 1
}
else {
- if (ctx.debug) {
- ctx.warning("Exceeded recursion depth attempting to print type.")
- (new Throwable).printStackTrace
- }
+ recursionLimitExceeeded()
"..."
}
- def show(tp: Type): String = controlled {
- tp match {
- case TermRef(pre, name) =>
- ??? // showPrefix(pre) + show(name)
+ protected def recursionLimitExceeeded() = {
+ ctx.warning("Exceeded recursion depth attempting to print type.")
+ (new Throwable).printStackTrace
+ }
+ protected def showSimpleName(sym: Symbol) = sym.originalName.decode
+ def showName(sym: Symbol): String =
+ showSimpleName(sym) + (if (ctx.settings.uniqid.value) "#" + sym.id else "")
- }
- }
+ def showFullName(sym: Symbol): String =
+ if (sym.isRoot || sym == NoSymbol || sym.owner.isEffectiveRoot)
+ showName(sym)
+ else
+ showFullName(sym.effectiveOwner.enclosingClass) + "." + showName(sym)
protected def objectPrefix = "object "
protected def packagePrefix = "package "
@@ -80,28 +92,51 @@ object Printers {
(defn.UnqualifiedOwners contains sym) || isEmptyPrefix(sym)
protected def isEmptyPrefix(sym: Symbol) =
- sym.isEffectiveRoot || sym.isAnonymousClass || ??? // nme.isReplWrapperName(sym.name)
-
+ sym.isEffectiveRoot || sym.isAnonymousClass || sym.name.isReplWrapperName
def showPrefix(tp: Type): String = controlled {
tp match {
+ case RefinedThis(_) =>
+ "this."
case ThisType(cls) =>
- if (ctx.debug) showName(cls) + ".this."
- else if (cls.isAnonymousClass) "this."
- else ???
+ showName(cls) + ".this."
+ case SuperType(thistpe, _) =>
+ showPrefix(thistpe).replaceAll("""\bthis\.$""", "super.")
+ case tp @ TermRef(pre, name) =>
+ val sym = tp.symbol
+ if (!sym.exists) showPrefix(pre) + name + "."
+ else showPrefix(pre) + showName(sym) + "."
+ case MethodParam(mt, idx) =>
+ mt.paramNames(idx) + "."
case NoPrefix =>
""
+ case ConstantType(value) =>
+ "(" + value + ")."
case _ =>
trimPrefix(show(tp)) + "#"
+ }
+ }
+
+ def show(tp: Type): String = controlled {
+ tp match {
+ case tp: SingletonType =>
+ val str = showPrefix(tp)
+ if (str.endsWith(".")) str + "type"
+ else showFullName(tp.underlying.typeSymbol.skipPackageObject) + ".type"
+ case
+ TermRef(pre, name) =>
+ ??? // showPrefix(pre) + show(name)
+
+
}
}
+
def show(sym: Symbol): String = controlled {
???
}
- def showName(sym: Symbol): String = ???
def showLocated(sym: Symbol): String = ???
def showDef(sym: Symbol): String = ???
def show(sc: Scope): String =
@@ -112,9 +147,29 @@ object Printers {
def showNameDetailed(name: Name): String =
(if (name.isTypeName) "type " else "term ") + name
+ }
+
+ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
+ override protected def recursionLimitExceeeded() = {}
+ override protected def showSimpleName(sym: Symbol) = sym.name.toString
+
+ override def showPrefix(tp: Type): String = controlled {
+ tp match {
+ case ThisType(cls) =>
+ if (cls.isAnonymousClass) return "this."
+ if (isOmittablePrefix(cls)) return ""
+ if (cls.isModuleClass) return showFullName(cls) + "."
+ case tp @ TermRef(pre, name) =>
+ val sym = tp.symbol
+ if (sym is PackageObject) return showPrefix(pre)
+ if (isOmittablePrefix(sym)) return ""
+ case _ =>
+ }
+ super.showPrefix(tp)
+ }
}
- final val maxShowRecursions = 50
+ final val maxShowRecursions = 100
} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 5e2ff4dfa..9319e1573 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -78,6 +78,9 @@ object SymDenotations {
/** is this denotation a method? */
//def isMethod: Boolean = false
+ def originalName =
+ if (flags is ExpandedName) initial.asSymDenotation.name else name
+
def isSubClass(cls: Symbol)(implicit ctx: Context) = false
def isNonBottomSubClass(cls: Symbol)(implicit ctx: Context) = false
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index 5f60922ee..6c267da62 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -145,6 +145,14 @@ object Symbols {
denot
}
+ private[this] var _id: Int = _
+
+ /** The unique id of this symbol */
+ def id(implicit ctx: Context) = {
+ if (_id == 0) _id = ctx.nextId
+ _id
+ }
+
/** Subclass tests and casts */
final def isTerm: Boolean = isInstanceOf[TermSymbol]
final def isType: Boolean = isInstanceOf[TypeSymbol]
@@ -201,6 +209,9 @@ object Symbols {
/** The current annotations of this symbol */
final def annotations(implicit ctx: Context): List[Annotation] = denot.annotations
+ /** The name with which this symbol was created */
+ def originalName(implicit ctx: Context) = denot.originalName
+
/** Set given flags(s) of this symbol */
def setFlag(flags: FlagSet)(implicit ctx: Context): Unit = denot.setFlag(flags)