From 88fe73df46bade2cedd73c22c3007a8c26772342 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 6 Dec 2017 02:11:56 +0300 Subject: [PATCH] Added code simplification to gofmt (#408) --- ast/position_test.go | 24 ++++++++++++------------ cli_test.go | 8 ++++---- program/program.go | 6 +++--- transpiler/declarations.go | 8 ++++---- transpiler/enum.go | 2 +- transpiler/transpiler.go | 2 +- transpiler/variables.go | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ast/position_test.go b/ast/position_test.go index aa4461bfb..26f21f6e2 100644 --- a/ast/position_test.go +++ b/ast/position_test.go @@ -6,84 +6,84 @@ import ( func TestNewPositionFromString(t *testing.T) { tests := map[string]Position{ - `col:30`: Position{ + `col:30`: { File: "", Line: 0, Column: 30, LineEnd: 0, ColumnEnd: 0, }, - `col:47, col:57`: Position{ + `col:47, col:57`: { File: "", Line: 0, Column: 47, LineEnd: 0, ColumnEnd: 57, }, - `/usr/include/sys/cdefs.h:313:68`: Position{ + `/usr/include/sys/cdefs.h:313:68`: { File: "/usr/include/sys/cdefs.h", Line: 313, Column: 68, LineEnd: 0, ColumnEnd: 0, }, - `/usr/include/AvailabilityInternal.h:21697:88, col:124`: Position{ + `/usr/include/AvailabilityInternal.h:21697:88, col:124`: { File: "/usr/include/AvailabilityInternal.h", Line: 21697, Column: 88, LineEnd: 0, ColumnEnd: 124, }, - `line:275:50, col:99`: Position{ + `line:275:50, col:99`: { File: "", Line: 275, Column: 50, LineEnd: 0, ColumnEnd: 99, }, - `line:11:5, line:12:21`: Position{ + `line:11:5, line:12:21`: { File: "", Line: 11, Column: 5, LineEnd: 12, ColumnEnd: 21, }, - `col:54, line:358:1`: Position{ + `col:54, line:358:1`: { File: "", Line: 0, Column: 54, LineEnd: 358, ColumnEnd: 1, }, - `/usr/include/secure/_stdio.h:42:1, line:43:32`: Position{ + `/usr/include/secure/_stdio.h:42:1, line:43:32`: { File: "/usr/include/secure/_stdio.h", Line: 42, Column: 1, LineEnd: 43, ColumnEnd: 32, }, - `line:244:5`: Position{ + `line:244:5`: { File: "", Line: 244, Column: 5, LineEnd: 0, ColumnEnd: 0, }, - ``: Position{ + ``: { File: "", Line: 0, Column: 0, LineEnd: 0, ColumnEnd: 0, }, - `/usr/include/sys/stdio.h:39:1, /usr/include/AvailabilityInternal.h:21697:126`: Position{ + `/usr/include/sys/stdio.h:39:1, /usr/include/AvailabilityInternal.h:21697:126`: { File: "/usr/include/sys/stdio.h", Line: 39, Column: 1, LineEnd: 0, ColumnEnd: 0, }, - `col:1, /usr/include/sys/cdefs.h:351:63`: Position{ + `col:1, /usr/include/sys/cdefs.h:351:63`: { File: "", Line: 0, Column: 1, diff --git a/cli_test.go b/cli_test.go index d527ed867..28a693c13 100644 --- a/cli_test.go +++ b/cli_test.go @@ -24,16 +24,16 @@ func setupTest(args []string) (*bytes.Buffer, func()) { var cliTests = map[string][]string{ // Test that help is printed if no files are given - "TranspileNoFilesHelp": []string{"test", "transpile"}, + "TranspileNoFilesHelp": {"test", "transpile"}, // Test that help is printed if help flag is set, even if file is given - "TranspileHelpFlag": []string{"test", "transpile", "-h", "foo.c"}, + "TranspileHelpFlag": {"test", "transpile", "-h", "foo.c"}, // Test that help is printed if no files are given - "AstNoFilesHelp": []string{"test", "ast"}, + "AstNoFilesHelp": {"test", "ast"}, // Test that help is printed if help flag is set, even if file is given - "AstHelpFlag": []string{"test", "ast", "-h", "foo.c"}, + "AstHelpFlag": {"test", "ast", "-h", "foo.c"}, } func TestCLI(t *testing.T) { diff --git a/program/program.go b/program/program.go index 17d93b060..c2a0437ce 100644 --- a/program/program.go +++ b/program/program.go @@ -96,19 +96,19 @@ func NewProgram() *Program { // Example node for adding: // &ast.TypedefDecl{ ... Type:"struct __locale_struct *" ... } - "struct __va_list_tag [1]": &Struct{ + "struct __va_list_tag [1]": { Name: "struct __va_list_tag [1]", IsUnion: false, }, // Pos:ast.Position{File:"/usr/include/xlocale.h", Line:27 - "struct __locale_struct *": &Struct{ + "struct __locale_struct *": { Name: "struct __locale_struct *", IsUnion: false, }, // Pos:ast.Position{File:"/usr/include/x86_64-linux-gnu/sys/time.h", Line:61 - "struct timezone *__restrict": &Struct{ + "struct timezone *__restrict": { Name: "struct timezone *__restrict", IsUnion: false, }, diff --git a/transpiler/declarations.go b/transpiler/declarations.go index 7367be1a2..012ff6b3a 100644 --- a/transpiler/declarations.go +++ b/transpiler/declarations.go @@ -282,7 +282,7 @@ func transpileVarDecl(p *program.Program, n *ast.VarDecl) (decls []goast.Decl, t return []goast.Decl{&goast.GenDecl{ Tok: token.VAR, Specs: []goast.Spec{&goast.ValueSpec{ - Names: []*goast.Ident{&goast.Ident{Name: name}}, + Names: []*goast.Ident{{Name: name}}, Type: util.NewTypeIdent(theType), }}, }}, "", nil @@ -303,7 +303,7 @@ func transpileVarDecl(p *program.Program, n *ast.VarDecl) (decls []goast.Decl, t return []goast.Decl{&goast.GenDecl{ Tok: token.VAR, Specs: []goast.Spec{&goast.ValueSpec{ - Names: []*goast.Ident{&goast.Ident{Name: name}}, + Names: []*goast.Ident{{Name: name}}, Type: util.NewTypeIdent(theType), }}, }}, "", nil @@ -350,7 +350,7 @@ func transpileVarDecl(p *program.Program, n *ast.VarDecl) (decls []goast.Decl, t return []goast.Decl{&goast.GenDecl{ Tok: token.VAR, Specs: []goast.Spec{&goast.ValueSpec{ - Names: []*goast.Ident{&goast.Ident{Name: nameVar1}}, + Names: []*goast.Ident{{Name: nameVar1}}, Type: functionType, Values: []goast.Expr{&goast.TypeAssertExpr{ X: &goast.Ident{Name: nameVar2}, @@ -378,7 +378,7 @@ func transpileVarDecl(p *program.Program, n *ast.VarDecl) (decls []goast.Decl, t decls = append(decls, &goast.GenDecl{ Tok: token.VAR, Specs: []goast.Spec{&goast.ValueSpec{ - Names: []*goast.Ident{&goast.Ident{Name: nameVar1}}, + Names: []*goast.Ident{{Name: nameVar1}}, Type: functionType, }, }}) diff --git a/transpiler/enum.go b/transpiler/enum.go index 07c39858b..cbb497c39 100644 --- a/transpiler/enum.go +++ b/transpiler/enum.go @@ -132,7 +132,7 @@ func transpileEnumDecl(p *program.Program, n *ast.EnumDecl) (decls []goast.Decl, switch v := val.Values[0].(type) { case *goast.Ident: e = &goast.ValueSpec{ - Names: []*goast.Ident{&goast.Ident{Name: c.Name}}, + Names: []*goast.Ident{{Name: c.Name}}, Values: []goast.Expr{&goast.BasicLit{Kind: token.INT, Value: strconv.Itoa(counter)}}, Type: val.Type, } diff --git a/transpiler/transpiler.go b/transpiler/transpiler.go index 777b2ae20..e487bfae5 100644 --- a/transpiler/transpiler.go +++ b/transpiler/transpiler.go @@ -48,7 +48,7 @@ func TranspileAST(fileName, packageName string, p *program.Program, root ast.Nod Type: &goast.FuncType{ Params: &goast.FieldList{ List: []*goast.Field{ - &goast.Field{ + { Names: []*goast.Ident{util.NewIdent("t")}, Type: util.NewTypeIdent("*testing.T"), }, diff --git a/transpiler/variables.go b/transpiler/variables.go index d2755bcc6..65fcc142e 100644 --- a/transpiler/variables.go +++ b/transpiler/variables.go @@ -96,7 +96,7 @@ func newDeclStmt(a *ast.VarDecl, p *program.Program) ( return &goast.DeclStmt{Decl: &goast.GenDecl{ Tok: token.VAR, Specs: []goast.Spec{&goast.ValueSpec{ - Names: []*goast.Ident{&goast.Ident{Name: nameVar1}}, + Names: []*goast.Ident{{Name: nameVar1}}, Type: functionType, Values: []goast.Expr{&goast.TypeAssertExpr{ X: &goast.Ident{Name: nameVar2},