fix: UI Bug

This commit is contained in:
Kagura 2024-11-01 09:14:07 +08:00
parent 3460f3133d
commit 0e461e1419
3 changed files with 61 additions and 35 deletions

View file

@ -4,6 +4,9 @@
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="PWA">
<option name="wasEnabledAtLeastOnce" value="true" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>

View file

@ -21,6 +21,10 @@ import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import core.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import ui.TextfieldWithLineNumber
import utils.*
@ -47,39 +51,43 @@ fun App() {
}) {
AlertDialog(
title = {
Text(
text = when (page) {
0 -> "函数定义的变量"
1 -> "函数内每条语句的定义和使用"
2 -> "函数内每个变量 def-use 链"
3 -> "函数间每个变量 def-use 链"
else -> "出错了"
},
color = Color.Black,
fontWeight = FontWeight.Bold,
fontSize = 24.sp,
textAlign = TextAlign.Center,
modifier = Modifier.padding(top = 10.dp)
)
Column(modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = when (page) {
0 -> "函数定义的变量"
1 -> "函数内每条语句的定义和使用"
2 -> "函数内每个变量 def-use 链"
3 -> "函数间每个变量 def-use 链"
else -> "出错了"
},
color = Color.Black,
fontWeight = FontWeight.Bold,
fontSize = 24.sp,
textAlign = TextAlign.Center
)
}
},
text = {
Text(
text = when (page) {
0 -> defineList
1 -> useList
2 -> traceTree
3 -> funcTraceTree
else -> "出错了(ง •̀_•́)ง"
},
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.wrapContentHeight(),
textAlign = TextAlign.Start,
color = Color.Black,
fontSize = 18.sp,
fontFamily = FontFamily("monospace")
)
Box(modifier = Modifier.fillMaxWidth()
.fillMaxHeight(0.8f)) {
Text(
text = when (page) {
0 -> defineList
1 -> useList
2 -> traceTree
3 -> funcTraceTree
else -> "出错了(ง •̀_•́)ง"
},
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
textAlign = TextAlign.Start,
color = Color.Black,
fontSize = 18.sp,
fontFamily = FontFamily("monospace")
)
}
},
onDismissRequest = {
showResult.value = false
@ -157,6 +165,7 @@ fun App() {
val def = getDefineList(sf.getDef())
def.ifEmpty {
"分析失败:可能输入有错误!"
return@TextfieldWithLineNumber
}
} catch (e: Exception) {
e.printStackTrace().toString()
@ -166,12 +175,26 @@ fun App() {
} catch (e: Exception) {
e.printStackTrace().toString()
}
// 异步获取 traceTree
val relations = mutableMapOf<String, List<Relation>>()
val traceTreeStr = StringBuilder()
sf.functions.forEach { func ->
traceTreeStr.append(getTraceTreeString(func.getTraceTree().getStringRepr(),func.name))
relations.putAll(parseRelation(func.name,func.getTraceTree().getStringRepr()))
runBlocking {
val deferredResults = sf.functions.map { func ->
async(Dispatchers.Default) {
val traceStr = getTraceTreeString(func.getTraceTree().getStringRepr(), func.name)
val parsedRelations = parseRelation(func.name, func.getTraceTree().getStringRepr())
Pair(traceStr, parsedRelations)
}
}
// 等待所有协程结束
deferredResults.awaitAll().forEach { (traceStr, parsedRelations) ->
traceTreeStr.append(traceStr)
relations.putAll(parsedRelations)
}
}
traceTree = traceTreeStr.toString()
funcTraceTree =

View file

@ -182,7 +182,7 @@ class SourceFile {
}
/**
* 任务1获取使用的值的情况
* 获取使用的值的情况
* @return Map of<函数 to List<使用值的情况>>
* @see utils.getUseList 获取要求的格式
*/