Fix missing return cariage in printers

pull/373/head
Josselin 5 years ago
parent 28d9981726
commit 0ef908e4f5
  1. 10
      slither/core/declarations/function.py
  2. 4
      slither/printers/call/call_graph.py
  3. 5
      slither/printers/functions/cfg.py
  4. 19
      slither/printers/inheritance/inheritance.py
  5. 2
      slither/printers/inheritance/inheritance_graph.py
  6. 14
      slither/printers/summary/constructor_calls.py
  7. 24
      slither/printers/summary/slithir.py
  8. 20
      slither/printers/summary/slithir_ssa.py

@ -1028,19 +1028,21 @@ class Function(ChildContract, ChildInheritance, SourceMapping):
filename (str)
"""
from slither.core.cfg.node import NodeType
content = ''
with open(filename, 'w', encoding='utf8') as f:
f.write('digraph{\n')
content += 'digraph{\n'
for node in self.nodes:
label = 'Node Type: {} {}\n'.format(NodeType.str(node.type), node.node_id)
if node.expression:
label += '\nEXPRESSION:\n{}\n'.format(node.expression)
if node.irs:
label += '\nIRs:\n' + '\n'.join([str(ir) for ir in node.irs])
f.write('{}[label="{}"];\n'.format(node.node_id, label))
content += '{}[label="{}"];\n'.format(node.node_id, label)
for son in node.sons:
f.write('{}->{};\n'.format(node.node_id, son.node_id))
content += '{}->{};\n'.format(node.node_id, son.node_id)
f.write("}\n")
content += "}\n"
return content
def dominator_tree_to_dot(self, filename):
"""

@ -163,14 +163,14 @@ class PrinterCallGraph(AbstractPrinter):
info = ''
results = []
with open(filename, 'w', encoding='utf8') as f:
info += f'Call Graph: {filename}'
info += f'Call Graph: {filename}\n'
content = '\n'.join(['strict digraph {'] + [self._process_functions(self.slither.functions)] + ['}'])
f.write(content)
results.append((filename, content))
for derived_contract in self.slither.contracts_derived:
with open(f'{derived_contract.name}.dot', 'w', encoding='utf8') as f:
info += f'Call Graph: {derived_contract.name}.dot'
info += f'Call Graph: {derived_contract.name}.dot\n'
content = '\n'.join(['strict digraph {'] + [self._process_functions(derived_contract.functions)] + ['}'])
f.write(content)
results.append((filename, content))

@ -22,8 +22,11 @@ class CFG(AbstractPrinter):
all_files = []
for contract in self.contracts:
for function in contract.functions + contract.modifiers:
if original_filename:
filename = "{}-{}-{}.dot".format(original_filename, contract.name, function.full_name)
info += 'Export {}'.format(filename)
else:
filename = "{}-{}.dot".format(contract.name, function.full_name)
info += 'Export {}\n'.format(filename)
content = function.slithir_cfg_to_dot(filename)
with open(filename, 'w', encoding='utf8') as f:
f.write(content)

@ -36,11 +36,10 @@ class PrinterInheritance(AbstractPrinter):
info += blue('Child_Contract -> ') + green('Immediate_Base_Contracts')
info += green(' [Not_Immediate_Base_Contracts]')
result = {}
result['child_to_base'] = {}
result = {'child_to_base': {}}
for child in self.contracts:
info += blue(f'\n+ {child.name}')
info += blue(f'\n+ {child.name}\n')
result['child_to_base'][child.name] = {'immediate': [],
'not_immediate': []}
if child.inheritance:
@ -48,18 +47,18 @@ class PrinterInheritance(AbstractPrinter):
immediate = child.immediate_inheritance
not_immediate = [i for i in child.inheritance if i not in immediate]
info += ' -> ' + green(", ".join(map(str, immediate)))
info += ' -> ' + green(", ".join(map(str, immediate))) + '\n'
result['child_to_base'][child.name]['immediate'] = list(map(str, immediate))
if not_immediate:
info += ", ["+ green(", ".join(map(str, not_immediate))) + "]"
info += ", ["+ green(", ".join(map(str, not_immediate))) + "]\n"
result['child_to_base'][child.name]['not_immediate'] = list(map(str, not_immediate))
info += green('\n\nBase_Contract -> ') + blue('Immediate_Child_Contracts')
info += blue(' [Not_Immediate_Child_Contracts]')
info += green('\n\nBase_Contract -> ') + blue('Immediate_Child_Contracts') + '\n'
info += blue(' [Not_Immediate_Child_Contracts]') + '\n'
result['base_to_child'] = {}
for base in self.contracts:
info += green(f'\n+ {base.name}')
info += green(f'\n+ {base.name}') + '\n'
children = list(self._get_child_contracts(base))
result['base_to_child'][base.name] = {'immediate': [],
@ -68,10 +67,10 @@ class PrinterInheritance(AbstractPrinter):
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)))
info += ' -> ' + blue(", ".join(map(str, immediate))) + '\n'
result['base_to_child'][base.name]['immediate'] = list(map(str, immediate))
if not_immediate:
info += ', [' + blue(", ".join(map(str, not_immediate))) + ']'
info += ', [' + blue(", ".join(map(str, not_immediate))) + ']' + '\n'
result['base_to_child'][base.name]['not_immediate'] = list(map(str, immediate))
self.info(info)

