|
@@ -171,6 +171,31 @@ func Generate(outfile, buildTag, codecPkgPath string, uid int64, useUnsafe bool,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // keep track of types with selfer methods
|
|
|
|
|
+ // selferMethods := []string{"CodecEncodeSelf", "CodecDecodeSelf"}
|
|
|
|
|
+ selferEncTyps := make(map[string]bool)
|
|
|
|
|
+ selferDecTyps := make(map[string]bool)
|
|
|
|
|
+ for _, f := range astfiles {
|
|
|
|
|
+ for _, d := range f.Decls {
|
|
|
|
|
+ // if fd, ok := d.(*ast.FuncDecl); ok && fd.Recv != nil && fd.Recv.NumFields() == 1 {
|
|
|
|
|
+ if fd, ok := d.(*ast.FuncDecl); ok && fd.Recv != nil && len(fd.Recv.List) == 1 {
|
|
|
|
|
+ recvType := fd.Recv.List[0].Type
|
|
|
|
|
+ if ptr, ok := recvType.(*ast.StarExpr); ok {
|
|
|
|
|
+ recvType = ptr.X
|
|
|
|
|
+ }
|
|
|
|
|
+ if id, ok := recvType.(*ast.Ident); ok {
|
|
|
|
|
+ switch fd.Name.Name {
|
|
|
|
|
+ case "CodecEncodeSelf":
|
|
|
|
|
+ selferEncTyps[id.Name] = true
|
|
|
|
|
+ case "CodecDecodeSelf":
|
|
|
|
|
+ selferDecTyps[id.Name] = true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // now find types
|
|
|
for _, f := range astfiles {
|
|
for _, f := range astfiles {
|
|
|
for _, d := range f.Decls {
|
|
for _, d := range f.Decls {
|
|
|
if gd, ok := d.(*ast.GenDecl); ok {
|
|
if gd, ok := d.(*ast.GenDecl); ok {
|
|
@@ -191,7 +216,14 @@ func Generate(outfile, buildTag, codecPkgPath string, uid int64, useUnsafe bool,
|
|
|
// FuncType, InterfaceType, StarExpr (ptr), etc
|
|
// FuncType, InterfaceType, StarExpr (ptr), etc
|
|
|
switch td.Type.(type) {
|
|
switch td.Type.(type) {
|
|
|
case *ast.StructType, *ast.Ident, *ast.MapType, *ast.ArrayType, *ast.ChanType:
|
|
case *ast.StructType, *ast.Ident, *ast.MapType, *ast.ArrayType, *ast.ChanType:
|
|
|
- if regexName.FindStringIndex(td.Name.Name) != nil && notRegexName.FindStringIndex(td.Name.Name) == nil {
|
|
|
|
|
|
|
+ // only add to tv.Types iff
|
|
|
|
|
+ // - it matches per the -r parameter
|
|
|
|
|
+ // - it doesn't match per the -nr parameter
|
|
|
|
|
+ // - it doesn't have any of the Selfer methods in the file
|
|
|
|
|
+ if regexName.FindStringIndex(td.Name.Name) != nil &&
|
|
|
|
|
+ notRegexName.FindStringIndex(td.Name.Name) == nil &&
|
|
|
|
|
+ !selferEncTyps[td.Name.Name] &&
|
|
|
|
|
+ !selferDecTyps[td.Name.Name] {
|
|
|
tv.Types = append(tv.Types, td.Name.Name)
|
|
tv.Types = append(tv.Types, td.Name.Name)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|