aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/representation.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/representation.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/representation.go')
-rw-r--r--nexgb/xgbgen/representation.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/nexgb/xgbgen/representation.go b/nexgb/xgbgen/representation.go
new file mode 100644
index 0000000..928e219
--- /dev/null
+++ b/nexgb/xgbgen/representation.go
@@ -0,0 +1,56 @@
+package main
+
+type Protocol struct {
+ Name string
+ ExtXName string
+ ExtName string
+ MajorVersion string
+ MinorVersion string
+
+ Imports []*Protocol
+ Types []Type
+ Requests []*Request
+}
+
+// Initialize traverses all structures, looks for 'Translation' type,
+// and looks up the real type in the namespace. It also sets the source
+// name for all relevant fields/structures.
+// This is necessary because we don't traverse the XML in order initially.
+func (p *Protocol) Initialize() {
+ for _, typ := range p.Types {
+ typ.Initialize(p)
+ }
+ for _, req := range p.Requests {
+ req.Initialize(p)
+ }
+}
+
+type Request struct {
+ srcName string
+ xmlName string
+ Opcode int
+ Combine bool
+ Fields []Field
+ Reply *Reply
+}
+
+func (r *Request) Initialize(p *Protocol) {
+ r.srcName = SrcName(r.xmlName)
+ if r.Reply != nil {
+ r.Reply.Initialize(p)
+ }
+ for _, field := range r.Fields {
+ field.Initialize(p)
+ }
+}
+
+type Reply struct {
+ Fields []Field
+}
+
+func (r *Reply) Initialize(p *Protocol) {
+ for _, field := range r.Fields {
+ field.Initialize(p)
+ }
+}
+