diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-03-08 18:48:26 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-03-08 18:48:26 +0100 |
| commit | 36d1c4540af3ef058d68092e41af05aa4a8c5eca (patch) | |
| tree | 3657a5920e4b100749ccb9d2d555652e7b7e28e9 /pkg/compiler | |
| parent | 63ef857906766b3cafe4aebc43bc38edf42096c3 (diff) | |
all: fix gometalinter warnings
Fix typos, non-canonical code, remove dead code, etc.
Diffstat (limited to 'pkg/compiler')
| -rw-r--r-- | pkg/compiler/check.go | 20 | ||||
| -rw-r--r-- | pkg/compiler/compiler.go | 2 | ||||
| -rw-r--r-- | pkg/compiler/types.go | 28 |
3 files changed, 26 insertions, 24 deletions
diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index 4dac37260..6d304d26b 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -578,11 +578,11 @@ func (comp *compiler) checkStruct(ctx checkCtx, n *ast.Struct) { type checkFlags int const ( - checkIsArg checkFlags = 1 << iota // immidiate syscall arg type - checkIsRet // immidiate syscall ret type - checkIsStruct // immidiate struct field type - checkIsResourceBase // immidiate resource base type - checkIsTypedef // immidiate type alias/template type + checkIsArg checkFlags = 1 << iota // immediate syscall arg type + checkIsRet // immediate syscall ret type + checkIsStruct // immediate struct field type + checkIsResourceBase // immediate resource base type + checkIsTypedef // immediate type alias/template type ) type checkCtx struct { @@ -603,7 +603,7 @@ func (comp *compiler) checkType(ctx checkCtx, t *ast.Type, flags checkFlags) { err0 := comp.errors // Replace t with type alias/template target type inplace, // and check the replaced type recursively. - comp.replaceTypedef(&ctx, t, desc, flags) + comp.replaceTypedef(&ctx, t, flags) if err0 == comp.errors { comp.checkType(ctx, t, flags) } @@ -682,7 +682,7 @@ func (comp *compiler) checkType(ctx checkCtx, t *ast.Type, flags checkFlags) { } } -func (comp *compiler) replaceTypedef(ctx *checkCtx, t *ast.Type, desc *typeDesc, flags checkFlags) { +func (comp *compiler) replaceTypedef(ctx *checkCtx, t *ast.Type, flags checkFlags) { typedefName := t.Ident if t.HasColon { comp.error(t.Pos, "type alias %v with ':'", t.Ident) @@ -740,7 +740,7 @@ func (comp *compiler) replaceTypedef(ctx *checkCtx, t *ast.Type, desc *typeDesc, t.Pos = pos0 // Remove base type if it's not needed in this context. - desc = comp.getTypeDesc(t) + desc := comp.getTypeDesc(t) if flags&checkIsArg != 0 && desc.NeedBase { baseTypePos := len(t.Args) - 1 if t.Args[baseTypePos].Ident == "opt" { @@ -938,7 +938,9 @@ func (comp *compiler) checkDupConsts() { // The second one is meant to be const[BAR], // Unfortunately, this does not fully work as it detects lots of false positives. // But was useful to find real bugs as well. So for now it's disabled, but can be run manually. - return + if true { + return + } dups := make(map[string]map[string]dupConstArg) for _, decl := range comp.desc.Nodes { switch n := decl.(type) { diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index f0d1176e7..f1e39b269 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -27,7 +27,7 @@ import ( // 4.1. assignSyscallNumbers: uses consts to assign syscall numbers. // This step also detects unsupported syscalls and discards no longer // needed AST nodes (inlcude, define, comments, etc). -// 4.2. patchConsts: patches Int nodes refering to consts with corresponding values. +// 4.2. patchConsts: patches Int nodes referring to consts with corresponding values. // Also detects unsupported syscalls, structs, resources due to missing consts. // 4.3. check: does extensive semantical checks of AST. // 4.4. gen: generates prog objects from AST. diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index f5ec1221e..019b734dd 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -267,10 +267,7 @@ var typeFilename = &typeDesc{ OptArgs: 1, Args: []namedArg{{"size", typeArgInt}}, Varlen: func(comp *compiler, t *ast.Type, args []*ast.Type) bool { - if len(args) >= 1 { - return false - } - return true + return len(args) == 0 }, Gen: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) prog.Type { base.TypeSize = 0 @@ -448,13 +445,17 @@ var typeBuffer = &typeDesc{ }, } +const ( + stringnoz = "stringnoz" +) + var typeString = &typeDesc{ - Names: []string{"string", "stringnoz"}, + Names: []string{"string", stringnoz}, CanBeTypedef: true, OptArgs: 2, Args: []namedArg{{"literal or flags", typeArgStringFlags}, {"size", typeArgInt}}, Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) { - if t.Ident == "stringnoz" && len(args) > 1 { + if t.Ident == stringnoz && len(args) > 1 { comp.error(args[0].Pos, "fixed-size string can't be non-zero-terminated") } }, @@ -491,7 +492,7 @@ var typeString = &typeDesc{ Kind: prog.BufferString, SubKind: subkind, Values: vals, - NoZ: t.Ident == "stringnoz", + NoZ: t.Ident == stringnoz, } }, } @@ -505,7 +506,7 @@ func (comp *compiler) genStrings(t *ast.Type, args []*ast.Type) []string { vals = genStrArray(comp.strFlags[args[0].Ident].Values) } } - if t.Ident == "stringnoz" { + if t.Ident == stringnoz { return vals } var size uint64 @@ -645,12 +646,11 @@ func init() { FldName: base.FldName, StructDesc: desc, } - } else { - return &prog.StructType{ - Key: key, - FldName: base.FldName, - StructDesc: desc, - } + } + return &prog.StructType{ + Key: key, + FldName: base.FldName, + StructDesc: desc, } } } |
