From 1c3bab0dccb8f434d5019334bea56cd9ca28eaa3 Mon Sep 17 00:00:00 2001 From: Greg Date: Sat, 4 Aug 2018 16:39:39 -0400 Subject: [PATCH] Simplified type handling. --- cmd/pgen/main.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cmd/pgen/main.go b/cmd/pgen/main.go index 7b96dd6..0aa5a47 100644 --- a/cmd/pgen/main.go +++ b/cmd/pgen/main.go @@ -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)