diff --git a/engine/tests/demo/leetcode5.gos b/engine/tests/demo/leetcode5.gos index 8120065d..c811fdfb 100644 --- a/engine/tests/demo/leetcode5.gos +++ b/engine/tests/demo/leetcode5.gos @@ -83,9 +83,9 @@ func main() { //t(1000) } //assert(j == 10) - + result := longestPalindrome2(s) - assert(result == "aaabbbaaabbbaaa") + assert(result == "aaabbbaaabbbaaa") //assert(longestPalindrome("aa") == "aa") diff --git a/engine/tests/group1/closure4.gos b/engine/tests/group1/closure4.gos index 263c08cd..fd5ccad8 100644 --- a/engine/tests/group1/closure4.gos +++ b/engine/tests/group1/closure4.gos @@ -6,7 +6,7 @@ func tt() { c := 3 return func()int { d := 2 - return a + 1 + c + d + return a + 1 + c + d } } e := func() int { @@ -26,7 +26,7 @@ func main() { c := 3 return func()int { d := 2 - return a + 1 + c + d + return a + 1 + c + d } } e := func() int { diff --git a/engine/tests/group1/defer.gos b/engine/tests/group1/defer.gos index 2a6d8f23..a9ed2acb 100644 --- a/engine/tests/group1/defer.gos +++ b/engine/tests/group1/defer.gos @@ -2,15 +2,15 @@ package main import ( - "fmt" + "fmt" ) func f() (result int) { - defer func() { - // result is accessed after it was set to 6 by the return statement - result *= 7 - }() - return 6 + defer func() { + // result is accessed after it was set to 6 by the return statement + result *= 7 + }() + return 6 } func main() { @@ -18,7 +18,7 @@ func main() { fmt.Println(f()) for i := 0; i <= 3; i++ { - defer fmt.Println(i) + defer fmt.Println(i) } } diff --git a/engine/tests/group1/map1.gos b/engine/tests/group1/map1.gos index 00653eed..684e8f97 100644 --- a/engine/tests/group1/map1.gos +++ b/engine/tests/group1/map1.gos @@ -2,43 +2,43 @@ package main func a () (int, int) { - return 6,7 + return 6,7 } func b() int { - return 8 + return 8 } func commaOk() { - - var i interface{} = "hello" + var i interface{} = "hello" - s, ok := i.(string) - assert(ok) - assert(s == "hello") - - s1 := i.(string) - assert(s1 == "hello") + s, ok := i.(string) + assert(ok) + assert(s == "hello") + + s1 := i.(string) + assert(s1 == "hello") - - m := map[int]int{1:10, 2:20} - int1, ok := m[1] - assert(int1 == 10) - assert(ok) - int2 := m[2] - assert(int2 == 20) - t1, t2 := a() - assert(t1 == 6) - assert(t2 == 7) - t3 := b() - assert(t3 == 8) + + m := map[int]int{1:10, 2:20} + int1, ok := m[1] + assert(int1 == 10) + assert(ok) + int2 := m[2] + assert(int2 == 20) + + t1, t2 := a() + assert(t1 == 6) + assert(t2 == 7) + t3 := b() + assert(t3 == 8) t01, t02 := 33, m[2] assert(t01 == 33) - assert(t02 == 20) + assert(t02 == 20) } func main() { diff --git a/engine/tests/group1/pkg.gos b/engine/tests/group1/pkg.gos index 91f525da..47862f76 100644 --- a/engine/tests/group1/pkg.gos +++ b/engine/tests/group1/pkg.gos @@ -29,10 +29,10 @@ func main() { } func fa () (int, int) { - assert(8 == fb()) - return 6,7 + assert(8 == fb()) + return 6,7 } func fb() int { - return 8 + return 8 } diff --git a/engine/tests/group1/type.gos b/engine/tests/group1/type.gos index 2b67b6d2..3f231734 100644 --- a/engine/tests/group1/type.gos +++ b/engine/tests/group1/type.gos @@ -38,7 +38,7 @@ type Add func(a int, b int) int func main() { type S2 struct {i int} - var s1 S1 + var s1 S1 //var s2 S2 s1.Inc() diff --git a/engine/tests/group1/typeswitch.gos b/engine/tests/group1/typeswitch.gos index 5faaa4ab..564f0b51 100644 --- a/engine/tests/group1/typeswitch.gos +++ b/engine/tests/group1/typeswitch.gos @@ -1,47 +1,47 @@ package main import ( - "fmt" + "fmt" ) type S1 struct {i int; j int} func typeName(v interface{}) string { - switch v.(type) { - case int: - return "int" - case string: - return "string" + switch v.(type) { + case int: + return "int" + case string: + return "string" case *S1: return "S1" - default: - return "unknown" - } + default: + return "unknown" + } } func typeName2(v interface{}) string { kk := 2 - switch i := v.(type) { - case int: + switch i := v.(type) { + case int: assert(i + kk == 890) - return "int" - case string: - return "string" + return "int" + case string: + return "string" case *S1: - _ = i + _ = i return "S1" - case []int: - return "[]int" - case map[string]int: - return "map[string]int" - case map[string][]int: - return "map[string][]int" - default: - return "unknown" - } - return "int" + case []int: + return "[]int" + case map[string]int: + return "map[string]int" + case map[string][]int: + return "map[string][]int" + default: + return "unknown" + } + return "int" } func main() { diff --git a/engine/tests/group2/case0.gos b/engine/tests/group2/case0.gos index c519c2b6..0de1a750 100644 --- a/engine/tests/group2/case0.gos +++ b/engine/tests/group2/case0.gos @@ -8,16 +8,16 @@ type TestKey struct { } func ptr() (*int, *int) { - i := 100 - return &i, &i + i := 100 + return &i, &i } func main() { var errNil error - var mapNil map[int]string - //mapNil[1] = "aa" + var mapNil map[int]string + //mapNil[1] = "aa" m := make(map[int]string) m[1] = "bb" diff --git a/engine/tests/group2/case3.gos b/engine/tests/group2/case3.gos index 969e4a97..6494df24 100644 --- a/engine/tests/group2/case3.gos +++ b/engine/tests/group2/case3.gos @@ -1,13 +1,13 @@ package main import ( - "fmt" + "fmt" ) func main() { - var v = new(int) + var v = new(int) var vv = 2 *v = 8 var vvv = *v @@ -17,7 +17,7 @@ func main() { var sa = &A{} - fmt.Println("Hello, playground", v, vv, vvv, s, s1, s3, sa) + fmt.Println("Hello, playground", v, vv, vvv, s, s1, s3, sa) } type A []int diff --git a/engine/tests/group2/nil.gos b/engine/tests/group2/nil.gos index bba66f03..50f1993c 100644 --- a/engine/tests/group2/nil.gos +++ b/engine/tests/group2/nil.gos @@ -1,7 +1,7 @@ package main import ( - "fmt" + "fmt" ) type III interface{} @@ -12,7 +12,7 @@ i int } func main() { - //var m []string + //var m []string var ia interface{} ia = 8 @@ -31,7 +31,7 @@ func main() { a = b b.i = 55 - fmt.Println("Hello, playground", ia, ia == nil, ib, ib == nil, 10, a.i, b.i) + fmt.Println("Hello, playground", ia, ia == nil, ib, ib == nil, 10, a.i, b.i) c := &a d := &b diff --git a/engine/tests/group2/unicode0.gos b/engine/tests/group2/unicode0.gos index 104d3c16..a730a60c 100644 --- a/engine/tests/group2/unicode0.gos +++ b/engine/tests/group2/unicode0.gos @@ -1,38 +1,38 @@ package main import ( - "fmt" + "fmt" "unicode/utf8" ) func ExampleDecodeLastRune() { - b := []byte("Hello, 世界") - utf8.DecodeLastRune(b) + b := []byte("Hello, 世界") + utf8.DecodeLastRune(b) - - for len(b) > 0 { - r, size := utf8.DecodeLastRune(b) - fmt.Println("%c %v\n", r, size) + + for len(b) > 0 { + r, size := utf8.DecodeLastRune(b) + fmt.Println("%c %v\n", r, size) - b = b[:len(b)-size] - } - - // Output: - // 界 3 - // 世 3 - // 1 - // , 1 - // o 1 - // l 1 - // l 1 - // e 1 - // H 1 + b = b[:len(b)-size] + } + + // Output: + // 界 3 + // 世 3 + // 1 + // , 1 + // o 1 + // l 1 + // l 1 + // e 1 + // H 1 } func main() { ExampleDecodeLastRune() - fmt.Println(utf8.RuneError, "a \n b👌") - s := "\\ \n \\" - fmt.Println(s[0], len(s), s) + fmt.Println(utf8.RuneError, "a \n b👌") + s := "\\ \n \\" + fmt.Println(s[0], len(s), s) } \ No newline at end of file diff --git a/parser/src/ast.rs b/parser/src/ast.rs index 04dca8f8..b8359688 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -860,10 +860,10 @@ pub struct BadDecl { // // Relationship between Tok value and Specs element type: // -// Token::IMPORT ImportSpec -// Token::CONST ValueSpec -// Token::TYPE TypeSpec -// Token::VAR ValueSpec +// Token::IMPORT ImportSpec +// Token::CONST ValueSpec +// Token::TYPE TypeSpec +// Token::VAR ValueSpec #[derive(Debug)] pub struct GenDecl { pub token_pos: position::Pos, diff --git a/parser/src/parser.rs b/parser/src/parser.rs index ba17215c..741de647 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -174,7 +174,7 @@ impl<'a> Parser<'a> { unreachable!(); }; let list = &ass_stmt!(self, assign).lhs; - let mut n = 0; // number of new variables + let mut n = 0; // number of new variables for expr in list { match expr { Expr::Ident(id) => { @@ -597,7 +597,7 @@ impl<'a> Parser<'a> { self.trace_begin("FieldDecl"); // 1st FieldDecl - // A type name used as an anonymous field looks like a field identifier. + // A type name used as an anonymous field looks like a field identifier. let mut list = vec![]; loop { list.push(self.parse_var_type(false)); @@ -726,7 +726,7 @@ impl<'a> Parser<'a> { self.trace_begin("ParameterList"); // 1st ParameterDecl - // A list of identifiers looks like a list of type names. + // A list of identifiers looks like a list of type names. let mut list = vec![]; loop { list.push(self.parse_var_type(ellipsis_ok)); @@ -747,8 +747,8 @@ impl<'a> Parser<'a> { let field = new_field!(self, idents, t, None); params.push(field); // Go spec: The scope of an identifier denoting a function - // parameter or result variable is the function body. - self.declare(DeclObj::Field(field), EntityData::NoData, + // parameter or result variable is the function body. + self.declare(DeclObj::Field(field), EntityData::NoData, EntityKind::Var, &scope); if let Some(ident) = to_resolve { self.resolve(&ident); @@ -1967,7 +1967,7 @@ impl<'a> Parser<'a> { // to the variable declared in the initial SimpleStmt. // Introduce extra scope to avoid redeclaration errors: // - // switch t := 0; t := x.(T) { ... } + // switch t := 0; t := x.(T) { ... } // // (this code is not valid Go because the first t // cannot be accessed and thus is never used, the extra @@ -2021,7 +2021,7 @@ impl<'a> Parser<'a> { // SendStmt if lhs.len() > 1 { self.error_expected(lhs[0].pos(&self.objects), "1 expression"); - // continue with first expression + // continue with first expression } let arrow = self.pos; self.next(); @@ -2150,7 +2150,7 @@ impl<'a> Parser<'a> { } }; // parseSimpleStmt returned a right-hand side that - // is a single unary expression of the form "range x" + // is a single unary expression of the form "range x" if let Expr::Unary(unary) = ass.rhs.remove(0) { Stmt::Range(Rc::new(RangeStmt{ for_pos: pos, @@ -2190,9 +2190,9 @@ impl<'a> Parser<'a> { Stmt::Decl(Rc::new(self.parse_decl(Token::is_stmt_start))), Token::IDENT(_) | Token::INT(_) | Token::FLOAT(_) | Token::IMAG(_) | Token::CHAR(_) | Token::STRING(_) | Token::FUNC | Token::LPAREN | // operands - Token::LBRACK | Token::STRUCT | + Token::LBRACK | Token::STRUCT | Token::MAP | Token::CHAN | Token::INTERFACE | // composite types - Token::ADD | Token::SUB | Token::MUL | Token::AND | + Token::ADD | Token::SUB | Token::MUL | Token::AND | Token::XOR | Token::ARROW | Token::NOT => { // unary operators let s = self.parse_simple_stmt(ParseSimpleMode::LabelOk).0; if let Stmt::Labeled(_) = s {} else {self.expect_semi();} @@ -2326,9 +2326,9 @@ impl<'a> Parser<'a> { } // Go spec: The scope of a constant or variable identifier declared inside - // a function begins at the end of the ConstSpec or VarSpec and ends at - // the end of the innermost containing block. - // (Global identifiers are resolved in a separate phase after parsing.) + // a function begins at the end of the ConstSpec or VarSpec and ends at + // the end of the innermost containing block. + // (Global identifiers are resolved in a separate phase after parsing.) let spec = specs_mut!(self_).insert(Spec::Value(Rc::new(ValueSpec{ names: idents, typ: typ, values: values}))); let kind = if let Token::VAR = keyword { @@ -2349,9 +2349,9 @@ impl<'a> Parser<'a> { let ident = self.parse_ident(); // Go spec: The scope of a type identifier declared inside a function begins - // at the identifier in the TypeSpec and ends at the end of the innermost - // containing block. - // (Global identifiers are resolved in a separate phase after parsing.) + // at the identifier in the TypeSpec and ends at the end of the innermost + // containing block. + // (Global identifiers are resolved in a separate phase after parsing.) let placeholder = Expr::new_bad(0, 0); let spec_val = Spec::Type(Rc::new(TypeSpec{ name: ident, assign: 0, typ: placeholder @@ -2497,7 +2497,7 @@ impl<'a> Parser<'a> { let err_count = self.errors.len(); let pos = self.expect(&Token::PACKAGE); // Go spec: The package clause is not a declaration; - // the package name does not appear in any scope. + // the package name does not appear in any scope. let ident = self.parse_ident(); if ident!(self, ident).name == "_" { self.error_str(self.pos, "invalid package name _"); @@ -2505,8 +2505,8 @@ impl<'a> Parser<'a> { self.expect_semi(); // Don't bother parsing the rest if we had errors parsing the package clause. - // Likely not a Go source file at all. - if self.errors.len() > err_count { + // Likely not a Go source file at all. + if self.errors.len() > err_count { self.trace_end(); return None } @@ -2555,10 +2555,10 @@ impl<'a> Parser<'a> { #[cfg(test)] mod test { - use super::*; + use super::*; - #[test] - fn test_parser () { + #[test] + fn test_parser () { let mut fs = position::FileSet::new(); let f = fs.add_file("testfile1.gs".to_string(), None, 1000); diff --git a/types/src/check/decl.rs b/types/src/check/decl.rs index 30ed753e..17f4d4f6 100644 --- a/types/src/check/decl.rs +++ b/types/src/check/decl.rs @@ -416,11 +416,11 @@ impl<'a> Checker<'a> { // The underlying type of named may be itself a named type that is // incomplete: // - // type ( - // A B - // B *C - // C A - // ) + // type ( + // A B + // B *C + // C A + // ) // // The type of C is the (named) type of A which is incomplete, // and which has as its underlying type the named type B. diff --git a/types/src/lookup.rs b/types/src/lookup.rs index 8e1edd9f..119548b0 100644 --- a/types/src/lookup.rs +++ b/types/src/lookup.rs @@ -200,9 +200,9 @@ impl MethodSet { /// The last index entry is the field or method index in the (possibly embedded) /// type where the entry was found, either: /// -/// 1) the list of declared methods of a named type; or -/// 2) the list of all methods (method set) of an interface type; or -/// 3) the list of fields of a struct type. +/// 1) the list of declared methods of a named type; or +/// 2) the list of all methods (method set) of an interface type; or +/// 3) the list of fields of a struct type. /// /// The earlier index entries are the indices of the embedded struct fields /// traversed to get to the found entry, starting at depth 0. diff --git a/types/src/selection.rs b/types/src/selection.rs index 00454211..65bd7386 100644 --- a/types/src/selection.rs +++ b/types/src/selection.rs @@ -16,18 +16,18 @@ pub enum SelectionKind { /// A Selection describes a selector expression x.f. /// For the declarations: /// -/// type T struct{ x int; E } -/// type E struct{} -/// func (e E) m() {} -/// var p *T +/// type T struct{ x int; E } +/// type E struct{} +/// func (e E) m() {} +/// var p *T /// /// the following relations exist: /// -/// Selector Kind Recv Obj Type Index Indirect +/// Selector Kind Recv Obj Type Index Indirect /// -/// p.x FieldVal T x int {0} true -/// p.m MethodVal *T m func (e *T) m() {1, 0} true -/// T.m MethodExpr T m func m(_ T) {1, 0} false +/// p.x FieldVal T x int {0} true +/// p.m MethodVal *T m func (e *T) m() {1, 0} true +/// T.m MethodExpr T m func m(_ T) {1, 0} false /// #[derive(Clone, Debug)] pub struct Selection { @@ -89,9 +89,9 @@ impl Selection { /// The last indices entry is the field or method indices of the type declaring f; /// either: /// - /// 1) the list of declared methods of a named type; or - /// 2) the list of methods of an interface type; or - /// 3) the list of fields of a struct type. + /// 1) the list of declared methods of a named type; or + /// 2) the list of methods of an interface type; or + /// 3) the list of fields of a struct type. /// /// The earlier indices entries are the indices of the embedded fields implicitly /// traversed to get from (the type of) x to f, starting at embedding depth 0. diff --git a/types/tests/data/builtins.gos b/types/tests/data/builtins.gos index 55b1d99d..0b34c542 100644 --- a/types/tests/data/builtins.gos +++ b/types/tests/data/builtins.gos @@ -449,7 +449,7 @@ func make1() { _ = make([]int, 10 /* ERROR length and capacity swapped */ , 9) _ = make([]int, 1 /* ERROR overflows */ <<100, 12345) _ = make([]int, m /* ERROR must be integer */ ) - _ = &make /* ERROR cannot take address */ ([]int, 0) + _ = &make /* ERROR cannot take address */ ([]int, 0) // maps _ = make /* ERROR arguments */ (map[int]string, 10, 20) @@ -460,7 +460,7 @@ func make1() { _ = make(map[int]float32, int64(n)) _ = make(map[string]bool, 10.0) _ = make(map[string]bool, 10.0<