|
|
@ -1,14 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"go/ast"
|
|
|
|
"go/ast"
|
|
|
|
"go/parser"
|
|
|
|
"go/parser"
|
|
|
|
"go/token"
|
|
|
|
|
|
|
|
"go/printer"
|
|
|
|
"go/printer"
|
|
|
|
|
|
|
|
"go/token"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func getexprs(e ast.Expr) string {
|
|
|
|
func getexprs(e ast.Expr) string {
|
|
|
@ -67,19 +66,19 @@ func genatomdecl(origfn *ast.FuncDecl, origname, origtag string) (decls []ast.De
|
|
|
|
case "bytesleft":
|
|
|
|
case "bytesleft":
|
|
|
|
typ = "[]byte"
|
|
|
|
typ = "[]byte"
|
|
|
|
case "bytes":
|
|
|
|
case "bytes":
|
|
|
|
typ = "["+name2+"]byte"
|
|
|
|
typ = "[" + name2 + "]byte"
|
|
|
|
case "uint24":
|
|
|
|
case "uint24":
|
|
|
|
typ = "uint32"
|
|
|
|
typ = "uint32"
|
|
|
|
case "time64", "time32":
|
|
|
|
case "time64", "time32":
|
|
|
|
typ = "time.Time"
|
|
|
|
typ = "time.Time"
|
|
|
|
case "atom":
|
|
|
|
case "atom":
|
|
|
|
typ = "*"+name2
|
|
|
|
typ = "*" + name2
|
|
|
|
case "atoms":
|
|
|
|
case "atoms":
|
|
|
|
typ = "[]*"+name2
|
|
|
|
typ = "[]*" + name2
|
|
|
|
case "slice":
|
|
|
|
case "slice":
|
|
|
|
typ = "[]"+name2
|
|
|
|
typ = "[]" + name2
|
|
|
|
case "array":
|
|
|
|
case "array":
|
|
|
|
typ = "["+len3+"]"+name2
|
|
|
|
typ = "[" + len3 + "]" + name2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fieldslist.List = append(fieldslist.List, &ast.Field{
|
|
|
|
fieldslist.List = append(fieldslist.List, &ast.Field{
|
|
|
@ -135,7 +134,7 @@ func typegetlen(typ string) (n int) {
|
|
|
|
func typegetlens(typ string) string {
|
|
|
|
func typegetlens(typ string) string {
|
|
|
|
n := typegetlen(typ)
|
|
|
|
n := typegetlen(typ)
|
|
|
|
if n == 0 {
|
|
|
|
if n == 0 {
|
|
|
|
return "Len"+typ
|
|
|
|
return "Len" + typ
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return fmt.Sprint(n)
|
|
|
|
return fmt.Sprint(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -187,7 +186,7 @@ func typegetputfn(typ string) (fn string) {
|
|
|
|
case "fixed16":
|
|
|
|
case "fixed16":
|
|
|
|
fn = "PutFixed16"
|
|
|
|
fn = "PutFixed16"
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
fn = "Put"+typ
|
|
|
|
fn = "Put" + typ
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -218,7 +217,7 @@ func typegetgetfn(typ string) (fn string) {
|
|
|
|
case "fixed16":
|
|
|
|
case "fixed16":
|
|
|
|
fn = "GetFixed16"
|
|
|
|
fn = "GetFixed16"
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
fn = "Get"+typ
|
|
|
|
fn = "Get" + typ
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -237,7 +236,7 @@ func addn(n int) (stmts []ast.Stmt) {
|
|
|
|
return addns(fmt.Sprint(n))
|
|
|
|
return addns(fmt.Sprint(n))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func simplecall(fun string, args... string) *ast.ExprStmt {
|
|
|
|
func simplecall(fun string, args ...string) *ast.ExprStmt {
|
|
|
|
_args := []ast.Expr{}
|
|
|
|
_args := []ast.Expr{}
|
|
|
|
for _, s := range args {
|
|
|
|
for _, s := range args {
|
|
|
|
_args = append(_args, ast.NewIdent(s))
|
|
|
|
_args = append(_args, ast.NewIdent(s))
|
|
|
@ -319,7 +318,7 @@ func getstructputgetlenfn(origfn *ast.FuncDecl, origname string) (decls []ast.De
|
|
|
|
getstmts = append(getstmts, &ast.ReturnStmt{})
|
|
|
|
getstmts = append(getstmts, &ast.ReturnStmt{})
|
|
|
|
|
|
|
|
|
|
|
|
decls = append(decls, &ast.FuncDecl{
|
|
|
|
decls = append(decls, &ast.FuncDecl{
|
|
|
|
Name: ast.NewIdent("Get"+origname),
|
|
|
|
Name: ast.NewIdent("Get" + origname),
|
|
|
|
Type: &ast.FuncType{
|
|
|
|
Type: &ast.FuncType{
|
|
|
|
Params: &ast.FieldList{
|
|
|
|
Params: &ast.FieldList{
|
|
|
|
List: []*ast.Field{
|
|
|
|
List: []*ast.Field{
|
|
|
@ -336,7 +335,7 @@ func getstructputgetlenfn(origfn *ast.FuncDecl, origname string) (decls []ast.De
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
decls = append(decls, &ast.FuncDecl{
|
|
|
|
decls = append(decls, &ast.FuncDecl{
|
|
|
|
Name: ast.NewIdent("Put"+origname),
|
|
|
|
Name: ast.NewIdent("Put" + origname),
|
|
|
|
Type: &ast.FuncType{
|
|
|
|
Type: &ast.FuncType{
|
|
|
|
Params: &ast.FieldList{
|
|
|
|
Params: &ast.FieldList{
|
|
|
|
List: []*ast.Field{
|
|
|
|
List: []*ast.Field{
|
|
|
@ -352,7 +351,7 @@ func getstructputgetlenfn(origfn *ast.FuncDecl, origname string) (decls []ast.De
|
|
|
|
Tok: token.CONST,
|
|
|
|
Tok: token.CONST,
|
|
|
|
Specs: []ast.Spec{
|
|
|
|
Specs: []ast.Spec{
|
|
|
|
&ast.ValueSpec{
|
|
|
|
&ast.ValueSpec{
|
|
|
|
Names: []*ast.Ident{ast.NewIdent("Len"+origname)},
|
|
|
|
Names: []*ast.Ident{ast.NewIdent("Len" + origname)},
|
|
|
|
Values: []ast.Expr{ast.NewIdent(fmt.Sprint(totlen))},
|
|
|
|
Values: []ast.Expr{ast.NewIdent(fmt.Sprint(totlen))},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -431,7 +430,7 @@ func getatommarshalfn(origfn *ast.FuncDecl,
|
|
|
|
|
|
|
|
|
|
|
|
callmarshal := func(name string) (stmts []ast.Stmt) {
|
|
|
|
callmarshal := func(name string) (stmts []ast.Stmt) {
|
|
|
|
callexpr := &ast.CallExpr{
|
|
|
|
callexpr := &ast.CallExpr{
|
|
|
|
Fun: ast.NewIdent(name+".Marshal"),
|
|
|
|
Fun: ast.NewIdent(name + ".Marshal"),
|
|
|
|
Args: []ast.Expr{ast.NewIdent("b[n:]")},
|
|
|
|
Args: []ast.Expr{ast.NewIdent("b[n:]")},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assign := &ast.AssignStmt{
|
|
|
|
assign := &ast.AssignStmt{
|
|
|
@ -459,7 +458,7 @@ func getatommarshalfn(origfn *ast.FuncDecl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
calllenstruct := func(typ, name string) (stmts []ast.Stmt) {
|
|
|
|
calllenstruct := func(typ, name string) (stmts []ast.Stmt) {
|
|
|
|
inc := typegetlens(typ)+"*len("+name+")"
|
|
|
|
inc := typegetlens(typ) + "*len(" + name + ")"
|
|
|
|
stmts = append(stmts, &ast.AssignStmt{
|
|
|
|
stmts = append(stmts, &ast.AssignStmt{
|
|
|
|
Tok: token.ADD_ASSIGN,
|
|
|
|
Tok: token.ADD_ASSIGN,
|
|
|
|
Lhs: []ast.Expr{ast.NewIdent("n")},
|
|
|
|
Lhs: []ast.Expr{ast.NewIdent("n")},
|
|
|
@ -470,7 +469,7 @@ func getatommarshalfn(origfn *ast.FuncDecl,
|
|
|
|
|
|
|
|
|
|
|
|
calllen := func(name string) (stmts []ast.Stmt) {
|
|
|
|
calllen := func(name string) (stmts []ast.Stmt) {
|
|
|
|
callexpr := &ast.CallExpr{
|
|
|
|
callexpr := &ast.CallExpr{
|
|
|
|
Fun: ast.NewIdent(name+".Len"),
|
|
|
|
Fun: ast.NewIdent(name + ".Len"),
|
|
|
|
Args: []ast.Expr{},
|
|
|
|
Args: []ast.Expr{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assign := &ast.AssignStmt{
|
|
|
|
assign := &ast.AssignStmt{
|
|
|
@ -574,7 +573,7 @@ func getatommarshalfn(origfn *ast.FuncDecl,
|
|
|
|
unmarshalatom := func(typ, init string) (stmts []ast.Stmt) {
|
|
|
|
unmarshalatom := func(typ, init string) (stmts []ast.Stmt) {
|
|
|
|
return []ast.Stmt{
|
|
|
|
return []ast.Stmt{
|
|
|
|
&ast.AssignStmt{Tok: token.DEFINE,
|
|
|
|
&ast.AssignStmt{Tok: token.DEFINE,
|
|
|
|
Lhs: []ast.Expr{ast.NewIdent("atom")}, Rhs: []ast.Expr{ast.NewIdent("&"+typ+"{"+init+"}")},
|
|
|
|
Lhs: []ast.Expr{ast.NewIdent("atom")}, Rhs: []ast.Expr{ast.NewIdent("&" + typ + "{" + init + "}")},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&ast.IfStmt{
|
|
|
|
&ast.IfStmt{
|
|
|
|
Init: &ast.AssignStmt{
|
|
|
|
Init: &ast.AssignStmt{
|
|
|
@ -591,10 +590,10 @@ func getatommarshalfn(origfn *ast.FuncDecl,
|
|
|
|
unmrashalatoms := func() (stmts []ast.Stmt) {
|
|
|
|
unmrashalatoms := func() (stmts []ast.Stmt) {
|
|
|
|
blocks := []ast.Stmt{}
|
|
|
|
blocks := []ast.Stmt{}
|
|
|
|
|
|
|
|
|
|
|
|
blocks = append(blocks, &ast.AssignStmt{ Tok: token.DEFINE, Lhs: []ast.Expr{ast.NewIdent("tag")},
|
|
|
|
blocks = append(blocks, &ast.AssignStmt{Tok: token.DEFINE, Lhs: []ast.Expr{ast.NewIdent("tag")},
|
|
|
|
Rhs: []ast.Expr{ast.NewIdent("Tag(pio.U32BE(b[n+4:]))")},
|
|
|
|
Rhs: []ast.Expr{ast.NewIdent("Tag(pio.U32BE(b[n+4:]))")},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
blocks = append(blocks, &ast.AssignStmt{ Tok: token.DEFINE, Lhs: []ast.Expr{ast.NewIdent("size")},
|
|
|
|
blocks = append(blocks, &ast.AssignStmt{Tok: token.DEFINE, Lhs: []ast.Expr{ast.NewIdent("size")},
|
|
|
|
Rhs: []ast.Expr{ast.NewIdent("int(pio.U32BE(b[n:]))")},
|
|
|
|
Rhs: []ast.Expr{ast.NewIdent("int(pio.U32BE(b[n:]))")},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
blocks = append(blocks, &ast.IfStmt{
|
|
|
|
blocks = append(blocks, &ast.IfStmt{
|
|
|
@ -614,7 +613,7 @@ func getatommarshalfn(origfn *ast.FuncDecl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for i, atom := range atomarrnames {
|
|
|
|
for i, atom := range atomarrnames {
|
|
|
|
selfatom := "self."+atom
|
|
|
|
selfatom := "self." + atom
|
|
|
|
cases = append(cases, &ast.CaseClause{
|
|
|
|
cases = append(cases, &ast.CaseClause{
|
|
|
|
List: []ast.Expr{ast.NewIdent(strings.ToUpper(struct2tag(atomarrtypes[i])))},
|
|
|
|
List: []ast.Expr{ast.NewIdent(strings.ToUpper(struct2tag(atomarrtypes[i])))},
|
|
|
|
Body: []ast.Stmt{&ast.BlockStmt{
|
|
|
|
Body: []ast.Stmt{&ast.BlockStmt{
|
|
|
@ -695,7 +694,7 @@ func getatommarshalfn(origfn *ast.FuncDecl,
|
|
|
|
Cond: &ast.BinaryExpr{
|
|
|
|
Cond: &ast.BinaryExpr{
|
|
|
|
X: ast.NewIdent("len(b)"),
|
|
|
|
X: ast.NewIdent("len(b)"),
|
|
|
|
Op: token.LSS,
|
|
|
|
Op: token.LSS,
|
|
|
|
Y: ast.NewIdent("n+"+inc),
|
|
|
|
Y: ast.NewIdent("n+" + inc),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Body: &ast.BlockStmt{List: parseerrreturn(debug)},
|
|
|
|
Body: &ast.BlockStmt{List: parseerrreturn(debug)},
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -710,16 +709,16 @@ func getatommarshalfn(origfn *ast.FuncDecl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkstructlendo := func(typ, name, debug string,
|
|
|
|
checkstructlendo := func(typ, name, debug string,
|
|
|
|
foreach func(string,[]ast.Stmt)[]ast.Stmt,
|
|
|
|
foreach func(string, []ast.Stmt) []ast.Stmt,
|
|
|
|
) (stmts []ast.Stmt) {
|
|
|
|
) (stmts []ast.Stmt) {
|
|
|
|
inc := typegetlens(typ)+"*len("+name+")"
|
|
|
|
inc := typegetlens(typ) + "*len(" + name + ")"
|
|
|
|
stmts = append(stmts, checkcurlen(inc, debug)...)
|
|
|
|
stmts = append(stmts, checkcurlen(inc, debug)...)
|
|
|
|
stmts = append(stmts, foreach(name, append(
|
|
|
|
stmts = append(stmts, foreach(name, append(
|
|
|
|
[]ast.Stmt{
|
|
|
|
[]ast.Stmt{
|
|
|
|
&ast.AssignStmt{
|
|
|
|
&ast.AssignStmt{
|
|
|
|
Tok: token.ASSIGN,
|
|
|
|
Tok: token.ASSIGN,
|
|
|
|
Lhs: []ast.Expr{
|
|
|
|
Lhs: []ast.Expr{
|
|
|
|
ast.NewIdent(name+"[i]"),
|
|
|
|
ast.NewIdent(name + "[i]"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Rhs: []ast.Expr{
|
|
|
|
Rhs: []ast.Expr{
|
|
|
|
&ast.CallExpr{
|
|
|
|
&ast.CallExpr{
|
|
|
@ -967,7 +966,7 @@ func genatoms(filename, outfilename string) {
|
|
|
|
&ast.GenDecl{
|
|
|
|
&ast.GenDecl{
|
|
|
|
Tok: token.IMPORT,
|
|
|
|
Tok: token.IMPORT,
|
|
|
|
Specs: []ast.Spec{
|
|
|
|
Specs: []ast.Spec{
|
|
|
|
&ast.ImportSpec{Path: &ast.BasicLit{Kind: token.STRING, Value: `"github.com/Danile71/joy4/utils/bits/pio"`}},
|
|
|
|
&ast.ImportSpec{Path: &ast.BasicLit{Kind: token.STRING, Value: `"gitlab.com/ics_cinnamon/joy4/utils/bits/pio"`}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&ast.GenDecl{
|
|
|
|
&ast.GenDecl{
|
|
|
@ -1054,4 +1053,3 @@ func main() {
|
|
|
|
genatoms(os.Args[2], os.Args[3])
|
|
|
|
genatoms(os.Args[2], os.Args[3])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|