diff options
| author | Andrew Gallant (Ocelot) <[email protected]> | 2012-04-29 14:09:03 -0400 |
|---|---|---|
| committer | Andrew Gallant (Ocelot) <[email protected]> | 2012-04-29 14:09:03 -0400 |
| commit | f8f11e1419e4cf86189ccb9964b8235cef90eb4f (patch) | |
| tree | 402041713e5adb5dbbbdc6563e3946a926dec9c1 /xgbgen/xml.go | |
| parent | eb4f8cde88068649a60c494168490cb66335944c (diff) | |
last commit before i tear everything down
Diffstat (limited to 'xgbgen/xml.go')
| -rw-r--r-- | xgbgen/xml.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/xgbgen/xml.go b/xgbgen/xml.go index 12932b2..e4202d0 100644 --- a/xgbgen/xml.go +++ b/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 { |
