Commit 10242e80 authored by Robert Griesemer's avatar Robert Griesemer

gofmt'ed parts of go

R=rsc
http://go/go-review/1023001
parent 65063bc6
......@@ -37,8 +37,10 @@ const (
func (p *printer) linebreak(line, min, max int, ws whiteSpace, newSection bool) (printedBreak bool) {
n := line - p.pos.Line;
switch {
case n < min: n = min;
case n > max: n = max;
case n < min:
n = min;
case n > max:
n = max;
}
if n > 0 {
p.print(ws);
......@@ -118,9 +120,10 @@ func (p *printer) stringList(list []*ast.BasicLit, multiLine *bool) {
}
type exprListMode uint;
type exprListMode uint
const (
blankStart exprListMode = 1 << iota; // print a blank before the list
blankStart exprListMode = 1<<iota; // print a blank before the list
commaSep; // elements are separated by commas
commaTerm; // elements are terminated by comma
noIndent; // no extra indentation in multi-line lists
......@@ -150,7 +153,7 @@ func (p *printer) exprList(prev token.Position, list []ast.Expr, mode exprListMo
// all list entries on a single line
for i, x := range list {
if i > 0 {
if mode & commaSep != 0 {
if mode&commaSep != 0 {
p.print(token.COMMA);
}
p.print(blank);
......@@ -179,7 +182,7 @@ func (p *printer) exprList(prev token.Position, list []ast.Expr, mode exprListMo
prev := line;
line = x.Pos().Line;
if i > 0 {
if mode & commaSep != 0 {
if mode&commaSep != 0 {
p.print(token.COMMA);
}
if prev < line {
......@@ -353,7 +356,7 @@ func needsBlanks(expr ast.Expr) bool {
return false;
case *ast.IndexExpr:
// index expressions don't need blanks if the indexed expressions are simple
return needsBlanks(x.X)
return needsBlanks(x.X);
case *ast.CallExpr:
// call expressions need blanks if they have more than one
// argument or if the function expression needs blanks
......@@ -539,7 +542,7 @@ func (p *printer) expr1(expr ast.Expr, prec1 int, multiLine *bool) (optSemi bool
p.print(blank);
}
p.print(x.Lbrace, token.LBRACE);
p.exprList(x.Lbrace, x.Elts, commaSep|commaTerm, multiLine);
p.exprList(x.Lbrace, x.Elts, commaSep | commaTerm, multiLine);
p.print(x.Rbrace, token.RBRACE);
case *ast.Ellipsis:
......@@ -862,7 +865,8 @@ func (p *printer) stmt(stmt ast.Stmt, multiLine *bool) (optSemi bool) {
// ----------------------------------------------------------------------------
// Declarations
type declContext uint;
type declContext uint
const (
atTop declContext = iota;
inGroup;
......
......@@ -57,7 +57,7 @@ var noPos token.Position
// Use ignoreMultiLine if the multiLine information is not important.
var ignoreMultiLine = new(bool);
var ignoreMultiLine = new(bool)
type printer struct {
......@@ -126,7 +126,7 @@ func (p *printer) write(data []byte) {
p.write0(data[i0 : i+1]);
// update p.pos
p.pos.Offset += i+1 - i0;
p.pos.Offset += i+1-i0;
p.pos.Line++;
p.pos.Column = 1;
......@@ -151,21 +151,26 @@ func (p *printer) write(data []byte) {
case '"', '\'', '&', '<', '>':
if p.Mode & GenHTML != 0 {
// write segment ending in b
p.write0(data[i0 : i]);
p.write0(data[i0:i]);
// write HTML-escaped b
var esc []byte;
switch b {
case '"': esc = esc_quot;
case '\'': esc = esc_apos;
case '&': esc = esc_amp;
case '<': esc = esc_lt;
case '>': esc = esc_gt;
case '"':
esc = esc_quot;
case '\'':
esc = esc_apos;
case '&':
esc = esc_amp;
case '<':
esc = esc_lt;
case '>':
esc = esc_gt;
}
p.write0(esc);
// update p.pos
d := i+1 - i0;
d := i+1-i0;
p.pos.Offset += d;
p.pos.Column += d;
......@@ -179,10 +184,10 @@ func (p *printer) write(data []byte) {
}
// write remaining segment
p.write0(data[i0 : len(data)]);
p.write0(data[i0:len(data)]);
// update p.pos
d := len(data) - i0;
d := len(data)-i0;
p.pos.Offset += d;
p.pos.Column += d;
}
......@@ -193,7 +198,7 @@ func (p *printer) writeNewlines(n int) {
if n > maxNewlines {
n = maxNewlines;
}
p.write(newlines[0 : n]);
p.write(newlines[0:n]);
}
}
......@@ -393,7 +398,7 @@ func commonPrefix(a, b []byte) []byte {
for i < len(a) && i < len(b) && a[i] == b[i] && (a[i] <= ' ' || a[i] == '*') {
i++;
}
return a[0 : i];
return a[0:i];
}
......@@ -447,7 +452,7 @@ func stripCommonPrefix(lines [][]byte) {
// for the opening /*, assume up to 3 blanks or a tab. This
// whitespace may be found as suffix in the common prefix.
first := lines[0];
if isBlank(first[2 : len(first)]) {
if isBlank(first[2:len(first)]) {
// no comment text on the first line:
// reduce prefix by up to 3 blanks or a tab
// if present - this keeps comment text indented
......@@ -480,7 +485,7 @@ func stripCommonPrefix(lines [][]byte) {
// Shorten the computed common prefix by the length of
// suffix, if it is found as suffix of the prefix.
if bytes.HasSuffix(prefix, suffix) {
prefix = prefix[0 : len(prefix) - len(suffix)];
prefix = prefix[0 : len(prefix)-len(suffix)];
}
}
}
......@@ -508,7 +513,7 @@ func stripCommonPrefix(lines [][]byte) {
// Remove the common prefix from all but the first and empty lines.
for i, line := range lines {
if i > 0 && len(line) != 0 {
lines[i] = line[len(prefix) : len(line)];
lines[i] = line[len(prefix):len(line)];
}
}
}
......@@ -721,7 +726,7 @@ func (p *printer) print(args ...) {
// (note that valid Go programs cannot contain esc ('\xff')
// bytes since they do not appear in legal UTF-8 sequences)
// TODO(gri): this this more efficiently.
data = strings.Bytes("\xff" + string(data) + "\xff");
data = strings.Bytes("\xff"+string(data)+"\xff");
case token.Token:
if p.Styler != nil {
data, tag = p.Styler.Token(x);
......@@ -865,7 +870,7 @@ func (p *trimmer) Write(data []byte) (n int, err os.Error) {
// General printing is controlled with these Config.Mode flags.
const (
GenHTML uint = 1 << iota; // generate HTML
GenHTML uint = 1<<iota; // generate HTML
RawFormat; // do not use a tabwriter; if set, UseSpaces is ignored
UseSpaces; // use spaces instead of tabs for indentation and alignment
)
......
......@@ -21,7 +21,7 @@ const (
)
var update = flag.Bool("update", false, "update golden files");
var update = flag.Bool("update", false, "update golden files")
func lineString(text []byte, i int) string {
......@@ -29,11 +29,12 @@ func lineString(text []byte, i int) string {
for i < len(text) && text[i] != '\n' {
i++;
}
return string(text[i0 : i]);
return string(text[i0:i]);
}
type checkMode uint;
type checkMode uint
const (
export checkMode = 1<<iota;
rawFormat;
......@@ -56,7 +57,7 @@ func check(t *testing.T, source, golden string, mode checkMode) {
// determine printer configuration
cfg := Config{Tabwidth: tabwidth};
if mode&rawFormat != 0 {
if mode & rawFormat != 0 {
cfg.Mode |= RawFormat;
}
......@@ -111,14 +112,14 @@ type entry struct {
// Use gotest -update to create/update the respective golden files.
var data = []entry{
entry{ "empty.input", "empty.golden", 0 },
entry{ "comments.input", "comments.golden", 0 },
entry{ "comments.input", "comments.x", export },
entry{ "linebreaks.input", "linebreaks.golden", 0 },
entry{ "expressions.input", "expressions.golden", 0 },
entry{ "expressions.input", "expressions.raw", rawFormat },
entry{ "declarations.input", "declarations.golden", 0 },
entry{ "statements.input", "statements.golden", 0 },
entry{"empty.input", "empty.golden", 0},
entry{"comments.input", "comments.golden", 0},
entry{"comments.input", "comments.x", export},
entry{"linebreaks.input", "linebreaks.golden", 0},
entry{"expressions.input", "expressions.golden", 0},
entry{"expressions.input", "expressions.raw", rawFormat},
entry{"declarations.input", "declarations.golden", 0},
entry{"statements.input", "statements.golden", 0},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment