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 (
|
|
|
|
"golang.org/x/tools/go/types"
|
|
|
|
)
|
|
|
|
|
2015-07-28 12:33:47 +00:00
|
|
|
type Object interface {
|
2015-07-28 10:38:11 +00:00
|
|
|
Package() *Package
|
2015-07-28 10:26:33 +00:00
|
|
|
ID() string
|
|
|
|
Doc() string
|
2015-07-28 12:33:47 +00:00
|
|
|
GoName() string
|
2015-07-28 10:26:33 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 12:33:47 +00:00
|
|
|
type Type interface {
|
|
|
|
Object
|
|
|
|
GoType() types.Type
|
|
|
|
}
|
|
|
|
|
2015-07-24 14:16:31 +00:00
|
|
|
func needWrapType(typ types.Type) bool {
|
|
|
|
switch typ.(type) {
|
2015-08-07 11:43:07 +00:00
|
|
|
case *types.Basic:
|
|
|
|
return false
|
2015-07-24 14:16:31 +00:00
|
|
|
case *types.Struct:
|
|
|
|
return true
|
|
|
|
case *types.Named:
|
2015-08-07 11:43:07 +00:00
|
|
|
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.Slice:
|
|
|
|
return true
|
|
|
|
case *types.Interface:
|
2015-08-07 11:43:07 +00:00
|
|
|
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
|
2015-07-24 14:16:31 +00:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|