diff --git a/chore/_xtool/llcppsigfetch/parse/cvt.go b/chore/_xtool/llcppsigfetch/parse/cvt.go index 13c22898..842c5bd6 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt.go @@ -255,6 +255,12 @@ func (ct *Converter) ProcessFunctionType(t clang.Type) *ast.FuncType { }) } + if t.IsFunctionTypeVariadic() != 0 { + params.List = append(params.List, &ast.Field{ + Type: &ast.Variadic{}, + }) + } + return &ast.FuncType{ Ret: ret, Params: params, @@ -296,38 +302,7 @@ func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl { } if isMethod(cursor) { - - if parent := cursor.SemanticParent(); parent.Equal(cursor.LexicalParent()) != 1 { - fn.DeclBase.Parent = buildScopingExpr(cursor.SemanticParent()) - } - - if cursor.Kind == clang.CursorDestructor { - fn.IsDestructor = true - } - if cursor.Kind == clang.CursorConstructor { - fn.IsConstructor = true - if cursor.IsExplicit() != 0 { - fn.IsExplicit = true - } - } - if cursor.IsStatic() != 0 { - fn.IsStatic = true - } - // virtual & pure virtual - if cursor.IsVirtual() != 0 || cursor.IsPureVirtual() != 0 { - fn.IsVirtual = true - } - if cursor.IsConst() != 0 { - fn.IsConst = true - } - - var numOverridden c.Uint - var overridden *clang.Cursor - cursor.OverriddenCursors(&overridden, &numOverridden) - if numOverridden > 0 { - fn.IsOverride = true - } - overridden.DisposeOverriddenCursors() + ct.ProcessMethodAttributes(cursor, fn) } else { if cursor.StorageClass() == clang.SCStatic { fn.IsStatic = true @@ -337,6 +312,41 @@ func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl { return fn } +// get Methods Attributes +func (ct *Converter) ProcessMethodAttributes(cursor clang.Cursor, fn *ast.FuncDecl) { + if parent := cursor.SemanticParent(); parent.Equal(cursor.LexicalParent()) != 1 { + fn.DeclBase.Parent = buildScopingExpr(cursor.SemanticParent()) + } + + switch cursor.Kind { + case clang.CursorDestructor: + fn.IsDestructor = true + case clang.CursorConstructor: + fn.IsConstructor = true + if cursor.IsExplicit() != 0 { + fn.IsExplicit = true + } + } + + if cursor.IsStatic() != 0 { + fn.IsStatic = true + } + if cursor.IsVirtual() != 0 || cursor.IsPureVirtual() != 0 { + fn.IsVirtual = true + } + if cursor.IsConst() != 0 { + fn.IsConst = true + } + + var numOverridden c.Uint + var overridden *clang.Cursor + cursor.OverriddenCursors(&overridden, &numOverridden) + if numOverridden > 0 { + fn.IsOverride = true + } + overridden.DisposeOverriddenCursors() +} + type visitEnumContext struct { enum *[]*ast.EnumItem converter *Converter @@ -449,12 +459,18 @@ func visitFieldList(cursor, parent clang.Cursor, clientData unsafe.Pointer) clan return clang.ChildVisit_Continue } +// For Record Type(struct,union ...) & Func 's FieldList func (ct *Converter) ProcessFieldList(cursor clang.Cursor) *ast.FieldList { params := &ast.FieldList{List: []*ast.Field{}} ctx := &visitFieldContext{ params: params, converter: ct, } + if (cursor.Kind == clang.CursorFunctionDecl || isMethod(cursor)) && cursor.IsVariadic() != 0 { + params.List = append(params.List, &ast.Field{ + Type: &ast.Variadic{}, + }) + } clang.VisitChildren(cursor, visitFieldList, c.Pointer(ctx)) return params } diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/func_test/func.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/func_test/func.go index 55caff06..f2e18e17 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/func_test/func.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/func_test/func.go @@ -10,6 +10,7 @@ func TestFuncDecl() { testCases := []string{ `void foo();`, `void foo(int a);`, + `void foo(int a,...);`, `float* foo(int a,double b);`, `static inline int add(int a, int b);`, } 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 638976bb..227f446c 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 @@ -88,6 +88,63 @@ TestFuncDecl Case 2: } TestFuncDecl Case 3: +{ + "temp.h": { + "decls": [{ + "Loc": { + "File": "temp.h" + }, + "Doc": { + "List": [] + }, + "Parent": null, + "Name": { + "Name": "foo" + }, + "Type": { + "Params": { + "List": [{ + "Type": { + }, + "Doc": null, + "Comment": null, + "Names": [] + }, { + "Type": { + "Kind": 6, + "Flags": 0 + }, + "Doc": { + "List": [] + }, + "Comment": { + "List": [] + }, + "Names": [{ + "Name": "a" + }] + }] + }, + "Ret": { + "Kind": 0, + "Flags": 0 + } + }, + "IsInline": false, + "IsStatic": false, + "IsConst": false, + "IsExplicit": false, + "IsConstructor": false, + "IsDestructor": false, + "IsVirtual": false, + "IsOverride": false + }], + "includes": [], + "macros": [] + } +} + +TestFuncDecl Case 4: { "temp.h": { "decls": [{ @@ -154,7 +211,7 @@ TestFuncDecl Case 3: } } -TestFuncDecl Case 4: +TestFuncDecl Case 5: { "temp.h": { "decls": [{ diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/typedef_test/llgo.expect b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/typedef_test/llgo.expect index 98f60b2c..d88c973a 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/typedef_test/llgo.expect +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/typedef_test/llgo.expect @@ -94,6 +94,12 @@ TestTypeDefDecl Case 3: "Doc": null, "Comment": null, "Names": [] + }, { + "Type": { + }, + "Doc": null, + "Comment": null, + "Names": [] }] }, "Ret": { diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/typedef_test/typedef.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/typedef_test/typedef.go index 7b2548cf..240fc660 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/typedef_test/typedef.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/typedef_test/typedef.go @@ -13,7 +13,7 @@ func TestTypeDefDecl() { `typedef int INT; typedef INT STANDARD_INT;`, - `typedef int (*Foo)(int, int);`, + `typedef int (*Foo)(int, int, ...);`, } test.RunTest("TestTypeDefDecl", testCases) } diff --git a/chore/_xtool/llcppsigfetch/parse/dump.go b/chore/_xtool/llcppsigfetch/parse/dump.go index 17b37f1e..5cc02bb0 100644 --- a/chore/_xtool/llcppsigfetch/parse/dump.go +++ b/chore/_xtool/llcppsigfetch/parse/dump.go @@ -148,6 +148,7 @@ func MarshalASTExpr(t ast.Expr) *cjson.JSON { names.AddItem(MarshalASTExpr(n)) } root.SetItem(c.Str("Names"), names) + case *ast.Variadic: case *ast.Ident: if d == nil { return cjson.Null()