From 402a0dc87e7d51812a18fa76feeb46d66efda175 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 6 Jan 2018 14:46:52 +0100 Subject: 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. --- pkg/compiler/compiler.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pkg/compiler/compiler.go') diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index d250eda68..0be7f2817 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -53,6 +53,7 @@ func Compile(desc *ast.Description, consts map[string]uint64, target *targets.Ta ptrSize: target.PtrSize, unsupported: make(map[string]bool), resources: make(map[string]*ast.Resource), + typedefs: make(map[string]*ast.TypeDef), structs: make(map[string]*ast.Struct), intFlags: make(map[string]*ast.IntFlags), strFlags: make(map[string]*ast.StrFlags), @@ -89,6 +90,7 @@ type compiler struct { unsupported map[string]bool resources map[string]*ast.Resource + typedefs map[string]*ast.TypeDef structs map[string]*ast.Struct intFlags map[string]*ast.IntFlags strFlags map[string]*ast.StrFlags @@ -163,6 +165,9 @@ func (comp *compiler) getTypeDesc(t *ast.Type) *typeDesc { if comp.structs[t.Ident] != nil { return typeStruct } + if comp.typedefs[t.Ident] != nil { + return typeTypedef + } return nil } -- cgit mrf-deployment