cgo: implement void* pointer type

void* is translated to unsafe.Pointer on the Go side.
This commit is contained in:
Ayke van Laethem
2019-04-20 15:48:45 +02:00
committed by Ron Evans
parent 9c46ac4eed
commit b815d3f760
5 changed files with 22 additions and 1 deletions
+15 -1
View File
@@ -307,9 +307,23 @@ func (info *fileInfo) makeASTType(typ C.CXType) ast.Expr {
typeName = "complex128"
}
case C.CXType_Pointer:
pointeeType := C.clang_getPointeeType(typ)
if pointeeType.kind == C.CXType_Void {
// void* type is translated to Go as unsafe.Pointer
return &ast.SelectorExpr{
X: &ast.Ident{
NamePos: info.importCPos,
Name: "unsafe",
},
Sel: &ast.Ident{
NamePos: info.importCPos,
Name: "Pointer",
},
}
}
return &ast.StarExpr{
Star: info.importCPos,
X: info.makeASTType(C.clang_getPointeeType(typ)),
X: info.makeASTType(pointeeType),
}
case C.CXType_ConstantArray:
return &ast.ArrayType{