10 #ifndef CPROVER_UTIL_IREP_H
11 #define CPROVER_UTIL_IREP_H
26 #if !defined(NAMED_SUB_IS_FORWARD_LIST) && !defined(_GLIBCXX_DEBUG)
27 # define NAMED_SUB_IS_FORWARD_LIST 1
30 #if NAMED_SUB_IS_FORWARD_LIST
40 #if defined(__GNUC__) && __GNUC__ >= 14
43 inline const std::string &
59 template <
bool enabled>
67 unsigned ref_count = 1;
88 template <
typename treet,
typename named_subtreest,
bool sharing = true>
93 typedef std::vector<treet>
subt;
139 :
data(std::move(_data)),
147 template <
typename derivedt,
typename named_subtreest>
163 :
data(new
dt(std::move(_id), std::move(_named_sub), std::move(_sub)))
191 std::cout <<
"COPY MOVE\n";
199 std::cout <<
"ASSIGN\n";
219 std::cout <<
"ASSIGN MOVE\n";
256 template <
typename derivedt,
typename named_subtreest>
261 template <
typename derivedt,
typename named_subtreest>
277 :
data(std::move(_id), std::move(_named_sub), std::move(_sub))
356 : public non_sharing_treet<
359 #if NAMED_SUB_IS_FORWARD_LIST
360 forward_list_as_mapt<irep_idt, irept>>
362 std::map<irep_idt, irept>>
370 return id() == ID_nil;
374 return id() != ID_nil;
382 :
baset(_id, _named_sub, _sub)
418 add(name, std::move(irep));
420 void set(
const irep_idt &name,
const long long value);
431 return !(*
this==other);
453 std::size_t
hash()
const;
458 std::string
pretty(
unsigned indent=0,
unsigned max_indent=0)
const;
461 {
return !name.
empty() && name[0]==
'#'; }
509 template <
typename derivedt,
typename named_subtreest>
513 std::cout <<
"DETACH1: " << data <<
'\n';
521 std::cout <<
"ALLOCATED " << data <<
'\n';
524 else if(data->ref_count > 1)
527 data =
new dt(*old_data);
530 std::cout <<
"ALLOCATED " << data <<
'\n';
534 remove_ref(old_data);
540 std::cout <<
"DETACH2: " << data <<
'\n';
544 template <
typename derivedt,
typename named_subtreest>
547 if(old_data == &empty_d)
551 nonrecursive_destructor(old_data);
557 std::cout <<
"R: " << old_data <<
" " << old_data->
ref_count <<
'\n';
564 std::cout <<
"D: " << pretty() <<
'\n';
565 std::cout <<
"DELETING " << old_data->
data <<
" " << old_data <<
'\n';
567 std::cout <<
"DEALLOCATING " << old_data <<
"\n";
574 std::cout <<
"DONE\n";
582 template <
typename derivedt,
typename named_subtreest>
586 std::vector<dt *> stack(1, old_data);
588 while(!stack.empty())
590 dt *d = stack.back();
591 stack.erase(--stack.end());
604 for(
typename named_subt::iterator it = d->
named_sub.begin();
608 stack.push_back(it->second.data);
609 it->second.data = &empty_d;
612 for(
typename subt::iterator it = d->
sub.begin(); it != d->
sub.end(); it++)
614 stack.push_back(it->data);
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
There are a large number of kinds of tree structured or tree-like data in CPROVER.
static std::size_t number_of_non_comments(const named_subt &)
count the number of named_sub elements that are not comments
bool get_bool(const irep_idt &name) const
bool operator==(const irept &other) const
void set(const irep_idt &name, irept irep)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
void move_to_named_sub(const irep_idt &name, irept &irep)
std::size_t get_size_t(const irep_idt &name) const
bool operator!=(const irept &other) const
const irept & find(const irep_idt &name) const
bool ordering(const irept &other) const
defines ordering on the internal representation
const subt & get_sub() const
const irep_idt & get(const irep_idt &name) const
named_subt & get_named_sub()
irept(const irep_idt &_id)
const std::string & id_string() const
void remove(const irep_idt &name)
void set(const irep_idt &name, const irep_idt &value)
const named_subt & get_named_sub() const
void set_size_t(const irep_idt &name, const std::size_t value)
irept(const irep_idt &_id, const named_subt &_named_sub, const subt &_sub)
int compare(const irept &i) const
defines ordering on the internal representation comments are ignored
bool operator<(const irept &other) const
defines ordering on the internal representation
const irep_idt & id() const
bool full_eq(const irept &other) const
long long get_long_long(const irep_idt &name) const
std::size_t full_hash() const
signed int get_int(const irep_idt &name) const
static bool is_comment(const irep_idt &name)
void move_to_sub(irept &irep)
void id(const irep_idt &_data)
const std::string & get_string(const irep_idt &name) const
irept & add(const irep_idt &name)
Base class for tree-like data structures without sharing.
non_sharing_treet(irep_idt _id, named_subt _named_sub, subt _sub)
non_sharing_treet()=default
non_sharing_treet(irep_idt _id)
typename dt::named_subt named_subt
Base class for tree-like data structures with sharing.
sharing_treet(irep_idt _id, named_subt _named_sub, subt _sub)
sharing_treet(irep_idt _id)
sharing_treet & operator=(sharing_treet &&irep)
static void remove_ref(dt *old_data)
typename dt::named_subt named_subt
sharing_treet tree_implementationt
Used to refer to this class from derived classes.
sharing_treet(const sharing_treet &irep)
static void nonrecursive_destructor(dt *old_data)
Does the same as remove_ref, but using an explicit stack instead of recursion.
sharing_treet & operator=(const sharing_treet &irep)
sharing_treet(sharing_treet &&irep)
A node with data in a tree, it contains:
named_subtreest named_subt
tree_nodet(irep_idt _data, named_subt _named_sub, subt _sub)
std::vector< treet > subt
tree_nodet(irep_idt _data)
irep_idt data
This irep_idt is the only place to store data in an tree node.
dstring_hash irep_id_hash
const irept & get_nil_irep()
const std::string & id2string(const irep_idt &d)
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
#define POSTCONDITION(CONDITION)
std::string as_string(const ai_verifier_statust &status)
Makes a status message string from a status.
static std::string diagnostics_as_string(const irep_pretty_diagnosticst &irep)
Helper to give us some diagnostic in a usable form on assertion failure.
bool operator()(const irept &i1, const irept &i2) const
std::size_t operator()(const irept &irep) const
std::size_t operator()(const irept &irep) const
irep_pretty_diagnosticst(const irept &irep)
Used in tree_nodet for activating or not reference counting.