Skip to content

Commit

Permalink
🩹 C3 printer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Dec 24, 2023
1 parent 0248709 commit 446c85a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions wake_printers/c3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ def print(self) -> None:
pass

def visit_contract_definition(self, node: ir.ContractDefinition) -> None:
print(f"[italic]C3 linearization ordered[/italic]")
tree = Tree(".")

# Using Rich Tree strcutrue to print the C3 linearization
def add_contract_to_tree(parent_node, n, index):
contract_name = n.canonical_name
if not self._interfaces and contract_name.startswith("I"):
return

contract_node = parent_node.add(
f"{index:2d}.[bold][link={self.generate_link(n)}]{contract_name}[/link][/bold]"
Expand Down Expand Up @@ -64,12 +61,18 @@ def add_contract_to_tree(parent_node, n, index):
# Counter for more readable output
counter = 1
for n in node.linearized_base_contracts:
if not self._interfaces and n.kind == ir.enums.ContractKind.INTERFACE:
continue

add_contract_to_tree(tree, n, counter)
counter += (
1 if self._interfaces or not n.canonical_name.startswith("I") else 0
)
counter += 1

print(tree)
if counter > 1:
print(
f"[italic][link={self.generate_link(node)}]{node.name}[/link] C3 linearization ordered[/italic]"
)
print(tree)
print()

@printer.command(name="c3")
@click.option(
Expand Down

0 comments on commit 446c85a

Please sign in to comment.