From 976239a9963f9ab0a7eef41656a3625f04fac2f6 Mon Sep 17 00:00:00 2001 From: Josselin Date: Fri, 22 Feb 2019 13:14:08 +0000 Subject: [PATCH] Add referenced declaration for functions (AST compact pnly) (temporary fix for 177) --- slither/solc_parsing/declarations/function.py | 12 ++++++++++++ .../solc_parsing/expressions/expression_parsing.py | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/slither/solc_parsing/declarations/function.py b/slither/solc_parsing/declarations/function.py index 45f90a72f..6b95ca9f9 100644 --- a/slither/solc_parsing/declarations/function.py +++ b/slither/solc_parsing/declarations/function.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 ################################################################################### ################################################################################### diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py index 592b7c5b8..12d53f4e0 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -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))