From c8e06b58370d480daace4b5672570dd2c67f778c Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Tue, 10 Sep 2024 12:04:46 +0800 Subject: [PATCH] llcppsigfetch:func mangled name --- chore/_xtool/llcppsigfetch/parse/cvt.go | 16 ++++++++++++---- .../cvt_test/decl_test/class_test/llgo.expect | 12 ++++++++++++ .../cvt_test/decl_test/comment_test/llgo.expect | 10 ++++++++++ .../cvt_test/decl_test/func_test/llgo.expect | 5 +++++ .../cvt_test/decl_test/scope_test/llgo.expect | 5 +++++ chore/_xtool/llcppsigfetch/parse/dump.go | 1 + 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/chore/_xtool/llcppsigfetch/parse/cvt.go b/chore/_xtool/llcppsigfetch/parse/cvt.go index 83fb4e99..d6540994 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt.go @@ -434,10 +434,11 @@ func (ct *Converter) ProcessUnderlyingType(cursor clang.Cursor) ast.Expr { } // converts functions, methods, constructors, destructors (including out-of-class decl) to ast.FuncDecl nodes. -// todo(zzy): manglename (c++) func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl { name := cursor.String() + mangledName := cursor.Mangling() defer name.Dispose() + defer mangledName.Dispose() // function type will only collect return type // ProcessType can't get the field names,will collect in follows @@ -448,10 +449,17 @@ func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl { } params := ct.ProcessFieldList(cursor) funcType.Params = params + + mangledNameStr := c.GoString(mangledName.CStr()) + if len(mangledNameStr) >= 1 && mangledNameStr[0] == '_' { + mangledNameStr = mangledNameStr[1:] + } + funcDecl := &ast.FuncDecl{ - DeclBase: ct.CreateDeclBase(cursor), - Name: &ast.Ident{Name: c.GoString(name.CStr())}, - Type: funcType, + DeclBase: ct.CreateDeclBase(cursor), + Name: &ast.Ident{Name: c.GoString(name.CStr())}, + Type: funcType, + MangledName: mangledNameStr, } if cursor.IsFunctionInlined() != 0 { diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/class_test/llgo.expect b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/class_test/llgo.expect index 2b13b4e1..c75368df 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/class_test/llgo.expect +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/class_test/llgo.expect @@ -128,6 +128,7 @@ TestClassDecl Case 2: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_ZN1A3fooEid", "Type": { "_Type": "FuncType", "Params": { @@ -224,6 +225,7 @@ TestClassDecl Case 3: "_Type": "Ident", "Name": "A" }, + "MangledName": "_ZN1AC1Ev", "Type": { "_Type": "FuncType", "Params": { @@ -259,6 +261,7 @@ TestClassDecl Case 3: "_Type": "Ident", "Name": "A" }, + "MangledName": "_ZN1AC1Ev", "Type": { "_Type": "FuncType", "Params": { @@ -294,6 +297,7 @@ TestClassDecl Case 3: "_Type": "Ident", "Name": "~A" }, + "MangledName": "_ZN1AD1Ev", "Type": { "_Type": "FuncType", "Params": { @@ -329,6 +333,7 @@ TestClassDecl Case 3: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_ZN1A3fooEv", "Type": { "_Type": "FuncType", "Params": { @@ -395,6 +400,7 @@ TestClassDecl Case 4: "_Type": "Ident", "Name": "Base" }, + "MangledName": "_ZN4BaseC1Ev", "Type": { "_Type": "FuncType", "Params": { @@ -430,6 +436,7 @@ TestClassDecl Case 4: "_Type": "Ident", "Name": "~Base" }, + "MangledName": "_ZN4BaseD1Ev", "Type": { "_Type": "FuncType", "Params": { @@ -465,6 +472,7 @@ TestClassDecl Case 4: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_ZN4Base3fooEv", "Type": { "_Type": "FuncType", "Params": { @@ -521,6 +529,7 @@ TestClassDecl Case 4: "_Type": "Ident", "Name": "Derived" }, + "MangledName": "_ZN7DerivedC1Ev", "Type": { "_Type": "FuncType", "Params": { @@ -556,6 +565,7 @@ TestClassDecl Case 4: "_Type": "Ident", "Name": "~Derived" }, + "MangledName": "_ZN7DerivedD1Ev", "Type": { "_Type": "FuncType", "Params": { @@ -591,6 +601,7 @@ TestClassDecl Case 4: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_ZN7Derived3fooEv", "Type": { "_Type": "FuncType", "Params": { @@ -669,6 +680,7 @@ TestClassDecl Case 5: "_Type": "Ident", "Name": "bar" }, + "MangledName": "_ZN1A3Foo3barEv", "Type": { "_Type": "FuncType", "Params": { diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/comment_test/llgo.expect b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/comment_test/llgo.expect index 2b11b87f..0a08f88d 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/comment_test/llgo.expect +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/comment_test/llgo.expect @@ -15,6 +15,7 @@ TestDoc Case 1: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -57,6 +58,7 @@ TestDoc Case 2: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -105,6 +107,7 @@ TestDoc Case 3: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -153,6 +156,7 @@ TestDoc Case 4: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -201,6 +205,7 @@ TestDoc Case 5: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -252,6 +257,7 @@ TestDoc Case 6: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -303,6 +309,7 @@ TestDoc Case 7: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -354,6 +361,7 @@ TestDoc Case 8: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -411,6 +419,7 @@ TestDoc Case 9: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -698,6 +707,7 @@ TestDoc Case 11: "_Type": "Ident", "Name": "Foo" }, + "MangledName": "_ZN3Doc3FooEv", "Type": { "_Type": "FuncType", "Params": { diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/func_test/llgo.expect b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/func_test/llgo.expect index 135b4292..3332ed99 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/func_test/llgo.expect +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/func_test/llgo.expect @@ -15,6 +15,7 @@ TestFuncDecl Case 1: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -57,6 +58,7 @@ TestFuncDecl Case 2: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3fooi", "Type": { "_Type": "FuncType", "Params": { @@ -114,6 +116,7 @@ TestFuncDecl Case 3: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3fooiz", "Type": { "_Type": "FuncType", "Params": { @@ -181,6 +184,7 @@ TestFuncDecl Case 4: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3fooid", "Type": { "_Type": "FuncType", "Params": { @@ -256,6 +260,7 @@ TestFuncDecl Case 5: "_Type": "Ident", "Name": "add" }, + "MangledName": "_ZL3addii", "Type": { "_Type": "FuncType", "Params": { diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/scope_test/llgo.expect b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/scope_test/llgo.expect index 72584baa..66093d7f 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/scope_test/llgo.expect +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/scope_test/llgo.expect @@ -15,6 +15,7 @@ TestScope Case 1: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_Z3foov", "Type": { "_Type": "FuncType", "Params": { @@ -60,6 +61,7 @@ TestScope Case 2: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_ZN1a3fooEv", "Type": { "_Type": "FuncType", "Params": { @@ -112,6 +114,7 @@ TestScope Case 3: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_ZN1a1b3fooEv", "Type": { "_Type": "FuncType", "Params": { @@ -176,6 +179,7 @@ TestScope Case 4: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_ZN1a3fooEv", "Type": { "_Type": "FuncType", "Params": { @@ -252,6 +256,7 @@ TestScope Case 5: "_Type": "Ident", "Name": "foo" }, + "MangledName": "_ZN1a1b3fooEv", "Type": { "_Type": "FuncType", "Params": { diff --git a/chore/_xtool/llcppsigfetch/parse/dump.go b/chore/_xtool/llcppsigfetch/parse/dump.go index 932d8995..c235c4f2 100644 --- a/chore/_xtool/llcppsigfetch/parse/dump.go +++ b/chore/_xtool/llcppsigfetch/parse/dump.go @@ -124,6 +124,7 @@ func MarshalASTDecl(decl ast.Decl) *cjson.JSON { root.SetItem(c.Str("_Type"), stringField("FuncDecl")) MarshalASTDeclBase(d.DeclBase, root) root.SetItem(c.Str("Name"), MarshalASTExpr(d.Name)) + root.SetItem(c.Str("MangledName"), stringField(d.MangledName)) root.SetItem(c.Str("Type"), MarshalASTExpr(d.Type)) root.SetItem(c.Str("IsInline"), boolField(d.IsInline)) root.SetItem(c.Str("IsStatic"), boolField(d.IsStatic))