1
0
mirror of https://github.com/golang/go synced 2024-09-30 04:24:29 -06:00

go/types: report object path in trace mode

For debugging only; disabled (dead code) by default
unless internal constant trace flag is set to true.

For #8699.

Change-Id: Ib7b272c6ac8efacccbbbe24650ef500c5a9ddcf5
Reviewed-on: https://go-review.googlesource.com/115457
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2018-05-30 18:13:27 -07:00
parent 6dbaf0352a
commit e4259d67b9
3 changed files with 15 additions and 3 deletions

View File

@ -160,6 +160,18 @@ func (check *Checker) pop() Object {
return obj
}
// pathString returns a string of the form a->b-> ... ->g for an object path [a, b, ... g].
func (check *Checker) pathString() string {
var s string
for i, p := range check.objPath {
if i > 0 {
s += "->"
}
s += p.Name()
}
return s
}
// NewChecker returns a new Checker instance for a given package.
// Package files may be added incrementally via checker.Files.
func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker {

View File

@ -158,7 +158,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
}
if trace {
check.trace(obj.Pos(), "-- checking %s (path = %s)", obj, pathString(path))
check.trace(obj.Pos(), "-- checking %s (path = %s, objPath = %s)", obj, pathString(path), check.pathString())
check.indent++
defer func() {
check.indent--
@ -208,7 +208,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
// to the next. For instance, for "type p *p" the object path contains
// p followed by indir, indicating that there's an indirection *p.
// Indirections are used to break type cycles.
var indir = new(TypeName)
var indir = NewTypeName(token.NoPos, nil, "*", nil)
// typeCycle checks if the cycle starting with obj is valid and
// reports an error if it is not.

View File

@ -144,7 +144,7 @@ func (check *Checker) infoFromTypeLit(scope *Scope, iface *ast.InterfaceType, tn
}
if trace {
check.trace(iface.Pos(), "-- collect methods for %v (path = %s)", iface, pathString(path))
check.trace(iface.Pos(), "-- collect methods for %v (path = %s, objPath = %s)", iface, pathString(path), check.pathString())
check.indent++
defer func() {
check.indent--