1
1
package dotty .tools .dotc
2
2
package core
3
3
4
- import Types ._ , Symbols ._ , Contexts ._ , Scopes ._ , Names ._
4
+ import Types ._ , Symbols ._ , Contexts ._ , Scopes ._ , Names ._ , NameOps . _ , Flags . _
5
5
6
6
trait Printers { this : Context =>
7
7
@@ -40,10 +40,19 @@ object Printers {
40
40
def show (sc : Scope ): String
41
41
def show (syms : List [Symbol ], sep : String ): String
42
42
def showNameDetailed (name : Name ): String
43
+ def showFullName (sym : Symbol ): String
44
+
45
+ /** String representation of symbol's simple name.
46
+ * If !settings.debug translates expansions of operators back to operator symbol.
47
+ * E.g. $eq => =.
48
+ * If settings.uniqid, adds id.
49
+ * If settings.Yshowsymkinds, adds abbreviated symbol kind.
50
+ */
51
+ def showName (sym : Symbol ): String
43
52
}
44
53
45
- class StdPrinter ( implicit ctx : Context ) extends Printer {
46
-
54
+ class PlainPrinter ( _ctx : Context ) extends Printer {
55
+ protected [ this ] implicit val ctx = _ctx
47
56
def controlled (op : => String ): String =
48
57
if (ctx.showRecursions < maxShowRecursions)
49
58
try {
@@ -53,22 +62,25 @@ object Printers {
53
62
ctx.showRecursions -= 1
54
63
}
55
64
else {
56
- if (ctx.debug) {
57
- ctx.warning(" Exceeded recursion depth attempting to print type." )
58
- (new Throwable ).printStackTrace
59
- }
65
+ recursionLimitExceeeded()
60
66
" ..."
61
67
}
62
68
63
- def show ( tp : Type ) : String = controlled {
64
- tp match {
65
- case TermRef (pre, name) =>
66
- ??? // showPrefix(pre) + show(name)
69
+ protected def recursionLimitExceeeded () = {
70
+ ctx.warning( " Exceeded recursion depth attempting to print type. " )
71
+ ( new Throwable ).printStackTrace
72
+ }
67
73
74
+ protected def showSimpleName (sym : Symbol ) = sym.originalName.decode
68
75
76
+ def showName (sym : Symbol ): String =
77
+ showSimpleName(sym) + (if (ctx.settings.uniqid.value) " #" + sym.id else " " )
69
78
70
- }
71
- }
79
+ def showFullName (sym : Symbol ): String =
80
+ if (sym.isRoot || sym == NoSymbol || sym.owner.isEffectiveRoot)
81
+ showName(sym)
82
+ else
83
+ showFullName(sym.effectiveOwner.enclosingClass) + " ." + showName(sym)
72
84
73
85
protected def objectPrefix = " object "
74
86
protected def packagePrefix = " package "
@@ -80,28 +92,51 @@ object Printers {
80
92
(defn.UnqualifiedOwners contains sym) || isEmptyPrefix(sym)
81
93
82
94
protected def isEmptyPrefix (sym : Symbol ) =
83
- sym.isEffectiveRoot || sym.isAnonymousClass || ??? // nme.isReplWrapperName(sym.name)
84
-
95
+ sym.isEffectiveRoot || sym.isAnonymousClass || sym.name.isReplWrapperName
85
96
86
97
def showPrefix (tp : Type ): String = controlled {
87
98
tp match {
99
+ case RefinedThis (_) =>
100
+ " this."
88
101
case ThisType (cls) =>
89
- if (ctx.debug) showName(cls) + " .this."
90
- else if (cls.isAnonymousClass) " this."
91
- else ???
102
+ showName(cls) + " .this."
103
+ case SuperType (thistpe, _) =>
104
+ showPrefix(thistpe).replaceAll(""" \bthis\.$""" , " super." )
105
+ case tp @ TermRef (pre, name) =>
106
+ val sym = tp.symbol
107
+ if (! sym.exists) showPrefix(pre) + name + " ."
108
+ else showPrefix(pre) + showName(sym) + " ."
109
+ case MethodParam (mt, idx) =>
110
+ mt.paramNames(idx) + " ."
92
111
case NoPrefix =>
93
112
" "
113
+ case ConstantType (value) =>
114
+ " (" + value + " )."
94
115
case _ =>
95
116
trimPrefix(show(tp)) + " #"
117
+ }
118
+ }
119
+
120
+ def show (tp : Type ): String = controlled {
121
+ tp match {
122
+ case tp : SingletonType =>
123
+ val str = showPrefix(tp)
124
+ if (str.endsWith(" ." )) str + " type"
125
+ else showFullName(tp.underlying.typeSymbol.skipPackageObject) + " .type"
126
+ case
127
+ TermRef (pre, name) =>
128
+ ??? // showPrefix(pre) + show(name)
129
+
130
+
96
131
97
132
}
98
133
}
99
134
135
+
100
136
def show (sym : Symbol ): String = controlled {
101
137
102
138
???
103
139
}
104
- def showName (sym : Symbol ): String = ???
105
140
def showLocated (sym : Symbol ): String = ???
106
141
def showDef (sym : Symbol ): String = ???
107
142
def show (sc : Scope ): String =
@@ -112,9 +147,29 @@ object Printers {
112
147
113
148
def showNameDetailed (name : Name ): String =
114
149
(if (name.isTypeName) " type " else " term " ) + name
150
+ }
151
+
152
+ class RefinedPrinter (_ctx : Context ) extends PlainPrinter (_ctx) {
153
+ override protected def recursionLimitExceeeded () = {}
115
154
155
+ override protected def showSimpleName (sym : Symbol ) = sym.name.toString
156
+
157
+ override def showPrefix (tp : Type ): String = controlled {
158
+ tp match {
159
+ case ThisType (cls) =>
160
+ if (cls.isAnonymousClass) return " this."
161
+ if (isOmittablePrefix(cls)) return " "
162
+ if (cls.isModuleClass) return showFullName(cls) + " ."
163
+ case tp @ TermRef (pre, name) =>
164
+ val sym = tp.symbol
165
+ if (sym is PackageObject ) return showPrefix(pre)
166
+ if (isOmittablePrefix(sym)) return " "
167
+ case _ =>
168
+ }
169
+ super .showPrefix(tp)
170
+ }
116
171
}
117
172
118
- final val maxShowRecursions = 50
173
+ final val maxShowRecursions = 100
119
174
120
175
}
0 commit comments