2017-08-26 19:36:08 +00:00
|
|
|
// Copyright 2017 syzkaller project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package ast
|
|
|
|
|
2018-01-10 15:13:34 +00:00
|
|
|
func (desc *Description) Clone() *Description {
|
2017-08-26 19:36:08 +00:00
|
|
|
desc1 := &Description{}
|
|
|
|
for _, n := range desc.Nodes {
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
desc1.Nodes = append(desc1.Nodes, n.Clone())
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
return desc1
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *NewLine) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &NewLine{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Comment) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Comment{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
2017-08-26 19:36:08 +00:00
|
|
|
Text: n.Text,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Include) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Include{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
File: n.File.Clone().(*String),
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Incdir) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Incdir{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Dir: n.Dir.Clone().(*String),
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Define) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Define{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Name: n.Name.Clone().(*Ident),
|
|
|
|
Value: n.Value.Clone().(*Int),
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Resource) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Resource{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Name: n.Name.Clone().(*Ident),
|
|
|
|
Base: n.Base.Clone().(*Type),
|
2018-07-31 10:42:52 +00:00
|
|
|
Values: cloneInts(n.Values),
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *TypeDef) Clone() Node {
|
|
|
|
var args []*Ident
|
|
|
|
for _, v := range n.Args {
|
|
|
|
args = append(args, v.Clone().(*Ident))
|
|
|
|
}
|
|
|
|
var typ *Type
|
|
|
|
if n.Type != nil {
|
|
|
|
typ = n.Type.Clone().(*Type)
|
|
|
|
}
|
|
|
|
var str *Struct
|
|
|
|
if n.Struct != nil {
|
|
|
|
str = n.Struct.Clone().(*Struct)
|
|
|
|
}
|
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.
2018-01-06 13:46:52 +00:00
|
|
|
return &TypeDef{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Name: n.Name.Clone().(*Ident),
|
|
|
|
Args: args,
|
|
|
|
Type: typ,
|
|
|
|
Struct: str,
|
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.
2018-01-06 13:46:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Call) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
var ret *Type
|
|
|
|
if n.Ret != nil {
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
ret = n.Ret.Clone().(*Type)
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
return &Call{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Name: n.Name.Clone().(*Ident),
|
2017-08-26 19:36:08 +00:00
|
|
|
CallName: n.CallName,
|
|
|
|
NR: n.NR,
|
2018-07-31 10:42:52 +00:00
|
|
|
Args: cloneFields(n.Args),
|
2017-08-26 19:36:08 +00:00
|
|
|
Ret: ret,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Struct) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Struct{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Name: n.Name.Clone().(*Ident),
|
2018-07-31 10:42:52 +00:00
|
|
|
Fields: cloneFields(n.Fields),
|
|
|
|
Attrs: cloneTypes(n.Attrs),
|
|
|
|
Comments: cloneComments(n.Comments),
|
2017-08-26 19:36:08 +00:00
|
|
|
IsUnion: n.IsUnion,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *IntFlags) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &IntFlags{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Name: n.Name.Clone().(*Ident),
|
2018-07-31 10:42:52 +00:00
|
|
|
Values: cloneInts(n.Values),
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *StrFlags) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
var values []*String
|
|
|
|
for _, v := range n.Values {
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
values = append(values, v.Clone().(*String))
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
return &StrFlags{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Name: n.Name.Clone().(*Ident),
|
2017-08-26 19:36:08 +00:00
|
|
|
Values: values,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Ident) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Ident{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
2017-08-26 19:36:08 +00:00
|
|
|
Name: n.Name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *String) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &String{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
2017-08-26 19:36:08 +00:00
|
|
|
Value: n.Value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Int) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Int{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
2017-08-26 19:36:08 +00:00
|
|
|
Value: n.Value,
|
2018-07-09 18:47:07 +00:00
|
|
|
ValueFmt: n.ValueFmt,
|
2017-08-26 19:36:08 +00:00
|
|
|
Ident: n.Ident,
|
|
|
|
CExpr: n.CExpr,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Type) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Type{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
2017-08-26 19:36:08 +00:00
|
|
|
Value: n.Value,
|
2018-07-09 18:47:07 +00:00
|
|
|
ValueFmt: n.ValueFmt,
|
2017-08-26 19:36:08 +00:00
|
|
|
Ident: n.Ident,
|
|
|
|
String: n.String,
|
2018-01-23 10:05:51 +00:00
|
|
|
HasString: n.HasString,
|
2017-08-26 19:36:08 +00:00
|
|
|
HasColon: n.HasColon,
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos2: n.Pos2,
|
2017-08-26 19:36:08 +00:00
|
|
|
Value2: n.Value2,
|
2018-07-09 18:47:07 +00:00
|
|
|
Value2Fmt: n.Value2Fmt,
|
2017-08-26 19:36:08 +00:00
|
|
|
Ident2: n.Ident2,
|
2018-07-31 10:42:52 +00:00
|
|
|
Args: cloneTypes(n.Args),
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
func (n *Field) Clone() Node {
|
2017-08-26 19:36:08 +00:00
|
|
|
return &Field{
|
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]])
```
2018-01-10 15:13:34 +00:00
|
|
|
Pos: n.Pos,
|
|
|
|
Name: n.Name.Clone().(*Ident),
|
|
|
|
Type: n.Type.Clone().(*Type),
|
2017-08-26 19:36:08 +00:00
|
|
|
NewBlock: n.NewBlock,
|
2018-07-31 10:42:52 +00:00
|
|
|
Comments: cloneComments(n.Comments),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func cloneFields(list []*Field) (res []*Field) {
|
|
|
|
for _, n := range list {
|
|
|
|
res = append(res, n.Clone().(*Field))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func cloneInts(list []*Int) (res []*Int) {
|
|
|
|
for _, n := range list {
|
|
|
|
res = append(res, n.Clone().(*Int))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func cloneTypes(list []*Type) (res []*Type) {
|
|
|
|
for _, n := range list {
|
|
|
|
res = append(res, n.Clone().(*Type))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func cloneComments(list []*Comment) (res []*Comment) {
|
|
|
|
for _, n := range list {
|
|
|
|
res = append(res, n.Clone().(*Comment))
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|
2018-07-31 10:42:52 +00:00
|
|
|
return
|
2017-08-26 19:36:08 +00:00
|
|
|
}
|