mirror of
https://github.com/golang/go
synced 2024-11-18 21:34:46 -07:00
go.oracle: describe: disambiguate 'func' object kinds.
The typechecker uses *types.Func for functions, concrete methods and interface methods; and *types.Var for variables and struct fields. This change makes clear which kind of function we're describing. (We can't do it for vars since go/types doesn't expose enough information, yet.) Also: add "omitempty" to one JSON field. R=crawshaw CC=golang-dev https://golang.org/cl/13527044
This commit is contained in:
parent
b21b4e8c88
commit
a1dade8bdc
@ -448,19 +448,36 @@ type describeValueResult struct {
|
||||
}
|
||||
|
||||
func (r *describeValueResult) display(printf printfFunc) {
|
||||
suffix := ""
|
||||
var prefix, suffix string
|
||||
if r.constVal != nil {
|
||||
suffix = fmt.Sprintf(" of constant value %s", r.constVal)
|
||||
}
|
||||
switch obj := r.obj.(type) {
|
||||
case *types.Func:
|
||||
if recv := obj.Type().(*types.Signature).Recv(); recv != nil {
|
||||
if _, ok := recv.Type().Underlying().(*types.Interface); ok {
|
||||
prefix = "interface method "
|
||||
} else {
|
||||
prefix = "method "
|
||||
}
|
||||
}
|
||||
|
||||
case *types.Var:
|
||||
// TODO(adonovan): go/types should make it simple to
|
||||
// ask: IsStructField(*Var)?
|
||||
if false {
|
||||
prefix = "struct field "
|
||||
}
|
||||
}
|
||||
|
||||
// Describe the expression.
|
||||
if r.obj != nil {
|
||||
if r.obj.Pos() == r.expr.Pos() {
|
||||
// defining ident
|
||||
printf(r.expr, "definition of %s%s", r.obj, suffix)
|
||||
printf(r.expr, "definition of %s%s%s", prefix, r.obj, suffix)
|
||||
} else {
|
||||
// referring ident
|
||||
printf(r.expr, "reference to %s%s", r.obj, suffix)
|
||||
printf(r.expr, "reference to %s%s%s", prefix, r.obj, suffix)
|
||||
if def := r.obj.Pos(); def != token.NoPos {
|
||||
printf(def, "defined here")
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ type DescribePTALabel struct {
|
||||
//
|
||||
type DescribePointer struct {
|
||||
Type string `json:"type"` // (concrete) type of the pointer
|
||||
NamePos string `json:"namepos"` // location of type defn, if Named
|
||||
NamePos string `json:"namepos,omitempty"` // location of type defn, if Named
|
||||
Labels []DescribePTALabel `json:"labels,omitempty"` // pointed-to objects
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,6 @@
|
||||
"pts": [
|
||||
{
|
||||
"type": "*int",
|
||||
"namepos": "",
|
||||
"labels": [
|
||||
{
|
||||
"pos": "testdata/src/main/describe-json.go:10:6",
|
||||
|
10
oracle/testdata/src/main/describe.golden
vendored
10
oracle/testdata/src/main/describe.golden
vendored
@ -35,15 +35,15 @@ reference to func describe.main()
|
||||
defined here
|
||||
|
||||
-------- @describe func-ref-*C.f --------
|
||||
reference to func (*describe.C).f()
|
||||
reference to method func (*describe.C).f()
|
||||
defined here
|
||||
|
||||
-------- @describe func-ref-D.f --------
|
||||
reference to func (describe.D).f()
|
||||
reference to method func (describe.D).f()
|
||||
defined here
|
||||
|
||||
-------- @describe func-ref-I.f --------
|
||||
reference to func (describe.I).f()
|
||||
reference to interface method func (describe.I).f()
|
||||
defined here
|
||||
|
||||
-------- @describe type-D --------
|
||||
@ -59,11 +59,11 @@ Method set:
|
||||
method (describe.I) f()
|
||||
|
||||
-------- @describe func-ref-d.f --------
|
||||
reference to func (describe.D).f()
|
||||
reference to method func (describe.D).f()
|
||||
defined here
|
||||
|
||||
-------- @describe func-ref-i.f --------
|
||||
reference to func (describe.I).f()
|
||||
reference to interface method func (describe.I).f()
|
||||
defined here
|
||||
|
||||
-------- @describe ref-lexical-d --------
|
||||
|
2
oracle/testdata/src/main/imports.golden
vendored
2
oracle/testdata/src/main/imports.golden
vendored
@ -27,7 +27,7 @@ Method set:
|
||||
method (lib.Type) Method(x *int) *int
|
||||
|
||||
-------- @describe ref-method --------
|
||||
reference to func (lib.Type).Method(x *int) *int
|
||||
reference to method func (lib.Type).Method(x *int) *int
|
||||
defined here
|
||||
|
||||
-------- @describe p --------
|
||||
|
Loading…
Reference in New Issue
Block a user