@@ -36,6 +36,7 @@ type Builtin struct {
3636 name string
3737 pkg string
3838 sym string
39+ fn bool
3940}
4041
4142func (t * Builtin ) Parent () * types.Scope {
@@ -65,6 +66,9 @@ func (t *Builtin) String() string {
6566func (t * Builtin ) Sym () string {
6667 return t .pkg + "." + t .sym
6768}
69+ func (t * Builtin ) IsFunc () bool {
70+ return t .fn
71+ }
6872
6973var (
7074 Universe * types.Scope
@@ -74,33 +78,35 @@ var builtinDefs = [...]struct {
7478 name string
7579 pkg string
7680 sym string
81+ fn bool
7782}{
78- {"bigint" , "github.com/goplus/gop/builtin/ng" , "" },
79- {"bigrat" , "github.com/goplus/gop/builtin/ng" , "" },
80- {"bigfloat" , "github.com/goplus/gop/builtin/ng" , "" },
81- {"int128" , "github.com/goplus/gop/builtin/ng" , "" },
82- {"uint128" , "github.com/goplus/gop/builtin/ng" , "" },
83- {"lines" , "github.com/goplus/gop/builtin/iox" , "" },
84- {"blines" , "github.com/goplus/gop/builtin/iox" , "BLines" },
85- {"newRange" , "github.com/goplus/gop/builtin" , "NewRange__0" },
86- {"echo" , "fmt" , "Println" },
87- {"print" , "fmt" , "" },
88- {"println" , "fmt" , "" },
89- {"printf" , "fmt" , "" },
90- {"errorf" , "fmt" , "" },
91- {"fprint" , "fmt" , "" },
92- {"fprintln" , "fmt" , "" },
93- {"sprint" , "fmt" , "" },
94- {"sprintln" , "fmt" , "" },
95- {"sprintf" , "fmt" , "" },
96- {"open" , "os" , "" },
97- {"create" , "os" , "" },
98- {"type" , "reflect" , "TypeOf" },
83+ {"bigint" , "github.com/goplus/gop/builtin/ng" , "" , false },
84+ {"bigrat" , "github.com/goplus/gop/builtin/ng" , "" , false },
85+ {"bigfloat" , "github.com/goplus/gop/builtin/ng" , "" , false },
86+ {"int128" , "github.com/goplus/gop/builtin/ng" , "" , false },
87+ {"uint128" , "github.com/goplus/gop/builtin/ng" , "" , false },
88+ {"lines" , "github.com/goplus/gop/builtin/iox" , "" , true },
89+ {"blines" , "github.com/goplus/gop/builtin/iox" , "BLines" , true },
90+ {"newRange" , "github.com/goplus/gop/builtin" , "NewRange__0" , true },
91+ {"echo" , "fmt" , "Println" , true },
92+ {"print" , "fmt" , "" , true },
93+ {"println" , "fmt" , "" , true },
94+ {"printf" , "fmt" , "" , true },
95+ {"errorf" , "fmt" , "" , true },
96+ {"fprint" , "fmt" , "" , true },
97+ {"fprintln" , "fmt" , "" , true },
98+ {"sprint" , "fmt" , "" , true },
99+ {"sprintln" , "fmt" , "" , true },
100+ {"sprintf" , "fmt" , "" , true },
101+ {"open" , "os" , "" , true },
102+ {"create" , "os" , "" , true },
103+ {"type" , "reflect" , "TypeOf" , true },
99104}
100105
101106type defSym struct {
102107 name string
103108 sym string
109+ fn bool
104110}
105111
106112var (
@@ -114,22 +120,25 @@ func init() {
114120 if def .sym == "" {
115121 def .sym = string (def .name [0 ]- ('a' - 'A' )) + def .name [1 :]
116122 }
117- builtinSym [def .pkg ] = append (builtinSym [def .pkg ], defSym {name : def .name , sym : def .sym })
118- obj := & Builtin {name : def .name , pkg : def .pkg , sym : def .sym }
123+ builtinSym [def .pkg ] = append (builtinSym [def .pkg ], defSym {name : def .name , sym : def .sym , fn : def . fn })
124+ obj := & Builtin {name : def .name , pkg : def .pkg , sym : def .sym , fn : def . fn }
119125 Universe .Insert (obj )
120126 }
121127}
122128
123- func initBuiltin (pkg * gogen.Package , builtin * types.Package ) {
129+ func initBuiltin (pkg * gogen.Package , builtin * types.Package , conf * gogen. Config ) {
124130 scope := builtin .Scope ()
125131 for im , defs := range builtinSym {
126132 if p := pkg .TryImport (im ); p .Types != nil {
127133 for _ , def := range defs {
128134 obj := p .Ref (def .sym )
129- if _ , ok := obj .Type ().(* types.Named ); ok {
130- scope .Insert (types .NewTypeName (token .NoPos , builtin , def .name , obj .Type ()))
131- } else {
135+ if def .fn {
132136 scope .Insert (gogen .NewOverloadFunc (token .NoPos , builtin , def .name , obj ))
137+ } else {
138+ scope .Insert (types .NewTypeName (token .NoPos , builtin , def .name , obj .Type ()))
139+ }
140+ if rec , ok := conf .Recorder .(* goxRecorder ); ok {
141+ rec .Builtin (def .name , obj )
133142 }
134143 }
135144 }
@@ -147,7 +156,7 @@ func newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package {
147156 if ng .Types != nil {
148157 initMathBig (pkg , conf , ng )
149158 }
150- initBuiltin (pkg , builtin )
159+ initBuiltin (pkg , builtin , conf )
151160 gogen .InitBuiltin (pkg , builtin , conf )
152161 if strx .Types != nil {
153162 ti := pkg .BuiltinTI (types .Typ [types .String ])
0 commit comments