Skip to content

Commit

Permalink
Merge pull request #162 from trailofbits/dev-inheritance
Browse files Browse the repository at this point in the history
Improve inheritance printers
  • Loading branch information
montyly committed Feb 5, 2019
2 parents 90c2b60 + 331868d commit 87f3be5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions slither/printers/inheritance/inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,26 @@ def output(self, filename):
if not self.contracts:
return

info += blue('Child_Contract -> ') + green('Base_Contracts')
info += blue('Child_Contract -> ') + green('Immediate_Base_Contracts')
info += green(' [Not_Immediate_Base_Contracts]')
for child in self.contracts:
info += blue(f'\n+ {child.name}')
if child.inheritance:
info += ' -> ' + green(", ".join(map(str, child.inheritance)))

info += green('\n\nBase_Contract -> ') + blue('Child_Contracts')
immediate = child.immediate_inheritance
not_immediate = [i for i in child.inheritance if i not in immediate]
info += ' -> ' + green(", ".join(map(str, immediate)))
if not_immediate:
info += ", ["+ green(", ".join(map(str, not_immediate))) + "]"

info += green('\n\nBase_Contract -> ') + blue('Immediate_Child_Contracts')
info += blue(' [Not_Immediate_Child_Contracts]')
for base in self.contracts:
info += green(f'\n+ {base.name}')
children = list(self._get_child_contracts(base))
if children:
info += ' -> ' + blue(", ".join(map(str, children)))
immediate = [child for child in children if base in child.immediate_inheritance]
not_immediate = [child for child in children if not child in immediate]
info += ' -> ' + blue(", ".join(map(str, immediate)))
if not_immediate:
info += ', [' + blue(", ".join(map(str, not_immediate))) + ']'
self.info(info)
2 changes: 1 addition & 1 deletion slither/printers/inheritance/inheritance_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _summary(self, contract):
"""
ret = ''
# Add arrows
for i in contract.inheritance:
for i in contract.immediate_inheritance:
ret += '%s -> %s;\n' % (contract.name, i)

# Functions
Expand Down

0 comments on commit 87f3be5

Please sign in to comment.