mirror of
https://github.com/golang/go
synced 2024-11-19 02:24:41 -07:00
1f6463f823
import ( "vector" -> "container/vector" "ast" -> "go/ast" "sha1" -> "hash/sha1" etc. ) and update Makefiles. Because I did the conversion semi-automatically, I sorted all the import blocks as a post-processing. Some files have therefore changed that didn't strictly need to. Rename local packages to lower case. The upper/lower distinction doesn't work on OS X and complicates the "single-package directories with the same package name as directory name" heuristic used by gobuild and godoc to create the correlation between source and binary locations. Now that we have a plan to avoid globally unique names, the upper/lower is unnecessary. The renamings will cause trouble for a few users, but so will the change in import paths. This way, the two maintenance fixes are rolled into one inconvenience. R=r OCL=27573 CL=27575
87 lines
1.8 KiB
Go
87 lines
1.8 KiB
Go
// Copyright 2009 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.
|
|
|
|
package main
|
|
|
|
import (
|
|
"astprinter";
|
|
"compilation";
|
|
"flag";
|
|
"go/ast";
|
|
"os";
|
|
"platform";
|
|
"tabwriter";
|
|
)
|
|
|
|
|
|
var (
|
|
flags Compilation.Flags;
|
|
silent = flag.Bool("s", false, "silent mode: no pretty print output");
|
|
|
|
// layout control
|
|
html = flag.Bool("html", false, "generate html");
|
|
tabwidth = flag.Int("pretty_tabwidth", 4, "tab width");
|
|
usetabs = flag.Bool("pretty_usetabs", false, "align with tabs instead of blanks");
|
|
)
|
|
|
|
|
|
func init() {
|
|
flag.BoolVar(&flags.Verbose, "v", false, "verbose mode: trace parsing");
|
|
flag.BoolVar(&flags.Deps, "d", false, "print dependency information only");
|
|
flag.BoolVar(&flags.Columns, "columns", Platform.USER == "gri", "print column info in error messages");
|
|
}
|
|
|
|
|
|
func usage() {
|
|
print("usage: pretty { flags } { files }\n");
|
|
flag.PrintDefaults();
|
|
sys.Exit(0);
|
|
}
|
|
|
|
|
|
func print(prog *ast.Program) {
|
|
// initialize tabwriter for nicely aligned output
|
|
padchar := byte(' ');
|
|
if *usetabs {
|
|
padchar = '\t';
|
|
}
|
|
writer := tabwriter.NewWriter(os.Stdout, *tabwidth, 1, padchar, tabwriter.FilterHTML);
|
|
|
|
// initialize printer
|
|
var printer astPrinter.Printer;
|
|
printer.Init(writer, nil, prog.Comments, *html);
|
|
|
|
printer.DoProgram(prog);
|
|
|
|
// flush any pending output
|
|
writer.Flush();
|
|
}
|
|
|
|
|
|
func main() {
|
|
flag.Parse();
|
|
|
|
if flag.NFlag() == 0 && flag.NArg() == 0 {
|
|
usage();
|
|
}
|
|
|
|
// process files
|
|
for i := 0; i < flag.NArg(); i++ {
|
|
src_file := flag.Arg(i);
|
|
|
|
if flags.Deps {
|
|
Compilation.ComputeDeps(src_file, &flags);
|
|
|
|
} else {
|
|
prog, errors := Compilation.Compile(src_file, &flags);
|
|
if errors == nil || len(errors) > 0 {
|
|
sys.Exit(1);
|
|
}
|
|
if !*silent {
|
|
print(prog);
|
|
}
|
|
}
|
|
}
|
|
}
|