Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define more type separately in 1 go file #32

Open
fastfading opened this issue Mar 14, 2017 · 6 comments
Open

define more type separately in 1 go file #32

fastfading opened this issue Mar 14, 2017 · 6 comments
Assignees
Labels

Comments

@fastfading
Copy link

check code below , I just want to define 2 type separately in 1 file
however it generate ReadPairInt8 ReadPairInt16 many times,
could u find a way fix it, like if there is only 1 type in one function , do not repeat it
or define a generic.SingleType
`
//go:generate genny -in=$GOFILE -out=../util/$GOFILE gen "T1=int8,int16,int32,int64,int,uint8,uint16,uint32,uint64,uint T2=float32,float64"

package util

import (
"strconv"
"github.com/cheekybits/genny/generic"
)

type T1 generic.Type

func ReadPairT1(data string) (x, y T1) {
splits := SplitParams(data)
lx, _ := strconv.Atoi(splits[0])
ly, _ := strconv.Atoi(splits[1])
x = T1(lx)
y = T1(ly)
return
}

type T2 generic.Type

func ReadPairT2(data string) (x, y T2) {
splits := SplitParams(data)
lx, _ := strconv.ParseFloat(splits[0], 32)
ly, _ := strconv.ParseFloat(splits[1], 32)
x = T2(lx)
y = T2(ly)
return
}
`

@fastfading
Copy link
Author

one more question the go:generate xxxxxx command is too long, how can I write it into several lines

@fastfading
Copy link
Author

I just want to write ReadPair in one file , and use different generic function for int and float

@icock
Copy link

icock commented Jul 1, 2017

Also, given S=More,Than,One,Type T=Multiple,Types, and

func f(s S) {}
func g(s S, t T) {}

genny will generate redundant definitions for f(S).

@olivoil
Copy link

olivoil commented Dec 27, 2017

I experienced the same issue. Would appreciate any guidance on how to implement a fix if a PR would be welcome.

@pdrum
Copy link
Collaborator

pdrum commented Aug 17, 2018

@olivoil parser.go generates the whole code once for each combination of specific types. For example it tends to generate the code once for S=More, T=Multiple, Once for S=Than, T=Multiple and so on (Each of these mappings is represented via a so called typeset). This leads to the bug mentioned in this issue.

Are you still thinking of making the PR? Please let me know if any more details would help.

@pdrum pdrum added the bug label Aug 17, 2018
@pdrum pdrum modified the milestone: Next release Aug 21, 2018
@pdrum pdrum self-assigned this Aug 21, 2018
@picasso250
Copy link

3 year passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants