llcppsigfetch:refine mock gettype
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user