Skip to content

Commit c1f7f85

Browse files
andreast271tautschnig
authored andcommitted
C++ front-end: Enable compilation with DEBUG defined
Some of the code inside #ifdef DEBUG ... #endif had become stale. Also perform minor style improvements.
1 parent ba576c4 commit c1f7f85

12 files changed

+99
-103
lines changed

src/cpp/cpp_declaration.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1515

1616
void cpp_declarationt::output(std::ostream &out) const
1717
{
18-
out << "is_template: " << is_template() << "\n";
19-
out << "storage: " << storage_spec().pretty() << "\n";
20-
out << "template_type: " << template_type().pretty() << "\n";
21-
out << "type: " << type().pretty() << "\n";
18+
out << "is_template: " << is_template() << '\n';
19+
out << "storage: " << storage_spec().pretty() << '\n';
20+
out << "template_type: " << template_type().pretty() << '\n';
21+
out << "type: " << type().pretty() << '\n';
2222

23-
out << "Declarators:" << "\n";
23+
out << "Declarators:" << '\n';
2424

2525
for(const auto &it : declarators())
2626
{
2727
it.output(out);
28-
out << "\n";
28+
out << '\n';
2929
}
3030
}
3131

src/cpp/cpp_declarator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1818

1919
void cpp_declaratort::output(std::ostream &out) const
2020
{
21-
out << " name: " << name().pretty() << "\n";
22-
out << " type: " << type().pretty() << "\n";
23-
out << " value: " << value().pretty() << "\n";
24-
out << " init_args: " << init_args().pretty() << "\n";
25-
out << " method_qualifier: " << method_qualifier().pretty() << "\n";
21+
out << " name: " << name().pretty() << '\n';
22+
out << " type: " << type().pretty() << '\n';
23+
out << " value: " << value().pretty() << '\n';
24+
out << " init_args: " << init_args().pretty() << '\n';
25+
out << " method_qualifier: " << method_qualifier().pretty() << '\n';
2626
}
2727

2828
typet cpp_declaratort::merge_type(const typet &declaration_type) const

src/cpp/cpp_declarator_converter.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,24 @@ void cpp_declarator_convertert::handle_initializer(
344344
}
345345
else
346346
{
347-
#if 0
348-
cpp_typecheck.error().source_location=declarator.name());
347+
#if 0
348+
cpp_typecheck.error().source_location=source_location;
349349

350350
if(is_code)
351-
cpp_typecheck.str << "body of function `"
351+
{
352+
cpp_typecheck.error() << "body of function `"
352353
<< symbol.display_name()
353-
<< "' has already been defined";
354+
<< "' has already been defined" << messaget::eom;
355+
}
354356
else
355-
cpp_typecheck.str << "symbol `"
357+
{
358+
cpp_typecheck.error() << "symbol `"
356359
<< symbol.display_name()
357-
<< "' already has an initializer";
360+
<< "' already has an initializer" << messaget::eom;
361+
}
358362

359363
throw 0;
360-
#endif
364+
#endif
361365
}
362366
}
363367

src/cpp/cpp_namespace_spec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1717

1818
void cpp_namespace_spect::output(std::ostream &out) const
1919
{
20-
out << " namespace: " << get_namespace() << "\n";
20+
out << " namespace: " << get_namespace() << '\n';
2121
}

src/cpp/cpp_scopes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void cpp_scopest::print_current(std::ostream &out) const
7676
do
7777
{
7878
scope->print_fields(out);
79-
out << "\n";
79+
out << '\n';
8080
scope=&scope->get_parent();
8181
}
8282
while(!scope->is_root_scope());

