augmentCall walks the function and populate call accordingly.
(call *Call, f *ast.FuncDecl)
| 240 | |
| 241 | // augmentCall walks the function and populate call accordingly. |
| 242 | func augmentCall(call *Call, f *ast.FuncDecl) { |
| 243 | flatArgs := make([]*Arg, 0, len(call.Args.Values)) |
| 244 | call.Args.walk(func(arg *Arg) { |
| 245 | flatArgs = append(flatArgs, arg) |
| 246 | }) |
| 247 | |
| 248 | pop := func() *Arg { |
| 249 | if len(flatArgs) == 0 { |
| 250 | return nil |
| 251 | } |
| 252 | a := flatArgs[0] |
| 253 | flatArgs = flatArgs[1:] |
| 254 | return a |
| 255 | } |
| 256 | popFmt := func(fmtFn func(v uint64) string) string { |
| 257 | a := pop() |
| 258 | if a == nil { |
| 259 | return "<nil>" |
| 260 | } |
| 261 | if a.IsOffsetTooLarge { |
| 262 | return "_" |
| 263 | } |
| 264 | return fmtFn(a.Value) |
| 265 | } |
| 266 | popName := func() string { |
| 267 | a := pop() |
| 268 | if a == nil { |
| 269 | return "<nil>" |
| 270 | } |
| 271 | if len(a.Name) != 0 { |
| 272 | return a.Name |
| 273 | } |
| 274 | if a.IsOffsetTooLarge { |
| 275 | return "_" |
| 276 | } |
| 277 | return fmt.Sprintf("0x%x", a.Value) |
| 278 | } |
| 279 | |
| 280 | types, extra := extractArgumentsType(f) |
| 281 | for i := 0; len(flatArgs) != 0; i++ { |
| 282 | var t string |
| 283 | if i >= len(types) { |
| 284 | if !extra { |
| 285 | // These are unexpected value! Print them as hex. |
| 286 | call.Args.Processed = append(call.Args.Processed, popName()) |
| 287 | continue |
| 288 | } |
| 289 | t = types[len(types)-1] |
| 290 | } else { |
| 291 | t = types[i] |
| 292 | } |
| 293 | var str string |
| 294 | switch t { |
| 295 | case "float32": |
| 296 | str = popFmt(func(v uint64) string { |
| 297 | f := float64(math.Float32frombits(uint32(v))) |
| 298 | return strconv.FormatFloat(f, 'g', -1, 32) |
| 299 | }) |
no test coverage detected
searching dependent graphs…