ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
python_typechecking.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <nlohmann/json.hpp>
6#include <util/irep/expr.h>
9#include <util/irep/type.h>
10#include <util/symtab/symbol.h>
12
13#include <string>
14#include <unordered_map>
15#include <vector>
16
18
20{
21public:
22 explicit python_typechecking(python_converter &converter);
23
24 std::vector<typet>
25 collect_annotation_types(const nlohmann::json &annotation) const;
26
27 void
28 cache_annotation_types(symbolt &symbol, const nlohmann::json &annotation);
29
30 std::vector<typet> get_annotation_types(const std::string &symbol_id) const;
31
33 const nlohmann::json &function_node,
34 const symbol_id &function_id,
35 const code_typet &type,
36 exprt &function_body);
37
38 bool should_skip_type_assertion(const typet &annotated_type) const;
39
41 const exprt &value_expr,
42 const typet &annotated_type) const;
43
45 const exprt &value_expr,
46 const typet &annotated_type,
47 const std::vector<typet> &allowed_types,
48 const std::string &context_name,
49 const locationt &location,
50 code_assertt &out_assert) const;
51
53 const exprt &value_expr,
54 const typet &annotated_type,
55 const std::vector<typet> &allowed_types,
56 const std::string &context_name,
57 const locationt &location,
58 codet &target_block);
59
60 std::string get_constructor_name(const nlohmann::json &func_node) const;
61
63 const std::string &class_name,
64 const std::string &expected_base) const;
65
66private:
67 exprt build_none_check(const exprt &value_expr) const;
68
69 python_converter &converter_;
70 std::unordered_map<std::string, std::vector<typet>> annotation_type_cache_;
71};
Definition std_code.h:243
Definition std_types.h:280
Definition std_code.h:8
Definition expr.h:34
Definition location.h:7
Main converter for transforming Python AST into ESBMC's intermediate representation.
Definition python_converter.h:76
void inject_parameter_type_assertions(const nlohmann::json &function_node, const symbol_id &function_id, const code_typet &type, exprt &function_body)
Definition python_typechecking.cpp:361
python_typechecking(python_converter &converter)
Definition python_typechecking.cpp:13
void cache_annotation_types(symbolt &symbol, const nlohmann::json &annotation)
Definition python_typechecking.cpp:105
exprt build_isinstance_check(const exprt &value_expr, const typet &annotated_type) const
Definition python_typechecking.cpp:161
bool class_derives_from(const std::string &class_name, const std::string &expected_base) const
Definition python_typechecking.cpp:451
void emit_type_annotation_assertion(const exprt &value_expr, const typet &annotated_type, const std::vector< typet > &allowed_types, const std::string &context_name, const locationt &location, codet &target_block)
Definition python_typechecking.cpp:340
std::string get_constructor_name(const nlohmann::json &func_node) const
Definition python_typechecking.cpp:437
bool build_type_assertion(const exprt &value_expr, const typet &annotated_type, const std::vector< typet > &allowed_types, const std::string &context_name, const locationt &location, code_assertt &out_assert) const
Definition python_typechecking.cpp:253
std::vector< typet > get_annotation_types(const std::string &symbol_id) const
Definition python_typechecking.cpp:128
bool should_skip_type_assertion(const typet &annotated_type) const
Definition python_typechecking.cpp:136
std::vector< typet > collect_annotation_types(const nlohmann::json &annotation) const
Definition python_typechecking.cpp:18
Definition symbol_id.h:6
Definition symbol.h:12
Definition type.h:9