Skip to content

Commit

Permalink
Add new APIs to core.contract:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
montyly committed Jan 4, 2019
1 parent c8952db commit b549a3e
Showing 1 changed file with 68 additions and 6 deletions.
74 changes: 68 additions & 6 deletions slither/core/declarations/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ def enums(self):
def enums_as_dict(self):
return self._enums

@property
def modifiers(self):
'''
list(Modifier): List of the modifiers
'''
return list(self._modifiers.values())

def modifiers_as_dict(self):
return self._modifiers
Expand All @@ -113,6 +107,74 @@ def functions_inherited(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
def all_functions_called(self):
'''
Expand Down

0 comments on commit b549a3e

Please sign in to comment.