-
Notifications
You must be signed in to change notification settings - Fork 0
/
constant.go
74 lines (58 loc) · 1.7 KB
/
constant.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package acal
// Constant ...
type Constant[T any] struct {
namedValue
valueFormatter[T]
value T
}
// NewConstant ...
func NewConstant[T any](value T) *Constant[T] {
return &Constant[T]{
value: value,
}
}
// NewConstantWithFormat ...
func NewConstantWithFormat[T any](value T, formatFn func(T) string) *Constant[T] {
c := &Constant[T]{
value: value,
}
c.WithFormatFn(formatFn)
return c
}
// IsNil returns whether this Constant is nil.
func (c *Constant[T]) IsNil() bool {
return c == nil
}
// SetAlias does nothing for Constant as it's a constant.
func (c *Constant[T]) SetAlias(alias string) {
}
// GetTypedValue returns the typed value this Constant contains.
func (c *Constant[T]) GetTypedValue() T {
return c.value
}
// GetValue returns the untyped value this Constant contains.
func (c *Constant[T]) GetValue() any {
return c.GetTypedValue()
}
// ToSyntaxOperand returns the SyntaxOperand representation of this Constant.
func (c *Constant[T]) ToSyntaxOperand(nextOp Op) *SyntaxOperand {
return NewSyntaxOperandWithStaticValue(c.Stringify())
}
// HasFormula returns whether this Constant has a formula.
func (c *Constant[T]) HasFormula() bool {
return true
}
// GetFormulaFn returns the function to build a formula of this Constant.
func (c *Constant[T]) GetFormulaFn() func() *SyntaxNode {
return func() *SyntaxNode {
return NewSyntaxNode(OpCategoryAssignStatic, OpTransparent, c.Stringify(), nil)
}
}
// ExtractValues does nothing for Constant as it's a constant.
func (c *Constant[T]) ExtractValues(cache IValueCache) IValueCache {
return cache
}
// Stringify returns the value this Constant contains as a string.
func (c *Constant[T]) Stringify() string {
return c.formatValue(c.value)
}