MCPcopy
hub / github.com/rocky/python-uncompyle6 / custom_classfunc_rule

Method custom_classfunc_rule

uncompyle6/parsers/parse36.py:554–683  ·  view source on GitHub ↗
(self, opname, token, customize, next_token, is_pypy)

Source from the content-addressed store, hash-verified

552 return
553
554 def custom_classfunc_rule(self, opname, token, customize, next_token, is_pypy):
555 args_pos, args_kw = self.get_pos_kw(token)
556
557 # Additional exprs for * and ** args:
558 # 0 if neither
559 # 1 for CALL_FUNCTION_VAR or CALL_FUNCTION_KW
560 # 2 for * and ** args (CALL_FUNCTION_VAR_KW).
561 # Yes, this computation based on instruction name is a little bit hoaky.
562 nak = (len(opname) - len("CALL_FUNCTION")) // 3
563 uniq_param = args_kw + args_pos
564
565 if frozenset(("GET_AWAITABLE", "YIELD_FROM")).issubset(self.seen_ops):
566 rule = (
567 "async_call ::= expr "
568 + ("pos_arg " * args_pos)
569 + ("kwarg " * args_kw)
570 + "expr " * nak
571 + token.kind
572 + " GET_AWAITABLE LOAD_CONST YIELD_FROM"
573 )
574 self.add_unique_rule(rule, token.kind, uniq_param, customize)
575 self.add_unique_rule(
576 "expr ::= async_call", token.kind, uniq_param, customize
577 )
578
579 if opname.startswith("CALL_FUNCTION_KW"):
580 if is_pypy:
581 # PYPY doesn't follow CPython 3.6 CALL_FUNCTION_KW conventions
582 super(Python36Parser, self).custom_classfunc_rule(
583 opname, token, customize, next_token, is_pypy
584 )
585 else:
586 self.addRule("expr ::= call_kw36", nop_func)
587 values = "expr " * token.attr
588 rule = "call_kw36 ::= expr {values} LOAD_CONST {opname}".format(
589 **locals()
590 )
591 self.add_unique_rule(rule, token.kind, token.attr, customize)
592 elif opname == "CALL_FUNCTION_EX_KW":
593 # Note: this doesn't exist in 3.7 and later
594 self.addRule(
595 """expr ::= call_ex_kw4
596 call_ex_kw4 ::= expr
597 expr
598 expr
599 CALL_FUNCTION_EX_KW
600 """,
601 nop_func,
602 )
603 if "BUILD_MAP_UNPACK_WITH_CALL" in self.seen_op_basenames:
604 self.addRule(
605 """expr ::= call_ex_kw
606 call_ex_kw ::= expr expr build_map_unpack_with_call
607 CALL_FUNCTION_EX_KW
608 """,
609 nop_func,
610 )
611 if "BUILD_TUPLE_UNPACK_WITH_CALL" in self.seen_op_basenames:

Callers

nothing calls this directly

Calls 3

get_pos_kwMethod · 0.80
add_unique_ruleMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected