Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
48f598a3
Commit
48f598a3
authored
Jul 14, 2011
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/printer: simplify internal state
No formatting changes. R=rsc CC=golang-dev
https://golang.org/cl/4735042
parent
38a53c7e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
25 deletions
+5
-25
nodes.go
src/pkg/go/printer/nodes.go
+0
-10
printer.go
src/pkg/go/printer/printer.go
+5
-15
No files found.
src/pkg/go/printer/nodes.go
View file @
48f598a3
...
...
@@ -346,11 +346,6 @@ func (p *printer) setLineComment(text string) {
}
func
(
p
*
printer
)
fieldList
(
fields
*
ast
.
FieldList
,
isStruct
,
isIncomplete
bool
)
{
p
.
nesting
++
defer
func
()
{
p
.
nesting
--
}()
lbrace
:=
fields
.
Opening
list
:=
fields
.
List
rbrace
:=
fields
.
Closing
...
...
@@ -1413,11 +1408,6 @@ func (p *printer) funcBody(b *ast.BlockStmt, headerSize int, isLit bool, multiLi
return
}
p
.
nesting
++
defer
func
()
{
p
.
nesting
--
}()
if
p
.
isOneLineFunc
(
b
,
headerSize
)
{
sep
:=
vtab
if
isLit
{
...
...
src/pkg/go/printer/printer.go
View file @
48f598a3
...
...
@@ -63,7 +63,6 @@ type printer struct {
errors
chan
os
.
Error
// Current state
nesting
int
// nesting level (0: top-level (package scope), >0: functions/decls.)
written
int
// number of bytes written
indent
int
// current indentation
mode
pmode
// current printer mode
...
...
@@ -123,18 +122,14 @@ func (p *printer) escape(s string) string {
}
// nlines returns the adjusted number of linebreaks given the desired number
// of breaks n such that min <= result <= max where max depends on the current
// nesting level.
// of breaks n such that min <= result <= max.
//
func
(
p
*
printer
)
nlines
(
n
,
min
int
)
int
{
if
n
<
min
{
const
max
=
2
// max. number of newlines
switch
{
case
n
<
min
:
return
min
}
max
:=
2
// max. number of newlines at the top level (p.nesting == 0)
if
p
.
nesting
>
0
{
max
=
2
// max. number of newlines everywhere else
}
if
n
>
max
{
case
n
>
max
:
return
max
}
return
n
...
...
@@ -961,11 +956,9 @@ func (cfg *Config) fprint(output io.Writer, fset *token.FileSet, node interface{
go
func
()
{
switch
n
:=
node
.
(
type
)
{
case
ast
.
Expr
:
p
.
nesting
=
1
p
.
useNodeComments
=
true
p
.
expr
(
n
,
ignoreMultiLine
)
case
ast
.
Stmt
:
p
.
nesting
=
1
p
.
useNodeComments
=
true
// A labeled statement will un-indent to position the
// label. Set indent to 1 so we don't get indent "underflow".
...
...
@@ -974,15 +967,12 @@ func (cfg *Config) fprint(output io.Writer, fset *token.FileSet, node interface{
}
p
.
stmt
(
n
,
false
,
ignoreMultiLine
)
case
ast
.
Decl
:
p
.
nesting
=
1
p
.
useNodeComments
=
true
p
.
decl
(
n
,
ignoreMultiLine
)
case
ast
.
Spec
:
p
.
nesting
=
1
p
.
useNodeComments
=
true
p
.
spec
(
n
,
1
,
false
,
ignoreMultiLine
)
case
*
ast
.
File
:
p
.
nesting
=
0
p
.
comments
=
n
.
Comments
p
.
useNodeComments
=
n
.
Comments
==
nil
p
.
file
(
n
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment