ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
element_type_registry.h
Go to the documentation of this file.
1#pragma once
2
3#include <util/irep/type.h>
4
5#include <array>
6#include <cassert>
7#include <string>
8#include <unordered_map>
9#include <utility>
10#include <vector>
11
12class type_handler;
13
34
49{
50public:
53 using entry = std::pair<std::string, typet>;
54 using entries = std::vector<entry>;
55
56 void record(
57 const std::string &id,
58 const std::string &elem_id,
59 const typet &elem_type,
61
64 const std::string &id,
65 size_t index,
66 const typet &elem_type,
68
71 void assign(
72 const std::string &id,
73 const typet &elem_type,
75
78 void assign_from(
79 const std::string &from,
80 const std::string &to,
82
86 void append_from(
87 const std::string &from,
88 const std::string &to,
89 size_t times = 1,
91
94 void pop_last(const std::string &id, type_slot slot = type_slot::elements);
95
98 void reverse(const std::string &id, type_slot slot = type_slot::elements);
99
103 void replace(
104 const std::string &id,
105 size_t index,
106 const std::string &elem_id,
107 const typet &elem_type,
109
110 size_t
111 size(const std::string &id, type_slot slot = type_slot::elements) const;
112
114 const entries *
115 find(const std::string &id, type_slot slot = type_slot::elements) const;
116
120 const std::string &id,
121 size_t index = 0,
122 type_slot slot = type_slot::elements) const;
123
126 const std::string &id,
127 type_slot slot = type_slot::elements) const;
128
131 std::string element_id(
132 const std::string &id,
133 size_t index,
134 type_slot slot = type_slot::elements) const;
135
138 const std::string &id,
139 type_slot slot = type_slot::elements) const;
140
144 const std::string &id,
145 type_slot slot = type_slot::elements) const;
146
150 const std::string &id,
151 type_slot slot = type_slot::elements) const;
152
158 const std::string &id,
159 type_slot slot = type_slot::elements) const;
160
167 const std::string &id,
168 const std::string &func_name,
169 type_slot slot = type_slot::elements) const;
170
176 typet memoized_pop_type(const std::string &site) const;
177
178 void memoize_pop_type(const std::string &site, const typet &elem_type);
179
185 void type_flags(
186 const std::string &id,
187 const type_handler &th,
188 int &type_flag,
189 size_t &float_type_id,
190 type_slot slot = type_slot::elements) const;
191
192private:
193 using slot_map = std::unordered_map<std::string, entries>;
194
195 slot_map &map_for(type_slot slot)
196 {
197 assert(slot < type_slot::slot_count);
198 return maps_[static_cast<size_t>(slot)];
199 }
200
201 const slot_map &map_for(type_slot slot) const
202 {
203 assert(slot < type_slot::slot_count);
204 return maps_[static_cast<size_t>(slot)];
205 }
206
207 std::array<slot_map, static_cast<size_t>(type_slot::slot_count)> maps_;
208
210 std::unordered_map<std::string, typet> pop_memo_;
211};
The single owner of per-instance element-type tracking for the Python frontend: "which types does thi...
Definition element_type_registry.h:49
std::vector< entry > entries
Definition element_type_registry.h:54
void reverse(const std::string &id, type_slot slot=type_slot::elements)
Mirrors an in-place reversal so later index-based lookups stay correct.
Definition element_type_registry.cpp:104
const entries * find(const std::string &id, type_slot slot=type_slot::elements) const
The recorded entries, or nullptr when nothing is recorded.
Definition element_type_registry.cpp:131
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.
Definition element_type_registry.cpp:113
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 e...
Definition element_type_registry.cpp:33
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.
Definition element_type_registry.cpp:92
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 e...
Definition element_type_registry.cpp:199
void record(const std::string &id, const std::string &elem_id, const typet &elem_type, type_slot slot=type_slot::elements)
Definition element_type_registry.cpp:24
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.
Definition element_type_registry.cpp:161
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.
Definition element_type_registry.cpp:41
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.
Definition element_type_registry.cpp:57
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() a...
Definition element_type_registry.cpp:262
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.
Definition element_type_registry.cpp:180
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 pr...
Definition element_type_registry.cpp:237
size_t size(const std::string &id, type_slot slot=type_slot::elements) const
Definition element_type_registry.cpp:140
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.
Definition element_type_registry.cpp:221
std::pair< std::string, typet > entry
A recorded element: its symbol id, empty when the type came from an annotation rather than a concrete...
Definition element_type_registry.h:53
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.
Definition element_type_registry.cpp:146
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.
Definition element_type_registry.cpp:72
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.
Definition element_type_registry.cpp:169
void memoize_pop_type(const std::string &site, const typet &elem_type)
Definition element_type_registry.cpp:318
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: ...
Definition element_type_registry.cpp:325
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 an...
Definition element_type_registry.cpp:312
Definition type_handler.h:113
Definition type.h:9
type_slot
Selects which per-instance element-type sequence a registry query addresses.
Definition element_type_registry.h:21
@ slot_count
Number of slots. Not a slot itself.
Definition element_type_registry.h:32
@ elements
The container's own elements: lists, sets, tuples, and a dict's internal keys/values lists.
Definition element_type_registry.h:24
@ dict_value_list_elems
The uniform element type of a literal dict's list-typed values, keyed by its values-list symbol id,...
Definition element_type_registry.h:30
@ dict_value_types
A literal dict's per-value types, keyed by its values-list symbol id.
Definition element_type_registry.h:27