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

Function generate_offset_table

mypyc/codegen/emitclass.py:557–570  ·  view source on GitHub ↗

Generate attribute offset row of a trait vtable.

(
    trait_offset_table_name: str, emitter: Emitter, trait: ClassIR, cl: ClassIR
)

Source from the content-addressed store, hash-verified

555
556
557def generate_offset_table(
558 trait_offset_table_name: str, emitter: Emitter, trait: ClassIR, cl: ClassIR
559) -> None:
560 """Generate attribute offset row of a trait vtable."""
561 emitter.emit_line(f"size_t {trait_offset_table_name}_scratch[] = {{")
562 for attr in trait.attributes:
563 emitter.emit_line(f"offsetof({cl.struct_name(emitter.names)}, {emitter.attr(attr)}),")
564 if not trait.attributes:
565 # This is for msvc.
566 emitter.emit_line("0")
567 emitter.emit_line("};")
568 emitter.emit_line(
569 "memcpy({name}, {name}_scratch, sizeof({name}));".format(name=trait_offset_table_name)
570 )
571
572
573def generate_vtable(

Callers 1

generate_vtablesFunction · 0.85

Calls 4

attrMethod · 0.80
emit_lineMethod · 0.45
struct_nameMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…