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
d3f05e73
Commit
d3f05e73
authored
Jan 17, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8dd95245
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
115 deletions
+7
-115
t/neo/protogen.go
t/neo/protogen.go
+7
-115
No files found.
t/neo/protogen.go
View file @
d3f05e73
...
...
@@ -30,16 +30,11 @@ import (
"os"
)
// information about one packet type
type
PacketType
struct
{
name
string
msgCode
uint16
// message code for this packet type - derived from type order number in source
}
// parsed & typechecked input
var
fset
=
token
.
NewFileSet
()
var
info
=
&
types
.
Info
{
Types
:
make
(
map
[
ast
.
Expr
]
types
.
TypeAndValue
),
Uses
:
make
(
map
[
*
ast
.
Ident
]
types
.
Object
),
//Uses: make(map[*ast.Ident]types.Object), XXX seems not needed
Defs
:
make
(
map
[
*
ast
.
Ident
]
types
.
Object
),
}
...
...
@@ -59,8 +54,6 @@ func main() {
log
.
SetFlags
(
0
)
//typeMap := map[string]*PacketType{} // XXX needed ?
// go through proto.go and collect packets type definitions
var
mode
parser
.
Mode
=
0
// parser.Trace
var
fv
[]
*
ast
.
File
...
...
@@ -85,8 +78,9 @@ func main() {
//ast.Print(fset, f)
//return
// prologue
f
:=
fv
[
0
]
// proto.go comes first
buf
:=
Buffer
{}
buf
:=
bytes
.
Buffer
{}
buf
.
WriteString
(
`// DO NOT EDIT - AUTOGENERATED (by protogen.go)
package neo
...
...
@@ -95,6 +89,7 @@ import (
)
`
)
// go over packet types declaration and generate marshal code for them
for
_
,
decl
:=
range
f
.
Decls
{
// we look for types (which can be only under GenDecl)
gendecl
,
ok
:=
decl
.
(
*
ast
.
GenDecl
)
...
...
@@ -138,14 +133,6 @@ import (
}
}
/*
// wiresize returns wire size of a type
// type must be of fixed size (e.g. not a slice or map)
// XXX ast.Expr -> ?
func wiresize(*ast.Expr) int {
// TODO
}
*/
// info about wire decode/encode of a basic type
type
basicXXX
struct
{
...
...
@@ -172,19 +159,10 @@ var basicDecode = map[types.BasicKind]basicXXX {
// XXX string ?
}
// bytes.Buffer + bell&whistless
type
Buffer
struct
{
bytes
.
Buffer
}
func
(
b
*
Buffer
)
Printfln
(
format
string
,
a
...
interface
{})
(
n
int
,
err
error
)
{
return
fmt
.
Fprintf
(
b
,
format
+
"
\n
"
,
a
...
)
}
// state of decode codegen
type
decoder
struct
{
buf
Buffer
// buffer for generated code
buf
bytes
.
Buffer
// buffer for generated code
n
int
// current decode position in data
}
...
...
@@ -345,90 +323,4 @@ func gendecode(typespec *ast.TypeSpec) string {
d
.
emit
(
"return int(nread) + %v, nil"
,
d
.
n
)
d
.
emit
(
"}"
)
return
d
.
buf
.
String
()
// for _, fieldv := range t.Fields.List {
// // type B struct { ... }
// //
// // type A struct {
// // x, y int <- fieldv
// // B <- fieldv
//
// // embedding: change `B` -> `B B` (field type must be Ident)
// fieldnamev := fieldv.Names
// if fieldnamev == nil {
// fieldnamev = []*ast.Ident{fieldv.Type.(*ast.Ident)}
// }
//
//
// for _, fieldname := range fieldnamev {
// fieldtype := info.Types[fieldv.Type].Type
//
// switch u := fieldtype.Underlying().(type) {
// // we are processing: <fieldname> <fieldtype>
//
// // bool, uint32, string, ...
// case *types.Basic:
// if u.Kind() == types.String {
// emitstrbytes(fieldname.Name)
// continue
// }
//
// emit("p.%s = %s", fieldname, decodeBasic(u))
//
// case *types.Slice:
// // TODO
//
// case *types.Map:
// // TODO
//
//
// //case *types.Struct:
// // TODO
//
//
//
// /*
//
// // simple types like uint16
// case *ast.Ident:
// // TODO
//
// // array or slice
// case *ast.ArrayType:
// if fieldtype.Len != nil {
// log.Fatalf("%s: TODO arrays not suported", pos(fieldtype))
// }
//
// eltsize := wiresize(fieldtype.Elt) // TODO
//
// // len u32
// // [len] items
// emit("length = Uint32(data[%s:])", n)
// n += 4
// emit("for ; length != 0; length-- {")
// emit("}")
//
//
//
// // map
// case *ast.MapType:
// // len u32
// // [len] key, value
// emit("length = Uint32(data[%s:])", n)
// n += 4
//
// keysize := wiresize(fieldtype.Key)
// valsize := wiresize(fieldtype.Value)
//
// // XXX *ast.StructType ?
// */
//
// default:
// log.Fatalf("%v: field %v has unsupported type %v (%v)", pos(fieldv),
// fieldname, fieldtype, u)
// }
// }
// }
}
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