func (it *PackagesIterator) SkipChildren() {
	fringe := it.fringeStack[len(it.fringeStack)-1]
	if fringe != nil && len(*fringe) != 0 {
		(*fringe) = nil
	}
}
SkipChildren will skip visiting the children of the current package.
package visit
import (
	"sort"
	"golang.org/x/tools/go/packages"
)
func Packages(pkgs []*packages.Package) *PackagesIterator {
	return &PackagesIterator{
		fringeStack: []*[]*packages.Package{&pkgs},
		seen:        make(map[*packages.Package]bool),
	}
}
type PackagesIterator struct {
	fringeStack []*[]*packages.Package
	stack       []*packages.Package
	cur         *packages.Package
	seen        map[*packages.Package]bool
}
func (it *PackagesIterator) Next() bool {
	for {
		if len(it.fringeStack) == 0 {
			return false
		}
		fringe := it.fringeStack[len(it.fringeStack)-1]
		if fringe != nil && len(*fringe) != 0 {
			it.cur = (*fringe)[0]
			(*fringe) = (*fringe)[1:]
			if !it.seen[it.cur] || it.cur == nil {
				it.seen[it.cur] = true
				it.visitCur()
				return true
			}
		} else {
			it.fringeStack = it.fringeStack[:len(it.fringeStack)-1]
		}
	}
}
func (it *PackagesIterator) visitCur() {
	if it.cur == nil {
		it.fringeStack = append(it.fringeStack, nil)
		return
	}
	paths := make([]string, 0, len(it.cur.Imports))
	for path := range it.cur.Imports {
		paths = append(paths, path)
	}
	curfringe := make([]*packages.Package, 0, len(it.cur.Imports)+1)
	sort.Strings(paths)
	for _, path := range paths {
		curfringe = append(curfringe, it.cur.Imports[path])
	}
	curfringe = append(curfringe, nil)
	it.fringeStack = append(it.fringeStack, &curfringe)
}
func (it *PackagesIterator) Pkg() *packages.Package {
	return it.cur
}
func (it *PackagesIterator) Path() []*packages.Package {
	return it.stack
}