From 5afdaaf8355193bcb1cdc306ced5b5f63d1a2973 Mon Sep 17 00:00:00 2001 From: esteban marin Date: Mon, 13 Jun 2022 16:10:17 -0500 Subject: [PATCH] Remove DecompilerPrinter.scala Description: We tested all methods in REPL and none of them are used all test passes. Do while do not exist anymore, `packages` are printed, not content of classes either. fixes #14806 --- .../dotc/printing/DecompilerPrinter.scala | 78 ------------------- .../tools/dotc/printing/ReplPrinter.scala | 2 +- 2 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala diff --git a/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala b/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala deleted file mode 100644 index 83dc32d6e7ac..000000000000 --- a/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala +++ /dev/null @@ -1,78 +0,0 @@ -package dotty.tools.dotc.printing - -import dotty.tools.dotc.ast.Trees._ -import dotty.tools.dotc.ast.untpd.{Tree, PackageDef, Template, TypeDef} -import dotty.tools.dotc.ast.{Trees, untpd} -import dotty.tools.dotc.printing.Texts._ -import dotty.tools.dotc.core.Contexts._ -import dotty.tools.dotc.core.StdNames.nme -import dotty.tools.dotc.core.Flags._ -import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.core.StdNames._ - -class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) { - - override protected def dropAnnotForModText(sym: Symbol): Boolean = - super.dropAnnotForModText(sym) || sym == defn.SourceFileAnnot - - override protected def blockToText[T >: Untyped](block: Block[T]): Text = - block match { - case Block(DefDef(_, _, _, Trees.If(cond, Trees.Block(body :: Nil, _), _)) :: Nil, y) if y.symbol.name == nme.WHILE_PREFIX => - keywordText("while") ~ " (" ~ toText(cond) ~ ")" ~ toText(body) - case Block(DefDef(_, _, _, Trees.Block(body :: Nil, Trees.If(cond, _, _))) :: Nil, y) if y.symbol.name == nme.DO_WHILE_PREFIX => - keywordText("do") ~ toText(body) ~ keywordText("while") ~ " (" ~ toText(cond) ~ ")" - case Block((meth @ DefDef(nme.ANON_FUN, _, _, _)) :: Nil, _: Closure[T]) => - withEnclosingDef(meth) { - addParamssText("", meth.termParamss) ~ " => " ~ toText(meth.rhs) - } - case _ => - super.blockToText(block) - } - - override protected def packageDefText(tree: PackageDef): Text = { - val stats = tree.stats.filter { - case vdef: ValDef[?] => !vdef.symbol.is(Module) - case _ => true - } - val statsText = stats match { - case (pdef: PackageDef) :: Nil => toText(pdef) - case _ => Fluid(toTextGlobal(stats, "\n") :: Nil) - } - val bodyText = - if (tree.pid.symbol.isEmptyPackage) statsText - else if (currentPrecedence == TopLevelPrec) "\n" ~ statsText - else " {" ~ statsText ~ "}" - (keywordStr("package ") ~ toTextPackageId(tree.pid)).provided(!tree.symbol.isEmptyPackage) ~ bodyText - } - - override protected def templateText(tree: TypeDef, impl: Template): Text = { - val decl = - if (!tree.mods.is(Module)) modText(tree.mods, tree.symbol, keywordStr(if (tree.mods.is(Trait)) "trait" else "class"), isType = true) - else modText(tree.mods, tree.symbol, keywordStr("object"), isType = false) - decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~ "" - } - - override protected def toTextTemplate(impl: Template, ofNew: Boolean = false): Text = { - def isSynthetic(parent: Tree): Boolean = { - val sym = parent.symbol - sym.maybeOwner == defn.ObjectClass || - (sym == defn.ProductClass && impl.symbol.owner.is(Case)) || - (sym == defn.SerializableClass && impl.symbol.owner.is(Case)) - } - val parents = impl.parents.filterNot(isSynthetic) - val body = impl.body.filterNot(_.symbol.is(ParamAccessor)) - - // We don't print self type and constructor for objects - val isObject = impl.constr.symbol.owner.is(Module) - if (isObject) { - val parentsText = keywordText(" extends") ~~ Text(parents.map(constrText), keywordStr(" with ")) - val bodyText = " {" ~~ toTextGlobal(impl.body, "\n") ~ "}" - parentsText.provided(parents.nonEmpty) ~ bodyText - } - else super.toTextTemplate(untpd.cpy.Template(impl)(parents = parents, body = body), ofNew) - } - - override protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = - if (tree.symbol eq defn.QuotedRuntime_exprQuote) "'" - else super.typeApplyText(tree) -} diff --git a/compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala b/compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala index 8bed651ba18b..57a38126cfd4 100644 --- a/compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala @@ -11,7 +11,7 @@ import dotty.tools.dotc.core.Types._ import dotty.tools.dotc.printing.Texts._ -class ReplPrinter(_ctx: Context) extends DecompilerPrinter(_ctx) { +class ReplPrinter(_ctx: Context) extends RefinedPrinter(_ctx) { val debugPrint = _ctx.settings.YprintDebug.value