From 588a542b2a23ba477031bf20b4c46b0f40a04b7d Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 31 Oct 2016 15:15:13 -0600 Subject: sys: add string flags Allow to define string flags in txt descriptions. E.g.: filesystem = "ext2", "ext3", "ext4" and then use it in string type: ptr[in, string[filesystem]] --- sys/decl.go | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'sys/decl.go') diff --git a/sys/decl.go b/sys/decl.go index d5ec9a547..2f86ea87c 100644 --- a/sys/decl.go +++ b/sys/decl.go @@ -105,7 +105,6 @@ const ( BufferString BufferFilename BufferSockaddr - BufferFilesystem BufferAlgType BufferAlgName ) @@ -115,6 +114,8 @@ type BufferType struct { Kind BufferKind RangeBegin uintptr // for BufferBlobRange kind RangeEnd uintptr // for BufferBlobRange kind + SubKind string + Values []string // possible values for BufferString kind } func (t *BufferType) Size() uintptr { @@ -123,14 +124,16 @@ func (t *BufferType) Size() uintptr { return 14 case BufferAlgName: return 64 + case BufferString: + if len(t.Values) == 1 { + return uintptr(len(t.Values[0])) + } case BufferBlobRange: if t.RangeBegin == t.RangeEnd { return t.RangeBegin } - fallthrough - default: - panic(fmt.Sprintf("buffer size is not statically known: %v", t.Name())) } + panic(fmt.Sprintf("buffer size is not statically known: %v", t.Name())) } func (t *BufferType) Align() uintptr { @@ -196,20 +199,6 @@ func (t *ConstType) Align() uintptr { return t.Size() } -type StrConstType struct { - TypeCommon - TypeSize uintptr - Val string -} - -func (t *StrConstType) Size() uintptr { - return uintptr(len(t.Val)) -} - -func (t *StrConstType) Align() uintptr { - return 1 -} - type IntKind int const ( @@ -486,9 +475,8 @@ func ForeachType(meta *Call, f func(Type)) { for _, opt := range a.Options { rec(opt) } - case *ResourceType, *BufferType, - *VmaType, *LenType, *FlagsType, *ConstType, - *StrConstType, *IntType: + case *ResourceType, *BufferType, *VmaType, *LenType, + *FlagsType, *ConstType, *IntType: default: panic("unknown type") } -- cgit mrf-deployment