OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 The Go Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style |
| 3 // license that can be found in the LICENSE file. |
| 4 |
| 5 package main |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 "os" |
| 10 "go/ast" |
| 11 ) |
| 12 |
| 13 var _ fmt.Stringer |
| 14 var _ os.Error |
| 15 |
| 16 var mathFix = fix{ |
| 17 "math", |
| 18 math, |
| 19 `Remove the leading F from math functions such as Fabs. |
| 20 |
| 21 http://codereview.appspot.com/5158043 |
| 22 `, |
| 23 } |
| 24 |
| 25 func init() { |
| 26 register(mathFix) |
| 27 } |
| 28 |
| 29 var mathRenames = []struct{ in, out string }{ |
| 30 {"Fabs", "Abs"}, |
| 31 {"Fdim", "Dim"}, |
| 32 {"Fmax", "Max"}, |
| 33 {"Fmin", "Min"}, |
| 34 {"Fmod", "Mod"}, |
| 35 } |
| 36 |
| 37 func math(f *ast.File) bool { |
| 38 if !imports(f, "math") { |
| 39 return false |
| 40 } |
| 41 |
| 42 fixed := false |
| 43 |
| 44 walk(f, func(n interface{}) { |
| 45 // Rename functions. |
| 46 if expr, ok := n.(ast.Expr); ok { |
| 47 for _, s := range mathRenames { |
| 48 if isPkgDot(expr, "math", s.in) { |
| 49 expr.(*ast.SelectorExpr).Sel.Name = s.ou
t |
| 50 fixed = true |
| 51 return |
| 52 } |
| 53 } |
| 54 } |
| 55 }) |
| 56 return fixed |
| 57 } |
OLD | NEW |