From 0d047c8d5a8c3a1c89d9d78511f4ed7aef49ea0c Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 22 Dec 2016 14:50:28 -0800 Subject: [PATCH] cmd/godex: handle printing of type aliases Also: remove go1.5 build tags (x/tools requires Go 1.6 or higher). For golang/go#18130. Change-Id: I3d9deee9e87d8794b2884281c0bb53caa5ed6221 Reviewed-on: https://go-review.googlesource.com/35106 Reviewed-by: Alan Donovan --- cmd/godex/gc.go | 2 -- cmd/godex/gccgo.go | 2 -- cmd/godex/godex.go | 2 -- cmd/godex/isAlias18.go | 13 +++++++++++++ cmd/godex/isAlias19.go | 13 +++++++++++++ cmd/godex/print.go | 10 +++++++--- cmd/godex/source.go | 2 -- cmd/godex/writetype.go | 2 -- 8 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 cmd/godex/isAlias18.go create mode 100644 cmd/godex/isAlias19.go diff --git a/cmd/godex/gc.go b/cmd/godex/gc.go index 66b0a0e617..95eba658b5 100644 --- a/cmd/godex/gc.go +++ b/cmd/godex/gc.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build go1.5 - // This file implements access to gc-generated export data. package main diff --git a/cmd/godex/gccgo.go b/cmd/godex/gccgo.go index 785441cd32..7644998d92 100644 --- a/cmd/godex/gccgo.go +++ b/cmd/godex/gccgo.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build go1.5 - // This file implements access to gccgo-generated export data. package main diff --git a/cmd/godex/godex.go b/cmd/godex/godex.go index 5d40d878f3..a222ed63c5 100644 --- a/cmd/godex/godex.go +++ b/cmd/godex/godex.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build go1.5 - package main import ( diff --git a/cmd/godex/isAlias18.go b/cmd/godex/isAlias18.go new file mode 100644 index 0000000000..cab1292681 --- /dev/null +++ b/cmd/godex/isAlias18.go @@ -0,0 +1,13 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !go1.9 + +package main + +import "go/types" + +func isAlias(obj *types.TypeName) bool { + return false // there are no type aliases before Go 1.9 +} diff --git a/cmd/godex/isAlias19.go b/cmd/godex/isAlias19.go new file mode 100644 index 0000000000..6ebdd42eb8 --- /dev/null +++ b/cmd/godex/isAlias19.go @@ -0,0 +1,13 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.9 + +package main + +import "go/types" + +func isAlias(obj *types.TypeName) bool { + return obj.IsAlias() +} diff --git a/cmd/godex/print.go b/cmd/godex/print.go index 02b46060d5..adce86462a 100644 --- a/cmd/godex/print.go +++ b/cmd/godex/print.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build go1.5 - package main import ( @@ -143,7 +141,13 @@ func (p *printer) printPackage(pkg *types.Package, filter func(types.Object) boo p.printDecl("type", len(typez), func() { for _, obj := range typez { p.printf("%s ", obj.Name()) - p.writeType(p.pkg, obj.Type().Underlying()) + typ := obj.Type() + if isAlias(obj) { + p.print("= ") + p.writeType(p.pkg, typ) + } else { + p.writeType(p.pkg, typ.Underlying()) + } p.print("\n") } }) diff --git a/cmd/godex/source.go b/cmd/godex/source.go index 0d3c006859..85235e9fa4 100644 --- a/cmd/godex/source.go +++ b/cmd/godex/source.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build go1.5 - // This file implements access to export data from source. package main diff --git a/cmd/godex/writetype.go b/cmd/godex/writetype.go index ed0bd9f2ff..dd17f90d7d 100644 --- a/cmd/godex/writetype.go +++ b/cmd/godex/writetype.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build go1.5 - // This file implements writing of types. The functionality is lifted // directly from go/types, but now contains various modifications for // nicer output.