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

Method custom_classfunc_rule

uncompyle6/parsers/parse35.py:233–284  ·  view source on GitHub ↗
(self, opname, token, customize, *args)

Source from the content-addressed store, hash-verified

231 return
232
233 def custom_classfunc_rule(self, opname, token, customize, *args):
234 args_pos, args_kw = self.get_pos_kw(token)
235
236 # Additional exprs for * and ** args:
237 # 0 if neither
238 # 1 for CALL_FUNCTION_VAR or CALL_FUNCTION_KW
239 # 2 for * and ** args (CALL_FUNCTION_VAR_KW).
240 # Yes, this computation based on instruction name is a little bit hoaky.
241 nak = (len(opname) - len("CALL_FUNCTION")) // 3
242 uniq_param = args_kw + args_pos
243
244 if frozenset(("GET_AWAITABLE", "YIELD_FROM")).issubset(self.seen_ops):
245 rule = (
246 "async_call ::= expr "
247 + ("pos_arg " * args_pos)
248 + ("kwarg " * args_kw)
249 + "expr " * nak
250 + token.kind
251 + " GET_AWAITABLE LOAD_CONST YIELD_FROM"
252 )
253 self.add_unique_rule(rule, token.kind, uniq_param, customize)
254 self.add_unique_rule(
255 "expr ::= async_call", token.kind, uniq_param, customize
256 )
257
258 if opname.startswith("CALL_FUNCTION_VAR"):
259 # Python 3.5 changes the stack position of *args. KW args come
260 # after *args.
261
262 # Note: Python 3.6+ replaces CALL_FUNCTION_VAR and
263 # CALL_FUNCTION_VAR_KW with CALL_FUNCTION_EX
264
265 token.kind = self.call_fn_name(token)
266 if opname.endswith("KW"):
267 kw = "expr "
268 else:
269 kw = ""
270 rule = (
271 "call ::= expr expr "
272 + ("pos_arg " * args_pos)
273 + ("kwarg " * args_kw)
274 + kw
275 + token.kind
276 )
277
278 # Note: semantic actions make use of the fact of whether "args_pos"
279 # zero or not in creating a template rule.
280 self.add_unique_rule(rule, token.kind, args_pos, customize)
281 else:
282 super(Python35Parser, self).custom_classfunc_rule(
283 opname, token, customize, *args
284 )
285
286
287class Python35ParserSingle(Python35Parser, PythonParserSingle):

Callers

nothing calls this directly

Calls 3

get_pos_kwMethod · 0.80
add_unique_ruleMethod · 0.80
call_fn_nameMethod · 0.45

Tested by

no test coverage detected