c/clang/symg:refine config usage

This commit is contained in:
luoliwoshang
2024-07-30 09:33:05 +08:00
parent 1219230168
commit 67b10d8d38
2 changed files with 25 additions and 10 deletions

View File

@@ -53,6 +53,7 @@ func main() {
config, err := getConf(data) config, err := getConf(data)
check(err) check(err)
defer config.Delete()
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "Failed to parse config file:", cfgFile) fmt.Fprintln(os.Stderr, "Failed to parse config file:", cfgFile)
@@ -77,19 +78,24 @@ func check(err error) {
} }
} }
func getConf(data []byte) (*types.Config, error) { func getConf(data []byte) (types.Conf, error) {
conf := cjson.ParseBytes(data) parsedConf := cjson.ParseBytes(data)
if conf == nil { if parsedConf == nil {
return nil, errors.New("failed to parse config") return types.Conf{}, errors.New("failed to parse config")
} }
config := &types.Config{ config := &types.Config{
Name: getStringItem(conf, "name", ""), Name: getStringItem(parsedConf, "name", ""),
CFlags: getStringItem(conf, "cflags", ""), CFlags: getStringItem(parsedConf, "cflags", ""),
Libs: getStringItem(conf, "libs", ""), Libs: getStringItem(parsedConf, "libs", ""),
Include: getStringArrayItem(conf, "include"), Include: getStringArrayItem(parsedConf, "include"),
TrimPrefixes: getStringArrayItem(conf, "trimPrefixes"), TrimPrefixes: getStringArrayItem(parsedConf, "trimPrefixes"),
} }
return config, nil
return types.Conf{
JSON: parsedConf,
Config: config,
}, nil
} }
func getString(obj *cjson.JSON) (value string) { func getString(obj *cjson.JSON) (value string) {

View File

@@ -16,6 +16,10 @@
package types package types
import (
"github.com/goplus/llgo/c/cjson"
)
// Config represents a configuration for the llcppg tool. // Config represents a configuration for the llcppg tool.
type Config struct { type Config struct {
Name string `json:"name"` Name string `json:"name"`
@@ -26,6 +30,11 @@ type Config struct {
JSONPath string `json:"jsonPath"` JSONPath string `json:"jsonPath"`
} }
type Conf struct {
*cjson.JSON
*Config
}
type CPPSymbol struct { type CPPSymbol struct {
Symbol string `json:"symbol"` Symbol string `json:"symbol"`
Type string `json:"type"` Type string `json:"type"`