}
// convert list
- group := make([]*ast.Comment, list.Len())
- for i := 0; i < list.Len(); i++ {
- group[i] = list.At(i).(*ast.Comment)
+ group := make([]*ast.Comment, len(list))
+ for i, x := range list {
+ group[i] = x.(*ast.Comment)
}
// add comment group to the comments list
}
// convert vector
- idents := make([]*ast.Ident, list.Len())
- for i := 0; i < list.Len(); i++ {
- idents[i] = list.At(i).(*ast.Ident)
+ idents := make([]*ast.Ident, len(list))
+ for i, x := range list {
+ idents[i] = x.(*ast.Ident)
}
return idents
func makeExprList(list *vector.Vector) []ast.Expr {
- exprs := make([]ast.Expr, list.Len())
- for i := 0; i < list.Len(); i++ {
- exprs[i] = list.At(i).(ast.Expr)
+ exprs := make([]ast.Expr, len(*list))
+ for i, x := range *list {
+ exprs[i] = x.(ast.Expr)
}
return exprs
}
func (p *parser) makeIdentList(list *vector.Vector) []*ast.Ident {
- idents := make([]*ast.Ident, list.Len())
- for i := 0; i < list.Len(); i++ {
- ident, isIdent := list.At(i).(*ast.Ident)
+ idents := make([]*ast.Ident, len(*list))
+ for i, x := range *list {
+ ident, isIdent := x.(*ast.Ident)
if !isIdent {
- pos := list.At(i).(ast.Expr).Pos()
+ pos := x.(ast.Expr).Pos()
p.errorExpected(pos, "identifier")
idents[i] = &ast.Ident{pos, ""}
}
idents = p.makeIdentList(&list)
} else {
// Type (anonymous field)
- if list.Len() == 1 {
+ if len(list) == 1 {
// TODO(gri): check that this looks like a type
typ = list.At(0).(ast.Expr)
} else {
rbrace := p.expect(token.RBRACE)
// convert vector
- fields := make([]*ast.Field, list.Len())
- for i := list.Len() - 1; i >= 0; i-- {
- fields[i] = list.At(i).(*ast.Field)
+ fields := make([]*ast.Field, len(list))
+ for i, x := range list {
+ fields[i] = x.(*ast.Field)
}
return &ast.StructType{pos, lbrace, fields, rbrace, false}
} else {
// Type { "," Type } (anonymous parameters)
// convert list of types into list of *Param
- for i := 0; i < list.Len(); i++ {
- list.Set(i, &ast.Field{Type: list.At(i).(ast.Expr)})
+ for i, x := range *list {
+ list.Set(i, &ast.Field{Type: x.(ast.Expr)})
}
}
// convert list
- params := make([]*ast.Field, list.Len())
- for i := 0; i < list.Len(); i++ {
- params[i] = list.At(i).(*ast.Field)
+ params := make([]*ast.Field, len(*list))
+ for i, x := range *list {
+ params[i] = x.(*ast.Field)
}
return params
rbrace := p.expect(token.RBRACE)
// convert vector
- methods := make([]*ast.Field, list.Len())
- for i := list.Len() - 1; i >= 0; i-- {
- methods[i] = list.At(i).(*ast.Field)
+ methods := make([]*ast.Field, len(list))
+ for i, x := range list {
+ methods[i] = x.(*ast.Field)
}
return &ast.InterfaceType{pos, lbrace, methods, rbrace, false}
// Blocks
func makeStmtList(list *vector.Vector) []ast.Stmt {
- stats := make([]ast.Stmt, list.Len())
- for i := 0; i < list.Len(); i++ {
- stats[i] = list.At(i).(ast.Stmt)
+ stats := make([]ast.Stmt, len(*list))
+ for i, x := range *list {
+ stats[i] = x.(ast.Stmt)
}
return stats
}
}
// convert vector
- specs := make([]ast.Spec, list.Len())
- for i := 0; i < list.Len(); i++ {
- specs[i] = list.At(i).(ast.Spec)
+ specs := make([]ast.Spec, len(list))
+ for i, x := range list {
+ specs[i] = x.(ast.Spec)
}
return &ast.GenDecl{doc, pos, keyword, lparen, specs, rparen}
}
// convert vector
- decls := make([]ast.Decl, list.Len())
- for i := 0; i < list.Len(); i++ {
- decls[i] = list.At(i).(ast.Decl)
+ decls := make([]ast.Decl, len(list))
+ for i, x := range list {
+ decls[i] = x.(ast.Decl)
}
return decls
}
// convert declaration list
- decls = make([]ast.Decl, list.Len())
- for i := 0; i < list.Len(); i++ {
- decls[i] = list.At(i).(ast.Decl)
+ decls = make([]ast.Decl, len(list))
+ for i, x := range list {
+ decls[i] = x.(ast.Decl)
}
}