Skip to content

Commit 45f469d

Browse files
authored
Merge pull request #3025 from tautschnig/cpp_namet
Use cpp_namet's and namet's constructors
2 parents 0c55a08 + 7f817ca commit 45f469d

13 files changed

+48
-206
lines changed

src/cpp/cpp_constructor.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,10 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
228228
// there is always a constructor for non-PODs
229229
assert(constructor_name!="");
230230

231-
irept cpp_name(ID_cpp_name);
232-
cpp_name.get_sub().push_back(irept(ID_name));
233-
cpp_name.get_sub().back().set(ID_identifier, constructor_name);
234-
cpp_name.get_sub().back().set(ID_C_source_location, source_location);
235-
236231
side_effect_expr_function_callt function_call;
237232
function_call.add_source_location()=source_location;
238-
function_call.function().swap(static_cast<exprt&>(cpp_name));
233+
function_call.function() =
234+
cpp_namet(constructor_name, source_location).as_expr();
239235
function_call.arguments().reserve(operands_tc.size());
240236

241237
for(exprt::operandst::iterator

src/cpp/cpp_declarator_converter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ symbolt &cpp_declarator_convertert::convert(
4545
type.swap(declarator.name().get_sub().back());
4646
declarator.type().subtype()=type;
4747
cpp_typecheck.typecheck_type(type);
48-
irept name(ID_name);
49-
name.set(ID_identifier, "("+cpp_type2name(type)+")");
48+
cpp_namet::namet name("(" + cpp_type2name(type) + ")");
5049
declarator.name().get_sub().back().swap(name);
5150
}
5251

src/cpp/cpp_destructor.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
102102
// there is always a destructor for non-PODs
103103
assert(dtor_name!="");
104104

105-
irept cpp_name(ID_cpp_name);
106-
cpp_name.get_sub().push_back(irept(ID_name));
107-
cpp_name.get_sub().back().set(ID_identifier, dtor_name);
108-
cpp_name.get_sub().back().set(ID_C_source_location, source_location);
105+
cpp_namet cpp_name(dtor_name, source_location);
109106

110107
exprt member(ID_member);
111108
member.add(ID_component_cpp_name) = cpp_name;

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
301301
typet type=static_cast<typet &>(declarator.name().get_sub()[1]);
302302
declarator.type().subtype()=type;
303303

304-
irept name(ID_name);
305-
name.set(ID_identifier, "("+cpp_type2name(type)+")");
304+
cpp_namet::namet name("(" + cpp_type2name(type) + ")");
306305
declarator.name().get_sub().back().swap(name);
307306
}
308307

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 18 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,8 @@ void cpp_typecheckt::default_ctor(
162162
const irep_idt &base_name,
163163
cpp_declarationt &ctor) const
164164
{
165-
exprt name(ID_name);
166-
name.set(ID_identifier, base_name);
167-
name.add_source_location()=source_location;
168-
169165
cpp_declaratort decl;
170-
decl.name().id(ID_cpp_name);
171-
decl.name().move_to_sub(name);
166+
decl.name() = cpp_namet(base_name, source_location);
172167
decl.type()=typet(ID_function_type);
173168
decl.type().subtype().make_nil();
174169
decl.add_source_location()=source_location;
@@ -204,20 +199,10 @@ void cpp_typecheckt::default_cpctor(
204199
std::string param_identifier("ref");
205200

206201
// Compound name
207-
irept comp_name(ID_name);
208-
comp_name.set(ID_identifier, symbol.base_name);
209-
comp_name.set(ID_C_source_location, source_location);
210-
211-
cpp_namet cppcomp;
212-
cppcomp.move_to_sub(comp_name);
202+
const cpp_namet cppcomp(symbol.base_name, source_location);
213203

214204
// Parameter name
215-
exprt param_name(ID_name);
216-
param_name.add_source_location()=source_location;
217-
param_name.set(ID_identifier, param_identifier);
218-
219-
cpp_namet cpp_parameter;
220-
cpp_parameter.move_to_sub(param_name);
205+
const cpp_namet cpp_parameter(param_identifier, source_location);
221206

222207
// Parameter declarator
223208
cpp_declaratort parameter_tor;
@@ -230,8 +215,7 @@ void cpp_typecheckt::default_cpctor(
230215
cpp_declarationt parameter_decl;
231216
parameter_decl.set(ID_type, ID_merged_type);
232217
auto &sub = to_type_with_subtypes(parameter_decl.type()).subtypes();
233-
sub.push_back(
234-
static_cast<const typet &>(static_cast<const irept &>(cppcomp)));
218+
sub.push_back(cppcomp.as_type());
235219
irept constnd(ID_const);
236220
sub.push_back(static_cast<const typet &>(constnd));
237221
parameter_decl.move_to_operands(parameter_tor);
@@ -264,18 +248,12 @@ void cpp_typecheckt::default_cpctor(
264248
irep_idt ctor_name=parsymb.base_name;
265249

266250
// Call the parent default copy constructor
267-
exprt name(ID_name);
268-
name.set(ID_identifier, ctor_name);
269-
name.add_source_location()=source_location;
270-
271-
cpp_namet cppname;
272-
cppname.move_to_sub(name);
251+
const cpp_namet cppname(ctor_name, source_location);
273252

274253
codet mem_init(ID_member_initializer);
275254
mem_init.add_source_location()=source_location;
276255
mem_init.set(ID_member, cppname);
277-
mem_init.copy_to_operands(
278-
static_cast<const exprt &>(static_cast<const irept &>(cpp_parameter)));
256+
mem_init.copy_to_operands(cpp_parameter.as_expr());
279257
initializers.move_to_sub(mem_init);
280258
}
281259
}
@@ -289,12 +267,7 @@ void cpp_typecheckt::default_cpctor(
289267
// Take care of virtual tables
290268
if(mem_c.get_bool(ID_is_vtptr))
291269
{
292-
exprt name(ID_name);
293-
name.set(ID_identifier, mem_c.get_base_name());
294-
name.add_source_location()=source_location;
295-
296-
cpp_namet cppname;
297-
cppname.move_to_sub(name);
270+
const cpp_namet cppname(mem_c.get_base_name(), source_location);
298271

299272
const symbolt &virtual_table_symbol_type =
300273
lookup(mem_c.type().subtype().get(ID_identifier));
@@ -327,21 +300,15 @@ void cpp_typecheckt::default_cpctor(
327300

328301
const irep_idt &mem_name = mem_c.get_base_name();
329302

330-
exprt name(ID_name);
331-
name.set(ID_identifier, mem_name);
332-
name.add_source_location()=source_location;
333-
334-
cpp_namet cppname;
335-
cppname.move_to_sub(name);
303+
const cpp_namet cppname(mem_name, source_location);
336304

337305
codet mem_init(ID_member_initializer);
338306
mem_init.set(ID_member, cppname);
339307
mem_init.add_source_location()=source_location;
340308

341309
exprt memberexpr(ID_member);
342310
memberexpr.set(ID_component_cpp_name, cppname);
343-
memberexpr.copy_to_operands(
344-
static_cast<const exprt &>(static_cast<const irept &>(cpp_parameter)));
311+
memberexpr.copy_to_operands(cpp_parameter.as_expr());
345312
memberexpr.add_source_location()=source_location;
346313

347314
if(mem_c.type().id() == ID_array)
@@ -400,12 +367,8 @@ void cpp_typecheckt::default_assignop(
400367
auto &args_decl_type_sub = to_type_with_subtypes(args_decl.type()).subtypes();
401368

402369
args_decl.type().id(ID_merged_type);
403-
args_decl_type_sub.push_back(typet(ID_cpp_name));
404-
args_decl_type_sub.back().get_sub().push_back(irept(ID_name));
405-
args_decl_type_sub.back().get_sub().back().set(
406-
ID_identifier, symbol.base_name);
407-
args_decl_type_sub.back().get_sub().back().set(
408-
ID_C_source_location, source_location);
370+
args_decl_type_sub.push_back(
371+
cpp_namet(symbol.base_name, source_location).as_type());
409372

410373
args_decl_type_sub.push_back(typet(ID_const));
411374
args_decl.operands().push_back(exprt(ID_cpp_declarator));
@@ -414,9 +377,7 @@ void cpp_typecheckt::default_assignop(
414377
cpp_declaratort &args_decl_declor=
415378
static_cast<cpp_declaratort&>(args_decl.operands().back());
416379

417-
args_decl_declor.name().id(ID_cpp_name);
418-
args_decl_declor.name().get_sub().push_back(irept(ID_name));
419-
args_decl_declor.name().get_sub().back().add(ID_identifier).id(arg_name);
380+
args_decl_declor.name() = cpp_namet(arg_name, source_location);
420381
args_decl_declor.add_source_location()=source_location;
421382

422383
args_decl_declor.type()=pointer_type(typet(ID_nil));
@@ -522,8 +483,6 @@ void cpp_typecheckt::check_member_initializers(
522483
const irept &initializer=*init_it;
523484
assert(initializer.is_not_nil());
524485

525-
assert(initializer.get(ID_member)==ID_cpp_name);
526-
527486
const cpp_namet &member_name=
528487
to_cpp_name(initializer.find(ID_member));
529488

@@ -665,15 +624,7 @@ void cpp_typecheckt::full_member_initialization(
665624
// ifthenelse only gets to have two operands (instead of three)
666625
codet cond(ID_ifthenelse);
667626

668-
{
669-
cpp_namet most_derived;
670-
most_derived.get_sub().push_back(irept(ID_name));
671-
most_derived.get_sub().back().set(ID_identifier, "@most_derived");
672-
673-
exprt tmp;
674-
tmp.swap(most_derived);
675-
cond.move_to_operands(tmp);
676-
}
627+
cond.copy_to_operands(cpp_namet("@most_derived").as_expr());
677628

678629
code_blockt block;
679630

@@ -683,11 +634,7 @@ void cpp_typecheckt::full_member_initialization(
683634
if(!cpp_is_pod(symb.type))
684635
{
685636
// default initializer
686-
irept name(ID_name);
687-
name.set(ID_identifier, symb.base_name);
688-
689-
cpp_namet cppname;
690-
cppname.move_to_sub(name);
637+
const cpp_namet cppname(symb.base_name);
691638

692639
codet mem_init(ID_member_initializer);
693640
mem_init.set(ID_member, cppname);
@@ -723,8 +670,6 @@ void cpp_typecheckt::full_member_initialization(
723670
{
724671
irept initializer=*m_it;
725672

726-
assert(initializer.get(ID_member)==ID_cpp_name);
727-
728673
const cpp_namet &member_name=
729674
to_cpp_name(initializer.find(ID_member));
730675

@@ -772,11 +717,7 @@ void cpp_typecheckt::full_member_initialization(
772717
// Call the parent default constructor
773718
if(!found)
774719
{
775-
irept name(ID_name);
776-
name.set(ID_identifier, ctor_name);
777-
778-
cpp_namet cppname;
779-
cppname.move_to_sub(name);
720+
const cpp_namet cppname(ctor_name);
780721

781722
codet mem_init(ID_member_initializer);
782723
mem_init.set(ID_member, cppname);
@@ -789,15 +730,7 @@ void cpp_typecheckt::full_member_initialization(
789730
// ifthenelse only gets to have two operands (instead of three)
790731
codet cond(ID_ifthenelse);
791732

792-
{
793-
cpp_namet most_derived;
794-
most_derived.get_sub().push_back(irept(ID_name));
795-
most_derived.get_sub().back().set(ID_identifier, "@most_derived");
796-
797-
exprt tmp;
798-
tmp.swap(most_derived);
799-
cond.move_to_operands(tmp);
800-
}
733+
cond.copy_to_operands(cpp_namet("@most_derived").as_expr());
801734

802735
{
803736
codet tmp(ID_member_initializer);
@@ -815,12 +748,7 @@ void cpp_typecheckt::full_member_initialization(
815748
// Take care of virtual tables
816749
if(c.get_bool(ID_is_vtptr))
817750
{
818-
exprt name(ID_name);
819-
name.set(ID_identifier, c.get_base_name());
820-
name.add_source_location() = c.source_location();
821-
822-
cpp_namet cppname;
823-
cppname.move_to_sub(name);
751+
const cpp_namet cppname(c.get_base_name(), c.source_location());
824752

825753
const symbolt &virtual_table_symbol_type =
826754
lookup(c.type().subtype().get(ID_identifier));
@@ -892,11 +820,7 @@ void cpp_typecheckt::full_member_initialization(
892820
// then its default constructor is called.
893821
if(!found && !cpp_is_pod(c.type()))
894822
{
895-
irept name(ID_name);
896-
name.set(ID_identifier, mem_name);
897-
898-
cpp_namet cppname;
899-
cppname.move_to_sub(name);
823+
cpp_namet cppname(mem_name);
900824

901825
codet mem_init(ID_member_initializer);
902826
mem_init.set(ID_member, cppname);

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
10811081
{
10821082
// To take care of the possible virtual case,
10831083
// we build the function as a member expression.
1084-
irept func_name(ID_name);
1085-
func_name.set(ID_identifier, component.get_base_name());
1086-
cpp_namet cpp_func_name;
1087-
cpp_func_name.get_sub().push_back(func_name);
1084+
const cpp_namet cpp_func_name(component.get_base_name());
10881085

10891086
exprt member_func(ID_member);
10901087
member_func.add(ID_component_cpp_name)=cpp_func_name;
@@ -1312,10 +1309,7 @@ bool cpp_typecheckt::reference_binding(
13121309
{
13131310
// To take care of the possible virtual case,
13141311
// we build the function as a member expression.
1315-
irept func_name(ID_name);
1316-
func_name.set(ID_identifier, component.get_base_name());
1317-
cpp_namet cpp_func_name;
1318-
cpp_func_name.get_sub().push_back(func_name);
1312+
const cpp_namet cpp_func_name(component.get_base_name());
13191313

13201314
exprt member_func(ID_member);
13211315
member_func.add(ID_component_cpp_name)=cpp_func_name;

src/cpp/cpp_typecheck_declaration.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ void cpp_typecheckt::convert_anonymous_union(
4141
// unnamed object
4242
std::string identifier="#anon_union"+std::to_string(anon_counter++);
4343

44-
irept name(ID_name);
45-
name.set(ID_identifier, identifier);
46-
name.set(ID_C_source_location, declaration.source_location());
47-
48-
cpp_namet cpp_name;
49-
cpp_name.move_to_sub(name);
44+
const cpp_namet cpp_name(identifier, declaration.source_location());
5045
cpp_declaratort declarator;
5146
declarator.name()=cpp_name;
5247

src/cpp/cpp_typecheck_destructor.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,8 @@ void cpp_typecheckt::default_dtor(
3232
assert(symbol.type.id()==ID_struct ||
3333
symbol.type.id()==ID_union);
3434

35-
irept name;
36-
name.id(ID_name);
37-
name.set(ID_identifier, "~"+id2string(symbol.base_name));
38-
name.set(ID_C_source_location, symbol.location);
39-
4035
cpp_declaratort decl;
41-
decl.name().id(ID_cpp_name);
42-
decl.name().move_to_sub(name);
36+
decl.name() = cpp_namet("~" + id2string(symbol.base_name), symbol.location);
4337
decl.type().id(ID_function_type);
4438
decl.type().subtype().make_nil();
4539

@@ -78,11 +72,7 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
7872
{
7973
if(c.get_bool(ID_is_vtptr))
8074
{
81-
exprt name(ID_name);
82-
name.set(ID_identifier, c.get_base_name());
83-
84-
cpp_namet cppname;
85-
cppname.move_to_sub(name);
75+
const cpp_namet cppname(c.get_base_name());
8676

8777
const symbolt &virtual_table_symbol_type =
8878
lookup(c.type().subtype().get(ID_identifier));
@@ -123,12 +113,7 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
123113
cpp_is_pod(type))
124114
continue;
125115

126-
irept name(ID_name);
127-
name.set(ID_identifier, cit->get_base_name());
128-
name.set(ID_C_source_location, source_location);
129-
130-
cpp_namet cppname;
131-
cppname.get_sub().push_back(name);
116+
const cpp_namet cppname(cit->get_base_name(), source_location);
132117

133118
exprt member(ID_ptrmember, type);
134119
member.set(ID_component_cpp_name, cppname);

0 commit comments

Comments
 (0)