Updated to work with new xproto XML files.
Namely, the "doc" element is ignored. Also, I've sorted everything before output so that diff isn't completely useless.
This commit is contained in:
parent
5d96993ee1
commit
4b20ffaf4f
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -70,6 +71,8 @@ func (c *Context) Morph(xmlBytes []byte) {
|
||||||
if c.protocol.isExt() {
|
if c.protocol.isExt() {
|
||||||
c.Putln("\"github.com/BurntSushi/xgb/xproto\"")
|
c.Putln("\"github.com/BurntSushi/xgb/xproto\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Sort(Protocols(c.protocol.Imports))
|
||||||
for _, imp := range c.protocol.Imports {
|
for _, imp := range c.protocol.Imports {
|
||||||
// We always import xproto, so skip it if it's explicitly imported
|
// We always import xproto, so skip it if it's explicitly imported
|
||||||
if imp.Name == "xproto" {
|
if imp.Name == "xproto" {
|
||||||
|
@ -142,6 +145,8 @@ func (c *Context) Morph(xmlBytes []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now write Go source code
|
// Now write Go source code
|
||||||
|
sort.Sort(Types(c.protocol.Types))
|
||||||
|
sort.Sort(Requests(c.protocol.Requests))
|
||||||
for _, typ := range c.protocol.Types {
|
for _, typ := range c.protocol.Types {
|
||||||
typ.Define(c)
|
typ.Define(c)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,12 @@ type Protocol struct {
|
||||||
Requests []*Request
|
Requests []*Request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Protocols []*Protocol
|
||||||
|
|
||||||
|
func (ps Protocols) Len() int { return len(ps) }
|
||||||
|
func (ps Protocols) Swap(i, j int) { ps[i], ps[j] = ps[j], ps[i] }
|
||||||
|
func (ps Protocols) Less(i, j int) bool { return ps[i].ExtName < ps[j].ExtName }
|
||||||
|
|
||||||
// Initialize traverses all structures, looks for 'Translation' type,
|
// Initialize traverses all structures, looks for 'Translation' type,
|
||||||
// and looks up the real type in the namespace. It also sets the source
|
// and looks up the real type in the namespace. It also sets the source
|
||||||
// name for all relevant fields/structures.
|
// name for all relevant fields/structures.
|
||||||
|
|
|
@ -17,6 +17,12 @@ type Request struct {
|
||||||
Reply *Reply // A reply, if one exists for this request.
|
Reply *Reply // A reply, if one exists for this request.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Requests []*Request
|
||||||
|
|
||||||
|
func (rs Requests) Len() int { return len(rs) }
|
||||||
|
func (rs Requests) Swap(i, j int) { rs[i], rs[j] = rs[j], rs[i] }
|
||||||
|
func (rs Requests) Less(i, j int) bool { return rs[i].xmlName < rs[j].xmlName }
|
||||||
|
|
||||||
// Initialize creates the proper Go source name for this request.
|
// Initialize creates the proper Go source name for this request.
|
||||||
// It also initializes the reply if one exists, and all fields in this request.
|
// It also initializes the reply if one exists, and all fields in this request.
|
||||||
func (r *Request) Initialize(p *Protocol) {
|
func (r *Request) Initialize(p *Protocol) {
|
||||||
|
|
|
@ -137,10 +137,13 @@ func (x *XMLEvent) Translate() *Event {
|
||||||
xmlName: x.Name,
|
xmlName: x.Name,
|
||||||
Number: x.Number,
|
Number: x.Number,
|
||||||
NoSequence: x.NoSequence,
|
NoSequence: x.NoSequence,
|
||||||
Fields: make([]Field, len(x.Fields)),
|
Fields: make([]Field, 0, len(x.Fields)),
|
||||||
}
|
}
|
||||||
for i, field := range x.Fields {
|
for _, field := range x.Fields {
|
||||||
ev.Fields[i] = field.Translate(ev)
|
if field.XMLName.Local == "doc" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ev.Fields = append(ev.Fields, field.Translate(ev))
|
||||||
}
|
}
|
||||||
return ev
|
return ev
|
||||||
}
|
}
|
||||||
|
@ -200,11 +203,14 @@ func (x *XMLRequest) Translate() *Request {
|
||||||
xmlName: x.Name,
|
xmlName: x.Name,
|
||||||
Opcode: x.Opcode,
|
Opcode: x.Opcode,
|
||||||
Combine: x.Combine,
|
Combine: x.Combine,
|
||||||
Fields: make([]Field, len(x.Fields)),
|
Fields: make([]Field, 0, len(x.Fields)),
|
||||||
Reply: x.Reply.Translate(),
|
Reply: x.Reply.Translate(),
|
||||||
}
|
}
|
||||||
for i, field := range x.Fields {
|
for _, field := range x.Fields {
|
||||||
r.Fields[i] = field.Translate(r)
|
if field.XMLName.Local == "doc" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
r.Fields = append(r.Fields, field.Translate(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Address bug (or legacy code) in QueryTextExtents.
|
// Address bug (or legacy code) in QueryTextExtents.
|
||||||
|
@ -229,10 +235,13 @@ func (x *XMLReply) Translate() *Reply {
|
||||||
}
|
}
|
||||||
|
|
||||||
r := &Reply{
|
r := &Reply{
|
||||||
Fields: make([]Field, len(x.Fields)),
|
Fields: make([]Field, 0, len(x.Fields)),
|
||||||
}
|
}
|
||||||
for i, field := range x.Fields {
|
for _, field := range x.Fields {
|
||||||
r.Fields[i] = field.Translate(r)
|
if field.XMLName.Local == "doc" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
r.Fields = append(r.Fields, field.Translate(r))
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
@ -380,7 +389,6 @@ func SrcName(p *Protocol, name string) string {
|
||||||
if newn, ok := NameMap[name]; ok {
|
if newn, ok := NameMap[name]; ok {
|
||||||
return newn
|
return newn
|
||||||
}
|
}
|
||||||
|
|
||||||
return splitAndTitle(name)
|
return splitAndTitle(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,16 @@ type Type interface {
|
||||||
Define(c *Context)
|
Define(c *Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Types []Type
|
||||||
|
|
||||||
|
func (ts Types) Len() int { return len(ts) }
|
||||||
|
func (ts Types) Swap(i, j int) { ts[i], ts[j] = ts[j], ts[i] }
|
||||||
|
func (ts Types) Less(i, j int) bool {
|
||||||
|
x1, x2 := ts[i].XmlName(), ts[j].XmlName()
|
||||||
|
s1, s2 := ts[i].SrcName(), ts[j].SrcName()
|
||||||
|
return (s1 == s2 && x1 < x2) || s1 < s2
|
||||||
|
}
|
||||||
|
|
||||||
// Translation is used *only* when transitioning from XML types to
|
// Translation is used *only* when transitioning from XML types to
|
||||||
// our better representation. They are placeholders for the real types (below)
|
// our better representation. They are placeholders for the real types (below)
|
||||||
// that will replace them.
|
// that will replace them.
|
||||||
|
|
Loading…
Reference in New Issue