mirror of
https://github.com/golang/go
synced 2024-11-24 05:20:04 -07:00
go/types: change local gotype command to use source importer
Also: Remove -gccgo flag (not supported after 1.5), minor cleanups. Change-Id: I625241b07b277ac50ff836e2230b7b285887d35e Reviewed-on: https://go-review.googlesource.com/37654 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
13c35a1b20
commit
4be4da6331
@ -21,6 +21,10 @@ package.
|
|||||||
Otherwise, each path must be the filename of Go file belonging to
|
Otherwise, each path must be the filename of Go file belonging to
|
||||||
the same package.
|
the same package.
|
||||||
|
|
||||||
|
Imports are processed by importing directly from the source of
|
||||||
|
imported packages (default), or by importing from compiled and
|
||||||
|
installed packages (by setting -c to the respective compiler).
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
gotype [flags] [path...]
|
gotype [flags] [path...]
|
||||||
|
|
||||||
@ -32,11 +36,7 @@ The flags are:
|
|||||||
-v
|
-v
|
||||||
verbose mode
|
verbose mode
|
||||||
-c
|
-c
|
||||||
compiler used to compile packages (gc or gccgo); default: gc
|
compiler used for installed packages (gc, gccgo, or source); default: source
|
||||||
(gotype based on Go1.5 and up only)
|
|
||||||
-gccgo
|
|
||||||
use gccimporter instead of gcimporter
|
|
||||||
(gotype based on Go1.4 and before only)
|
|
||||||
|
|
||||||
Debugging flags:
|
Debugging flags:
|
||||||
-seq
|
-seq
|
||||||
@ -90,7 +90,7 @@ var (
|
|||||||
allFiles = flag.Bool("a", false, "use all (incl. _test.go) files when processing a directory")
|
allFiles = flag.Bool("a", false, "use all (incl. _test.go) files when processing a directory")
|
||||||
allErrors = flag.Bool("e", false, "report all errors (not just the first 10)")
|
allErrors = flag.Bool("e", false, "report all errors (not just the first 10)")
|
||||||
verbose = flag.Bool("v", false, "verbose mode")
|
verbose = flag.Bool("v", false, "verbose mode")
|
||||||
gccgo = flag.Bool("gccgo", false, "use gccgoimporter instead of gcimporter")
|
compiler = flag.String("c", "source", "compiler used for installed packages (gc, gccgo, or source)")
|
||||||
|
|
||||||
// debugging support
|
// debugging support
|
||||||
sequential = flag.Bool("seq", false, "parse sequentially, rather than in parallel")
|
sequential = flag.Bool("seq", false, "parse sequentially, rather than in parallel")
|
||||||
@ -103,7 +103,6 @@ var (
|
|||||||
fset = token.NewFileSet()
|
fset = token.NewFileSet()
|
||||||
errorCount = 0
|
errorCount = 0
|
||||||
parserMode parser.Mode
|
parserMode parser.Mode
|
||||||
sizes types.Sizes
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func initParserMode() {
|
func initParserMode() {
|
||||||
@ -118,18 +117,6 @@ func initParserMode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initSizes() {
|
|
||||||
wordSize := 8
|
|
||||||
maxAlign := 8
|
|
||||||
switch build.Default.GOARCH {
|
|
||||||
case "386", "arm":
|
|
||||||
wordSize = 4
|
|
||||||
maxAlign = 4
|
|
||||||
// add more cases as needed
|
|
||||||
}
|
|
||||||
sizes = &types.StdSizes{WordSize: int64(wordSize), MaxAlign: int64(maxAlign)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
fmt.Fprintln(os.Stderr, "usage: gotype [flags] [path ...]")
|
fmt.Fprintln(os.Stderr, "usage: gotype [flags] [path ...]")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
@ -248,11 +235,9 @@ func getPkgFiles(args []string) ([]*ast.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkPkgFiles(files []*ast.File) {
|
func checkPkgFiles(files []*ast.File) {
|
||||||
compiler := "gc"
|
|
||||||
if *gccgo {
|
|
||||||
compiler = "gccgo"
|
|
||||||
}
|
|
||||||
type bailout struct{}
|
type bailout struct{}
|
||||||
|
|
||||||
|
// if checkPkgFiles is called multiple times, set up conf only once
|
||||||
conf := types.Config{
|
conf := types.Config{
|
||||||
FakeImportC: true,
|
FakeImportC: true,
|
||||||
Error: func(err error) {
|
Error: func(err error) {
|
||||||
@ -261,8 +246,8 @@ func checkPkgFiles(files []*ast.File) {
|
|||||||
}
|
}
|
||||||
report(err)
|
report(err)
|
||||||
},
|
},
|
||||||
Importer: importer.For(compiler, nil),
|
Importer: importer.For(*compiler, nil),
|
||||||
Sizes: sizes,
|
Sizes: types.SizesFor(build.Default.GOARCH),
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -301,7 +286,6 @@ func main() {
|
|||||||
*sequential = true
|
*sequential = true
|
||||||
}
|
}
|
||||||
initParserMode()
|
initParserMode()
|
||||||
initSizes()
|
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user