Simplified type handling.
This commit is contained in:
parent
ee4f005b6c
commit
1c3bab0dcc
|
@ -15,6 +15,7 @@ type visitor struct{}
|
|||
|
||||
func trimType(n *string) {
|
||||
*n = pkgreg.ReplaceAllString(*n,"")
|
||||
*n = treg.ReplaceAllString(*n,"")
|
||||
}
|
||||
|
||||
func (v *visitor) Visit(node ast.Node) ast.Visitor {
|
||||
|
@ -36,14 +37,7 @@ func (v *visitor) Visit(node ast.Node) ast.Visitor {
|
|||
case *ast.CompositeLit:
|
||||
tp = types.TypeString(info.TypeOf(arg),types.RelativeTo(pkg))
|
||||
case *ast.Ident:
|
||||
if arg.Name == "true" || arg.Name == "false" {
|
||||
tp = "bool"
|
||||
break
|
||||
}
|
||||
if arg.Obj.Kind != ast.Var { return v }
|
||||
inner := pkg.Scope().Innermost(arg.Pos())
|
||||
_,obj := inner.LookupParent(arg.Obj.Name,arg.Pos())
|
||||
tp = types.TypeString(obj.Type(),types.RelativeTo(pkg))
|
||||
tp = types.TypeString(info.TypeOf(arg),types.RelativeTo(pkg))
|
||||
trimType(&tp)
|
||||
for _, s := range impreg.FindAllStringSubmatchIndex(tp, -1) {
|
||||
pkgname := impreg.ExpandString(make([]byte,0), "$1", tp, s)
|
||||
|
@ -67,6 +61,7 @@ var ts map[string]tps
|
|||
var reg *regexp.Regexp
|
||||
var pkgreg *regexp.Regexp
|
||||
var impreg *regexp.Regexp
|
||||
var treg *regexp.Regexp
|
||||
var imps map[string]string
|
||||
var needImps map[string]bool
|
||||
var info *types.Info
|
||||
|
@ -104,6 +99,7 @@ func init() {
|
|||
|
||||
pkgreg = regexp.MustCompile(`[a-zA-Z_]+[a-zA-Z_0-9\.]*/|"`)
|
||||
impreg = regexp.MustCompile(`([a-zA-Z_]+[a-zA-Z_0-9]+)\.[a-zA-Z_]+[a-zA-Z_0-9]+`)
|
||||
treg = regexp.MustCompile(`untyped `)
|
||||
|
||||
imps = make(map[string]string)
|
||||
needImps = make(map[string]bool)
|
||||
|
|
Loading…
Reference in New Issue
Block a user