Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Gallant (Ocelot) authored and Andrew Gallant (Ocelot) committed Apr 30, 2012
1 parent 91ec0c0 commit f7be3db
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 233 deletions.
15 changes: 0 additions & 15 deletions xgbgen/bufcount.go

This file was deleted.

4 changes: 2 additions & 2 deletions xgbgen/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type Context struct {
protocol *Protocol
out *bytes.Buffer
out *bytes.Buffer
}

func newContext() *Context {
Expand All @@ -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'.
Expand Down
11 changes: 5 additions & 6 deletions xgbgen/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Expression interface {
}

type BinaryOp struct {
Op string
Op string
Expr1 Expression
Expr2 Expression
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func (e *BinaryOp) Initialize(p *Protocol) {
}

type UnaryOp struct {
Op string
Op string
Expr Expression
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -273,4 +273,3 @@ func (e *SumOf) String() string {
func (e *SumOf) Initialize(p *Protocol) {
e.Name = SrcName(e.Name)
}

19 changes: 9 additions & 10 deletions xgbgen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -132,8 +132,8 @@ func (f *ValueField) Initialize(p *Protocol) {
}

type SwitchField struct {
Name string
Expr Expression
Name string
Expr Expression
Bitcases []*Bitcase
}

Expand Down Expand Up @@ -165,6 +165,5 @@ func (f *SwitchField) Initialize(p *Protocol) {

type Bitcase struct {
Fields []Field
Expr Expression
Expr Expression
}

57 changes: 28 additions & 29 deletions xgbgen/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,51 @@ 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
// in the functions that follow. Basically, every occurrence of the key
// 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...

Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}

1 change: 0 additions & 1 deletion xgbgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ func main() {
}
}
}

50 changes: 0 additions & 50 deletions xgbgen/morph.go

This file was deleted.

17 changes: 8 additions & 9 deletions xgbgen/representation.go
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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) {
Expand All @@ -53,4 +53,3 @@ func (r *Reply) Initialize(p *Protocol) {
field.Initialize(p)
}
}

1 change: 0 additions & 1 deletion xgbgen/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ func (s1 Size) Add(s2 Size) Size {
func (s1 Size) Multiply(s2 Size) Size {
return Size{newBinaryOp("*", s1, s2)}
}

Loading

0 comments on commit f7be3db

Please sign in to comment.