Skip to content

Commit 57ee7ac

Browse files
committed
Remove irep_namet
It is impossible for irep_namet to be different from irep_idt as irep_ids.h creates dstringt/std::string constants, which will then be used 1) as arguments to irept::get, which requires an irep_namet, hence irep_namet must be the same type as whichever irep_ids.h generates; 2) in equality tests comparing to irept::id(), hence irep_idt must be the same type as whichever irep_ids.h generates. While all of this may be fixable (by providing suitable operators for whatever type irep_ids.h generates), we do not seem to use irep_namet anywhere other than irep.{h,cpp}, and will most likely run into many implicit assumptions that irep_idt and irep_namet are the same type.
1 parent 308c503 commit 57ee7ac

File tree

8 files changed

+46
-59
lines changed

8 files changed

+46
-59
lines changed

src/cpp/cpp_type2name.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static std::string irep2name(const irept &irep)
6161
else
6262
result += ',';
6363

64-
result += do_prefix(name2string(named_sub.first));
64+
result += do_prefix(id2string(named_sub.first));
6565

6666
result += '=';
6767
result += irep2name(named_sub.second);
@@ -78,7 +78,7 @@ static std::string irep2name(const irept &irep)
7878
first=false;
7979
else
8080
result+=',';
81-
result += do_prefix(name2string(named_sub.first));
81+
result += do_prefix(id2string(named_sub.first));
8282
result+='=';
8383
result += irep2name(named_sub.second);
8484
}

src/util/README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,12 @@ standard data structures as in irept.
7272

7373
\subsection irep_idt_section Strings: dstringt, the string_container and the ID_*
7474

75-
Within cbmc, strings are represented using \ref irep_idt or \ref irep_namet
76-
for keys to [named_sub](\ref irept::dt::named_sub). By default these are both
77-
typedefed to \ref dstringt. For debugging purposes you can set `USE_STD_STRING`,
78-
in which case they are both typedefed to `std::string`. You can also easily
79-
convert an [irep_idt](\ref irep_idt) or [irep_namet](\ref irep_namet) to a
80-
`std::string` using the [id2string](\ref id2string) or
81-
[name2string](\ref name2string) function, respectively, or either of them to a
82-
`char*` using the [c_str()](\ref dstringt::c_str) member function.
75+
Within cbmc, strings are represented using \ref irep_idt. By default this is
76+
typedefed to \ref dstringt. For debugging purposes you can set `USE_STD_STRING`
77+
to change this typedef to `std::string`. You can also easily convert an
78+
[irep_idt](\ref irep_idt) to a `std::string` using the
79+
[id2string](\ref id2string) function, or to a `char*` using the
80+
[c_str()](\ref dstringt::c_str) member function.
8381

8482
\ref dstringt stores a string as an index into a large
8583
static table of strings. This makes it easy to compare if two

src/util/dstring.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Author: Daniel Kroening, [email protected]
2727
/// copies of the same string you only have to store the whole string once,
2828
/// which saves space.
2929
///
30-
/// `irep_idt` and `irep_namet` are typedef-ed to \ref dstringt in irep.h unless
31-
/// `USE_STD_STRING` is set.
30+
/// `irep_idt` is typedef-ed to \ref dstringt in irep.h unless `USE_STD_STRING`
31+
/// is set.
3232
///
3333
///
3434
/// Note: Marked final to disable inheritance. No virtual destructor, so

src/util/irep.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const irept &get_nil_irep()
2424
return nil_rep_storage;
2525
}
2626

27-
void irept::move_to_named_sub(const irep_namet &name, irept &irep)
27+
void irept::move_to_named_sub(const irep_idt &name, irept &irep)
2828
{
2929
#ifdef SHARING
3030
detach();
@@ -42,7 +42,7 @@ void irept::move_to_sub(irept &irep)
4242
get_sub().back().swap(irep);
4343
}
4444

45-
const irep_idt &irept::get(const irep_namet &name) const
45+
const irep_idt &irept::get(const irep_idt &name) const
4646
{
4747
const named_subt &s = get_named_sub();
4848
named_subt::const_iterator it=s.find(name);
@@ -55,27 +55,27 @@ const irep_idt &irept::get(const irep_namet &name) const
5555
return it->second.id();
5656
}
5757

58-
bool irept::get_bool(const irep_namet &name) const
58+
bool irept::get_bool(const irep_idt &name) const
5959
{
6060
return get(name)==ID_1;
6161
}
6262

