lang: ast: Add a util function for node map copying
This commit is contained in:
@@ -3125,15 +3125,7 @@ func (obj *StmtProg) Ordering(produces map[string]interfaces.Node) (*pgraph.Grap
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move to a util package?
|
||||
cp := func(in map[string]interfaces.Node) map[string]interfaces.Node {
|
||||
out := make(map[string]interfaces.Node)
|
||||
for k, v := range in {
|
||||
out[k] = v // copy the map, not the Node's
|
||||
}
|
||||
return out
|
||||
}
|
||||
newProduces := cp(produces) // don't modify the input map!
|
||||
newProduces := CopyNodeMapping(produces) // don't modify the input map!
|
||||
|
||||
// Overwrite anything in this scope with the shadowed parent variable!
|
||||
for key, val := range prod {
|
||||
|
||||
@@ -265,3 +265,12 @@ func CollectFiles(ast interfaces.Stmt) ([]string, error) {
|
||||
}
|
||||
return fileList, nil
|
||||
}
|
||||
|
||||
// CopyNodeMapping copies the map of string to node and is used in Ordering.
|
||||
func CopyNodeMapping(in map[string]interfaces.Node) map[string]interfaces.Node {
|
||||
out := make(map[string]interfaces.Node)
|
||||
for k, v := range in {
|
||||
out[k] = v // copy the map, not the Node's
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user