slither.solc_parsing.declarations.structure_contract

Structure module

 1"""
 2    Structure module
 3"""
 4from typing import TYPE_CHECKING, Dict
 5
 6from slither.core.declarations.structure import Structure
 7from slither.core.variables.structure_variable import StructureVariable
 8from slither.solc_parsing.variables.structure_variable import StructureVariableSolc
 9
10if TYPE_CHECKING:
11    from slither.solc_parsing.declarations.contract import ContractSolc
12
13
14class StructureContractSolc:  # pylint: disable=too-few-public-methods
15    """
16    Structure class
17    """
18
19    # elems = [(type, name)]
20
21    def __init__(  # pylint: disable=too-many-arguments
22        self,
23        st: Structure,
24        struct: Dict,
25        contract_parser: "ContractSolc",
26    ) -> None:
27
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:
15class StructureContractSolc:  # pylint: disable=too-few-public-methods
16    """
17    Structure class
18    """
19
20    # elems = [(type, name)]
21
22    def __init__(  # pylint: disable=too-many-arguments
23        self,
24        st: Structure,
25        struct: Dict,
26        contract_parser: "ContractSolc",
27    ) -> None:
28
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)
22    def __init__(  # pylint: disable=too-many-arguments
23        self,
24        st: Structure,
25        struct: Dict,
26        contract_parser: "ContractSolc",
27    ) -> None:
28
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 = []