ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
string_builder.h
Go to the documentation of this file.
1#pragma once
2
3#include <util/irep/expr.h>
4#include <util/irep/type.h>
5#include <nlohmann/json.hpp>
6#include <vector>
7#include <string>
8#include <cstdint>
9
10// Forward declaration
12class type_handler;
13class contextt;
14class string_handler;
15
20{
21public:
22 explicit string_builder(python_converter &converter, string_handler *handler);
23
26
28 exprt make_char_constant(unsigned char ch);
29
32 std::vector<exprt> extract_string_chars(
33 const exprt &expr,
34 const nlohmann::json &json_node = nlohmann::json());
35
38 exprt build_null_terminated_string(const std::vector<exprt> &chars);
39
41 exprt build_string_literal(const std::string &str);
42
44 exprt build_byte_string(const std::vector<uint8_t> &bytes);
45
49
52 const exprt &lhs,
53 const exprt &rhs,
54 const nlohmann::json &left = nlohmann::json(),
55 const nlohmann::json &right = nlohmann::json());
56
58
61 exprt build_raw_byte_array(const std::vector<uint8_t> &bytes);
62
64 const exprt &lhs,
65 const exprt &rhs,
66 const nlohmann::json &left);
67
76 const std::string &fn_name,
77 const typet &arg_type,
78 const exprt &arg);
79
84 exprt
85 build_runtime_str_join_call(const exprt &separator, const exprt &list_expr);
86
87private:
88 python_converter &converter_;
89 string_handler *str_handler_;
90 contextt &get_symbol_table() const;
91 type_handler &get_type_handler();
92};
Definition context.h:57
Definition expr.h:34
Main converter for transforming Python AST into ESBMC's intermediate representation.
Definition python_converter.h:76
exprt build_string_literal(const std::string &str)
Create a null-terminated string from a std::string.
Definition string_builder.cpp:190
exprt build_null_terminated_string(const std::vector< exprt > &chars)
Create a null-terminated string array from a vector of character expressions.
Definition string_builder.cpp:167
std::vector< exprt > extract_string_chars(const exprt &expr, const nlohmann::json &json_node=nlohmann::json())
Extract characters from an expression, stopping at null terminator Returns a vector of character expr...
Definition string_builder.cpp:44
exprt build_byte_string(const std::vector< uint8_t > &bytes)
Create a null-terminated string from a vector of bytes.
Definition string_builder.cpp:200
exprt ensure_null_terminated_string(exprt &e)
Ensure an expression is a null-terminated string Converts single characters or promotes to proper str...
Definition string_builder.cpp:210
exprt handle_string_repetition(exprt &lhs, exprt &rhs)
Definition string_builder.cpp:314
exprt make_char_constant(unsigned char ch)
Create a character constant from a byte value.
Definition string_builder.cpp:37
exprt concatenate_strings(const exprt &lhs, const exprt &rhs, const nlohmann::json &left=nlohmann::json(), const nlohmann::json &right=nlohmann::json())
Concatenate two string expressions with proper null-termination.
Definition string_builder.cpp:233
exprt build_raw_byte_array(const std::vector< uint8_t > &bytes)
Create a raw byte array without null termination (for Python bytes literals).
Definition string_builder.cpp:488
string_builder(python_converter &converter, string_handler *handler)
Definition string_builder.cpp:15
exprt build_runtime_str_conversion_call(const std::string &fn_name, const typet &arg_type, const exprt &arg)
Build a side-effect call to a char *fn(arg_type) operational model.
Definition string_builder.cpp:569
exprt make_null_terminator()
Create a null terminator character constant.
Definition string_builder.cpp:30
exprt build_runtime_str_join_call(const exprt &separator, const exprt &list_expr)
Build a side-effect call to the runtime __python_str_join operational model.
Definition string_builder.cpp:600
exprt concatenate_strings_via_c_function(const exprt &lhs, const exprt &rhs, const nlohmann::json &left)
Definition string_builder.cpp:513
Handles all string-related operations for Python-to-C conversion.
Definition string_handler.h:36
Definition type_handler.h:113
Definition type.h:9