-
Notifications
You must be signed in to change notification settings - Fork 10
/
local_value.go
48 lines (41 loc) · 1.01 KB
/
local_value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package addrs
import (
"fmt"
)
// LocalValue is the address of a local value.
type LocalValue struct {
referenceable
Name string
}
func (v LocalValue) String() string {
return "local." + v.Name
}
// Absolute converts the receiver into an absolute address within the given
// module instance.
func (v LocalValue) Absolute(m ModuleInstance) AbsLocalValue {
return AbsLocalValue{
Module: m,
LocalValue: v,
}
}
// AbsLocalValue is the absolute address of a local value within a module instance.
type AbsLocalValue struct {
Module ModuleInstance
LocalValue LocalValue
}
// LocalValue returns the absolute address of a local value of the given
// name within the receiving module instance.
func (m ModuleInstance) LocalValue(name string) AbsLocalValue {
return AbsLocalValue{
Module: m,
LocalValue: LocalValue{
Name: name,
},
}
}
func (v AbsLocalValue) String() string {
if len(v.Module) == 0 {
return v.LocalValue.String()
}
return fmt.Sprintf("%s.%s", v.Module.String(), v.LocalValue.String())
}