Add new APIs to core.contract:

- functions_inherited
- functions_not_inherited
- modifiers_inherited
- modifiers_not_inherited
- functions_and_modifiers_inherited
- functions_and_modifiers_not_inherited
- functions_entry_points
- get_functions_overridden_by
pull/122/head
Josselin 6 years ago
parent c8952db2ed
commit b549a3ed53
  1. 74
      slither/core/declarations/contract.py

@ -85,12 +85,6 @@ class Contract(ChildSlither, SourceMapping):
def enums_as_dict(self): def enums_as_dict(self):
return self._enums return self._enums
@property
def modifiers(self):
'''
list(Modifier): List of the modifiers
'''
return list(self._modifiers.values())
def modifiers_as_dict(self): def modifiers_as_dict(self):
return self._modifiers return self._modifiers
@ -113,6 +107,74 @@ class Contract(ChildSlither, SourceMapping):
''' '''
return [f for f in self.functions if f.contract != self] return [f for f in self.functions if f.contract != self]
@property
def functions_not_inherited(self):
'''
list(Function): List of the functions defined within the contract (not inherited)
'''
return [f for f in self.functions if f.contract == self]
@property
def functions_entry_points(self):
'''
list(Functions): List of public and external functions
'''
return [f for f in self.functions if f.visibility in ['public', 'external']]
@property
def modifiers(self):
'''
list(Modifier): List of the modifiers
'''
return list(self._modifiers.values())
@property
def modifiers_inherited(self):
'''
list(Modifier): List of the inherited modifiers
'''
return [m for m in self.modifiers if m.contract != self]
@property
def modifiers_not_inherited(self):
'''
list(Modifier): List of the modifiers defined within the contract (not inherited)
'''
return [m for m in self.modifiers if m.contract == self]
@property
def functions_and_modifiers(self):
'''
list(Function|Modifier): List of the functions and modifiers
'''
return self.functions + self.modifiers
@property
def functions_and_modifiers_inherited(self):
'''
list(Function|Modifier): List of the inherited functions and modifiers
'''
return self.functions_inherited + self.modifiers_inherited
@property
def functions_and_modifiers_not_inherited(self):
'''
list(Function|Modifier): List of the functions and modifiers defined within the contract (not inherited)
'''
return self.functions_not_inherited + self.modifiers_not_inherited
def get_functions_overridden_by(self, function):
'''
Return the list of functions overriden by the function
Args:
(core.Function)
Returns:
list(core.Function)
'''
candidates = self.functions_inherited
return [f for f in candidates if f.name == function]
@property @property
def all_functions_called(self): def all_functions_called(self):
''' '''

Loading…
Cancel
Save