c/clang/symg:normal gen json

This commit is contained in:
luoliwoshang
2024-07-26 14:37:26 +08:00
parent f391ccb8e8
commit c53484f92e
3 changed files with 21 additions and 6 deletions

View File

@@ -70,7 +70,13 @@ func collectFuncInfo(cursor clang.Cursor) ASTInformation {
symbol := cursor.Mangling()
info.Name = c.GoString(cursorStr.CStr())
info.Symbol = c.GoString(symbol.CStr())
if len(info.Symbol) >= 1 {
if info.Symbol[0] == '_' {
info.Symbol = info.Symbol[1:]
}
}
defer symbol.Dispose()
defer cursorStr.Dispose()
@@ -212,6 +218,7 @@ func main() {
fmt.Fprintln(os.Stderr, "Usage: <C++ header file>\n")
return
} else {
// sourceFile := *c.Advance(c.Argv, 1)
printJson(parse(c.Index(c.Argv, 1)))
// fmt.Println("Json end")

View File

@@ -2,8 +2,7 @@
"name": "inih",
"cflags": "$(pkg-config --cflags INIReader)",
"include": [
"INIReader.h",
"AnotherHeaderFile.h"
"INIReader.h"
],
"libs": "$(pkg-config --libs INIReader)",
"trimPrefixes": ["Ini", "INI"]

View File

@@ -22,8 +22,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/common"
"github.com/goplus/llgo/chore/llcppg/types"
"io"
"os"
"os/exec"
@@ -31,6 +29,9 @@ import (
"regexp"
"strconv"
"strings"
"github.com/goplus/llgo/chore/_xtool/llcppsymg/common"
"github.com/goplus/llgo/chore/llcppg/types"
)
func main() {
@@ -161,11 +162,16 @@ func decodeSymbolName(symbolName string) (string, error) {
// parseHeaderFile
func parseHeaderFile(config types.Config) ([]common.ASTInformation, error) {
files := generateHeaderFilePath(config.CFlags, config.Include)
fmt.Println(files)
headerFileCmd := exec.Command("llcppinfofetch", files...)
fmt.Println("Executing command:", headerFileCmd.String())
headerFileOutput, err := headerFileCmd.Output()
if err != nil {
return nil, errors.New("failed to execute header file command")
}
fmt.Println("headerFileOutput:", string(headerFileOutput), len(headerFileOutput))
t := make([]common.ASTInformation, 0)
err = json.Unmarshal(headerFileOutput, &t)
if err != nil {
@@ -234,11 +240,14 @@ func generateMangle(astInfo common.ASTInformation, count int) string {
res += "__" + strconv.Itoa(count-1)
}
} else {
res = "(*" + astInfo.Class + ")." + astInfo.Name + "__" + string(rune(count))
res = "(*" + astInfo.Class + ")." + astInfo.Name
if count > 1 {
res += "__" + strconv.Itoa(count-1)
}
}
} else {
res = astInfo.Name
if count > 0 {
if count > 1 {
res += "__" + strconv.Itoa(count-1)
}
}