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
620b5776
Commit
620b5776
authored
Jan 25, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
fd40d0b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
15 deletions
+11
-15
t/neo/protogen.go
t/neo/protogen.go
+11
-15
No files found.
t/neo/protogen.go
View file @
620b5776
...
...
@@ -240,15 +240,16 @@ func (b *Buffer) emit(format string, a ...interface{}) {
// interface of a codegenerator (for sizer/coder/decoder XXX naming)
type
CodeGenerator
interface
{
// tell codegen it should generate code for
top-level function
// tell codegen it should generate code for
which type & receiver name
setFunc
(
recvName
,
typeName
string
,
typ
types
.
Type
)
// TODO gen*() -> visit*() ?
// emit code to process basic fixed types (not string)
// generate code to process a basic fixed type (not string)
// userType is type actually used in source (for which typ is underlying), or nil
// path is TODO
genBasic
(
path
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
)
// generate code to process slice or map
// (see genBasic for argument details)
genSlice
(
path
string
,
typ
*
types
.
Slice
,
obj
types
.
Object
)
genMap
(
path
string
,
typ
*
types
.
Map
,
obj
types
.
Object
)
...
...
@@ -279,18 +280,13 @@ func (c *commonCoder) setFunc(recvName, typeName string, typ types.Type) {
c
.
typ
=
typ
}
// get variable name for varname
func
(
c
*
commonCoder
)
var__
(
varname
string
)
string
{
return
varname
// XXX was varname + N
}
// get variable for varname (and automatically mark var as used)
func
(
c
*
commonCoder
)
var_
(
varname
string
)
string
{
varnameX
:=
c
.
var__
(
varname
)
if
c
.
varUsed
==
nil
{
c
.
varUsed
=
make
(
map
[
string
]
bool
)
}
c
.
varUsed
[
varname
]
=
true
return
varname
X
return
varname
}
// information about a size
...
...
@@ -381,7 +377,7 @@ func (s *sizer) generatedCode() string {
// prologue
code
.
emit
(
"func (%s *%s) NEOEncodedLen() int {"
,
s
.
recvName
,
s
.
typeName
)
if
s
.
varUsed
[
"size"
]
{
code
.
emit
(
"var %s int"
,
s
.
var_
_
(
"size"
))
code
.
emit
(
"var %s int"
,
s
.
var_
(
"size"
))
}
code
.
Write
(
s
.
Bytes
())
// XXX -> s.buf.Bytes() ?
...
...
@@ -389,7 +385,7 @@ func (s *sizer) generatedCode() string {
// epilogue
size
:=
s
.
size
.
String
()
if
s
.
varUsed
[
"size"
]
{
size
+=
" + "
+
s
.
var_
_
(
"size"
)
size
+=
" + "
+
s
.
var_
(
"size"
)
}
code
.
emit
(
"return %v"
,
size
)
code
.
emit
(
"}
\n
"
)
...
...
@@ -461,7 +457,7 @@ func (d *decoder) generatedCode() string {
code
.
emit
(
"func (%s *%s) NEODecode(data []byte) (int, error) {"
,
d
.
recvName
,
d
.
typeName
)
}
if
d
.
varUsed
[
"nread"
]
{
code
.
emit
(
"var %v uint32"
,
d
.
var_
_
(
"nread"
))
code
.
emit
(
"var %v uint32"
,
d
.
var_
(
"nread"
))
}
code
.
Write
(
d
.
buf
.
Bytes
())
...
...
@@ -469,7 +465,7 @@ func (d *decoder) generatedCode() string {
// epilogue
retexpr
:=
fmt
.
Sprintf
(
"%v"
,
d
.
n
)
if
d
.
varUsed
[
"nread"
]
{
retexpr
+=
fmt
.
Sprintf
(
" + int(%v)"
,
d
.
var_
_
(
"nread"
))
retexpr
+=
fmt
.
Sprintf
(
" + int(%v)"
,
d
.
var_
(
"nread"
))
}
code
.
emit
(
"return %v, nil"
,
retexpr
)
...
...
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