This commit is contained in:
Andrew Gallant (Ocelot) 2012-04-30 02:44:31 -04:00
parent 05d8ec6a16
commit 2a2d8653b3
14 changed files with 163 additions and 233 deletions

View File

@ -1,15 +0,0 @@
package main
/*
A buffer count is a mechanism by which to keep track of which byte one
is reading or writing to/from the wire.
It's an abstraction over the fact that while such a counter is usually
fixed, it can be made variable based on values at run-time.
*/
type BufCount struct {
Fixed int
Exprs []*Expression
}

View File

@ -20,7 +20,7 @@ func newContext() *Context {
// Putln calls put and adds a new line to the end of 'format'. // Putln calls put and adds a new line to the end of 'format'.
func (c *Context) Putln(format string, v ...interface{}) { func (c *Context) Putln(format string, v ...interface{}) {
c.Put(format + "\n", v...) c.Put(format+"\n", v...)
} }
// Put is a short alias to write to 'out'. // Put is a short alias to write to 'out'.

View File

@ -159,7 +159,7 @@ func (e *Value) String() string {
return e.Reduce("", "") return e.Reduce("", "")
} }
func (e *Value) Initialize(p *Protocol) { } func (e *Value) Initialize(p *Protocol) {}
type Bit struct { type Bit struct {
b uint b uint
@ -181,7 +181,7 @@ func (e *Bit) String() string {
return e.Reduce("", "") return e.Reduce("", "")
} }
func (e *Bit) Initialize(p *Protocol) { } func (e *Bit) Initialize(p *Protocol) {}
type FieldRef struct { type FieldRef struct {
Name string Name string
@ -273,4 +273,3 @@ func (e *SumOf) String() string {
func (e *SumOf) Initialize(p *Protocol) { func (e *SumOf) Initialize(p *Protocol) {
e.Name = SrcName(e.Name) e.Name = SrcName(e.Name)
} }

View File

@ -167,4 +167,3 @@ type Bitcase struct {
Fields []Field Fields []Field
Expr Expression Expr Expression
} }

View File

@ -60,7 +60,7 @@ var TypeMap = map[string]string{
} }
// NameMap is the same as TypeMap, but for names. // NameMap is the same as TypeMap, but for names.
var NameMap = map[string]string{ } var NameMap = map[string]string{}
// Reading, writing and defining... // Reading, writing and defining...
@ -408,4 +408,3 @@ func (f *SwitchField) Define(c *Context) {
func (f *SwitchField) Read(c *Context) { func (f *SwitchField) Read(c *Context) {
c.Putln("// reading switch field: %s (%s)", f.Name, f.Expr) c.Putln("// reading switch field: %s (%s)", f.Name, f.Expr)
} }

View File

@ -62,4 +62,3 @@ func main() {
} }
} }
} }

View File

@ -1,50 +0,0 @@
// Morph cascades down all of the XML and calls each type's corresponding
// Morph function with itself as an argument (the context).
func (x *XML) Morph(c *Context) {
// Start the header...
c.Putln("package xgb")
c.Putln("/*")
c.Putln("\tX protocol API for '%s.xml'.", c.xml.Header)
c.Putln("\tThis file is automatically generated. Edit at your own peril!")
c.Putln("\tGenerated on %s",
time.Now().Format("Jan 2, 2006 at 3:04:05pm MST"))
c.Putln("*/")
c.Putln("")
x.Imports.Morph(c)
c.Putln("")
x.Enums.Morph(c)
c.Putln("")
x.Xids.Morph(c)
c.Putln("")
x.XidUnions.Morph(c)
c.Putln("")
x.TypeDefs.Morph(c)
c.Putln("")
x.Structs.Morph(c)
c.Putln("")
x.Unions.Morph(c)
c.Putln("")
x.Requests.Morph(c)
c.Putln("")
x.Errors.Morph(c)
c.Putln("")
x.ErrorCopies.Morph(c)
c.Putln("")
x.Events.Morph(c)
c.Putln("")
x.EventCopies.Morph(c)
c.Putln("")
}

View File

@ -53,4 +53,3 @@ func (r *Reply) Initialize(p *Protocol) {
field.Initialize(p) field.Initialize(p)
} }
} }

View File

