Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
58f78727
Commit
58f78727
authored
Jan 25, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
af3ac0d2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
23 deletions
+18
-23
t/neo/protogen.go
t/neo/protogen.go
+18
-23
No files found.
t/neo/protogen.go
View file @
58f78727
...
@@ -267,6 +267,7 @@ type CodeGenerator interface {
...
@@ -267,6 +267,7 @@ type CodeGenerator interface {
// common part of codegenerators
// common part of codegenerators
type
commonCodeGen
struct
{
type
commonCodeGen
struct
{
buf
Buffer
// code is emitted here
recvName
string
// receiver/type for top-level func
recvName
string
// receiver/type for top-level func
typeName
string
// or empty
typeName
string
// or empty
typ
types
.
Type
typ
types
.
Type
...
@@ -274,6 +275,10 @@ type commonCodeGen struct {
...
@@ -274,6 +275,10 @@ type commonCodeGen struct {
varUsed
map
[
string
]
bool
// whether a variable was used
varUsed
map
[
string
]
bool
// whether a variable was used
}
}
func
(
c
*
commonCodeGen
)
emit
(
format
string
,
a
...
interface
{})
{
c
.
buf
.
emit
(
format
,
a
...
)
}
func
(
c
*
commonCodeGen
)
setFunc
(
recvName
,
typeName
string
,
typ
types
.
Type
)
{
func
(
c
*
commonCodeGen
)
setFunc
(
recvName
,
typeName
string
,
typ
types
.
Type
)
{
c
.
recvName
=
recvName
c
.
recvName
=
recvName
c
.
typeName
=
typeName
c
.
typeName
=
typeName
...
@@ -341,26 +346,23 @@ func (s *SymSize) Reset() {
...
@@ -341,26 +346,23 @@ func (s *SymSize) Reset() {
// XXX naming ok?
// XXX naming ok?
// XXX -> Gen_NEOEncodedLen ?
// XXX -> Gen_NEOEncodedLen ?
type
sizeCodeGen
struct
{
type
sizeCodeGen
struct
{
Buffer
// buffer for code
size
SymSize
// currently accumulated packet size
commonCodeGen
commonCodeGen
size
SymSize
// currently accumulated packet size
}
}
// encoder generates code to encode a packet
// encoder generates code to encode a packet
type
encoder
struct
{
type
encoder
struct
{
Buffer
// XXX
n
int
// current write position in data
commonCodeGen
commonCodeGen
n
int
// current write position in data
}
}
// decoder generates code to decode a packet
// decoder generates code to decode a packet
type
decoder
struct
{
type
decoder
struct
{
// buffers for generated code
commonCodeGen
// current delayed overflow check will be inserted in between buf & bufCur
buf
Buffer
// done buffer for generated code
bufCur
Buffer
// current delayed overflow check will be inserted in between buf & bufDone
bufDone
Buffer
// current read position in data.
// current read position in data.
n
int
n
int
...
@@ -370,8 +372,6 @@ type decoder struct {
...
@@ -370,8 +372,6 @@ type decoder struct {
// whether overflow was already checked for current decodings
// whether overflow was already checked for current decodings
overflowChecked
bool
overflowChecked
bool
commonCodeGen
}
}
var
_
CodeGenerator
=
(
*
sizeCodeGen
)(
nil
)
var
_
CodeGenerator
=
(
*
sizeCodeGen
)(
nil
)
...
@@ -387,7 +387,7 @@ func (s *sizeCodeGen) generatedCode() string {
...
@@ -387,7 +387,7 @@ func (s *sizeCodeGen) generatedCode() string {
code
.
emit
(
"var %s int"
,
s
.
var_
(
"size"
))
code
.
emit
(
"var %s int"
,
s
.
var_
(
"size"
))
}
}
code
.
Write
(
s
.
Bytes
())
// XXX -> s.buf.Bytes() ?
code
.
Write
(
s
.
buf
.
Bytes
())
// epilogue
// epilogue
size
:=
s
.
size
.
String
()
size
:=
s
.
size
.
String
()
...
@@ -405,7 +405,7 @@ func (e *encoder) generatedCode() string {
...
@@ -405,7 +405,7 @@ func (e *encoder) generatedCode() string {
// prologue
// prologue
code
.
emit
(
"func (%s *%s) NEOEncode(data []byte) {"
,
e
.
recvName
,
e
.
typeName
)
code
.
emit
(
"func (%s *%s) NEOEncode(data []byte) {"
,
e
.
recvName
,
e
.
typeName
)
code
.
Write
(
e
.
Bytes
())
// XXX -> e.buf.Bytes() ?
code
.
Write
(
e
.
buf
.
Bytes
())
// epilogue
// epilogue
code
.
emit
(
"}
\n
"
)
code
.
emit
(
"}
\n
"
)
...
@@ -413,11 +413,6 @@ func (e *encoder) generatedCode() string {
...
@@ -413,11 +413,6 @@ func (e *encoder) generatedCode() string {
return
code
.
String
()
return
code
.
String
()
}
}
// XXX place?
func
(
d
*
decoder
)
emit
(
format
string
,
a
...
interface
{})
{
d
.
bufCur
.
emit
(
format
,
a
...
)
}
// XXX place?
// XXX place?
// data <- data[pos:]
// data <- data[pos:]
// pos <- 0
// pos <- 0
...
@@ -448,13 +443,13 @@ func (d *decoder) resetPos() {
...
@@ -448,13 +443,13 @@ func (d *decoder) resetPos() {
func
(
d
*
decoder
)
overflowCheckpoint
()
{
func
(
d
*
decoder
)
overflowCheckpoint
()
{
//d.buf.emit("// overflow check point")
//d.buf.emit("// overflow check point")
if
!
d
.
overflowCheckSize
.
IsZero
()
{
if
!
d
.
overflowCheckSize
.
IsZero
()
{
d
.
buf
.
emit
(
"if uint32(len(data)) < %v { goto overflow }"
,
&
d
.
overflowCheckSize
)
d
.
buf
Done
.
emit
(
"if uint32(len(data)) < %v { goto overflow }"
,
&
d
.
overflowCheckSize
)
}
}
d
.
overflowCheckSize
.
Reset
()
d
.
overflowCheckSize
.
Reset
()
d
.
buf
.
Write
(
d
.
bufCur
.
Bytes
())
d
.
buf
Done
.
Write
(
d
.
buf
.
Bytes
())
d
.
buf
Cur
.
Reset
()
d
.
buf
.
Reset
()
}
}
func
(
d
*
decoder
)
generatedCode
()
string
{
func
(
d
*
decoder
)
generatedCode
()
string
{
...
@@ -467,7 +462,7 @@ func (d *decoder) generatedCode() string {
...
@@ -467,7 +462,7 @@ func (d *decoder) generatedCode() string {
code
.
emit
(
"var %v uint32"
,
d
.
var_
(
"nread"
))
code
.
emit
(
"var %v uint32"
,
d
.
var_
(
"nread"
))
}
}
code
.
Write
(
d
.
buf
.
Bytes
())
code
.
Write
(
d
.
buf
Done
.
Bytes
())
// epilogue
// epilogue
retexpr
:=
fmt
.
Sprintf
(
"%v"
,
d
.
n
)
retexpr
:=
fmt
.
Sprintf
(
"%v"
,
d
.
n
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment