Commit 2ce57ec1 authored by Robert Griesemer's avatar Robert Griesemer

gofmt-ify src/pkg/go (excluding printer directory due to pending CL,

and parser.go and scanner_test.go which have minor formatting issues)

R=rsc
http://go/go-review/1016042
parent 26c3f6c1
...@@ -331,29 +331,51 @@ func (x *KeyValueExpr) Pos() token.Position { ...@@ -331,29 +331,51 @@ func (x *KeyValueExpr) Pos() token.Position {
// exprNode() ensures that only expression/type nodes can be // exprNode() ensures that only expression/type nodes can be
// assigned to an ExprNode. // assigned to an ExprNode.
func (x *BadExpr) exprNode() {} func (x *BadExpr) exprNode() {
func (x *Ident) exprNode() {} }
func (x *Ellipsis) exprNode() {} func (x *Ident) exprNode() {
func (x *BasicLit) exprNode() {} }
func (x *StringList) exprNode() {} func (x *Ellipsis) exprNode() {
func (x *FuncLit) exprNode() {} }
func (x *CompositeLit) exprNode() {} func (x *BasicLit) exprNode() {
func (x *ParenExpr) exprNode() {} }
func (x *SelectorExpr) exprNode() {} func (x *StringList) exprNode() {
func (x *IndexExpr) exprNode() {} }
func (x *TypeAssertExpr) exprNode() {} func (x *FuncLit) exprNode() {
func (x *CallExpr) exprNode() {} }
func (x *StarExpr) exprNode() {} func (x *CompositeLit) exprNode() {
func (x *UnaryExpr) exprNode() {} }
func (x *BinaryExpr) exprNode() {} func (x *ParenExpr) exprNode() {
func (x *KeyValueExpr) exprNode() {} }
func (x *SelectorExpr) exprNode() {
func (x *ArrayType) exprNode() {} }
func (x *StructType) exprNode() {} func (x *IndexExpr) exprNode() {
func (x *FuncType) exprNode() {} }
func (x *InterfaceType) exprNode() {} func (x *TypeAssertExpr) exprNode() {
func (x *MapType) exprNode() {} }
func (x *ChanType) exprNode() {} func (x *CallExpr) exprNode() {
}
func (x *StarExpr) exprNode() {
}
func (x *UnaryExpr) exprNode() {
}
func (x *BinaryExpr) exprNode() {
}
func (x *KeyValueExpr) exprNode() {
}
func (x *ArrayType) exprNode() {
}
func (x *StructType) exprNode() {
}
func (x *FuncType) exprNode() {
}
func (x *InterfaceType) exprNode() {
}
func (x *MapType) exprNode() {
}
func (x *ChanType) exprNode() {
}
// IsExported returns whether name is an exported Go symbol // IsExported returns whether name is an exported Go symbol
...@@ -564,27 +586,48 @@ func (s *AssignStmt) Pos() token.Position { ...@@ -564,27 +586,48 @@ func (s *AssignStmt) Pos() token.Position {
// stmtNode() ensures that only statement nodes can be // stmtNode() ensures that only statement nodes can be
// assigned to a StmtNode. // assigned to a StmtNode.
// //
func (s *BadStmt) stmtNode() {} func (s *BadStmt) stmtNode() {
func (s *DeclStmt) stmtNode() {} }
func (s *EmptyStmt) stmtNode() {} func (s *DeclStmt) stmtNode() {
func (s *LabeledStmt) stmtNode() {} }
func (s *ExprStmt) stmtNode() {} func (s *EmptyStmt) stmtNode() {
func (s *IncDecStmt) stmtNode() {} }
func (s *AssignStmt) stmtNode() {} func (s *LabeledStmt) stmtNode() {
func (s *GoStmt) stmtNode() {} }
func (s *DeferStmt) stmtNode() {} func (s *ExprStmt) stmtNode() {
func (s *ReturnStmt) stmtNode() {} }
func (s *BranchStmt) stmtNode() {} func (s *IncDecStmt) stmtNode() {
func (s *BlockStmt) stmtNode() {} }
func (s *IfStmt) stmtNode() {} func (s *AssignStmt) stmtNode() {
func (s *CaseClause) stmtNode() {} }
func (s *SwitchStmt) stmtNode() {} func (s *GoStmt) stmtNode() {
func (s *TypeCaseClause) stmtNode() {} }
func (s *TypeSwitchStmt) stmtNode() {} func (s *DeferStmt) stmtNode() {
func (s *CommClause) stmtNode() {} }
func (s *SelectStmt) stmtNode() {} func (s *ReturnStmt) stmtNode() {
func (s *ForStmt) stmtNode() {} }
func (s *RangeStmt) stmtNode() {} func (s *BranchStmt) stmtNode() {
}
func (s *BlockStmt) stmtNode() {
}
func (s *IfStmt) stmtNode() {
}
func (s *CaseClause) stmtNode() {
}
func (s *SwitchStmt) stmtNode() {
}
func (s *TypeCaseClause) stmtNode() {
}
func (s *TypeSwitchStmt) stmtNode() {
}
func (s *CommClause) stmtNode() {
}
func (s *SelectStmt) stmtNode() {
}
func (s *ForStmt) stmtNode() {
}
func (s *RangeStmt) stmtNode() {
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -648,9 +691,12 @@ func (s *TypeSpec) Pos() token.Position { ...@@ -648,9 +691,12 @@ func (s *TypeSpec) Pos() token.Position {
// specNode() ensures that only spec nodes can be // specNode() ensures that only spec nodes can be
// assigned to a Spec. // assigned to a Spec.
// //
func (s *ImportSpec) specNode() {} func (s *ImportSpec) specNode() {
func (s *ValueSpec) specNode() {} }
func (s *TypeSpec) specNode() {} func (s *ValueSpec) specNode() {
}
func (s *TypeSpec) specNode() {
}
// A declaration is represented by one of the following declaration nodes. // A declaration is represented by one of the following declaration nodes.
...@@ -704,9 +750,12 @@ func (d *FuncDecl) Pos() token.Position { ...@@ -704,9 +750,12 @@ func (d *FuncDecl) Pos() token.Position {
// declNode() ensures that only declaration nodes can be // declNode() ensures that only declaration nodes can be
// assigned to a DeclNode. // assigned to a DeclNode.
// //
func (d *BadDecl) declNode() {} func (d *BadDecl) declNode() {
func (d *GenDecl) declNode() {} }
func (d *FuncDecl) declNode() {} func (d *GenDecl) declNode() {
}
func (d *FuncDecl) declNode() {
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
......
...@@ -12,7 +12,7 @@ package ast ...@@ -12,7 +12,7 @@ package ast
// //
type Scope struct { type Scope struct {
Outer *Scope; Outer *Scope;
Names map[string]*Ident Names map[string]*Ident;
} }
......
...@@ -31,8 +31,8 @@ func CommentText(comment *ast.CommentGroup) string { ...@@ -31,8 +31,8 @@ func CommentText(comment *ast.CommentGroup) string {
// Remove comment markers. // Remove comment markers.
// The parser has given us exactly the comment text. // The parser has given us exactly the comment text.
switch n := len(c); { switch n := len(c); {
case n >= 4 && c[0:2] == "/*" && c[n-2:n] == "*/": case n >= 4 && c[0:2] == "/*" && c[n-2 : n] == "*/":
c = c[2:n-2]; c = c[2 : n-2];
case n >= 2 && c[0:2] == "//": case n >= 2 && c[0:2] == "//":
c = c[2:n]; c = c[2:n];
// Remove leading space after //, if there is one. // Remove leading space after //, if there is one.
...@@ -51,7 +51,7 @@ func CommentText(comment *ast.CommentGroup) string { ...@@ -51,7 +51,7 @@ func CommentText(comment *ast.CommentGroup) string {
for m > 0 && (l[m-1] == ' ' || l[m-1] == '\n' || l[m-1] == '\t' || l[m-1] == '\r') { for m > 0 && (l[m-1] == ' ' || l[m-1] == '\n' || l[m-1] == '\t' || l[m-1] == '\r') {
m--; m--;
} }
l = l[0 : m]; l = l[0:m];
// Add to list. // Add to list.
n := len(lines); n := len(lines);
...@@ -76,7 +76,7 @@ func CommentText(comment *ast.CommentGroup) string { ...@@ -76,7 +76,7 @@ func CommentText(comment *ast.CommentGroup) string {
n++; n++;
} }
} }
lines = lines[0 : n]; lines = lines[0:n];
// Add final "" entry to get trailing newline from Join. // Add final "" entry to get trailing newline from Join.
// The original loop always leaves room for one more. // The original loop always leaves room for one more.
...@@ -115,7 +115,7 @@ func split(text []byte) [][]byte { ...@@ -115,7 +115,7 @@ func split(text []byte) [][]byte {
} }
} }
if last < len(text) { if last < len(text) {
out[n] = text[last : len(text)]; out[n] = text[last:len(text)];
} }
return out; return out;
...@@ -133,7 +133,7 @@ func commentEscape(w io.Writer, s []byte) { ...@@ -133,7 +133,7 @@ func commentEscape(w io.Writer, s []byte) {
last := 0; last := 0;
for i := 0; i < len(s)-1; i++ { for i := 0; i < len(s)-1; i++ {
if s[i] == s[i+1] && (s[i] == '`' || s[i] == '\'') { if s[i] == s[i+1] && (s[i] == '`' || s[i] == '\'') {
template.HtmlEscape(w, s[last : i]); template.HtmlEscape(w, s[last:i]);
last = i+2; last = i+2;
switch s[i] { switch s[i] {
case '`': case '`':
...@@ -144,7 +144,7 @@ func commentEscape(w io.Writer, s []byte) { ...@@ -144,7 +144,7 @@ func commentEscape(w io.Writer, s []byte) {
i++; // loop will add one more i++; // loop will add one more
} }
} }
template.HtmlEscape(w, s[last : len(s)]); template.HtmlEscape(w, s[last:len(s)]);
} }
...@@ -166,7 +166,7 @@ func indentLen(s []byte) int { ...@@ -166,7 +166,7 @@ func indentLen(s []byte) int {
func isBlank(s []byte) bool { func isBlank(s []byte) bool {
return len(s) == 0 || (len(s) == 1 && s[0] == '\n') return len(s) == 0 || (len(s) == 1 && s[0] == '\n');
} }
...@@ -175,7 +175,7 @@ func commonPrefix(a, b []byte) []byte { ...@@ -175,7 +175,7 @@ func commonPrefix(a, b []byte) []byte {
for i < len(a) && i < len(b) && a[i] == b[i] { for i < len(a) && i < len(b) && a[i] == b[i] {
i++; i++;
} }
return a[0 : i]; return a[0:i];
} }
...@@ -196,7 +196,7 @@ func unindent(block [][]byte) { ...@@ -196,7 +196,7 @@ func unindent(block [][]byte) {
// remove // remove
for i, line := range block { for i, line := range block {
if !isBlank(line) { if !isBlank(line) {
block[i] = line[n : len(line)]; block[i] = line[n:len(line)];
} }
} }
} }
...@@ -260,7 +260,7 @@ func ToHtml(w io.Writer, s []byte) { ...@@ -260,7 +260,7 @@ func ToHtml(w io.Writer, s []byte) {
for j > i && isBlank(lines[j-1]) { for j > i && isBlank(lines[j-1]) {
j--; j--;
} }
block := lines[i : j]; block := lines[i:j];
i = j; i = j;
unindent(block); unindent(block);
...@@ -288,4 +288,3 @@ func ToHtml(w io.Writer, s []byte) { ...@@ -288,4 +288,3 @@ func ToHtml(w io.Writer, s []byte) {
inpara = false; inpara = false;
} }
} }
...@@ -131,103 +131,103 @@ const ( ...@@ -131,103 +131,103 @@ const (
// At the moment we have no array literal syntax that lets us describe // At the moment we have no array literal syntax that lets us describe
// the index for each element - use a map for now to make sure they are // the index for each element - use a map for now to make sure they are
// in sync. // in sync.
var tokens = map [Token] string { var tokens = map[Token]string{
ILLEGAL : "ILLEGAL", ILLEGAL: "ILLEGAL",
EOF : "EOF", EOF: "EOF",
COMMENT : "COMMENT", COMMENT: "COMMENT",
IDENT : "IDENT", IDENT: "IDENT",
INT : "INT", INT: "INT",
FLOAT : "FLOAT", FLOAT: "FLOAT",
CHAR : "CHAR", CHAR: "CHAR",
STRING : "STRING", STRING: "STRING",
ADD : "+", ADD: "+",
SUB : "-", SUB: "-",
MUL : "*", MUL: "*",
QUO : "/", QUO: "/",
REM : "%", REM: "%",
AND : "&", AND: "&",
OR : "|", OR: "|",
XOR : "^", XOR: "^",
SHL : "<<", SHL: "<<",
SHR : ">>", SHR: ">>",
AND_NOT : "&^", AND_NOT: "&^",
ADD_ASSIGN : "+=", ADD_ASSIGN: "+=",
SUB_ASSIGN : "-=", SUB_ASSIGN: "-=",
MUL_ASSIGN : "*=", MUL_ASSIGN: "*=",
QUO_ASSIGN : "/=", QUO_ASSIGN: "/=",
REM_ASSIGN : "%=", REM_ASSIGN: "%=",
AND_ASSIGN : "&=", AND_ASSIGN: "&=",
OR_ASSIGN : "|=", OR_ASSIGN: "|=",
XOR_ASSIGN : "^=", XOR_ASSIGN: "^=",
SHL_ASSIGN : "<<=", SHL_ASSIGN: "<<=",
SHR_ASSIGN : ">>=", SHR_ASSIGN: ">>=",
AND_NOT_ASSIGN : "&^=", AND_NOT_ASSIGN: "&^=",
LAND : "&&", LAND: "&&",
LOR : "||", LOR: "||",
ARROW : "<-", ARROW: "<-",
INC : "++", INC: "++",
DEC : "--", DEC: "--",
EQL : "==", EQL: "==",
LSS : "<", LSS: "<",
GTR : ">", GTR: ">",
ASSIGN : "=", ASSIGN: "=",
NOT : "!", NOT: "!",
NEQ : "!=", NEQ: "!=",
LEQ : "<=", LEQ: "<=",
GEQ : ">=", GEQ: ">=",
DEFINE : ":=", DEFINE: ":=",
ELLIPSIS : "...", ELLIPSIS: "...",
LPAREN : "(", LPAREN: "(",
LBRACK : "[", LBRACK: "[",
LBRACE : "{", LBRACE: "{",
COMMA : ",", COMMA: ",",
PERIOD : ".", PERIOD: ".",
RPAREN : ")", RPAREN: ")",
RBRACK : "]", RBRACK: "]",
RBRACE : "}", RBRACE: "}",
SEMICOLON : ";", SEMICOLON: ";",
COLON : ":", COLON: ":",
BREAK : "break", BREAK: "break",
CASE : "case", CASE: "case",
CHAN : "chan", CHAN: "chan",
CONST : "const", CONST: "const",
CONTINUE : "continue", CONTINUE: "continue",
DEFAULT : "default", DEFAULT: "default",
DEFER : "defer", DEFER: "defer",
ELSE : "else", ELSE: "else",
FALLTHROUGH : "fallthrough", FALLTHROUGH: "fallthrough",
FOR : "for", FOR: "for",
FUNC : "func", FUNC: "func",
GO : "go", GO: "go",
GOTO : "goto", GOTO: "goto",
IF : "if", IF: "if",
IMPORT : "import", IMPORT: "import",
INTERFACE : "interface", INTERFACE: "interface",
MAP : "map", MAP: "map",
PACKAGE : "package", PACKAGE: "package",
RANGE : "range", RANGE: "range",
RETURN : "return", RETURN: "return",
SELECT : "select", SELECT: "select",
STRUCT : "struct", STRUCT: "struct",
SWITCH : "switch", SWITCH: "switch",
TYPE : "type", TYPE: "type",
VAR : "var", VAR: "var",
} }
...@@ -281,10 +281,10 @@ func (op Token) Precedence() int { ...@@ -281,10 +281,10 @@ func (op Token) Precedence() int {
} }
var keywords map [string] Token; var keywords map[string]Token
func init() { func init() {
keywords = make(map [string] Token); keywords = make(map[string]Token);
for i := keyword_beg + 1; i < keyword_end; i++ { for i := keyword_beg + 1; i < keyword_end; i++ {
keywords[tokens[i]] = i; keywords[tokens[i]] = i;
} }
...@@ -348,7 +348,7 @@ func (pos *Position) Pos() Position { ...@@ -348,7 +348,7 @@ func (pos *Position) Pos() Position {
// IsValid returns true if the position is valid. // IsValid returns true if the position is valid.
func (pos *Position) IsValid() bool { func (pos *Position) IsValid() bool {
return pos.Line > 0 return pos.Line > 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