Commit 653a4785 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c1eed395
This diff is collapsed.
...@@ -55,16 +55,18 @@ func main() { ...@@ -55,16 +55,18 @@ func main() {
log.SetFlags(0) log.SetFlags(0)
// go through proto.go and collect packets type definitions // go through proto.go and collect packets type definitions
var mode parser.Mode = 0 // parser.Trace
var fv []*ast.File var fv []*ast.File
for _, src := range []string{"proto.go", "neo.go"} { for _, src := range []string{"proto.go", "neo.go"} {
f, err := parser.ParseFile(fset, src, nil, mode) f, err := parser.ParseFile(fset, src, nil, 0)
if err != nil { if err != nil {
log.Fatalf("parse: %v", err) log.Fatalf("parse: %v", err)
} }
fv = append(fv, f) fv = append(fv, f)
} }
//ast.Print(fset, fv[0])
//return
conf := types.Config{Importer: importer.Default()} conf := types.Config{Importer: importer.Default()}
neoPkg, err := conf.Check("neo", fset, fv, info) neoPkg, err := conf.Check("neo", fset, fv, info)
if err != nil { if err != nil {
...@@ -73,11 +75,6 @@ func main() { ...@@ -73,11 +75,6 @@ func main() {
neoQualifier = types.RelativeTo(neoPkg) neoQualifier = types.RelativeTo(neoPkg)
//ncode := 0
//ast.Print(fset, f)
//return
// prologue // prologue
f := fv[0] // proto.go comes first f := fv[0] // proto.go comes first
buf := bytes.Buffer{} buf := bytes.Buffer{}
...@@ -90,6 +87,7 @@ import ( ...@@ -90,6 +87,7 @@ import (
`) `)
// go over packet types declaration and generate marshal code for them // go over packet types declaration and generate marshal code for them
pktCode := 0
for _, decl := range f.Decls { for _, decl := range f.Decls {
// we look for types (which can be only under GenDecl) // we look for types (which can be only under GenDecl)
gendecl, ok := decl.(*ast.GenDecl) gendecl, ok := decl.(*ast.GenDecl)
...@@ -99,7 +97,7 @@ import ( ...@@ -99,7 +97,7 @@ import (
for _, spec := range gendecl.Specs { for _, spec := range gendecl.Specs {
typespec := spec.(*ast.TypeSpec) // must be because tok = TYPE typespec := spec.(*ast.TypeSpec) // must be because tok = TYPE
//typename := typespec.Name.Name typename := typespec.Name.Name
switch typespec.Type.(type) { switch typespec.Type.(type) {
default: default:
...@@ -112,8 +110,12 @@ import ( ...@@ -112,8 +110,12 @@ import (
//fmt.Println(t) //fmt.Println(t)
//ast.Print(fset, t) //ast.Print(fset, t)
fmt.Fprintf(&buf, "// %d. %s\n\n", pktCode, typename)
buf.WriteString(gendecode(typespec)) buf.WriteString(gendecode(typespec))
buf.WriteString("\n") buf.WriteString("\n")
pktCode++
} }
} }
......
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