diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-09-19 19:42:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-19 19:42:00 +0200 |
| commit | d18f8aa3669db8a7c2a9d235aa720bce8041f329 (patch) | |
| tree | 56195536ec22d1414e7614403dc2757d9d76d4ca /sys | |
| parent | 0c97d70213a4fbc6d8d57626c18b603f2a281047 (diff) | |
| parent | f41935d53ff6271e8c2a9022f41b99ccee9b634b (diff) | |
Merge pull request #73 from xairy/ranged_arrays
Allow range sized arrays
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/README.md | 2 | ||||
| -rw-r--r-- | sys/align.go | 2 | ||||
| -rw-r--r-- | sys/decl.go | 20 |
3 files changed, 15 insertions, 9 deletions
diff --git a/sys/README.md b/sys/README.md index 46c0a1a59..1355ad4f8 100644 --- a/sys/README.md +++ b/sys/README.md @@ -45,7 +45,7 @@ rest of the type-options are type-specific: "ptr": a pointer to an object, type-options: type of the object; direction (in/out/inout) "array": a variable/fixed-length array, type-options: - type of elements, optional size for fixed-length arrays + type of elements, optional size (fixed "5", or ranged "5:10", boundaries inclusive) "intN"/"intptr": an integer without a particular meaning, type-options: range of values (e.g. "5:10", or "-100:200", optional) ``` diff --git a/sys/align.go b/sys/align.go index 5e67f6175..4c91c28be 100644 --- a/sys/align.go +++ b/sys/align.go @@ -64,7 +64,7 @@ func addAlignment(t *StructType) Type { } off += f.Size() fields = append(fields, f) - if at, ok := f.(ArrayType); ok && at.Len == 0 { + if at, ok := f.(ArrayType); ok && (at.Kind == ArrayRandLen || (at.Kind == ArrayRangeLen && at.RangeBegin != at.RangeEnd)) { varLen = true } if varLen && i != len(t.Fields)-1 { diff --git a/sys/decl.go b/sys/decl.go index a9f9d1ad3..2cc8f22e5 100644 --- a/sys/decl.go +++ b/sys/decl.go @@ -236,21 +236,27 @@ func (t FilenameType) Align() uintptr { return 1 } +type ArrayKind int + +const ( + ArrayRandLen ArrayKind = iota + ArrayRangeLen +) + type ArrayType struct { TypeCommon - Type Type - Len uintptr // 0 if variable-length, unused for now + Type Type + Kind ArrayKind + RangeBegin uintptr + RangeEnd uintptr } func (t ArrayType) Size() uintptr { - if t.Len == 0 { - return 0 // for trailing embed arrays - } - return t.Len * t.Type.Size() + panic("should not be called") } func (t ArrayType) Align() uintptr { - return t.Type.Align() + panic("should not be called") } type PtrType struct { |
