Commit d8f0220c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 620b5776
...@@ -289,24 +289,24 @@ func (c *commonCoder) var_(varname string) string { ...@@ -289,24 +289,24 @@ func (c *commonCoder) var_(varname string) string {
return varname return varname
} }
// information about a size // information about symbolic size
// consists of numeric & symbolic parts // consists of numeric & symbolic parts
// size is num + expr1 + expr2 + ... // size is num + expr1 + expr2 + ...
type size struct { type SymSize struct {
num int // numeric part of size num int // numeric part of size
exprv []string // symbolic part of size exprv []string // symbolic part of size
} }
func (s *size) Add(n int) { func (s *SymSize) Add(n int) {
s.num += n s.num += n
} }
func (s *size) AddExpr(format string, a ...interface{}) { func (s *SymSize) AddExpr(format string, a ...interface{}) {
expr := fmt.Sprintf(format, a...) expr := fmt.Sprintf(format, a...)
s.exprv = append(s.exprv, expr) s.exprv = append(s.exprv, expr)
} }
func (s *size) String() string { func (s *SymSize) String() string {
// num + expr1 + expr2 + ... (omitting what is possible) // num + expr1 + expr2 + ... (omitting what is possible)
sizev := []string{} sizev := []string{}
if s.num != 0 { if s.num != 0 {
...@@ -323,11 +323,11 @@ func (s *size) String() string { ...@@ -323,11 +323,11 @@ func (s *size) String() string {
return sizeStr return sizeStr
} }
func (s *size) ExprString() string { func (s *SymSize) ExprString() string {
return strings.Join(s.exprv, " + ") return strings.Join(s.exprv, " + ")
} }
func (s *size) IsZero() bool { func (s *SymSize) IsZero() bool {
return s.num == 0 && len(s.exprv) == 0 return s.num == 0 && len(s.exprv) == 0
} }
...@@ -335,7 +335,7 @@ func (s *size) IsZero() bool { ...@@ -335,7 +335,7 @@ func (s *size) IsZero() bool {
// sizer generates code to compute encoded size of a packet // sizer generates code to compute encoded size of a packet
type sizer struct { type sizer struct {
Buffer // buffer for code Buffer // buffer for code
size size size SymSize
commonCoder commonCoder
} }
...@@ -359,7 +359,7 @@ type decoder struct { ...@@ -359,7 +359,7 @@ type decoder struct {
n int n int
// size that will be checked for overflow at current overflow check point // size that will be checked for overflow at current overflow check point
overflowCheckSize size overflowCheckSize SymSize
// whether overflow was already checked for current decodings // whether overflow was already checked for current decodings
overflowChecked bool overflowChecked bool
...@@ -442,7 +442,7 @@ func (d *decoder) overflowCheckpoint() { ...@@ -442,7 +442,7 @@ func (d *decoder) overflowCheckpoint() {
d.buf.emit("if uint32(len(data)) < %v { goto overflow }", &d.overflowCheckSize) d.buf.emit("if uint32(len(data)) < %v { goto overflow }", &d.overflowCheckSize)
} }
d.overflowCheckSize = size{} // zero d.overflowCheckSize = SymSize{} // zero
d.buf.Write(d.bufCur.Bytes()) d.buf.Write(d.bufCur.Bytes())
d.bufCur.Reset() d.bufCur.Reset()
...@@ -602,7 +602,7 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) { ...@@ -602,7 +602,7 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
s.size.Add(4) s.size.Add(4)
curSize := s.size curSize := s.size
s.size = size{} // zero s.size = SymSize{} // zero
s.emit("for i := 0; i < len(%v); i++ {", path) s.emit("for i := 0; i < len(%v); i++ {", path)
s.emit("a := &%s[i]", path) s.emit("a := &%s[i]", path)
...@@ -695,7 +695,7 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) { ...@@ -695,7 +695,7 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) {
s.size.Add(4) s.size.Add(4)
curSize := s.size curSize := s.size
s.size = size{} // zero s.size = SymSize{} // zero
// FIXME for map of map gives ...[key][key] => key -> different variables // FIXME for map of map gives ...[key][key] => key -> different variables
s.emit("for key := range %s {", path) s.emit("for key := range %s {", path)
......
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