Skip to content

Commit fdf3373

Browse files
committed
cmd/compile: refactor constant node constructors
Passes toolstash-check. Change-Id: I6a2d46e69d4d3a06858c80c4ea1ad3f5a58f6956 Reviewed-on: https://go-review.googlesource.com/103859 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 917c33f commit fdf3373

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/cmd/compile/internal/gc/const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ illegal:
12461246
}
12471247
}
12481248

1249+
// nodlit returns a new untyped constant with value v.
12491250
func nodlit(v Val) *Node {
12501251
n := nod(OLITERAL, nil, nil)
12511252
n.SetVal(v)

src/cmd/compile/internal/gc/subr.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -413,21 +413,15 @@ func (x methcmp) Less(i, j int) bool {
413413
}
414414

415415
func nodintconst(v int64) *Node {
416-
c := nod(OLITERAL, nil, nil)
417-
c.SetAddable(true)
418-
c.SetVal(Val{new(Mpint)})
419-
c.Val().U.(*Mpint).SetInt64(v)
420-
c.Type = types.Types[TIDEAL]
421-
return c
416+
u := new(Mpint)
417+
u.SetInt64(v)
418+
return nodlit(Val{u})
422419
}
423420

424421
func nodfltconst(v *Mpflt) *Node {
425-
c := nod(OLITERAL, nil, nil)
426-
c.SetAddable(true)
427-
c.SetVal(Val{newMpflt()})
428-
c.Val().U.(*Mpflt).Set(v)
429-
c.Type = types.Types[TIDEAL]
430-
return c
422+
u := newMpflt()
423+
u.Set(v)
424+
return nodlit(Val{u})
431425
}
432426

433427
func nodconst(n *Node, t *types.Type, v int64) {
@@ -444,17 +438,11 @@ func nodconst(n *Node, t *types.Type, v int64) {
444438
}
445439

446440
func nodnil() *Node {
447-
c := nodintconst(0)
448-
c.SetVal(Val{new(NilVal)})
449-
c.Type = types.Types[TNIL]
450-
return c
441+
return nodlit(Val{new(NilVal)})
451442
}
452443

453444
func nodbool(b bool) *Node {
454-
c := nodintconst(0)
455-
c.SetVal(Val{b})
456-
c.Type = types.Idealbool
457-
return c
445+
return nodlit(Val{b})
458446
}
459447

460448
func nodstr(s string) *Node {

0 commit comments

Comments
 (0)