Refactor pgen to use a visitor struct instead of globals.

This commit is contained in:
gmp
2018-08-06 12:35:35 -04:00
parent 2f95327892
commit 4c5821c7d5
2 changed files with 46 additions and 36 deletions
+6 -4
View File
@@ -131,14 +131,16 @@ func (g *Generator) Add(newName, typName, typ string) {
g.firstone = false
}
func (g *Generator) Import(name string) {
func (g *Generator) Import(ns ...string) {
if g.nodes == nil {
return
}
// strip quotation marks from imports
name = qexp.ReplaceAllString(name,"")
astutil.AddImport(g.fset, g.nodes, name)
for _,n := range ns {
// strip quotation marks from imports
n = qexp.ReplaceAllString(n,"")
astutil.AddImport(g.fset, g.nodes, n)
}
}
func (g *Generator) Save(of io.Writer) {