gopy/bind/types.go

57 lines
1.0 KiB
Go
Raw Permalink Normal View History

2015-07-24 14:16:31 +00:00
// Copyright 2015 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package bind
import (
"go/types"
2015-07-24 14:16:31 +00:00
)
2015-07-28 12:33:47 +00:00
type Object interface {
Package() *Package
ID() string
Doc() string
2015-07-28 12:33:47 +00:00
GoName() string
}
2015-07-24 14:16:31 +00:00
func needWrapType(typ types.Type) bool {
switch typ := typ.(type) {
case *types.Basic:
return false
2015-07-24 14:16:31 +00:00
case *types.Struct:
return true
case *types.Named:
switch ut := typ.Underlying().(type) {
case *types.Basic:
return false
default:
return needWrapType(ut)
2015-07-24 14:16:31 +00:00
}
2015-07-31 16:01:49 +00:00
case *types.Array:
return true
case *types.Map:
return true
2015-07-31 16:01:49 +00:00
case *types.Slice:
return true
case *types.Interface:
wrap := true
if typ.Underlying() == universe.syms["error"].GoType().Underlying() {
wrap = false
}
return wrap
case *types.Signature:
2015-07-31 16:01:49 +00:00
return true
case *types.Pointer:
return needWrapType(typ.Elem())
2015-07-24 14:16:31 +00:00
}
return false
}
func gofmt(pkgname string, t types.Type) string {
return types.TypeString(
t,
func(*types.Package) string { return pkgname },
)
}