aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/gofmt/gofmt.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/gofmt/gofmt.go')
-rw-r--r--src/cmd/gofmt/gofmt.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go
index b82aa7e7a9..95f537d91e 100644
--- a/src/cmd/gofmt/gofmt.go
+++ b/src/cmd/gofmt/gofmt.go
@@ -26,13 +26,16 @@ import (
var (
// main operation modes
- list = flag.Bool("l", false, "list files whose formatting differs from gofmt's")
- write = flag.Bool("w", false, "write result to (source) file instead of stdout")
- rewriteRule = flag.String("r", "", "rewrite rule (e.g., 'a[b:len(a)] -> a[b:]')")
- simplifyAST = flag.Bool("s", false, "simplify code")
- doDiff = flag.Bool("d", false, "display diffs instead of rewriting files")
- allErrors = flag.Bool("e", false, "report all errors (not just the first 10 on different lines)")
- allowTypeParams = flag.Bool("G", false, "allow generic code")
+ list = flag.Bool("l", false, "list files whose formatting differs from gofmt's")
+ write = flag.Bool("w", false, "write result to (source) file instead of stdout")
+ rewriteRule = flag.String("r", "", "rewrite rule (e.g., 'a[b:len(a)] -> a[b:]')")
+ simplifyAST = flag.Bool("s", false, "simplify code")
+ doDiff = flag.Bool("d", false, "display diffs instead of rewriting files")
+ allErrors = flag.Bool("e", false, "report all errors (not just the first 10 on different lines)")
+
+ // allowTypeParams controls whether type parameters are allowed in the code
+ // being formatted. It is enabled for go1.18 in gofmt_go1.18.go.
+ allowTypeParams = false
// debugging
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to this file")
@@ -48,6 +51,10 @@ const (
//
// This value is defined in go/printer specifically for go/format and cmd/gofmt.
printerNormalizeNumbers = 1 << 30
+
+ // parseTypeParams tells go/parser to parse type parameters. Must be kept in
+ // sync with go/parser/interface.go.
+ parseTypeParams parser.Mode = 1 << 30
)
var (
@@ -72,8 +79,8 @@ func initParserMode() {
if *allErrors {
parserMode |= parser.AllErrors
}
- if *allowTypeParams {
- parserMode |= parser.ParseTypeParams
+ if allowTypeParams {
+ parserMode |= parseTypeParams
}
}