From 1e05a58b11012eaa9d4021fa188c16df16b27dcc Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 25 Oct 2013 13:59:40 -0700 Subject: [PATCH] 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 --- go/types/builtins.go | 6 +++--- go/types/call.go | 2 +- go/types/conversions.go | 2 +- go/types/errors.go | 10 +++++----- go/types/expr.go | 26 +++++++++++++------------- go/types/gcimporter.go | 16 ++++++++-------- go/types/operand.go | 2 +- go/types/predicates.go | 10 +++++----- go/types/sizes.go | 6 +++--- go/types/stmt.go | 12 ++++++------ go/types/types.go | 20 ++++++++++---------- go/types/typexpr.go | 10 +++++----- 12 files changed, 61 insertions(+), 61 deletions(-) diff --git a/go/types/builtins.go b/go/types/builtins.go index 75d74c017c4..312ef39a794 100644 --- a/go/types/builtins.go +++ b/go/types/builtins.go @@ -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 { diff --git a/go/types/call.go b/go/types/call.go index f665b2cc091..2a0eec17905 100644 --- a/go/types/call.go +++ b/go/types/call.go @@ -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 { diff --git a/go/types/conversions.go b/go/types/conversions.go index c8f88437b77..3a057d6f6f0 100644 --- a/go/types/conversions.go +++ b/go/types/conversions.go @@ -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 diff --git a/go/types/errors.go b/go/types/errors.go index 7c0271d99d7..7173774afca 100644 --- a/go/types/errors.go +++ b/go/types/errors.go @@ -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 := "" diff --git a/go/types/expr.go b/go/types/expr.go index cfedd205544..b08d6eca768 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -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: diff --git a/go/types/gcimporter.go b/go/types/gcimporter.go index 51da2a68810..065b8a1b4c5 100644 --- a/go/types/gcimporter.go +++ b/go/types/gcimporter.go @@ -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 '*': diff --git a/go/types/operand.go b/go/types/operand.go index de518218a5e..57fe32f9475 100644 --- a/go/types/operand.go +++ b/go/types/operand.go @@ -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) } } diff --git a/go/types/predicates.go b/go/types/predicates.go index 67267321658..407135df653 100644 --- a/go/types/predicates.go +++ b/go/types/predicates.go @@ -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: diff --git a/go/types/sizes.go b/go/types/sizes.go index 3c378117a95..fc27481828c 100644 --- a/go/types/sizes.go +++ b/go/types/sizes.go @@ -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 diff --git a/go/types/stmt.go b/go/types/stmt.go index f11086e14d7..060b67a3a90 100644 --- a/go/types/stmt.go +++ b/go/types/stmt.go @@ -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) diff --git a/go/types/types.go b/go/types/types.go index 8b54a7fc030..b7dae86bdfa 100644 --- a/go/types/types.go +++ b/go/types/types.go @@ -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 { diff --git a/go/types/typexpr.go b/go/types/typexpr.go index f2554fbffeb..0690dba9460 100644 --- a/go/types/typexpr.go +++ b/go/types/typexpr.go @@ -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