mirror of
https://github.com/golang/go.git
synced 2025-05-18 22:04:38 +00:00
cleanup in personal dir:
- delete some unused files (copies archived elsewhere) TBR=r OCL=34994 CL=34994
This commit is contained in:
parent
f448057b8a
commit
0d17ebde1c
@ -1,35 +0,0 @@
|
|||||||
# 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.
|
|
||||||
|
|
||||||
# -*- Makefile -*-
|
|
||||||
|
|
||||||
GO = /home/iant/go/bin/gccgo
|
|
||||||
|
|
||||||
LDFLAGS = -Wl,-R,/home/iant/go/lib,-static-libgo
|
|
||||||
|
|
||||||
PRETTY_OBJS = \
|
|
||||||
astprinter.o \
|
|
||||||
format.o \
|
|
||||||
pretty.o \
|
|
||||||
|
|
||||||
pretty: $(PRETTY_OBJS)
|
|
||||||
$(GO) $(LDFLAGS) -o $@ $(PRETTY_OBJS)
|
|
||||||
|
|
||||||
test: pretty
|
|
||||||
test.sh
|
|
||||||
|
|
||||||
install: pretty
|
|
||||||
cp pretty $(HOME)/bin/pretty
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f pretty *.o *~
|
|
||||||
|
|
||||||
|
|
||||||
pretty.o: astprinter.o format.o
|
|
||||||
|
|
||||||
.SUFFIXES:
|
|
||||||
.SUFFIXES: .go .o
|
|
||||||
|
|
||||||
.go.o:
|
|
||||||
$(GO) -O2 -c -g $<
|
|
@ -2,43 +2,65 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// Format file for printing AST nodes.
|
// This is the datafmt format file for printing AST nodes.
|
||||||
|
// It is used by go/ast/format.go. It assumes that the output
|
||||||
|
// is fed through a tabwriter.Writer for proper alignment.
|
||||||
|
// Form feed chars ('\f') are used to control the tabwriter's
|
||||||
|
// column formatting.
|
||||||
|
|
||||||
|
// TODO change these to "go/ast", "go/token" once
|
||||||
|
// the full path is returned by reflection
|
||||||
ast "ast";
|
ast "ast";
|
||||||
token "token";
|
token "token";
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Custom formatters
|
||||||
|
//
|
||||||
|
// TODO should be able to reduce this number/find better primitives
|
||||||
|
// The following formatters are defined in go/ast/format.go:
|
||||||
|
//
|
||||||
|
// allCode
|
||||||
|
// setComments
|
||||||
|
// isVisible (currently not used)
|
||||||
|
// isValidPos
|
||||||
|
// isParenResult
|
||||||
|
// isSend
|
||||||
|
// isRecv
|
||||||
|
// writeComment
|
||||||
|
// clearOptSemi
|
||||||
|
// setOptSemi
|
||||||
|
// optSemi
|
||||||
|
// token.Position
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Basic types, support rules
|
// Basic types, support rules
|
||||||
|
|
||||||
array =
|
array =
|
||||||
*;
|
*;
|
||||||
|
|
||||||
|
bytes =
|
||||||
|
{*};
|
||||||
|
|
||||||
|
char =
|
||||||
|
"%c";
|
||||||
|
|
||||||
|
interface =
|
||||||
|
*;
|
||||||
|
|
||||||
ptr =
|
ptr =
|
||||||
*;
|
*;
|
||||||
|
|
||||||
string =
|
string =
|
||||||
"%s";
|
"%s";
|
||||||
|
|
||||||
char =
|
|
||||||
"%c";
|
|
||||||
|
|
||||||
bytes =
|
|
||||||
{*};
|
|
||||||
|
|
||||||
empty =
|
empty =
|
||||||
;
|
;
|
||||||
|
|
||||||
exists =
|
exists =
|
||||||
*:empty;
|
*:empty;
|
||||||
|
|
||||||
ast.Expr =
|
|
||||||
*;
|
|
||||||
|
|
||||||
ast.Stmt =
|
|
||||||
*;
|
|
||||||
|
|
||||||
ast.Decl =
|
|
||||||
*;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Tokens and comments
|
// Tokens and comments
|
||||||
@ -47,10 +69,7 @@ token.Token =
|
|||||||
@:string;
|
@:string;
|
||||||
|
|
||||||
ast.Comment =
|
ast.Comment =
|
||||||
// TODO this doesn't indent properly after //-style comments because
|
Position Text:writeComment;
|
||||||
// the '\n'-char is printed as part of the comment - need to
|
|
||||||
// address this
|
|
||||||
Text:string [Text:isMultiLineComment "\n"];
|
|
||||||
|
|
||||||
ast.Comments =
|
ast.Comments =
|
||||||
{*};
|
{*};
|
||||||
@ -60,28 +79,31 @@ ast.Comments =
|
|||||||
// Expressions & Types
|
// Expressions & Types
|
||||||
|
|
||||||
ast.Field =
|
ast.Field =
|
||||||
[Names:exists {Names / ", "} " "] Type;
|
[Names:exists {Names / ", "} "\t"] Type ["\t" Tag];
|
||||||
|
|
||||||
|
ast.Expr =
|
||||||
|
*;
|
||||||
|
|
||||||
ast.BadExpr =
|
ast.BadExpr =
|
||||||
"BAD EXPR";
|
Position "BAD EXPR";
|
||||||
|
|
||||||
ast.Ident =
|
ast.Ident =
|
||||||
Value;
|
Position Value;
|
||||||
|
|
||||||
ast.Ellipsis =
|
ast.Ellipsis =
|
||||||
"...";
|
Position "...";
|
||||||
|
|
||||||
ast.IntLit =
|
ast.IntLit =
|
||||||
Value:string;
|
Position Value:string;
|
||||||
|
|
||||||
ast.FloatLit =
|
ast.FloatLit =
|
||||||
Value:string;
|
Position Value:string;
|
||||||
|
|
||||||
ast.CharLit =
|
ast.CharLit =
|
||||||
Value:string;
|
Position Value:string;
|
||||||
|
|
||||||
ast.StringLit =
|
ast.StringLit =
|
||||||
Value:string;
|
Position Value:string;
|
||||||
|
|
||||||
ast.StringList =
|
ast.StringList =
|
||||||
{Strings / "\n"};
|
{Strings / "\n"};
|
||||||
@ -90,71 +112,77 @@ ast.FuncLit =
|
|||||||
Type " " Body @:clearOptSemi; // no optional ; after a func literal body
|
Type " " Body @:clearOptSemi; // no optional ; after a func literal body
|
||||||
|
|
||||||
ast.CompositeLit =
|
ast.CompositeLit =
|
||||||
Type "{" {Elts / ", "} "}";
|
Type Lbrace "{" {Elts / ", "} Rbrace "}";
|
||||||
|
|
||||||
ast.ParenExpr =
|
ast.ParenExpr =
|
||||||
"(" X ")";
|
Position "(" X ")";
|
||||||
|
|
||||||
ast.SelectorExpr =
|
ast.SelectorExpr =
|
||||||
X "." Sel;
|
X "." Sel;
|
||||||
|
|
||||||
ast.IndexExpr =
|
ast.IndexExpr =
|
||||||
X "[" Index [":" End] "]";
|
X "[" Index [" : " End] "]";
|
||||||
|
|
||||||
ast.TypeAssertExpr =
|
ast.TypeAssertExpr =
|
||||||
X ".(" Type ")";
|
X ".(" Type ")";
|
||||||
|
|
||||||
ast.CallExpr =
|
ast.CallExpr =
|
||||||
Fun "(" {Args / ", "} ")";
|
Fun Lparen "(" {Args / ", "} Rparen ")";
|
||||||
|
|
||||||
ast.StarExpr =
|
ast.StarExpr =
|
||||||
"*" X;
|
Position "*" X;
|
||||||
|
|
||||||
ast.UnaryExpr =
|
ast.UnaryExpr =
|
||||||
Op X;
|
Position Op X;
|
||||||
|
|
||||||
ast.BinaryExpr =
|
ast.BinaryExpr =
|
||||||
X " " Op " " Y;
|
X " " OpPos Op " " Y;
|
||||||
|
|
||||||
ast.KeyValueExpr =
|
ast.KeyValueExpr =
|
||||||
Key ": " Value;
|
Key Colon ": " Value;
|
||||||
|
|
||||||
ast.ArrayType =
|
ast.ArrayType =
|
||||||
"[" [Len] "]" Elt;
|
Position "[" [Len] "]" Elt;
|
||||||
|
|
||||||
ast.StructType =
|
ast.StructType =
|
||||||
"struct"
|
Position "struct"
|
||||||
[Lbrace:isValidPos " {"]
|
[Lbrace:isValidPos " " Lbrace "{"]
|
||||||
[ Fields:exists
|
[ Fields:exists
|
||||||
( "\t" >> "\n"
|
( "\t" >> "\f"
|
||||||
{Fields / ";\n"}
|
{Fields / ";\n"}
|
||||||
) "\n"
|
) "\n"
|
||||||
]
|
]
|
||||||
[Rbrace:isValidPos "}"];
|
[Rbrace:isValidPos Rbrace "}"];
|
||||||
|
|
||||||
signature =
|
signature =
|
||||||
"(" {Params / ", "} ")" [Results:exists " (" {Results / ", "} ")"];
|
"(" {Params / ", "} ")"
|
||||||
|
[ Results:exists " "
|
||||||
|
( Results:isParenResult "(" {Results / ", "} ")"
|
||||||
|
| {Results}
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
funcSignature =
|
funcSignature =
|
||||||
*:signature;
|
*:signature;
|
||||||
|
|
||||||
ast.FuncType =
|
ast.FuncType =
|
||||||
[Position:isValidPos "func"] @:signature;
|
[Position:isValidPos Position "func"] @:signature;
|
||||||
|
|
||||||
ast.InterfaceType =
|
ast.InterfaceType =
|
||||||
"interface"
|
Position "interface"
|
||||||
[Lbrace:isValidPos " {"]
|
[Lbrace:isValidPos " " Lbrace "{"]
|
||||||
[ Methods:exists
|
[ Methods:exists
|
||||||
( "\t" >> "\n"
|
( "\t" >> "\f"
|
||||||
{Methods / ";\n"}
|
{Methods / ";\n"}
|
||||||
) "\n"
|
) "\n"
|
||||||
]
|
]
|
||||||
[Rbrace:isValidPos "}"];
|
[Rbrace:isValidPos Rbrace "}"];
|
||||||
|
|
||||||
ast.MapType =
|
ast.MapType =
|
||||||
"map[" Key "]" Value;
|
Position "map[" Key "]" Value;
|
||||||
|
|
||||||
ast.ChanType =
|
ast.ChanType =
|
||||||
|
Position
|
||||||
( Dir:isSend Dir:isRecv
|
( Dir:isSend Dir:isRecv
|
||||||
"chan "
|
"chan "
|
||||||
| Dir:isSend
|
| Dir:isSend
|
||||||
@ -167,14 +195,17 @@ ast.ChanType =
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Statements
|
// Statements
|
||||||
|
|
||||||
|
ast.Stmt =
|
||||||
|
*;
|
||||||
|
|
||||||
ast.BadStmt =
|
ast.BadStmt =
|
||||||
"BAD STMT";
|
Position "BAD STMT";
|
||||||
|
|
||||||
ast.DeclStmt =
|
ast.DeclStmt =
|
||||||
Decl;
|
Decl;
|
||||||
|
|
||||||
ast.EmptyStmt =
|
ast.EmptyStmt =
|
||||||
;
|
Position ;
|
||||||
|
|
||||||
ast.LabeledStmt =
|
ast.LabeledStmt =
|
||||||
Label ":\t" Stmt;
|
Label ":\t" Stmt;
|
||||||
@ -186,19 +217,19 @@ ast.IncDecStmt =
|
|||||||
X Tok;
|
X Tok;
|
||||||
|
|
||||||
ast.AssignStmt =
|
ast.AssignStmt =
|
||||||
{Lhs / ", "} " " Tok " " {Rhs / ", "};
|
{Lhs / ", "} " " TokPos Tok " " {Rhs / ", "};
|
||||||
|
|
||||||
ast.GoStmt =
|
ast.GoStmt =
|
||||||
"go " Call;
|
Position "go " Call;
|
||||||
|
|
||||||
ast.DeferStmt =
|
ast.DeferStmt =
|
||||||
"defer " Call;
|
Position "defer " Call;
|
||||||
|
|
||||||
ast.ReturnStmt =
|
ast.ReturnStmt =
|
||||||
"return" {" " Results / ","};
|
Position "return" {" " Results / ","};
|
||||||
|
|
||||||
ast.BranchStmt =
|
ast.BranchStmt =
|
||||||
Tok [" " Label];
|
Position Tok [" " Label];
|
||||||
|
|
||||||
stmtList =
|
stmtList =
|
||||||
{@ / @:optSemi "\n"};
|
{@ / @:optSemi "\n"};
|
||||||
@ -206,7 +237,7 @@ stmtList =
|
|||||||
blockStmt = // like ast.BlockStmt but w/o indentation
|
blockStmt = // like ast.BlockStmt but w/o indentation
|
||||||
"{"
|
"{"
|
||||||
[List:exists
|
[List:exists
|
||||||
"\n"
|
"\f"
|
||||||
List:stmtList
|
List:stmtList
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
@ -216,22 +247,26 @@ blockStmtPtr =
|
|||||||
*:blockStmt;
|
*:blockStmt;
|
||||||
|
|
||||||
ast.BlockStmt =
|
ast.BlockStmt =
|
||||||
"{"
|
Position "{"
|
||||||
[List:exists
|
[List:exists
|
||||||
( "\t" >> "\n"
|
( "\t" >> "\f"
|
||||||
List:stmtList
|
List:stmtList
|
||||||
) "\n"
|
) "\n"
|
||||||
]
|
]
|
||||||
"}" @:setOptSemi;
|
Rbrace "}" @:setOptSemi;
|
||||||
|
|
||||||
ast.IfStmt =
|
ast.IfStmt =
|
||||||
"if " [Init "; "] [Cond " "] Body [" else " Else];
|
Position "if " [Init "; "] [Cond " "] Body [" else " Else];
|
||||||
|
|
||||||
ast.CaseClause =
|
ast.CaseClause =
|
||||||
( Values:exists "case " {Values / ", "}
|
// TODO the code below should work with () instead of []
|
||||||
|
// but doesn't (after first case, always default is
|
||||||
|
// selected).
|
||||||
|
Position
|
||||||
|
[ Values:exists "case " {Values / ", "}
|
||||||
| "default"
|
| "default"
|
||||||
)
|
]
|
||||||
":"
|
Colon ":"
|
||||||
[Body:exists
|
[Body:exists
|
||||||
( "\t" >> "\n"
|
( "\t" >> "\n"
|
||||||
Body:stmtList
|
Body:stmtList
|
||||||
@ -239,14 +274,15 @@ ast.CaseClause =
|
|||||||
];
|
];
|
||||||
|
|
||||||
ast.SwitchStmt =
|
ast.SwitchStmt =
|
||||||
"switch " [Init "; "] [Tag " "]
|
Position "switch " [Init "; "] [Tag " "]
|
||||||
Body:blockStmtPtr;
|
Body:blockStmtPtr;
|
||||||
|
|
||||||
ast.TypeCaseClause =
|
ast.TypeCaseClause =
|
||||||
|
Position
|
||||||
( Type:exists "case " Type
|
( Type:exists "case " Type
|
||||||
| "default"
|
| "default"
|
||||||
)
|
)
|
||||||
":"
|
Colon ":"
|
||||||
[Body:exists
|
[Body:exists
|
||||||
( "\t" >> "\n"
|
( "\t" >> "\n"
|
||||||
Body:stmtList
|
Body:stmtList
|
||||||
@ -254,14 +290,15 @@ ast.TypeCaseClause =
|
|||||||
];
|
];
|
||||||
|
|
||||||
ast.TypeSwitchStmt =
|
ast.TypeSwitchStmt =
|
||||||
"switch " Assign " "
|
Position "switch " Assign " "
|
||||||
Body:blockStmtPtr;
|
Body:blockStmtPtr;
|
||||||
|
|
||||||
ast.CommClause =
|
ast.CommClause =
|
||||||
|
Position
|
||||||
( "case " [Lhs " " Tok " "] Rhs
|
( "case " [Lhs " " Tok " "] Rhs
|
||||||
| "default"
|
| "default"
|
||||||
)
|
)
|
||||||
":"
|
Colon ":"
|
||||||
[Body:exists
|
[Body:exists
|
||||||
( "\t" >> "\n"
|
( "\t" >> "\n"
|
||||||
Body:stmtList
|
Body:stmtList
|
||||||
@ -269,7 +306,7 @@ ast.CommClause =
|
|||||||
];
|
];
|
||||||
|
|
||||||
ast.SelectStmt =
|
ast.SelectStmt =
|
||||||
"select "
|
Position "select "
|
||||||
Body:blockStmtPtr;
|
Body:blockStmtPtr;
|
||||||
|
|
||||||
ast.ForStmt =
|
ast.ForStmt =
|
||||||
@ -281,7 +318,7 @@ ast.ForStmt =
|
|||||||
Body;
|
Body;
|
||||||
|
|
||||||
ast.RangeStmt =
|
ast.RangeStmt =
|
||||||
"for " Key [", " Value] " " Tok " range " X
|
Position "for " Key [", " Value] " " TokPos Tok " range " X
|
||||||
" "
|
" "
|
||||||
Body;
|
Body;
|
||||||
|
|
||||||
@ -293,35 +330,44 @@ ast.Spec =
|
|||||||
*;
|
*;
|
||||||
|
|
||||||
ast.ImportSpec =
|
ast.ImportSpec =
|
||||||
Doc
|
[@:allCode Doc]
|
||||||
[Name] "\t" {Path};
|
[Name] "\t" {Path};
|
||||||
|
|
||||||
ast.ValueSpec =
|
ast.ValueSpec =
|
||||||
{Names / ", "} [" " Type] [Values:exists " = " {Values / ", "}];
|
{Names / ", "} ["\t" Type] [Values:exists "\t= " {Values / ", "}];
|
||||||
|
|
||||||
ast.TypeSpec =
|
ast.TypeSpec =
|
||||||
Name " " // TODO using "\t" instead of " " screws up struct field alignment
|
Name "\t" Type;
|
||||||
Type;
|
|
||||||
|
ast.Decl =
|
||||||
|
*;
|
||||||
|
|
||||||
ast.BadDecl =
|
ast.BadDecl =
|
||||||
"BAD DECL";
|
Position "BAD DECL";
|
||||||
|
|
||||||
ast.GenDecl =
|
ast.GenDecl =
|
||||||
Doc
|
[@:allCode Doc]
|
||||||
Tok " "
|
Position Tok " "
|
||||||
( Lparen:isValidPos "("
|
( Lparen:isValidPos Lparen "("
|
||||||
[Specs:exists
|
[Specs:exists
|
||||||
( "\t" >> "\n"
|
( "\t" >> "\f"
|
||||||
{Specs / ";\n"}
|
{Specs / ";\n"}
|
||||||
) "\n"
|
) "\n"
|
||||||
]
|
]
|
||||||
")" @:setOptSemi
|
Rparen ")" @:setOptSemi
|
||||||
| {Specs / ";\n"}
|
| {Specs / ";\n"}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
funcKeyword =
|
||||||
|
Position "func ";
|
||||||
|
|
||||||
|
funcTypePtr =
|
||||||
|
*:funcKeyword;
|
||||||
|
|
||||||
ast.FuncDecl =
|
ast.FuncDecl =
|
||||||
"func " ["(" Recv ") "] Name Type:funcSignature
|
[@:allCode Doc]
|
||||||
[" " Body]
|
Type:funcTypePtr ["(" Recv ") "] Name Type:funcSignature
|
||||||
|
[@:allCode " " Body]
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
|
|
||||||
@ -329,6 +375,9 @@ ast.FuncDecl =
|
|||||||
// Program
|
// Program
|
||||||
|
|
||||||
ast.Program =
|
ast.Program =
|
||||||
Doc
|
Comments:setComments
|
||||||
"package " Name "\n\n"
|
""
|
||||||
{Decls / "\n\n"};
|
[@:allCode Doc]
|
||||||
|
Position "package " Name "\n\n"
|
||||||
|
{Decls / "\n\n"}
|
||||||
|
"\n"; // TODO necessary because tabwriter.Flush doesn't format last line correctly - fix this
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
// 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 main
|
|
||||||
|
|
||||||
type Proto struct {
|
|
||||||
a int "a tag";
|
|
||||||
b, c, d *Proto "bcd" "tag";
|
|
||||||
*Proto "proto tag"
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
// 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 main
|
|
||||||
|
|
||||||
import P0 /* ERROR expected */ ; /* SYNC */
|
|
||||||
import P1 /* ERROR expected */ Flags /* SYNC */
|
|
||||||
import P2 /* ERROR expected */ 42 /* SYNC */
|
|
||||||
|
|
||||||
|
|
||||||
type S0 struct {
|
|
||||||
f0, f1, f2 int;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func /* ERROR receiver */ () f0() {} /* SYNC */
|
|
||||||
func /* ERROR receiver */ (*S0, *S0) f1() {} /* SYNC */
|
|
||||||
|
|
||||||
|
|
||||||
func f0(a b, c /* ERROR type */ ) /* SYNC */ {}
|
|
||||||
|
|
||||||
|
|
||||||
func f1() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func CompositeLiterals() {
|
|
||||||
a1 := []int();
|
|
||||||
a2 := []int(0, 1, 2, );
|
|
||||||
a3 := []int(0, 1, 2, /* ERROR single value expected */ 3 : 4, 5); /* SYNC */
|
|
||||||
a1 := []int(0 : 1, 2 : 3, /* ERROR key:value pair expected */ 4, ); /* SYNC */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func main () {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func /* ERROR EOF */
|
|
@ -1,158 +0,0 @@
|
|||||||
// 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 main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"container/vector"; // not needed
|
|
||||||
"utf8"; // not needed
|
|
||||||
Fmt "fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
const /* enum1 */ (
|
|
||||||
EnumTag0 = iota;
|
|
||||||
EnumTag1;
|
|
||||||
EnumTag2;
|
|
||||||
EnumTag3;
|
|
||||||
EnumTag4;
|
|
||||||
EnumTag5;
|
|
||||||
EnumTag6;
|
|
||||||
EnumTag7;
|
|
||||||
EnumTag8;
|
|
||||||
EnumTag9;
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
const /* enum2 */ (
|
|
||||||
a, b = iota*2 + 1, iota*2;
|
|
||||||
c, d;
|
|
||||||
e, f;
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
type S struct {}
|
|
||||||
|
|
||||||
|
|
||||||
type T struct {
|
|
||||||
x, y int;
|
|
||||||
s string;
|
|
||||||
next_t *T
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var (
|
|
||||||
aa = 5;
|
|
||||||
u, v, w int = 0, 0, 0;
|
|
||||||
foo = "foo";
|
|
||||||
fixed_array0 = [10]int{};
|
|
||||||
fixed_array1 = [10]int{0, 1, 2};
|
|
||||||
fixed_array2 = [...]string{"foo", "bar"};
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Unicode identifiers
|
|
||||||
ä, ö, ü, ƒ, ß int;
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func d0() {
|
|
||||||
var (
|
|
||||||
a string;
|
|
||||||
b, c string;
|
|
||||||
d, e, f string;
|
|
||||||
g, h, i, j string;
|
|
||||||
k, l, m, n, o string;
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func f0(a, b int) int {
|
|
||||||
if a < b {
|
|
||||||
a = a + 1; // estimate
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func f1(tag int) {
|
|
||||||
switch tag {
|
|
||||||
case
|
|
||||||
EnumTag0, EnumTag1, EnumTag2, EnumTag3, EnumTag4,
|
|
||||||
EnumTag5, EnumTag6, EnumTag7, EnumTag8, EnumTag9: break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func f2(tag int) {
|
|
||||||
type T struct {}
|
|
||||||
var x T
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func f3(a *[]int, m map[string] int) {
|
|
||||||
println("A1");
|
|
||||||
for i := range a {
|
|
||||||
println(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
println("A2");
|
|
||||||
for i, x := range a {
|
|
||||||
println(i, x);
|
|
||||||
}
|
|
||||||
|
|
||||||
println("A3");
|
|
||||||
for i, x := range a {
|
|
||||||
println(i, x);
|
|
||||||
}
|
|
||||||
|
|
||||||
println("M1");
|
|
||||||
for i := range m {
|
|
||||||
println(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
println("M2");
|
|
||||||
for i, x := range m {
|
|
||||||
println(i, x);
|
|
||||||
}
|
|
||||||
|
|
||||||
println("M3");
|
|
||||||
var i string;
|
|
||||||
var x int;
|
|
||||||
for i, x = range m {
|
|
||||||
defer Fmt.Println(i, x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type I interface {}
|
|
||||||
|
|
||||||
/*
|
|
||||||
func f4(x I) int {
|
|
||||||
switch tmp := x.(type) {
|
|
||||||
case S: return 1;
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case t := x.(S): return 2;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// the prologue
|
|
||||||
for i := 0; i <= 10 /* limit */; i++ {
|
|
||||||
println(i); // the index
|
|
||||||
println(i + 1); // the index + 1
|
|
||||||
println(i + 1000); // the index + 1000
|
|
||||||
println();
|
|
||||||
}
|
|
||||||
f3(&[]int{2, 3, 5, 7}, map[string]int{"two":2, "three":3, "five":5, "seven":7});
|
|
||||||
// the epilogue
|
|
||||||
println("foo"); // foo
|
|
||||||
println("foobar"); // foobar
|
|
||||||
var x int; // declare x
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user