@ -161,7 +161,7 @@ class PrinterInheritanceGraph(AbstractPrinter):
filename = 'contracts.dot'
if not filename.endswith('.dot'):
filename += ".dot"
info = 'Inheritance Graph: ' + filename
info = 'Inheritance Graph: ' + filename + '\n'
self.info(info)
content = 'digraph "" {\n'

@ -23,8 +23,8 @@ class ConstructorPrinter(AbstractPrinter):
for contract in self.contracts:
stack_name = []
stack_definition = []
info += "\n\nContact Name: " + contract.name
info += " Constructor Call Sequence: "
info += "\n\nContact Name: " + contract.name + '\n'
info += " Constructor Call Sequence: " + '\n'
cst = contract.constructors_declared
if cst:
stack_name.append(contract.name)
@ -35,16 +35,16 @@ class ConstructorPrinter(AbstractPrinter):
stack_name.append(inherited_contract.name)
stack_definition.append(self._get_soruce_code(cst))
if len(stack_name) > 0:
info += " " + ' '.join(stack_name[len(stack_name) - 1])
info += " " + ' '.join(stack_name[len(stack_name) - 1]) + '\n'
count = len(stack_name) - 2
while count >= 0:
info += "-->" + ' '.join(stack_name[count])
info += "-->" + ' '.join(stack_name[count]) + '\n'
count = count - 1
info += "\n Constructor Definitions:"
info += "\n Constructor Definitions:" + '\n'
count = len(stack_definition) - 1
while count >= 0:
info += "\n Contract name:" + str(stack_name[count])
info += "\n" + str(stack_definition[count])
info += "\n Contract name:" + str(stack_name[count]) + '\n'
info += "\n" + str(stack_definition[count]) + '\n'
count = count - 1
self.info(info)

@ -22,30 +22,30 @@ class PrinterSlithIR(AbstractPrinter):
for contract in self.contracts:
txt += 'Contract {}'.format(contract.name)
for function in contract.functions:
txt += f'\tFunction {function.canonical_name} {"" if function.is_shadowed else "(*)"}'
txt += f'\tFunction {function.canonical_name} {"" if function.is_shadowed else "(*)"}\n'
for node in function.nodes:
if node.expression:
txt += '\t\tExpression: {}'.format(node.expression)
txt += '\t\tIRs:'
txt += '\t\tExpression: {}\n'.format(node.expression)
txt += '\t\tIRs:\n'
for ir in node.irs:
txt += '\t\t\t{}'.format(ir)
txt += '\t\t\t{}\n'.format(ir)
elif node.irs:
txt += '\t\tIRs:'
txt += '\t\tIRs:\n'
for ir in node.irs:
txt += '\t\t\t{}'.format(ir)
txt += '\t\t\t{}\n'.format(ir)
for modifier_statement in function.modifiers_statements:
txt += f'\t\tModifier Call {modifier_statement.entry_point.expression}'
txt += f'\t\tModifier Call {modifier_statement.entry_point.expression}\n'
for modifier_statement in function.explicit_base_constructor_calls_statements:
txt += f'\t\tConstructor Call {modifier_statement.entry_point.expression}'
txt += f'\t\tConstructor Call {modifier_statement.entry_point.expression}\n'
for modifier in contract.modifiers:
txt += '\tModifier {}'.format(modifier.canonical_name)
txt += '\tModifier {}\n'.format(modifier.canonical_name)
for node in modifier.nodes:
txt += str(node)
if node.expression:
txt += '\t\tExpression: {}'.format(node.expression)
txt += '\t\tIRs:'
txt += '\t\tExpression: {}\n'.format(node.expression)
txt += '\t\tIRs:\n'
for ir in node.irs:
txt += '\t\t\t{}'.format(ir)
txt += '\t\t\t{}\n'.format(ir)
self.info(txt)
res = self.generate_output(txt)
return res

@ -21,26 +21,26 @@ class PrinterSlithIRSSA(AbstractPrinter):
txt = ""
for contract in self.contracts:
txt += 'Contract {}'.format(contract.name)
txt += 'Contract {}'.format(contract.name) + '\n'
for function in contract.functions:
txt += '\tFunction {}'.format(function.canonical_name)
txt += '\tFunction {}'.format(function.canonical_name) + '\n'
for node in function.nodes:
if node.expression:
txt += '\t\tExpression: {}'.format(node.expression)
txt += '\t\tExpression: {}'.format(node.expression) + '\n'
if node.irs_ssa:
txt += '\t\tIRs:'
txt += '\t\tIRs:' + '\n'
for ir in node.irs_ssa:
txt += '\t\t\t{}'.format(ir)
txt += '\t\t\t{}'.format(ir) + '\n'
for modifier in contract.modifiers:
txt += '\tModifier {}'.format(modifier.canonical_name)
txt += '\tModifier {}'.format(modifier.canonical_name) + '\n'
for node in modifier.nodes:
txt += str(node)
txt += str(node) + '\n'
if node.expression:
txt += '\t\tExpression: {}'.format(node.expression)
txt += '\t\tExpression: {}'.format(node.expression) + '\n'
if node.irs_ssa:
txt += '\t\tIRs:'
txt += '\t\tIRs:' + '\n'
for ir in node.irs_ssa:
txt += '\t\t\t{}'.format(ir)
txt += '\t\t\t{}'.format(ir) + '\n'
self.info(txt)
res = self.generate_output(txt)
return res

Loading…
Cancel
Save