aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-10 12:47:19 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-10 12:47:19 -0400
commite239bb3c68a4981a3916534203c2fbd6b96f593c (patch)
treeebb9b1a4a4659d09edaf57ec39a744ff4bc15ff0 /nexgb/xgbgen
parent00c6217ca905b08ce0acda9a90492b5c1dc358e8 (diff)
downloadhaven-e239bb3c68a4981a3916534203c2fbd6b96f593c.tar.gz
haven-e239bb3c68a4981a3916534203c2fbd6b96f593c.tar.xz
haven-e239bb3c68a4981a3916534203c2fbd6b96f593c.zip
make resource ids their own individual types. last commit before overhaul to sub-packages
Diffstat (limited to 'nexgb/xgbgen')
-rw-r--r--nexgb/xgbgen/go.go22
-rw-r--r--nexgb/xgbgen/go_error.go12
-rw-r--r--nexgb/xgbgen/go_list.go3
-rw-r--r--nexgb/xgbgen/go_single_field.go2
-rw-r--r--nexgb/xgbgen/translation.go5
5 files changed, 25 insertions, 19 deletions
diff --git a/nexgb/xgbgen/go.go b/nexgb/xgbgen/go.go
index e0d4579..2b2c191 100644
--- a/nexgb/xgbgen/go.go
+++ b/nexgb/xgbgen/go.go
@@ -4,10 +4,6 @@ import (
"fmt"
)
-// xgbResourceIdName is the name of the type used for all resource identifiers.
-// As of right now, it needs to be declared somewhere manually.
-var xgbGenResourceIdName = "Id"
-
// BaseTypeMap is a map from X base types to Go types.
// X base types should correspond to the smallest set of X types
// that can be used to rewrite ALL X types in terms of Go types.
@@ -27,7 +23,6 @@ var BaseTypeMap = map[string]string{
"double": "float64",
"char": "byte",
"void": "byte",
- "Id": "Id",
}
// BaseTypeSizes should have precisely the same keys as in BaseTypeMap,
@@ -45,7 +40,10 @@ var BaseTypeSizes = map[string]uint{
"double": 8,
"char": 1,
"void": 1,
- "Id": 4,
+
+ // Id is a special type used to determine the size of all Xid types.
+ // "Id" is not actually written in the source.
+ "Id": 4,
}
// TypeMap is a map from types in the XML to type names that is used
@@ -82,8 +80,16 @@ func (enum *Enum) Define(c *Context) {
// Resource types
func (res *Resource) Define(c *Context) {
- c.Putln("// Skipping resource definition of '%s'",
- SrcName(c.protocol, res.XmlName()))
+ c.Putln("type %s uint32", res.SrcName())
+ c.Putln("")
+ c.Putln("func (c *Conn) New%sId() (%s, error) {",
+ res.SrcName(), res.SrcName())
+ c.Putln("id, err := c.NewId()")
+ c.Putln("if err != nil {")
+ c.Putln("return 0, err")
+ c.Putln("}")
+ c.Putln("return %s(id), nil", res.SrcName())
+ c.Putln("}")
c.Putln("")
}
diff --git a/nexgb/xgbgen/go_error.go b/nexgb/xgbgen/go_error.go
index c96866c..f4577ef 100644
--- a/nexgb/xgbgen/go_error.go
+++ b/nexgb/xgbgen/go_error.go
@@ -68,9 +68,9 @@ func (e *Error) ImplementsError(c *Context) {
c.Putln("return err.Sequence")
c.Putln("}")
c.Putln("")
- c.Putln("func (err %s) BadId() Id {", e.ErrType())
+ c.Putln("func (err %s) BadId() uint32 {", e.ErrType())
if !c.protocol.isExt() {
- c.Putln("return Id(err.BadValue)")
+ c.Putln("return err.BadValue")
} else {
c.Putln("return 0")
}
@@ -128,8 +128,12 @@ func (e *ErrorCopy) ImplementsError(c *Context) {
c.Putln("return err.Sequence")
c.Putln("}")
c.Putln("")
- c.Putln("func (err %s) BadId() Id {", e.ErrType())
- c.Putln("return Id(err.BadValue)")
+ c.Putln("func (err %s) BadId() uint32 {", e.ErrType())
+ if !c.protocol.isExt() {
+ c.Putln("return err.BadValue")
+ } else {
+ c.Putln("return 0")
+ }
c.Putln("}")
c.Putln("")
c.Putln("func (err %s) Error() string {", e.ErrType())
diff --git a/nexgb/xgbgen/go_list.go b/nexgb/xgbgen/go_list.go
index ad859bb..b01519b 100644
--- a/nexgb/xgbgen/go_list.go
+++ b/nexgb/xgbgen/go_list.go
@@ -16,7 +16,8 @@ func (f *ListField) Read(c *Context, prefix string) {
switch t := f.Type.(type) {
case *Resource:
length := f.LengthExpr.Reduce(prefix)
- c.Putln("%s%s = make([]Id, %s)", prefix, f.SrcName(), length)
+ c.Putln("%s%s = make([]%s, %s)",
+ prefix, f.SrcName(), t.SrcName(), length)
c.Putln("for i := 0; i < int(%s); i++ {", length)
ReadSimpleSingleField(c, fmt.Sprintf("%s%s[i]", prefix, f.SrcName()), t)
c.Putln("}")
diff --git a/nexgb/xgbgen/go_single_field.go b/nexgb/xgbgen/go_single_field.go
index ea43d55..433ebe3 100644
--- a/nexgb/xgbgen/go_single_field.go
+++ b/nexgb/xgbgen/go_single_field.go
@@ -12,7 +12,7 @@ func (f *SingleField) Define(c *Context) {
func ReadSimpleSingleField(c *Context, name string, typ Type) {
switch t := typ.(type) {
case *Resource:
- c.Putln("%s = Id(Get32(buf[b:]))", name)
+ c.Putln("%s = %s(Get32(buf[b:]))", name, t.SrcName())
case *TypeDef:
switch t.Size().Eval() {
case 1:
diff --git a/nexgb/xgbgen/translation.go b/nexgb/xgbgen/translation.go
index e4d81bc..44d615d 100644
--- a/nexgb/xgbgen/translation.go
+++ b/nexgb/xgbgen/translation.go
@@ -395,11 +395,6 @@ func TypeSrcName(p *Protocol, typ Type) string {
return newt
}
- // If it's a resource type, just use 'Id'.
- if _, ok := typ.(*Resource); ok {
- return xgbGenResourceIdName
- }
-
// If there's a namespace to this type, just use it and be done.
if colon := strings.Index(t, ":"); colon > -1 {
namespace := t[:colon]