slither.core.declarations.structure
1from typing import List, TYPE_CHECKING, Dict, Optional 2 3from slither.core.source_mapping.source_mapping import SourceMapping 4 5if TYPE_CHECKING: 6 from slither.core.variables.structure_variable import StructureVariable 7 from slither.core.compilation_unit import SlitherCompilationUnit 8 9 10class Structure(SourceMapping): 11 def __init__(self, compilation_unit: "SlitherCompilationUnit") -> None: 12 super().__init__() 13 self._name: Optional[str] = None 14 self._canonical_name: Optional[str] = None 15 self._elems: Dict[str, "StructureVariable"] = {} 16 # Name of the elements in the order of declaration 17 self._elems_ordered: List[str] = [] 18 self.compilation_unit = compilation_unit 19 20 @property 21 def canonical_name(self) -> str: 22 assert self._canonical_name 23 return self._canonical_name 24 25 @canonical_name.setter 26 def canonical_name(self, name: str) -> None: 27 self._canonical_name = name 28 29 @property 30 def name(self) -> str: 31 assert self._name 32 return self._name 33 34 @name.setter 35 def name(self, new_name: str) -> None: 36 self._name = new_name 37 38 @property 39 def elems(self) -> Dict[str, "StructureVariable"]: 40 return self._elems 41 42 def add_elem_in_order(self, s: str) -> None: 43 self._elems_ordered.append(s) 44 45 @property 46 def elems_ordered(self) -> List["StructureVariable"]: 47 ret = [] 48 for e in self._elems_ordered: 49 ret.append(self._elems[e]) 50 return ret 51 52 def __str__(self) -> str: 53 return self.name 54 55 def __eq__(self, other) -> bool: 56 if not isinstance(other, Structure): 57 return False 58 if len(self.elems) != len(other.elems): 59 return False 60 for idx, elem in enumerate(self.elems_ordered): 61 other_elem = other.elems_ordered[idx] 62 if str(other_elem.type) != str(elem.type) or other_elem.name != elem.name: 63 return False 64 return self.name == other.name 65 66 def __hash__(self): 67 return hash(self.name)
11class Structure(SourceMapping): 12 def __init__(self, compilation_unit: "SlitherCompilationUnit") -> None: 13 super().__init__() 14 self._name: Optional[str] = None 15 self._canonical_name: Optional[str] = None 16 self._elems: Dict[str, "StructureVariable"] = {} 17 # Name of the elements in the order of declaration 18 self._elems_ordered: List[str] = [] 19 self.compilation_unit = compilation_unit 20 21 @property 22 def canonical_name(self) -> str: 23 assert self._canonical_name 24 return self._canonical_name 25 26 @canonical_name.setter 27 def canonical_name(self, name: str) -> None: 28 self._canonical_name = name 29 30 @property 31 def name(self) -> str: 32 assert self._name 33 return self._name 34 35 @name.setter 36 def name(self, new_name: str) -> None: 37 self._name = new_name 38 39 @property 40 def elems(self) -> Dict[str, "StructureVariable"]: 41 return self._elems 42 43 def add_elem_in_order(self, s: str) -> None: 44 self._elems_ordered.append(s) 45 46 @property 47 def elems_ordered(self) -> List["StructureVariable"]: 48 ret = [] 49 for e in self._elems_ordered: 50 ret.append(self._elems[e]) 51 return ret 52 53 def __str__(self) -> str: 54 return self.name 55 56 def __eq__(self, other) -> bool: 57 if not isinstance(other, Structure): 58 return False 59 if len(self.elems) != len(other.elems): 60 return False 61 for idx, elem in enumerate(self.elems_ordered): 62 other_elem = other.elems_ordered[idx] 63 if str(other_elem.type) != str(elem.type) or other_elem.name != elem.name: 64 return False 65 return self.name == other.name 66 67 def __hash__(self): 68 return hash(self.name)
Structure( compilation_unit: slither.core.compilation_unit.SlitherCompilationUnit)
12 def __init__(self, compilation_unit: "SlitherCompilationUnit") -> None: 13 super().__init__() 14 self._name: Optional[str] = None 15 self._canonical_name: Optional[str] = None 16 self._elems: Dict[str, "StructureVariable"] = {} 17 # Name of the elements in the order of declaration 18 self._elems_ordered: List[str] = [] 19 self.compilation_unit = compilation_unit
elems: dict[str, slither.core.variables.structure_variable.StructureVariable]
elems_ordered: list[slither.core.variables.structure_variable.StructureVariable]