aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/context.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 02:40:55 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 02:40:55 -0400
commit05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4 (patch)
tree028bfcc345c02afad9a6201e2af63ed638a3e8d9 /nexgb/xgbgen/context.go
parent3115c13e88badfd3b6b1762f2239edbf9d0b8951 (diff)
downloadhaven-05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4.tar.gz
haven-05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4.tar.xz
haven-05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4.zip
complete and total overhaul like i promised. things are much easier to reason about. still not working yet though.
Diffstat (limited to 'nexgb/xgbgen/context.go')
-rw-r--r--nexgb/xgbgen/context.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/nexgb/xgbgen/context.go b/nexgb/xgbgen/context.go
index 712cad4..d3cbb81 100644
--- a/nexgb/xgbgen/context.go
+++ b/nexgb/xgbgen/context.go
@@ -8,13 +8,12 @@ import (
)
type Context struct {
- xml *XML
+ protocol *Protocol
out *bytes.Buffer
}
func newContext() *Context {
return &Context{
- xml: &XML{},
out: bytes.NewBuffer([]byte{}),
}
}
@@ -32,22 +31,24 @@ func (c *Context) Put(format string, v ...interface{}) {
}
}
-
-// Translate is the big daddy of them all. It takes in an XML byte slice
+// Morph is the big daddy of them all. It takes in an XML byte slice,
+// parse it, transforms the XML types into more usable types,
// and writes Go code to the 'out' buffer.
-func (c *Context) Translate(xmlBytes []byte) {
- err := xml.Unmarshal(xmlBytes, c.xml)
+func (c *Context) Morph(xmlBytes []byte) {
+ parsedXml := &XML{}
+ err := xml.Unmarshal(xmlBytes, parsedXml)
if err != nil {
log.Fatal(err)
}
// Parse all imports
- c.xml.Imports.Eval()
+ parsedXml.Imports.Eval()
- // Make sure all top level enumerations have expressions
- // (For when there are empty items.)
- c.xml.Enums.Eval()
+ // Translate XML types to nice types
+ c.protocol = parsedXml.Translate()
- // It's Morphin' Time!
- c.xml.Morph(c)
+ // Now write Go source code
+ for _, typ := range c.protocol.Types {
+ typ.Define(c)
+ }
}