yess
This commit is contained in:
@@ -205,6 +205,7 @@ func (g *Generator) GenerateTypes(prefix string, types Types) error {
|
||||
if slices.Contains(g.Settings.ReplaceWithTodoNames, k) {
|
||||
v = "todo"
|
||||
}
|
||||
|
||||
g.Depth = 0
|
||||
e, err := g.VisitType(v)
|
||||
if errors.Is(err, ToDoError) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
)
|
||||
|
||||
func ParseCompareTo(g *Generator, compareTo string) (e ast.Expr, err error) {
|
||||
func (g *Generator) ParseCompareTo(compareTo string) (e ast.Expr, err error) {
|
||||
parts := strings.Split(compareTo, "/")
|
||||
downPrefixCount := 0
|
||||
for _, part := range parts {
|
||||
|
||||
@@ -110,6 +110,7 @@ func OptionDecoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s
|
||||
func ArrayDecoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s []ast.Stmt, err error) {
|
||||
var data struct {
|
||||
CountType any
|
||||
Count string
|
||||
Type any
|
||||
}
|
||||
lName := "l" + CamelCase(name)
|
||||
@@ -117,13 +118,27 @@ func ArrayDecoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
countType, err := g.VisitType(data.CountType)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s2, err := g.VisitDecoder(Ident(lName), data.CountType, name)
|
||||
if err != nil {
|
||||
return
|
||||
var s2 []ast.Stmt
|
||||
countType, err := g.VisitNameAndData("varint", nil)
|
||||
if data.CountType != nil {
|
||||
countType, err = g.VisitType(data.CountType)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s2, err = g.VisitDecoder(Ident(lName), data.CountType, name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
var n int
|
||||
n, err = strconv.Atoi(data.Count)
|
||||
var e ast.Expr
|
||||
if err == nil {
|
||||
e = NumLit(n)
|
||||
} else {
|
||||
e, err = g.ParseCompareTo(data.Count)
|
||||
}
|
||||
s2 = append(s2, Assign121(Ident(lName), e))
|
||||
}
|
||||
|
||||
normalType, err := g.VisitType(data.Type)
|
||||
@@ -223,7 +238,7 @@ func SwitchDecoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
compareToExpr, err := ParseCompareTo(g, data.CompareTo)
|
||||
compareToExpr, err := g.ParseCompareTo(data.CompareTo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
|
||||
@@ -66,20 +65,20 @@ func SimpleTypeEncoder(_ *Generator, data ast.Expr, _ any, _ string) (s []ast.St
|
||||
func ArrayEncoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s []ast.Stmt, err error) {
|
||||
var data struct {
|
||||
CountType any
|
||||
Count string
|
||||
Type any
|
||||
}
|
||||
err = mapstructure.Decode(dataRaw, &data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if data.CountType == nil {
|
||||
data.CountType = "varint"
|
||||
}
|
||||
ct, err := g.VisitType(data.CountType)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, ok := ct.(*ast.Ident)
|
||||
if !ok {
|
||||
err = errors.New("array count type must be simple type otherwise wtf")
|
||||
}
|
||||
iName := "i" + name
|
||||
s, err = g.VisitEncoder(varToSet, data.Type, name)
|
||||
s1, err := g.VisitEncoder(Call(ct, Call(Ident("len"), varToSet)), data.CountType, name)
|
||||
@@ -174,7 +173,7 @@ func SwitchEncoder(g *Generator, varToSet ast.Expr, dataRaw any, name string) (s
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
compareToExpr, err := ParseCompareTo(g, data.CompareTo)
|
||||
compareToExpr, err := g.ParseCompareTo(data.CompareTo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user