MCPcopy Index your code
hub / github.com/python/cpython / ArgResolver

Class ArgResolver

Lib/dis.py:556–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

554
555
556class ArgResolver:
557 def __init__(self, co_consts=None, names=None, varname_from_oparg=None, labels_map=None):
558 self.co_consts = co_consts
559 self.names = names
560 self.varname_from_oparg = varname_from_oparg
561 self.labels_map = labels_map or {}
562
563 def offset_from_jump_arg(self, op, arg, offset):
564 deop = _deoptop(op)
565 if deop in hasjabs:
566 return arg * 2
567 elif deop in hasjrel:
568 signed_arg = -arg if _is_backward_jump(deop) else arg
569 argval = offset + 2 + signed_arg*2
570 caches = _get_cache_size(_all_opname[deop])
571 argval += 2 * caches
572 return argval
573 return None
574
575 def get_label_for_offset(self, offset):
576 return self.labels_map.get(offset, None)
577
578 def get_argval_argrepr(self, op, arg, offset):
579 get_name = None if self.names is None else self.names.__getitem__
580 argval = None
581 argrepr = ''
582 deop = _deoptop(op)
583 if arg is not None:
584 # Set argval to the dereferenced value of the argument when
585 # available, and argrepr to the string representation of argval.
586 # _disassemble_bytes needs the string repr of the
587 # raw name index for LOAD_GLOBAL, LOAD_CONST, etc.
588 argval = arg
589 if deop in hasconst:
590 argval, argrepr = _get_const_info(deop, arg, self.co_consts)
591 elif deop in hasname:
592 if deop == LOAD_GLOBAL:
593 argval, argrepr = _get_name_info(arg//2, get_name)
594 if (arg & 1) and argrepr:
595 argrepr = f"{argrepr} + NULL"
596 elif deop == LOAD_ATTR:
597 argval, argrepr = _get_name_info(arg//2, get_name)
598 if (arg & 1) and argrepr:
599 argrepr = f"{argrepr} + NULL|self"
600 elif deop == LOAD_SUPER_ATTR:
601 argval, argrepr = _get_name_info(arg//4, get_name)
602 if (arg & 1) and argrepr:
603 argrepr = f"{argrepr} + NULL|self"
604 elif deop == IMPORT_NAME:
605 argval, argrepr = _get_name_info(arg//4, get_name)
606 if (arg & 1) and argrepr:
607 argrepr = f"{argrepr} + lazy"
608 elif (arg & 2) and argrepr:
609 argrepr = f"{argrepr} + eager"
610 else:
611 argval, argrepr = _get_name_info(arg, get_name)
612 elif deop in hasjump or deop in hasexc:
613 argval = self.offset_from_jump_arg(op, arg, offset)

Callers 5

disFunction · 0.85
get_instructionsFunction · 0.85
disassembleFunction · 0.85
__iter__Method · 0.85
disMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…