ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
exception_typeid.h
Go to the documentation of this file.
1#pragma once
2
3#include <util/irep/irep.h>
4#include <cstddef>
5#include <map>
6#include <set>
7#include <vector>
8
9class namespacet;
10
30{
31public:
33 exception_typeidt() = default;
34
37 explicit exception_typeidt(const namespacet &ns);
38
40 static constexpr unsigned no_type = 0;
41
47 void register_chain(const std::vector<irep_idt> &chain);
48
53 unsigned id_of(const irep_idt &name);
54
59 bool is_registered(const irep_idt &name) const
60 {
61 // `void_ptr` is the universal pointer catch — always matchable (it catches
62 // any thrown pointer), even when no throw names it explicitly.
63 return name == "void_ptr" || name_to_id.find(name) != name_to_id.end();
64 }
65
69 bool is_subtype(const irep_idt &thrown, const irep_idt &caught) const;
70
73 std::set<unsigned> concrete_subtype_ids(const irep_idt &caught) const;
74
79 std::vector<std::pair<irep_idt, unsigned>>
80 concrete_subtypes(const irep_idt &caught) const;
81
83 std::size_t size() const
84 {
85 return registered_count;
86 }
87
88private:
89 // name <-> id mapping. Ids are assigned in register_chain call order, which
90 // is deterministic for a given program (throws are visited in function-map
91 // then instruction order).
92 std::map<irep_idt, unsigned> name_to_id;
93
94 // Flattened transitive bases per registered type, from throw lists.
95 std::map<irep_idt, std::vector<irep_idt>> direct_bases;
96
97 std::size_t registered_count = 0;
98 unsigned next_id = no_type + 1;
99};
bool is_registered(const irep_idt &name) const
True iff name is an actual program type seen in a throw list (not a primitive #cpp_type,...
Definition exception_typeid.h:59
void register_chain(const std::vector< irep_idt > &chain)
Ingest an exception type's ancestry from a THROW's exception_list (front = dynamic type,...
Definition exception_typeid.cpp:47
bool is_subtype(const irep_idt &thrown, const irep_idt &caught) const
Reflexive-transitive subtype test: true iff thrown equals caught or derives from it transitively thro...
Definition exception_typeid.cpp:81
exception_typeidt()=default
Empty registry (populate with register_chain).
std::vector< std::pair< irep_idt, unsigned > > concrete_subtypes(const irep_idt &caught) const
{ (T, id_of(T)) : T <: caught } over all registered program types.
Definition exception_typeid.cpp:125
std::size_t size() const
Number of registered program types (excludes lazily-added unknowns).
Definition exception_typeid.h:83
unsigned id_of(const irep_idt &name)
Stable id for name.
Definition exception_typeid.cpp:72
static constexpr unsigned no_type
Reserved id meaning "no in-flight exception type".
Definition exception_typeid.h:40
std::set< unsigned > concrete_subtype_ids(const irep_idt &caught) const
{ id_of(T) : T <: caught } over all registered program types — the right-hand side of the catch-match...
Definition exception_typeid.cpp:115
Definition irep_idt.h:12
Definition namespace.h:10