From 16b7735cd664e3d2dce9f1862c7ffe36787e2e14 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 25 Aug 2021 10:38:18 +0300 Subject: [PATCH] [FIR] Fix rendering of labels for return edgeds in CFG --- .../kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt | 2 +- .../fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt index ed489e40eda..c85778d7ac6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraph.kt @@ -143,7 +143,7 @@ object UncaughtExceptionPath : EdgeLabel(label = "onUncaughtException") // TODO: Label `return`ing edge with this. class ReturnPath( returnTargetSymbol: FirFunctionSymbol<*> -) : EdgeLabel(label = "return@${returnTargetSymbol.callableId}") +) : EdgeLabel(label = "\"return@${returnTargetSymbol.callableId}\"") enum class EdgeKind( val usedInDfa: Boolean, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt index 665fbe7d430..aef735688d4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt @@ -25,6 +25,8 @@ class FirControlFlowGraphRenderVisitor( private const val RED = "red" private const val BLUE = "blue" + private val DIGIT_REGEX = """\d""".toRegex() + private val EDGE_STYLE = EnumMap( mapOf( EdgeKind.Forward to "", @@ -47,8 +49,12 @@ class FirControlFlowGraphRenderVisitor( private val allGraphs = mutableSetOf() override fun visitFile(file: FirFile) { + var name = file.name.replace(".", "_") + if (DIGIT_REGEX.matches(name.first().toString())) { + name = "_$name" + } printer - .println("digraph ${file.name.replace(".", "_")} {") + .println("digraph $name {") .pushIndent() .println("graph [nodesep=3]") .println("node [shape=box penwidth=2]")