63-
int irept::get_int(const irep_namet &name) const
63+
int irept::get_int(const irep_idt &name) const
6464
{
6565
return unsafe_string2int(get_string(name));
6666
}
6767

68-
std::size_t irept::get_size_t(const irep_namet &name) const
68+
std::size_t irept::get_size_t(const irep_idt &name) const
6969
{
7070
return unsafe_string2size_t(get_string(name));
7171
}
7272

73-
long long irept::get_long_long(const irep_namet &name) const
73+
long long irept::get_long_long(const irep_idt &name) const
7474
{
7575
return unsafe_string2signedlonglong(get_string(name));
7676
}
7777

78-
void irept::set(const irep_namet &name, const long long value)
78+
void irept::set(const irep_idt &name, const long long value)
7979
{
8080
#ifdef USE_DSTRING
8181
add(name).id(to_dstring(value));
@@ -84,7 +84,7 @@ void irept::set(const irep_namet &name, const long long value)
8484
#endif
8585
}
8686

87-
void irept::set_size_t(const irep_namet &name, const std::size_t value)
87+
void irept::set_size_t(const irep_idt &name, const std::size_t value)
8888
{
8989
#ifdef USE_DSTRING
9090
add(name).id(to_dstring(value));
@@ -93,7 +93,7 @@ void irept::set_size_t(const irep_namet &name, const std::size_t value)
9393
#endif
9494
}
9595

96-
void irept::remove(const irep_namet &name)
96+
void irept::remove(const irep_idt &name)
9797
{
9898
#if NAMED_SUB_IS_FORWARD_LIST
9999
return get_named_sub().remove(name);
@@ -103,7 +103,7 @@ void irept::remove(const irep_namet &name)
103103
#endif
104104
}
105105

106-
const irept &irept::find(const irep_namet &name) const
106+
const irept &irept::find(const irep_idt &name) const
107107
{
108108
const named_subt &s = get_named_sub();
109109
auto it = s.find(name);
@@ -113,13 +113,13 @@ const irept &irept::find(const irep_namet &name) const
113113
return it->second;
114114
}
115115

116-
irept &irept::add(const irep_namet &name)
116+
irept &irept::add(const irep_idt &name)
117117
{
118118
named_subt &s = get_named_sub();
119119
return s[name];
120120
}
121121

122-
irept &irept::add(const irep_namet &name, irept irep)
122+
irept &irept::add(const irep_idt &name, irept irep)
123123
{
124124
named_subt &s = get_named_sub();
125125

src/util/irep.h

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ Author: Daniel Kroening, [email protected]
3535

3636
#ifdef USE_DSTRING
3737
typedef dstringt irep_idt;
38-
typedef dstringt irep_namet;
3938
// NOLINTNEXTLINE(readability/identifiers)
4039
typedef dstring_hash irep_id_hash;
4140
#else
4241
#include "string_hash.h"
4342
typedef std::string irep_idt;
44-
typedef std::string irep_namet;
4543
// NOLINTNEXTLINE(readability/identifiers)
4644
typedef string_hash irep_id_hash;
4745
#endif
@@ -55,15 +53,6 @@ inline const std::string &id2string(const irep_idt &d)
5553
#endif
5654
}
5755

58-
inline const std::string &name2string(const irep_namet &n)
59-
{
60-
#ifdef USE_DSTRING
61-
return as_string(n);
62-
#else
63-
return n;
64-
#endif
65-
}
66-
6756
#ifdef IREP_DEBUG
6857
#include <iostream>
6958
#endif
@@ -91,7 +80,7 @@ struct ref_count_ift<true>
9180
/// actually a \ref dstringt and thus an integer which is a reference into a
9281
/// string table.)
9382
///
94-
/// * \ref irept::dt::named_sub : A map from `irep_namet` (a string) to \ref
83+
/// * \ref irept::dt::named_sub : A map from `irep_idt` (a string) to \ref
9584
/// irept. This is used for named children, i.e. subexpressions, parameters,
9685
/// etc. Children whose name begins with '#' are ignored by the
9786
/// default \ref operator==.
@@ -376,9 +365,9 @@ class irept
376365
irept,
377366
#endif
378367
#if NAMED_SUB_IS_FORWARD_LIST
379-
forward_list_as_mapt<irep_namet, irept>>
368+
forward_list_as_mapt<irep_idt, irept>>
380369
#else
381-
std::map<irep_namet, irept>>
370+
std::map<irep_idt, irept>>
382371
#endif
383372
{
384373
public:
@@ -413,35 +402,35 @@ class irept
413402
void id(const irep_idt &_data)
414403
{ write().data=_data; }
415404

416-
const irept &find(const irep_namet &name) const;
417-
irept &add(const irep_namet &name);
418-
irept &add(const irep_namet &name, irept irep);
405+
const irept &find(const irep_idt &name) const;
406+
irept &add(const irep_idt &name);
407+
irept &add(const irep_idt &name, irept irep);
419408

420-
const std::string &get_string(const irep_namet &name) const
409+
const std::string &get_string(const irep_idt &name) const
421410
{
422411
return id2string(get(name));
423412
}
424413

425-
const irep_idt &get(const irep_namet &name) const;
426-
bool get_bool(const irep_namet &name) const;
427-
signed int get_int(const irep_namet &name) const;
428-
std::size_t get_size_t(const irep_namet &name) const;
429-
long long get_long_long(const irep_namet &name) const;
414+
const irep_idt &get(const irep_idt &name) const;
415+
bool get_bool(const irep_idt &name) const;
416+
signed int get_int(const irep_idt &name) const;
417+
std::size_t get_size_t(const irep_idt &name) const;
418+
long long get_long_long(const irep_idt &name) const;
430419

431-
void set(const irep_namet &name, const irep_idt &value)
420+
void set(const irep_idt &name, const irep_idt &value)
432421
{
433422
add(name, irept(value));
434423
}
435-
void set(const irep_namet &name, irept irep)
424+
void set(const irep_idt &name, irept irep)
436425
{
437426
add(name, std::move(irep));
438427
}
439-
void set(const irep_namet &name, const long long value);
440-
void set_size_t(const irep_namet &name, const std::size_t value);
428+
void set(const irep_idt &name, const long long value);
429+
void set_size_t(const irep_idt &name, const std::size_t value);
441430

442-
void remove(const irep_namet &name);
431+
void remove(const irep_idt &name);
443432
void move_to_sub(irept &irep);
444-
void move_to_named_sub(const irep_namet &name, irept &irep);
433+
void move_to_named_sub(const irep_idt &name, irept &irep);
445434

446435
bool operator==(const irept &other) const;
447436

@@ -476,7 +465,7 @@ class irept
476465

477466
std::string pretty(unsigned indent=0, unsigned max_indent=0) const;
478467

479-
static bool is_comment(const irep_namet &name)
468+
static bool is_comment(const irep_idt &name)
480469
{ return !name.empty() && name[0]=='#'; }
481470

482471
/// count the number of named_sub elements that are not comments

src/util/lispirep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void irep2lisp(const irept &src, lispexprt &dest)
7878
{
7979
lispexprt name;
8080
name.type=lispexprt::String;
81-
name.value = name2string(irep_entry.first);
81+
name.value = id2string(irep_entry.first);
8282
dest.push_back(name);
8383

8484
lispexprt sub;

src/util/type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ class typet:public irept
7878
return static_cast<source_locationt &>(add(ID_C_source_location));
7979
}
8080

81-
typet &add_type(const irep_namet &name)
81+
typet &add_type(const irep_idt &name)
8282
{
8383
return static_cast<typet &>(add(name));
8484
}
8585

86-
const typet &find_type(const irep_namet &name) const
86+
const typet &find_type(const irep_idt &name) const
8787
{
8888
return static_cast<const typet &>(find(name));
8989
}

src/util/xml_irep.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void convert(
3434
if(!irept::is_comment(irep_entry.first))
3535
{
3636
xmlt &x_nsub = xml.new_element("named_sub");
37-
x_nsub.set_attribute("name", name2string(irep_entry.first));
37+
x_nsub.set_attribute("name", id2string(irep_entry.first));
3838
convert(irep_entry.second, x_nsub);
3939
}
4040
}
@@ -44,7 +44,7 @@ void convert(
4444
if(!irept::is_comment(irep_entry.first))
4545
{
4646
xmlt &x_com = xml.new_element("comment");
47-
x_com.set_attribute("name", name2string(irep_entry.first));
47+
x_com.set_attribute("name", id2string(irep_entry.first));
4848
convert(irep_entry.second, x_com);
4949
}
5050
}

0 commit comments

Comments
 (0)