ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
python_lambda.h
Go to the documentation of this file.
1#ifndef ESBMC_PYTHON_LAMBDA_H
2#define ESBMC_PYTHON_LAMBDA_H
3
5#include <util/irep/expr.h>
7#include <nlohmann/json.hpp>
8#include <optional>
9
11class type_handler;
12
14{
15public:
17 python_converter &converter,
18 contextt &context,
20
21 // Main method to create lambda expression from AST. Parameters take
22 // `argument_types` when given, those of the lambda's one call.
24 const nlohmann::json &element,
25 const std::vector<std::optional<typet>> &argument_types);
26
27 // Check if a variable assignment involves a lambda
28 bool is_lambda_assignment(const nlohmann::json &ast_node) const;
29
30 // Handle lambda assignment type adjustments
31 void handle_lambda_assignment(symbolt *lhs_symbol, exprt &lhs, exprt &rhs);
32
33 // The parameter types a copy of the lambda needs for @p call, which passes
34 // an int where @p signature, taken from calls that disagree, has a float
35 // (#8941). Names resolve in @p scope. Empty when @p signature serves it.
36 std::vector<std::optional<typet>> narrowed_parameter_types(
37 const nlohmann::json &call,
38 const nlohmann::json &scope,
39 const code_typet &signature) const;
40
41 // Infer return type from a lambda body node
42 typet infer_lambda_return_type(const nlohmann::json &body_node);
43
44private:
45 python_converter &converter_;
46 contextt &context_;
47 type_handler &type_handler_;
48
49 // Counter for generating unique lambda names
50 static int lambda_counter_;
51
52 // Helper methods
53 void process_lambda_parameters(
54 const nlohmann::json &args_node,
55 code_typet &lambda_type,
56 const std::string &lambda_id,
57 const std::string &param_scope_id,
58 const locationt &location,
59 const nlohmann::json &body_node,
60 const std::vector<std::optional<typet>> &call_site_types);
61
62 // Per-parameter type taken from `argument_types` when given, else from a
63 // call through the name this lambda is bound to; an entry is empty when no
64 // such call pins that argument down (#7328).
65 std::vector<std::optional<typet>> call_site_argument_types(
66 const nlohmann::json &element,
67 const std::vector<std::optional<typet>> &argument_types) const;
68
69 exprt process_lambda_body(
70 const nlohmann::json &body_node,
71 const locationt &location);
72
73 std::string generate_unique_lambda_name();
74
75 symbolt create_symbol(
76 const std::string &id,
77 const std::string &name,
78 const typet &type,
79 const locationt &location,
80 const std::string &module_name,
81 bool file_local,
82 bool is_parameter = false);
83};
84
86const nlohmann::json *binding_target(const nlohmann::json &stmt);
87
89size_t count_bindings(const nlohmann::json &node, const std::string &name);
90
91#endif // ESBMC_PYTHON_LAMBDA_H
Definition std_types.h:280
Definition context.h:57
Definition expr.h:34
Definition location.h:7
Main converter for transforming Python AST into ESBMC's intermediate representation.
Definition python_converter.h:76
typet infer_lambda_return_type(const nlohmann::json &body_node)
Definition python_lambda.cpp:163
void handle_lambda_assignment(symbolt *lhs_symbol, exprt &lhs, exprt &rhs)
Definition python_lambda.cpp:40
std::vector< std::optional< typet > > narrowed_parameter_types(const nlohmann::json &call, const nlohmann::json &scope, const code_typet &signature) const
Definition python_lambda.cpp:913
bool is_lambda_assignment(const nlohmann::json &ast_node) const
Definition python_lambda.cpp:34
exprt get_lambda_expr(const nlohmann::json &element, const std::vector< std::optional< typet > > &argument_types)
Definition python_lambda.cpp:1100
python_lambda(python_converter &converter, contextt &context, type_handler &type_handler)
Definition python_lambda.cpp:21
Definition symbol.h:12
Definition type_handler.h:113
Definition type.h:9
size_t count_bindings(const nlohmann::json &node, const std::string &name)
Every construct under node that binds name, in any nested scope too.
Definition python_lambda.cpp:625
const nlohmann::json * binding_target(const nlohmann::json &stmt)
The one name target a plain x = v or x: T = v statement binds, or null.
Definition python_lambda.cpp:283