MCPcopy
hub / github.com/tinylib/msgp / stringify

Function stringify

parse/getast.go:664–695  ·  view source on GitHub ↗

stringify a field type name

(e ast.Expr)

Source from the content-addressed store, hash-verified

662
663// stringify a field type name
664func stringify(e ast.Expr) string {
665 switch e := e.(type) {
666 case *ast.Ident:
667 return e.Name
668 case *ast.StarExpr:
669 return "*" + stringify(e.X)
670 case *ast.SelectorExpr:
671 return stringify(e.X) + "." + e.Sel.Name
672 case *ast.ArrayType:
673 if e.Len == nil {
674 return "[]" + stringify(e.Elt)
675 }
676 return fmt.Sprintf("[%s]%s", stringify(e.Len), stringify(e.Elt))
677 case *ast.InterfaceType:
678 if e.Methods == nil || e.Methods.NumFields() == 0 {
679 return "interface{}"
680 }
681 case *ast.BasicLit:
682 return e.Value
683 case *ast.IndexExpr:
684 // Single type argument: Generic[T]
685 return fmt.Sprintf("%s[%s]", stringify(e.X), stringify(e.Index))
686 case *ast.IndexListExpr:
687 // Multiple type arguments: Generic[A,B,...]
688 args := make([]string, 0, len(e.Indices))
689 for _, ix := range e.Indices {
690 args = append(args, stringify(ix))
691 }
692 return fmt.Sprintf("%s[%s]", stringify(e.X), strings.Join(args, ","))
693 }
694 return "<BAD>"
695}
696
697// recursively translate ast.Expr to gen.Elem; nil means type not supported
698// expected input types:

Callers 6

isrtforFunction · 0.85
findRTForInInterfaceFunction · 0.85
getMspTypeParamsFunction · 0.85
getTypeSpecsMethod · 0.85
fieldNameFunction · 0.85
parseExprMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…