1
0
mirror of https://github.com/golang/go synced 2024-11-19 00:44:40 -07:00

go.tools/go/types: consistently use 'elem' instead of 'elt'

This is simply a rename of unexported struct fields.
No other changes.

R=adonovan
CC=golang-dev
https://golang.org/cl/17330043
This commit is contained in:
Robert Griesemer 2013-10-25 13:59:40 -07:00
parent cf08eefe7f
commit 1e05a58b11
12 changed files with 61 additions and 61 deletions

View File

@ -69,7 +69,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
S := x.typ
var T Type
if s, _ := S.Underlying().(*Slice); s != nil {
T = s.elt
T = s.elem
} else {
check.invalidArg(x.pos(), "%s is not a slice", x)
return
@ -262,7 +262,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
// copy(x, y []T) int
var dst Type
if t, _ := x.typ.Underlying().(*Slice); t != nil {
dst = t.elt
dst = t.elem
}
var y operand
@ -277,7 +277,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
src = Typ[Byte]
}
case *Slice:
src = t.elt
src = t.elem
}
if dst == nil || src == nil {

View File

@ -237,7 +237,7 @@ func (check *checker) argument(sig *Signature, i int, x *operand, passSlice bool
}
} else if sig.isVariadic && i >= n-1 {
// use the variadic parameter slice's element type
typ = typ.(*Slice).elt
typ = typ.(*Slice).elem
}
if !check.assignment(x, typ) && x.mode != invalid {

View File

@ -135,7 +135,7 @@ func isPointer(typ Type) bool {
func isBytesOrRunes(typ Type) bool {
if s, ok := typ.(*Slice); ok {
t, ok := s.elt.Underlying().(*Basic)
t, ok := s.elem.Underlying().(*Basic)
return ok && (t.kind == Byte || t.kind == Rune)
}
return false

View File

@ -193,7 +193,7 @@ func writeTuple(buf *bytes.Buffer, tup *Tuple, isVariadic bool) {
typ := v.typ
if isVariadic && i == len(tup.vars)-1 {
buf.WriteString("...")
typ = typ.(*Slice).elt
typ = typ.(*Slice).elem
}
writeType(buf, typ)
}
@ -231,11 +231,11 @@ func writeType(buf *bytes.Buffer, typ Type) {
case *Array:
fmt.Fprintf(buf, "[%d]", t.len)
writeType(buf, t.elt)
writeType(buf, t.elem)
case *Slice:
buf.WriteString("[]")
writeType(buf, t.elt)
writeType(buf, t.elem)
case *Struct:
buf.WriteString("struct{")
@ -300,7 +300,7 @@ func writeType(buf *bytes.Buffer, typ Type) {
buf.WriteString("map[")
writeType(buf, t.key)
buf.WriteByte(']')
writeType(buf, t.elt)
writeType(buf, t.elem)
case *Chan:
var s string
@ -313,7 +313,7 @@ func writeType(buf *bytes.Buffer, typ Type) {
s = "chan "
}
buf.WriteString(s)
writeType(buf, t.elt)
writeType(buf, t.elem)
case *Named:
s := "<Named w/o object>"

View File

@ -108,7 +108,7 @@ func (check *checker) unary(x *operand, op token.Token) {
return
}
x.mode = commaok
x.typ = typ.elt
x.typ = typ.elem
return
}
@ -987,7 +987,7 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
// We have an "open" [...]T array type.
// Create a new ArrayType with unknown length (-1)
// and finish setting it up after analyzing the literal.
typ = &Array{len: -1, elt: check.typ(atyp.Elt, nil, false)}
typ = &Array{len: -1, elem: check.typ(atyp.Elt, nil, false)}
openArray = true
}
}
@ -1070,14 +1070,14 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
}
case *Array:
n := check.indexedElts(e.Elts, utyp.elt, utyp.len)
n := check.indexedElts(e.Elts, utyp.elem, utyp.len)
// if we have an "open" [...]T array, set the length now that we know it
if openArray {
utyp.len = n
}
case *Slice:
check.indexedElts(e.Elts, utyp.elt, -1)
check.indexedElts(e.Elts, utyp.elem, -1)
case *Map:
visited := make(map[interface{}]bool, len(e.Elts))
@ -1101,10 +1101,10 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
}
visited[x.val] = true
}
check.exprWithHint(x, kv.Value, utyp.elt)
if !check.assignment(x, utyp.elt) {
check.exprWithHint(x, kv.Value, utyp.elem)
if !check.assignment(x, utyp.elem) {
if x.mode != invalid {
check.errorf(x.pos(), "cannot use %s as %s value in map literal", x, utyp.elt)
check.errorf(x.pos(), "cannot use %s as %s value in map literal", x, utyp.elem)
}
continue
}
@ -1154,20 +1154,20 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
if x.mode != variable {
x.mode = value
}
x.typ = typ.elt
x.typ = typ.elem
case *Pointer:
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
valid = true
length = typ.len
x.mode = variable
x.typ = typ.elt
x.typ = typ.elem
}
case *Slice:
valid = true
x.mode = variable
x.typ = typ.elt
x.typ = typ.elem
case *Map:
var key operand
@ -1179,7 +1179,7 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
goto Error
}
x.mode = mapindex
x.typ = typ.elt
x.typ = typ.elem
x.expr = e
return expression
}
@ -1231,14 +1231,14 @@ func (check *checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
check.invalidOp(x.pos(), "cannot slice %s (value not addressable)", x)
goto Error
}
x.typ = &Slice{elt: typ.elt}
x.typ = &Slice{elem: typ.elem}
case *Pointer:
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
valid = true
length = typ.len
x.mode = variable
x.typ = &Slice{elt: typ.elt}
x.typ = &Slice{elem: typ.elem}
}
case *Slice:

