@@ -160,6 +160,7 @@ func (fc *funcContext) importDecls() (importedPaths []string, importDecls []*Dec
160
160
func (fc * funcContext ) newImportDecl (importedPkg * types.Package ) * Decl {
161
161
pkgVar := fc .importedPkgVar (importedPkg )
162
162
d := & Decl {
163
+ FullName : importDeclFullName (importedPkg ),
163
164
Vars : []string {pkgVar },
164
165
DeclCode : []byte (fmt .Sprintf ("\t %s = $packages[\" %s\" ];\n " , pkgVar , importedPkg .Path ())),
165
166
InitCode : fc .CatchOutput (1 , func () { fc .translateStmt (fc .importInitializer (importedPkg .Path ()), nil ) }),
@@ -224,7 +225,9 @@ func (fc *funcContext) varDecls(vars []*types.Var) []*Decl {
224
225
// newVarDecl creates a new Decl describing a variable, given an explicit
225
226
// initializer.
226
227
func (fc * funcContext ) newVarDecl (init * types.Initializer ) * Decl {
227
- var d Decl
228
+ d := & Decl {
229
+ FullName : varDeclFullName (init ),
230
+ }
228
231
229
232
assignLHS := []ast.Expr {}
230
233
for _ , o := range init .Lhs {
@@ -241,7 +244,7 @@ func (fc *funcContext) newVarDecl(init *types.Initializer) *Decl {
241
244
}
242
245
}
243
246
244
- fc .pkgCtx .CollectDCEDeps (& d , func () {
247
+ fc .pkgCtx .CollectDCEDeps (d , func () {
245
248
fc .localVars = nil
246
249
d .InitCode = fc .CatchOutput (1 , func () {
247
250
fc .translateStmt (& ast.AssignStmt {
@@ -261,7 +264,7 @@ func (fc *funcContext) newVarDecl(init *types.Initializer) *Decl {
261
264
if len (init .Lhs ) != 1 || analysis .HasSideEffect (init .Rhs , fc .pkgCtx .Info .Info ) {
262
265
d .Dce ().SetAsAlive ()
263
266
}
264
- return & d
267
+ return d
265
268
}
266
269
267
270
// funcDecls translates all package-level function and methods.
@@ -279,15 +282,18 @@ func (fc *funcContext) funcDecls(functions []*ast.FuncDecl) ([]*Decl, error) {
279
282
if fun .Recv == nil {
280
283
// Auxiliary decl shared by all instances of the function that defines
281
284
// package-level variable by which they all are referenced.
282
- varDecl := Decl {}
285
+ objName := fc .objectName (o )
286
+ varDecl := & Decl {
287
+ FullName : funcVarDeclFullName (o ),
288
+ Vars : []string {objName },
289
+ }
283
290
varDecl .Dce ().SetName (o )
284
- varDecl .Vars = []string {fc .objectName (o )}
285
291
if o .Type ().(* types.Signature ).TypeParams ().Len () != 0 {
286
292
varDecl .DeclCode = fc .CatchOutput (0 , func () {
287
- fc .Printf ("%s = {};" , fc . objectName ( o ) )
293
+ fc .Printf ("%s = {};" , objName )
288
294
})
289
295
}
290
- funcDecls = append (funcDecls , & varDecl )
296
+ funcDecls = append (funcDecls , varDecl )
291
297
}
292
298
293
299
for _ , inst := range fc .knownInstances (o ) {
@@ -306,6 +312,7 @@ func (fc *funcContext) funcDecls(functions []*ast.FuncDecl) ([]*Decl, error) {
306
312
// been initialized. It must come after all other functions, especially all
307
313
// init() functions, otherwise main() will be invoked too early.
308
314
funcDecls = append (funcDecls , & Decl {
315
+ FullName : mainFuncDeclFullName (),
309
316
InitCode : fc .CatchOutput (1 , func () { fc .translateStmt (fc .callMainFunc (mainFunc ), nil ) }),
310
317
})
311
318
}
@@ -316,7 +323,7 @@ func (fc *funcContext) funcDecls(functions []*ast.FuncDecl) ([]*Decl, error) {
316
323
func (fc * funcContext ) newFuncDecl (fun * ast.FuncDecl , inst typeparams.Instance ) * Decl {
317
324
o := fc .pkgCtx .Defs [fun .Name ].(* types.Func )
318
325
d := & Decl {
319
- FullName : o . FullName ( ),
326
+ FullName : funcDeclFullName ( inst ),
320
327
Blocking : fc .pkgCtx .IsBlocking (inst ),
321
328
LinkingName : symbol .New (o ),
322
329
}
@@ -417,15 +424,19 @@ func (fc *funcContext) namedTypeDecls(typeNames typesutil.TypeNames) ([]*Decl, e
417
424
// of the type, keyed by the type argument combination. Otherwise it contains
418
425
// the type definition directly.
419
426
func (fc * funcContext ) newNamedTypeVarDecl (obj * types.TypeName ) * Decl {
420
- varDecl := & Decl {Vars : []string {fc .objectName (obj )}}
427
+ name := fc .objectName (obj )
428
+ varDecl := & Decl {
429
+ FullName : typeVarDeclFullName (obj ),
430
+ Vars : []string {name },
431
+ }
421
432
if typeparams .HasTypeParams (obj .Type ()) {
422
433
varDecl .DeclCode = fc .CatchOutput (0 , func () {
423
- fc .Printf ("%s = {};" , fc . objectName ( obj ) )
434
+ fc .Printf ("%s = {};" , name )
424
435
})
425
436
}
426
437
if isPkgLevel (obj ) {
427
438
varDecl .TypeInitCode = fc .CatchOutput (0 , func () {
428
- fc .Printf ("$pkg.%s = %s;" , encodeIdent (obj .Name ()), fc . objectName ( obj ) )
439
+ fc .Printf ("$pkg.%s = %s;" , encodeIdent (obj .Name ()), name )
429
440
})
430
441
}
431
442
return varDecl
@@ -449,7 +460,9 @@ func (fc *funcContext) newNamedTypeInstDecl(inst typeparams.Instance) (*Decl, er
449
460
}
450
461
451
462
underlying := instanceType .Underlying ()
452
- d := & Decl {}
463
+ d := & Decl {
464
+ FullName : typeDeclFullName (inst ),
465
+ }
453
466
d .Dce ().SetName (inst .Object , inst .TArgs ... )
454
467
fc .pkgCtx .CollectDCEDeps (d , func () {
455
468
// Code that declares a JS type (i.e. prototype) for each Go type.
@@ -571,7 +584,8 @@ func (fc *funcContext) anonTypeDecls(anonTypes []*types.TypeName) []*Decl {
571
584
decls := []* Decl {}
572
585
for _ , t := range anonTypes {
573
586
d := & Decl {
574
- Vars : []string {t .Name ()},
587
+ FullName : anonTypeDeclFullName (t ),
588
+ Vars : []string {t .Name ()},
575
589
}
576
590
d .Dce ().SetName (t )
577
591
fc .pkgCtx .CollectDCEDeps (d , func () {
0 commit comments