x/tools: remove old renaming imports of go/constant as exact

Fixes golang/go#26522

Change-Id: Ie8184a358f11bc7ad855e0eeb964c29848d2263e
Reviewed-on: https://go-review.googlesource.com/128998
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alan Donovan 2018-08-10 12:49:16 -04:00
parent 00d4fcd841
commit e96c4e2476
12 changed files with 89 additions and 90 deletions

View File

@ -7,7 +7,7 @@ package main
import (
"bytes"
"fmt"
exact "go/constant"
"go/constant"
"go/token"
"go/types"
"io"
@ -213,9 +213,9 @@ func (p *printer) printDecl(keyword string, n int, printGroup func()) {
// absInt returns the absolute value of v as a *big.Int.
// v must be a numeric value.
func absInt(v exact.Value) *big.Int {
func absInt(v constant.Value) *big.Int {
// compute big-endian representation of v
b := exact.Bytes(v) // little-endian
b := constant.Bytes(v) // little-endian
for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
b[i], b[j] = b[j], b[i]
}
@ -229,14 +229,14 @@ var (
// floatString returns the string representation for a
// numeric value v in normalized floating-point format.
func floatString(v exact.Value) string {
if exact.Sign(v) == 0 {
func floatString(v constant.Value) string {
if constant.Sign(v) == 0 {
return "0.0"
}
// x != 0
// convert |v| into a big.Rat x
x := new(big.Rat).SetFrac(absInt(exact.Num(v)), absInt(exact.Denom(v)))
x := new(big.Rat).SetFrac(absInt(constant.Num(v)), absInt(constant.Denom(v)))
// normalize x and determine exponent e
// (This is not very efficient, but also not speed-critical.)
@ -272,7 +272,7 @@ func floatString(v exact.Value) string {
if e != 0 {
s += fmt.Sprintf("e%+d", e)
}
if exact.Sign(v) < 0 {
if constant.Sign(v) < 0 {
s = "-" + s
}
@ -286,29 +286,29 @@ func floatString(v exact.Value) string {
// valString returns the string representation for the value v.
// Setting floatFmt forces an integer value to be formatted in
// normalized floating-point format.
// TODO(gri) Move this code into package exact.
func valString(v exact.Value, floatFmt bool) string {
// TODO(gri) Move this code into package constant.
func valString(v constant.Value, floatFmt bool) string {
switch v.Kind() {
case exact.Int:
case constant.Int:
if floatFmt {
return floatString(v)
}
case exact.Float:
case constant.Float:
return floatString(v)
case exact.Complex:
re := exact.Real(v)
im := exact.Imag(v)
case constant.Complex:
re := constant.Real(v)
im := constant.Imag(v)
var s string
if exact.Sign(re) != 0 {
if constant.Sign(re) != 0 {
s = floatString(re)
if exact.Sign(im) >= 0 {
if constant.Sign(im) >= 0 {
s += " + "
} else {
s += " - "
im = exact.UnaryOp(token.SUB, im, 0) // negate im
im = constant.UnaryOp(token.SUB, im, 0) // negate im
}
}
// im != 0, otherwise v would be exact.Int or exact.Float
// im != 0, otherwise v would be constant.Int or constant.Float
return s + floatString(im) + "i"
}
return v.String()

View File

@ -8,7 +8,7 @@ import (
"bytes"
"fmt"
"go/ast"
exact "go/constant"
"go/constant"
"go/token"
"go/types"
"os"
@ -351,7 +351,7 @@ type describeValueResult struct {
qpos *queryPos
expr ast.Expr // query node
typ types.Type // type of expression
constVal exact.Value // value of expression, if constant
constVal constant.Value // value of expression, if constant
obj types.Object // var/func/const object, if expr was Ident
methods []*types.Selection
fields []describeField

View File

@ -64,7 +64,7 @@ import (
"fmt"
"go/ast"
"go/build"
exact "go/constant"
"go/constant"
"go/format"
"go/parser"
"go/token"
@ -390,7 +390,7 @@ type Value struct {
// by Value.String.
value uint64 // Will be converted to int64 when needed.
signed bool // Whether the constant is a signed type.
str string // The string representation given by the "go/exact" package.
str string // The string representation given by the "go/constant" package.
}
func (v *Value) String() string {
@ -464,11 +464,11 @@ func (f *File) genDecl(node ast.Node) bool {
log.Fatalf("can't handle non-integer constant type %s", typ)
}
value := obj.(*types.Const).Val() // Guaranteed to succeed as this is CONST.
if value.Kind() != exact.Int {
if value.Kind() != constant.Int {
log.Fatalf("can't happen: constant is not an integer %s", name)
}
i64, isInt := exact.Int64Val(value)
u64, isUint := exact.Uint64Val(value)
i64, isInt := constant.Int64Val(value)
u64, isUint := constant.Uint64Val(value)
if !isInt && !isUint {
log.Fatalf("internal error: value of %s is not an integer: %s", name, value.String())
}

View File

@ -16,7 +16,7 @@ import (
"errors"
"fmt"
"go/build"
exact "go/constant"
"go/constant"
"go/token"
"go/types"
"io"
@ -777,9 +777,9 @@ func (p *parser) parseInt() string {
// number = int_lit [ "p" int_lit ] .
//
func (p *parser) parseNumber() (typ *types.Basic, val exact.Value) {
func (p *parser) parseNumber() (typ *types.Basic, val constant.Value) {
// mantissa
mant := exact.MakeFromLiteral(p.parseInt(), token.INT, 0)
mant := constant.MakeFromLiteral(p.parseInt(), token.INT, 0)
if mant == nil {
panic("invalid mantissa")
}
@ -792,14 +792,14 @@ func (p *parser) parseNumber() (typ *types.Basic, val exact.Value) {
p.error(err)
}
if exp < 0 {
denom := exact.MakeInt64(1)
denom = exact.Shift(denom, token.SHL, uint(-exp))
denom := constant.MakeInt64(1)
denom = constant.Shift(denom, token.SHL, uint(-exp))
typ = types.Typ[types.UntypedFloat]
val = exact.BinaryOp(mant, token.QUO, denom)
val = constant.BinaryOp(mant, token.QUO, denom)
return
}
if exp > 0 {
mant = exact.Shift(mant, token.SHL, uint(exp))
mant = constant.Shift(mant, token.SHL, uint(exp))
}
typ = types.Typ[types.UntypedFloat]
val = mant
@ -830,7 +830,7 @@ func (p *parser) parseConstDecl() {
p.expect('=')
var typ types.Type
var val exact.Value
var val constant.Value
switch p.tok {
case scanner.Ident:
// bool_lit
@ -838,7 +838,7 @@ func (p *parser) parseConstDecl() {
p.error("expected true or false")
}
typ = types.Typ[types.UntypedBool]
val = exact.MakeBool(p.lit == "true")
val = constant.MakeBool(p.lit == "true")
p.next()
case '-', scanner.Int:
@ -862,18 +862,18 @@ func (p *parser) parseConstDecl() {
p.expectKeyword("i")
p.expect(')')
typ = types.Typ[types.UntypedComplex]
val = exact.BinaryOp(re, token.ADD, exact.MakeImag(im))
val = constant.BinaryOp(re, token.ADD, constant.MakeImag(im))
case scanner.Char:
// rune_lit
typ = types.Typ[types.UntypedRune]
val = exact.MakeFromLiteral(p.lit, token.CHAR, 0)
val = constant.MakeFromLiteral(p.lit, token.CHAR, 0)
p.next()
case scanner.String:
// string_lit
typ = types.Typ[types.UntypedString]
val = exact.MakeFromLiteral(p.lit, token.STRING, 0)
val = constant.MakeFromLiteral(p.lit, token.STRING, 0)
p.next()
default:

View File

@ -30,7 +30,7 @@ package pointer
import (
"fmt"
exact "go/constant"
"go/constant"
"go/types"
"reflect"
@ -1024,7 +1024,7 @@ func ext۰reflect۰ChanOf(a *analysis, cgn *cgnode) {
var dir reflect.ChanDir // unknown
if site := cgn.callersite; site != nil {
if c, ok := site.instr.Common().Args[0].(*ssa.Const); ok {
v, _ := exact.Int64Val(c.Value)
v, _ := constant.Int64Val(c.Value)
if 0 <= v && v <= int64(reflect.BothDir) {
dir = reflect.ChanDir(v)
}
@ -1668,7 +1668,7 @@ func ext۰reflect۰rtype۰FieldByName(a *analysis, cgn *cgnode) {
var name string
if site := cgn.callersite; site != nil {
if c, ok := site.instr.Common().Args[0].(*ssa.Const); ok {
name = exact.StringVal(c.Value)
name = constant.StringVal(c.Value)
}
}
@ -1751,7 +1751,7 @@ func ext۰reflect۰rtype۰InOut(a *analysis, cgn *cgnode, out bool) {
index := -1
if site := cgn.callersite; site != nil {
if c, ok := site.instr.Common().Args[0].(*ssa.Const); ok {
v, _ := exact.Int64Val(c.Value)
v, _ := constant.Int64Val(c.Value)
index = int(v)
}
}
@ -1910,7 +1910,7 @@ func ext۰reflect۰rtype۰MethodByName(a *analysis, cgn *cgnode) {
var name string
if site := cgn.callersite; site != nil {
if c, ok := site.instr.Common().Args[0].(*ssa.Const); ok {
name = exact.StringVal(c.Value)
name = constant.StringVal(c.Value)
}
}

View File

@ -32,7 +32,7 @@ package ssa
import (
"fmt"
"go/ast"
exact "go/constant"
"go/constant"
"go/token"
"go/types"
"os"
@ -63,7 +63,7 @@ var (
// SSA Value constants.
vZero = intConst(0)
vOne = intConst(1)
vTrue = NewConst(exact.MakeBool(true), tBool)
vTrue = NewConst(constant.MakeBool(true), tBool)
)
// builder holds state associated with the package currently being built.
@ -131,11 +131,11 @@ func (b *builder) logicalBinop(fn *Function, e *ast.BinaryExpr) Value {
switch e.Op {
case token.LAND:
b.cond(fn, e.X, rhs, done)
short = NewConst(exact.MakeBool(false), t)
short = NewConst(constant.MakeBool(false), t)
case token.LOR:
b.cond(fn, e.X, done, rhs)
short = NewConst(exact.MakeBool(true), t)
short = NewConst(constant.MakeBool(true), t)
}
// Is rhs unreachable?
@ -1998,7 +1998,7 @@ start:
op = token.SUB
}
loc := b.addr(fn, s.X, false)
b.assignOp(fn, loc, NewConst(exact.MakeInt64(1), loc.typ()), op, s.Pos())
b.assignOp(fn, loc, NewConst(constant.MakeInt64(1), loc.typ()), op, s.Pos())
case *ast.AssignStmt:
switch s.Tok {

View File

@ -8,7 +8,7 @@ package ssa
import (
"fmt"
exact "go/constant"
"go/constant"
"go/token"
"go/types"
"strconv"
@ -17,14 +17,14 @@ import (
// NewConst returns a new constant of the specified value and type.
// val must be valid according to the specification of Const.Value.
//
func NewConst(val exact.Value, typ types.Type) *Const {
func NewConst(val constant.Value, typ types.Type) *Const {
return &Const{typ, val}
}
// intConst returns an 'int' constant that evaluates to i.
// (i is an int64 in case the host is narrower than the target.)
func intConst(i int64) *Const {
return NewConst(exact.MakeInt64(i), tInt)
return NewConst(constant.MakeInt64(i), tInt)
}
// nilConst returns a nil constant of the specified type, which may
@ -36,7 +36,7 @@ func nilConst(typ types.Type) *Const {
// stringConst returns a 'string' constant that evaluates to s.
func stringConst(s string) *Const {
return NewConst(exact.MakeString(s), tString)
return NewConst(constant.MakeString(s), tString)
}
// zeroConst returns a new "zero" constant of the specified type,
@ -48,11 +48,11 @@ func zeroConst(t types.Type) *Const {
case *types.Basic:
switch {
case t.Info()&types.IsBoolean != 0:
return NewConst(exact.MakeBool(false), t)
return NewConst(constant.MakeBool(false), t)
case t.Info()&types.IsNumeric != 0:
return NewConst(exact.MakeInt64(0), t)
return NewConst(constant.MakeInt64(0), t)
case t.Info()&types.IsString != 0:
return NewConst(exact.MakeString(""), t)
return NewConst(constant.MakeString(""), t)
case t.Kind() == types.UnsafePointer:
fallthrough
case t.Kind() == types.UntypedNil:
@ -74,8 +74,8 @@ func (c *Const) RelString(from *types.Package) string {
var s string
if c.Value == nil {
s = "nil"
} else if c.Value.Kind() == exact.String {
s = exact.StringVal(c.Value)
} else if c.Value.Kind() == constant.String {
s = constant.StringVal(c.Value)
const max = 20
// TODO(adonovan): don't cut a rune in half.
if len(s) > max {
@ -121,14 +121,14 @@ func (c *Const) IsNil() bool {
// a signed 64-bit integer.
//
func (c *Const) Int64() int64 {
switch x := exact.ToInt(c.Value); x.Kind() {
case exact.Int:
if i, ok := exact.Int64Val(x); ok {
switch x := constant.ToInt(c.Value); x.Kind() {
case constant.Int:
if i, ok := constant.Int64Val(x); ok {
return i
}
return 0
case exact.Float:
f, _ := exact.Float64Val(x)
case constant.Float:
f, _ := constant.Float64Val(x)
return int64(f)
}
panic(fmt.Sprintf("unexpected constant value: %T", c.Value))
@ -138,14 +138,14 @@ func (c *Const) Int64() int64 {
// an unsigned 64-bit integer.
//
func (c *Const) Uint64() uint64 {
switch x := exact.ToInt(c.Value); x.Kind() {
case exact.Int:
if u, ok := exact.Uint64Val(x); ok {
switch x := constant.ToInt(c.Value); x.Kind() {
case constant.Int:
if u, ok := constant.Uint64Val(x); ok {
return u
}
return 0
case exact.Float:
f, _ := exact.Float64Val(x)
case constant.Float:
f, _ := constant.Float64Val(x)
return uint64(f)
}
panic(fmt.Sprintf("unexpected constant value: %T", c.Value))
@ -155,7 +155,7 @@ func (c *Const) Uint64() uint64 {
// a float64.
//
func (c *Const) Float64() float64 {
f, _ := exact.Float64Val(c.Value)
f, _ := constant.Float64Val(c.Value)
return f
}
@ -163,7 +163,7 @@ func (c *Const) Float64() float64 {
// fit a complex128.
//
func (c *Const) Complex128() complex128 {
re, _ := exact.Float64Val(exact.Real(c.Value))
im, _ := exact.Float64Val(exact.Imag(c.Value))
re, _ := constant.Float64Val(constant.Real(c.Value))
im, _ := constant.Float64Val(constant.Imag(c.Value))
return complex(re, im)
}

View File

@ -7,7 +7,7 @@ package interp
import (
"bytes"
"fmt"
exact "go/constant"
"go/constant"
"go/token"
"go/types"
"strings"
@ -40,7 +40,7 @@ func constValue(c *ssa.Const) value {
// TODO(adonovan): eliminate untyped constants from SSA form.
switch t.Kind() {
case types.Bool, types.UntypedBool:
return exact.BoolVal(c.Value)
return constant.BoolVal(c.Value)
case types.Int, types.UntypedInt:
// Assume sizeof(int) is same on host and target.
return int(c.Int64())
@ -75,8 +75,8 @@ func constValue(c *ssa.Const) value {
case types.Complex128, types.UntypedComplex:
return c.Complex128()
case types.String, types.UntypedString:
if c.Value.Kind() == exact.String {
return exact.StringVal(c.Value)
if c.Value.Kind() == constant.String {
return constant.StringVal(c.Value)
}
return string(rune(c.Int64()))
}

View File

@ -9,7 +9,7 @@ package ssa_test
import (
"fmt"
"go/ast"
exact "go/constant"
"go/constant"
"go/parser"
"go/token"
"go/types"
@ -144,7 +144,7 @@ func checkConstValue(t *testing.T, prog *ssa.Program, obj *types.Const) {
return
}
if obj.Name() != "nil" {
if !exact.Compare(c.Value, token.EQL, obj.Val()) {
if !constant.Compare(c.Value, token.EQL, obj.Val()) {
t.Errorf("ConstValue(%s).Value (%s) != %s",
obj, c.Value, obj.Val())
return

View File

@ -10,7 +10,7 @@ package ssa
import (
"fmt"
"go/ast"
exact "go/constant"
"go/constant"
"go/token"
"go/types"
"sync"
@ -404,9 +404,8 @@ type Parameter struct {
// All source-level constant expressions are represented by a Const
// of the same type and value.
//
// Value holds the exact value of the constant, independent of its
// Type(), using the same representation as package go/exact uses for
// constants, or nil for a typed nil value.
// Value holds the value of the constant, independent of its Type(),
// using go/constant representation, or nil for a typed nil value.
//
// Pos() returns token.NoPos.
//
@ -417,7 +416,7 @@ type Parameter struct {
//
type Const struct {
typ types.Type
Value exact.Value
Value constant.Value
}
// A Global is a named Value holding the address of a package-level
@ -658,7 +657,7 @@ type ChangeInterface struct {
// of X, and Program.Method(m) to find the implementation of a method.
//
// To construct the zero value of an interface type T, use:
// NewConst(exact.MakeNil(), T, pos)
// NewConst(constant.MakeNil(), T, pos)
//
// Pos() returns the ast.CallExpr.Lparen, if the instruction arose
// from an explicit conversion in the source.

View File

@ -11,7 +11,7 @@ package eg_test
import (
"bytes"
"flag"
exact "go/constant"
"go/constant"
"go/parser"
"go/token"
"go/types"
@ -110,7 +110,7 @@ func Test(t *testing.T) {
if err != nil {
if shouldFail == nil {
t.Errorf("NewTransformer(%s): %s", filename, err)
} else if want := exact.StringVal(shouldFail.Val()); !strings.Contains(err.Error(), want) {
} else if want := constant.StringVal(shouldFail.Val()); !strings.Contains(err.Error(), want) {
t.Errorf("NewTransformer(%s): got error %q, want error %q", filename, err, want)
}
} else if shouldFail != nil {

View File

@ -7,7 +7,7 @@ package eg
import (
"fmt"
"go/ast"
exact "go/constant"
"go/constant"
"go/token"
"go/types"
"log"
@ -67,9 +67,9 @@ func (tr *Transformer) matchExpr(x, y ast.Expr) bool {
case *ast.BasicLit:
y := y.(*ast.BasicLit)
xval := exact.MakeFromLiteral(x.Value, x.Kind, 0)
yval := exact.MakeFromLiteral(y.Value, y.Kind, 0)
return exact.Compare(xval, token.EQL, yval)
xval := constant.MakeFromLiteral(x.Value, x.Kind, 0)
yval := constant.MakeFromLiteral(y.Value, y.Kind, 0)
return constant.Compare(xval, token.EQL, yval)
case *ast.FuncLit:
// func literals (and thus statement syntax) never match.