aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/consts.go
diff options
context:
space:
mode:
authorPaul Chaignon <paul.chaignon@gmail.com>2023-11-09 19:20:07 +0100
committerAleksandr Nogikh <nogikh@google.com>2023-11-28 10:18:54 +0000
commitb2566dc325435823ffcfcef3c02016925556f81b (patch)
tree2ea69567f76d4dc7848b46ed4ff08480829b389c /pkg/compiler/consts.go
parent9fe51b7c608bca7b80c06c30f78c7c60810d51f1 (diff)
compiler: support type args with mixed kinds
Type args can currently have only one type of kindInt, kindIdent, kindString, or kindAny. The descriptions are checked against expected type arg kinds, with kindAny meaning that anything is allowed (often restricted with custom checks). Concretely, it means that in a description as follows, arg1 and arg2 can each take a single kind of values. type[arg1, arg2] This is limiting if we want arg1 to be able to take both an int or flags. We thus need type args to support having mixed kinds. This commit achieves this by turning the kind constants into bit flags. This will be useful in a subsequent commit, but we can also already use it for one existing type arg, the first of string types: string[literal_or_flags, size] literal_or_flags changes from kindAny to kindIdent|kindString and we can remove the custom check that used to enforce this. Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Diffstat (limited to 'pkg/compiler/consts.go')
-rw-r--r--pkg/compiler/consts.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/pkg/compiler/consts.go b/pkg/compiler/consts.go
index 6652a381c..e9f7227e7 100644
--- a/pkg/compiler/consts.go
+++ b/pkg/compiler/consts.go
@@ -105,7 +105,7 @@ func (comp *compiler) extractConsts() map[string]*ConstInfo {
func (comp *compiler) extractTypeConsts(infos map[string]*constInfo, n ast.Node) {
comp.foreachType(n, func(t *ast.Type, desc *typeDesc, args []*ast.Type, _ prog.IntTypeCommon) {
for i, arg := range args {
- if desc.Args[i].Type.Kind == kindInt {
+ if desc.Args[i].Type.Kind&kindInt != 0 {
if arg.Ident != "" {
comp.addConst(infos, arg.Pos, arg.Ident)
}
@@ -228,7 +228,7 @@ func (comp *compiler) patchConsts(consts0 map[string]uint64) {
comp.foreachType(decl, func(_ *ast.Type, desc *typeDesc,
args []*ast.Type, _ prog.IntTypeCommon) {
for i, arg := range args {
- if desc.Args[i].Type.Kind == kindInt {
+ if desc.Args[i].Type.Kind&kindInt != 0 {
comp.patchTypeConst(arg, consts, &missing)
}
}