Make modules targetable
This commit is contained in:
parent
50077eabe9
commit
7407fee9c2
|
@ -44,6 +44,56 @@ func (m Module) Equal(other Module) bool {
|
||||||
return m.String() == other.String()
|
return m.String() == other.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Module) targetableSigil() {
|
||||||
|
// Module is targetable
|
||||||
|
}
|
||||||
|
|
||||||
|
// TargetContains implements Targetable for Module by returning true if the given other
|
||||||
|
// address either matches the receiver, is a sub-module-instance of the
|
||||||
|
// receiver, or is a targetable absolute address within a module that
|
||||||
|
// is contained within the receiver.
|
||||||
|
func (m Module) TargetContains(other Targetable) bool {
|
||||||
|
switch to := other.(type) {
|
||||||
|
|
||||||
|
case Module:
|
||||||
|
if len(to) < len(m) {
|
||||||
|
// Can't be contained if the path is shorter
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// Other is contained if its steps match for the length of our own path.
|
||||||
|
for i, ourStep := range m {
|
||||||
|
otherStep := to[i]
|
||||||
|
if ourStep != otherStep {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If we fall out here then the prefixed matched, so it's contained.
|
||||||
|
return true
|
||||||
|
|
||||||
|
case ModuleInstance:
|
||||||
|
if len(to) < len(m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i, ourStep := range m {
|
||||||
|
otherStep := to[i]
|
||||||
|
// This is where ModuleInstance differs from Module
|
||||||
|
if ourStep != otherStep.Name {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
|
||||||
|
case AbsResource:
|
||||||
|
return m.TargetContains(to.Module)
|
||||||
|
|
||||||
|
case AbsResourceInstance:
|
||||||
|
return m.TargetContains(to.Module)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Child returns the address of a child call in the receiver, identified by the
|
// Child returns the address of a child call in the receiver, identified by the
|
||||||
// given name.
|
// given name.
|
||||||
func (m Module) Child(name string) Module {
|
func (m Module) Child(name string) Module {
|
||||||
|
|
|
@ -383,8 +383,7 @@ func (m ModuleInstance) CallInstance() (ModuleInstance, ModuleCallInstance) {
|
||||||
// is contained within the reciever.
|
// is contained within the reciever.
|
||||||
func (m ModuleInstance) TargetContains(other Targetable) bool {
|
func (m ModuleInstance) TargetContains(other Targetable) bool {
|
||||||
switch to := other.(type) {
|
switch to := other.(type) {
|
||||||
|
case Module:
|
||||||
case ModuleInstance:
|
|
||||||
if len(to) < len(m) {
|
if len(to) < len(m) {
|
||||||
// Can't be contained if the path is shorter
|
// Can't be contained if the path is shorter
|
||||||
return false
|
return false
|
||||||
|
@ -392,13 +391,25 @@ func (m ModuleInstance) TargetContains(other Targetable) bool {
|
||||||
// Other is contained if its steps match for the length of our own path.
|
// Other is contained if its steps match for the length of our own path.
|
||||||
for i, ourStep := range m {
|
for i, ourStep := range m {
|
||||||
otherStep := to[i]
|
otherStep := to[i]
|
||||||
if ourStep != otherStep {
|
if ourStep.Name != otherStep {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we fall out here then the prefixed matched, so it's contained.
|
// If we fall out here then the prefixed matched, so it's contained.
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
case ModuleInstance:
|
||||||
|
if len(to) < len(m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i, ourStep := range m {
|
||||||
|
otherStep := to[i]
|
||||||
|
if ourStep != otherStep {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
|
||||||
case AbsResource:
|
case AbsResource:
|
||||||
return m.TargetContains(to.Module)
|
return m.TargetContains(to.Module)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue