slither.solc_parsing.declarations.structure_contract
Structure module
1""" 2Structure module 3""" 4 5from typing import TYPE_CHECKING 6 7from slither.core.declarations.structure import Structure 8from slither.core.variables.structure_variable import StructureVariable 9from slither.solc_parsing.variables.structure_variable import StructureVariableSolc 10 11if TYPE_CHECKING: 12 from slither.solc_parsing.declarations.contract import ContractSolc 13 14 15class StructureContractSolc: 16 """ 17 Structure class 18 """ 19 20 # elems = [(type, name)] 21 22 def __init__( 23 self, 24 st: Structure, 25 struct: dict, 26 contract_parser: "ContractSolc", 27 ) -> None: 28 if contract_parser.is_compact_ast: 29 name = struct["name"] 30 attributes = struct 31 else: 32 name = struct["attributes"][contract_parser.get_key()] 33 attributes = struct["attributes"] 34 if "canonicalName" in attributes: 35 canonicalName = attributes["canonicalName"] 36 else: 37 canonicalName = contract_parser.underlying_contract.name + "." + name 38 39 children = struct["members"] if "members" in struct else struct.get("children", []) 40 41 self._structure = st 42 st.name = name 43 st.canonical_name = canonicalName 44 self._contract_parser = contract_parser 45 46 self._elemsNotParsed = children 47 48 def analyze(self) -> None: 49 for elem_to_parse in self._elemsNotParsed: 50 elem = StructureVariable() 51 elem.set_structure(self._structure) 52 elem.set_offset(elem_to_parse["src"], self._structure.contract.compilation_unit) 53 54 elem_parser = StructureVariableSolc(elem, elem_to_parse) 55 elem_parser.analyze(self._contract_parser) 56 57 self._structure.elems[elem.name] = elem 58 self._structure.add_elem_in_order(elem.name) 59 self._elemsNotParsed = []
class
StructureContractSolc:
16class StructureContractSolc: 17 """ 18 Structure class 19 """ 20 21 # elems = [(type, name)] 22 23 def __init__( 24 self, 25 st: Structure, 26 struct: dict, 27 contract_parser: "ContractSolc", 28 ) -> None: 29 if contract_parser.is_compact_ast: 30 name = struct["name"] 31 attributes = struct 32 else: 33 name = struct["attributes"][contract_parser.get_key()] 34 attributes = struct["attributes"] 35 if "canonicalName" in attributes: 36 canonicalName = attributes["canonicalName"] 37 else: 38 canonicalName = contract_parser.underlying_contract.name + "." + name 39 40 children = struct["members"] if "members" in struct else struct.get("children", []) 41 42 self._structure = st 43 st.name = name 44 st.canonical_name = canonicalName 45 self._contract_parser = contract_parser 46 47 self._elemsNotParsed = children 48 49 def analyze(self) -> None: 50 for elem_to_parse in self._elemsNotParsed: 51 elem = StructureVariable() 52 elem.set_structure(self._structure) 53 elem.set_offset(elem_to_parse["src"], self._structure.contract.compilation_unit) 54 55 elem_parser = StructureVariableSolc(elem, elem_to_parse) 56 elem_parser.analyze(self._contract_parser) 57 58 self._structure.elems[elem.name] = elem 59 self._structure.add_elem_in_order(elem.name) 60 self._elemsNotParsed = []
Structure class
StructureContractSolc( st: slither.core.declarations.structure.Structure, struct: dict, contract_parser: slither.solc_parsing.declarations.contract.ContractSolc)
23 def __init__( 24 self, 25 st: Structure, 26 struct: dict, 27 contract_parser: "ContractSolc", 28 ) -> None: 29 if contract_parser.is_compact_ast: 30 name = struct["name"] 31 attributes = struct 32 else: 33 name = struct["attributes"][contract_parser.get_key()] 34 attributes = struct["attributes"] 35 if "canonicalName" in attributes: 36 canonicalName = attributes["canonicalName"] 37 else: 38 canonicalName = contract_parser.underlying_contract.name + "." + name 39 40 children = struct["members"] if "members" in struct else struct.get("children", []) 41 42 self._structure = st 43 st.name = name 44 st.canonical_name = canonicalName 45 self._contract_parser = contract_parser 46 47 self._elemsNotParsed = children
def
analyze(self) -> None:
49 def analyze(self) -> None: 50 for elem_to_parse in self._elemsNotParsed: 51 elem = StructureVariable() 52 elem.set_structure(self._structure) 53 elem.set_offset(elem_to_parse["src"], self._structure.contract.compilation_unit) 54 55 elem_parser = StructureVariableSolc(elem, elem_to_parse) 56 elem_parser.analyze(self._contract_parser) 57 58 self._structure.elems[elem.name] = elem 59 self._structure.add_elem_in_order(elem.name) 60 self._elemsNotParsed = []