mirror of https://github.com/golang/go.git
go/ssa: replace DefaultType with go/types.Default
Remove duplicate DefaultType and use go/types.Default instead. DefaultTypes was moved to std repo in golang.org/cl/8530 and exposed in golang.org/cl/30715 . The use of types.Default improves the package by resolving UntypedRune to proper 'rune' named type instead of int32. Removes TODO left by adonovan. Change-Id: Ie1066ef5276115662c7f5cc4e8cfc20519358fde GitHub-Last-Rev: 2ea227133440c831f11e1335a051cabbd9eff8f6 GitHub-Pull-Request: golang/tools#200 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215517 Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
dc16b66866
commit
213b5e130a
|
|
@ -635,7 +635,7 @@ func (b *builder) expr0(fn *Function, e ast.Expr, tv types.TypeAndValue) Value {
|
|||
case token.EQL, token.NEQ, token.GTR, token.LSS, token.LEQ, token.GEQ:
|
||||
cmp := emitCompare(fn, e.Op, b.expr(fn, e.X), b.expr(fn, e.Y), e.OpPos)
|
||||
// The type of x==y may be UntypedBool.
|
||||
return emitConv(fn, cmp, DefaultType(tv.Type))
|
||||
return emitConv(fn, cmp, types.Default(tv.Type))
|
||||
default:
|
||||
panic("illegal op in BinaryExpr: " + e.Op.String())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ func emitConv(f *Function, val Value, typ types.Type) Value {
|
|||
|
||||
// Convert (non-nil) "untyped" literals to their default type.
|
||||
if t, ok := ut_src.(*types.Basic); ok && t.Info()&types.IsUntyped != 0 {
|
||||
val = emitConv(f, val, DefaultType(ut_src))
|
||||
val = emitConv(f, val, types.Default(ut_src))
|
||||
}
|
||||
|
||||
f.Pkg.Prog.needMethodsOf(val.Type())
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ func zero(t types.Type) value {
|
|||
// this is unreachable. Currently some
|
||||
// constants have 'untyped' types when they
|
||||
// should be defaulted by the typechecker.
|
||||
t = ssa.DefaultType(t).(*types.Basic)
|
||||
t = types.Default(t).(*types.Basic)
|
||||
}
|
||||
switch t.Kind() {
|
||||
case types.Bool:
|
||||
|
|
|
|||
|
|
@ -52,36 +52,6 @@ func recvType(obj *types.Func) types.Type {
|
|||
return obj.Type().(*types.Signature).Recv().Type()
|
||||
}
|
||||
|
||||
// DefaultType returns the default "typed" type for an "untyped" type;
|
||||
// it returns the incoming type for all other types. The default type
|
||||
// for untyped nil is untyped nil.
|
||||
//
|
||||
// Exported to ssa/interp.
|
||||
//
|
||||
// TODO(adonovan): use go/types.DefaultType after 1.8.
|
||||
//
|
||||
func DefaultType(typ types.Type) types.Type {
|
||||
if t, ok := typ.(*types.Basic); ok {
|
||||
k := t.Kind()
|
||||
switch k {
|
||||
case types.UntypedBool:
|
||||
k = types.Bool
|
||||
case types.UntypedInt:
|
||||
k = types.Int
|
||||
case types.UntypedRune:
|
||||
k = types.Rune
|
||||
case types.UntypedFloat:
|
||||
k = types.Float64
|
||||
case types.UntypedComplex:
|
||||
k = types.Complex128
|
||||
case types.UntypedString:
|
||||
k = types.String
|
||||
}
|
||||
typ = types.Typ[k]
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
// logStack prints the formatted "start" message to stderr and
|
||||
// returns a closure that prints the corresponding "end" message.
|
||||
// Call using 'defer logStack(...)()' to show builder stack on panic.
|
||||
|
|
|
|||
Loading…
Reference in New Issue