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

Remove core.children #1673

Merged
merged 2 commits into from
Mar 22, 2023
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
11 changes: 9 additions & 2 deletions slither/core/cfg/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Optional, List, Set, Dict, Tuple, Union, TYPE_CHECKING

from slither.all_exceptions import SlitherException
from slither.core.children.child_function import ChildFunction
from slither.core.declarations import Contract, Function
from slither.core.declarations.solidity_variables import (
SolidityVariable,
Expand Down Expand Up @@ -106,7 +105,7 @@ class NodeType(Enum):

# I am not sure why, but pylint reports a lot of "no-member" issue that are not real (Josselin)
# pylint: disable=no-member
class Node(SourceMapping, ChildFunction): # pylint: disable=too-many-public-methods
class Node(SourceMapping): # pylint: disable=too-many-public-methods
"""
Node class
Expand Down Expand Up @@ -189,6 +188,7 @@ def __init__(

self.scope: Union["Scope", "Function"] = scope
self.file_scope: "FileScope" = file_scope
self._function: Optional["Function"] = None

###################################################################################
###################################################################################
Expand Down Expand Up @@ -224,6 +224,13 @@ def will_return(self) -> bool:
return True
return False

def set_function(self, function: "Function") -> None:
self._function = function

@property
def function(self) -> "Function":
return self._function

# endregion
###################################################################################
###################################################################################
Expand Down
17 changes: 0 additions & 17 deletions slither/core/children/child_event.py

This file was deleted.

18 changes: 0 additions & 18 deletions slither/core/children/child_expression.py

This file was deleted.

17 changes: 0 additions & 17 deletions slither/core/children/child_function.py

This file was deleted.

17 changes: 0 additions & 17 deletions slither/core/children/child_inheritance.py

This file was deleted.

31 changes: 0 additions & 31 deletions slither/core/children/child_node.py

This file was deleted.

17 changes: 0 additions & 17 deletions slither/core/children/child_structure.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

from slither.core.source_mapping.source_mapping import SourceMapping

if TYPE_CHECKING:
from slither.core.declarations import Contract


class ChildContract(SourceMapping):
class ContractLevel(SourceMapping):
"""
This class is used to represent objects that are at the contract level
The opposite is TopLevel
"""

def __init__(self) -> None:
super().__init__()
self._contract = None
self._contract: Optional["Contract"] = None

def set_contract(self, contract: "Contract") -> None:
self._contract = contract

@property
def contract(self) -> "Contract":
assert self._contract
return self._contract
4 changes: 2 additions & 2 deletions slither/core/declarations/custom_error_contract.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from slither.core.children.child_contract import ChildContract
from slither.core.declarations.contract_level import ContractLevel
from slither.core.declarations.custom_error import CustomError


class CustomErrorContract(CustomError, ChildContract):
class CustomErrorContract(CustomError, ContractLevel):
def is_declared_by(self, contract):
"""
Check if the element is declared by the contract
Expand Down
4 changes: 2 additions & 2 deletions slither/core/declarations/enum_contract.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import TYPE_CHECKING

from slither.core.children.child_contract import ChildContract
from slither.core.declarations.contract_level import ContractLevel
from slither.core.declarations import Enum

if TYPE_CHECKING:
from slither.core.declarations import Contract


class EnumContract(Enum, ChildContract):
class EnumContract(Enum, ContractLevel):
def is_declared_by(self, contract: "Contract") -> bool:
"""
Check if the element is declared by the contract
Expand Down
4 changes: 2 additions & 2 deletions slither/core/declarations/event.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import List, Tuple, TYPE_CHECKING

from slither.core.children.child_contract import ChildContract
from slither.core.declarations.contract_level import ContractLevel
from slither.core.source_mapping.source_mapping import SourceMapping
from slither.core.variables.event_variable import EventVariable

if TYPE_CHECKING:
from slither.core.declarations import Contract


class Event(ChildContract, SourceMapping):
class Event(ContractLevel, SourceMapping):
def __init__(self) -> None:
super().__init__()
self._name = None
Expand Down
29 changes: 25 additions & 4 deletions slither/core/declarations/function_contract.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""
Function module
"""
from typing import Dict, TYPE_CHECKING, List, Tuple
from typing import Dict, TYPE_CHECKING, List, Tuple, Optional

from slither.core.children.child_contract import ChildContract
from slither.core.children.child_inheritance import ChildInheritance
from slither.core.declarations.contract_level import ContractLevel
from slither.core.declarations import Function


Expand All @@ -14,9 +13,31 @@
from slither.core.declarations import Contract
from slither.core.scope.scope import FileScope
from slither.slithir.variables.state_variable import StateIRVariable
from slither.core.compilation_unit import SlitherCompilationUnit


class FunctionContract(Function, ChildContract, ChildInheritance):
class FunctionContract(Function, ContractLevel):
def __init__(self, compilation_unit: "SlitherCompilationUnit") -> None:
super().__init__(compilation_unit)
self._contract_declarer: Optional["Contract"] = None

def set_contract_declarer(self, contract: "Contract") -> None:
self._contract_declarer = contract

@property
def contract_declarer(self) -> "Contract":
"""
Return the contract where this function was declared. Only functions have both a contract, and contract_declarer
This is because we need to have separate representation of the function depending of the contract's context
For example a function calling super.f() will generate different IR depending on the current contract's inheritance
Returns:
The contract where this function was declared
"""

assert self._contract_declarer
return self._contract_declarer

@property
def canonical_name(self) -> str:
"""
Expand Down
4 changes: 2 additions & 2 deletions slither/core/declarations/structure_contract.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from slither.core.children.child_contract import ChildContract
from slither.core.declarations.contract_level import ContractLevel
from slither.core.declarations import Structure


class StructureContract(Structure, ChildContract):
class StructureContract(Structure, ContractLevel):
def is_declared_by(self, contract):
"""
Check if the element is declared by the contract
Expand Down
6 changes: 5 additions & 1 deletion slither/core/declarations/top_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@


class TopLevel(SourceMapping):
pass
"""
This class is used to represent objects that are at the top level
The opposite is ContractLevel
"""
6 changes: 3 additions & 3 deletions slither/core/slither_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from crytic_compile import CryticCompile
from crytic_compile.utils.naming import Filename

from slither.core.children.child_contract import ChildContract
from slither.core.declarations.contract_level import ContractLevel
from slither.core.compilation_unit import SlitherCompilationUnit
from slither.core.context.context import Context
from slither.core.declarations import Contract, FunctionContract
Expand Down Expand Up @@ -206,7 +206,7 @@ def _compute_offsets_from_thing(self, thing: SourceMapping):
isinstance(thing, FunctionContract)
and thing.contract_declarer == thing.contract
)
or (isinstance(thing, ChildContract) and not isinstance(thing, FunctionContract))
or (isinstance(thing, ContractLevel) and not isinstance(thing, FunctionContract))
):
self._offset_to_objects[definition.filename][offset].add(thing)

Expand All @@ -224,7 +224,7 @@ def _compute_offsets_from_thing(self, thing: SourceMapping):
and thing.contract_declarer == thing.contract
)
or (
isinstance(thing, ChildContract) and not isinstance(thing, FunctionContract)
isinstance(thing, ContractLevel) and not isinstance(thing, FunctionContract)
)
):
self._offset_to_objects[definition.filename][offset].add(thing)
Expand Down
4 changes: 2 additions & 2 deletions slither/core/solidity_types/type_alias.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING, Tuple

from slither.core.children.child_contract import ChildContract
from slither.core.declarations.contract_level import ContractLevel
from slither.core.declarations.top_level import TopLevel
from slither.core.solidity_types import Type, ElementaryType

Expand Down Expand Up @@ -48,7 +48,7 @@ def __str__(self) -> str:
return self.name


class TypeAliasContract(TypeAlias, ChildContract):
class TypeAliasContract(TypeAlias, ContractLevel):
def __init__(self, underlying_type: Type, name: str, contract: "Contract") -> None:
super().__init__(underlying_type, name)
self._contract: "Contract" = contract
Expand Down
5 changes: 2 additions & 3 deletions slither/core/variables/event_variable.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from slither.core.variables.variable import Variable
from slither.core.children.child_event import ChildEvent


class EventVariable(ChildEvent, Variable):
class EventVariable(Variable):
def __init__(self) -> None:
super().__init__()
self._indexed = False
Expand All @@ -16,5 +15,5 @@ def indexed(self) -> bool:
return self._indexed

@indexed.setter
def indexed(self, is_indexed: bool):
def indexed(self, is_indexed: bool) -> None:
self._indexed = is_indexed
17 changes: 14 additions & 3 deletions slither/core/variables/local_variable.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
from typing import Optional
from typing import Optional, TYPE_CHECKING

from slither.core.variables.variable import Variable
from slither.core.children.child_function import ChildFunction
from slither.core.solidity_types.user_defined_type import UserDefinedType
from slither.core.solidity_types.array_type import ArrayType
from slither.core.solidity_types.mapping_type import MappingType
from slither.core.solidity_types.elementary_type import ElementaryType

from slither.core.declarations.structure import Structure

if TYPE_CHECKING: # type: ignore
from slither.core.declarations import Function

class LocalVariable(ChildFunction, Variable):

class LocalVariable(Variable):
def __init__(self) -> None:
super().__init__()
self._location: Optional[str] = None
self._function: Optional["Function"] = None

def set_function(self, function: "Function") -> None:
self._function = function

@property
def function(self) -> "Function":
assert self._function
return self._function

def set_location(self, loc: str) -> None:
self._location = loc
Expand Down
Loading