aboutsummaryrefslogtreecommitdiff
path: root/nexgb
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 02:44:31 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 02:44:31 -0400
commit2a2d8653b3a7918dfb00dcca8937b0e878279c70 (patch)
tree39505670885d7ae838f9c306070336db4685e078 /nexgb
parent05d8ec6a16acf88c5ae7521d86131f5ea7f9b4e4 (diff)
downloadhaven-2a2d8653b3a7918dfb00dcca8937b0e878279c70.tar.gz
haven-2a2d8653b3a7918dfb00dcca8937b0e878279c70.tar.xz
haven-2a2d8653b3a7918dfb00dcca8937b0e878279c70.zip
gofmt
Diffstat (limited to 'nexgb')
-rw-r--r--nexgb/xgbgen/bufcount.go15
-rw-r--r--nexgb/xgbgen/context.go4
-rw-r--r--nexgb/xgbgen/expression.go11
-rw-r--r--nexgb/xgbgen/field.go19
-rw-r--r--nexgb/xgbgen/go.go57
-rw-r--r--nexgb/xgbgen/main.go1
-rw-r--r--nexgb/xgbgen/morph.go50
-rw-r--r--nexgb/xgbgen/representation.go17
-rw-r--r--nexgb/xgbgen/size.go1
-rw-r--r--nexgb/xgbgen/translation.go75
-rw-r--r--nexgb/xgbgen/type.go32
-rw-r--r--nexgb/xgbgen/xml.go81
-rw-r--r--nexgb/xgbgen/xml_expression.go16
-rw-r--r--nexgb/xgbgen/xml_fields.go17
14 files changed, 163 insertions, 233 deletions
diff --git a/nexgb/xgbgen/bufcount.go b/nexgb/xgbgen/bufcount.go
deleted file mode 100644
index c3a5645..0000000
--- a/nexgb/xgbgen/bufcount.go
+++ /dev/null
@@ -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
-}
-
diff --git a/nexgb/xgbgen/context.go b/nexgb/xgbgen/context.go
index d3cbb81..67801c7 100644
--- a/nexgb/xgbgen/context.go
+++ b/nexgb/xgbgen/context.go
@@ -9,7 +9,7 @@ import (
type Context struct {
protocol *Protocol
- out *bytes.Buffer
+ out *bytes.Buffer
}
func newContext() *Context {
@@ -20,7 +20,7 @@ func newContext() *Context {
// Putln calls put and adds a new line to the end of 'format'.
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'.
diff --git a/nexgb/xgbgen/expression.go b/nexgb/xgbgen/expression.go
index a163692..7099c25 100644
--- a/nexgb/xgbgen/expression.go
+++ b/nexgb/xgbgen/expression.go
@@ -14,7 +14,7 @@ type Expression interface {
}
type BinaryOp struct {
- Op string
+ Op string
Expr1 Expression
Expr2 Expression
}
@@ -23,7 +23,7 @@ func newBinaryOp(op string, expr1, expr2 Expression) Expression {
switch {
case expr1 != nil && expr2 != nil:
return &BinaryOp{
- Op: op,
+ Op: op,
Expr1: expr1,
Expr2: expr2,
}
@@ -79,7 +79,7 @@ func (e *BinaryOp) Initialize(p *Protocol) {
}
type UnaryOp struct {
- Op string
+ Op string
Expr Expression
}
@@ -159,7 +159,7 @@ func (e *Value) String() string {
return e.Reduce("", "")
}
-func (e *Value) Initialize(p *Protocol) { }
+func (e *Value) Initialize(p *Protocol) {}
type Bit struct {
b uint
@@ -181,7 +181,7 @@ func (e *Bit) String() string {
return e.Reduce("", "")
}
-func (e *Bit) Initialize(p *Protocol) { }
+func (e *Bit) Initialize(p *Protocol) {}
type FieldRef struct {
Name string
@@ -273,4 +273,3 @@ func (e *SumOf) String() string {
func (e *SumOf) Initialize(p *Protocol) {
e.Name = SrcName(e.Name)
}
-
diff --git a/nexgb/xgbgen/field.go b/nexgb/xgbgen/field.go
index a659e6e..ed113e0 100644
--- a/nexgb/xgbgen/field.go
+++ b/nexgb/xgbgen/field.go
@@ -31,7 +31,7 @@ func (p *PadField) Size() Size {
type SingleField struct {
srcName string
xmlName string
- Type Type
+ Type Type
}
func (f *SingleField) Initialize(p *Protocol) {
@@ -52,9 +52,9 @@ func (f *SingleField) Size() Size {
}
type ListField struct {
- srcName string
- xmlName string
- Type Type
+ srcName string
+ xmlName string
+ Type Type
LengthExpr Expression
}
@@ -85,8 +85,8 @@ type LocalField struct {
type ExprField struct {
srcName string
xmlName string
- Type Type
- Expr Expression
+ Type Type
+ Expr Expression
}
func (f *ExprField) SrcName() string {
@@ -132,8 +132,8 @@ func (f *ValueField) Initialize(p *Protocol) {
}
type SwitchField struct {
- Name string
- Expr Expression
+ Name string
+ Expr Expression
Bitcases []*Bitcase
}
@@ -165,6 +165,5 @@ func (f *SwitchField) Initialize(p *Protocol) {
type Bitcase struct {
Fields []Field
- Expr Expression
+ Expr Expression
}
-
diff --git a/nexgb/xgbgen/go.go b/nexgb/xgbgen/go.go
index ac3ed2c..014b76b 100644
--- a/nexgb/xgbgen/go.go
+++ b/nexgb/xgbgen/go.go
@@ -16,37 +16,37 @@ var xgbGenResourceIdName = "Id"
// XML protocol description will produce an invalid Go program.
// The types on the left *never* show themselves in the source.
var BaseTypeMap = map[string]string{
- "CARD8": "byte",
+ "CARD8": "byte",
"CARD16": "uint16",
"CARD32": "uint32",
- "INT8": "int8",
- "INT16": "int16",
- "INT32": "int32",
- "BYTE": "byte",
- "BOOL": "bool",
- "float": "float64",
+ "INT8": "int8",
+ "INT16": "int16",
+ "INT32": "int32",
+ "BYTE": "byte",
+ "BOOL": "bool",
+ "float": "float64",
"double": "float64",
- "char": "byte",
- "void": "byte",
- "Id": "Id",
+ "char": "byte",
+ "void": "byte",
+ "Id": "Id",
}
// BaseTypeSizes should have precisely the same keys as in BaseTypeMap,
// and the values should correspond to the size of the type in bytes.
var BaseTypeSizes = map[string]uint{
- "CARD8": 1,
+ "CARD8": 1,
"CARD16": 2,
"CARD32": 4,
- "INT8": 1,
- "INT16": 2,
- "INT32": 4,
- "BYTE": 1,
- "BOOL": 1,
- "float": 4,
+ "INT8": 1,
+ "INT16": 2,
+ "INT32": 4,
+ "BYTE": 1,
+ "BOOL": 1,
+ "float": 4,
"double": 8,
- "char": 1,
- "void": 1,
- "Id": 4,
+ "char": 1,
+ "void": 1,
+ "Id": 4,
}
// TypeMap is a map from types in the XML to type names that is used
@@ -54,13 +54,13 @@ var BaseTypeSizes = map[string]uint{
// type is replaced with the value type.
var TypeMap = map[string]string{
"VISUALTYPE": "VisualInfo",
- "DEPTH": "DepthInfo",
- "SCREEN": "ScreenInfo",
- "Setup": "SetupInfo",
+ "DEPTH": "DepthInfo",
+ "SCREEN": "ScreenInfo",
+ "Setup": "SetupInfo",
}
// NameMap is the same as TypeMap, but for names.
-var NameMap = map[string]string{ }
+var NameMap = map[string]string{}
// Reading, writing and defining...
@@ -151,8 +151,8 @@ func (s *Struct) ReadList(c *Context) {
c.Putln("consumed := 0")
c.Putln("consumed = 0 + consumed // no-op") // dirty hack for a no-op
c.Putln("for i := 0; i < length; i++ {")
- c.Putln("v[i], consumed = New%s(buf[b:])", s.SrcName())
- c.Putln("b += consumed")
+ c.Putln("v[i], consumed = New%s(buf[b:])", s.SrcName())
+ c.Putln("b += consumed")
c.Putln("}")
c.Putln("return v, pad(b)")
@@ -347,14 +347,14 @@ func (f *ListField) Read(c *Context) {
length := f.LengthExpr.Reduce("v.", "")
c.Putln("v.%s = make([]Id, %s)", f.SrcName(), length)
c.Putln("for i := 0; i < %s; i++ {", length)
- ReadSimpleSingleField(c, fmt.Sprintf("v.%s[i]", f.SrcName()), t)
+ ReadSimpleSingleField(c, fmt.Sprintf("v.%s[i]", f.SrcName()), t)
c.Putln("}")
c.Putln("")
case *Base:
length := f.LengthExpr.Reduce("v.", "")
c.Putln("v.%s = make([]%s, %s)", f.SrcName(), t.SrcName(), length)
c.Putln("for i := 0; i < %s; i++ {", length)
- ReadSimpleSingleField(c, fmt.Sprintf("v.%s[i]", f.SrcName()), t)
+ ReadSimpleSingleField(c, fmt.Sprintf("v.%s[i]", f.SrcName()), t)
c.Putln("}")
c.Putln("")
case *Struct:
@@ -408,4 +408,3 @@ func (f *SwitchField) Define(c *Context) {
func (f *SwitchField) Read(c *Context) {
c.Putln("// reading switch field: %s (%s)", f.Name, f.Expr)
}
-
diff --git a/nexgb/xgbgen/main.go b/nexgb/xgbgen/main.go
index 33f7971..fd5eac7 100644
--- a/nexgb/xgbgen/main.go
+++ b/nexgb/xgbgen/main.go
@@ -62,4 +62,3 @@ func main() {
}
}
}
-
diff --git a/nexgb/xgbgen/morph.go b/nexgb/xgbgen/morph.go
deleted file mode 100644
index c39b333..0000000
--- a/nexgb/xgbgen/morph.go
+++ /dev/null
@@ -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("")
-}
diff --git a/nexgb/xgbgen/representation.go b/nexgb/xgbgen/representation.go
index 928e219..2d33a45 100644
--- a/nexgb/xgbgen/representation.go
+++ b/nexgb/xgbgen/representation.go
@@ -1,14 +1,14 @@
package main
type Protocol struct {
- Name string
- ExtXName string
- ExtName string
+ Name string
+ ExtXName string
+ ExtName string
MajorVersion string
MinorVersion string
- Imports []*Protocol
- Types []Type
+ Imports []*Protocol
+ Types []Type
Requests []*Request
}
@@ -28,10 +28,10 @@ func (p *Protocol) Initialize() {
type Request struct {
srcName string
xmlName string
- Opcode int
+ Opcode int
Combine bool
- Fields []Field
- Reply *Reply
+ Fields []Field
+ Reply *Reply
}
func (r *Request) Initialize(p *Protocol) {
@@ -53,4 +53,3 @@ func (r *Reply) Initialize(p *Protocol) {
field.Initialize(p)
}
}
-
diff --git a/nexgb/xgbgen/size.go b/nexgb/xgbgen/size.go
index d00e297..70edb8f 100644
--- a/nexgb/xgbgen/size.go
+++ b/nexgb/xgbgen/size.go
@@ -19,4 +19,3 @@ func (s1 Size) Add(s2 Size) Size {
func (s1 Size) Multiply(s2 Size) Size {
return Size{newBinaryOp("*", s1, s2)}
}
-
diff --git a/nexgb/xgbgen/translation.go b/nexgb/xgbgen/translation.go
index 85e756d..36daa8b 100644
--- a/nexgb/xgbgen/translation.go
+++ b/nexgb/xgbgen/translation.go
@@ -1,4 +1,5 @@
package main
+
/*
translation.go provides a 'Translate' method on every XML type that converts
the XML type into our "better" representation.
@@ -19,14 +20,14 @@ import (
func (xml *XML) Translate() *Protocol {
protocol := &Protocol{
- Name: xml.Header,
- ExtXName: xml.ExtensionXName,
- ExtName: xml.ExtensionName,
+ Name: xml.Header,
+ ExtXName: xml.ExtensionXName,
+ ExtName: xml.ExtensionName,
MajorVersion: xml.MajorVersion,
MinorVersion: xml.MinorVersion,
- Imports: make([]*Protocol, 0),
- Types: make([]Type, 0),
+ Imports: make([]*Protocol, 0),
+ Types: make([]Type, 0),
Requests: make([]*Request, len(xml.Requests)),
}
@@ -40,7 +41,7 @@ func (xml *XML) Translate() *Protocol {
newBaseType := &Base{
srcName: srcName,
xmlName: xmlName,
- size: newFixedSize(BaseTypeSizes[xmlName]),
+ size: newFixedSize(BaseTypeSizes[xmlName]),
}
protocol.Types = append(protocol.Types, newBaseType)
}
@@ -105,12 +106,12 @@ func (xml *XML) Translate() *Protocol {
func (x *XMLEnum) Translate() *Enum {
enum := &Enum{
xmlName: x.Name,
- Items: make([]*EnumItem, len(x.Items)),
+ Items: make([]*EnumItem, len(x.Items)),
}
for i, item := range x.Items {
enum.Items[i] = &EnumItem{
xmlName: item.Name,
- Expr: item.Expr.Translate(),
+ Expr: item.Expr.Translate(),
}
}
return enum
@@ -125,16 +126,16 @@ func (x *XMLXid) Translate() *Resource {
func (x *XMLTypeDef) Translate() *TypeDef {
return &TypeDef{
xmlName: x.New,
- Old: newTranslation(x.Old),
+ Old: newTranslation(x.Old),
}
}
func (x *XMLEvent) Translate() *Event {
ev := &Event{
- xmlName: x.Name,
- Number: x.Number,
+ xmlName: x.Name,
+ Number: x.Number,
NoSequence: x.NoSequence,
- Fields: make([]Field, len(x.Fields)),
+ Fields: make([]Field, len(x.Fields)),
}
for i, field := range x.Fields {
ev.Fields[i] = field.Translate()
@@ -145,16 +146,16 @@ func (x *XMLEvent) Translate() *Event {
func (x *XMLEventCopy) Translate() *EventCopy {
return &EventCopy{
xmlName: x.Name,
- Number: x.Number,
- Old: newTranslation(x.Ref),
+ Number: x.Number,
+ Old: newTranslation(x.Ref),
}
}
func (x *XMLError) Translate() *Error {
err := &Error{
xmlName: x.Name,
- Number: x.Number,
- Fields: make([]Field, len(x.Fields)),
+ Number: x.Number,
+ Fields: make([]Field, len(x.Fields)),
}
for i, field := range x.Fields {
err.Fields[i] = field.Translate()
@@ -165,15 +166,15 @@ func (x *XMLError) Translate() *Error {
func (x *XMLErrorCopy) Translate() *ErrorCopy {
return &ErrorCopy{
xmlName: x.Name,
- Number: x.Number,
- Old: newTranslation(x.Ref),
+ Number: x.Number,
+ Old: newTranslation(x.Ref),
}
}
func (x *XMLStruct) Translate() *Struct {
s := &Struct{
xmlName: x.Name,
- Fields: make([]Field, len(x.Fields)),
+ Fields: make([]Field, len(x.Fields)),
}
for i, field := range x.Fields {
s.Fields[i] = field.Translate()
@@ -184,7 +185,7 @@ func (x *XMLStruct) Translate() *Struct {
func (x *XMLUnion) Translate() *Union {
u := &Union{
xmlName: x.Name,
- Fields: make([]Field, len(x.Fields)),
+ Fields: make([]Field, len(x.Fields)),
}
for i, field := range x.Fields {
u.Fields[i] = field.Translate()
@@ -195,10 +196,10 @@ func (x *XMLUnion) Translate() *Union {
func (x *XMLRequest) Translate() *Request {
r := &Request{
xmlName: x.Name,
- Opcode: x.Opcode,
+ Opcode: x.Opcode,
Combine: x.Combine,
- Fields: make([]Field, len(x.Fields)),
- Reply: x.Reply.Translate(),
+ Fields: make([]Field, len(x.Fields)),
+ Reply: x.Reply.Translate(),
}
for i, field := range x.Fields {
r.Fields[i] = field.Translate()
@@ -211,7 +212,7 @@ func (x *XMLRequest) Translate() *Request {
// (i.e., a parameter in the caller but does not get send over the wire.)
stringLenLocal := &LocalField{&SingleField{
xmlName: "string_len",
- Type: newTranslation("CARD16"),
+ Type: newTranslation("CARD16"),
}}
r.Fields = append(r.Fields, stringLenLocal)
@@ -243,7 +244,7 @@ func (x *XMLExpression) Translate() Expression {
log.Panicf("'op' found %d expressions; expected 2.", len(x.Exprs))
}
return &BinaryOp{
- Op: x.Op,
+ Op: x.Op,
Expr1: x.Exprs[0].Translate(),
Expr2: x.Exprs[1].Translate(),
}
@@ -252,7 +253,7 @@ func (x *XMLExpression) Translate() Expression {
log.Panicf("'unop' found %d expressions; expected 1.", len(x.Exprs))
}
return &UnaryOp{
- Op: x.Op,
+ Op: x.Op,
Expr: x.Exprs[0].Translate(),
}
case "popcount":
@@ -279,7 +280,7 @@ func (x *XMLExpression) Translate() Expression {
x.Data)
}
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)
}
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.",
x.XMLName.Local)
panic("unreachable")
@@ -315,24 +316,24 @@ func (x *XMLField) Translate() Field {
case "field":
return &SingleField{
xmlName: x.Name,
- Type: newTranslation(x.Type),
+ Type: newTranslation(x.Type),
}
case "list":
return &ListField{
- xmlName: x.Name,
- Type: newTranslation(x.Type),
+ xmlName: x.Name,
+ Type: newTranslation(x.Type),
LengthExpr: x.Expr.Translate(),
}
case "localfield":
return &LocalField{&SingleField{
xmlName: x.Name,
- Type: newTranslation(x.Type),
+ Type: newTranslation(x.Type),
}}
case "exprfield":
return &ExprField{
xmlName: x.Name,
- Type: newTranslation(x.Type),
- Expr: x.Expr.Translate(),
+ Type: newTranslation(x.Type),
+ Expr: x.Expr.Translate(),
}
case "valueparam":
return &ValueField{
@@ -342,8 +343,8 @@ func (x *XMLField) Translate() Field {
}
case "switch":
swtch := &SwitchField{
- Name: x.Name,
- Expr: x.Expr.Translate(),
+ Name: x.Name,
+ Expr: x.Expr.Translate(),
Bitcases: make([]*Bitcase, len(x.Bitcases)),
}
for i, bitcase := range x.Bitcases {
@@ -358,7 +359,7 @@ func (x *XMLField) Translate() Field {
func (x *XMLBitcase) Translate() *Bitcase {
b := &Bitcase{
- Expr: x.Expr().Translate(),
+ Expr: x.Expr().Translate(),
Fields: make([]Field, len(x.Fields)),
}
for i, field := range x.Fields {
diff --git a/nexgb/xgbgen/type.go b/nexgb/xgbgen/type.go
index 1574922..9fbef65 100644
--- a/nexgb/xgbgen/type.go
+++ b/nexgb/xgbgen/type.go
@@ -77,7 +77,7 @@ func (t *Translation) Initialize(p *Protocol) {
type Base struct {
srcName string
xmlName string
- size Size
+ size Size
}
func (b *Base) SrcName() string {
@@ -99,13 +99,13 @@ func (b *Base) Initialize(p *Protocol) {
type Enum struct {
srcName string
xmlName string
- Items []*EnumItem
+ Items []*EnumItem
}
type EnumItem struct {
srcName string
xmlName string
- Expr Expression
+ Expr Expression
}
func (enum *Enum) SrcName() string {
@@ -154,7 +154,7 @@ func (r *Resource) Initialize(p *Protocol) {
type TypeDef struct {
srcName string
xmlName string
- Old Type
+ Old Type
}
func (t *TypeDef) SrcName() string {
@@ -175,11 +175,11 @@ func (t *TypeDef) Initialize(p *Protocol) {
}
type Event struct {
- srcName string
- xmlName string
- Number int
+ srcName string
+ xmlName string
+ Number int
NoSequence bool
- Fields []Field
+ Fields []Field
}
func (e *Event) SrcName() string {
@@ -208,8 +208,8 @@ func (e *Event) EvType() string {
type EventCopy struct {
srcName string
xmlName string
- Old Type
- Number int
+ Old Type
+ Number int
}
func (e *EventCopy) SrcName() string {
@@ -239,8 +239,8 @@ func (e *EventCopy) EvType() string {
type Error struct {
srcName string
xmlName string
- Number int
- Fields []Field
+ Number int
+ Fields []Field
}
func (e *Error) SrcName() string {
@@ -270,8 +270,8 @@ func (e *Error) ErrType() string {
type ErrorCopy struct {
srcName string
xmlName string
- Old Type
- Number int
+ Old Type
+ Number int
}
func (e *ErrorCopy) SrcName() string {
@@ -305,7 +305,7 @@ func (e *ErrorCopy) ErrType() string {
type Struct struct {
srcName string
xmlName string
- Fields []Field
+ Fields []Field
}
func (s *Struct) SrcName() string {
@@ -334,7 +334,7 @@ func (s *Struct) Initialize(p *Protocol) {
type Union struct {
srcName string
xmlName string
- Fields []Field
+ Fields []Field
}
func (u *Union) SrcName() string {
diff --git a/nexgb/xgbgen/xml.go b/nexgb/xgbgen/xml.go
index 7e50831..f219c2d 100644
--- a/nexgb/xgbgen/xml.go
+++ b/nexgb/xgbgen/xml.go
@@ -8,29 +8,29 @@ import (
type XML struct {
// Root 'xcb' element properties.
- XMLName xml.Name `xml:"xcb"`
- Header string `xml:"header,attr"`
- ExtensionXName string `xml:"extension-xname,attr"`
- ExtensionName string `xml:"extension-name,attr"`
- MajorVersion string `xml:"major-version,attr"`
- MinorVersion string `xml:"minor-version,attr"`
+ XMLName xml.Name `xml:"xcb"`
+ Header string `xml:"header,attr"`
+ ExtensionXName string `xml:"extension-xname,attr"`
+ ExtensionName string `xml:"extension-name,attr"`
+ MajorVersion string `xml:"major-version,attr"`
+ MinorVersion string `xml:"minor-version,attr"`
// Types for all top-level elements.
// First are the simple ones.
- Imports XMLImports `xml:"import"`
- Enums XMLEnums `xml:"enum"`
- Xids XMLXids `xml:"xidtype"`
- XidUnions XMLXids `xml:"xidunion"`
- TypeDefs XMLTypeDefs `xml:"typedef"`
+ Imports XMLImports `xml:"import"`
+ Enums XMLEnums `xml:"enum"`
+ Xids XMLXids `xml:"xidtype"`
+ XidUnions XMLXids `xml:"xidunion"`
+ TypeDefs XMLTypeDefs `xml:"typedef"`
EventCopies XMLEventCopies `xml:"eventcopy"`
ErrorCopies XMLErrorCopies `xml:"errorcopy"`
// Here are the complex ones, i.e., anything with "structure contents"
- Structs XMLStructs `xml:"struct"`
- Unions XMLUnions `xml:"union"`
+ Structs XMLStructs `xml:"struct"`
+ Unions XMLUnions `xml:"union"`
Requests XMLRequests `xml:"request"`
- Events XMLEvents `xml:"event"`
- Errors XMLErrors `xml:"error"`
+ Events XMLEvents `xml:"event"`
+ Errors XMLErrors `xml:"error"`
}
type XMLImports []*XMLImport
@@ -39,14 +39,14 @@ func (imports XMLImports) Eval() {
for _, imp := range imports {
xmlBytes, err := ioutil.ReadFile(*protoPath + "/" + imp.Name + ".xml")
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)
}
imp.xml = &XML{}
err = xml.Unmarshal(xmlBytes, imp.xml)
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)
}
@@ -57,18 +57,18 @@ func (imports XMLImports) Eval() {
type XMLImport struct {
Name string `xml:",chardata"`
- xml *XML `xml:"-"`
+ xml *XML `xml:"-"`
}
type XMLEnums []XMLEnum
type XMLEnum struct {
- Name string `xml:"name,attr"`
+ Name string `xml:"name,attr"`
Items []*XMLEnumItem `xml:"item"`
}
type XMLEnumItem struct {
- Name string `xml:"name,attr"`
+ Name string `xml:"name,attr"`
Expr *XMLExpression `xml:",any"`
}
@@ -76,7 +76,7 @@ type XMLXids []*XMLXid
type XMLXid struct {
XMLName xml.Name
- Name string `xml:"name,attr"`
+ Name string `xml:"name,attr"`
}
type XMLTypeDefs []*XMLTypeDef
@@ -89,41 +89,41 @@ type XMLTypeDef struct {
type XMLEventCopies []*XMLEventCopy
type XMLEventCopy struct {
- Name string `xml:"name,attr"`
- Number int `xml:"number,attr"`
- Ref string `xml:"ref,attr"`
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
+ Ref string `xml:"ref,attr"`
}
type XMLErrorCopies []*XMLErrorCopy
type XMLErrorCopy struct {
- Name string `xml:"name,attr"`
- Number int `xml:"number,attr"`
- Ref string `xml:"ref,attr"`
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
+ Ref string `xml:"ref,attr"`
}
type XMLStructs []*XMLStruct
type XMLStruct struct {
- Name string `xml:"name,attr"`
+ Name string `xml:"name,attr"`
Fields XMLFields `xml:",any"`
}
type XMLUnions []*XMLUnion
type XMLUnion struct {
- Name string `xml:"name,attr"`
+ Name string `xml:"name,attr"`
Fields XMLFields `xml:",any"`
}
type XMLRequests []*XMLRequest
type XMLRequest struct {
- Name string `xml:"name,attr"`
- Opcode int `xml:"opcode,attr"`
- Combine bool `xml:"combine-adjacent,attr"`
- Fields XMLFields `xml:",any"`
- Reply *XMLReply `xml:"reply"`
+ Name string `xml:"name,attr"`
+ Opcode int `xml:"opcode,attr"`
+ Combine bool `xml:"combine-adjacent,attr"`
+ Fields XMLFields `xml:",any"`
+ Reply *XMLReply `xml:"reply"`
}
type XMLReply struct {
@@ -133,17 +133,16 @@ type XMLReply struct {
type XMLEvents []*XMLEvent
type XMLEvent struct {
- Name string `xml:"name,attr"`
- Number int `xml:"number,attr"`
- NoSequence bool `xml:"no-sequence-number,true"`
- Fields XMLFields `xml:",any"`
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
+ NoSequence bool `xml:"no-sequence-number,true"`
+ Fields XMLFields `xml:",any"`
}
type XMLErrors []*XMLError
type XMLError struct {
- Name string `xml:"name,attr"`
- Number int `xml:"number,attr"`
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
Fields XMLFields `xml:",any"`
}
-
diff --git a/nexgb/xgbgen/xml_expression.go b/nexgb/xgbgen/xml_expression.go
index 57ff62e..2989668 100644
--- a/nexgb/xgbgen/xml_expression.go
+++ b/nexgb/xgbgen/xml_expression.go
@@ -13,14 +13,14 @@ type XMLExpression struct {
Exprs []*XMLExpression `xml:",any"`
Data string `xml:",chardata"`
- Op string `xml:"op,attr"`
- Ref string `xml:"ref,attr"`
+ Op string `xml:"op,attr"`
+ Ref string `xml:"ref,attr"`
}
func newValueExpression(v uint) *XMLExpression {
return &XMLExpression{
XMLName: xml.Name{Local: "value"},
- Data: fmt.Sprintf("%d", v),
+ Data: fmt.Sprintf("%d", v),
}
}
@@ -87,22 +87,22 @@ func (e *XMLExpression) Eval() uint {
e.Data)
}
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)
}
return 1 << uint(bit)
case "fieldref":
- log.Panicf("Cannot compute concrete value of 'fieldref' in " +
+ log.Panicf("Cannot compute concrete value of 'fieldref' in "+
"expression '%s'.", e)
case "enumref":
- log.Panicf("Cannot compute concrete value of 'enumref' in " +
+ log.Panicf("Cannot compute concrete value of 'enumref' in "+
"expression '%s'.", e)
case "sumof":
- log.Panicf("Cannot compute concrete value of 'sumof' in " +
+ log.Panicf("Cannot compute concrete value of 'sumof' in "+
"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.",
e.XMLName.Local)
panic("unreachable")
diff --git a/nexgb/xgbgen/xml_fields.go b/nexgb/xgbgen/xml_fields.go
index d6d99c5..991141b 100644
--- a/nexgb/xgbgen/xml_fields.go
+++ b/nexgb/xgbgen/xml_fields.go
@@ -1,4 +1,5 @@
package main
+
/*
A series of fields should be taken as "structure contents", and *not*
just the single 'field' elements. Namely, 'fields' subsumes 'field'
@@ -50,8 +51,8 @@ type XMLField struct {
// I don't know which elements these are for. The documentation is vague.
// They also seem to be completely optional.
- OptEnum string `xml:"enum,attr"`
- OptMask string `xml:"mask,attr"`
+ OptEnum string `xml:"enum,attr"`
+ OptMask string `xml:"mask,attr"`
OptAltEnum string `xml:"altenum,attr"`
}
@@ -103,14 +104,14 @@ type XMLBitcase struct {
// All the different expressions.
// When it comes time to choose one, use the 'Expr' method.
- ExprOp *XMLExpression `xml:"op"`
- ExprUnOp *XMLExpression `xml:"unop"`
+ ExprOp *XMLExpression `xml:"op"`
+ ExprUnOp *XMLExpression `xml:"unop"`
ExprField *XMLExpression `xml:"fieldref"`
ExprValue *XMLExpression `xml:"value"`
- ExprBit *XMLExpression `xml:"bit"`
- ExprEnum *XMLExpression `xml:"enumref"`
- ExprSum *XMLExpression `xml:"sumof"`
- ExprPop *XMLExpression `xml:"popcount"`
+ ExprBit *XMLExpression `xml:"bit"`
+ ExprEnum *XMLExpression `xml:"enumref"`
+ ExprSum *XMLExpression `xml:"sumof"`
+ ExprPop *XMLExpression `xml:"popcount"`
}
// StringPrefix is for debugging purposes only.