From 031c7941d7bd97b4acbf9bcd2513ed695b387ff2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 17 May 2018 12:02:30 +0200 Subject: pkg/compiler: add optional builtin template type optional[T] [ val T void void ] [varlen] --- docs/syscall_descriptions_syntax.md | 12 ++++++++---- pkg/compiler/testdata/all.txt | 1 + pkg/compiler/types.go | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/syscall_descriptions_syntax.md b/docs/syscall_descriptions_syntax.md index 47986651c..4708dc804 100644 --- a/docs/syscall_descriptions_syntax.md +++ b/docs/syscall_descriptions_syntax.md @@ -185,10 +185,7 @@ type filename string[filename] ## Type Templates -**Note: type templates are experimental, can have error handling bugs and are subject to change** - Type templates can be declared as follows: - ``` type buffer[DIR] ptr[DIR, array[int8]] type fileoff[BASE] BASE @@ -200,11 +197,18 @@ type nlattr[TYPE, PAYLOAD] { ``` and later used as follows: - ``` syscall(a buffer[in], b fileoff[int64], c ptr[in, nlattr[FOO, int32]]) ``` +There is builtin type template `optional` defined as: +``` +type optional[T] [ + val T + void void +] [varlen] +``` + ## Length You can specify length of a particular field in struct or a named argument by using `len`, `bytesize` and `bitsize` types, for example: diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt index d451f5a60..69ad6d181 100644 --- a/pkg/compiler/testdata/all.txt +++ b/pkg/compiler/testdata/all.txt @@ -102,6 +102,7 @@ struct_with_void1 { f1 int8 f2 array[void5] f3 int64 + f4 optional[int8] } foo$void0(a ptr[in, void0]) diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 825071324..97f7d18c4 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -744,6 +744,11 @@ type boolptr intptr[0:1] type filename string[filename] filename = "", "." + +type optional[T] [ + val T + void void +] [varlen] ` func init() { -- cgit mrf-deployment