1
0
mirror of https://github.com/golang/go synced 2024-10-01 06:08:32 -06:00

go/types: unexport UniverseByte/Rune; make Typ a slice

Also: backport https://go-review.googlesource.com/#/c/12443/ .

Change-Id: Ia8a664c627a70a17701b2d48946704c15f4f49c0
Reviewed-on: https://go-review.googlesource.com/12482
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Robert Griesemer 2015-07-21 11:38:22 -07:00
parent 436a79e5dd
commit 88421f4cb2
7 changed files with 16 additions and 15 deletions

View File

@ -659,8 +659,8 @@ func lookupBuiltinType(typ int) types.Type {
gccgoBuiltinCOMPLEX64: types.Typ[types.Complex64],
gccgoBuiltinCOMPLEX128: types.Typ[types.Complex128],
gccgoBuiltinERROR: types.Universe.Lookup("error").Type(),
gccgoBuiltinBYTE: types.Typ[types.Byte],
gccgoBuiltinRUNE: types.Typ[types.Rune],
gccgoBuiltinBYTE: types.Universe.Lookup("byte").Type(),
gccgoBuiltinRUNE: types.Universe.Lookup("rune").Type(),
}[typ]
}

View File

@ -76,8 +76,9 @@ var predeclared = []types.Type{
types.Typ[types.UnsafePointer],
// aliases
types.UniverseByte,
types.UniverseRune,
types.Universe.Lookup("byte").Type(),
types.Universe.Lookup("rune").Type(),
// error
types.Universe.Lookup("error").Type(),
}

View File

@ -96,7 +96,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
// spec: "As a special case, append also accepts a first argument assignable
// to type []byte with a second argument of string type followed by ... .
// This form appends the bytes of the string.
if nargs == 2 && call.Ellipsis.IsValid() && x.assignableTo(check.conf, NewSlice(UniverseByte)) {
if nargs == 2 && call.Ellipsis.IsValid() && x.assignableTo(check.conf, NewSlice(universeByte)) {
arg(x, 1)
if x.mode == invalid {
return
@ -289,7 +289,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
switch t := y.typ.Underlying().(type) {
case *Basic:
if isString(y.typ) {
src = UniverseByte
src = universeByte
}
case *Slice:
src = t.elem

View File

@ -1183,7 +1183,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
// (not a constant) even if the string and the
// index are constant
x.mode = value
x.typ = UniverseByte // use 'byte' name
x.typ = universeByte // use 'byte' name
}
case *Array:

View File

@ -296,7 +296,7 @@ func defaultType(typ Type) Type {
case UntypedInt:
return Typ[Int]
case UntypedRune:
return UniverseRune // use 'rune' name
return universeRune // use 'rune' name
case UntypedFloat:
return Typ[Float64]
case UntypedComplex:

View File

@ -629,7 +629,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
case *Basic:
if isString(typ) {
key = Typ[Int]
val = UniverseRune // use 'rune' name
val = universeRune // use 'rune' name
}
case *Array:
key = Typ[Int]

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file implements the universe and unsafe package scopes.
// This file sets up the universe scope and the unsafe package.
package types
@ -17,11 +17,11 @@ var (
Universe *Scope
Unsafe *Package
universeIota *Const
UniverseByte *Basic // uint8 alias, but has name "byte"
UniverseRune *Basic // int32 alias, but has name "rune"
universeByte *Basic // uint8 alias, but has name "byte"
universeRune *Basic // int32 alias, but has name "rune"
)
var Typ = [...]*Basic{
var Typ = []*Basic{
Invalid: {Invalid, 0, "invalid type"},
Bool: {Bool, IsBoolean, "bool"},
@ -187,8 +187,8 @@ func init() {
defPredeclaredFuncs()
universeIota = Universe.Lookup("iota").(*Const)
UniverseByte = Universe.Lookup("byte").(*TypeName).typ.(*Basic)
UniverseRune = Universe.Lookup("rune").(*TypeName).typ.(*Basic)
universeByte = Universe.Lookup("byte").(*TypeName).typ.(*Basic)
universeRune = Universe.Lookup("rune").(*TypeName).typ.(*Basic)
}
// Objects with names containing blanks are internal and not entered into