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

Delta Between Two Patch Sets: src/pkg/go/printer/printer.go

Issue 6849066: code review 6849066: go/printer: leave indentation alone when printing nodes... (Closed)
Left Patch Set: Created 11 years, 4 months ago
Right Patch Set: diff -r 821585f8baba https://code.google.com/p/go Created 11 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Package printer implements printing of AST nodes. 5 // Package printer implements printing of AST nodes.
6 package printer 6 package printer
7 7
8 import ( 8 import (
9 "fmt" 9 "fmt"
10 "go/ast" 10 "go/ast"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if pos.IsValid() { 218 if pos.IsValid() {
219 // update p.pos (if pos is invalid, continue with existing p.pos ) 219 // update p.pos (if pos is invalid, continue with existing p.pos )
220 // Note: Must do this after handling line beginnings because 220 // Note: Must do this after handling line beginnings because
221 // atLineBegin updates p.pos if there's indentation, but p.pos 221 // atLineBegin updates p.pos if there's indentation, but p.pos
222 // is the position of s. 222 // is the position of s.
223 p.pos = pos 223 p.pos = pos
224 // reset state if the file changed 224 // reset state if the file changed
225 // (used when printing merged ASTs of different files 225 // (used when printing merged ASTs of different files
226 // e.g., the result of ast.MergePackageFiles) 226 // e.g., the result of ast.MergePackageFiles)
227 if p.last.IsValid() && p.last.Filename != pos.Filename { 227 if p.last.IsValid() && p.last.Filename != pos.Filename {
228 » » » p.indent = 0 228 » » » // Note: Do not set p.indent to 0 - this seems to be a b ad heuristic.
229 » » » // ASTs may be created by various tools and built from nodes of
230 » » » // different files. An incorrectly constructed AST will likely
231 » » » // not print at all, but a (structurally) correct AST with bad
232 » » » // position information should still print structu rally correct.
233 » » » // If p.indent is reset, indentation may be off, a nd likely lead
234 » » » // to indentation underflow (to detect set: debug = true).
235 » » » // See also issue 4300 (11/16/2012).
229 p.mode = 0 236 p.mode = 0
230 p.wsbuf = p.wsbuf[0:0] 237 p.wsbuf = p.wsbuf[0:0]
231 } 238 }
232 } 239 }
233 240
234 if isLit { 241 if isLit {
235 // Protect s such that is passes through the tabwriter 242 // Protect s such that is passes through the tabwriter
236 // unchanged. Note that valid Go programs cannot contain 243 // unchanged. Note that valid Go programs cannot contain
237 // tabwriter.Escape bytes since they do not appear in legal 244 // tabwriter.Escape bytes since they do not appear in legal
238 // UTF-8 sequences. 245 // UTF-8 sequences.
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 func (cfg *Config) Fprint(output io.Writer, fset *token.FileSet, node interface{ }) error { 1256 func (cfg *Config) Fprint(output io.Writer, fset *token.FileSet, node interface{ }) error {
1250 return cfg.fprint(output, fset, node, make(map[ast.Node]int)) 1257 return cfg.fprint(output, fset, node, make(map[ast.Node]int))
1251 } 1258 }
1252 1259
1253 // Fprint "pretty-prints" an AST node to output. 1260 // Fprint "pretty-prints" an AST node to output.
1254 // It calls Config.Fprint with default settings. 1261 // It calls Config.Fprint with default settings.
1255 // 1262 //
1256 func Fprint(output io.Writer, fset *token.FileSet, node interface{}) error { 1263 func Fprint(output io.Writer, fset *token.FileSet, node interface{}) error {
1257 return (&Config{Tabwidth: 8}).Fprint(output, fset, node) 1264 return (&Config{Tabwidth: 8}).Fprint(output, fset, node)
1258 } 1265 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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