diff options
author | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-04-30 16:18:17 -0400 |
---|---|---|
committer | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-04-30 16:18:17 -0400 |
commit | 73154769b3eba60fe48a7c08882e8e64b1545e3f (patch) | |
tree | 3fe7c2a1f9ae1d22931b4673901d8ea340192d57 /nexgb/xgbgen/go_error.go | |
parent | 2a2d8653b3a7918dfb00dcca8937b0e878279c70 (diff) | |
download | haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.tar.gz haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.tar.xz haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.zip |
splitting up go specific code. too much for one file IMO. more progress. almost done with structs.
Diffstat (limited to 'nexgb/xgbgen/go_error.go')
-rw-r--r-- | nexgb/xgbgen/go_error.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/nexgb/xgbgen/go_error.go b/nexgb/xgbgen/go_error.go new file mode 100644 index 0000000..0cb77cc --- /dev/null +++ b/nexgb/xgbgen/go_error.go @@ -0,0 +1,39 @@ +package main + +// Error types +func (e *Error) Define(c *Context) { + c.Putln("// Error definition %s (%d)", e.SrcName(), e.Number) + c.Putln("") +} + +func (e *Error) Read(c *Context, prefix string) { + c.Putln("// Error read %s", e.SrcName()) +} + +func (e *Error) Write(c *Context, prefix string) { + c.Putln("// Error write %s", e.SrcName()) +} + +// ErrorCopy types +func (e *ErrorCopy) Define(c *Context) { + c.Putln("// ErrorCopy definition %s (%d)", e.SrcName(), e.Number) + c.Putln("") + c.Putln("const %s = %d", e.ErrConst(), e.Number) + c.Putln("") + c.Putln("type %s %s", e.ErrType(), e.Old.(*Error).ErrType()) + c.Putln("") + c.Putln("func New%s(buf []byte) %s {", e.SrcName(), e.ErrType()) + c.Putln("return (%s)(New%s(buf))", e.ErrType(), e.Old.SrcName()) + c.Putln("}") + c.Putln("") + c.Putln("func (err %s) ImplementsError() { }", e.ErrType()) + c.Putln("") + c.Putln("func (err %s) Bytes() []byte {", e.ErrType()) + c.Putln("return (%s)(err).Bytes()", e.Old.(*Error).ErrType()) + c.Putln("}") + c.Putln("") + c.Putln("func init() {") + c.Putln("newErrorFuncs[%d] = New%s", e.Number, e.SrcName()) + c.Putln("}") + c.Putln("") +} |