go.tools/oracle: show size and alignment for structs and named types.
Users should be familiar with the sizes of all other types. Currently we assume amd64 (as do other parts of the oracle, e.g. go/build tags). Will parameterize later. R=crawshaw CC=golang-dev, gri https://golang.org/cl/29710043
This commit is contained in:
parent
b844907f9f
commit
2e33158b60
|
|
@ -639,10 +639,22 @@ func describeType(o *Oracle, qpos *QueryPos, path []ast.Node) (*describeTypeResu
|
||||||
return nil, fmt.Errorf("unexpected AST for type: %T", n)
|
return nil, fmt.Errorf("unexpected AST for type: %T", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
description = description + "type " + qpos.TypeString(t)
|
||||||
|
|
||||||
|
// Show sizes for structs and named types (it's fairly obvious for others).
|
||||||
|
switch t.(type) {
|
||||||
|
case *types.Named, *types.Struct:
|
||||||
|
// TODO(adonovan): use o.imp.Config().TypeChecker.Sizes when
|
||||||
|
// we add the Config() method (needs some thought).
|
||||||
|
szs := types.StdSizes{8, 8}
|
||||||
|
description = fmt.Sprintf("%s (size %d, align %d)", description,
|
||||||
|
szs.Sizeof(t), szs.Alignof(t))
|
||||||
|
}
|
||||||
|
|
||||||
return &describeTypeResult{
|
return &describeTypeResult{
|
||||||
qpos: qpos,
|
qpos: qpos,
|
||||||
node: path[0],
|
node: path[0],
|
||||||
description: description + "type " + qpos.TypeString(t),
|
description: description,
|
||||||
typ: t,
|
typ: t,
|
||||||
methods: accessibleMethods(t, qpos.info.Pkg),
|
methods: accessibleMethods(t, qpos.info.Pkg),
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@
|
||||||
{
|
{
|
||||||
"mode": "describe",
|
"mode": "describe",
|
||||||
"describe": {
|
"describe": {
|
||||||
"desc": "definition of type C",
|
"desc": "definition of type C (size 8, align 8)",
|
||||||
"pos": "testdata/src/main/describe-json.go:27:6",
|
"pos": "testdata/src/main/describe-json.go:27:6",
|
||||||
"detail": "type",
|
"detail": "type",
|
||||||
"type": {
|
"type": {
|
||||||
|
|
|
||||||
|
|
@ -50,13 +50,13 @@ reference to interface method func (I).f()
|
||||||
defined here
|
defined here
|
||||||
|
|
||||||
-------- @describe type-D --------
|
-------- @describe type-D --------
|
||||||
reference to type D
|
reference to type D (size 0, align 1)
|
||||||
defined as struct{}
|
defined as struct{}
|
||||||
Method set:
|
Method set:
|
||||||
method (D) f()
|
method (D) f()
|
||||||
|
|
||||||
-------- @describe type-I --------
|
-------- @describe type-I --------
|
||||||
reference to type I
|
reference to type I (size 16, align 8)
|
||||||
defined as interface{f()}
|
defined as interface{f()}
|
||||||
Method set:
|
Method set:
|
||||||
method (I) f()
|
method (I) f()
|
||||||
|
|
@ -140,11 +140,11 @@ reference to const localpi untyped float of constant value 3141/1000
|
||||||
defined here
|
defined here
|
||||||
|
|
||||||
-------- @describe type-def-T --------
|
-------- @describe type-def-T --------
|
||||||
definition of type T
|
definition of type T (size 8, align 8)
|
||||||
No methods.
|
No methods.
|
||||||
|
|
||||||
-------- @describe type-ref-T --------
|
-------- @describe type-ref-T --------
|
||||||
reference to type T
|
reference to type T (size 8, align 8)
|
||||||
defined as int
|
defined as int
|
||||||
No methods.
|
No methods.
|
||||||
|
|
||||||
|
|
@ -186,7 +186,7 @@ definition of var b *int
|
||||||
no points-to information: PTA did not encounter this expression (dead code?)
|
no points-to information: PTA did not encounter this expression (dead code?)
|
||||||
|
|
||||||
-------- @describe def-iface-I --------
|
-------- @describe def-iface-I --------
|
||||||
definition of type I
|
definition of type I (size 16, align 8)
|
||||||
Method set:
|
Method set:
|
||||||
method (I) f()
|
method (I) f()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ reference to var lib.Var int
|
||||||
defined here
|
defined here
|
||||||
|
|
||||||
-------- @describe ref-type --------
|
-------- @describe ref-type --------
|
||||||
reference to type lib.Type
|
reference to type lib.Type (size 8, align 8)
|
||||||
defined as int
|
defined as int
|
||||||
Method set:
|
Method set:
|
||||||
method (lib.Type) Method(x *int) *int
|
method (lib.Type) Method(x *int) *int
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue