Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate source location for using_for construct #1

Merged
merged 4 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions slither/core/declarations/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from slither.slithir.variables.variable import SlithIRVariable
from slither.core.variables.variable import Variable
from slither.core.variables.state_variable import StateVariable
from slither.core.declarations.structure import Structure
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.core.declarations.custom_error_contract import CustomErrorContract
from slither.core.scope.scope import FileScope
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(self, compilation_unit: "SlitherCompilationUnit", scope: "FileScope

# The only str is "*"
self._using_for: Dict[Union[str, Type], List[str]] = {}
self._using_for_src: Dict[Union[str, Type], List[Tuple[str, "Structure"]]] = {}
self._kind: Optional[str] = None
self._is_interface: bool = False

Expand Down Expand Up @@ -246,6 +248,10 @@ def events_as_dict(self) -> Dict[str, "Event"]:
def using_for(self) -> Dict[Union[str, Type], List[str]]:
return self._using_for

@property
def using_for_src(self) -> Dict[Union[str, Type], List[Tuple[str, "Structure"]]]:
return self._using_for_src

# endregion
###################################################################################
###################################################################################
Expand Down
10 changes: 9 additions & 1 deletion slither/solc_parsing/declarations/contract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import List, Dict, Callable, TYPE_CHECKING, Union, Set

from slither.core.declarations import Modifier, Event, EnumContract, StructureContract, Function
from slither.core.declarations import Modifier, Event, EnumContract, StructureContract, Function, Structure
from slither.core.declarations.contract import Contract
from slither.core.declarations.custom_error_contract import CustomErrorContract
from slither.core.declarations.function_contract import FunctionContract
Expand Down Expand Up @@ -559,7 +559,15 @@ def analyze_using_for(self):
type_name = "*"
if type_name not in self._contract.using_for:
self._contract.using_for[type_name] = []
self._contract.using_for_src[type_name] = []
# This is to populate the source location of using_for construct
# We reuse the Structure class to store the source location instead
# of creating a new class `UsingFor` for simplicity
uf = Structure(self._contract.compilation_unit)
runmingl marked this conversation as resolved.
Show resolved Hide resolved
uf.set_offset(using_for["src"], self._contract.compilation_unit)
uf.canonical_name = uf.name = f"using {lib_name} for {type_name} in {self._contract}"
self._contract.using_for[type_name].append(lib_name)
self._contract.using_for_src[type_name].append((lib_name, uf))
else:
for using_for in self._usingForNotParsed:
children = using_for[self.get_children()]
Expand Down