diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-01-06 14:46:52 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-01-08 12:52:31 +0100 |
| commit | 402a0dc87e7d51812a18fa76feeb46d66efda175 (patch) | |
| tree | 03ae2832257917a68829137b0a504f6f8c2e499a /pkg/compiler/testdata/errors.txt | |
| parent | 93b4c6f135aeecbb756fe8c8a3d46c7a05412a54 (diff) | |
sys: support type aliases (aka typedefs)
Complex types that are often repeated can be given short type aliases using the
following syntax:
```
type identifier underlying_type
```
For example:
```
type signalno int32[0:65]
type net_port proc[20000, 4, int16be]
```
Then, type alias can be used instead of the underlying type in any contexts.
Underlying type needs to be described as if it's a struct field, that is,
with the base type if it's required. However, type alias can be used as syscall
arguments as well. Underlying types are currently restricted to integer types,
`ptr`, `ptr64`, `const`, `flags` and `proc` types.
Diffstat (limited to 'pkg/compiler/testdata/errors.txt')
| -rw-r--r-- | pkg/compiler/testdata/errors.txt | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/pkg/compiler/testdata/errors.txt b/pkg/compiler/testdata/errors.txt index ade8c624f..237519aa3 100644 --- a/pkg/compiler/testdata/errors.txt +++ b/pkg/compiler/testdata/errors.txt @@ -178,3 +178,66 @@ define d1 `some C expression` define d2 some C expression define d2 SOMETHING ### duplicate define d2 define d3 1 + +# Type aliases. + +type bool8 int8[0:1] +type bool16 int16[0:1] +type net_port proc[100, 1, int16be] +resource typeres0[bool8] +typestruct { + f1 bool8 + f2 bool16 +} +typeunion [ + f1 bool8 + f2 bool16 +] + +type type0 int8 +type type0 int8 ### type type0 redeclared, previously declared as type alias at errors.txt:197:6 +resource type0[int32] ### type type0 redeclared, previously declared as type alias at errors.txt:197:6 +type0 = 0, 1 +type type1 type1 ### type aliases can't refer to other type aliases +type type2 int8:4 ### unexpected ':', only struct fields can be bitfields +type type3 type2 ### unknown type type2 +type type4 const[0] ### wrong number of arguments for type const, expect value, base type +type type5 typeunion ### typeunion can't be type alias target +type type6 len[foo, int32] ### len can't be type alias target +type type7 len[foo] ### len can't be type alias target +resource typeres1[int32] +type type8 typeres1 ### typeres1 can't be type alias target +type int8 int8 ### type name int8 conflicts with builtin type +type opt int8 ### type uses reserved name opt +type type9 const[0, int8] +type type10 type0 ### type aliases can't refer to other type aliases +type type11 typestruct11 ### typestruct11 can't be type alias target +type type12 proc[123, 2, int16, opt] +type type13 ptr[in, typestruct13] +type type14 flags[type0, int32] +type type15 const[0, type0] ### unexpected value type0 for base type argument of const type, expect [int8 int16 int32 int64 int16be int32be int64be intptr] +type type16 ptr[in, type0] ### type aliases can't refer to other type aliases + +typestruct11 { + f type11 ### unknown type type11 +} + +typestruct12 { + f type11 ### unknown type type11 +} + +typestruct13 { + f1 type9 + f2 type12 +} + +foo$100(a bool8, b bool16) +foo$101(a type5) ### unknown type type5 +foo$102(a type2) ### unknown type type2 +foo$103(a type0:4) ### type alias type0 with ':' +foo$104(a type0[opt]) ### type alias type0 with arguments +foo$105() type0 +foo$106() type6 ### unknown type type6 +foo$107(a type9, b type12) +foo$108(a flags[type0]) +foo$109(a ptr[in, type0]) |
