From 6b52293f4defa6b45b564d037fd641be5d6d0e0e Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 10 Jan 2018 16:13:34 +0100 Subject: pkg/compiler: support type templates Netlink descriptions contain tons of code duplication, and need much more for proper descriptions. Introduce type templates to simplify writing such descriptions and remove code duplication. Note: type templates are experimental, have poor error handling and are subject to change. Type templates can be declared as follows: ``` type buffer[DIR] ptr[DIR, array[int8]] type fileoff[BASE] BASE type nlattr[TYPE, PAYLOAD] { nla_len len[parent, int16] nla_type const[TYPE, int16] payload PAYLOAD } [align_4] ``` and later used as follows: ``` syscall(a buffer[in], b fileoff[int64], c ptr[in, nlattr[FOO, int32]]) ``` --- pkg/ast/testdata/all.txt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'pkg/ast/testdata') diff --git a/pkg/ast/testdata/all.txt b/pkg/ast/testdata/all.txt index 268b49a47..d4452b34f 100644 --- a/pkg/ast/testdata/all.txt +++ b/pkg/ast/testdata/all.txt @@ -48,5 +48,20 @@ s2 { type mybool8 int8 type net_port proc[1, 2, int16be] -type mybool16 ### unexpected '\n', expecting int, identifier, string -type type4:4 int32 ### unexpected ':', expecting int, identifier, string +type mybool16 ### unexpected '\n', expecting '[', identifier +type type4:4 int32 ### unexpected ':', expecting '[', identifier + +type templ0[] int8 ### unexpected ']', expecting identifier +type templ1[A,] int8 ### unexpected ']', expecting identifier +type templ2[,] int8 ### unexpected ',', expecting identifier +type templ3[ ### unexpected '\n', expecting identifier +type templ4[A] ### unexpected '\n', expecting int, identifier, string +type templ5[A] const[A] +type templ6[A, B] const[A, B] +type templ7[0] ptr[in, int8] ### unexpected int, expecting identifier + +type templ_struct0[A, B] { + len len[parent, int16] + typ const[A, int16] + data B +} [align_4] -- cgit mrf-deployment