|
ESBMC
Efficient SMT-based Context-Bounded Model Checker
|
Handles all string-related operations for Python-to-C conversion. More...
#include <string_handler.h>
Public Member Functions | |
| string_handler (python_converter &converter, contextt &symbol_table, type_handler &type_handler, string_builder *str_builder) | |
| Constructs a string_handler. | |
| void | set_string_builder (string_builder *sb) |
| BigInt | get_string_size (const exprt &expr) |
| Calculate the size of a string expression. | |
| exprt | convert_to_string (const exprt &expr) |
| Convert an expression to a string representation. | |
| exprt | build_fstring_conversion (const nlohmann::json &value, int conversion, const exprt &operand, const locationt &location) |
| The rendered part for an f-string replacement field carrying a !r / !a conversion: the folded repr where possible, else a sound nondet string. | |
| exprt | build_repr (const exprt &value, const locationt &location) |
| repr() of a runtime value, or nil when its type has no model: a number or bool renders as str() does, a str through __python_str_repr. | |
| exprt | format_fstring_part (const nlohmann::json &value) |
| The rendered text of one f-string replacement field. | |
| exprt | build_nondet_string_fallback (const locationt &location) |
| exprt | build_nondet_string (const locationt &location) |
| A bounded, NUL-terminated str of nondet content, as nondet_str() gives. | |
| std::string | extract_string_from_array_operands (const exprt &array_expr) const |
| Extract string content from array operands. | |
| void | ensure_string_array (exprt &expr) |
| Ensure an expression is a null-terminated string array. | |
| exprt | ensure_null_terminated_string (exprt &e) |
| Ensure string is null-terminated. | |
| std::string | process_format_spec (const nlohmann::json &format_spec) |
| Process format specification for f-strings. | |
| exprt | apply_format_specification (const exprt &expr, const std::string &format) |
| Apply format specification to an expression. | |
| exprt | format_runtime_value (const exprt &expr, const std::string &format) |
| A spec on a value not folded at conversion time: a fixed-point float through its model, anything else as a nondet string. | |
| exprt | get_fstring_expr (const nlohmann::json &element) |
| Convert f-string JSON to expression. | |
| exprt | handle_string_concatenation (const exprt &lhs, const exprt &rhs, const nlohmann::json &left, const nlohmann::json &right) |
| Handle string concatenation. | |
| exprt | handle_string_concatenation_with_promotion (exprt &lhs, exprt &rhs, const nlohmann::json &left, const nlohmann::json &right) |
| Handle string concatenation with type promotion. | |
| exprt | handle_string_comparison (const std::string &op, exprt &lhs, exprt &rhs, const nlohmann::json &element) |
| Handle string comparison operations. | |
| exprt | handle_single_char_comparison (const std::string &op, exprt &lhs, exprt &rhs) |
| Handle single character comparisons. | |
| exprt | create_char_comparison_expr (const std::string &op, const exprt &lhs_char_value, const exprt &rhs_char_value, const exprt &lhs_source, const exprt &rhs_source) const |
| Create a character comparison expression. | |
| exprt | handle_string_repetition (exprt &lhs, exprt &rhs) |
| Handle string repetition. | |
| exprt | handle_string_operations (const std::string &op, exprt &lhs, exprt &rhs, const nlohmann::json &left, const nlohmann::json &right, const nlohmann::json &element) |
| Handle general string operations. | |
| exprt | handle_str_join (const nlohmann::json &call_json) |
| Handle str.join() method. | |
| exprt | join_unfoldable_iterable (const exprt &separator, const nlohmann::json &call_json) |
| exprt | convert_join_items (const nlohmann::json &elements, std::vector< exprt > &elem_exprs) |
| Convert a join() literal's elements into elem_exprs. | |
| exprt | handle_string_attribute_call (const nlohmann::json &call_json) |
| Dispatch and handle string attribute method calls. | |
| exprt | read_tagged_str_receiver (const exprt &receiver, const std::string &method, const nlohmann::json &call_json) |
| The str a tagged receiver of str-only method method holds, after raising AttributeError on the paths where it holds another type. | |
| exprt | try_handle_len_string_fast_path (const nlohmann::json &call_json, const exprt &arg_expr) |
| Try fast-path folding for len() when argument is string-like. | |
| exprt | char_array_type_length (const exprt &arg_expr) const |
| exprt | handle_string_startswith (const exprt &string_obj, const exprt &prefix_arg, const locationt &location) |
| Handle str.startswith() method. | |
| exprt | handle_string_endswith (const exprt &string_obj, const exprt &suffix_arg, const locationt &location) |
| Handle str.endswith() method. | |
| exprt | handle_startswith_endswith_with_pos (const exprt &string_obj, const nlohmann::json &args, python_converter &converter, const locationt &location, bool is_suffix) |
| Handle str.startswith/endswith with optional start/end position arguments: s.startswith(prefix, start[, end]) is evaluated as s[start:end].startswith(prefix). | |
| exprt | build_affix_tuple_match (const exprt &string_obj, const exprt &affix_tuple, const locationt &location, bool is_suffix) |
| Shared implementation for startswith()/endswith() with a tuple of affixes: True iff the string matches any element. | |
| exprt | handle_string_isdigit (const exprt &string_obj, const locationt &location) |
| Handle str.isdigit() method. | |
| exprt | handle_string_isalpha (const exprt &string_obj, const locationt &location) |
| Handle str.isalpha() method. | |
| exprt | handle_string_isspace (const exprt &str_expr, const locationt &location) |
| Handle str.isspace() method for strings. | |
| exprt | handle_char_isspace (const exprt &char_expr, const locationt &location) |
| Handle char.isspace() method for single characters. | |
| exprt | handle_string_lstrip (const exprt &str_expr, const exprt &chars_arg, const locationt &location) |
| Handle str.lstrip() method. | |
| exprt | handle_string_strip (const exprt &str_expr, const exprt &chars_arg, const locationt &location) |
| Handle str.strip() method. | |
| exprt | handle_string_rstrip (const exprt &str_expr, const exprt &chars_arg, const locationt &location) |
| Handle str.rstrip() method. | |
| exprt | handle_string_membership (exprt &lhs, exprt &rhs, const nlohmann::json &element) |
| Handle 'in' operator for strings. | |
| exprt | handle_string_islower (const exprt &string_obj, const locationt &location) |
| Handle Python's str.islower() method. | |
| exprt | handle_string_lower (const exprt &string_obj, const locationt &location) |
| Handle str.lower() method. | |
| exprt | handle_string_upper (const exprt &string_obj, const locationt &location) |
| Handle str.upper() method. | |
| exprt | handle_string_find (const exprt &string_obj, const exprt &find_arg, const locationt &location) |
| Handle str.find() method. | |
| exprt | handle_string_find_range (const exprt &string_obj, const exprt &find_arg, const exprt &start_arg, const exprt &end_arg, const locationt &location) |
| Handle str.find() with start/end. | |
| exprt | handle_string_index (const nlohmann::json &call, const exprt &string_obj, const exprt &find_arg, const locationt &location) |
| Handle str.index() method. | |
| exprt | handle_string_index_range (const nlohmann::json &call, const exprt &string_obj, const exprt &find_arg, const exprt &start_arg, const exprt &end_arg, const locationt &location) |
| Handle str.index() with start/end. | |
| exprt | handle_string_rfind (const exprt &string_obj, const exprt &find_arg, const locationt &location) |
| Handle str.rfind() method. | |
| exprt | handle_string_rfind_range (const exprt &string_obj, const exprt &find_arg, const exprt &start_arg, const exprt &end_arg, const locationt &location) |
| Handle str.rfind() with start/end. | |
| exprt | handle_string_rindex (const nlohmann::json &call, const exprt &string_obj, const exprt &find_arg, const locationt &location) |
| Handle str.rindex() method (rfind that raises on not-found). | |
| exprt | handle_string_rindex_range (const nlohmann::json &call, const exprt &string_obj, const exprt &find_arg, const exprt &start_arg, const exprt &end_arg, const locationt &location) |
| Handle str.rindex() with start/end. | |
| exprt | handle_string_replace (const exprt &string_obj, const exprt &old_arg, const exprt &new_arg, const exprt &count_arg, const locationt &location) |
| Handle str.replace() method. | |
| exprt | handle_string_capitalize (const exprt &string_obj, const locationt &location) |
| Handle str.capitalize() method. | |
| exprt | handle_string_title (const exprt &string_obj, const locationt &location) |
| Handle str.title() method. | |
| exprt | handle_string_swapcase (const exprt &string_obj, const locationt &location) |
| Handle str.swapcase() method. | |
| exprt | handle_string_casefold (const exprt &string_obj, const locationt &location) |
| Handle str.casefold() method. | |
| exprt | handle_string_count (const exprt &string_obj, const exprt &sub_arg, const exprt &start_arg, const exprt &end_arg, const locationt &location) |
| Handle str.count() method (constant fold, else runtime model). | |
| exprt | handle_string_removeprefix (const exprt &string_obj, const exprt &prefix_arg, const locationt &location) |
| Handle str.removeprefix() method. | |
| exprt | handle_string_removesuffix (const exprt &string_obj, const exprt &suffix_arg, const locationt &location) |
| Handle str.removesuffix() method. | |
| exprt | handle_string_splitlines (const nlohmann::json &call, const exprt &string_obj, const locationt &location, bool keepends=false) |
| Handle str.splitlines() method (constant-only support). | |
| exprt | handle_string_format (const nlohmann::json &call, const exprt &string_obj, const locationt &location) |
| Handle str.format() method (minimal support, constant-only). | |
| exprt | handle_string_partition (const exprt &string_obj, const exprt &sep_arg, const locationt &location) |
| Handle str.partition() method (constant-only support). | |
| exprt | handle_string_rpartition (const exprt &string_obj, const exprt &sep_arg, const locationt &location) |
| Handle str.rpartition() method (constant-only support). | |
| exprt | build_partition_tuple (const exprt &string_obj, const exprt &sep_arg, const locationt &location, bool from_right) |
Shared implementation of partition()/rpartition(): builds the 3-tuple (before, sep, after), searching from the left when from_right is false and from the right when true. | |
| exprt | handle_string_isalnum (const exprt &string_obj, const locationt &location) |
| Handle str.isalnum() method. | |
| exprt | handle_string_isupper (const exprt &string_obj, const locationt &location) |
| Handle str.isupper() method. | |
| exprt | handle_string_isnumeric (const exprt &string_obj, const locationt &location) |
| Handle str.isnumeric() method. | |
| exprt | handle_string_isidentifier (const exprt &string_obj, const locationt &location) |
| Handle str.isidentifier() method. | |
| exprt | handle_string_center (const exprt &string_obj, const exprt &width_arg, const exprt &fill_arg, const locationt &location) |
| Handle str.center() method (constant-only support). | |
| exprt | handle_string_ljust (const exprt &string_obj, const exprt &width_arg, const exprt &fill_arg, const locationt &location) |
| Handle str.ljust() method (constant-only support). | |
| exprt | handle_string_rjust (const exprt &string_obj, const exprt &width_arg, const exprt &fill_arg, const locationt &location) |
| Handle str.rjust() method (constant-only support). | |
| exprt | handle_string_zfill (const exprt &string_obj, const exprt &width_arg, const locationt &location) |
| Handle str.zfill() method (constant-only support). | |
| exprt | handle_string_expandtabs (const exprt &string_obj, const exprt &tabsize_arg, const locationt &location) |
| Handle str.expandtabs() method (constant-only support). | |
| exprt | handle_string_format_map (const nlohmann::json &call, const exprt &string_obj, const locationt &location) |
| Handle str.format_map() method (minimal support, constant-only). | |
| bool | is_zero_length_array (const exprt &expr) |
| Check if an expression is a zero-length array. | |
| exprt | get_array_base_address (const exprt &arr) |
| Get base address of array (first element). | |
| exprt | handle_string_to_int (const exprt &string_obj, const exprt &base_arg, const locationt &location) |
| Convert a string to an integer using Python's int() function. | |
| exprt | handle_string_to_int_base10 (const exprt &string_obj, const locationt &location) |
| Convert a string to an integer using base 10 (convenience method). | |
| exprt | handle_int_conversion (const exprt &arg, const locationt &location) |
| Handle int() builtin with automatic type detection Supports int(x) where x can be: int, float, bool, or string. | |
| exprt | handle_int_conversion_with_base (const exprt &arg, const exprt &base, const locationt &location) |
| Handle int() builtin with explicit base Supports int(x, base) where x is a string. | |
| exprt | handle_string_to_float (const exprt &string_obj, const locationt &location) |
| Convert a runtime string expression to a double via the __python_str_to_float operational model. | |
| exprt | handle_string_is_float (const exprt &string_obj, const locationt &location) |
| Build a call to the __python_str_is_float operational model, returning a bool that is true iff the runtime string is a valid Python float literal. | |
| exprt | handle_chr_conversion (const exprt &codepoint_arg, const locationt &location) |
| Handle chr() builtin function Converts a Unicode code point to its string representation Supports chr(i) where i is an integer in range [0, 0x10FFFF]. | |
| exprt | handle_ord_conversion (const exprt &string_obj, const locationt &location) |
| Handle ord() of a runtime string whose value is not known at compile time. | |
Static Public Member Functions | |
| static std::string | fstring_repr_of_constant (const nlohmann::json &operand) |
| Build a sound symbolic fallback for a char * string value when a string handler cannot compile-time-fold its argument. | |
| static int | nondet_str_buffer_size () |
| The nondet str buffer size: –nondet-str-length plus the NUL. | |
| static bool | extract_constant_string (const nlohmann::json &node, python_converter &converter, std::string &out) |
| Extract a constant string from the AST node (literal or const var). | |
| static std::string | cpython_float_str (double d) |
| Render a constant double as CPython's str()/repr() would: the shortest decimal string that reads back as the same double. | |
Handles all string-related operations for Python-to-C conversion.
This class extracts string manipulation functionality from python_converter to improve modularity and maintainability. It handles:
| string_handler::string_handler | ( | python_converter & | converter, |
| contextt & | symbol_table, | ||
| type_handler & | type_handler, | ||
| string_builder * | str_builder ) |
Constructs a string_handler.
| converter | Reference to the parent python_converter |
| symbol_table | Reference to the symbol table (contextt) |
| type_handler | Reference to the type handler |
| str_builder | Pointer to the string builder |
Apply format specification to an expression.
| expr | Expression to format |
| format | Format string |
| exprt string_handler::build_affix_tuple_match | ( | const exprt & | string_obj, |
| const exprt & | affix_tuple, | ||
| const locationt & | location, | ||
| bool | is_suffix ) |
Shared implementation for startswith()/endswith() with a tuple of affixes: True iff the string matches any element.
is_suffix selects endswith (true) vs startswith (false).
| exprt string_handler::build_fstring_conversion | ( | const nlohmann::json & | value, |
| int | conversion, | ||
| const exprt & | operand, | ||
| const locationt & | location ) |
The rendered part for an f-string replacement field carrying a !r / !a conversion: the folded repr where possible, else a sound nondet string.
A bounded, NUL-terminated str of nondet content, as nondet_str() gives.
| exprt string_handler::build_partition_tuple | ( | const exprt & | string_obj, |
| const exprt & | sep_arg, | ||
| const locationt & | location, | ||
| bool | from_right ) |
Shared implementation of partition()/rpartition(): builds the 3-tuple (before, sep, after), searching from the left when from_right is false and from the right when true.
repr() of a runtime value, or nil when its type has no model: a number or bool renders as str() does, a str through __python_str_repr.
For an ASCII value this is also ascii().
| exprt string_handler::convert_join_items | ( | const nlohmann::json & | elements, |
| std::vector< exprt > & | elem_exprs ) |
Convert a join() literal's elements into elem_exprs.
Returns a TypeError raise for an element that is known not to be a str, nil otherwise.
Convert an expression to a string representation.
| expr | Expression to convert |
|
static |
Render a constant double as CPython's str()/repr() would: the shortest decimal string that reads back as the same double.
A whole value below 1e16 gets the "N.0" spelling; every other finite value (and nan/inf) uses the fewest g significant digits that round-trip, which reproduces CPython's shortest repr and its fixed/exponential cut-over. This is total: it renders every double, so str()/repr() and f-string interpolation fold to the exact CPython string for inexact values too (str(0.1 + 0.2) == "0.30000000000000004", str(1e-5) == "1e-05"). The caller still emits a nondet string for a 32-bit float or a nondet value.
| exprt string_handler::create_char_comparison_expr | ( | const std::string & | op, |
| const exprt & | lhs_char_value, | ||
| const exprt & | rhs_char_value, | ||
| const exprt & | lhs_source, | ||
| const exprt & | rhs_source ) const |
Create a character comparison expression.
| op | Comparison operator |
| lhs_char_value | Left character value (as integer) |
| rhs_char_value | Right character value (as integer) |
| lhs_source | Original left source expression |
| rhs_source | Original right source expression |
Ensure string is null-terminated.
| e | String expression |
| void string_handler::ensure_string_array | ( | exprt & | expr | ) |
Ensure an expression is a null-terminated string array.
| expr | Expression to convert |
|
static |
Extract a constant string from the AST node (literal or const var).
| node | JSON node to inspect |
| converter | Converter used to resolve Name references |
| out | Output string |
| std::string string_handler::extract_string_from_array_operands | ( | const exprt & | array_expr | ) | const |
Extract string content from array operands.
| array_expr | Array expression containing characters |
| exprt string_handler::format_fstring_part | ( | const nlohmann::json & | value | ) |
The rendered text of one f-string replacement field.
A spec on a value not folded at conversion time: a fixed-point float through its model, anything else as a nondet string.
|
static |
Build a sound symbolic fallback for a char * string value when a string handler cannot compile-time-fold its argument.
Replaces the historical throw "X() requires constant string" aborts so that GOTO conversion can proceed. Returns a side_effect_expr_nondett of pointer-to-char type; subsequent string ops see arbitrary content, which is sound over-approximation for safety properties (we cannot conclude a specific functional result, but we cannot wrongly conclude SAFE either). repr() of a constant f-string operand under !r / !a, or empty when the spelling is one this does not fold. Only an int's digits and a string needing no escape are folded: reproducing CPython's quote choice and escaping here would be easy to get subtly wrong (#7559).
Get base address of array (first element).
| arr | Array expression |
| exprt string_handler::get_fstring_expr | ( | const nlohmann::json & | element | ) |
Convert f-string JSON to expression.
| element | JSON element representing f-string |
Calculate the size of a string expression.
| expr | Expression to measure |
Handle char.isspace() method for single characters.
| char_expr | Character expression |
| location | Source location |
| exprt string_handler::handle_chr_conversion | ( | const exprt & | codepoint_arg, |
| const locationt & | location ) |
Handle chr() builtin function Converts a Unicode code point to its string representation Supports chr(i) where i is an integer in range [0, 0x10FFFF].
| codepoint_arg | The integer code point to convert |
| location | Source location for error reporting |
| exprt string_handler::handle_int_conversion_with_base | ( | const exprt & | arg, |
| const exprt & | base, | ||
| const locationt & | location ) |
Handle int() builtin with explicit base Supports int(x, base) where x is a string.
| arg | The string argument to convert |
| base | The base for conversion |
| location | Source location for error reporting |
| exprt string_handler::handle_ord_conversion | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle ord() of a runtime string whose value is not known at compile time.
Returns the integer code point of the string's first character, (int) *base. A length-1 precondition is not enforced because a runtime guard cannot be short-circuited inside an and/or operand; constant strings (including multi-byte) are folded by the caller instead.
| string_obj | The runtime string argument |
| location | Source location for error reporting |
| exprt string_handler::handle_single_char_comparison | ( | const std::string & | op, |
| exprt & | lhs, | ||
| exprt & | rhs ) |
Handle single character comparisons.
| op | Comparison operator |
| lhs | Left operand |
| rhs | Right operand |
| exprt string_handler::handle_startswith_endswith_with_pos | ( | const exprt & | string_obj, |
| const nlohmann::json & | args, | ||
| python_converter & | converter, | ||
| const locationt & | location, | ||
| bool | is_suffix ) |
Handle str.startswith/endswith with optional start/end position arguments: s.startswith(prefix, start[, end]) is evaluated as s[start:end].startswith(prefix).
is_suffix selects endswith. Constant receiver and constant start/end only.
| exprt string_handler::handle_str_join | ( | const nlohmann::json & | call_json | ) |
Handle str.join() method.
| call_json | JSON node representing the join call |
Handles Python's str.join(iterable) method, e.g.:
| exprt string_handler::handle_string_attribute_call | ( | const nlohmann::json & | call_json | ) |
Dispatch and handle string attribute method calls.
Returns a non-nil expression when the attribute method is recognized as a supported string operation. Returns nil_exprt for non-string methods so callers can continue normal dispatch.
| exprt string_handler::handle_string_capitalize | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.capitalize() method.
| exprt string_handler::handle_string_casefold | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.casefold() method.
| exprt string_handler::handle_string_center | ( | const exprt & | string_obj, |
| const exprt & | width_arg, | ||
| const exprt & | fill_arg, | ||
| const locationt & | location ) |
Handle str.center() method (constant-only support).
| exprt string_handler::handle_string_comparison | ( | const std::string & | op, |
| exprt & | lhs, | ||
| exprt & | rhs, | ||
| const nlohmann::json & | element ) |
Handle string comparison operations.
| op | Comparison operator (Eq, NotEq, etc.) |
| lhs | Left operand |
| rhs | Right operand |
| element | JSON element with location info |
| exprt string_handler::handle_string_concatenation | ( | const exprt & | lhs, |
| const exprt & | rhs, | ||
| const nlohmann::json & | left, | ||
| const nlohmann::json & | right ) |
Handle string concatenation.
| lhs | Left operand |
| rhs | Right operand |
| left | JSON node for left operand |
| right | JSON node for right operand |
| exprt string_handler::handle_string_concatenation_with_promotion | ( | exprt & | lhs, |
| exprt & | rhs, | ||
| const nlohmann::json & | left, | ||
| const nlohmann::json & | right ) |
Handle string concatenation with type promotion.
| lhs | Left operand |
| rhs | Right operand |
| left | JSON node for left operand |
| right | JSON node for right operand |
| exprt string_handler::handle_string_count | ( | const exprt & | string_obj, |
| const exprt & | sub_arg, | ||
| const exprt & | start_arg, | ||
| const exprt & | end_arg, | ||
| const locationt & | location ) |
Handle str.count() method (constant fold, else runtime model).
| exprt string_handler::handle_string_endswith | ( | const exprt & | string_obj, |
| const exprt & | suffix_arg, | ||
| const locationt & | location ) |
Handle str.endswith() method.
| string_obj | String object |
| suffix_arg | Suffix to check |
| location | Source location |
| exprt string_handler::handle_string_expandtabs | ( | const exprt & | string_obj, |
| const exprt & | tabsize_arg, | ||
| const locationt & | location ) |
Handle str.expandtabs() method (constant-only support).
| exprt string_handler::handle_string_find | ( | const exprt & | string_obj, |
| const exprt & | find_arg, | ||
| const locationt & | location ) |
Handle str.find() method.
| string_obj | String object |
| find_arg | String to check |
| location | Source location |
| exprt string_handler::handle_string_find_range | ( | const exprt & | string_obj, |
| const exprt & | find_arg, | ||
| const exprt & | start_arg, | ||
| const exprt & | end_arg, | ||
| const locationt & | location ) |
Handle str.find() with start/end.
| string_obj | String object |
| find_arg | String to check |
| start_arg | Start index |
| end_arg | End index (INT_MIN means default) |
| location | Source location |
| exprt string_handler::handle_string_format | ( | const nlohmann::json & | call, |
| const exprt & | string_obj, | ||
| const locationt & | location ) |
Handle str.format() method (minimal support, constant-only).
| exprt string_handler::handle_string_format_map | ( | const nlohmann::json & | call, |
| const exprt & | string_obj, | ||
| const locationt & | location ) |
Handle str.format_map() method (minimal support, constant-only).
| exprt string_handler::handle_string_index | ( | const nlohmann::json & | call, |
| const exprt & | string_obj, | ||
| const exprt & | find_arg, | ||
| const locationt & | location ) |
Handle str.index() method.
| string_obj | String object |
| find_arg | String to check |
| location | Source location |
| ValueError | if substring is not found. |
| exprt string_handler::handle_string_index_range | ( | const nlohmann::json & | call, |
| const exprt & | string_obj, | ||
| const exprt & | find_arg, | ||
| const exprt & | start_arg, | ||
| const exprt & | end_arg, | ||
| const locationt & | location ) |
Handle str.index() with start/end.
| string_obj | String object |
| find_arg | String to check |
| start_arg | Start index |
| end_arg | End index (INT_MIN means default) |
| location | Source location |
| ValueError | if substring is not found. |
| exprt string_handler::handle_string_is_float | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Build a call to the __python_str_is_float operational model, returning a bool that is true iff the runtime string is a valid Python float literal.
| string_obj | The string argument to validate |
| location | Source location for error reporting |
| exprt string_handler::handle_string_isalnum | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.isalnum() method.
| exprt string_handler::handle_string_isalpha | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.isalpha() method.
| string_obj | String object (can be string or single char) |
| location | Source location |
| exprt string_handler::handle_string_isdigit | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.isdigit() method.
| string_obj | String object |
| location | Source location |
| exprt string_handler::handle_string_isidentifier | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.isidentifier() method.
| exprt string_handler::handle_string_islower | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle Python's str.islower() method.
| string_obj | Expression representing the string or character to check |
| location | Source location for error reporting |
| exprt string_handler::handle_string_isnumeric | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.isnumeric() method.
Handle str.isspace() method for strings.
| str_expr | String expression |
| location | Source location |
| exprt string_handler::handle_string_isupper | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.isupper() method.
| exprt string_handler::handle_string_ljust | ( | const exprt & | string_obj, |
| const exprt & | width_arg, | ||
| const exprt & | fill_arg, | ||
| const locationt & | location ) |
Handle str.ljust() method (constant-only support).
Handle str.lower() method.
| string_obj | String object |
| location | Source location |
| exprt string_handler::handle_string_lstrip | ( | const exprt & | str_expr, |
| const exprt & | chars_arg, | ||
| const locationt & | location ) |
Handle str.lstrip() method.
| str_expr | String expression |
| chars_arg | Optional characters to strip (empty for whitespace) |
| location | Source location |
| exprt string_handler::handle_string_membership | ( | exprt & | lhs, |
| exprt & | rhs, | ||
| const nlohmann::json & | element ) |
Handle 'in' operator for strings.
| lhs | Substring to find |
| rhs | String to search in |
| element | JSON element with location info |
| exprt string_handler::handle_string_operations | ( | const std::string & | op, |
| exprt & | lhs, | ||
| exprt & | rhs, | ||
| const nlohmann::json & | left, | ||
| const nlohmann::json & | right, | ||
| const nlohmann::json & | element ) |
Handle general string operations.
| op | Operation type |
| lhs | Left operand |
| rhs | Right operand |
| left | JSON node for left operand |
| right | JSON node for right operand |
| element | JSON element with location info |
| exprt string_handler::handle_string_partition | ( | const exprt & | string_obj, |
| const exprt & | sep_arg, | ||
| const locationt & | location ) |
Handle str.partition() method (constant-only support).
| exprt string_handler::handle_string_removeprefix | ( | const exprt & | string_obj, |
| const exprt & | prefix_arg, | ||
| const locationt & | location ) |
Handle str.removeprefix() method.
| exprt string_handler::handle_string_removesuffix | ( | const exprt & | string_obj, |
| const exprt & | suffix_arg, | ||
| const locationt & | location ) |
Handle str.removesuffix() method.
Handle string repetition.
| lhs | Left operand |
| rhs | Right operand |
| exprt string_handler::handle_string_replace | ( | const exprt & | string_obj, |
| const exprt & | old_arg, | ||
| const exprt & | new_arg, | ||
| const exprt & | count_arg, | ||
| const locationt & | location ) |
Handle str.replace() method.
| string_obj | String object |
| old_arg | Substring to replace |
| new_arg | Replacement substring |
| count_arg | Maximum replacements (-1 for all) |
| location | Source location |
| exprt string_handler::handle_string_rfind | ( | const exprt & | string_obj, |
| const exprt & | find_arg, | ||
| const locationt & | location ) |
Handle str.rfind() method.
| string_obj | String object |
| find_arg | String to check |
| location | Source location |
| exprt string_handler::handle_string_rfind_range | ( | const exprt & | string_obj, |
| const exprt & | find_arg, | ||
| const exprt & | start_arg, | ||
| const exprt & | end_arg, | ||
| const locationt & | location ) |
Handle str.rfind() with start/end.
| string_obj | String object |
| find_arg | String to check |
| start_arg | Start index |
| end_arg | End index (INT_MIN means default) |
| location | Source location |
| exprt string_handler::handle_string_rindex | ( | const nlohmann::json & | call, |
| const exprt & | string_obj, | ||
| const exprt & | find_arg, | ||
| const locationt & | location ) |
Handle str.rindex() method (rfind that raises on not-found).
| call | Call AST node (for the temp/exception location) |
| string_obj | String object |
| find_arg | Substring to locate |
| location | Source location |
| ValueError | if substring is not found. |
| exprt string_handler::handle_string_rindex_range | ( | const nlohmann::json & | call, |
| const exprt & | string_obj, | ||
| const exprt & | find_arg, | ||
| const exprt & | start_arg, | ||
| const exprt & | end_arg, | ||
| const locationt & | location ) |
Handle str.rindex() with start/end.
| call | Call AST node (for the temp/exception location) |
| string_obj | String object |
| find_arg | Substring to locate |
| start_arg | Start index |
| end_arg | End index (INT_MIN means default) |
| location | Source location |
| ValueError | if substring is not found. |
| exprt string_handler::handle_string_rjust | ( | const exprt & | string_obj, |
| const exprt & | width_arg, | ||
| const exprt & | fill_arg, | ||
| const locationt & | location ) |
Handle str.rjust() method (constant-only support).
| exprt string_handler::handle_string_rpartition | ( | const exprt & | string_obj, |
| const exprt & | sep_arg, | ||
| const locationt & | location ) |
Handle str.rpartition() method (constant-only support).
Like partition() but splits at the last occurrence of the separator.
| exprt string_handler::handle_string_rstrip | ( | const exprt & | str_expr, |
| const exprt & | chars_arg, | ||
| const locationt & | location ) |
Handle str.rstrip() method.
| str_expr | String expression |
| chars_arg | Optional characters to strip (empty for whitespace) |
| location | Source location |
| exprt string_handler::handle_string_splitlines | ( | const nlohmann::json & | call, |
| const exprt & | string_obj, | ||
| const locationt & | location, | ||
| bool | keepends = false ) |
Handle str.splitlines() method (constant-only support).
| exprt string_handler::handle_string_startswith | ( | const exprt & | string_obj, |
| const exprt & | prefix_arg, | ||
| const locationt & | location ) |
Handle str.startswith() method.
| string_obj | String object |
| prefix_arg | Prefix to check |
| location | Source location |
| exprt string_handler::handle_string_strip | ( | const exprt & | str_expr, |
| const exprt & | chars_arg, | ||
| const locationt & | location ) |
Handle str.strip() method.
| str_expr | String expression |
| chars_arg | Optional characters to strip (empty for whitespace) |
| location | Source location |
| exprt string_handler::handle_string_swapcase | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Handle str.swapcase() method.
Handle str.title() method.
| exprt string_handler::handle_string_to_float | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Convert a runtime string expression to a double via the __python_str_to_float operational model.
Handles both char arrays and char pointers (function parameters). The caller is responsible for gating the conversion on handle_string_is_float() and raising ValueError on the invalid path.
| string_obj | The string argument to convert |
| location | Source location for error reporting |
| exprt string_handler::handle_string_to_int | ( | const exprt & | string_obj, |
| const exprt & | base_arg, | ||
| const locationt & | location ) |
Convert a string to an integer using Python's int() function.
| string_obj | The string expression to convert |
| base_arg | The base for conversion (2-36, or 0 for auto-detect) |
| location | Source location for error reporting |
| exprt string_handler::handle_string_to_int_base10 | ( | const exprt & | string_obj, |
| const locationt & | location ) |
Convert a string to an integer using base 10 (convenience method).
| string_obj | The string expression to convert |
| location | Source location for error reporting |
Handle str.upper() method.
| string_obj | String object |
| location | Source location |
| exprt string_handler::handle_string_zfill | ( | const exprt & | string_obj, |
| const exprt & | width_arg, | ||
| const locationt & | location ) |
Handle str.zfill() method (constant-only support).
Check if an expression is a zero-length array.
| expr | Expression to check |
| exprt string_handler::join_unfoldable_iterable | ( | const exprt & | separator, |
| const nlohmann::json & | call_json ) |
|
static |
The nondet str buffer size: –nondet-str-length plus the NUL.
| std::string string_handler::process_format_spec | ( | const nlohmann::json & | format_spec | ) |
Process format specification for f-strings.
| format_spec | JSON format specification |
| exprt string_handler::read_tagged_str_receiver | ( | const exprt & | receiver, |
| const std::string & | method, | ||
| const nlohmann::json & | call_json ) |
The str a tagged receiver of str-only method method holds, after raising AttributeError on the paths where it holds another type.
Any other receiver is returned unchanged.
|
inline |
| exprt string_handler::try_handle_len_string_fast_path | ( | const nlohmann::json & | call_json, |
| const exprt & | arg_expr ) |
Try fast-path folding for len() when argument is string-like.
Returns non-nil when a compile-time or cheap symbolic shortcut is available. Returns nil_exprt when caller should fall back to the generic len() handling path.