1
2
3
4
5 package ir
6
7 import (
8 "cmd/internal/src"
9 )
10
11
12 func Copy(n Node) Node {
13 return n.copy()
14 }
15
16
17
18
19 func DeepCopy(pos src.XPos, n Node) Node {
20 var edit func(Node) Node
21 edit = func(x Node) Node {
22 switch x.Op() {
23 case ONAME, ONONAME, OLITERAL, ONIL, OTYPE:
24 return x
25 }
26 x = Copy(x)
27 if pos.IsKnown() {
28 x.SetPos(pos)
29 }
30 EditChildren(x, edit)
31 return x
32 }
33 return edit(n)
34 }
35
36
37 func DeepCopyList(pos src.XPos, list []Node) []Node {
38 var out []Node
39 for _, n := range list {
40 out = append(out, DeepCopy(pos, n))
41 }
42 return out
43 }
44
View as plain text