Skip to content
Snippets Groups Projects
Commit 949f28fb authored by Manos Koukoutos's avatar Manos Koukoutos
Browse files

Print functions/unapply objects with paths, fix printing with braces

parent d6ea932c
No related branches found
No related tags found
No related merge requests found
...@@ -53,11 +53,10 @@ class PrettyPrinter(opts: PrinterOptions, ...@@ -53,11 +53,10 @@ class PrettyPrinter(opts: PrinterOptions,
def pp(tree: Tree)(implicit ctx: PrinterContext): Unit = { def pp(tree: Tree)(implicit ctx: PrinterContext): Unit = {
if (requiresBraces(tree, ctx.parent)) { if (requiresBraces(tree, ctx.parent) && !ctx.parent.contains(tree)) {
val ctx1: PrinterContext = ctx.copy(parents = Nil)
p"""|{ p"""|{
| $tree | $tree
|}"""(ctx1) |}"""
return return
} }
...@@ -213,14 +212,14 @@ class PrettyPrinter(opts: PrinterOptions, ...@@ -213,14 +212,14 @@ class PrettyPrinter(opts: PrinterOptions,
p"($presentArgs)" p"($presentArgs)"
} }
case FunctionInvocation(tfd, args) => case FunctionInvocation(TypedFunDef(fd, tps), args) =>
p"${tfd.id}" printWithPath(fd)
if (tfd.tps.nonEmpty) { if (tps.nonEmpty) {
p"[${tfd.tps}]" p"[$tps]"
} }
if (tfd.fd.isRealFunction) { if (fd.isRealFunction) {
// The non-present arguments are synthetic function invocations // The non-present arguments are synthetic function invocations
val presentArgs = args filter { val presentArgs = args filter {
case MethodInvocation(_, _, tfd, _) if tfd.fd.isSynthetic => false case MethodInvocation(_, _, tfd, _) if tfd.fd.isSynthetic => false
...@@ -377,12 +376,17 @@ class PrettyPrinter(opts: PrinterOptions, ...@@ -377,12 +376,17 @@ class PrettyPrinter(opts: PrinterOptions,
ob.foreach { b => p"$b @ " } ob.foreach { b => p"$b @ " }
// @mk: I admit this is pretty ugly // @mk: I admit this is pretty ugly
val id = for { (for {
p <- opgm p <- opgm
mod <- p.modules.find( _.definedFunctions contains tfd.fd ) mod <- p.modules.find( _.definedFunctions contains tfd.fd )
} yield mod.id } yield mod) match {
case Some(obj) =>
p"${id.getOrElse("<unknown object>")}(${nary(subps)})" printWithPath(obj)
case None =>
p"<unkown object>"
}
p"(${nary(subps)})"
case LiteralPattern(ob, lit) => case LiteralPattern(ob, lit) =>
ob foreach { b => p"$b @ " } ob foreach { b => p"$b @ " }
......
...@@ -54,7 +54,8 @@ object PrinterHelpers { ...@@ -54,7 +54,8 @@ object PrinterHelpers {
nary(ts).print(nctx) nary(ts).print(nctx)
case t: Tree => case t: Tree =>
val parents = if (nctx.current == t) { // Don't add same tree twice in parents
val parents = if (nctx.parents.headOption contains nctx.current) {
nctx.parents nctx.parents
} else { } else {
nctx.current :: nctx.parents nctx.current :: nctx.parents
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment