@@ -369,9 +369,12 @@ type blockCtx struct {
369
369
tlookup * typeParamLookup
370
370
c2goBase string // default is `github.com/goplus/`
371
371
relBaseDir string
372
- classRecv * ast.FieldList // available when gmxSettings != nil
373
- fileScope * types.Scope // only valid when isGopFile
374
- rec * goxRecorder
372
+
373
+ classRecv * ast.FieldList // available when isClass
374
+ baseClass types.Object // available when isClass
375
+
376
+ fileScope * types.Scope // available when isGopFile
377
+ rec * goxRecorder
375
378
376
379
fileLine bool
377
380
isClass bool
@@ -742,12 +745,14 @@ func preloadGopFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, con
742
745
}
743
746
if f .IsProj {
744
747
o := proj .game
748
+ ctx .baseClass = o
745
749
baseTypeName , baseType = o .Name (), o .Type ()
746
750
if proj .gameIsPtr {
747
751
baseType = types .NewPointer (baseType )
748
752
}
749
753
} else {
750
754
o := proj .sprite [c .ext ]
755
+ ctx .baseClass = o
751
756
baseTypeName , baseType , spxClass = o .Name (), o .Type (), true
752
757
}
753
758
}
@@ -1215,8 +1220,17 @@ func loadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool) {
1215
1220
log .Printf ("==> Load method %v.%s\n " , recv .Type (), name )
1216
1221
}
1217
1222
}
1218
- pkg := ctx .pkg
1219
- if d .Operator {
1223
+ var pkg = ctx .pkg
1224
+ var sigBase * types.Signature
1225
+ if d .Shadow {
1226
+ if recv != nil {
1227
+ if base := ctx .baseClass ; base != nil {
1228
+ if f := findMethod (base , name ); f != nil {
1229
+ sigBase = makeMainSig (recv , f )
1230
+ }
1231
+ }
1232
+ }
1233
+ } else if d .Operator {
1220
1234
if recv != nil { // binary op
1221
1235
if v , ok := binaryGopNames [name ]; ok {
1222
1236
name = v
@@ -1232,7 +1246,10 @@ func loadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool) {
1232
1246
}
1233
1247
}
1234
1248
}
1235
- sig := toFuncType (ctx , d .Type , recv , d )
1249
+ sig := sigBase
1250
+ if sig == nil {
1251
+ sig = toFuncType (ctx , d .Type , recv , d )
1252
+ }
1236
1253
fn , err := pkg .NewFuncWith (d .Name .Pos (), name , sig , func () token.Pos {
1237
1254
return d .Recv .List [0 ].Type .Pos ()
1238
1255
})
@@ -1253,11 +1270,11 @@ func loadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool) {
1253
1270
file := pkg .CurFile ()
1254
1271
ctx .inits = append (ctx .inits , func () { // interface issue: #795
1255
1272
old := pkg .RestoreCurFile (file )
1256
- loadFuncBody (ctx , fn , body , d )
1273
+ loadFuncBody (ctx , fn , body , sigBase , d )
1257
1274
pkg .RestoreCurFile (old )
1258
1275
})
1259
1276
} else {
1260
- loadFuncBody (ctx , fn , body , d )
1277
+ loadFuncBody (ctx , fn , body , nil , d )
1261
1278
}
1262
1279
}
1263
1280
}
@@ -1316,8 +1333,18 @@ var unaryGopNames = map[string]string{
1316
1333
"<-" : "Gop_Recv" ,
1317
1334
}
1318
1335
1319
- func loadFuncBody (ctx * blockCtx , fn * gox.Func , body * ast.BlockStmt , src ast.Node ) {
1336
+ func loadFuncBody (ctx * blockCtx , fn * gox.Func , body * ast.BlockStmt , sigBase * types. Signature , src ast.Node ) {
1320
1337
cb := fn .BodyStart (ctx .pkg , body )
1338
+ if sigBase != nil {
1339
+ // this.Sprite.Main(...) or this.Game.MainEntry(...)
1340
+ cb .VarVal ("this" ).MemberVal (ctx .baseClass .Name ()).MemberVal (fn .Name ())
1341
+ params := sigBase .Params ()
1342
+ n := params .Len ()
1343
+ for i := 0 ; i < n ; i ++ {
1344
+ cb .Val (params .At (i ))
1345
+ }
1346
+ cb .Call (n ).EndStmt ()
1347
+ }
1321
1348
compileStmts (ctx , body .List )
1322
1349
if rec := ctx .recorder (); rec != nil {
1323
1350
switch fn := src .(type ) {
0 commit comments