[FIR] Fix rendering of labels for return edgeds in CFG

This commit is contained in:
Dmitriy Novozhilov
2021-08-25 10:38:18 +03:00
parent 0924216ed2
commit 16b7735cd6
2 changed files with 8 additions and 2 deletions
@@ -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,
@@ -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<ControlFlowGraph>()
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]")