aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/printing
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-06-29 20:00:59 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-11 13:35:02 +0200
commit60d81f81ddfc85719fd303e8d15d3891adbf4dfd (patch)
tree17e830e9e73157451c1a46ba2d716ca0d1037f97 /src/dotty/tools/dotc/printing
parentd1f809f14cad2c14c312767d71361c7f2e7d8244 (diff)
downloaddotty-60d81f81ddfc85719fd303e8d15d3891adbf4dfd.tar.gz
dotty-60d81f81ddfc85719fd303e8d15d3891adbf4dfd.tar.bz2
dotty-60d81f81ddfc85719fd303e8d15d3891adbf4dfd.zip
Start new, direct HK scheme
- Re-introduce newHK option. Label some things that will be removed with OLD.
Diffstat (limited to 'src/dotty/tools/dotc/printing')
-rw-r--r--src/dotty/tools/dotc/printing/PlainPrinter.scala35
-rw-r--r--src/dotty/tools/dotc/printing/RefinedPrinter.scala29
2 files changed, 35 insertions, 29 deletions
diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala
index a8888fd3c..07819ef77 100644
--- a/src/dotty/tools/dotc/printing/PlainPrinter.scala
+++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala
@@ -6,6 +6,7 @@ import Texts._, Types._, Flags._, Names._, Symbols._, NameOps._, Constants._, De
import Contexts.Context, Scopes.Scope, Denotations.Denotation, Annotations.Annotation
import StdNames.{nme, tpnme}
import ast.Trees._, ast._
+import config.Config
import java.lang.Integer.toOctalString
import config.Config.summarizeDepth
import scala.annotation.switch
@@ -50,8 +51,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
homogenize(tp1) & homogenize(tp2)
case OrType(tp1, tp2) =>
homogenize(tp1) | homogenize(tp2)
- case tp: RefinedType =>
- tp.normalizeHkApply
+ case tp: RefinedType if !Config.newHK =>
+ tp.normalizeHkApplyOLD
case tp: SkolemType =>
homogenize(tp.info)
case tp: LazyRef =>
@@ -110,6 +111,30 @@ class PlainPrinter(_ctx: Context) extends Printer {
protected def toTextRefinement(rt: RefinedType) =
(refinementNameString(rt) ~ toTextRHS(rt.refinedInfo)).close
+ protected def argText(arg: Type): Text = arg match {
+ case arg: TypeBounds => "_" ~ toTextGlobal(arg)
+ case _ => toTextGlobal(arg)
+ }
+
+ /** The text for a TypeLambda
+ *
+ * [v_1 p_1: B_1, ..., v_n p_n: B_n] -> T
+ *
+ * where
+ * @param paramNames = p_1, ..., p_n
+ * @param variances = v_1, ..., v_n
+ * @param argBoundss = B_1, ..., B_n
+ * @param body = T
+ */
+ protected def typeLambdaText(paramNames: List[String], variances: List[Int], argBoundss: List[TypeBounds], body: Type): Text = {
+ def lambdaParamText(variance: Int, name: String, bounds: TypeBounds): Text =
+ varianceString(variance) ~ name ~ toText(bounds)
+ changePrec(GlobalPrec) {
+ "[" ~ Text((variances, paramNames, argBoundss).zipped.map(lambdaParamText), ", ") ~
+ "] -> " ~ toTextGlobal(body)
+ }
+ }
+
/** The longest sequence of refinement types, starting at given type
* and following parents.
*/
@@ -174,6 +199,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
toText(polyParamName(pt.paramNames(n))) ~ polyHash(pt)
case AnnotatedType(tpe, annot) =>
toTextLocal(tpe) ~ " " ~ toText(annot)
+ case tp: TypeLambda =>
+ typeLambdaText(tp.paramNames.map(_.toString), tp.variances, tp.paramBounds, tp.resultType)
+ case HKApply(tycon, args) =>
+ toTextLocal(tycon) ~ "[!" ~ Text(args.map(argText), ", ") ~ "]"
case tp: TypeVar =>
if (tp.isInstantiated)
toTextLocal(tp.instanceOpt) ~ "'" // debug for now, so that we can see where the TypeVars are.
@@ -186,7 +215,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
else toText(tp.origin)
}
case tp: LazyRef =>
- "LazyRef(" ~ toTextGlobal(tp.ref) ~ ")"
+ "LazyRef(" ~ toTextGlobal(tp.ref) ~ ")" // TODO: only print this during debug mode?
case _ =>
tp.fallbackToText(this)
}
diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
index 3da977b31..91f896da2 100644
--- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala
+++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala
@@ -95,10 +95,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
}
override def toText(tp: Type): Text = controlled {
- def argText(arg: Type): Text = arg match {
- case arg: TypeBounds => "_" ~ toTextGlobal(arg)
- case _ => toTextGlobal(arg)
- }
def toTextTuple(args: List[Type]): Text =
"(" ~ toTextGlobal(args, ", ") ~ ")"
def toTextFunction(args: List[Type]): Text =
@@ -117,7 +113,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
if (defn.isFunctionClass(cls)) return toTextFunction(args)
if (defn.isTupleClass(cls)) return toTextTuple(args)
return (toTextLocal(tycon) ~ "[" ~ Text(args map argText, ", ") ~ "]").close
- case tp @ TypeLambda(argBoundss, body) =>
+ case tp @ TypeLambdaOLD(argBoundss, body) =>
val variances = argBoundss.map(b => BindingKind.toVariance(b.bindingKind))
val prefix = ((('X' - 'A') + lambdaNestingLevel) % 26 + 'A').toChar
val paramNames = argBoundss.indices.toList.map(prefix.toString + _)
@@ -130,13 +126,13 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
}
}
def apply(t: Type): Type = t match {
- case TypeRef(RecThis(rt), name) if name.isHkArgName && contains(tp, rt) =>
+ case TypeRef(RecThis(rt), name) if name.isHkArgNameOLD && contains(tp, rt) =>
// Make up a name that prints as "Xi". Need to be careful we do not
// accidentally unique-hash to something else. That's why we can't
// use prefix = NoPrefix or a WithFixedSym instance.
TypeRef.withSymAndName(
defn.EmptyPackageClass.thisType, defn.AnyClass,
- paramNames(name.hkArgIndex).toTypeName)
+ paramNames(name.hkArgIndexOLD).toTypeName)
case _ =>
mapOver(t)
}
@@ -186,25 +182,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
def blockText[T >: Untyped](trees: List[Tree[T]]): Text =
"{" ~ toText(trees, "\n") ~ "}"
- /** The text for a TypeLambda
- *
- * [v_1 p_1: B_1, ..., v_n p_n: B_n] -> T
- *
- * where
- * @param paramNames = p_1, ..., p_n
- * @param variances = v_1, ..., v_n
- * @param argBoundss = B_1, ..., B_n
- * @param body = T
- */
- def typeLambdaText(paramNames: List[String], variances: List[Int], argBoundss: List[TypeBounds], body: Type): Text = {
- def lambdaParamText(variance: Int, name: String, bounds: TypeBounds): Text =
- varianceString(variance) ~ name ~ toText(bounds)
- changePrec(GlobalPrec) {
- "[" ~ Text((variances, paramNames, argBoundss).zipped.map(lambdaParamText), ", ") ~
- "] -> " ~ toTextGlobal(body)
- }
- }
-
override def toText[T >: Untyped](tree: Tree[T]): Text = controlled {
import untpd.{modsDeco => _, _}