mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: replace Ctype switches with type switches
Instead of switching on Ctype (which internally uses a type switch) and then scattering lots of type assertions throughout the CTFOO case clauses, just use type switches directly on the underlying constant value. Passes toolstash/buildall. Change-Id: I9bc172cc67e5f391cddc15539907883b4010689e Reviewed-on: https://go-review.googlesource.com/22384 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
2d342fba78
commit
97360096e5
9 changed files with 146 additions and 168 deletions
|
|
@ -342,20 +342,23 @@ func gdata(nam *Node, nr *Node, wid int) {
|
|||
|
||||
switch nr.Op {
|
||||
case OLITERAL:
|
||||
switch nr.Val().Ctype() {
|
||||
case CTCPLX:
|
||||
gdatacomplex(nam, nr.Val().U.(*Mpcplx))
|
||||
switch u := nr.Val().U.(type) {
|
||||
case *Mpcplx:
|
||||
gdatacomplex(nam, u)
|
||||
|
||||
case CTSTR:
|
||||
gdatastring(nam, nr.Val().U.(string))
|
||||
case string:
|
||||
gdatastring(nam, u)
|
||||
|
||||
case CTINT, CTRUNE, CTBOOL:
|
||||
i, _ := nr.IntLiteral()
|
||||
case bool:
|
||||
i := int64(obj.Bool2int(u))
|
||||
Linksym(nam.Sym).WriteInt(Ctxt, nam.Xoffset, wid, i)
|
||||
|
||||
case CTFLT:
|
||||
case *Mpint:
|
||||
Linksym(nam.Sym).WriteInt(Ctxt, nam.Xoffset, wid, u.Int64())
|
||||
|
||||
case *Mpflt:
|
||||
s := Linksym(nam.Sym)
|
||||
f := nr.Val().U.(*Mpflt).Float64()
|
||||
f := u.Float64()
|
||||
switch nam.Type.Etype {
|
||||
case TFLOAT32:
|
||||
s.WriteFloat32(Ctxt, nam.Xoffset, float32(f))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue