aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/field.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 16:18:17 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 16:18:17 -0400
commit73154769b3eba60fe48a7c08882e8e64b1545e3f (patch)
tree3fe7c2a1f9ae1d22931b4673901d8ea340192d57 /nexgb/xgbgen/field.go
parent2a2d8653b3a7918dfb00dcca8937b0e878279c70 (diff)
downloadhaven-73154769b3eba60fe48a7c08882e8e64b1545e3f.tar.gz
haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.tar.xz
haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.zip
splitting up go specific code. too much for one file IMO. more progress. almost done with structs.
Diffstat (limited to 'nexgb/xgbgen/field.go')
-rw-r--r--nexgb/xgbgen/field.go31
1 files changed, 30 insertions, 1 deletions
diff --git a/nexgb/xgbgen/field.go b/nexgb/xgbgen/field.go
index ed113e0..0f2323e 100644
--- a/nexgb/xgbgen/field.go
+++ b/nexgb/xgbgen/field.go
@@ -1,5 +1,10 @@
package main
+import (
+ "fmt"
+ "log"
+)
+
type Field interface {
Initialize(p *Protocol)
SrcName() string
@@ -8,6 +13,7 @@ type Field interface {
Define(c *Context)
Read(c *Context)
+ Write(c *Context)
}
func (pad *PadField) Initialize(p *Protocol) {}
@@ -66,8 +72,31 @@ func (f *ListField) XmlName() string {
return f.xmlName
}
+// func (f *ListField) Size() Size {
+ // return newExpressionSize(f.LengthExpr).Multiply(f.Type.Size())
+// }
+
func (f *ListField) Size() Size {
- return newExpressionSize(f.LengthExpr).Multiply(f.Type.Size())
+ simpleLen := &Function{
+ Name: "pad",
+ Expr: newBinaryOp("*", f.LengthExpr, f.Type.Size().Expression),
+ }
+
+ switch f.Type.(type) {
+ case *Struct:
+ sizeFun := &Function{
+ Name: fmt.Sprintf("%sListSize", f.Type.SrcName()),
+ Expr: &FieldRef{Name: f.SrcName()},
+ }
+ return newExpressionSize(sizeFun)
+ case *Base:
+ return newExpressionSize(simpleLen)
+ case *Resource:
+ return newExpressionSize(simpleLen)
+ default:
+ log.Fatalf("Cannot compute list size with type '%T'.", f.Type)
+ }
+ panic("unreachable")
}
func (f *ListField) Initialize(p *Protocol) {