From fc04083cb2be2dd0e527ff39cb56e1fa9dacb5f7 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Mon, 26 Aug 2024 14:17:33 +0800 Subject: [PATCH] llcppsigfetch:collect public methods --- chore/_xtool/llcppsigfetch/parse/cvt.go | 7 +++++-- .../parse/cvt_test/decl_test/class_test/class.go | 7 +++++++ .../parse/cvt_test/decl_test/scope_test/scope.go | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/chore/_xtool/llcppsigfetch/parse/cvt.go b/chore/_xtool/llcppsigfetch/parse/cvt.go index a4f38f99..d59485c3 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt.go @@ -300,7 +300,7 @@ func (ct *Converter) ProcessFuncDecl(cursor clang.Cursor) *ast.FuncDecl { fn.IsInline = true } - if cursor.Kind == clang.CursorCXXMethod || cursor.Kind == clang.CursorDestructor || cursor.Kind == clang.CursorConstructor { + if isMethod(cursor) { if cursor.Kind == clang.CursorDestructor { fn.IsDestructor = true } @@ -466,7 +466,7 @@ type visitMethodsContext struct { func visitMethods(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVisitResult { ctx := (*visitMethodsContext)(clientData) - if cursor.Kind == clang.CursorCXXMethod || cursor.Kind == clang.CursorConstructor || cursor.Kind == clang.CursorDestructor { + if isMethod(cursor) && cursor.CXXAccessSpecifier() != clang.CXXPrivate { method := ctx.converter.ProcessFuncDecl(cursor) if method != nil { *ctx.methods = append(*ctx.methods, method) @@ -653,6 +653,9 @@ func toToken(tok clang.Token) token.Token { return token.Token(tok.Kind() + 1) } } +func isMethod(cursor clang.Cursor) bool { + return cursor.Kind == clang.CursorCXXMethod || cursor.Kind == clang.CursorConstructor || cursor.Kind == clang.CursorDestructor +} func qualifiedExpr(name string) ast.Expr { parts := strings.Split(name, "::") diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/class_test/class.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/class_test/class.go index 5da535c8..65f4ca5f 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/class_test/class.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/class_test/class.go @@ -9,26 +9,33 @@ func main() { func TestClassDecl() { testCases := []string{ `class A { + public: int a; int b; };`, `class A { + public: int a; int b; float foo(int a,double b); + private: + void bar(); };`, `class A { + public: A(); explicit A(); ~A(); static inline void foo(); };`, `class Base { + public: Base(); virtual ~Base(); virtual void foo(); }; class Derived : public Base { + public: Derived(); ~Derived() override; void foo() override; diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/scope_test/scope.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/scope_test/scope.go index 4c6985ce..29332bfb 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/scope_test/scope.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/decl_test/scope_test/scope.go @@ -18,10 +18,12 @@ func TestScope() { } }`, `class a { + public: void foo(); };`, `namespace a { class b { + public: void foo(); }; }`,