API add: contract.state_variables_ordered: keep variables declaration order + shadowed variables

Update variable order printer to use state_variables_ordered
Fix #250
pull/254/head
Josselin 6 years ago
parent c81c32d31c
commit 29e8a3a905
  1. 8
      slither/core/declarations/contract.py
  2. 4
      slither/printers/summary/variable_order.py
  3. 2
      slither/solc_parsing/declarations/contract.py

@ -33,6 +33,7 @@ class Contract(ChildSlither, SourceMapping):
self._structures = {}
self._events = {}
self._variables = {}
self._variables_ordered = [] # contain also shadowed variables
self._modifiers = {}
self._functions = {}
@ -196,6 +197,13 @@ class Contract(ChildSlither, SourceMapping):
'''
return list(self._variables.values())
@property
def state_variables_ordered(self):
'''
list(StateVariable): List of the state variables by order of declaration. Contains also shadowed variables
'''
return list(self._variables_ordered)
@property
def state_variables_inherited(self):
'''

@ -23,9 +23,9 @@ class VariableOrder(AbstractPrinter):
for contract in self.slither.contracts_derived:
txt += '\n{}:\n'.format(contract.name)
table = PrettyTable(['Name', 'Type'])
for variable in contract.state_variables:
for variable in contract.state_variables_ordered:
if not variable.is_constant:
table.add_row([variable.name, str(variable.type)])
table.add_row([variable.canonical_name, str(variable.type)])
txt += str(table) + '\n'
self.info(txt)

@ -222,6 +222,7 @@ class ContractSolc04(Contract):
def parse_state_variables(self):
for father in self.inheritance_reverse:
self._variables.update(father.variables_as_dict())
self._variables_ordered += father.state_variables_ordered
for varNotParsed in self._variablesNotParsed:
var = StateVariableSolc(varNotParsed)
@ -229,6 +230,7 @@ class ContractSolc04(Contract):
var.set_contract(self)
self._variables[var.name] = var
self._variables_ordered.append(var)
def _parse_modifier(self, modifier):

Loading…
Cancel
Save