From e6529b30ec934f285d57dc16dd8acbbab074f102 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 29 Dec 2015 15:00:57 +0100 Subject: sys: add union type --- sysgen/sysgen.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'sysgen') diff --git a/sysgen/sysgen.go b/sysgen/sysgen.go index 14ecd51fa..c26768abb 100644 --- a/sysgen/sysgen.go +++ b/sysgen/sysgen.go @@ -65,8 +65,9 @@ type Syscall struct { } type Struct struct { - Name string - Flds [][]string + Name string + Flds [][]string + IsUnion bool } func generate(syscalls []Syscall, structs map[string]Struct, unnamed map[string][]string, flags map[string][]string, flagVals map[string]string, out io.Writer) { @@ -311,7 +312,13 @@ func generateArg(name, typ string, a []string, structs map[string]Struct, unname failf("unknown unnamed type '%v'", typ) } if str, ok := structs[typ]; ok { - fmt.Fprintf(out, "StructType{TypeCommon: TypeCommon{TypeName: \"%v\", IsOptional: %v}, Fields: []Type{", str.Name, false) + typ := "StructType" + fields := "Fields" + if str.IsUnion { + typ = "UnionType" + fields = "Options" + } + fmt.Fprintf(out, "%v{TypeCommon: TypeCommon{TypeName: \"%v\", IsOptional: %v}, %v: []Type{", typ, str.Name, false, fields) for i, a := range str.Flds { if i != 0 { fmt.Fprintf(out, ", ") @@ -538,8 +545,8 @@ func parse(in io.Reader) (includes []string, defines map[string]string, syscalls } if str != nil { // Parsing a struct. - if p.Char() == '}' { - p.Parse('}') + if p.Char() == '}' || p.Char() == ']' { + p.Parse(p.Char()) if _, ok := structs[str.Name]; ok { failf("%v struct is defined multiple times", str.Name) } @@ -614,6 +621,9 @@ func parse(in io.Reader) (includes []string, defines map[string]string, syscalls case '{': p.Parse('{') str = &Struct{Name: name} + case '[': + p.Parse('[') + str = &Struct{Name: name, IsUnion: true} default: failf("bad line (%v)", p.Str()) } -- cgit mrf-deployment