OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 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 "go/ast" | 7 import "go/ast" |
8 | 8 |
9 func init() { | 9 func init() { |
10 register(mapdeleteFix) | 10 register(mapdeleteFix) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 if !canDrop(as.Rhs[0]) { | 42 if !canDrop(as.Rhs[0]) { |
43 warn(as.Pos(), "two-element map assignment with non-triv
ial first value") | 43 warn(as.Pos(), "two-element map assignment with non-triv
ial first value") |
44 return | 44 return |
45 } | 45 } |
46 *stmt = &ast.ExprStmt{ | 46 *stmt = &ast.ExprStmt{ |
47 X: &ast.CallExpr{ | 47 X: &ast.CallExpr{ |
48 Fun: &ast.Ident{ | 48 Fun: &ast.Ident{ |
49 NamePos: as.Pos(), | 49 NamePos: as.Pos(), |
50 Name: "delete", | 50 Name: "delete", |
51 }, | 51 }, |
52 » » » » Args: []ast.Expr{ix.X, ix.Index}, | 52 » » » » Args: {ix.X, ix.Index}, |
53 }, | 53 }, |
54 } | 54 } |
55 fixed = true | 55 fixed = true |
56 }) | 56 }) |
57 return fixed | 57 return fixed |
58 } | 58 } |
59 | 59 |
60 // canDrop reports whether it is safe to drop the | 60 // canDrop reports whether it is safe to drop the |
61 // evaluation of n from the program. | 61 // evaluation of n from the program. |
62 // It is very conservative. | 62 // It is very conservative. |
(...skipping 17 matching lines...) Expand all Loading... |
80 return true | 80 return true |
81 case *ast.StarExpr: | 81 case *ast.StarExpr: |
82 // Dropping *x is questionable, | 82 // Dropping *x is questionable, |
83 // but we have to be able to drop (*T)(nil). | 83 // but we have to be able to drop (*T)(nil). |
84 return canDrop(n.X) | 84 return canDrop(n.X) |
85 case *ast.ArrayType, *ast.ChanType, *ast.FuncType, *ast.InterfaceType, *
ast.MapType, *ast.StructType: | 85 case *ast.ArrayType, *ast.ChanType, *ast.FuncType, *ast.InterfaceType, *
ast.MapType, *ast.StructType: |
86 return true | 86 return true |
87 } | 87 } |
88 return false | 88 return false |
89 } | 89 } |
OLD | NEW |