@@ -145,6 +145,26 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
145
145
this
146
146
}
147
147
148
+ case While (cond, stats) =>
149
+ this += " while ("
150
+ printTree(cond)
151
+ this += " ) {"
152
+ indented {
153
+ this += lineBreak()
154
+ printTrees(stats, lineBreak())
155
+ }
156
+ this += lineBreak() += " }"
157
+
158
+ case DoWhile (stats, cond) =>
159
+ this += " do {"
160
+ indented {
161
+ this += lineBreak()
162
+ printTrees(stats, lineBreak())
163
+ }
164
+ this += lineBreak() += " } while ("
165
+ printTree(cond)
166
+ this += " )"
167
+
148
168
case ddef@ DefDef (name, targs, argss, tpt, rhs) =>
149
169
val flags = ddef.flags
150
170
if (flags.isOverride) sb.append(" override " )
@@ -225,7 +245,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
225
245
this += " = "
226
246
printTree(rhs)
227
247
228
- case Term .Block (stats, expr) =>
248
+ case Term .Block (stats0, expr) =>
249
+ def isLoopContinue (tree : Tree ): Boolean = tree match {
250
+ case Term .Apply (Term .Ident (" while$" | " doWhile$" ), _) => true
251
+ case _ => false
252
+ }
253
+
254
+ val stats = stats0.filterNot(isLoopContinue)
255
+
229
256
expr match {
230
257
case Term .Lambda (_, _) =>
231
258
// Decompile lambda from { def annon$(...) = ...; closure(annon$, ...)}
@@ -236,30 +263,17 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
236
263
printTree(rhs)
237
264
this += " )"
238
265
239
- case Term .Apply (Term .Ident (" while$" ), _) =>
240
- val DefDef (" while$" , _, _, _, Some (Term .If (cond, Term .Block (body :: Nil , _), _))) = stats.head
241
- this += " while ("
242
- printTree(cond)
243
- this += " ) "
244
- printTree(body)
245
-
246
- case Term .Apply (Term .Ident (" doWhile$" ), _) =>
247
- val DefDef (" doWhile$" , _, _, _, Some (Term .Block (List (body), Term .If (cond, _, _)))) = stats.head
248
- this += " do "
249
- printTree(body)
250
- this += " while ("
251
- printTree(cond)
252
- this += " )"
253
-
254
266
case _ =>
255
267
this += " {"
256
268
indented {
257
269
if (! stats.isEmpty) {
258
270
this += lineBreak()
259
271
printTrees(stats, lineBreak())
260
272
}
261
- this += lineBreak()
262
- printTree(expr)
273
+ if (! isLoopContinue(expr)) {
274
+ this += lineBreak()
275
+ printTree(expr)
276
+ }
263
277
}
264
278
this += lineBreak() += " }"
265
279
}
@@ -719,6 +733,20 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
719
733
}
720
734
}
721
735
736
+ private object While {
737
+ def unapply (arg : Term )(implicit ctx : Context ): Option [(Term , List [Statement ])] = arg match {
738
+ case DefDef (" while$" , _, _, _, Some (Term .If (cond, Term .Block (bodyStats, _), _))) => Some ((cond, bodyStats))
739
+ case _ => None
740
+ }
741
+ }
742
+
743
+ private object DoWhile {
744
+ def unapply (arg : Term )(implicit ctx : Context ): Option [(List [Statement ], Term )] = arg match {
745
+ case DefDef (" doWhile$" , _, _, _, Some (Term .Block (body, Term .If (cond, _, _)))) => Some ((body, cond))
746
+ case _ => None
747
+ }
748
+ }
749
+
722
750
// TODO Provide some of these in scala.tasty.Tasty.scala and implement them using checks on symbols for performance
723
751
private object Types {
724
752
0 commit comments