-
Notifications
You must be signed in to change notification settings - Fork 50
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
Support overriden types #116
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package gengo | ||
|
||
import ( | ||
"go/ast" | ||
"go/parser" | ||
"go/token" | ||
"path" | ||
"strings" | ||
) | ||
|
||
// getExternTypes provides a mapping of all types defined in the destination package. | ||
// It is used by generate to not duplicate defined types to allow overriding of types. | ||
func getExternTypes(pth string) (map[string]struct{}, error) { | ||
set := token.NewFileSet() | ||
packs, err := parser.ParseDir(set, pth, nil, 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
types := make(map[string]struct{}) | ||
for _, pack := range packs { | ||
for fname, f := range pack.Files { | ||
if strings.HasPrefix(path.Base(fname), "ipldsch_") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is a generator and the performance isn't the most important thing, but parsing all files to then only look at a small minority is a bit wasteful :) It would be significantly less work to use globbing to find the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is excluding the three There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤦 I read the logic backwards. I guess my point here is still valid, though now it's just "you can avoid reading+parsing these 3-4 files". |
||
continue | ||
} | ||
for _, d := range f.Decls { | ||
if t, isType := d.(*ast.GenDecl); isType { | ||
if t.Tok == token.TYPE { | ||
for _, s := range t.Specs { | ||
ts := s.(*ast.TypeSpec) | ||
types[ts.Name.Name] = struct{}{} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return types, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overridenTypes
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
manualHijinx
?