From b9c4780f07d31d7b92d331ffd46e0807de37c54f Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 3 May 2018 11:53:06 -0700 Subject: [PATCH] addrs: Helper methods for converting module calls to absolute modules --- addrs/module_call.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addrs/module_call.go b/addrs/module_call.go index bbbd76685..09596cc84 100644 --- a/addrs/module_call.go +++ b/addrs/module_call.go @@ -43,6 +43,14 @@ func (c ModuleCallInstance) String() string { return fmt.Sprintf("module.%s%s", c.Call.Name, c.Key) } +// ModuleInstance returns the address of the module instance that corresponds +// to the receiving call instance when resolved in the given calling module. +// In other words, it returns the child module instance that the receving +// call instance creates. +func (c ModuleCallInstance) ModuleInstance(caller ModuleInstance) ModuleInstance { + return caller.Child(c.Call.Name, c.Key) +} + // Output returns the address of an output of the receiver identified by its // name. func (c ModuleCallInstance) Output(name string) ModuleCallOutput { @@ -63,3 +71,11 @@ type ModuleCallOutput struct { func (co ModuleCallOutput) String() string { return fmt.Sprintf("%s.%s", co.Call.String(), co.Name) } + +// AbsOutputValue returns the absolute output value address that corresponds +// to the receving module call output address, once resolved in the given +// calling module. +func (co ModuleCallOutput) AbsOutputValue(caller ModuleInstance) AbsOutputValue { + moduleAddr := co.Call.ModuleInstance(caller) + return moduleAddr.OutputValue(co.Name) +}