1
0
mirror of https://github.com/golang/go synced 2024-10-01 03:28:32 -06:00

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:
Alan Donovan 2013-11-20 16:00:23 -05:00
parent b844907f9f
commit 2e33158b60
4 changed files with 20 additions and 8 deletions

View File

@ -639,10 +639,22 @@ func describeType(o *Oracle, qpos *QueryPos, path []ast.Node) (*describeTypeResu
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{
qpos: qpos,
node: path[0],
description: description + "type " + qpos.TypeString(t),
description: description,
typ: t,
methods: accessibleMethods(t, qpos.info.Pkg),
}, nil

View File

@ -133,7 +133,7 @@
{
"mode": "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",
"detail": "type",
"type": {

View File

@ -50,13 +50,13 @@ reference to interface method func (I).f()
defined here
-------- @describe type-D --------
reference to type D
reference to type D (size 0, align 1)
defined as struct{}
Method set:
method (D) f()
-------- @describe type-I --------
reference to type I
reference to type I (size 16, align 8)
defined as interface{f()}
Method set:
method (I) f()
@ -140,11 +140,11 @@ reference to const localpi untyped float of constant value 3141/1000
defined here
-------- @describe type-def-T --------
definition of type T
definition of type T (size 8, align 8)
No methods.
-------- @describe type-ref-T --------
reference to type T
reference to type T (size 8, align 8)
defined as int
No methods.
@ -186,7 +186,7 @@ definition of var b *int
no points-to information: PTA did not encounter this expression (dead code?)
-------- @describe def-iface-I --------
definition of type I
definition of type I (size 16, align 8)
Method set:
method (I) f()

View File

@ -19,7 +19,7 @@ reference to var lib.Var int
defined here
-------- @describe ref-type --------
reference to type lib.Type
reference to type lib.Type (size 8, align 8)
defined as int
Method set:
method (lib.Type) Method(x *int) *int