From 10f0067eb1394491fe079dd2df6cab2a7039219b Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 2 Jan 2014 10:07:48 -0800 Subject: [PATCH] go.tools/go.types: cleanups Per feedback for CL 37250044. R=adonovan CC=golang-codereviews https://golang.org/cl/47150043 --- go/importer/export.go | 16 +++++++++------- go/importer/import.go | 11 +++++++---- go/importer/import_test.go | 10 +++------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/go/importer/export.go b/go/importer/export.go index 62f51535..4723a164 100644 --- a/go/importer/export.go +++ b/go/importer/export.go @@ -218,6 +218,8 @@ func (p *exporter) fraction(x exact.Value) { p.ufloat(exact.Denom(x)) } +// ufloat writes abs(x) in form of a binary exponent +// followed by its mantissa bytes; x must be != 0. func (p *exporter) ufloat(x exact.Value) { mant := exact.Bytes(x) exp8 := -1 @@ -288,6 +290,13 @@ func (p *exporter) typ(typ types.Type) { case *types.Interface: p.int(interfaceTag) + // write embedded interfaces + m := t.NumEmbeddeds() + p.int(m) + for i := 0; i < m; i++ { + p.typ(t.Embedded(i)) + } + // write methods n := t.NumExplicitMethods() p.int(n) @@ -297,13 +306,6 @@ func (p *exporter) typ(typ types.Type) { p.typ(m.Type()) } - // write embedded interfaces - m := t.NumEmbeddeds() - p.int(m) - for i := 0; i < m; i++ { - p.typ(t.Embedded(i)) - } - case *types.Map: p.int(mapTag) p.typ(t.Key()) diff --git a/go/importer/import.go b/go/importer/import.go index 0832050e..7e0e5b57 100644 --- a/go/importer/import.go +++ b/go/importer/import.go @@ -253,16 +253,19 @@ func (p *importer) typ() types.Type { t := new(types.Interface) p.record(t) + // read embedded interfaces + embeddeds := make([]*types.Named, p.int()) + for i := range embeddeds { + embeddeds[i] = p.typ().(*types.Named) + } + + // read methods methods := make([]*types.Func, p.int()) for i := range methods { pkg, name := p.qualifiedName() methods[i] = types.NewFunc(token.NoPos, pkg, name, p.typ().(*types.Signature)) } - embeddeds := make([]*types.Named, p.int()) - for i := range embeddeds { - embeddeds[i] = p.typ().(*types.Named) - } *t = *types.NewInterface(methods, embeddeds) return t diff --git a/go/importer/import_test.go b/go/importer/import_test.go index b47b22f3..6bee004f 100644 --- a/go/importer/import_test.go +++ b/go/importer/import_test.go @@ -7,7 +7,6 @@ package importer import ( "bufio" "bytes" - "flag" "fmt" "go/ast" "go/build" @@ -24,8 +23,6 @@ import ( "code.google.com/p/go.tools/go/types" ) -var verbose = flag.Bool("importer.v", false, "verbose mode") - var tests = []string{ `package p`, @@ -108,7 +105,7 @@ func TestImportStdLib(t *testing.T) { // can be compared reasonably well types.GcCompatibilityMode = true - var totSize, totGcsize, n int + var totSize, totGcsize int for _, lib := range libs { // limit run time for short tests if testing.Short() && time.Since(start) >= 750*time.Millisecond { @@ -128,15 +125,14 @@ func TestImportStdLib(t *testing.T) { } size, gcsize := testExportImport(t, pkg, lib) - if *verbose { + if testing.Verbose() { fmt.Printf("%s\t%d\t%d\t%d%%\n", lib, size, gcsize, int(float64(size)*100/float64(gcsize))) } totSize += size totGcsize += gcsize - n++ } - if *verbose { + if testing.Verbose() { fmt.Printf("\n%d\t%d\t%d%%\n", totSize, totGcsize, int(float64(totSize)*100/float64(totGcsize))) }