Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(508)

Unified Diff: src/cmd/gofmt/gofmt.go

Issue 146520043: code review 146520043: go/format, cmd/gofmt: added missing comments, minor int... (Closed)
Patch Set: diff -r d5330a8278e5eb84a4ae6edb7e0518308d9b0dd7 https://code.google.com/p/go/ Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/go/format/format.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/cmd/gofmt/gofmt.go
===================================================================
--- a/src/cmd/gofmt/gofmt.go
+++ b/src/cmd/gofmt/gofmt.go
@@ -106,7 +106,7 @@
simplify(file)
}
- res, err := format(fileSet, file, sourceAdj, indentAdj, src)
+ res, err := format(fileSet, file, sourceAdj, indentAdj, src, printer.Config{Mode: printerMode, Tabwidth: tabWidth})
if err != nil {
return err
}
@@ -235,8 +235,16 @@
}
-// parse parses src, which was read from filename,
-// as a Go source file or statement list.
+// ----------------------------------------------------------------------------
+// Support functions
+//
+// The functions parse, format, and isSpace below are identical to the
+// respective functions in src/go/format/format.go - keep them in sync!
+//
+// TODO(gri) Factor out this functionality, eventually.
+
+// parse parses src, which was read from the named file,
+// as a Go source file, declaration, or statement list.
func parse(fset *token.FileSet, filename string, src []byte, fragmentOk bool) (
file *ast.File,
sourceAdj func(src []byte, indent int) []byte,
@@ -303,11 +311,21 @@
return
}
-func format(fset *token.FileSet, file *ast.File, sourceAdj func(src []byte, indent int) []byte, indentAdj int, src []byte) ([]byte, error) {
+// format formats the given package file originally obtained from src
+// and adjusts the result based on the original source via sourceAdj
+// and indentAdj.
+func format(
+ fset *token.FileSet,
+ file *ast.File,
+ sourceAdj func(src []byte, indent int) []byte,
+ indentAdj int,
+ src []byte,
+ cfg printer.Config,
+) ([]byte, error) {
if sourceAdj == nil {
// Complete source file.
var buf bytes.Buffer
- err := (&printer.Config{Mode: printerMode, Tabwidth: tabWidth}).Fprint(&buf, fset, file)
+ err := cfg.Fprint(&buf, fset, file)
if err != nil {
return nil, err
}
@@ -348,7 +366,6 @@
// Format the source.
// Write it without any leading and trailing space.
- cfg := &printer.Config{Mode: printerMode, Tabwidth: tabWidth}
cfg.Indent = indent + indentAdj
var buf bytes.Buffer
err := cfg.Fprint(&buf, fset, file)
« no previous file with comments | « no previous file | src/go/format/format.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b