src/cpp/cpp_typecheck.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,11 @@ bool cpp_typecheckt::contains_cpp_name(const exprt &expr)
337337
{
338338
if(expr.id() == ID_cpp_name || expr.id() == ID_cpp_declaration)
339339
return true;
340-
forall_operands(it, expr)
341-
if(contains_cpp_name(*it))
340+
341+
for(const exprt &op : expr.operands())
342+
{
343+
if(contains_cpp_name(op))
342344
return true;
345+
}
343346
return false;
344347
}

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,12 +1325,9 @@ void cpp_typecheckt::typecheck_member_function(
13251325
if(symbol_table.move(symbol, new_symbol))
13261326
{
13271327
error().source_location=symbol.location;
1328-
error() << "failed to insert new method symbol: "
1329-
<< symbol.name << "\n"
1330-
<< "name of previous symbol: "
1331-
<< new_symbol->name << "\n"
1332-
<< "location of previous symbol: "
1333-
<< new_symbol->location << eom;
1328+
error() << "failed to insert new method symbol: " << symbol.name << '\n'
1329+
<< "name of previous symbol: " << new_symbol->name << '\n'
1330+
<< "location of previous symbol: " << new_symbol->location << eom;
13341331

13351332
throw 0;
13361333
}

src/cpp/cpp_typecheck_declaration.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
66
77
\********************************************************************/
88

9-
109
/// \file
1110
/// C++ Language Type Checking
1211

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ void cpp_typecheckt::typecheck_method_application(
23442344
static_cast<const cpp_template_args_tct &>(template_args));
23452345
add_method_body(&method_symbol);
23462346
#ifdef DEBUG
2347-
std::cout << "MAP for " << symbol << ":" << std::endl;
2347+
std::cout << "MAP for " << symbol << ":\n";
23482348
template_map.print(std::cout);
23492349
#endif
23502350
}

src/cpp/cpp_typecheck_method_bodies.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ void cpp_typecheckt::typecheck_method_bodies()
3737
continue;
3838

3939
#ifdef DEBUG
40-
std::cout << "convert_method_body: " << method_symbol.name << std::endl;
41-
std::cout << " is_not_nil: " << body.is_not_nil() << std::endl;
42-
std::cout << " !is_zero: " << (!body.is_zero()) << std::endl;
40+
std::cout << "convert_method_body: " << method_symbol.name << '\n';
41+
std::cout << " is_not_nil: " << body.is_not_nil() << '\n';
42+
std::cout << " !is_zero: " << (!body.is_zero()) << '\n';
4343
#endif
4444
if(body.is_not_nil() && !body.is_zero())
4545
convert_function(method_symbol);
@@ -51,22 +51,18 @@ void cpp_typecheckt::typecheck_method_bodies()
5151
void cpp_typecheckt::add_method_body(symbolt *_method_symbol)
5252
{
5353
#ifdef DEBUG
54-
std::cout << "add_method_body: " << _method_symbol->name << std::endl;
54+
std::cout << "add_method_body: " << _method_symbol->name << '\n';
5555
#endif
56-
57-
// We have to prevent the same method to be added multiple times
58-
// otherwise we get duplicated symbol prefixes
59-
if(methods_seen.find(_method_symbol->name) != methods_seen.end())
56+
// Converting a method body might add method bodies for methods that we have
57+
// already analyzed. Adding the same method more than once causes duplicated
58+
// symbol prefixes, therefore we have to keep track.
59+
if(methods_seen.insert(_method_symbol->name).second)
6060
{
61+
method_bodies.push_back(
62+
method_bodyt(_method_symbol, template_map, instantiation_stack));
63+
}
6164
#ifdef DEBUG
62-
std::cout << " already exists" << std::endl;
65+
else
66+
std::cout << " already exists\n";
6367
#endif
64-
return;
65-
}
66-
method_bodies.push_back(
67-
method_bodyt(_method_symbol, template_map, instantiation_stack));
68-
69-
// Converting a method body might add method bodies for methods
70-
// that we have already analyzed. Hence, we have to keep track.
71-
methods_seen.insert(_method_symbol->name);
7268
}

0 commit comments

Comments
 (0)