Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(770)

Side by Side Diff: cmd/vet/atomic.go

Issue 106510044: go.tools/cmd/vet: enable file level checker short-circuiting (Closed)
Patch Set: diff -r 0f0740bbe48a https://code.google.com/p/go.tools Created 9 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cmd/vet/assign.go ('k') | cmd/vet/bool.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Go Authors. All rights reserved. 1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "go/ast" 8 "go/ast"
9 "go/token" 9 "go/token"
10 ) 10 )
11 11
12 func init() { 12 func init() {
13 register("atomic", 13 register("atomic",
14 "check for common mistaken usages of the sync/atomic package", 14 "check for common mistaken usages of the sync/atomic package",
15 filterAtomicAssignment,
15 checkAtomicAssignment, 16 checkAtomicAssignment,
16 assignStmt) 17 assignStmt)
17 } 18 }
18 19
20 func filterAtomicAssignment(f *File) bool { return f.imports(`"sync/atomic"`) }
21
19 // checkAtomicAssignment walks the assignment statement checking for common 22 // checkAtomicAssignment walks the assignment statement checking for common
20 // mistaken usage of atomic package, such as: x = atomic.AddUint64(&x, 1) 23 // mistaken usage of atomic package, such as: x = atomic.AddUint64(&x, 1)
21 func checkAtomicAssignment(f *File, node ast.Node) { 24 func checkAtomicAssignment(f *File, node ast.Node) {
22 n := node.(*ast.AssignStmt) 25 n := node.(*ast.AssignStmt)
23 if len(n.Lhs) != len(n.Rhs) { 26 if len(n.Lhs) != len(n.Rhs) {
24 return 27 return
25 } 28 }
26 29
27 for i, right := range n.Rhs { 30 for i, right := range n.Rhs {
28 call, ok := right.(*ast.CallExpr) 31 call, ok := right.(*ast.CallExpr)
(...skipping 28 matching lines...) Expand all
57 if uarg, ok := arg.(*ast.UnaryExpr); ok && uarg.Op == token.AND { 60 if uarg, ok := arg.(*ast.UnaryExpr); ok && uarg.Op == token.AND {
58 broken = f.gofmt(left) == f.gofmt(uarg.X) 61 broken = f.gofmt(left) == f.gofmt(uarg.X)
59 } else if star, ok := left.(*ast.StarExpr); ok { 62 } else if star, ok := left.(*ast.StarExpr); ok {
60 broken = f.gofmt(star.X) == f.gofmt(arg) 63 broken = f.gofmt(star.X) == f.gofmt(arg)
61 } 64 }
62 65
63 if broken { 66 if broken {
64 f.Bad(left.Pos(), "direct assignment to atomic value") 67 f.Bad(left.Pos(), "direct assignment to atomic value")
65 } 68 }
66 } 69 }
OLDNEW
« no previous file with comments | « cmd/vet/assign.go ('k') | cmd/vet/bool.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b