llcppsigfetch:refine mock gettype
This commit is contained in:
@@ -2,7 +2,6 @@ package cvttest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/goplus/llgo/c"
|
"github.com/goplus/llgo/c"
|
||||||
"github.com/goplus/llgo/c/cjson"
|
"github.com/goplus/llgo/c/cjson"
|
||||||
@@ -74,22 +73,13 @@ func GetType(option *GetTypeOptions) (clang.Type, *clang.Index, *clang.Translati
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cursor := unit.Cursor()
|
cursor := unit.Cursor()
|
||||||
visitType := &typeVisitData{typ: &clang.Type{}, expectTypeKind: option.ExpectTypeKind}
|
var typ clang.Type
|
||||||
|
parse.VisitChildren(cursor, func(child, parent clang.Cursor) clang.ChildVisitResult {
|
||||||
clang.VisitChildren(cursor, typeVisit, unsafe.Pointer(visitType))
|
if child.Kind == clang.CursorVarDecl && (option.ExpectTypeKind == clang.TypeInvalid || option.ExpectTypeKind == child.Type().Kind) {
|
||||||
return *visitType.typ, index, unit
|
typ = child.Type()
|
||||||
}
|
|
||||||
|
|
||||||
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_Break
|
||||||
}
|
}
|
||||||
return clang.ChildVisit_Continue
|
return clang.ChildVisit_Continue
|
||||||
|
})
|
||||||
|
return typ, index, unit
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user