Skip to content

Commit

Permalink
Merge pull request #89 from tsingbx/llcppsigfetch/lost_receiver
Browse files Browse the repository at this point in the history
fix llcppgsigfetch: lost receiver
  • Loading branch information
luoliwoshang authored Dec 26, 2024
2 parents 56c14ad + 2a2ce1c commit ba626a8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
22 changes: 22 additions & 0 deletions _xtool/llcppsigfetch/dbg/debug.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 5 additions & 1 deletion _xtool/llcppsigfetch/llcppsigfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
20 changes: 15 additions & 5 deletions _xtool/llcppsigfetch/parse/cvt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:]...)...)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 5 additions & 19 deletions _xtool/llcppsigfetch/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions _xtool/llcppsymg/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ba626a8

Please sign in to comment.