diff --git a/_xtool/llcppsigfetch/dbg/debug.go b/_xtool/llcppsigfetch/dbg/debug.go new file mode 100644 index 00000000..5d74bbc2 --- /dev/null +++ b/_xtool/llcppsigfetch/dbg/debug.go @@ -0,0 +1,22 @@ +package dbg + +type dbgFlags = int + +var flags dbgFlags + +const ( + DbgParse dbgFlags = 1 << iota + DbgFlagAll = DbgParse +) + +func SetDebugParse() { + flags |= DbgParse +} + +func GetDebugParse() bool { + return flags&DbgParse != 0 +} + +func SetDebugAll() { + flags = DbgFlagAll +} diff --git a/_xtool/llcppsigfetch/llcppsigfetch.go b/_xtool/llcppsigfetch/llcppsigfetch.go index d6bf6e48..a5b54e57 100644 --- a/_xtool/llcppsigfetch/llcppsigfetch.go +++ b/_xtool/llcppsigfetch/llcppsigfetch.go @@ -22,6 +22,7 @@ import ( "os" "strings" + "github.com/goplus/llcppg/_xtool/llcppsigfetch/dbg" "github.com/goplus/llcppg/_xtool/llcppsigfetch/parse" "github.com/goplus/llcppg/_xtool/llcppsymg/args" "github.com/goplus/llcppg/_xtool/llcppsymg/clangutils" @@ -40,8 +41,11 @@ func main() { printUsage() return } + if ags.VerboseSigfetchParse { + dbg.SetDebugParse() + } if ags.Verbose { - parse.SetDebug(parse.DbgFlagAll) + dbg.SetDebugAll() } extract := false out := false diff --git a/_xtool/llcppsigfetch/parse/cvt.go b/_xtool/llcppsigfetch/parse/cvt.go index 5b4cee9c..a0f314a7 100644 --- a/_xtool/llcppsigfetch/parse/cvt.go +++ b/_xtool/llcppsigfetch/parse/cvt.go @@ -7,6 +7,7 @@ import ( "strings" "unsafe" + "github.com/goplus/llcppg/_xtool/llcppsigfetch/dbg" "github.com/goplus/llcppg/_xtool/llcppsymg/clangutils" "github.com/goplus/llcppg/ast" "github.com/goplus/llcppg/token" @@ -47,7 +48,7 @@ type Config struct { } func NewConverter(config *clangutils.Config) (*Converter, error) { - if debugParse { + if dbg.GetDebugParse() { fmt.Fprintln(os.Stderr, "NewConverter: config") fmt.Fprintln(os.Stderr, "config.File", config.File) fmt.Fprintln(os.Stderr, "config.Args", config.Args) @@ -131,12 +132,12 @@ func (ct *Converter) decIndent() { } func (ct *Converter) logf(format string, args ...interface{}) { - if debugParse { + if dbg.GetDebugParse() { fmt.Fprintf(os.Stderr, ct.logBase()+format, args...) } } func (ct *Converter) logln(args ...interface{}) { - if debugParse { + if dbg.GetDebugParse() { if len(args) > 0 { firstArg := fmt.Sprintf("%s%v", ct.logBase(), args[0]) fmt.Fprintln(os.Stderr, append([]interface{}{firstArg}, args[1:]...)...) @@ -501,7 +502,7 @@ func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl { defer ct.decIndent() name, kind := getCursorDesc(cursor) mangledName := toStr(cursor.Mangling()) - ct.logln("ProcessFuncDecl: CursorName:", name, "CursorKind:", kind) + ct.logln("ProcessFuncDecl: CursorName:", name, "CursorKind:", kind, "mangledName:", mangledName) // function type will only collect return type // ProcessType can't get the field names,will collect in follows @@ -525,7 +526,16 @@ func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl { // For function type references (e.g. `typedef void (fntype)(); fntype foo;`), // params are already processed in ProcessType via CanonicalType if fnType.Kind != clang.TypeElaborated { - funcType.Params = ct.ProcessFieldList(cursor) + numArgs := cursor.NumArguments() + numFields := c.Int(len(funcType.Params.List)) + for i := c.Int(0); i < numArgs; i++ { + arg := cursor.Argument(c.Uint(i)) + name := clang.GoString(arg.DisplayName()) + if len(name) > 0 && i < numFields { + field := funcType.Params.List[i] + field.Names = []*ast.Ident{&ast.Ident{Name: name}} + } + } } // Linux has one less leading underscore than macOS, so remove one leading underscore on macOS diff --git a/_xtool/llcppsigfetch/parse/parse.go b/_xtool/llcppsigfetch/parse/parse.go index 0971922b..fe73800b 100644 --- a/_xtool/llcppsigfetch/parse/parse.go +++ b/_xtool/llcppsigfetch/parse/parse.go @@ -6,26 +6,12 @@ import ( "os" "strings" + "github.com/goplus/llcppg/_xtool/llcppsigfetch/dbg" "github.com/goplus/llcppg/_xtool/llcppsymg/clangutils" "github.com/goplus/llcppg/types" "github.com/goplus/llgo/c/cjson" ) -type dbgFlags = int - -const ( - DbgParse dbgFlags = 1 << iota - DbgFlagAll = DbgParse -) - -var ( - debugParse bool -) - -func SetDebug(dbgFlags dbgFlags) { - debugParse = (dbgFlags & DbgParse) != 0 -} - type Context struct { Files []*FileEntry *ContextConfig @@ -52,7 +38,7 @@ func (p *Context) Output() *cjson.JSON { // ProcessFiles processes the given files and adds them to the context func (p *Context) ProcessFiles(files []string) error { - if debugParse { + if dbg.GetDebugParse() { fmt.Fprintln(os.Stderr, "ProcessFiles: files", files, "isCpp", p.Conf.Cplusplus) } for _, file := range files { @@ -65,12 +51,12 @@ func (p *Context) ProcessFiles(files []string) error { // parse file and add it to the context,avoid duplicate parsing func (p *Context) processFile(path string) error { - if debugParse { + if dbg.GetDebugParse() { fmt.Fprintln(os.Stderr, "processFile: path", path) } for _, entry := range p.Files { if entry.Path == path { - if debugParse { + if dbg.GetDebugParse() { fmt.Fprintln(os.Stderr, "processFile: already parsed", path) } return nil @@ -86,7 +72,7 @@ func (p *Context) processFile(path string) error { } func (p *Context) parseFile(path string) ([]*FileEntry, error) { - if debugParse { + if dbg.GetDebugParse() { fmt.Fprintln(os.Stderr, "parseFile: path", path) } converter, err := NewConverter(&clangutils.Config{ diff --git a/_xtool/llcppsymg/args/args.go b/_xtool/llcppsymg/args/args.go index b94263d2..601e5243 100644 --- a/_xtool/llcppsymg/args/args.go +++ b/_xtool/llcppsymg/args/args.go @@ -13,6 +13,7 @@ const LLCPPG_PUB = "llcppg.pub" type Args struct { Help bool Verbose bool + VerboseSigfetchParse bool //-vsp llcppsigfetch parse.go VerboseParseIsMethod bool //-vpim UseStdin bool CfgFile string @@ -34,6 +35,9 @@ func ParseArgs(args []string, defaultCfgFile string, swflags map[string]bool) (* case "-vpim": result.VerboseParseIsMethod = true continue + case "-vsp": + result.VerboseSigfetchParse = true + continue case "-": result.UseStdin = true continue