예제 #1
0
    def add_constructor_variables(self):
        if self.state_variables:
            for (idx, variable_candidate) in enumerate(self.state_variables):
                if variable_candidate.expression and not variable_candidate.is_constant:

                    constructor_variable = Function()
                    constructor_variable.set_function_type(
                        FunctionType.CONSTRUCTOR_VARIABLES)
                    constructor_variable.set_contract(self)
                    constructor_variable.set_contract_declarer(self)
                    constructor_variable.set_visibility('internal')
                    # For now, source mapping of the constructor variable is the whole contract
                    # Could be improved with a targeted source mapping
                    constructor_variable.set_offset(self.source_mapping,
                                                    self.slither)
                    self._functions[constructor_variable.
                                    canonical_name] = constructor_variable

                    prev_node = self._create_node(constructor_variable, 0,
                                                  variable_candidate)
                    counter = 1
                    for v in self.state_variables[idx + 1:]:
                        if v.expression and not v.is_constant:
                            next_node = self._create_node(
                                constructor_variable, counter, v)
                            prev_node.add_son(next_node)
                            next_node.add_father(prev_node)
                            counter += 1

                    break
예제 #2
0
    def _parse_function(self, function_data: Dict):
        func = Function()
        func.set_offset(function_data["src"], self._contract.slither)
        func.set_contract(self._contract)
        func.set_contract_declarer(self._contract)

        func_parser = FunctionSolc(func, function_data, self)
        self._contract.slither.add_function(func)
        self._functions_no_params.append(func_parser)
        self._functions_parser.append(func_parser)

        self._slither_parser.add_functions_parser(func_parser)