diff --git a/cmd/godex/print.go b/cmd/godex/print.go index adce86462a..1bb5214edf 100644 --- a/cmd/godex/print.go +++ b/cmd/godex/print.go @@ -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() diff --git a/cmd/guru/describe.go b/cmd/guru/describe.go index dd32911de5..4975f4caca 100644 --- a/cmd/guru/describe.go +++ b/cmd/guru/describe.go @@ -8,7 +8,7 @@ import ( "bytes" "fmt" "go/ast" - exact "go/constant" + "go/constant" "go/token" "go/types" "os" @@ -349,10 +349,10 @@ func describeValue(qpos *queryPos, path []ast.Node) (*describeValueResult, error type describeValueResult struct { qpos *queryPos - expr ast.Expr // query node - typ types.Type // type of expression - constVal exact.Value // value of expression, if constant - obj types.Object // var/func/const object, if expr was Ident + expr ast.Expr // query node + typ types.Type // type of expression + constVal constant.Value // value of expression, if constant + obj types.Object // var/func/const object, if expr was Ident methods []*types.Selection fields []describeField } diff --git a/cmd/stringer/stringer.go b/cmd/stringer/stringer.go index 5e660fdf76..5c3ad3547e 100644 --- a/cmd/stringer/stringer.go +++ b/cmd/stringer/stringer.go @@ -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()) } diff --git a/go/internal/gcimporter/gcimporter.go b/go/internal/gcimporter/gcimporter.go index 12408e0a3b..47dd461362 100644 --- a/go/internal/gcimporter/gcimporter.go +++ b/go/internal/gcimporter/gcimporter.go @@ -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: diff --git a/go/pointer/reflect.go b/go/pointer/reflect.go index 3439a89659..7aa1a9cb88 100644 --- a/go/pointer/reflect.go +++ b/go/pointer/reflect.go @@ -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) } } diff --git a/go/ssa/builder.go b/go/ssa/builder.go index aff5e33762..fb6638a406 100644 --- a/go/ssa/builder.go +++ b/go/ssa/builder.go @@ -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 { diff --git a/go/ssa/const.go b/go/ssa/const.go index 2870eea5e9..f43792e7f3 100644 --- a/go/ssa/const.go +++ b/go/ssa/const.go @@ -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) } diff --git a/go/ssa/interp/ops.go b/go/ssa/interp/ops.go index f3419ec482..334d5b7b4d 100644 --- a/go/ssa/interp/ops.go +++ b/go/ssa/interp/ops.go @@ -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())) } diff --git a/go/ssa/source_test.go b/go/ssa/source_test.go index 43051f80e2..d543c1b140 100644 --- a/go/ssa/source_test.go +++ b/go/ssa/source_test.go @@ -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 diff --git a/go/ssa/ssa.go b/go/ssa/ssa.go index 7cde827cec..7f7998a513 100644 --- a/go/ssa/ssa.go +++ b/go/ssa/ssa.go @@ -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. diff --git a/refactor/eg/eg_test.go b/refactor/eg/eg_test.go index 89b7d08fb2..fc3dc321d5 100644 --- a/refactor/eg/eg_test.go +++ b/refactor/eg/eg_test.go @@ -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 { diff --git a/refactor/eg/match.go b/refactor/eg/match.go index 43466202aa..89c0f8d450 100644 --- a/refactor/eg/match.go +++ b/refactor/eg/match.go @@ -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.