]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: small Mpint method simplifications
authorMatthew Dempsky <mdempsky@google.com>
Wed, 23 Mar 2016 18:07:20 +0000 (11:07 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 23 Mar 2016 19:22:53 +0000 (19:22 +0000)
Get rid of (*Mpint).Add's "quiet" parameter: it's always set to 0.

Inline (*Mpint).shift into (*Mpint).Lsh and (*Mpint).Rsh. There's no
need for a common shift method that can handle both left or right
shifts based on sign when the higher level abstractions only ever do
one or the other.

Change-Id: Icd3b082413f9193961b6835279e0bd4b6a6a6621
Reviewed-on: https://go-review.googlesource.com/21050
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/mpint.go
src/cmd/compile/internal/gc/parser.go

index a1271163abc33643e552e45f80b0397884e455f2..b09fc2215e940df4fcbafbdda956b3decac6df45 100644 (file)
@@ -833,7 +833,7 @@ func evconst(n *Node) {
 
        case OADD_ | CTINT_,
                OADD_ | CTRUNE_:
-               v.U.(*Mpint).Add(rv.U.(*Mpint), 0)
+               v.U.(*Mpint).Add(rv.U.(*Mpint))
 
        case OSUB_ | CTINT_,
                OSUB_ | CTRUNE_:
index d0f87deb00dd56bfbeaaab590d5040cc98b07ff5..c4ff897e26f1724f0398286198fb3cb1ac9778a9 100644 (file)
@@ -68,7 +68,7 @@ func (a *Mpint) SetFloat(b *Mpflt) int {
        return -1
 }
 
-func (a *Mpint) Add(b *Mpint, quiet int) {
+func (a *Mpint) Add(b *Mpint) {
        if a.Ovf || b.Ovf {
                if nsavederrors+nerrors == 0 {
                        Yyerror("ovf in mpaddfixfix")
@@ -79,7 +79,7 @@ func (a *Mpint) Add(b *Mpint, quiet int) {
 
        a.Val.Add(&a.Val, &b.Val)
 
-       if a.checkOverflow(0) && quiet == 0 {
+       if a.checkOverflow(0) {
                Yyerror("constant addition overflow")
        }
 }
@@ -198,20 +198,6 @@ func (a *Mpint) Xor(b *Mpint) {
        a.Val.Xor(&a.Val, &b.Val)
 }
 
-// shift left by s (or right by -s)
-func (a *Mpint) shift(s int) {
-       switch {
-       case s > 0:
-               if a.checkOverflow(s) {
-                       Yyerror("constant shift overflow")
-                       return
-               }
-               a.Val.Lsh(&a.Val, uint(s))
-       case s < 0:
-               a.Val.Rsh(&a.Val, uint(-s))
-       }
-}
-
 func (a *Mpint) Lsh(b *Mpint) {
        if a.Ovf || b.Ovf {
                if nsavederrors+nerrors == 0 {
@@ -232,7 +218,11 @@ func (a *Mpint) Lsh(b *Mpint) {
                return
        }
 
-       a.shift(int(s))
+       if a.checkOverflow(int(s)) {
+               Yyerror("constant shift overflow")
+               return
+       }
+       a.Val.Lsh(&a.Val, uint(s))
 }
 
 func (a *Mpint) Rsh(b *Mpint) {
@@ -255,7 +245,7 @@ func (a *Mpint) Rsh(b *Mpint) {
                return
        }
 
-       a.shift(int(-s))
+       a.Val.Rsh(&a.Val, uint(s))
 }
 
 func (a *Mpint) Cmp(b *Mpint) int {
index 96b3d24af5866d2edb24454f208bfc39cf68391c..7634e1c2b0f54b8b05ef44a920dd1ac7f05f9da1 100644 (file)
@@ -3318,7 +3318,7 @@ func (p *parser) hidden_constant() *Node {
 
                if s2.Val().Ctype() == CTRUNE && s4.Val().Ctype() == CTINT {
                        ss := s2
-                       s2.Val().U.(*Mpint).Add(s4.Val().U.(*Mpint), 0)
+                       s2.Val().U.(*Mpint).Add(s4.Val().U.(*Mpint))
                        return ss
                }
                s4.Val().U.(*Mpcplx).Real = s4.Val().U.(*Mpcplx).Imag