MCPcopy
hub / github.com/lutzroeder/netron / getSugaredVar

Method getSugaredVar

source/python.js:14497–14537  ·  view source on GitHub ↗
(ident, range, required)

Source from the content-addressed store, hash-verified

14495 }
14496 }
14497 getSugaredVar(ident, range, required) {
14498 required = required || true;
14499 let retval = this.findInAnyFrame(ident);
14500 if (!retval) {
14501 torch._C.Environment.globals = torch._C.Environment.globals || new Map([
14502 ['print', new torch._C.PrintValue()],
14503 ['tuple', torch._C.SpecialFormValue.create('prim::TupleConstruct')],
14504 ['float', new torch._C.MagicMethod('__float__', new torch._C.CastValue(torch.FloatType.get(), 'aten::Float'))],
14505 ['int', new torch._C.MagicMethod('__int__', new torch._C.CastValue(torch.IntType.get(), 'aten::Int'))],
14506 ['bool', new torch._C.MagicMethod('__bool__', new torch._C.CastValue(torch.BoolType.get(), 'aten::Bool'))],
14507 ['str', new torch._C.MagicMethod('__str__', new torch._C.CastValue(torch.StringType.get(), 'aten::str'))],
14508 ['getattr', torch._C.SpecialFormValue.create('prim::GetAttr')],
14509 ['hasattr', torch._C.SpecialFormValue.create('prim::HasAttr')],
14510 ['isinstance', torch._C.SpecialFormValue.create('prim::isinstance')],
14511 ['range', torch._C.SpecialFormValue.create('prim::range')],
14512 ['sorted', new torch._C.BuiltinFunction('aten::sorted', null)],
14513 ]);
14514 if (torch._C.Environment.globals.has(ident)) {
14515 retval = torch._C.Environment.globals.get(ident);
14516 }
14517 }
14518 if (!retval) {
14519 const type = this.resolver.resolveType(ident, range);
14520 if (type instanceof torch.TupleType) {
14521 retval = new torch.jit.NamedTupleConstructor(type);
14522 }
14523 }
14524 if (!retval) {
14525 retval = this.resolver.resolveValue(ident, this.method, range);
14526 }
14527 if (!retval) {
14528 const type = this.resolver.resolveType(ident, range);
14529 if (type instanceof torch.ClassType) {
14530 retval = new torch.jit.ClassValue(type);
14531 }
14532 }
14533 if (!retval && required) {
14534 throw new python.Error(`The name '${ident}' is not defined.`);
14535 }
14536 return retval;
14537 }
14538 getVar(ident, range) {
14539 return this.getSugaredVar(ident, range).asValue(range, this.method);
14540 }

Callers 3

getVarMethod · 0.80
emitToBoolMethod · 0.80
emitSugaredExprMethod · 0.80

Calls 6

findInAnyFrameMethod · 0.80
resolveValueMethod · 0.80
createMethod · 0.45
getMethod · 0.45
hasMethod · 0.45
resolveTypeMethod · 0.45

Tested by

no test coverage detected