chore: doc

This commit is contained in:
Kagura 2024-10-31 23:48:39 +08:00
parent dfc9815e83
commit 8402dc68b9
3 changed files with 26 additions and 14 deletions

View file

@ -173,7 +173,7 @@ fun App() {
traceTree = traceTreeStr.toString() traceTree = traceTreeStr.toString()
funcTraceTree = funcTraceTree =
getInvokeTraceTreeString(sf,relations) getInvokeTraceTreeString(sf)
ttGraph = generateGraph(relations) ttGraph = generateGraph(relations)
ivGraph = sf.functions.getInvokeGraph() ivGraph = sf.functions.getInvokeGraph()

View file

@ -1,5 +1,3 @@
@file:Suppress("unused")
package core package core
import java.io.File import java.io.File
@ -30,7 +28,7 @@ class SourceFile {
} }
// 处理 DEFINE, 支持如下 // 处理 DEFINE, 支持如下
// #define SOMETHING ANOTHERTHING 这样的 // #define SOMETHING ANOTHER 这样的
// #define ADD(a, b) a + b // #define ADD(a, b) a + b
val noFuncInDefine = StringBuilder() val noFuncInDefine = StringBuilder()
// 获取 define 的内容 // 获取 define 的内容
@ -154,7 +152,11 @@ class SourceFile {
this.content = formatSource(content) this.content = formatSource(content)
} }
fun parseFunction(): List<CFunction> { // 找所有的函数定义 /**
* 找所有的函数定义
* @return 所有定义的函数
*/
fun parseFunction(): List<CFunction> {
val result = mutableListOf<CFunction>() val result = mutableListOf<CFunction>()
function_define_regex.findAll(content).forEach { function_define_regex.findAll(content).forEach {
if (it.groups.size >= 2 && it.groups[1] != null) { if (it.groups.size >= 2 && it.groups[1] != null) {
@ -165,7 +167,12 @@ class SourceFile {
return result return result
} }
fun getDef(): Map<String, List<String>> { // 获取所有的定义 /**
* 找所有的变量定义
* @return Map of<函数名称 to List<定义的变量>>
* @see utils.getDefineList
*/
fun getDef(): Map<String, List<String>> {
val result = mutableMapOf<String, List<String>>() val result = mutableMapOf<String, List<String>>()
functions.forEach { functions.forEach {
result[it.name] = it.cParser.defineList result[it.name] = it.cParser.defineList
@ -173,6 +180,11 @@ class SourceFile {
return result return result
} }
/**
* 任务1获取使用的值的情况
* @return Map of<函数 to List<使用值的情况>>
* @see utils.getUseList 获取要求的格式
*/
fun getUse(): Map<String, List<String>> { fun getUse(): Map<String, List<String>> {
val globalResult = mutableMapOf<String, List<String>>() val globalResult = mutableMapOf<String, List<String>>()
functions.forEach { functions.forEach {
@ -210,7 +222,7 @@ class SourceFile {
useCache.append("${sentence.left}-def") useCache.append("${sentence.left}-def")
} }
DEFINE_VALUE_PARAM, CHANGE_VALUE_PARAM -> { DEFINE_VALUE_PARAM, CHANGE_VALUE_PARAM -> { // 作为参数出现的
useCache.append(";${sentence.right}-use") useCache.append(";${sentence.right}-use")
} }
@ -226,17 +238,17 @@ class SourceFile {
} }
} }
fun main() { fun main() { // 测试用, NoGUI
val sourceFile = SourceFile(File("src/main/CTests/test.c")) val sourceFile = SourceFile(File("src/main/CTests/test.c"))
val funcs = sourceFile.parseFunction() val functions = sourceFile.parseFunction()
val relations = mutableMapOf<String, List<Relation>>() val relations = mutableMapOf<String, List<Relation>>()
funcs.forEach { functions.forEach {
relations.putAll(parseRelation(it.name, it.getTraceTree().getStringRepr())) relations.putAll(parseRelation(it.name, it.getTraceTree().getStringRepr()))
} }
for (function in funcs) { for (function in functions) {
println(funcs.getInvokeTree(function.name).getFuncRepr(function.name)) println(functions.getInvokeTree(function.name).getFuncRepr(function.name))
} }
println(generateGraph(relations)) println(generateGraph(relations))
println(funcs.getInvokeGraph()) println(functions.getInvokeGraph())
} }

View file

@ -31,7 +31,7 @@ fun getTraceTreeString(traceTreeStr: String, funcName: String): String {
return sb.toString() return sb.toString()
} }
fun getInvokeTraceTreeString(sourceFile: SourceFile, relations: Map<String, List<Relation>>): String { fun getInvokeTraceTreeString(sourceFile: SourceFile): String {
val tree = StringBuilder() val tree = StringBuilder()
for (function in sourceFile.functions) { for (function in sourceFile.functions) {
val chain = sourceFile.functions.getInvokeTree(function.name).getFuncRepr(function.name) val chain = sourceFile.functions.getInvokeTree(function.name).getFuncRepr(function.name)