| |
| |
| |
|
|
| package reflectdata |
|
|
| import ( |
| "cmd/compile/internal/base" |
| "cmd/compile/internal/ir" |
| "cmd/compile/internal/types" |
| "cmd/internal/src" |
| ) |
|
|
| func hasRType(n, rtype ir.Node, fieldName string) bool { |
| if rtype != nil { |
| return true |
| } |
|
|
| return false |
| } |
|
|
| |
| func assertOp(n ir.Node, op ir.Op) { |
| base.AssertfAt(n.Op() == op, n.Pos(), "want %v, have %v", op, n) |
| } |
|
|
| |
| func assertOp2(n ir.Node, op1, op2 ir.Op) { |
| base.AssertfAt(n.Op() == op1 || n.Op() == op2, n.Pos(), "want %v or %v, have %v", op1, op2, n) |
| } |
|
|
| |
| |
| func kindRType(pos src.XPos, typ *types.Type, k types.Kind) ir.Node { |
| base.AssertfAt(typ.Kind() == k, pos, "want %v type, have %v", k, typ) |
| return TypePtrAt(pos, typ) |
| } |
|
|
| |
| |
| func mapRType(pos src.XPos, typ *types.Type) ir.Node { |
| return kindRType(pos, typ, types.TMAP) |
| } |
|
|
| |
| |
| func chanRType(pos src.XPos, typ *types.Type) ir.Node { |
| return kindRType(pos, typ, types.TCHAN) |
| } |
|
|
| |
| |
| |
| func sliceElemRType(pos src.XPos, typ *types.Type) ir.Node { |
| base.AssertfAt(typ.IsSlice(), pos, "want slice type, have %v", typ) |
| return TypePtrAt(pos, typ.Elem()) |
| } |
|
|
| |
| |
| |
| func concreteRType(pos src.XPos, typ *types.Type) ir.Node { |
| base.AssertfAt(!typ.IsInterface(), pos, "want non-interface type, have %v", typ) |
| return TypePtrAt(pos, typ) |
| } |
|
|
| |
| |
| |
| func AppendElemRType(pos src.XPos, n *ir.CallExpr) ir.Node { |
| assertOp(n, ir.OAPPEND) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return sliceElemRType(pos, n.Type()) |
| } |
|
|
| |
| |
| |
| |
| func CompareRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { |
| assertOp2(n, ir.OEQ, ir.ONE) |
| base.AssertfAt(n.X.Type().IsInterface() != n.Y.Type().IsInterface(), n.Pos(), "expect mixed interface and non-interface, have %L and %L", n.X, n.Y) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| typ := n.X.Type() |
| if typ.IsInterface() { |
| typ = n.Y.Type() |
| } |
| return concreteRType(pos, typ) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| func ConvIfaceTypeWord(pos src.XPos, n *ir.ConvExpr) ir.Node { |
| assertOp(n, ir.OCONVIFACE) |
| src, dst := n.X.Type(), n.Type() |
| base.AssertfAt(dst.IsInterface(), n.Pos(), "want interface type, have %L", n) |
| if hasRType(n, n.TypeWord, "TypeWord") { |
| return n.TypeWord |
| } |
| if dst.IsEmptyInterface() { |
| return concreteRType(pos, src) |
| } |
| if !src.IsInterface() { |
| return ITabAddrAt(pos, src, dst) |
| } |
| return TypePtrAt(pos, dst) |
| } |
|
|
| |
| |
| |
| |
| func ConvIfaceSrcRType(pos src.XPos, n *ir.ConvExpr) ir.Node { |
| assertOp(n, ir.OCONVIFACE) |
| if hasRType(n, n.SrcRType, "SrcRType") { |
| return n.SrcRType |
| } |
| return concreteRType(pos, n.X.Type()) |
| } |
|
|
| |
| |
| |
| func CopyElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { |
| assertOp(n, ir.OCOPY) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return sliceElemRType(pos, n.X.Type()) |
| } |
|
|
| |
| |
| |
| func DeleteMapRType(pos src.XPos, n *ir.CallExpr) ir.Node { |
| assertOp(n, ir.ODELETE) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return mapRType(pos, n.Args[0].Type()) |
| } |
|
|
| |
| |
| |
| func IndexMapRType(pos src.XPos, n *ir.IndexExpr) ir.Node { |
| assertOp(n, ir.OINDEXMAP) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return mapRType(pos, n.X.Type()) |
| } |
|
|
| |
| |
| |
| func MakeChanRType(pos src.XPos, n *ir.MakeExpr) ir.Node { |
| assertOp(n, ir.OMAKECHAN) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return chanRType(pos, n.Type()) |
| } |
|
|
| |
| |
| |
| func MakeMapRType(pos src.XPos, n *ir.MakeExpr) ir.Node { |
| assertOp(n, ir.OMAKEMAP) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return mapRType(pos, n.Type()) |
| } |
|
|
| |
| |
| |
| func MakeSliceElemRType(pos src.XPos, n *ir.MakeExpr) ir.Node { |
| assertOp2(n, ir.OMAKESLICE, ir.OMAKESLICECOPY) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return sliceElemRType(pos, n.Type()) |
| } |
|
|
| |
| |
| |
| func RangeMapRType(pos src.XPos, n *ir.RangeStmt) ir.Node { |
| assertOp(n, ir.ORANGE) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return mapRType(pos, n.X.Type()) |
| } |
|
|
| |
| |
| |
| func UnsafeSliceElemRType(pos src.XPos, n *ir.BinaryExpr) ir.Node { |
| assertOp(n, ir.OUNSAFESLICE) |
| if hasRType(n, n.RType, "RType") { |
| return n.RType |
| } |
| return sliceElemRType(pos, n.Type()) |
| } |
|
|