| 1 | // Copyright 2024 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package astutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/ |
| 6 | |
| 7 | import ( |
| 8 | "go/astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/" |
| 9 | "iterscip-go gomod github.com/golang/go/src go1.25.0 iter/" |
| 10 | ) |
| 11 | |
| 12 | // FlatFields 'flattens' an ast.FieldList, returning an iterator over each |
| 13 | // (name, field) combination in the list. For unnamed fields, the identifier is |
| 14 | // nil. |
| 15 | func FlatFieldsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/astutil`/FlatFields().(list *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.FieldListscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/FieldList#) iterscip-go gomod github.com/golang/go/src go1.25.0 iter/.Seq2scip-go gomod github.com/golang/go/src go1.25.0 iter/Seq2#[*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Identscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Ident#, *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Fieldscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Field#] { |
| 16 | return func(yield func(*astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Identscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Ident#, *astscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/.Fieldscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Field#) bool) { |
| 17 | if list == nil { |
| 18 | return |
| 19 | } |
| 20 | |
| 21 | for _, field := range list.Listscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/FieldList#List. { |
| 22 | if len(field.Namesscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Field#Names.) == 0 { |
| 23 | if !yield(nil, field) { |
| 24 | return |
| 25 | } |
| 26 | } else { |
| 27 | for _, name := range field.Namesscip-go gomod github.com/golang/go/src go1.25.0 `go/ast`/Field#Names. { |
| 28 | if !yield(name, field) { |
| 29 | return |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | } |