From ea30f1a0a718e5e86343cceac12104baab1bedca Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sun, 6 May 2012 03:06:02 -0400 Subject: [PATCH] more bug fixes for the rest of the extensions --- nexgb/{randr.go => auto_randr.go} | 0 nexgb/{render.go => auto_render.go} | 0 nexgb/{xinerama.go => auto_xinerama.go} | 0 nexgb/{xproto.go => auto_xproto.go} | 0 nexgb/xgbgen/expression.go | 34 ++++++++++++------------- nexgb/xgbgen/field.go | 3 +-- nexgb/xgbgen/go.go | 18 ++++++++----- nexgb/xgbgen/go_struct.go | 6 ++++- nexgb/xgbgen/size.go | 2 +- nexgb/xgbgen/translation.go | 10 ++++---- 10 files changed, 41 insertions(+), 32 deletions(-) rename nexgb/{randr.go => auto_randr.go} (100%) rename nexgb/{render.go => auto_render.go} (100%) rename nexgb/{xinerama.go => auto_xinerama.go} (100%) rename nexgb/{xproto.go => auto_xproto.go} (100%) diff --git a/nexgb/randr.go b/nexgb/auto_randr.go similarity index 100% rename from nexgb/randr.go rename to nexgb/auto_randr.go diff --git a/nexgb/render.go b/nexgb/auto_render.go similarity index 100% rename from nexgb/render.go rename to nexgb/auto_render.go diff --git a/nexgb/xinerama.go b/nexgb/auto_xinerama.go similarity index 100% rename from nexgb/xinerama.go rename to nexgb/auto_xinerama.go diff --git a/nexgb/xproto.go b/nexgb/auto_xproto.go similarity index 100% rename from nexgb/xproto.go rename to nexgb/auto_xproto.go diff --git a/nexgb/xgbgen/expression.go b/nexgb/xgbgen/expression.go index 721ebfd..0966b58 100644 --- a/nexgb/xgbgen/expression.go +++ b/nexgb/xgbgen/expression.go @@ -18,7 +18,7 @@ type Expression interface { // Eval evaluates a concrete expression. It is an error to call Eval // on any expression that is not concrete (or contains any sub-expression // that is not concrete). - Eval() uint + Eval() int // Reduce attempts to evaluate any concrete sub-expressions. // i.e., (1 + 2 * (5 + 1 + someSizeOfStruct) reduces to @@ -45,7 +45,7 @@ func (e *Function) Concrete() bool { return false } -func (e *Function) Eval() uint { +func (e *Function) Eval() int { log.Fatalf("Cannot evaluate a 'Function'. It is not concrete.") panic("unreachable") } @@ -95,7 +95,7 @@ func (e *BinaryOp) Concrete() bool { return e.Expr1.Concrete() && e.Expr2.Concrete() } -func (e *BinaryOp) Eval() uint { +func (e *BinaryOp) Eval() int { switch e.Op { case "+": return e.Expr1.Eval() + e.Expr2.Eval() @@ -108,7 +108,7 @@ func (e *BinaryOp) Eval() uint { case "&": return e.Expr1.Eval() & e.Expr2.Eval() case "<<": - return e.Expr1.Eval() << e.Expr2.Eval() + return int(uint(e.Expr1.Eval()) << uint(e.Expr2.Eval())) } log.Fatalf("Invalid binary operator '%s' for expression.", e.Op) @@ -161,7 +161,7 @@ func (e *UnaryOp) Concrete() bool { return e.Expr.Concrete() } -func (e *UnaryOp) Eval() uint { +func (e *UnaryOp) Eval() int { switch e.Op { case "~": return ^e.Expr.Eval() @@ -196,8 +196,8 @@ func (e *Padding) Concrete() bool { return e.Expr.Concrete() } -func (e *Padding) Eval() uint { - return uint(pad(int(e.Expr.Eval()))) +func (e *Padding) Eval() int { + return pad(e.Expr.Eval()) } func (e *Padding) Reduce(prefix string) string { @@ -225,8 +225,8 @@ func (e *PopCount) Concrete() bool { return e.Expr.Concrete() } -func (e *PopCount) Eval() uint { - return popCount(e.Expr.Eval()) +func (e *PopCount) Eval() int { + return int(popCount(uint(e.Expr.Eval()))) } func (e *PopCount) Reduce(prefix string) string { @@ -246,14 +246,14 @@ func (e *PopCount) Initialize(p *Protocol) { // Value represents some constant integer. type Value struct { - v uint + v int } func (e *Value) Concrete() bool { return true } -func (e *Value) Eval() uint { +func (e *Value) Eval() int { return e.v } @@ -269,15 +269,15 @@ func (e *Value) Initialize(p *Protocol) {} // Bit represents some bit whose value is computed by '1 << bit'. type Bit struct { - b uint + b int } func (e *Bit) Concrete() bool { return true } -func (e *Bit) Eval() uint { - return 1 << e.b +func (e *Bit) Eval() int { + return int(1 << uint(e.b)) } func (e *Bit) Reduce(prefix string) string { @@ -300,7 +300,7 @@ func (e *FieldRef) Concrete() bool { return false } -func (e *FieldRef) Eval() uint { +func (e *FieldRef) Eval() int { log.Fatalf("Cannot evaluate a 'FieldRef'. It is not concrete.") panic("unreachable") } @@ -333,7 +333,7 @@ func (e *EnumRef) Concrete() bool { return false } -func (e *EnumRef) Eval() uint { +func (e *EnumRef) Eval() int { log.Fatalf("Cannot evaluate an 'EnumRef'. It is not concrete.") panic("unreachable") } @@ -361,7 +361,7 @@ func (e *SumOf) Concrete() bool { return false } -func (e *SumOf) Eval() uint { +func (e *SumOf) Eval() int { log.Fatalf("Cannot evaluate a 'SumOf'. It is not concrete.") panic("unreachable") } diff --git a/nexgb/xgbgen/field.go b/nexgb/xgbgen/field.go index 725f3de..4452408 100644 --- a/nexgb/xgbgen/field.go +++ b/nexgb/xgbgen/field.go @@ -142,8 +142,7 @@ func (f *ListField) Length() Size { // special function written in go_struct.go to compute the size (since the // size in this case can only be computed recursively). func (f *ListField) Size() Size { - simpleLen := &Function{ - Name: "pad", + simpleLen := &Padding{ Expr: newBinaryOp("*", f.Length().Expression, f.Type.Size().Expression), } diff --git a/nexgb/xgbgen/go.go b/nexgb/xgbgen/go.go index df12e69..e0d4579 100644 --- a/nexgb/xgbgen/go.go +++ b/nexgb/xgbgen/go.go @@ -150,15 +150,21 @@ func (f *ExprField) Write(c *Context, prefix string) { // Value field func (f *ValueField) Define(c *Context) { - c.Putln("// valueparam field: type: %s, mask name: %s, list name: %s", - f.MaskType.SrcName(), f.MaskName, f.ListName) - panic("todo") + c.Putln("%s %s", f.MaskName, f.SrcType()) + c.Putln("%s []uint32", f.ListName) } func (f *ValueField) Read(c *Context, prefix string) { - c.Putln("// reading valueparam: type: %s, mask name: %s, list name: %s", - f.MaskType.SrcName(), f.MaskName, f.ListName) - panic("todo") + ReadSimpleSingleField(c, + fmt.Sprintf("%s%s", prefix, f.MaskName), f.MaskType) + c.Putln("") + c.Putln("%s%s = make([]uint32, %s)", + prefix, f.ListName, f.ListLength().Reduce(prefix)) + c.Putln("for i := 0; i < %s; i++ {", f.ListLength().Reduce(prefix)) + c.Putln("%s%s[i] = Get32(buf[b:])", prefix, f.ListName) + c.Putln("b += 4") + c.Putln("}") + c.Putln("b = pad(b)") } func (f *ValueField) Write(c *Context, prefix string) { diff --git a/nexgb/xgbgen/go_struct.go b/nexgb/xgbgen/go_struct.go index 1e43199..9884194 100644 --- a/nexgb/xgbgen/go_struct.go +++ b/nexgb/xgbgen/go_struct.go @@ -104,7 +104,11 @@ func (s *Struct) WriteListSize(c *Context) { c.Putln("// Struct list size %s", s.SrcName()) c.Putln("func %sListSize(list []%s) int {", s.SrcName(), s.SrcName()) c.Putln("size := 0") - c.Putln("for _, item := range list {") + if s.Size().Expression.Concrete() { + c.Putln("for _ = range list {") + } else { + c.Putln("for _, item := range list {") + } c.Putln("size += %s", s.Size().Reduce("item.")) c.Putln("}") c.Putln("return size") diff --git a/nexgb/xgbgen/size.go b/nexgb/xgbgen/size.go index d8d3ac3..8836892 100644 --- a/nexgb/xgbgen/size.go +++ b/nexgb/xgbgen/size.go @@ -11,7 +11,7 @@ type Size struct { // newFixedSize creates a new Size with some fixed and known value. func newFixedSize(fixed uint) Size { - return Size{&Value{v: fixed}} + return Size{&Value{v: int(fixed)}} } // newExpressionSize creates a new Size with some expression. diff --git a/nexgb/xgbgen/translation.go b/nexgb/xgbgen/translation.go index b650bc4..90cd0f3 100644 --- a/nexgb/xgbgen/translation.go +++ b/nexgb/xgbgen/translation.go @@ -89,7 +89,7 @@ func (xml *XML) Translate() *Protocol { if !ok { continue } - nextValue := uint(0) + nextValue := 0 for _, item := range enum.Items { if item.Expr == nil { item.Expr = &Value{v: nextValue} @@ -267,16 +267,16 @@ func (x *XMLExpression) Translate() Expression { Expr: x.Exprs[0].Translate(), } case "value": - val, err := strconv.Atoi(x.Data) + val, err := strconv.Atoi(strings.TrimSpace(x.Data)) if err != nil { log.Panicf("Could not convert '%s' in 'value' expression to int.", x.Data) } return &Value{ - v: uint(val), + v: val, } case "bit": - bit, err := strconv.Atoi(x.Data) + bit, err := strconv.Atoi(strings.TrimSpace(x.Data)) if err != nil { log.Panicf("Could not convert '%s' in 'bit' expression to int.", x.Data) @@ -286,7 +286,7 @@ func (x *XMLExpression) Translate() Expression { " is %d", bit) } return &Bit{ - b: uint(bit), + b: bit, } case "fieldref": return &FieldRef{