From 313e14bc5401d6350d80331179ba2356df5bc5d5 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Tue, 24 Sep 2024 15:09:03 +0800 Subject: [PATCH] llcppsigfetch:refine mock gettype --- .../llcppsigfetch/parse/cvt_test/cvt.go | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go b/chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go index da6cb3c2..f45a4f6a 100644 --- a/chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go +++ b/chore/_xtool/llcppsigfetch/parse/cvt_test/cvt.go @@ -2,7 +2,6 @@ package cvttest import ( "fmt" - "unsafe" "github.com/goplus/llgo/c" "github.com/goplus/llgo/c/cjson" @@ -74,22 +73,13 @@ func GetType(option *GetTypeOptions) (clang.Type, *clang.Index, *clang.Translati panic(err) } cursor := unit.Cursor() - visitType := &typeVisitData{typ: &clang.Type{}, expectTypeKind: option.ExpectTypeKind} - - clang.VisitChildren(cursor, typeVisit, unsafe.Pointer(visitType)) - return *visitType.typ, index, unit -} - -type typeVisitData struct { - typ *clang.Type - expectTypeKind clang.TypeKind -} - -func typeVisit(cursor, parent clang.Cursor, clientData unsafe.Pointer) clang.ChildVisitResult { - visitData := (*typeVisitData)(clientData) - if cursor.Kind == clang.CursorVarDecl && (visitData.expectTypeKind == clang.TypeInvalid || cursor.Type().Kind == visitData.expectTypeKind) { - *visitData.typ = cursor.Type() - return clang.ChildVisit_Break - } - return clang.ChildVisit_Continue + var typ clang.Type + parse.VisitChildren(cursor, func(child, parent clang.Cursor) clang.ChildVisitResult { + if child.Kind == clang.CursorVarDecl && (option.ExpectTypeKind == clang.TypeInvalid || option.ExpectTypeKind == child.Type().Kind) { + typ = child.Type() + return clang.ChildVisit_Break + } + return clang.ChildVisit_Continue + }) + return typ, index, unit }