@@ -1270,22 +1270,26 @@ type mthdSignature interface {
1270
1270
Params () * types.Tuple
1271
1271
}
1272
1272
1273
- type builtinTI struct {
1273
+ type BuiltinTI struct {
1274
1274
typ types.Type
1275
1275
methods []* builtinMethod
1276
1276
}
1277
1277
1278
- func (p * builtinTI ) NumMethods () int {
1278
+ func (p * BuiltinTI ) AddMethod (name string , fn types.Object , eargs ... interface {}) {
1279
+ p .methods = append (p .methods , & builtinMethod {name , fn , eargs })
1280
+ }
1281
+
1282
+ func (p * BuiltinTI ) numMethods () int {
1279
1283
return len (p .methods )
1280
1284
}
1281
1285
1282
- func (p * builtinTI ) Method (i int ) * builtinMethod {
1286
+ func (p * BuiltinTI ) method (i int ) * builtinMethod {
1283
1287
return p .methods [i ]
1284
1288
}
1285
1289
1286
- func (p * builtinTI ) lookupByName (name string ) mthdSignature {
1287
- for i , n := 0 , p .NumMethods (); i < n ; i ++ {
1288
- method := p .Method (i )
1290
+ func (p * BuiltinTI ) lookupByName (name string ) mthdSignature {
1291
+ for i , n := 0 , p .numMethods (); i < n ; i ++ {
1292
+ method := p .method (i )
1289
1293
if method .name == name {
1290
1294
return method
1291
1295
}
@@ -1301,8 +1305,8 @@ var (
1301
1305
1302
1306
func initBuiltinTIs (pkg * Package ) {
1303
1307
var (
1304
- float64TI , intTI , int64TI , uint64TI * builtinTI
1305
- ioxTI , stringTI , stringSliceTI * builtinTI
1308
+ float64TI , intTI , int64TI , uint64TI * BuiltinTI
1309
+ ioxTI , stringTI , stringSliceTI * BuiltinTI
1306
1310
)
1307
1311
btiMap := new (typeutil.Map )
1308
1312
strconv := pkg .TryImport ("strconv" )
@@ -1317,7 +1321,7 @@ func initBuiltinTIs(pkg *Package) {
1317
1321
if ioxPkg != "" {
1318
1322
if os := pkg .TryImport ("os" ); os .isValid () {
1319
1323
if iox := pkg .TryImport (ioxPkg ); iox .isValid () {
1320
- ioxTI = & builtinTI {
1324
+ ioxTI = & BuiltinTI {
1321
1325
typ : os .Ref ("File" ).Type (),
1322
1326
methods : []* builtinMethod {
1323
1327
{"Gop_Enum" , iox .Ref ("EnumLines" ), nil },
@@ -1328,33 +1332,33 @@ func initBuiltinTIs(pkg *Package) {
1328
1332
}
1329
1333
}
1330
1334
if strconv .isValid () {
1331
- float64TI = & builtinTI {
1335
+ float64TI = & BuiltinTI {
1332
1336
typ : types .Typ [types .Float64 ],
1333
1337
methods : []* builtinMethod {
1334
1338
{"String" , strconv .Ref ("FormatFloat" ), bmExargs {'g' , - 1 , 64 }},
1335
1339
},
1336
1340
}
1337
- intTI = & builtinTI {
1341
+ intTI = & BuiltinTI {
1338
1342
typ : types .Typ [types .Int ],
1339
1343
methods : []* builtinMethod {
1340
1344
{"String" , strconv .Ref ("Itoa" ), nil },
1341
1345
},
1342
1346
}
1343
- int64TI = & builtinTI {
1347
+ int64TI = & BuiltinTI {
1344
1348
typ : types .Typ [types .Int64 ],
1345
1349
methods : []* builtinMethod {
1346
1350
{"String" , strconv .Ref ("FormatInt" ), bmExargs {10 }},
1347
1351
},
1348
1352
}
1349
- uint64TI = & builtinTI {
1353
+ uint64TI = & BuiltinTI {
1350
1354
typ : types .Typ [types .Uint64 ],
1351
1355
methods : []* builtinMethod {
1352
1356
{"String" , strconv .Ref ("FormatUint" ), bmExargs {10 }},
1353
1357
},
1354
1358
}
1355
1359
}
1356
1360
if strings .isValid () && strconv .isValid () {
1357
- stringTI = & builtinTI {
1361
+ stringTI = & BuiltinTI {
1358
1362
typ : types .Typ [types .String ],
1359
1363
methods : []* builtinMethod {
1360
1364
{"Len" , btoLen , nil },
@@ -1400,7 +1404,7 @@ func initBuiltinTIs(pkg *Package) {
1400
1404
}
1401
1405
}
1402
1406
if strings .isValid () {
1403
- stringSliceTI = & builtinTI {
1407
+ stringSliceTI = & BuiltinTI {
1404
1408
typ : types .NewSlice (types .Typ [types .String ]),
1405
1409
methods : []* builtinMethod {
1406
1410
{"Len" , btoLen , nil },
@@ -1409,7 +1413,7 @@ func initBuiltinTIs(pkg *Package) {
1409
1413
},
1410
1414
}
1411
1415
}
1412
- tis := []* builtinTI {
1416
+ tis := []* BuiltinTI {
1413
1417
ioxTI ,
1414
1418
float64TI ,
1415
1419
intTI ,
@@ -1445,7 +1449,7 @@ func initBuiltinTIs(pkg *Package) {
1445
1449
pkg .cb .btiMap = btiMap
1446
1450
}
1447
1451
1448
- func (p * CodeBuilder ) getBuiltinTI (typ types.Type ) * builtinTI {
1452
+ func (p * CodeBuilder ) getBuiltinTI (typ types.Type ) * BuiltinTI {
1449
1453
switch t := typ .(type ) {
1450
1454
case * types.Basic :
1451
1455
typ = types .Default (typ )
@@ -1459,9 +1463,15 @@ func (p *CodeBuilder) getBuiltinTI(typ types.Type) *builtinTI {
1459
1463
typ = tyChan
1460
1464
}
1461
1465
if bti := p .btiMap .At (typ ); bti != nil {
1462
- return bti .(* builtinTI )
1466
+ return bti .(* BuiltinTI )
1463
1467
}
1464
1468
return nil
1465
1469
}
1466
1470
1467
1471
// ----------------------------------------------------------------------------
1472
+
1473
+ func (p * Package ) BuiltinTI (typ types.Type ) * BuiltinTI {
1474
+ return p .cb .getBuiltinTI (typ )
1475
+ }
1476
+
1477
+ // ----------------------------------------------------------------------------
0 commit comments