2012-04-29 05:25:57 +02:00
|
|
|
package main
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// xgbResourceIdName is the name of the type used for all resource identifiers.
|
|
|
|
// As of right now, it needs to be declared somewhere manually.
|
|
|
|
var xgbGenResourceIdName = "Id"
|
2012-04-29 05:25:57 +02:00
|
|
|
|
|
|
|
// BaseTypeMap is a map from X base types to Go types.
|
|
|
|
// X base types should correspond to the smallest set of X types
|
|
|
|
// that can be used to rewrite ALL X types in terms of Go types.
|
|
|
|
// That is, if you remove any of the following types, at least one
|
|
|
|
// 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{
|
2012-04-30 08:44:31 +02:00
|
|
|
"CARD8": "byte",
|
2012-04-29 05:25:57 +02:00
|
|
|
"CARD16": "uint16",
|
|
|
|
"CARD32": "uint32",
|
2012-04-30 08:44:31 +02:00
|
|
|
"INT8": "int8",
|
|
|
|
"INT16": "int16",
|
|
|
|
"INT32": "int32",
|
|
|
|
"BYTE": "byte",
|
|
|
|
"BOOL": "bool",
|
|
|
|
"float": "float64",
|
2012-04-29 05:25:57 +02:00
|
|
|
"double": "float64",
|
2012-04-30 08:44:31 +02:00
|
|
|
"char": "byte",
|
|
|
|
"void": "byte",
|
|
|
|
"Id": "Id",
|
2012-04-29 09:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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{
|
2012-04-30 08:44:31 +02:00
|
|
|
"CARD8": 1,
|
2012-04-29 09:38:29 +02:00
|
|
|
"CARD16": 2,
|
|
|
|
"CARD32": 4,
|
2012-04-30 08:44:31 +02:00
|
|
|
"INT8": 1,
|
|
|
|
"INT16": 2,
|
|
|
|
"INT32": 4,
|
|
|
|
"BYTE": 1,
|
|
|
|
"BOOL": 1,
|
|
|
|
"float": 4,
|
2012-04-29 09:38:29 +02:00
|
|
|
"double": 8,
|
2012-04-30 08:44:31 +02:00
|
|
|
"char": 1,
|
|
|
|
"void": 1,
|
|
|
|
"Id": 4,
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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",
|
2012-04-30 08:44:31 +02:00
|
|
|
"DEPTH": "DepthInfo",
|
|
|
|
"SCREEN": "ScreenInfo",
|
|
|
|
"Setup": "SetupInfo",
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NameMap is the same as TypeMap, but for names.
|
2012-04-30 08:44:31 +02:00
|
|
|
var NameMap = map[string]string{}
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// Reading, writing and defining...
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// Base types
|
|
|
|
func (b *Base) Define(c *Context) {
|
|
|
|
c.Putln("// Skipping definition for base type '%s'", SrcName(b.XmlName()))
|
|
|
|
c.Putln("")
|
2012-04-29 09:38:29 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// Enum types
|
|
|
|
func (enum *Enum) Define(c *Context) {
|
|
|
|
c.Putln("const (")
|
|
|
|
for _, item := range enum.Items {
|
|
|
|
c.Putln("%s%s = %d", enum.SrcName(), item.srcName, item.Expr.Eval())
|
2012-04-29 09:38:29 +02:00
|
|
|
}
|
2012-04-30 08:40:55 +02:00
|
|
|
c.Putln(")")
|
|
|
|
c.Putln("")
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// Resource types
|
|
|
|
func (res *Resource) Define(c *Context) {
|
|
|
|
c.Putln("// Skipping resource definition of '%s'", SrcName(res.XmlName()))
|
|
|
|
c.Putln("")
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// TypeDef types
|
|
|
|
func (td *TypeDef) Define(c *Context) {
|
|
|
|
c.Putln("type %s %s", td.srcName, td.Old.SrcName())
|
|
|
|
c.Putln("")
|
2012-04-29 09:38:29 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// Field definitions, reads and writes.
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// Pad fields
|
|
|
|
func (f *PadField) Define(c *Context) {
|
|
|
|
c.Putln("// padding: %d bytes", f.Bytes)
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
func (f *PadField) Read(c *Context) {
|
|
|
|
c.Putln("b += %s // padding", f.Size())
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 22:18:17 +02:00
|
|
|
func (f *PadField) Write(c *Context) {
|
|
|
|
c.Putln("b += %s // padding", f.Size())
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// Local fields
|
|
|
|
func (f *LocalField) Define(c *Context) {
|
|
|
|
c.Putln("// local field: %s %s", f.SrcName(), f.Type.SrcName())
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
func (f *LocalField) Read(c *Context) {
|
|
|
|
c.Putln("// reading local field: %s (%s) :: %s",
|
|
|
|
f.SrcName(), f.Size(), f.Type.SrcName())
|
2012-04-30 22:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *LocalField) Write(c *Context) {
|
|
|
|
c.Putln("// writing local field: %s (%s) :: %s",
|
|
|
|
f.SrcName(), f.Size(), f.Type.SrcName())
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
// Expr fields
|
|
|
|
func (f *ExprField) Define(c *Context) {
|
|
|
|
c.Putln("// expression field: %s %s (%s)",
|
|
|
|
f.SrcName(), f.Type.SrcName(), f.Expr)
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
func (f *ExprField) Read(c *Context) {
|
|
|
|
c.Putln("// reading expression field: %s (%s) (%s) :: %s",
|
|
|
|
f.SrcName(), f.Size(), f.Expr, f.Type.SrcName())
|
2012-04-30 22:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ExprField) Write(c *Context) {
|
|
|
|
c.Putln("// writing expression field: %s (%s) (%s) :: %s",
|
|
|
|
f.SrcName(), f.Size(), f.Expr, f.Type.SrcName())
|
2012-04-30 08:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Value field
|
|
|
|
func (f *ValueField) Define(c *Context) {
|
|
|
|
c.Putln("// valueparam field: type: %s, mask name: %s, list name: %s",
|
|
|
|
f.MaskType.SrcName(), f.MaskName, f.ListName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ValueField) Read(c *Context) {
|
|
|
|
c.Putln("// reading valueparam: type: %s, mask name: %s, list name: %s",
|
|
|
|
f.MaskType.SrcName(), f.MaskName, f.ListName)
|
2012-04-30 22:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *ValueField) Write(c *Context) {
|
|
|
|
c.Putln("// writing valueparam: type: %s, mask name: %s, list name: %s",
|
|
|
|
f.MaskType.SrcName(), f.MaskName, f.ListName)
|
2012-04-30 08:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Switch field
|
|
|
|
func (f *SwitchField) Define(c *Context) {
|
|
|
|
c.Putln("// switch field: %s (%s)", f.Name, f.Expr)
|
2012-04-30 22:18:17 +02:00
|
|
|
panic("todo")
|
2012-04-30 08:40:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *SwitchField) Read(c *Context) {
|
|
|
|
c.Putln("// reading switch field: %s (%s)", f.Name, f.Expr)
|
2012-04-30 22:18:17 +02:00
|
|
|
panic("todo")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *SwitchField) Write(c *Context) {
|
|
|
|
c.Putln("// writing switch field: %s (%s)", f.Name, f.Expr)
|
|
|
|
panic("todo")
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|