MCPcopy
hub / github.com/gopherjs/gopherjs / objectName

Method objectName

compiler/utils.go:421–450  ·  view source on GitHub ↗

objectName returns a JS expression that refers to the given object. If the object hasn't been previously assigned a JS variable name, it will be allocated as needed.

(o types.Object)

Source from the content-addressed store, hash-verified

419// object hasn't been previously assigned a JS variable name, it will be
420// allocated as needed.
421func (fc *funcContext) objectName(o types.Object) string {
422 if isPkgLevel(o) {
423 var nestTArgs []types.Type
424 if typeparams.FindNestingFunc(o) == fc.instance.Object {
425 // Only set the nest type arguments for objects nested in this funcContext.
426 nestTArgs = fc.instance.TArgs
427 }
428 fc.pkgCtx.DeclareDCEDep(o, nestTArgs, nil)
429
430 if o.Pkg() != fc.pkgCtx.Pkg || (isVarOrConst(o) && o.Exported()) {
431 return fc.pkgVar(o.Pkg()) + "." + o.Name()
432 }
433 }
434
435 name, ok := fc.assignedObjectName(o)
436 if !ok {
437 pkgLevel := isPkgLevel(o)
438 name = fc.newVariable(o.Name(), pkgLevel)
439 if pkgLevel {
440 fc.root().objectNames[o] = name
441 } else {
442 fc.objectNames[o] = name
443 }
444 }
445
446 if v, ok := o.(*types.Var); ok && fc.pkgCtx.escapingVars[v] {
447 return name + "[0]"
448 }
449 return name
450}
451
452// knownInstances returns a list of known instantiations of the object.
453//

Callers 12

translateStmtMethod · 0.95
translateAssignMethod · 0.95
instNameMethod · 0.95
handleEscapingVarsMethod · 0.95
translateExprMethod · 0.95
translateConversionMethod · 0.95
translateFunctionBodyMethod · 0.95
topLevelObjectsMethod · 0.95
newVarDeclMethod · 0.95
funcDeclsMethod · 0.95
newFuncDeclMethod · 0.95
newNamedTypeVarDeclMethod · 0.95

Calls 10

pkgVarMethod · 0.95
assignedObjectNameMethod · 0.95
newVariableMethod · 0.95
rootMethod · 0.95
FindNestingFuncFunction · 0.92
isPkgLevelFunction · 0.85
isVarOrConstFunction · 0.85
DeclareDCEDepMethod · 0.80
PkgMethod · 0.80
NameMethod · 0.45

Tested by

no test coverage detected