MCPcopy
hub / github.com/google/mtail / emitConversion

Method emitConversion

internal/runtime/compiler/codegen/codegen.go:592–613  ·  view source on GitHub ↗
(n ast.Node, inType, outType types.Type)

Source from the content-addressed store, hash-verified

590}
591
592func (c *codegen) emitConversion(n ast.Node, inType, outType types.Type) error {
593 glog.V(2).Infof("Conversion: %q to %q", inType, outType)
594 switch {
595 case types.Equals(types.Int, inType) && types.Equals(types.Float, outType):
596 c.emit(n, code.I2f, nil)
597 case types.Equals(types.String, inType) && types.Equals(types.Float, outType):
598 c.emit(n, code.S2f, nil)
599 case types.Equals(types.String, inType) && types.Equals(types.Int, outType):
600 c.emit(n, code.S2i, nil)
601 case types.Equals(types.Float, inType) && types.Equals(types.String, outType):
602 c.emit(n, code.F2s, nil)
603 case types.Equals(types.Int, inType) && types.Equals(types.String, outType):
604 c.emit(n, code.I2s, nil)
605 case types.Equals(types.Pattern, inType) && types.Equals(types.Bool, outType):
606 // nothing, pattern is implicit bool
607 case types.Equals(inType, outType):
608 // Nothing; no-op.
609 default:
610 return errors.Errorf("can't convert %q to %q", inType, outType)
611 }
612 return nil
613}
614
615func (c *codegen) writeJumps() {
616 for j, i := range c.obj.Program {

Callers 1

VisitAfterMethod · 0.95

Calls 3

emitMethod · 0.95
EqualsFunction · 0.92
ErrorfFunction · 0.92

Tested by

no test coverage detected