1
// Copyright 2013 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
17
func isGoFile(dir os.FileInfo) bool {
18
return !dir.IsDir() &&
19
!strings.HasPrefix(dir.Name(), ".") && // ignore .files
20
path.Ext(dir.Name()) == ".go"
23
func isPkgFile(dir os.FileInfo) bool {
24
return isGoFile(dir) &&
25
!strings.HasSuffix(dir.Name(), "_test.go") // ignore test files
28
func pkgName(filename string) string {
29
file, err := parser.ParseFile(token.NewFileSet(), filename, nil, parser.PackageClauseOnly)
30
if err != nil || file == nil {
36
func parseDir(dirpath string) map[string]*ast.Package {
37
// the package name is the directory name within its parent.
38
// (use dirname instead of path because dirname is clean; it
39
// has no trailing '/')
40
_, pkgname := path.Split(dirpath)
42
// filter function to select the desired .go files
43
filter := func(d os.FileInfo) bool {
45
// Some directories contain main packages: Only accept
46
// files that belong to the expected package so that
47
// parser.ParsePackage doesn't return "multiple packages
49
// Additionally, accept the special package name
50
// fakePkgName if we are looking at cmd documentation.
51
name := pkgName(dirpath + "/" + d.Name())
52
return name == pkgname
58
pkgs, err := parser.ParseDir(token.NewFileSet(), dirpath, filter, parser.ParseComments)
60
println("parse", dirpath, err.Error())
61
panic("go ParseDir fail: " + err.Error())
66
func stressParseGo() {
67
pkgroot := runtime.GOROOT() + "/src/pkg/"
69
m := make(map[string]map[string]*ast.Package)
70
for _, pkg := range packages {
71
m[pkg] = parseDir(pkgroot + pkg)
72
Println("parsed go package", pkg)
77
// find . -type d -not -path "./exp" -not -path "./exp/*" -printf "\t\"%p\",\n" | sort | sed "s/\.\///" | grep -v testdata
78
var packages = []string{
116
"database/sql/driver",
176
"net/http/cookiejar",
214
"text/template/parse",