Commit b6adb327 authored by Robert Griesemer's avatar Robert Griesemer

simplify some code that is using vectors

R=agl, agl1
CC=golang-dev
https://golang.org/cl/181080
parent 3c6bf095
...@@ -170,9 +170,9 @@ func (p *parser) consumeCommentGroup() int { ...@@ -170,9 +170,9 @@ func (p *parser) consumeCommentGroup() int {
} }
// convert list // convert list
group := make([]*ast.Comment, list.Len()) group := make([]*ast.Comment, len(list))
for i := 0; i < list.Len(); i++ { for i, x := range list {
group[i] = list.At(i).(*ast.Comment) group[i] = x.(*ast.Comment)
} }
// add comment group to the comments list // add comment group to the comments list
...@@ -321,9 +321,9 @@ func (p *parser) parseIdentList() []*ast.Ident { ...@@ -321,9 +321,9 @@ func (p *parser) parseIdentList() []*ast.Ident {
} }
// convert vector // convert vector
idents := make([]*ast.Ident, list.Len()) idents := make([]*ast.Ident, len(list))
for i := 0; i < list.Len(); i++ { for i, x := range list {
idents[i] = list.At(i).(*ast.Ident) idents[i] = x.(*ast.Ident)
} }
return idents return idents
...@@ -331,9 +331,9 @@ func (p *parser) parseIdentList() []*ast.Ident { ...@@ -331,9 +331,9 @@ func (p *parser) parseIdentList() []*ast.Ident {
func makeExprList(list *vector.Vector) []ast.Expr { func makeExprList(list *vector.Vector) []ast.Expr {
exprs := make([]ast.Expr, list.Len()) exprs := make([]ast.Expr, len(*list))
for i := 0; i < list.Len(); i++ { for i, x := range *list {
exprs[i] = list.At(i).(ast.Expr) exprs[i] = x.(ast.Expr)
} }
return exprs return exprs
} }
...@@ -421,11 +421,11 @@ func (p *parser) parseArrayType(ellipsisOk bool) ast.Expr { ...@@ -421,11 +421,11 @@ func (p *parser) parseArrayType(ellipsisOk bool) ast.Expr {
func (p *parser) makeIdentList(list *vector.Vector) []*ast.Ident { func (p *parser) makeIdentList(list *vector.Vector) []*ast.Ident {
idents := make([]*ast.Ident, list.Len()) idents := make([]*ast.Ident, len(*list))
for i := 0; i < list.Len(); i++ { for i, x := range *list {
ident, isIdent := list.At(i).(*ast.Ident) ident, isIdent := x.(*ast.Ident)
if !isIdent { if !isIdent {
pos := list.At(i).(ast.Expr).Pos() pos := x.(ast.Expr).Pos()
p.errorExpected(pos, "identifier") p.errorExpected(pos, "identifier")
idents[i] = &ast.Ident{pos, ""} idents[i] = &ast.Ident{pos, ""}
} }
...@@ -471,7 +471,7 @@ func (p *parser) parseFieldDecl() *ast.Field { ...@@ -471,7 +471,7 @@ func (p *parser) parseFieldDecl() *ast.Field {
idents = p.makeIdentList(&list) idents = p.makeIdentList(&list)
} else { } else {
// Type (anonymous field) // Type (anonymous field)
if list.Len() == 1 { if len(list) == 1 {
// TODO(gri): check that this looks like a type // TODO(gri): check that this looks like a type
typ = list.At(0).(ast.Expr) typ = list.At(0).(ast.Expr)
} else { } else {
...@@ -500,9 +500,9 @@ func (p *parser) parseStructType() *ast.StructType { ...@@ -500,9 +500,9 @@ func (p *parser) parseStructType() *ast.StructType {
rbrace := p.expect(token.RBRACE) rbrace := p.expect(token.RBRACE)
// convert vector // convert vector
fields := make([]*ast.Field, list.Len()) fields := make([]*ast.Field, len(list))
for i := list.Len() - 1; i >= 0; i-- { for i, x := range list {
fields[i] = list.At(i).(*ast.Field) fields[i] = x.(*ast.Field)
} }
return &ast.StructType{pos, lbrace, fields, rbrace, false} return &ast.StructType{pos, lbrace, fields, rbrace, false}
...@@ -597,15 +597,15 @@ func (p *parser) parseParameterList(ellipsisOk bool) []*ast.Field { ...@@ -597,15 +597,15 @@ func (p *parser) parseParameterList(ellipsisOk bool) []*ast.Field {
} else { } else {
// Type { "," Type } (anonymous parameters) // Type { "," Type } (anonymous parameters)
// convert list of types into list of *Param // convert list of types into list of *Param
for i := 0; i < list.Len(); i++ { for i, x := range *list {
list.Set(i, &ast.Field{Type: list.At(i).(ast.Expr)}) list.Set(i, &ast.Field{Type: x.(ast.Expr)})
} }
} }
// convert list // convert list
params := make([]*ast.Field, list.Len()) params := make([]*ast.Field, len(*list))
for i := 0; i < list.Len(); i++ { for i, x := range *list {
params[i] = list.At(i).(*ast.Field) params[i] = x.(*ast.Field)
} }
return params return params
...@@ -710,9 +710,9 @@ func (p *parser) parseInterfaceType() *ast.InterfaceType { ...@@ -710,9 +710,9 @@ func (p *parser) parseInterfaceType() *ast.InterfaceType {
rbrace := p.expect(token.RBRACE) rbrace := p.expect(token.RBRACE)
// convert vector // convert vector
methods := make([]*ast.Field, list.Len()) methods := make([]*ast.Field, len(list))
for i := list.Len() - 1; i >= 0; i-- { for i, x := range list {
methods[i] = list.At(i).(*ast.Field) methods[i] = x.(*ast.Field)
} }
return &ast.InterfaceType{pos, lbrace, methods, rbrace, false} return &ast.InterfaceType{pos, lbrace, methods, rbrace, false}
...@@ -796,9 +796,9 @@ func (p *parser) tryType() ast.Expr { return p.tryRawType(false) } ...@@ -796,9 +796,9 @@ func (p *parser) tryType() ast.Expr { return p.tryRawType(false) }
// Blocks // Blocks
func makeStmtList(list *vector.Vector) []ast.Stmt { func makeStmtList(list *vector.Vector) []ast.Stmt {
stats := make([]ast.Stmt, list.Len()) stats := make([]ast.Stmt, len(*list))
for i := 0; i < list.Len(); i++ { for i, x := range *list {
stats[i] = list.At(i).(ast.Stmt) stats[i] = x.(ast.Stmt)
} }
return stats return stats
} }
...@@ -1792,9 +1792,9 @@ func (p *parser) parseGenDecl(keyword token.Token, f parseSpecFunction) *ast.Gen ...@@ -1792,9 +1792,9 @@ func (p *parser) parseGenDecl(keyword token.Token, f parseSpecFunction) *ast.Gen
} }
// convert vector // convert vector
specs := make([]ast.Spec, list.Len()) specs := make([]ast.Spec, len(list))
for i := 0; i < list.Len(); i++ { for i, x := range list {
specs[i] = list.At(i).(ast.Spec) specs[i] = x.(ast.Spec)
} }
return &ast.GenDecl{doc, pos, keyword, lparen, specs, rparen} return &ast.GenDecl{doc, pos, keyword, lparen, specs, rparen}
...@@ -1898,9 +1898,9 @@ func (p *parser) parseDeclList() []ast.Decl { ...@@ -1898,9 +1898,9 @@ func (p *parser) parseDeclList() []ast.Decl {
} }
// convert vector // convert vector
decls := make([]ast.Decl, list.Len()) decls := make([]ast.Decl, len(list))
for i := 0; i < list.Len(); i++ { for i, x := range list {
decls[i] = list.At(i).(ast.Decl) decls[i] = x.(ast.Decl)
} }
return decls return decls
...@@ -1944,9 +1944,9 @@ func (p *parser) parseFile() *ast.File { ...@@ -1944,9 +1944,9 @@ func (p *parser) parseFile() *ast.File {
} }
// convert declaration list // convert declaration list
decls = make([]ast.Decl, list.Len()) decls = make([]ast.Decl, len(list))
for i := 0; i < list.Len(); i++ { for i, x := range list {
decls[i] = list.At(i).(ast.Decl) decls[i] = x.(ast.Decl)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment