~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/fix/netudpgroup.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(netudpgroupFix)
13
 
}
14
 
 
15
 
var netudpgroupFix = fix{
16
 
        "netudpgroup",
17
 
        "2011-08-18",
18
 
        netudpgroup,
19
 
        `Adapt 1-argument calls of net.(*UDPConn).JoinGroup, LeaveGroup to use 2-argument form.
20
 
 
21
 
http://codereview.appspot.com/4815074
22
 
`,
23
 
}
24
 
 
25
 
func netudpgroup(f *ast.File) bool {
26
 
        if !imports(f, "net") {
27
 
                return false
28
 
        }
29
 
 
30
 
        fixed := false
31
 
        for _, d := range f.Decls {
32
 
                fd, ok := d.(*ast.FuncDecl)
33
 
                if !ok || fd.Body == nil {
34
 
                        continue
35
 
                }
36
 
                walk(fd.Body, func(n interface{}) {
37
 
                        ce, ok := n.(*ast.CallExpr)
38
 
                        if !ok {
39
 
                                return
40
 
                        }
41
 
                        se, ok := ce.Fun.(*ast.SelectorExpr)
42
 
                        if !ok || len(ce.Args) != 1 {
43
 
                                return
44
 
                        }
45
 
                        switch se.Sel.String() {
46
 
                        case "JoinGroup", "LeaveGroup":
47
 
                                // c.JoinGroup(a) -> c.JoinGroup(nil, a)
48
 
                                // c.LeaveGroup(a) -> c.LeaveGroup(nil, a)
49
 
                                arg := ce.Args[0]
50
 
                                ce.Args = make([]ast.Expr, 2)
51
 
                                ce.Args[0] = ast.NewIdent("nil")
52
 
                                ce.Args[1] = arg
53
 
                                fixed = true
54
 
                        }
55
 
                })
56
 
        }
57
 
        return fixed
58
 
}