@ -19,4 +19,3 @@ func (s1 Size) Add(s2 Size) Size {
func (s1 Size) Multiply(s2 Size) Size { func (s1 Size) Multiply(s2 Size) Size {
return Size{newBinaryOp("*", s1, s2)} return Size{newBinaryOp("*", s1, s2)}
} }

View File

@ -1,4 +1,5 @@
package main package main
/* /*
translation.go provides a 'Translate' method on every XML type that converts translation.go provides a 'Translate' method on every XML type that converts
the XML type into our "better" representation. the XML type into our "better" representation.
@ -279,7 +280,7 @@ func (x *XMLExpression) Translate() Expression {
x.Data) x.Data)
} }
if bit < 0 || bit > 31 { if bit < 0 || bit > 31 {
log.Panicf("A 'bit' literal must be in the range [0, 31], but " + log.Panicf("A 'bit' literal must be in the range [0, 31], but "+
" is %d", bit) " is %d", bit)
} }
return &Bit{ return &Bit{
@ -300,7 +301,7 @@ func (x *XMLExpression) Translate() Expression {
} }
} }
log.Panicf("Unrecognized tag '%s' in expression context. Expected one of " + log.Panicf("Unrecognized tag '%s' in expression context. Expected one of "+
"op, fieldref, value, bit, enumref, unop, sumof or popcount.", "op, fieldref, value, bit, enumref, unop, sumof or popcount.",
x.XMLName.Local) x.XMLName.Local)
panic("unreachable") panic("unreachable")

View File

@ -39,14 +39,14 @@ func (imports XMLImports) Eval() {
for _, imp := range imports { for _, imp := range imports {
xmlBytes, err := ioutil.ReadFile(*protoPath + "/" + imp.Name + ".xml") xmlBytes, err := ioutil.ReadFile(*protoPath + "/" + imp.Name + ".xml")
if err != nil { if err != nil {
log.Fatalf("Could not read X protocol description for import " + log.Fatalf("Could not read X protocol description for import "+
"'%s' because: %s", imp.Name, err) "'%s' because: %s", imp.Name, err)
} }
imp.xml = &XML{} imp.xml = &XML{}
err = xml.Unmarshal(xmlBytes, imp.xml) err = xml.Unmarshal(xmlBytes, imp.xml)
if err != nil { if err != nil {
log.Fatal("Could not parse X protocol description for import " + log.Fatal("Could not parse X protocol description for import "+
"'%s' because: %s", imp.Name, err) "'%s' because: %s", imp.Name, err)
} }
@ -146,4 +146,3 @@ type XMLError struct {
Number int `xml:"number,attr"` Number int `xml:"number,attr"`
Fields XMLFields `xml:",any"` Fields XMLFields `xml:",any"`
} }

View File

@ -87,22 +87,22 @@ func (e *XMLExpression) Eval() uint {
e.Data) e.Data)
} }
if bit < 0 || bit > 31 { if bit < 0 || bit > 31 {
log.Panicf("A 'bit' literal must be in the range [0, 31], but " + log.Panicf("A 'bit' literal must be in the range [0, 31], but "+
" is %d", bit) " is %d", bit)
} }
return 1 << uint(bit) return 1 << uint(bit)
case "fieldref": case "fieldref":
log.Panicf("Cannot compute concrete value of 'fieldref' in " + log.Panicf("Cannot compute concrete value of 'fieldref' in "+
"expression '%s'.", e) "expression '%s'.", e)
case "enumref": case "enumref":
log.Panicf("Cannot compute concrete value of 'enumref' in " + log.Panicf("Cannot compute concrete value of 'enumref' in "+
"expression '%s'.", e) "expression '%s'.", e)
case "sumof": case "sumof":
log.Panicf("Cannot compute concrete value of 'sumof' in " + log.Panicf("Cannot compute concrete value of 'sumof' in "+
"expression '%s'.", e) "expression '%s'.", e)
} }
log.Panicf("Unrecognized tag '%s' in expression context. Expected one of " + log.Panicf("Unrecognized tag '%s' in expression context. Expected one of "+
"op, fieldref, value, bit, enumref, unop, sumof or popcount.", "op, fieldref, value, bit, enumref, unop, sumof or popcount.",
e.XMLName.Local) e.XMLName.Local)
panic("unreachable") panic("unreachable")

View File

@ -1,4 +1,5 @@
package main package main
/* /*
A series of fields should be taken as "structure contents", and *not* A series of fields should be taken as "structure contents", and *not*
just the single 'field' elements. Namely, 'fields' subsumes 'field' just the single 'field' elements. Namely, 'fields' subsumes 'field'