From 9c75f37409de0b46d3f18f9848fdaf40ba523f0a Mon Sep 17 00:00:00 2001 From: Kagura Date: Wed, 30 Oct 2024 09:47:07 +0800 Subject: [PATCH] Fix complex funcs --- src/main/kotlin/core/CFunction.kt | 2 +- src/main/kotlin/core/GraphvizHelper.kt | 2 -- src/main/kotlin/core/SourceFile.kt | 3 +-- src/main/kotlin/core/TraceTree.kt | 9 +++++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/core/CFunction.kt b/src/main/kotlin/core/CFunction.kt index d76e306..823ca5f 100644 --- a/src/main/kotlin/core/CFunction.kt +++ b/src/main/kotlin/core/CFunction.kt @@ -86,7 +86,7 @@ class CFunction( if (index > 0) { // 按理来说肯定成立,加个检查防止意外 var i = 0 var left = cParser.sentenceList[index - 1].left - while (left == "-" && index - i >= 0) { + while (left !in cParser.defineList && index - i >= 0) { left = cParser.sentenceList[index - i].left i++ } diff --git a/src/main/kotlin/core/GraphvizHelper.kt b/src/main/kotlin/core/GraphvizHelper.kt index cc2fa47..8197cb4 100644 --- a/src/main/kotlin/core/GraphvizHelper.kt +++ b/src/main/kotlin/core/GraphvizHelper.kt @@ -1,7 +1,5 @@ package core -import kotlin.math.abs - data class Relation(val from: String, val to: String) fun generateGraph(relations: Map>, crossLabelPaths: List? = null): String { diff --git a/src/main/kotlin/core/SourceFile.kt b/src/main/kotlin/core/SourceFile.kt index 13a3e05..a92138b 100644 --- a/src/main/kotlin/core/SourceFile.kt +++ b/src/main/kotlin/core/SourceFile.kt @@ -160,8 +160,7 @@ fun main() { relations.putAll(parseRelation(it.name,it.getTraceTree().getStringRepr())) } println(funcs.getInvokeTree("main").getFuncRepr("main")) - println(sourceFile.getDef()) - println(sourceFile.getUse()) + println(generateGraph(relations)) println(funcs.getInvokeGraph("main")) diff --git a/src/main/kotlin/core/TraceTree.kt b/src/main/kotlin/core/TraceTree.kt index 1a2558e..bd7b337 100644 --- a/src/main/kotlin/core/TraceTree.kt +++ b/src/main/kotlin/core/TraceTree.kt @@ -49,10 +49,15 @@ fun List.getStringRepr(): String { fun Map>.getFuncRepr(func: String): String { val result = StringBuilder() + var fName = "" this.forEach { (name, list) -> - result.append("$name:") + fName = name val listRepr = list.getStringRepr() result.append(listRepr.split('\n').filter { it.startsWith(func) }.joinToString("\n")) } - return result.toString() + val fixedResult = StringBuilder() + result.lines().forEach { line -> + fixedResult.append("$fName:$line\n") + } + return fixedResult.toString() } \ No newline at end of file