aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/check.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/compiler/check.go')
-rw-r--r--pkg/compiler/check.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go
index b5ced7a13..00695b6b1 100644
--- a/pkg/compiler/check.go
+++ b/pkg/compiler/check.go
@@ -20,6 +20,7 @@ func (comp *compiler) typecheck() {
comp.checkComments()
comp.checkDirectives()
comp.checkNames()
+ comp.checkFlags()
comp.checkFields()
comp.checkTypedefs()
comp.checkTypes()
@@ -156,6 +157,27 @@ func (comp *compiler) checkNames() {
}
}
+func (comp *compiler) checkFlags() {
+ checkFlagsGeneric[*ast.IntFlags, *ast.Int](comp, comp.intFlags)
+ checkFlagsGeneric[*ast.StrFlags, *ast.String](comp, comp.strFlags)
+}
+
+func checkFlagsGeneric[F ast.Flags[V], V ast.FlagValue](comp *compiler, allFlags map[string]F) {
+ for name, flags := range allFlags {
+ inConstIdent := true
+ for _, val := range flags.GetValues() {
+ if _, ok := allFlags[val.GetName()]; ok {
+ inConstIdent = false
+ } else {
+ if !inConstIdent {
+ comp.error(flags.GetPos(), "flags identifier not at the end in %v definition", name)
+ break
+ }
+ }
+ }
+ }
+}
+
func (comp *compiler) checkFields() {
for _, decl := range comp.desc.Nodes {
switch n := decl.(type) {