Add referenced declaration for functions (AST compact pnly) (temporary fix for 177)

pull/194/head
Josselin 6 years ago
parent 7e75f7de11
commit 976239a996
  1. 12
      slither/solc_parsing/declarations/function.py
  2. 4
      slither/solc_parsing/expressions/expression_parsing.py

@ -37,8 +37,13 @@ class FunctionSolc(Function):
def __init__(self, function, contract):
super(FunctionSolc, self).__init__()
self._contract = contract
# Only present if compact AST
self._referenced_declaration = None
if self.is_compact_ast:
self._name = function['name']
if 'id' in function:
self._referenced_declaration = function['id']
else:
self._name = function['attributes'][self.get_key()]
self._functionNotParsed = function
@ -73,6 +78,13 @@ class FunctionSolc(Function):
def is_compact_ast(self):
return self.slither.is_compact_ast
@property
def referenced_declaration(self):
'''
Return the compact AST referenced declaration id (None for legacy AST)
'''
return self._referenced_declaration
# endregion
###################################################################################
###################################################################################

@ -70,6 +70,7 @@ def get_pointer_name(variable):
def find_variable(var_name, caller_context, referenced_declaration=None):
if isinstance(caller_context, Contract):
function = None
contract = caller_context
@ -153,6 +154,9 @@ def find_variable(var_name, caller_context, referenced_declaration=None):
for contract in contract.slither.contracts:
if contract.id == referenced_declaration:
return contract
for function in contract.slither.functions:
if function.referenced_declaration == referenced_declaration:
return function
raise VariableNotFound('Variable not found: {}'.format(var_name))

Loading…
Cancel
Save