Passes toolstash -cmp.
Change-Id: I52e9d6f35f22d5d59ac6aad02011c5abaac45739
Reviewed-on: https://go-review.googlesource.com/c/go/+/279446
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
fmt.Fprintf(&buf, "}\n")
}
+ for _, name := range []string{"CaseClause", "CommClause"} {
+ sliceHelper(&buf, name)
+ }
+
out, err := format.Source(buf.Bytes())
if err != nil {
// write out mangled source so we can see the bug.
}
}
+func sliceHelper(buf *bytes.Buffer, name string) {
+ tmpl := fmt.Sprintf(`
+func copy%[1]ss(list []*%[2]s) []*%[2]s {
+ if list == nil {
+ return nil
+ }
+ c := make([]*%[2]s, len(list))
+ copy(c, list)
+ return c
+}
+func maybeDo%[1]ss(list []*%[2]s, err error, do func(Node) error) error {
+ if err != nil {
+ return err
+ }
+ for _, x := range list {
+ if x != nil {
+ if err := do(x); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+func edit%[1]ss(list []*%[2]s, edit func(Node) Node) {
+ for i, x := range list {
+ if x != nil {
+ list[i] = edit(x).(*%[2]s)
+ }
+ }
+}
+`, strings.TrimSuffix(name, "Clause"), name)
+ fmt.Fprintln(buf, tmpl)
+}
+
func forNodeFields(typName string, typ *types.Struct, f func(name string, is func(types.Type) bool)) {
for i, n := 0, typ.NumFields(); i < n; i++ {
v := typ.Field(i)
}
func (n *typeNode) editChildren(edit func(Node) Node) {
}
+
+func copyCases(list []*CaseClause) []*CaseClause {
+ if list == nil {
+ return nil
+ }
+ c := make([]*CaseClause, len(list))
+ copy(c, list)
+ return c
+}
+func maybeDoCases(list []*CaseClause, err error, do func(Node) error) error {
+ if err != nil {
+ return err
+ }
+ for _, x := range list {
+ if x != nil {
+ if err := do(x); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+func editCases(list []*CaseClause, edit func(Node) Node) {
+ for i, x := range list {
+ if x != nil {
+ list[i] = edit(x).(*CaseClause)
+ }
+ }
+}
+
+func copyComms(list []*CommClause) []*CommClause {
+ if list == nil {
+ return nil
+ }
+ c := make([]*CommClause, len(list))
+ copy(c, list)
+ return c
+}
+func maybeDoComms(list []*CommClause, err error, do func(Node) error) error {
+ if err != nil {
+ return err
+ }
+ for _, x := range list {
+ if x != nil {
+ if err := do(x); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+func editComms(list []*CommClause, edit func(Node) Node) {
+ for i, x := range list {
+ if x != nil {
+ list[i] = edit(x).(*CommClause)
+ }
+ }
+}
return n
}
-// TODO(mdempsky): Generate these with mknode.go.
-func copyCases(list []*CaseClause) []*CaseClause {
- if list == nil {
- return nil
- }
- c := make([]*CaseClause, len(list))
- copy(c, list)
- return c
-}
-func maybeDoCases(list []*CaseClause, err error, do func(Node) error) error {
- if err != nil {
- return err
- }
- for _, x := range list {
- if x != nil {
- if err := do(x); err != nil {
- return err
- }
- }
- }
- return nil
-}
-func editCases(list []*CaseClause, edit func(Node) Node) {
- for i, x := range list {
- if x != nil {
- list[i] = edit(x).(*CaseClause)
- }
- }
-}
-
type CommClause struct {
miniStmt
Comm Node // communication case
return n
}
-// TODO(mdempsky): Generate these with mknode.go.
-func copyComms(list []*CommClause) []*CommClause {
- if list == nil {
- return nil
- }
- c := make([]*CommClause, len(list))
- copy(c, list)
- return c
-}
-func maybeDoComms(list []*CommClause, err error, do func(Node) error) error {
- if err != nil {
- return err
- }
- for _, x := range list {
- if x != nil {
- if err := do(x); err != nil {
- return err
- }
- }
- }
- return nil
-}
-func editComms(list []*CommClause, edit func(Node) Node) {
- for i, x := range list {
- if x != nil {
- list[i] = edit(x).(*CommClause)
- }
- }
-}
-
// A ForStmt is a non-range for loop: for Init; Cond; Post { Body }
// Op can be OFOR or OFORUNTIL (!Cond).
type ForStmt struct {