@@ -53,7 +53,7 @@ class ReplCompiler(val directory: AbstractFile) extends Compiler {
53
53
}
54
54
55
55
(1 to objectIndex)
56
- .foldLeft(addImport( " dotty.Show " .toTermName)( initCtx) ) { (ictx, i) =>
56
+ .foldLeft(initCtx) { (ictx, i) =>
57
57
addImport(nme.EMPTY_PACKAGE ++ " ." ++ objectNames(i))(ictx)
58
58
}
59
59
}
@@ -74,67 +74,22 @@ class ReplCompiler(val directory: AbstractFile) extends Compiler {
74
74
75
75
implicit val ctx : Context = state.run.runContext
76
76
77
- def createShow (name : TermName , pos : Position ) = {
78
- val showName = name ++ " Show"
79
- val select = Select (Ident (name), " show" .toTermName)
80
- val valAsAnyRef = TypeApply (Select (Ident (name), nme.asInstanceOf_),
81
- List (Ident (tpnme.AnyRef )))
82
- val cond = InfixOp (valAsAnyRef,
83
- Ident (nme.EQ ),
84
- Literal (Constant (null )))
85
- val showWithNullCheck = If (cond, Literal (Constant (" null" )), select)
86
- DefDef (showName, Nil , Nil , TypeTree (), showWithNullCheck).withFlags(Synthetic ).withPos(pos)
87
- }
88
-
89
- def createPatDefShows (patDef : PatDef ) = {
90
- def createDeepShows (tree : untpd.Tree ) = {
91
- class PatFolder extends UntypedDeepFolder [List [DefDef ]] (
92
- (acc, tree) => tree match {
93
- case Ident (name) if name.isVariableName && name != nme.WILDCARD =>
94
- createShow(name.toTermName, tree.pos) :: acc
95
- case Bind (name, _) if name.isVariableName && name != nme.WILDCARD =>
96
- createShow(name.toTermName, tree.pos) :: acc
97
- case _ =>
98
- acc
99
- }
100
- )
101
- (new PatFolder ).apply(Nil , tree).reverse
102
- }
103
-
104
- // cannot fold over the whole tree because we need to generate show methods
105
- // for top level identifier starting with an uppercase (e.g. val X, Y = 2)
106
- patDef.pats.flatMap {
107
- case id @ Ident (name) if name != nme.WILDCARD =>
108
- List (createShow(name.toTermName, id.pos))
109
- case bd @ Bind (name, body) if name != nme.WILDCARD =>
110
- createShow(name.toTermName, bd.pos) :: createDeepShows(body)
111
- case other =>
112
- createDeepShows(other)
113
- }
114
- }
115
-
116
77
var valIdx = state.valIndex
117
78
118
79
val defs = trees.flatMap {
119
- case vd : ValDef =>
120
- List (vd, createShow(vd.name, vd.pos))
121
- case pd : PatDef =>
122
- pd :: createPatDefShows(pd)
123
80
case expr @ Assign (id : Ident , rhs) =>
124
81
// special case simple reassignment (e.g. x = 3)
125
82
// in order to print the new value in the REPL
126
83
val assignName = (id.name ++ str.REPL_ASSIGN_SUFFIX ).toTermName
127
84
val assign = ValDef (assignName, TypeTree (), id).withPos(expr.pos)
128
- val show = createShow(assignName, expr.pos)
129
- List (expr, assign, show)
85
+ List (expr, assign)
130
86
case expr if expr.isTerm =>
131
87
val resName = (str.REPL_RES_PREFIX + valIdx).toTermName
132
88
valIdx += 1
133
- val show = createShow(resName, expr.pos)
134
89
val vd = ValDef (resName, TypeTree (), expr).withPos(expr.pos)
135
- List (vd, show)
90
+ vd :: Nil
136
91
case other =>
137
- List ( other)
92
+ other :: Nil
138
93
}
139
94
140
95
Definitions (
@@ -154,7 +109,6 @@ class ReplCompiler(val directory: AbstractFile) extends Compiler {
154
109
* package <none> {
155
110
* object rs$line$nextId {
156
111
* import rs$line${i <- 0 until nextId}._
157
- * import dotty.Show._
158
112
*
159
113
* <trees>
160
114
* }
0 commit comments