aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ast
diff options
context:
space:
mode:
authorPaul Chaignon <paul.chaignon@gmail.com>2023-12-01 14:46:41 +0100
committerAleksandr Nogikh <nogikh@google.com>2023-12-05 13:40:28 +0000
commit3e9d168edd9e40138b295bb7d8adc92fa9430e78 (patch)
tree3350a4a2539a8c321c077cb63a22398fe00e4930 /pkg/ast
parent4ee90773d9aa928ec274a59e7ed206692b74637b (diff)
compiler: refactor recurFlattenFlags
This commit refactors recurFlattenFlags using Go generics and new interfaces so that it also applies to a different set of flags types. In a subsequent commit, we will use that to perform the same recursive flattening for string flags. Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Diffstat (limited to 'pkg/ast')
-rw-r--r--pkg/ast/ast.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go
index e225c69b2..2e8a7a015 100644
--- a/pkg/ast/ast.go
+++ b/pkg/ast/ast.go
@@ -27,6 +27,15 @@ type Node interface {
walk(cb func(Node))
}
+type Flags[T FlagValue] interface {
+ SetValues(values []T)
+ GetValues() []T
+}
+
+type FlagValue interface {
+ GetName() string
+}
+
// Top-level AST nodes.
type NewLine struct {
@@ -135,6 +144,14 @@ func (n *IntFlags) Info() (Pos, string, string) {
return n.Pos, "flags", n.Name.Name
}
+func (n *IntFlags) SetValues(values []*Int) {
+ n.Values = values
+}
+
+func (n *IntFlags) GetValues() []*Int {
+ return n.Values
+}
+
type StrFlags struct {
Pos Pos
Name *Ident
@@ -145,6 +162,14 @@ func (n *StrFlags) Info() (Pos, string, string) {
return n.Pos, "string flags", n.Name.Name
}
+func (n *StrFlags) SetValues(values []*String) {
+ n.Values = values
+}
+
+func (n *StrFlags) GetValues() []*String {
+ return n.Values
+}
+
type TypeDef struct {
Pos Pos
Name *Ident
@@ -180,6 +205,10 @@ func (n *String) Info() (Pos, string, string) {
return n.Pos, tok2str[tokString], ""
}
+func (n *String) GetName() string {
+ return n.Value
+}
+
type IntFmt int
const (
@@ -210,6 +239,10 @@ func (n *Int) Info() (Pos, string, string) {
return n.Pos, tok2str[tokInt], ""
}
+func (n *Int) GetName() string {
+ return n.Ident
+}
+
type Type struct {
Pos Pos
// Only one of Value, Ident, String is filled.