~ubuntu-branches/ubuntu/utopic/golang/utopic

« back to all changes in this revision

Viewing changes to src/cmd/fix/netdial.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
        "go/ast"
9
 
)
10
 
 
11
 
func init() {
12
 
        register(netdialFix)
13
 
        register(tlsdialFix)
14
 
        register(netlookupFix)
15
 
}
16
 
 
17
 
var netdialFix = fix{
18
 
        "netdial",
19
 
        "2011-03-28",
20
 
        netdial,
21
 
        `Adapt 3-argument calls of net.Dial to use 2-argument form.
22
 
 
23
 
http://codereview.appspot.com/4244055
24
 
`,
25
 
}
26
 
 
27
 
var tlsdialFix = fix{
28
 
        "tlsdial",
29
 
        "2011-03-28",
30
 
        tlsdial,
31
 
        `Adapt 4-argument calls of tls.Dial to use 3-argument form.
32
 
 
33
 
http://codereview.appspot.com/4244055
34
 
`,
35
 
}
36
 
 
37
 
var netlookupFix = fix{
38
 
        "netlookup",
39
 
        "2011-03-28",
40
 
        netlookup,
41
 
        `Adapt 3-result calls to net.LookupHost to use 2-result form.
42
 
 
43
 
http://codereview.appspot.com/4244055
44
 
`,
45
 
}
46
 
 
47
 
func netdial(f *ast.File) bool {
48
 
        if !imports(f, "net") {
49
 
                return false
50
 
        }
51
 
 
52
 
        fixed := false
53
 
        walk(f, func(n interface{}) {
54
 
                call, ok := n.(*ast.CallExpr)
55
 
                if !ok || !isPkgDot(call.Fun, "net", "Dial") || len(call.Args) != 3 {
56
 
                        return
57
 
                }
58
 
                // net.Dial(a, "", b) -> net.Dial(a, b)
59
 
                if !isEmptyString(call.Args[1]) {
60
 
                        warn(call.Pos(), "call to net.Dial with non-empty second argument")
61
 
                        return
62
 
                }
63
 
                call.Args[1] = call.Args[2]
64
 
                call.Args = call.Args[:2]
65
 
                fixed = true
66
 
        })
67
 
        return fixed
68
 
}
69
 
 
70
 
func tlsdial(f *ast.File) bool {
71
 
        if !imports(f, "crypto/tls") {
72
 
                return false
73
 
        }
74
 
 
75
 
        fixed := false
76
 
        walk(f, func(n interface{}) {
77
 
                call, ok := n.(*ast.CallExpr)
78
 
                if !ok || !isPkgDot(call.Fun, "tls", "Dial") || len(call.Args) != 4 {
79
 
                        return
80
 
                }
81
 
                // tls.Dial(a, "", b, c) -> tls.Dial(a, b, c)
82
 
                if !isEmptyString(call.Args[1]) {
83
 
                        warn(call.Pos(), "call to tls.Dial with non-empty second argument")
84
 
                        return
85
 
                }
86
 
                call.Args[1] = call.Args[2]
87
 
                call.Args[2] = call.Args[3]
88
 
                call.Args = call.Args[:3]
89
 
                fixed = true
90
 
        })
91
 
        return fixed
92
 
}
93
 
 
94
 
func netlookup(f *ast.File) bool {
95
 
        if !imports(f, "net") {
96
 
                return false
97
 
        }
98
 
 
99
 
        fixed := false
100
 
        walk(f, func(n interface{}) {
101
 
                as, ok := n.(*ast.AssignStmt)
102
 
                if !ok || len(as.Lhs) != 3 || len(as.Rhs) != 1 {
103
 
                        return
104
 
                }
105
 
                call, ok := as.Rhs[0].(*ast.CallExpr)
106
 
                if !ok || !isPkgDot(call.Fun, "net", "LookupHost") {
107
 
                        return
108
 
                }
109
 
                if !isBlank(as.Lhs[2]) {
110
 
                        warn(as.Pos(), "call to net.LookupHost expecting cname; use net.LookupCNAME")
111
 
                        return
112
 
                }
113
 
                as.Lhs = as.Lhs[:2]
114
 
                fixed = true
115
 
        })
116
 
        return fixed
117
 
}