From 05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Mon, 30 Apr 2012 02:40:55 -0400 Subject: complete and total overhaul like i promised. things are much easier to reason about. still not working yet though. --- nexgb/xgbgen/context.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'nexgb/xgbgen/context.go') 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) + } } -- cgit v1.2.3