Commit ce030bd4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0ba3696b
......@@ -362,13 +362,9 @@ import (
specAnnotation.parse(typespec.Doc)
// remember enum types
// FIXME separate dedicated first pass to extract enums first
if specAnnotation.enum {
//typ := typeInfo.Types[typespec.Type].Type
typ := typeInfo.Defs[typespec.Name].Type()
// XXX verify typ is basic int XXX or byte?
enumRegistry[typ]= enumSerial
//fmt.Printf("// enum %s #%d\n", typeName(typ), enumSerial)
enumSerial++
}
......@@ -400,7 +396,7 @@ import (
buf.WriteString(generateCodecCode(typespec, &encoderN{}))
buf.WriteString(generateCodecCode(typespec, &decoderN{}))
// XXX keep all M routines separate from N for code locality
// TODO keep all M routines separate from N for code locality ?
buf.WriteString(generateCodecCode(typespec, &sizerM{}))
buf.WriteString(generateCodecCode(typespec, &encoderM{}))
buf.WriteString(generateCodecCode(typespec, &decoderM{}))
......@@ -429,12 +425,9 @@ import (
// format & output generated code
code, err := format.Source(buf.Bytes())
//code = buf.Bytes()
if true {
if err != nil {
panic(err) // should not happen
}
}
_, err = os.Stdout.Write(code)
if err != nil {
......@@ -560,12 +553,10 @@ type CodeGenerator interface {
// mem.Buf
genBuf(path string)
/*
// generate code for a custom type which implements its own
// encoding/decoding via implementing neo.customCodecN interface.
// XXX move out of common interface?
genCustomN(path string)
*/
// // generate code for a custom type which implements its own
// // encoding/decoding via implementing neo.customCodecN interface.
// // XXX move out of common interface?
// genCustomN(path string)
// get generated code.
generatedCode() string
......@@ -591,7 +582,7 @@ type commonCodeGen struct {
recvName string // receiver/type for top-level func
typeName string // or empty
typ types.Type
enc byte // encoding variant
enc byte // encoding variant
varUsed map[string]bool // whether a variable was used
}
......@@ -940,7 +931,6 @@ func (d *decoderCommon) generatedCode() string {
code.Write(d.bufDone.Bytes())
// epilogue
// XXX M: return `n + (len0 - len(data))` without nread updates after every decode
retexpr := fmt.Sprintf("%v", d.nread)
if d.varUsed["nread"] {
// casting nread to int is ok even on 32 bit arches:
......@@ -1003,7 +993,7 @@ func (d *decoderN) genBasic(assignto string, typ *types.Basic, userType types.Ty
d.overflow.Add(basic.wireSize)
}
// M: XXX
// M: emit code to size/encode/decode basic fixed type
func (s *sizerM) genBasic(path string, typ *types.Basic, userType types.Type) {
// upath casts path into basic type if needed
// e.g. p.x -> int32(p.x) if p.x is custom type with underlying int32
......@@ -1039,10 +1029,10 @@ func (s *sizerM) genBasic(path string, typ *types.Basic, userType types.Type) {
case types.Float64: s.size.Add(1+8) // mfloat64 + <value64>
}
}
func (e *encoderM) genBasic(path string, typ *types.Basic, userType types.Type) {
// upath casts path into basic type if needed
// e.g. p.x -> int32(p.x) if p.x is custom type with underlying int32
// XXX dup?
upath := path
if userType.Underlying() != userType {
upath = fmt.Sprintf("%s(%s)", typ.Name(), upath)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment