From b1eb2412c509c3468adcef49c17e67be20204269 Mon Sep 17 00:00:00 2001 From: Haolan Date: Thu, 3 Jul 2025 19:08:42 +0800 Subject: [PATCH 1/2] feat: filter static function for AST scanning --- _xtool/llcppsymg/internal/symg/parse.go | 11 +++++++++-- _xtool/llcppsymg/internal/symg/symg_test.go | 3 +++ .../internal/symg/testdata/include/src/core/core.h | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/_xtool/llcppsymg/internal/symg/parse.go b/_xtool/llcppsymg/internal/symg/parse.go index ac688a10..dd73813d 100644 --- a/_xtool/llcppsymg/internal/symg/parse.go +++ b/_xtool/llcppsymg/internal/symg/parse.go @@ -226,8 +226,15 @@ func (p *SymbolProcessor) visitTop(cursor, parent clang.Cursor) clang.ChildVisit case clang.CursorNamespace, clang.CursorClassDecl: clangutils.VisitChildren(cursor, p.visitTop) case clang.CursorCXXMethod, clang.CursorFunctionDecl, clang.CursorConstructor, clang.CursorDestructor: - isPublicMethod := (cursor.CXXAccessSpecifier() == clang.CXXPublic) && cursor.Kind == clang.CursorCXXMethod || cursor.Kind == clang.CursorConstructor || cursor.Kind == clang.CursorDestructor - if p.isSelfFile(filename) && (cursor.Kind == clang.CursorFunctionDecl || isPublicMethod) { + isPublicFunc := cursor.Kind == clang.CursorFunctionDecl && + cursor.StorageClass() != clang.SCStatic + + isPublicMethod := cursor.CXXAccessSpecifier() == clang.CXXPublic && + cursor.Kind == clang.CursorCXXMethod || + cursor.Kind == clang.CursorConstructor || + cursor.Kind == clang.CursorDestructor + + if p.isSelfFile(filename) && (isPublicFunc || isPublicMethod) { p.collectFuncInfo(cursor) } } diff --git a/_xtool/llcppsymg/internal/symg/symg_test.go b/_xtool/llcppsymg/internal/symg/symg_test.go index c48dfd7b..bfa60ee2 100644 --- a/_xtool/llcppsymg/internal/symg/symg_test.go +++ b/_xtool/llcppsymg/internal/symg/symg_test.go @@ -428,6 +428,7 @@ func TestGen(t *testing.T) { "ZN9INIReaderD1Ev", "ZNK9INIReader10ParseErrorEv", "ZNK9INIReader3GetEPKcS1_S1_", + "ZN9INIReader7MakeKeyERKiS1_", }, }, { @@ -474,6 +475,8 @@ func TestGen(t *testing.T) { "Foo", "Foo_Bar", "Foo_Conf", + "Foo_Bar_Private", + "Foo_Bar_Private2", }, }, } diff --git a/_xtool/llcppsymg/internal/symg/testdata/include/src/core/core.h b/_xtool/llcppsymg/internal/symg/testdata/include/src/core/core.h index cd8944f3..85d1277f 100644 --- a/_xtool/llcppsymg/internal/symg/testdata/include/src/core/core.h +++ b/_xtool/llcppsymg/internal/symg/testdata/include/src/core/core.h @@ -1,2 +1,7 @@ #include "../conf.h" void Foo_Bar(); + +#define private static +static void Foo_Bar_Private(); +private +void Foo_Bar_Private2(); From 419f2f5aea65d4e19ad2a706d5d5f27503ef3d3c Mon Sep 17 00:00:00 2001 From: Haolan Date: Thu, 3 Jul 2025 19:36:49 +0800 Subject: [PATCH 2/2] test: add comments for private fields filtering --- _xtool/llcppsymg/internal/symg/symg_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/_xtool/llcppsymg/internal/symg/symg_test.go b/_xtool/llcppsymg/internal/symg/symg_test.go index bfa60ee2..35eb275e 100644 --- a/_xtool/llcppsymg/internal/symg/symg_test.go +++ b/_xtool/llcppsymg/internal/symg/symg_test.go @@ -428,6 +428,9 @@ func TestGen(t *testing.T) { "ZN9INIReaderD1Ev", "ZNK9INIReader10ParseErrorEv", "ZNK9INIReader3GetEPKcS1_S1_", + // Check whether private fields are filtered. + // If not, the result will certainly not match expect.json. + // NOTE(MeteorsLiu): Symbols below this comment must be removed during regeneration. "ZN9INIReader7MakeKeyERKiS1_", }, }, @@ -475,6 +478,8 @@ func TestGen(t *testing.T) { "Foo", "Foo_Bar", "Foo_Conf", + // only for checking the result of private fields filtering + // NOTE(MeteorsLiu): Symbols below this comment must be removed during regeneration. "Foo_Bar_Private", "Foo_Bar_Private2", },