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/ast/ast.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pkg/ast/ast.go') diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go index 4c9101f79..9e87a1b81 100644 --- a/pkg/ast/ast.go +++ b/pkg/ast/ast.go @@ -20,6 +20,10 @@ type Description struct { // Node is AST node interface. type Node interface { Info() (pos Pos, typ string, name string) + // Clone makes a deep copy of the node. + // If newPos is not zero, sets Pos of all nodes to newPos. + // If newPos is zero, Pos of nodes is left intact. + Clone(newPos Pos) Node } // Top-level AST nodes: @@ -130,6 +134,16 @@ func (n *StrFlags) Info() (Pos, string, string) { return n.Pos, "string flags", n.Name.Name } +type TypeDef struct { + Pos Pos + Name *Ident + Type *Type +} + +func (n *TypeDef) Info() (Pos, string, string) { + return n.Pos, "type", n.Name.Name +} + // Not top-level AST nodes: type Ident struct { -- cgit mrf-deployment