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

Method parseExpr

parse/getast.go:706–849  ·  view source on GitHub ↗

recursively translate ast.Expr to gen.Elem; nil means type not supported expected input types: - *ast.MapType (map[T]J) - *ast.Ident (name) - *ast.ArrayType ([(sz)]T) - *ast.StarExpr (*T) - *ast.StructType (struct {}) - *ast.SelectorExpr (a.B) - *ast.InterfaceType (interface {})

(e ast.Expr)

Source from the content-addressed store, hash-verified

704// - *ast.SelectorExpr (a.B)
705// - *ast.InterfaceType (interface {})
706func (fs *FileSet) parseExpr(e ast.Expr) gen.Elem {
707 switch e := e.(type) {
708
709 case *ast.MapType:
710 switch k := e.Key.(type) {
711 case *ast.Ident:
712 switch k.Name {
713 case "string":
714 if in := fs.parseExpr(e.Value); in != nil {
715 return &gen.Map{Value: in, AllowBinMaps: fs.AllowBinMaps, AllowMapShims: fs.AllowMapShims, AutoMapShims: fs.AutoMapShims}
716 }
717 warnf("%s: map keys of type are not supported\n", stringify(e.Key))
718 default:
719 if !fs.AllowMapShims && !fs.AllowBinMaps && !fs.AutoMapShims {
720 warnf("map keys of type %s are not supported without binary keys or shimming\n", stringify(e.Key))
721 return nil
722 }
723 // Allow for other types, assuming they will be shimmed later.
724 key := fs.parseExpr(k)
725 // Types that aren't idents are native types and cannot currently be used as map keys.
726 switch k := key.(type) {
727 case *gen.BaseElem:
728 switch k.Value {
729 case gen.IDENT:
730 if in := fs.parseExpr(e.Value); in != nil {
731 return &gen.Map{Value: in, Key: key, AllowBinMaps: fs.AllowBinMaps, AllowMapShims: fs.AllowMapShims, AutoMapShims: fs.AutoMapShims}
732 }
733 warnf("map keys of type %s are not supported\n", k.TypeName())
734 // Exclude types that cannot be used as native map keys.
735 case gen.Bytes:
736 warnf("map keys of type %s are not supported\n", k.TypeName())
737 default:
738 if in := fs.parseExpr(e.Value); (fs.AllowBinMaps || (fs.AutoMapShims && gen.CanAutoShim[k.Value])) && in != nil {
739 return &gen.Map{Value: in, Key: key, AllowBinMaps: fs.AllowBinMaps, AllowMapShims: fs.AllowMapShims, AutoMapShims: fs.AutoMapShims}
740 }
741 warnf("map keys of type %s are not supported without binary keys or shimming\n", k.TypeName())
742 }
743 default:
744 warnf("map keys of type %s are not supported\n", k.TypeName())
745 }
746 return nil
747 }
748 case *ast.ArrayType:
749 if fs.AllowBinMaps {
750 key := fs.parseExpr(k)
751 if in := fs.parseExpr(e.Value); fs.AllowBinMaps && in != nil {
752 return &gen.Map{Value: in, Key: key, AllowBinMaps: fs.AllowBinMaps, AllowMapShims: fs.AllowMapShims, AutoMapShims: fs.AutoMapShims}
753 }
754 }
755 warnf("array map keys (type %s) are not supported without binary keys or shimming\n", stringify(e.Key))
756 default:
757 warnf("array map key type not supported\n")
758 }
759 return nil
760
761 case *ast.Ident:
762 b := gen.Ident(e.Name)
763

Callers 3

processMethod · 0.95
getFieldMethod · 0.95
replaceFunction · 0.80

Calls 6

parseFieldListMethod · 0.95
IdentFunction · 0.92
warnfFunction · 0.85
stringifyFunction · 0.85
TypeNameMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected