MCPcopy Create free account
hub / github.com/google/gapid / PrintfSpecifier

Method PrintfSpecifier

core/codegen/builder.go:334–379  ·  view source on GitHub ↗

PrintfSpecifier returns the string and values that can be used to print v with printf.

(v *Value)

Source from the content-addressed store, hash-verified

332// PrintfSpecifier returns the string and values that can be used to print v
333// with printf.
334func (b *Builder) PrintfSpecifier(v *Value) (string, []*Value) {
335 t := v.Type()
336 switch t {
337 case b.m.Types.Bool:
338 v = b.Select(v, b.Scalar("true"), b.Scalar("false"))
339 return "%s", []*Value{v}
340 case b.m.Types.Float32:
341 return "%f", []*Value{v}
342 case b.m.Types.Float64:
343 return "%d", []*Value{v}
344 case b.m.Types.Int, b.m.Types.Int8, b.m.Types.Int16, b.m.Types.Int32, b.m.Types.Int64:
345 return "%lld", []*Value{v.Cast(b.m.Types.Int64)}
346 case b.m.Types.Uint, b.m.Types.Uint8, b.m.Types.Uint16, b.m.Types.Uint32, b.m.Types.Uint64:
347 return "%llu", []*Value{v.Cast(b.m.Types.Int64)}
348 case b.m.Types.Uintptr:
349 return "%p", []*Value{v.Cast(b.m.Types.Int64)}
350 case b.m.Types.Size:
351 return "%z", []*Value{v.Cast(b.m.Types.Int64)}
352 case b.m.Types.Float32:
353 return "%f", []*Value{v}
354 case b.m.Types.Float64:
355 return "%d", []*Value{v}
356 }
357 switch t := t.(type) {
358 case Pointer:
359 return "%p", []*Value{v}
360 case *Struct:
361 vals := []*Value{}
362 sb := strings.Builder{}
363 sb.WriteString(t.TypeName())
364 sb.WriteString("{ ")
365 for i, f := range t.Fields() {
366 if i > 0 {
367 sb.WriteString(", ")
368 }
369 fmt, val := b.PrintfSpecifier(v.Extract(i))
370 sb.WriteString(f.Name)
371 sb.WriteString(": ")
372 sb.WriteString(fmt)
373 vals = append(vals, val...)
374 }
375 sb.WriteString(" }")
376 return sb.String(), vals
377 }
378 return fmt.Sprintf("<%v>", v.Type()), nil
379}
380
381// StructOf builds a struct value that holds all the values in v.
382func (b *Builder) StructOf(name string, v []*Value) *Value {

Callers 2

assertMethod · 0.80
substitutePercentVsFunction · 0.80

Calls 9

SelectMethod · 0.95
ScalarMethod · 0.95
StringMethod · 0.95
WriteStringMethod · 0.80
FieldsMethod · 0.80
ExtractMethod · 0.80
TypeMethod · 0.65
TypeNameMethod · 0.65
CastMethod · 0.45

Tested by

no test coverage detected