LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 "fmt" | 8 "fmt" |
9 "go/ast" | 9 "go/ast" |
10 "go/parser" | 10 "go/parser" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // use new position only if old position was valid in the first
place | 225 // use new position only if old position was valid in the first
place |
226 if old := pattern.Interface().(token.Pos); !old.IsValid() { | 226 if old := pattern.Interface().(token.Pos); !old.IsValid() { |
227 return pattern | 227 return pattern |
228 } | 228 } |
229 return pos | 229 return pos |
230 } | 230 } |
231 | 231 |
232 // Otherwise copy. | 232 // Otherwise copy. |
233 switch p := pattern.(type) { | 233 switch p := pattern.(type) { |
234 case *reflect.SliceValue: | 234 case *reflect.SliceValue: |
235 » » v := reflect.MakeSlice(p.Type().(*reflect.SliceType), p.Len(), p
.Len()) | 235 » » v := reflect.MakeSlice(p.Type(), p.Len(), p.Len()) |
236 for i := 0; i < p.Len(); i++ { | 236 for i := 0; i < p.Len(); i++ { |
237 v.Elem(i).SetValue(subst(m, p.Elem(i), pos)) | 237 v.Elem(i).SetValue(subst(m, p.Elem(i), pos)) |
238 } | 238 } |
239 return v | 239 return v |
240 | 240 |
241 case *reflect.StructValue: | 241 case *reflect.StructValue: |
242 v := reflect.MakeZero(p.Type()).(*reflect.StructValue) | 242 v := reflect.MakeZero(p.Type()).(*reflect.StructValue) |
243 for i := 0; i < p.NumField(); i++ { | 243 for i := 0; i < p.NumField(); i++ { |
244 v.Field(i).SetValue(subst(m, p.Field(i), pos)) | 244 v.Field(i).SetValue(subst(m, p.Field(i), pos)) |
245 } | 245 } |
246 return v | 246 return v |
247 | 247 |
248 case *reflect.PtrValue: | 248 case *reflect.PtrValue: |
249 v := reflect.MakeZero(p.Type()).(*reflect.PtrValue) | 249 v := reflect.MakeZero(p.Type()).(*reflect.PtrValue) |
250 v.PointTo(subst(m, p.Elem(), pos)) | 250 v.PointTo(subst(m, p.Elem(), pos)) |
251 return v | 251 return v |
252 | 252 |
253 case *reflect.InterfaceValue: | 253 case *reflect.InterfaceValue: |
254 v := reflect.MakeZero(p.Type()).(*reflect.InterfaceValue) | 254 v := reflect.MakeZero(p.Type()).(*reflect.InterfaceValue) |
255 v.SetValue(subst(m, p.Elem(), pos)) | 255 v.SetValue(subst(m, p.Elem(), pos)) |
256 return v | 256 return v |
257 } | 257 } |
258 | 258 |
259 return pattern | 259 return pattern |
260 } | 260 } |
LEFT | RIGHT |