35 lines
1.8 KiB
Python
35 lines
1.8 KiB
Python
"""Reviewed native component module exports and their compilation dependencies."""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
EXPORTS = {
|
|
"properties": frozenset({
|
|
"native_properties_init", "native_temperature_ph_context", "native_density_context",
|
|
"native_gas_init", "native_gas", "native_gas_context", "native_medium_init",
|
|
"native_density", "native_temperature_ph", "native_viscosity",
|
|
"native_medium_gas", "native_medium_gas_context", "native_polytropic_gas_context",
|
|
}),
|
|
"orifice": frozenset({"native_orifice", "native_orifice_context", "native_medium_orifice", "native_medium_orifice_context"}),
|
|
"pipe": frozenset({"native_pipe_resistance", "native_pipe_flow", "native_pipe_flow_context",
|
|
"native_pipe_flow_cached", "native_pipe_flow_cached_context",
|
|
"native_pipe_diagnostics", "native_pipe_diagnostics_context"}),
|
|
"mechanics": frozenset({"native_contact", "native_stop_motion", "native_limit_force", "native_dry_friction"}),
|
|
"signal": frozenset({"native_signal", "native_signal_break"}),
|
|
}
|
|
DEPENDENCIES = {"orifice": ("properties",), "pipe": ("properties",)}
|
|
|
|
|
|
def component_modules(source: str) -> tuple[str, ...]:
|
|
# Generated C refers to these functions directly. Include identifier uses
|
|
# (also function pointers), conservatively including any comments/strings.
|
|
identifiers = set(re.findall(r"\bnative_[A-Za-z0-9_]+\b", source))
|
|
selected = {name for name, exports in EXPORTS.items() if identifiers & exports}
|
|
pending = list(selected)
|
|
while pending:
|
|
for dependency in DEPENDENCIES.get(pending.pop(), ()):
|
|
if dependency not in selected:
|
|
selected.add(dependency)
|
|
pending.append(dependency)
|
|
return tuple(name for name in EXPORTS if name in selected)
|