|
ESBMC
Efficient SMT-based Context-Bounded Model Checker
|
The single owner of per-instance element-type tracking for the Python frontend: "which types does this container instance hold?". More...
#include <element_type_registry.h>
Public Types | |
| using | entry = std::pair<std::string, typet> |
| A recorded element: its symbol id, empty when the type came from an annotation rather than a concrete element expression, and its type. | |
| using | entries = std::vector<entry> |
Public Member Functions | |
| void | record (const std::string &id, const std::string &elem_id, const typet &elem_type, type_slot slot=type_slot::elements) |
| void | set_element_type (const std::string &id, size_t index, const typet &elem_type, type_slot slot=type_slot::elements) |
Updates the type of the element at index. | |
| void | assign (const std::string &id, const typet &elem_type, type_slot slot=type_slot::elements) |
Replaces id's entries with one entry of elem_type, which index lookups past it reuse as the type of every element. | |
| void | assign_from (const std::string &from, const std::string &to, type_slot slot=type_slot::elements) |
Replaces to's entries with from's, leaving to untouched when from has nothing recorded. | |
| void | append_from (const std::string &from, const std::string &to, size_t times=1, type_slot slot=type_slot::elements) |
Appends from's entries onto to's, times over. | |
| void | pop_last (const std::string &id, type_slot slot=type_slot::elements) |
| Removes the most recently recorded entry, mirroring a pop from the end. | |
| void | reverse (const std::string &id, type_slot slot=type_slot::elements) |
| Mirrors an in-place reversal so later index-based lookups stay correct. | |
| void | replace (const std::string &id, size_t index, const std::string &elem_id, const typet &elem_type, type_slot slot=type_slot::elements) |
Mirrors a store of elem_id, of type elem_type, into element index. | |
| size_t | size (const std::string &id, type_slot slot=type_slot::elements) const |
| const entries * | find (const std::string &id, type_slot slot=type_slot::elements) const |
| The recorded entries, or nullptr when nothing is recorded. | |
| typet | element_type (const std::string &id, size_t index=0, type_slot slot=type_slot::elements) const |
The type at index, falling back to the first element's type when index is out of bounds. | |
| typet | last_element_type (const std::string &id, type_slot slot=type_slot::elements) const |
| The last recorded element's type; nil when nothing is recorded. | |
| std::string | element_id (const std::string &id, size_t index, type_slot slot=type_slot::elements) const |
The symbol id at index; empty when out of bounds or unrecorded. | |
| bool | has_mixed_numeric (const std::string &id, type_slot slot=type_slot::elements) const |
| True when both integer and floating-point elements are recorded. | |
| bool | mixes_str_and_number (const std::string &id, type_slot slot=type_slot::elements) const |
| True when both a string and a number (int, float or bool) are recorded: no single static type reads every element. | |
| typet | uniform_element_type (const std::string &id, type_slot slot=type_slot::elements) const |
| The shared type of every recorded element, or nil when nothing is recorded or the elements disagree. | |
| typet | numeric_element_type (const std::string &id, type_slot slot=type_slot::elements) const |
| Non-throwing element type of an all-numeric instance: double_type() when int and float mix (Python promotes int to float), the single shared integer type when every element shares it, otherwise nil — including for any non-numeric element or integers of differing widths. | |
| typet | homogeneous_element_type (const std::string &id, const std::string &func_name, type_slot slot=type_slot::elements) const |
| The common element type for an operation requiring one, promoting an int/float mix to double_type() as Python does. | |
| typet | memoized_pop_type (const std::string &site) const |
| The element type already answered for one syntactic pop() site, or nil when that site has not been answered yet. | |
| void | memoize_pop_type (const std::string &site, const typet &elem_type) |
| void | type_flags (const std::string &id, const type_handler &th, int &type_flag, size_t &float_type_id, type_slot slot=type_slot::elements) const |
| Computes the type_flag and float_type_id encoding shared with __ESBMC_list_sort and __ESBMC_list_lt: 0 = all-integer, 1 = all-float, 2 = string, 3 = mixed int+float. | |
The single owner of per-instance element-type tracking for the Python frontend: "which types does this container instance hold?".
One instance lives on python_converter, so the tracked state has the lifetime of a conversion rather than of the process. Every container operation that must forward element types through it — a slice, a sort, a pop, a dict subscript — consults this registry instead of reaching into a shared map, so a new operation has one place to preserve type information.
Invariant: an instance is either absent or has at least one recorded entry. Only record()/assign()/assign_from()/append_from() create entries and each adds at least one, so queries never observe a present-but-empty instance. find() therefore answers both "is anything recorded?" and "is this known?".
| using element_type_registry::entries = std::vector<entry> |
| using element_type_registry::entry = std::pair<std::string, typet> |
A recorded element: its symbol id, empty when the type came from an annotation rather than a concrete element expression, and its type.
| void element_type_registry::append_from | ( | const std::string & | from, |
| const std::string & | to, | ||
| size_t | times = 1, | ||
| type_slot | slot = type_slot::elements ) |
Appends from's entries onto to's, times over.
from is read once, so to == from (a l = l * n repetition) repeats the original sequence rather than compounding what earlier repetitions appended.
| void element_type_registry::assign | ( | const std::string & | id, |
| const typet & | elem_type, | ||
| type_slot | slot = type_slot::elements ) |
Replaces id's entries with one entry of elem_type, which index lookups past it reuse as the type of every element.
| void element_type_registry::assign_from | ( | const std::string & | from, |
| const std::string & | to, | ||
| type_slot | slot = type_slot::elements ) |
Replaces to's entries with from's, leaving to untouched when from has nothing recorded.
| std::string element_type_registry::element_id | ( | const std::string & | id, |
| size_t | index, | ||
| type_slot | slot = type_slot::elements ) const |
The symbol id at index; empty when out of bounds or unrecorded.
Unlike element_type(), an out-of-bounds index does not fall back.
| typet element_type_registry::element_type | ( | const std::string & | id, |
| size_t | index = 0, | ||
| type_slot | slot = type_slot::elements ) const |
The type at index, falling back to the first element's type when index is out of bounds.
Nil when nothing is recorded.
| const element_type_registry::entries * element_type_registry::find | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) const |
The recorded entries, or nullptr when nothing is recorded.
| bool element_type_registry::has_mixed_numeric | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) const |
True when both integer and floating-point elements are recorded.
| typet element_type_registry::homogeneous_element_type | ( | const std::string & | id, |
| const std::string & | func_name, | ||
| type_slot | slot = type_slot::elements ) const |
The common element type for an operation requiring one, promoting an int/float mix to double_type() as Python does.
Nil when nothing is recorded.
| std::runtime_error | when the elements mix incompatibly, naming func_name. |
| typet element_type_registry::last_element_type | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) const |
The last recorded element's type; nil when nothing is recorded.
| void element_type_registry::memoize_pop_type | ( | const std::string & | site, |
| const typet & | elem_type ) |
| typet element_type_registry::memoized_pop_type | ( | const std::string & | site | ) | const |
The element type already answered for one syntactic pop() site, or nil when that site has not been answered yet.
The assignment path converts its RHS more than once, and a pop consumes a recorded entry, so the second conversion must replay the first answer rather than consume another entry (#4780).
| bool element_type_registry::mixes_str_and_number | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) const |
True when both a string and a number (int, float or bool) are recorded: no single static type reads every element.
| typet element_type_registry::numeric_element_type | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) const |
Non-throwing element type of an all-numeric instance: double_type() when int and float mix (Python promotes int to float), the single shared integer type when every element shares it, otherwise nil — including for any non-numeric element or integers of differing widths.
| void element_type_registry::pop_last | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) |
Removes the most recently recorded entry, mirroring a pop from the end.
Erases the instance when its last entry goes, preserving the invariant.
| void element_type_registry::record | ( | const std::string & | id, |
| const std::string & | elem_id, | ||
| const typet & | elem_type, | ||
| type_slot | slot = type_slot::elements ) |
| void element_type_registry::replace | ( | const std::string & | id, |
| size_t | index, | ||
| const std::string & | elem_id, | ||
| const typet & | elem_type, | ||
| type_slot | slot = type_slot::elements ) |
Mirrors a store of elem_id, of type elem_type, into element index.
An index outside the recorded entries (e.g. one not known statically) erases the instance, since no single entry can be updated.
| void element_type_registry::reverse | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) |
Mirrors an in-place reversal so later index-based lookups stay correct.
A no-op for an unknown or single-element instance.
| void element_type_registry::set_element_type | ( | const std::string & | id, |
| size_t | index, | ||
| const typet & | elem_type, | ||
| type_slot | slot = type_slot::elements ) |
Updates the type of the element at index.
| size_t element_type_registry::size | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) const |
| void element_type_registry::type_flags | ( | const std::string & | id, |
| const type_handler & | th, | ||
| int & | type_flag, | ||
| size_t & | float_type_id, | ||
| type_slot | slot = type_slot::elements ) const |
Computes the type_flag and float_type_id encoding shared with __ESBMC_list_sort and __ESBMC_list_lt: 0 = all-integer, 1 = all-float, 2 = string, 3 = mixed int+float.
Inspects one instance only; a caller comparing two operands (e.g. an int list against a float list) must merge both flags itself.
| typet element_type_registry::uniform_element_type | ( | const std::string & | id, |
| type_slot | slot = type_slot::elements ) const |
The shared type of every recorded element, or nil when nothing is recorded or the elements disagree.