Skip to content

CombinedCallGraphNode

Bases: CallGraphNode

Class for combined call graph nodes.

A CombinedCallGraphNode represents a combined cycle of functions in the call graph.

Attributes:

Name Type Description
combines dict[NodeID, CallGraphNode]

A dictionary of all nodes that are combined into this node. This is later used for transferring the reasons of the combined node to the original nodes.

Source code in src/library_analyzer/processing/api/purity_analysis/model/_call_graph.py
@dataclass
class CombinedCallGraphNode(CallGraphNode):
    """Class for combined call graph nodes.

    A CombinedCallGraphNode represents a combined cycle of functions in the call graph.

    Attributes
    ----------
    combines :
        A dictionary of all nodes that are combined into this node.
        This is later used for transferring the reasons of the combined node to the original nodes.
    """

    combines: dict[NodeID, CallGraphNode] = field(default_factory=dict)

    def __hash__(self) -> int:
        return hash(str(self))

    def __str__(self) -> str:
        return f"{self.symbol.id}"

    def __repr__(self) -> str:
        return f"{self.symbol.name}: {id(self)}"

    def separate(self) -> dict[NodeID, CallGraphNode]:
        """Separate the node.

        After the purity of a combined node is inferred,
        the reasons of the combined node are transferred to the original nodes.

        Returns
        -------
        dict[NodeID, CallGraphNode]
            The original nodes with the transferred reasons.
        """
        original_nodes: dict[NodeID, CallGraphNode] = {}
        for node_id, node in self.combines.items():
            original_nodes[node_id] = node
            original_nodes[node_id].reasons.result = self.reasons.result

        return original_nodes

combines: dict[NodeID, CallGraphNode] = field(default_factory=dict) class-attribute instance-attribute

__hash__()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_call_graph.py
def __hash__(self) -> int:
    return hash(str(self))

__init__(symbol, reasons, children=dict(), combines=dict())

__repr__()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_call_graph.py
def __repr__(self) -> str:
    return f"{self.symbol.name}: {id(self)}"

__str__()

Source code in src/library_analyzer/processing/api/purity_analysis/model/_call_graph.py
def __str__(self) -> str:
    return f"{self.symbol.id}"

separate()

Separate the node.

After the purity of a combined node is inferred, the reasons of the combined node are transferred to the original nodes.

Returns:

Type Description
dict[NodeID, CallGraphNode]

The original nodes with the transferred reasons.

Source code in src/library_analyzer/processing/api/purity_analysis/model/_call_graph.py
def separate(self) -> dict[NodeID, CallGraphNode]:
    """Separate the node.

    After the purity of a combined node is inferred,
    the reasons of the combined node are transferred to the original nodes.

    Returns
    -------
    dict[NodeID, CallGraphNode]
        The original nodes with the transferred reasons.
    """
    original_nodes: dict[NodeID, CallGraphNode] = {}
    for node_id, node in self.combines.items():
        original_nodes[node_id] = node
        original_nodes[node_id].reasons.result = self.reasons.result

    return original_nodes