|
| 1 | +"""L1 body population: materialize `call` nodes from existing call sites. |
| 2 | +`callee` is left None here — the sanctioned null→id refinement happens at L2.""" |
| 3 | +from __future__ import annotations |
| 4 | +from codeanalyzer.schema.py_schema import PyApplication, PyClass, PyCallable, BodyNode, Span, byte_offsets |
| 5 | + |
| 6 | +def _do_callable(source: str, c: PyCallable) -> None: |
| 7 | + for cs in c.call_sites or []: |
| 8 | + key = f"{cs.start_line}:{cs.start_column}" |
| 9 | + span = Span(start=(cs.start_line, cs.start_column), |
| 10 | + end=(cs.end_line, cs.end_column), |
| 11 | + bytes=byte_offsets(source, cs.start_line, cs.start_column, cs.end_line, cs.end_column)) if source else None |
| 12 | + c.body[key] = BodyNode(kind="call", span=span, callee=None) |
| 13 | + for ic in (c.inner_callables or {}).values(): |
| 14 | + _do_callable(source, ic) |
| 15 | + for icl in (c.inner_classes or {}).values(): |
| 16 | + _do_class(source, icl) |
| 17 | + |
| 18 | +def _do_class(source: str, cl: PyClass) -> None: |
| 19 | + for m in (cl.methods or {}).values(): |
| 20 | + _do_callable(source, m) |
| 21 | + for ic in (cl.inner_classes or {}).values(): |
| 22 | + _do_class(source, ic) |
| 23 | + |
| 24 | +def populate_l1_body(app: PyApplication) -> None: |
| 25 | + for mod in app.symbol_table.values(): |
| 26 | + for fn in (mod.functions or {}).values(): |
| 27 | + _do_callable(mod.source, fn) |
| 28 | + for cl in (mod.classes or {}).values(): |
| 29 | + _do_class(mod.source, cl) |
0 commit comments