From 95e94beb322d4929b8e15f0dd26f35aa0d0f674a Mon Sep 17 00:00:00 2001 From: Josselin Date: Thu, 8 Nov 2018 16:09:03 +0100 Subject: [PATCH] Import contract summary printer --- slither/core/declarations/function.py | 6 ++--- slither/printers/summary/contract.py | 35 ++++++++++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/slither/core/declarations/function.py b/slither/core/declarations/function.py index a16438f48..cdc90048e 100644 --- a/slither/core/declarations/function.py +++ b/slither/core/declarations/function.py @@ -616,10 +616,10 @@ class Function(ChildContract, SourceMapping): """ Return the function summary Returns: - (str, str, list(str), list(str), listr(str), list(str), list(str); - name, visibility, modifiers, vars read, vars written, internal_calls, external_calls_as_expressions + (str, str, str, list(str), list(str), listr(str), list(str), list(str); + contract_name, name, visibility, modifiers, vars read, vars written, internal_calls, external_calls_as_expressions """ - return (self.name, self.visibility, + return (self.contract.name, self.full_name, self.visibility, [str(x) for x in self.modifiers], [str(x) for x in self.state_variables_read + self.solidity_variables_read], [str(x) for x in self.state_variables_written], diff --git a/slither/printers/summary/contract.py b/slither/printers/summary/contract.py index 51409ce91..0456eb221 100644 --- a/slither/printers/summary/contract.py +++ b/slither/printers/summary/contract.py @@ -1,7 +1,7 @@ """ Module printing summary of the contract """ - +import collections from slither.printers.abstract_printer import AbstractPrinter from slither.utils.colors import blue, green, magenta @@ -21,12 +21,29 @@ class ContractSummary(AbstractPrinter): for c in self.contracts: (name, _inheritance, _var, func_summaries, _modif_summaries) = c.get_summary() txt += blue("\n+ Contract %s\n"%name) - for (f_name, visi, _, _, _, _, _) in func_summaries: - txt += " - " - if visi in ['external', 'public']: - txt += green("%s (%s)\n"%(f_name, visi)) - elif visi in ['internal', 'private']: - txt += magenta("%s (%s)\n"%(f_name, visi)) - else: - txt += "%s (%s)\n"%(f_name, visi) + # (c_name, f_name, visi, _, _, _, _, _) in func_summaries + public = [(elem[0], (elem[1], elem[2]) ) for elem in func_summaries] +# private = [(elem[0], (elem[1], elem[2])) for elem in func_summaries if elem[2] in ['internal', 'private']] + # should never happen + # other = [(elem[0], (elem[1], elem[2])) for elem in func_summaries if elem[2] not in ['external', 'public', 'internal', 'private']] + # assert not other + + collect = collections.defaultdict(list) + for a,b in public: + collect[a].append(b) + public = list(collect.items()) + + for contract, functions in public: + txt += blue(" - From {}\n".format(contract)) + functions = sorted(functions) + for (function, visi) in functions: + if visi in ['external', 'public']: + txt += green(" - {} ({})\n".format(function, visi)) + for (function, visi) in functions: + if visi in ['internal', 'private']: + txt += magenta(" - {} ({})\n".format(function, visi)) + for (function, visi) in functions: + if visi not in ['external', 'public', 'internal', 'private']: + txt += " - {}  ({})\n".format(function, visi) + self.info(txt)