]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: generate case/comm clause functions in mknode.go
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 29 Dec 2020 16:26:45 +0000 (23:26 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 29 Dec 2020 18:29:47 +0000 (18:29 +0000)
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>
src/cmd/compile/internal/ir/mknode.go
src/cmd/compile/internal/ir/node_gen.go
src/cmd/compile/internal/ir/stmt.go

index 3b5da32d8c52e9760680c3812c1cf6a1c921ab39..17ef720172a6cc636aa429a86395c18ce7edea91 100644 (file)
@@ -136,6 +136,10 @@ func main() {
                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.
@@ -148,6 +152,40 @@ func main() {
        }
 }
 
+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)
index fe54b62f1805b16b826b4defd7f922b7744ae235..a2a30a05870a89ef532c269e1851cfca5ce9589c 100644 (file)
@@ -1015,3 +1015,61 @@ func (n *typeNode) doChildren(do func(Node) error) error {
 }
 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)
+               }
+       }
+}
index 1301e65e26922336a2dc2ea07a527097b39ac963..d88280dda767e96239f82f5744d0f29b24d2bfbe 100644 (file)
@@ -184,36 +184,6 @@ func NewCaseStmt(pos src.XPos, list, body []Node) *CaseClause {
        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
@@ -227,36 +197,6 @@ func NewCommStmt(pos src.XPos, comm Node, body []Node) *CommClause {
        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 {