MCPcopy Index your code
hub / github.com/python/mypy / transform_call_expr

Function transform_call_expr

mypyc/irbuild/expression.py:350–397  ·  view source on GitHub ↗
(builder: IRBuilder, expr: CallExpr)

Source from the content-addressed store, hash-verified

348
349
350def transform_call_expr(builder: IRBuilder, expr: CallExpr) -> Value:
351 callee = expr.callee
352 if isinstance(expr.analyzed, CastExpr):
353 return translate_cast_expr(builder, expr.analyzed)
354 elif isinstance(expr.analyzed, AssertTypeExpr):
355 # Compile to a no-op.
356 return builder.accept(expr.analyzed.expr)
357 elif (
358 isinstance(callee, (NameExpr, MemberExpr))
359 and isinstance(callee.node, TypeInfo)
360 and callee.node.is_newtype
361 ):
362 # A call to a NewType type is a no-op at runtime.
363 return builder.accept(expr.args[0])
364
365 if isinstance(callee, IndexExpr) and isinstance(callee.analyzed, TypeApplication):
366 analyzed = callee.analyzed
367 if (
368 isinstance(analyzed.expr, RefExpr)
369 and analyzed.expr.fullname == "librt.vecs.vec"
370 and len(analyzed.types) == 1
371 ):
372 item_type = builder.type_to_rtype(analyzed.types[0])
373 vec_type = RVec(item_type)
374 capacity = _get_vec_capacity(builder, expr)
375 if len(expr.args) == 0 or (len(expr.args) == 1 and expr.arg_kinds == [ARG_NAMED]):
376 # vec[T]() or vec[T](capacity=N)
377 return vec_create(builder.builder, vec_type, 0, expr.line, capacity=capacity)
378 elif (len(expr.args) == 1 and expr.arg_kinds == [ARG_POS]) or (
379 len(expr.args) == 2 and expr.arg_kinds == [ARG_POS, ARG_NAMED]
380 ):
381 # vec[T](items) or vec[T](items, capacity=N)
382 return translate_vec_create_from_iterable(
383 builder, vec_type, expr.args[0], capacity=capacity
384 )
385 callee = analyzed.expr # Unwrap type application
386
387 if isinstance(callee, MemberExpr):
388 if isinstance(callee.expr, RefExpr) and isinstance(callee.expr.node, MypyFile):
389 # Call a module-level function, not a method.
390 return translate_call(builder, expr, callee)
391 return apply_method_specialization(builder, expr, callee) or translate_method_call(
392 builder, expr, callee
393 )
394 elif isinstance(callee, SuperExpr):
395 return translate_super_method_call(builder, expr, callee)
396 else:
397 return translate_call(builder, expr, callee)
398
399
400def translate_call(builder: IRBuilder, expr: CallExpr, callee: Expression) -> Value:

Callers 1

visit_call_exprMethod · 0.90

Calls 13

RVecClass · 0.90
vec_createFunction · 0.90
isinstanceFunction · 0.85
translate_cast_exprFunction · 0.85
lenFunction · 0.85
_get_vec_capacityFunction · 0.85
translate_callFunction · 0.85
translate_method_callFunction · 0.85
acceptMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…