View File

@ -415,12 +415,12 @@ func (p *gcParser) parseArrayType() Type {
// "[" already consumed and lookahead known not to be "]"
lit := p.expect(scanner.Int)
p.expect(']')
elt := p.parseType()
elem := p.parseType()
n, err := strconv.ParseInt(lit, 10, 64)
if err != nil {
p.error(err)
}
return &Array{len: n, elt: elt}
return &Array{len: n, elem: elem}
}
// MapType = "map" "[" Type "]" Type .
@ -430,8 +430,8 @@ func (p *gcParser) parseMapType() Type {
p.expect('[')
key := p.parseType()
p.expect(']')
elt := p.parseType()
return &Map{key: key, elt: elt}
elem := p.parseType()
return &Map{key: key, elem: elem}
}
// Name = identifier | "?" | QualifiedName .
@ -550,7 +550,7 @@ func (p *gcParser) parseParameter() (par *Var, isVariadic bool) {
}
typ := p.parseType()
if isVariadic {
typ = &Slice{elt: typ}
typ = &Slice{elem: typ}
}
// ignore argument tag (e.g. "noescape")
if p.tok == scanner.String {
@ -657,8 +657,8 @@ func (p *gcParser) parseChanType() Type {
p.expectKeyword("chan")
dir = ast.RECV
}
elt := p.parseType()
return &Chan{dir: dir, elt: elt}
elem := p.parseType()
return &Chan{dir: dir, elem: elem}
}
// Type =
@ -700,7 +700,7 @@ func (p *gcParser) parseType() Type {
if p.tok == ']' {
// SliceType
p.next()
return &Slice{elt: p.parseType()}
return &Slice{elem: p.parseType()}
}
return p.parseArrayType()
case '*':

View File

@ -232,7 +232,7 @@ func (x *operand) isAssignableTo(conf *Config, T Type) bool {
// type, x's type V and T have identical element types,
// and at least one of V or T is not a named type
if Vc, ok := Vu.(*Chan); ok && Vc.dir == ast.SEND|ast.RECV {
if Tc, ok := Tu.(*Chan); ok && IsIdentical(Vc.elt, Tc.elt) {
if Tc, ok := Tu.(*Chan); ok && IsIdentical(Vc.elem, Tc.elem) {
return !isNamed(V) || !isNamed(T)
}
}

View File

@ -90,7 +90,7 @@ func isComparable(typ Type) bool {
}
return true
case *Array:
return isComparable(t.elt)
return isComparable(t.elem)
}
return false
}
@ -139,13 +139,13 @@ func isIdenticalInternal(x, y Type, p *ifacePair) bool {
// Two array types are identical if they have identical element types
// and the same array length.
if y, ok := y.(*Array); ok {
return x.len == y.len && isIdenticalInternal(x.elt, y.elt, p)
return x.len == y.len && isIdenticalInternal(x.elem, y.elem, p)
}
case *Slice:
// Two slice types are identical if they have identical element types.
if y, ok := y.(*Slice); ok {
return isIdenticalInternal(x.elt, y.elt, p)
return isIdenticalInternal(x.elem, y.elem, p)
}
case *Struct:
@ -256,14 +256,14 @@ func isIdenticalInternal(x, y Type, p *ifacePair) bool {
case *Map:
// Two map types are identical if they have identical key and value types.
if y, ok := y.(*Map); ok {
return isIdenticalInternal(x.key, y.key, p) && isIdenticalInternal(x.elt, y.elt, p)
return isIdenticalInternal(x.key, y.key, p) && isIdenticalInternal(x.elem, y.elem, p)
}
case *Chan:
// Two channel types are identical if they have identical value types
// and the same direction.
if y, ok := y.(*Chan); ok {
return x.dir == y.dir && isIdenticalInternal(x.elt, y.elt, p)
return x.dir == y.dir && isIdenticalInternal(x.elem, y.elem, p)
}
case *Named:

View File

@ -46,7 +46,7 @@ func (s *StdSizes) Alignof(T Type) int64 {
case *Array:
// spec: "For a variable x of array type: unsafe.Alignof(x)
// is the same as unsafe.Alignof(x[0]), but at least 1."
return s.Alignof(t.elt)
return s.Alignof(t.elem)
case *Struct:
// spec: "For a variable x of struct type: unsafe.Alignof(x)
// is the largest of the values unsafe.Alignof(x.f) for each
@ -92,8 +92,8 @@ func (s *StdSizes) Sizeof(T Type) int64 {
return s.WordSize * 2
}
case *Array:
a := s.Alignof(t.elt)
z := s.Sizeof(t.elt)
a := s.Alignof(t.elem)
z := s.Sizeof(t.elem)
return align(z, a) * t.len // may be 0
case *Slice:
return s.WordSize * 3

View File

@ -202,7 +202,7 @@ func (check *checker) stmt(ctxt stmtContext, s ast.Stmt) {
if ch.mode == invalid || x.mode == invalid {
return
}
if tch, ok := ch.typ.Underlying().(*Chan); !ok || tch.dir&ast.SEND == 0 || !check.assignment(&x, tch.elt) {
if tch, ok := ch.typ.Underlying().(*Chan); !ok || tch.dir&ast.SEND == 0 || !check.assignment(&x, tch.elem) {
if x.mode != invalid {
check.invalidOp(ch.pos(), "cannot send %s to channel %s", &x, &ch)
}
@ -524,20 +524,20 @@ func (check *checker) stmt(ctxt stmtContext, s ast.Stmt) {
}
case *Array:
key = Typ[Int]
val = typ.elt
val = typ.elem
case *Slice:
key = Typ[Int]
val = typ.elt
val = typ.elem
case *Pointer:
if typ, _ := typ.base.Underlying().(*Array); typ != nil {
key = Typ[Int]
val = typ.elt
val = typ.elem
}
case *Map:
key = typ.key
val = typ.elt
val = typ.elem
case *Chan:
key = typ.elt
key = typ.elem
val = Typ[Invalid]
if typ.dir&ast.RECV == 0 {
check.errorf(x.pos(), "cannot range over send-only channel %s", &x)

View File

@ -101,8 +101,8 @@ func (b *Basic) Name() string { return b.name }
// An Array represents an array type.
type Array struct {
len int64
elt Type
len int64
elem Type
}
// NewArray returns a new array type for the given element type and length.
@ -112,18 +112,18 @@ func NewArray(elem Type, len int64) *Array { return &Array{len, elem} }
func (a *Array) Len() int64 { return a.len }
// Elem returns element type of array a.
func (a *Array) Elem() Type { return a.elt }
func (a *Array) Elem() Type { return a.elem }
// A Slice represents a slice type.
type Slice struct {
elt Type
elem Type
}
// NewSlice returns a new slice type for the given element type.
func NewSlice(elem Type) *Slice { return &Slice{elem} }
// Elem returns the element type of slice s.
func (s *Slice) Elem() Type { return s.elt }
func (s *Slice) Elem() Type { return s.elem }
// A Struct represents a struct type.
type Struct struct {
@ -263,7 +263,7 @@ func (t *Interface) Method(i int) *Func { return t.allMethods[i] }
// A Map represents a map type.
type Map struct {
key, elt Type
key, elem Type
}
// NewMap returns a new map for the given key and element types.
@ -275,12 +275,12 @@ func NewMap(key, elem Type) *Map {
func (m *Map) Key() Type { return m.key }
// Elem returns the element type of map m.
func (m *Map) Elem() Type { return m.elt }
func (m *Map) Elem() Type { return m.elem }
// A Chan represents a channel type.
type Chan struct {
dir ast.ChanDir
elt Type
dir ast.ChanDir
elem Type
}
// NewChan returns a new channel type for the given direction and element type.
@ -292,7 +292,7 @@ func NewChan(dir ast.ChanDir, elem Type) *Chan {
func (c *Chan) Dir() ast.ChanDir { return c.dir }
// Elem returns the element type of channel c.
func (c *Chan) Elem() Type { return c.elt }
func (c *Chan) Elem() Type { return c.elem }
// A Named represents a named type.
type Named struct {

View File

@ -265,7 +265,7 @@ func (check *checker) typInternal(e ast.Expr, def *Named, cycleOk bool) Type {
}
typ.len = n
typ.elt = check.typ(e.Elt, nil, cycleOk)
typ.elem = check.typ(e.Elt, nil, cycleOk)
return typ
} else {
@ -274,7 +274,7 @@ func (check *checker) typInternal(e ast.Expr, def *Named, cycleOk bool) Type {
def.underlying = typ
}
typ.elt = check.typ(e.Elt, nil, true)
typ.elem = check.typ(e.Elt, nil, true)
return typ
}
@ -309,7 +309,7 @@ func (check *checker) typInternal(e ast.Expr, def *Named, cycleOk bool) Type {
}
typ.key = check.typ(e.Key, nil, true)
typ.elt = check.typ(e.Value, nil, true)
typ.elem = check.typ(e.Value, nil, true)
// spec: "The comparison operators == and != must be fully defined
// for operands of the key type; thus the key type must not be a
@ -329,7 +329,7 @@ func (check *checker) typInternal(e ast.Expr, def *Named, cycleOk bool) Type {
}
typ.dir = e.Dir
typ.elt = check.typ(e.Value, nil, true)
typ.elem = check.typ(e.Value, nil, true)
return typ
default:
@ -401,7 +401,7 @@ func (check *checker) collectParams(scope *Scope, list *ast.FieldList, variadicO
// For a variadic function, change the last parameter's type from T to []T.
if isVariadic && len(params) > 0 {
last := params[len(params)-1]
last.typ = &Slice{elt: last.typ}
last.typ = &Slice{elem: last.typ}
}
return