aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/xml.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-29 14:09:03 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-29 14:09:03 -0400
commit3115c13e88badfd3b6b1762f2239edbf9d0b8951 (patch)
treed6f43e521b496953faae7788d0b74bd13f6dda1c /nexgb/xgbgen/xml.go
parent6bf0191fb01f4c0b65bcd444bb5381013c627f95 (diff)
downloadhaven-3115c13e88badfd3b6b1762f2239edbf9d0b8951.tar.gz
haven-3115c13e88badfd3b6b1762f2239edbf9d0b8951.tar.xz
haven-3115c13e88badfd3b6b1762f2239edbf9d0b8951.zip
last commit before i tear everything down
Diffstat (limited to 'nexgb/xgbgen/xml.go')
-rw-r--r--nexgb/xgbgen/xml.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/nexgb/xgbgen/xml.go b/nexgb/xgbgen/xml.go
index 12932b2..e4202d0 100644
--- a/nexgb/xgbgen/xml.go
+++ b/nexgb/xgbgen/xml.go
@@ -166,6 +166,48 @@ type Name string
type Type string
+// Union returns the 'Union' struct corresponding to this type, if
+// one exists.
+func (typ Type) Union(c *Context) *Union {
+ // If this is a typedef, use that instead.
+ if oldTyp, ok := typ.TypeDef(c); ok {
+ return oldTyp.Union(c)
+ }
+
+ // Otherwise, just look for a union type with 'typ' name.
+ for _, union := range c.xml.Unions {
+ if typ == union.Name {
+ return union
+ }
+ }
+ for _, imp := range c.xml.Imports {
+ for _, union := range imp.xml.Unions {
+ if typ == union.Name {
+ return union
+ }
+ }
+ }
+ return nil
+}
+
+// TypeDef returns the 'old' type corresponding to this type, if it's found
+// in a type def. If not found, the second return value is false.
+func (typ Type) TypeDef(c *Context) (Type, bool) {
+ for _, typedef := range c.xml.TypeDefs {
+ if typ == typedef.New {
+ return typedef.Old, true
+ }
+ }
+ for _, imp := range c.xml.Imports {
+ for _, typedef := range imp.xml.TypeDefs {
+ if typ == typedef.New {
+ return typedef.Old, true
+ }
+ }
+ }
+ return "", false
+}
+
// Size is a nifty function that takes any type and digs until it finds
// its underlying base type. At which point, the size can be determined.
func (typ Type) Size(c *Context) uint {