func (p *printer) controlClause(isForStmt bool, init ast.Stmt, expr ast.Expr, post ast.Stmt) {
+ p.print(blank);
+ needsBlank := false;
if init == nil && post == nil {
// no semicolons required
if expr != nil {
- p.print(blank);
p.expr(expr);
+ needsBlank = true;
}
} else {
// all semicolons required
// (they are not separators, print them explicitly)
- p.print(blank);
if init != nil {
p.stmt(init);
}
p.print(token.SEMICOLON, blank);
if expr != nil {
p.expr(expr);
+ needsBlank = true;
}
if isForStmt {
p.print(token.SEMICOLON, blank);
+ needsBlank = false;
if post != nil {
p.stmt(post);
+ needsBlank = true;
}
}
}
+ if needsBlank {
+ p.print(blank);
+ }
}
case *ast.IfStmt:
p.print(token.IF);
p.controlClause(false, s.Init, s.Cond, nil);
- p.print(blank);
p.block(s.Body);
optSemi = true;
if s.Else != nil {
case *ast.SwitchStmt:
p.print(token.SWITCH);
p.controlClause(false, s.Init, s.Tag, nil);
- p.print(blank);
p.switchBlock(s.Body);
optSemi = true;
case *ast.ForStmt:
p.print(token.FOR);
p.controlClause(true, s.Init, s.Cond, s.Post);
- p.print(blank);
p.block(s.Body);
optSemi = true;
entry{ "linebreaks.go", "linebreaks.golden", false },
entry{ "expressions.go", "expressions.golden", false },
entry{ "declarations.go", "declarations.golden", false },
+ entry{ "statements.go", "statements.golden", false },
}
--- /dev/null
+// 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 statements
+
+var expr bool;
+
+func _() {
+ if {}
+ if expr{}
+ if _:=expr;{}
+ if _:=expr; expr {}
+}
+
+
+func _() {
+ switch {}
+ switch expr {}
+ switch _ := expr; {}
+ switch _ := expr; expr {}
+}
+
+
+func _() {
+ for{}
+ for expr {}
+ for;;{} // TODO ok to lose the semicolons here?
+ for _ :=expr;; {}
+ for; expr;{} // TODO ok to lose the semicolons here?
+ for; ; expr = false {}
+ for _ :=expr; expr; {}
+ for _ := expr;; expr=false {}
+ for;expr;expr =false {}
+ for _ := expr;expr;expr = false {}
+ for _ := range []int{} {}
+}
--- /dev/null
+// 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 statements
+
+var expr bool
+
+func _() {
+ if {}
+ if expr {}
+ if _ := expr; {}
+ if _ := expr; expr {}
+}
+
+func _() {
+ switch {}
+ switch expr {}
+ switch _ := expr; {}
+ switch _ := expr; expr {}
+}
+
+func _() {
+ for {}
+ for expr {}
+ for {} // TODO ok to lose the semicolons here?
+ for _ := expr; ; {}
+ for expr {} // TODO ok to lose the semicolons here?
+ for ; ; expr = false {}
+ for _ := expr; expr; {}
+ for _ := expr; ; expr = false {}
+ for ; expr; expr = false {}
+ for _ := expr; expr; expr = false {}
+ for _ := range []int{} {}
+}