aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ast/format.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-01-06 14:46:52 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-01-08 12:52:31 +0100
commit402a0dc87e7d51812a18fa76feeb46d66efda175 (patch)
tree03ae2832257917a68829137b0a504f6f8c2e499a /pkg/ast/format.go
parent93b4c6f135aeecbb756fe8c8a3d46c7a05412a54 (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/ast/format.go')
-rw-r--r--pkg/ast/format.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/pkg/ast/format.go b/pkg/ast/format.go
index 0f95d7ebf..a77662df8 100644
--- a/pkg/ast/format.go
+++ b/pkg/ast/format.go
@@ -62,6 +62,10 @@ func (res *Resource) serialize(w io.Writer) {
fmt.Fprintf(w, "\n")
}
+func (typedef *TypeDef) serialize(w io.Writer) {
+ fmt.Fprintf(w, "type %v %v\n", typedef.Name.Name, fmtType(typedef.Type))
+}
+
func (c *Call) serialize(w io.Writer) {
fmt.Fprintf(w, "%v(", c.Name.Name)
for i, a := range c.Args {