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

Method custom_classfunc_rule

uncompyle6/parsers/parse3.py:586–640  ·  view source on GitHub ↗

call ::= expr {expr}^n CALL_FUNCTION_n call ::= expr {expr}^n CALL_FUNCTION_VAR_n call ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n call ::= expr {expr}^n CALL_FUNCTION_KW_n classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc {expr}^n-1 CALL_FUNCTION_n

(self, opname, token, customize, next_token, is_pypy)

Source from the content-addressed store, hash-verified

584 return
585
586 def custom_classfunc_rule(self, opname, token, customize, next_token, is_pypy):
587 """
588 call ::= expr {expr}^n CALL_FUNCTION_n
589 call ::= expr {expr}^n CALL_FUNCTION_VAR_n
590 call ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n
591 call ::= expr {expr}^n CALL_FUNCTION_KW_n
592
593 classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc {expr}^n-1 CALL_FUNCTION_n
594 """
595 pos_args_count, kw_args_count = self.get_pos_kw(token)
596
597 # Additional exprs for * and ** args:
598 # 0 if neither
599 # 1 for CALL_FUNCTION_VAR or CALL_FUNCTION_KW
600 # 2 for * and ** args (CALL_FUNCTION_VAR_KW).
601 # Yes, this computation based on instruction name is a little bit hoaky.
602 nak = (len(opname) - len("CALL_FUNCTION")) // 3
603
604 uniq_param = kw_args_count + pos_args_count
605
606 # Note: 3.5+ have subclassed this method; so we don't handle
607 # 'CALL_FUNCTION_VAR' or 'CALL_FUNCTION_EX' here.
608 if is_pypy and self.version >= (3, 6):
609 if token == "CALL_FUNCTION":
610 token.kind = self.call_fn_name(token)
611 rule = (
612 "call ::= expr "
613 + ("pos_arg " * pos_args_count)
614 + ("kwarg " * kw_args_count)
615 + token.kind
616 )
617 else:
618 token.kind = self.call_fn_name(token)
619 rule = (
620 "call ::= expr "
621 + ("pos_arg " * pos_args_count)
622 + ("kwarg " * kw_args_count)
623 + "expr " * nak
624 + token.kind
625 )
626
627 self.add_unique_rule(rule, token.kind, uniq_param, customize)
628
629 if "LOAD_BUILD_CLASS" in self.seen_ops:
630 if (
631 next_token == "CALL_FUNCTION"
632 and next_token.attr == 1
633 and pos_args_count > 1
634 ):
635 rule = "classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc %s%s_%d" % (
636 ("expr " * (pos_args_count - 1)),
637 opname,
638 pos_args_count,
639 )
640 self.add_unique_rule(rule, token.kind, uniq_param, customize)
641
642 def add_make_function_rule(self, rule, opname, attr, customize):
643 """Python 3.3 added a an additional LOAD_STR before MAKE_FUNCTION and

Callers 1

Calls 3

call_fn_nameMethod · 0.95
get_pos_kwMethod · 0.80
add_unique_ruleMethod · 0.80

Tested by

no test coverage detected