mirror of
https://github.com/golang/go
synced 2024-11-19 01:04:40 -07: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:
parent
436a79e5dd
commit
88421f4cb2
@ -659,8 +659,8 @@ func lookupBuiltinType(typ int) types.Type {
|
|||||||
gccgoBuiltinCOMPLEX64: types.Typ[types.Complex64],
|
gccgoBuiltinCOMPLEX64: types.Typ[types.Complex64],
|
||||||
gccgoBuiltinCOMPLEX128: types.Typ[types.Complex128],
|
gccgoBuiltinCOMPLEX128: types.Typ[types.Complex128],
|
||||||
gccgoBuiltinERROR: types.Universe.Lookup("error").Type(),
|
gccgoBuiltinERROR: types.Universe.Lookup("error").Type(),
|
||||||
gccgoBuiltinBYTE: types.Typ[types.Byte],
|
gccgoBuiltinBYTE: types.Universe.Lookup("byte").Type(),
|
||||||
gccgoBuiltinRUNE: types.Typ[types.Rune],
|
gccgoBuiltinRUNE: types.Universe.Lookup("rune").Type(),
|
||||||
}[typ]
|
}[typ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +76,9 @@ var predeclared = []types.Type{
|
|||||||
types.Typ[types.UnsafePointer],
|
types.Typ[types.UnsafePointer],
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
types.UniverseByte,
|
types.Universe.Lookup("byte").Type(),
|
||||||
types.UniverseRune,
|
types.Universe.Lookup("rune").Type(),
|
||||||
|
|
||||||
|
// error
|
||||||
types.Universe.Lookup("error").Type(),
|
types.Universe.Lookup("error").Type(),
|
||||||
}
|
}
|
||||||
|
@ -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
|
// spec: "As a special case, append also accepts a first argument assignable
|
||||||
// to type []byte with a second argument of string type followed by ... .
|
// to type []byte with a second argument of string type followed by ... .
|
||||||
// This form appends the bytes of the string.
|
// 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)
|
arg(x, 1)
|
||||||
if x.mode == invalid {
|
if x.mode == invalid {
|
||||||
return
|
return
|
||||||
@ -289,7 +289,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
|
|||||||
switch t := y.typ.Underlying().(type) {
|
switch t := y.typ.Underlying().(type) {
|
||||||
case *Basic:
|
case *Basic:
|
||||||
if isString(y.typ) {
|
if isString(y.typ) {
|
||||||
src = UniverseByte
|
src = universeByte
|
||||||
}
|
}
|
||||||
case *Slice:
|
case *Slice:
|
||||||
src = t.elem
|
src = t.elem
|
||||||
|
@ -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
|
// (not a constant) even if the string and the
|
||||||
// index are constant
|
// index are constant
|
||||||
x.mode = value
|
x.mode = value
|
||||||
x.typ = UniverseByte // use 'byte' name
|
x.typ = universeByte // use 'byte' name
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Array:
|
case *Array:
|
||||||
|
@ -296,7 +296,7 @@ func defaultType(typ Type) Type {
|
|||||||
case UntypedInt:
|
case UntypedInt:
|
||||||
return Typ[Int]
|
return Typ[Int]
|
||||||
case UntypedRune:
|
case UntypedRune:
|
||||||
return UniverseRune // use 'rune' name
|
return universeRune // use 'rune' name
|
||||||
case UntypedFloat:
|
case UntypedFloat:
|
||||||
return Typ[Float64]
|
return Typ[Float64]
|
||||||
case UntypedComplex:
|
case UntypedComplex:
|
||||||
|
@ -629,7 +629,7 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
|
|||||||
case *Basic:
|
case *Basic:
|
||||||
if isString(typ) {
|
if isString(typ) {
|
||||||
key = Typ[Int]
|
key = Typ[Int]
|
||||||
val = UniverseRune // use 'rune' name
|
val = universeRune // use 'rune' name
|
||||||
}
|
}
|
||||||
case *Array:
|
case *Array:
|
||||||
key = Typ[Int]
|
key = Typ[Int]
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// 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
|
package types
|
||||||
|
|
||||||
@ -17,11 +17,11 @@ var (
|
|||||||
Universe *Scope
|
Universe *Scope
|
||||||
Unsafe *Package
|
Unsafe *Package
|
||||||
universeIota *Const
|
universeIota *Const
|
||||||
UniverseByte *Basic // uint8 alias, but has name "byte"
|
universeByte *Basic // uint8 alias, but has name "byte"
|
||||||
UniverseRune *Basic // int32 alias, but has name "rune"
|
universeRune *Basic // int32 alias, but has name "rune"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Typ = [...]*Basic{
|
var Typ = []*Basic{
|
||||||
Invalid: {Invalid, 0, "invalid type"},
|
Invalid: {Invalid, 0, "invalid type"},
|
||||||
|
|
||||||
Bool: {Bool, IsBoolean, "bool"},
|
Bool: {Bool, IsBoolean, "bool"},
|
||||||
@ -187,8 +187,8 @@ func init() {
|
|||||||
defPredeclaredFuncs()
|
defPredeclaredFuncs()
|
||||||
|
|
||||||
universeIota = Universe.Lookup("iota").(*Const)
|
universeIota = Universe.Lookup("iota").(*Const)
|
||||||
UniverseByte = Universe.Lookup("byte").(*TypeName).typ.(*Basic)
|
universeByte = Universe.Lookup("byte").(*TypeName).typ.(*Basic)
|
||||||
UniverseRune = Universe.Lookup("rune").(*TypeName).typ.(*Basic)
|
universeRune = Universe.Lookup("rune").(*TypeName).typ.(*Basic)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objects with names containing blanks are internal and not entered into
|
// Objects with names containing blanks are internal and not entered into
|
||||||
|
Loading…
Reference in New Issue
Block a user