From f8077d9fc4a2840a287bb5c9715a99a7ae0670c6 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 22 Jan 2024 13:04:23 -0500 Subject: [PATCH] lang: ast: Add a util function for node map copying --- lang/ast/structs.go | 10 +--------- lang/ast/util.go | 9 +++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lang/ast/structs.go b/lang/ast/structs.go index 0d6906bf..b9887374 100644 --- a/lang/ast/structs.go +++ b/lang/ast/structs.go @@ -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 { diff --git a/lang/ast/util.go b/lang/ast/util.go index 5cc9ce99..6cea932e 100644 --- a/lang/ast/util.go +++ b/lang/ast/util.go @@ -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 +}