From 88421f4cb273a62118790d1a4166031adc82ba5d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 21 Jul 2015 11:38:22 -0700 Subject: [PATCH] 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 --- go/gccgoimporter/parser.go | 4 ++-- go/importer/predefined.go | 5 +++-- go/types/builtins.go | 4 ++-- go/types/expr.go | 2 +- go/types/predicates.go | 2 +- go/types/stmt.go | 2 +- go/types/universe.go | 12 ++++++------ 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/go/gccgoimporter/parser.go b/go/gccgoimporter/parser.go index 5bd1858fb35..d20a967313f 100644 --- a/go/gccgoimporter/parser.go +++ b/go/gccgoimporter/parser.go @@ -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] } diff --git a/go/importer/predefined.go b/go/importer/predefined.go index a4db56886c9..b23dfcb4c20 100644 --- a/go/importer/predefined.go +++ b/go/importer/predefined.go @@ -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(), } diff --git a/go/types/builtins.go b/go/types/builtins.go index 3da49b92ce7..f45f930a42d 100644 --- a/go/types/builtins.go +++ b/go/types/builtins.go @@ -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 diff --git a/go/types/expr.go b/go/types/expr.go index 78b14e07e78..6efc7b4309d 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -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: diff --git a/go/types/predicates.go b/go/types/predicates.go index b5c39d9d167..993c6d290b1 100644 --- a/go/types/predicates.go +++ b/go/types/predicates.go @@ -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: diff --git a/go/types/stmt.go b/go/types/stmt.go index 0aafb30efb4..eeb2c31730c 100644 --- a/go/types/stmt.go +++ b/go/types/stmt.go @@ -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] diff --git a/go/types/universe.go b/go/types/universe.go index 472c6bef1ac..12a34ef8539 100644 --- a/go/types/universe.go +++ b/go/types/universe.go @@ -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