Skip to content

Commit 6eda189

Browse files
committed
Use go/types in Go 1.5 standard library.
Package golang.org/x/tools/go/types has moved into Go 1.5 standard library as go/types. Package golang.org/x/tools/go/exact is moved/renamed to go/constant.
1 parent f15a4ac commit 6eda189

File tree

13 files changed

+42
-51
lines changed

13 files changed

+42
-51
lines changed

compiler/analysis/bool.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ package analysis
22

33
import (
44
"go/ast"
5+
"go/constant"
56
"go/token"
6-
7-
"golang.org/x/tools/go/exact"
8-
"golang.org/x/tools/go/types"
7+
"go/types"
98
)
109

1110
func BoolValue(expr ast.Expr, info *types.Info) (bool, bool) {
1211
v := info.Types[expr].Value
13-
if v != nil && v.Kind() == exact.Bool {
14-
return exact.BoolVal(v), true
12+
if v != nil && v.Kind() == constant.Bool {
13+
return constant.BoolVal(v), true
1514
}
1615
switch e := expr.(type) {
1716
case *ast.BinaryExpr:

compiler/analysis/escape.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package analysis
33
import (
44
"go/ast"
55
"go/token"
6-
7-
"golang.org/x/tools/go/types"
6+
"go/types"
87
)
98

109
func EscapingObjects(n ast.Node, info *types.Info) map[*types.Var]bool {

compiler/analysis/info.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package analysis
33
import (
44
"go/ast"
55
"go/token"
6+
"go/types"
67

78
"github.com/gopherjs/gopherjs/compiler/astutil"
89
"github.com/gopherjs/gopherjs/compiler/typesutil"
9-
10-
"golang.org/x/tools/go/types"
1110
)
1211

1312
type continueStmt struct {

compiler/analysis/sideeffect.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package analysis
33
import (
44
"go/ast"
55
"go/token"
6-
7-
"golang.org/x/tools/go/types"
6+
"go/types"
87
)
98

109
func HasSideEffect(n ast.Node, info *types.Info) bool {

compiler/astutil/astutil.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package astutil
22

33
import (
44
"go/ast"
5-
6-
"golang.org/x/tools/go/types"
5+
"go/types"
76
)
87

98
func RemoveParens(e ast.Expr) ast.Expr {

compiler/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"encoding/json"
88
"fmt"
99
"go/token"
10+
"go/types"
1011
"io"
1112
"strings"
1213

1314
"github.com/gopherjs/gopherjs/compiler/prelude"
1415
"golang.org/x/tools/go/importer"
15-
"golang.org/x/tools/go/types"
1616
)
1717

1818
var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}

compiler/expressions.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import (
44
"bytes"
55
"fmt"
66
"go/ast"
7+
"go/constant"
78
"go/token"
9+
"go/types"
810
"sort"
911
"strconv"
1012
"strings"
1113

1214
"github.com/gopherjs/gopherjs/compiler/analysis"
1315
"github.com/gopherjs/gopherjs/compiler/astutil"
1416
"github.com/gopherjs/gopherjs/compiler/typesutil"
15-
16-
"golang.org/x/tools/go/exact"
17-
"golang.org/x/tools/go/types"
1817
)
1918

2019
type expression struct {
@@ -39,39 +38,39 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
3938
basic := exprType.Underlying().(*types.Basic)
4039
switch {
4140
case isBoolean(basic):
42-
return c.formatExpr("%s", strconv.FormatBool(exact.BoolVal(value)))
41+
return c.formatExpr("%s", strconv.FormatBool(constant.BoolVal(value)))
4342
case isInteger(basic):
4443
if is64Bit(basic) {
4544
if basic.Kind() == types.Int64 {
46-
d, ok := exact.Int64Val(value)
45+
d, ok := constant.Int64Val(value)
4746
if !ok {
4847
panic("could not get exact uint")
4948
}
5049
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatInt(d>>32, 10), strconv.FormatUint(uint64(d)&(1<<32-1), 10))
5150
}
52-
d, ok := exact.Uint64Val(value)
51+
d, ok := constant.Uint64Val(value)
5352
if !ok {
5453
panic("could not get exact uint")
5554
}
5655
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatUint(d>>32, 10), strconv.FormatUint(d&(1<<32-1), 10))
5756
}
58-
d, ok := exact.Int64Val(value)
57+
d, ok := constant.Int64Val(value)
5958
if !ok {
6059
panic("could not get exact int")
6160
}
6261
return c.formatExpr("%s", strconv.FormatInt(d, 10))
6362
case isFloat(basic):
64-
f, _ := exact.Float64Val(value)
63+
f, _ := constant.Float64Val(value)
6564
return c.formatExpr("%s", strconv.FormatFloat(f, 'g', -1, 64))
6665
case isComplex(basic):
67-
r, _ := exact.Float64Val(exact.Real(value))
68-
i, _ := exact.Float64Val(exact.Imag(value))
66+
r, _ := constant.Float64Val(constant.Real(value))
67+
i, _ := constant.Float64Val(constant.Imag(value))
6968
if basic.Kind() == types.UntypedComplex {
7069
exprType = types.Typ[types.Complex128]
7170
}
7271
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatFloat(r, 'g', -1, 64), strconv.FormatFloat(i, 'g', -1, 64))
7372
case isString(basic):
74-
return c.formatExpr("%s", encodeString(exact.StringVal(value)))
73+
return c.formatExpr("%s", encodeString(constant.StringVal(value)))
7574
default:
7675
panic("Unhandled constant type: " + basic.String())
7776
}
@@ -111,7 +110,7 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
111110
zero := c.translateExpr(c.zeroValue(elementType)).String()
112111
for _, element := range e.Elts {
113112
if kve, isKve := element.(*ast.KeyValueExpr); isKve {
114-
key, ok := exact.Int64Val(c.p.Types[kve.Key].Value)
113+
key, ok := constant.Int64Val(c.p.Types[kve.Key].Value)
115114
if !ok {
116115
panic("could not get exact int")
117116
}
@@ -920,7 +919,7 @@ func (c *funcContext) identifierConstant(expr ast.Expr) (string, bool) {
920919
if val == nil {
921920
return "", false
922921
}
923-
s := exact.StringVal(val)
922+
s := constant.StringVal(val)
924923
if len(s) == 0 {
925924
return "", false
926925
}
@@ -1303,7 +1302,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
13031302
case 'f':
13041303
e := a[n].(ast.Expr)
13051304
if val := c.p.Types[e].Value; val != nil {
1306-
d, _ := exact.Int64Val(val)
1305+
d, _ := constant.Int64Val(val)
13071306
out.WriteString(strconv.FormatInt(d, 10))
13081307
return
13091308
}
@@ -1317,7 +1316,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
13171316
case 'h':
13181317
e := a[n].(ast.Expr)
13191318
if val := c.p.Types[e].Value; val != nil {
1320-
d, _ := exact.Uint64Val(val)
1319+
d, _ := constant.Uint64Val(val)
13211320
if c.p.TypeOf(e).Underlying().(*types.Basic).Kind() == types.Int64 {
13221321
out.WriteString(strconv.FormatInt(int64(d)>>32, 10))
13231322
return
@@ -1328,21 +1327,21 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
13281327
writeExpr(".$high")
13291328
case 'l':
13301329
if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil {
1331-
d, _ := exact.Uint64Val(val)
1330+
d, _ := constant.Uint64Val(val)
13321331
out.WriteString(strconv.FormatUint(d&(1<<32-1), 10))
13331332
return
13341333
}
13351334
writeExpr(".$low")
13361335
case 'r':
13371336
if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil {
1338-
r, _ := exact.Float64Val(exact.Real(val))
1337+
r, _ := constant.Float64Val(constant.Real(val))
13391338
out.WriteString(strconv.FormatFloat(r, 'g', -1, 64))
13401339
return
13411340
}
13421341
writeExpr(".$real")
13431342
case 'i':
13441343
if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil {
1345-
i, _ := exact.Float64Val(exact.Imag(val))
1344+
i, _ := constant.Float64Val(constant.Imag(val))
13461345
out.WriteString(strconv.FormatFloat(i, 'g', -1, 64))
13471346
return
13481347
}

compiler/filter/incdecstmt.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package filter
22

33
import (
44
"go/ast"
5+
"go/constant"
56
"go/token"
7+
"go/types"
68

79
"github.com/gopherjs/gopherjs/compiler/analysis"
8-
9-
"golang.org/x/tools/go/exact"
10-
"golang.org/x/tools/go/types"
1110
)
1211

1312
func IncDecStmt(stmt ast.Stmt, info *analysis.Info) ast.Stmt {
@@ -30,7 +29,7 @@ func IncDecStmt(stmt ast.Stmt, info *analysis.Info) ast.Stmt {
3029
}
3130

3231
one := &ast.BasicLit{Kind: token.INT}
33-
info.Types[one] = types.TypeAndValue{Type: t, Value: exact.MakeInt64(1)}
32+
info.Types[one] = types.TypeAndValue{Type: t, Value: constant.MakeInt64(1)}
3433

3534
return &ast.AssignStmt{
3635
Lhs: []ast.Expr{s.X},

compiler/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"fmt"
77
"go/ast"
88
"go/token"
9+
"go/types"
910
"sort"
1011
"strings"
1112

1213
"github.com/gopherjs/gopherjs/compiler/analysis"
1314
"golang.org/x/tools/go/importer"
14-
"golang.org/x/tools/go/types"
1515
"golang.org/x/tools/go/types/typeutil"
1616
)
1717

compiler/statements.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ package compiler
33
import (
44
"fmt"
55
"go/ast"
6+
"go/constant"
67
"go/token"
8+
"go/types"
79
"strings"
810

911
"github.com/gopherjs/gopherjs/compiler/analysis"
1012
"github.com/gopherjs/gopherjs/compiler/astutil"
1113
"github.com/gopherjs/gopherjs/compiler/filter"
1214
"github.com/gopherjs/gopherjs/compiler/typesutil"
13-
14-
"golang.org/x/tools/go/exact"
15-
"golang.org/x/tools/go/types"
1615
)
1716

1817
type this struct {
@@ -71,7 +70,7 @@ func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
7170
tag := s.Tag
7271
if tag == nil {
7372
tag = ast.NewIdent("true")
74-
c.p.Types[tag] = types.TypeAndValue{Type: types.Typ[types.Bool], Value: exact.MakeBool(true)}
73+
c.p.Types[tag] = types.TypeAndValue{Type: types.Typ[types.Bool], Value: constant.MakeBool(true)}
7574
}
7675

7776
if c.p.Types[tag].Value == nil {
@@ -455,7 +454,7 @@ func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
455454
panic(fmt.Sprintf("unhandled: %T", comm))
456455
}
457456
indexLit := &ast.BasicLit{Kind: token.INT}
458-
c.p.Types[indexLit] = types.TypeAndValue{Type: types.Typ[types.Int], Value: exact.MakeInt64(int64(i))}
457+
c.p.Types[indexLit] = types.TypeAndValue{Type: types.Typ[types.Int], Value: constant.MakeInt64(int64(i))}
459458
caseClauses = append(caseClauses, &ast.CaseClause{
460459
List: []ast.Expr{indexLit},
461460
Body: clause.Body,

compiler/typesutil/typesutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package typesutil
22

3-
import "golang.org/x/tools/go/types"
3+
import "go/types"
44

55
func IsJsPackage(pkg *types.Package) bool {
66
return pkg != nil && pkg.Path() == "github.com/gopherjs/gopherjs/js"

compiler/utils.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import (
55
"encoding/binary"
66
"fmt"
77
"go/ast"
8+
"go/constant"
89
"go/token"
10+
"go/types"
911
"net/url"
1012
"sort"
1113
"strconv"
1214
"strings"
1315

1416
"github.com/gopherjs/gopherjs/compiler/analysis"
1517
"github.com/gopherjs/gopherjs/compiler/typesutil"
16-
17-
"golang.org/x/tools/go/exact"
18-
"golang.org/x/tools/go/types"
1918
)
2019

2120
func (c *funcContext) Write(b []byte) (int, error) {
@@ -173,11 +172,11 @@ func (c *funcContext) zeroValue(ty types.Type) ast.Expr {
173172
case *types.Basic:
174173
switch {
175174
case isBoolean(t):
176-
return c.newConst(ty, exact.MakeBool(false))
175+
return c.newConst(ty, constant.MakeBool(false))
177176
case isNumeric(t):
178-
return c.newConst(ty, exact.MakeInt64(0))
177+
return c.newConst(ty, constant.MakeInt64(0))
179178
case isString(t):
180-
return c.newConst(ty, exact.MakeString(""))
179+
return c.newConst(ty, constant.MakeString(""))
181180
case t.Kind() == types.UnsafePointer:
182181
// fall through to "nil"
183182
case t.Kind() == types.UntypedNil:
@@ -197,7 +196,7 @@ func (c *funcContext) zeroValue(ty types.Type) ast.Expr {
197196
return id
198197
}
199198

200-
func (c *funcContext) newConst(t types.Type, value exact.Value) ast.Expr {
199+
func (c *funcContext) newConst(t types.Type, value constant.Value) ast.Expr {
201200
id := &ast.Ident{}
202201
c.p.Types[id] = types.TypeAndValue{Type: t, Value: value}
203202
return id

tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"go/parser"
99
"go/scanner"
1010
"go/token"
11+
"go/types"
1112
"io"
1213
"io/ioutil"
1314
"net"
@@ -29,7 +30,6 @@ import (
2930
"github.com/spf13/cobra"
3031
"github.com/spf13/pflag"
3132
"golang.org/x/crypto/ssh/terminal"
32-
"golang.org/x/tools/go/types"
3333
)
3434

3535
var currentDirectory string

0 commit comments

Comments
 (0)