Skip to content

Commit 1899067

Browse files
authored
Merge pull request #4475 from tautschnig/c++-debug-cleanup
C++ front-end: Enable compilation with DEBUG defined [blocks: #1260]
2 parents 5dbc52f + c1f7f85 commit 1899067

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, [email protected]
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, [email protected]
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, [email protected]
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, [email protected]
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
}

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ exprt cpp_typecheck_resolvet::convert_template_parameter(
183183
const cpp_idt &identifier)
184184
{
185185
#ifdef DEBUG
186-
std::cout << "RESOLVE MAP:" << std::endl;
186+
std::cout << "RESOLVE MAP:\n";
187187
cpp_typecheck.template_map.print(std::cout);
188188
#endif
189189

@@ -1183,8 +1183,8 @@ struct_tag_typet cpp_typecheck_resolvet::disambiguate_template_classes(
11831183
if(instance.type.id()!=ID_struct)
11841184
{
11851185
cpp_typecheck.error().source_location=source_location;
1186-
cpp_typecheck.str << "template `"
1187-
<< base_name << "' is not a class";
1186+
cpp_typecheck.error() << "template `"
1187+
<< base_name << "' is not a class" << messaget::eom;
11881188
throw 0;
11891189
}
11901190

@@ -1360,11 +1360,11 @@ exprt cpp_typecheck_resolvet::resolve(
13601360
resolve_scope(cpp_name, base_name, template_args);
13611361

13621362
#ifdef DEBUG
1363-
std::cout << "base name: " << base_name << std::endl;
1364-
std::cout << "template args: " << template_args.pretty() << std::endl;
1365-
std::cout << "original-scope: " << original_scope->prefix << std::endl;
1366-
std::cout << "scope: "
1367-
<< cpp_typecheck.cpp_scopes.current_scope().prefix << std::endl;
1363+
std::cout << "base name: " << base_name << '\n';
1364+
std::cout << "template args: " << template_args.pretty() << '\n';
1365+
std::cout << "original-scope: " << original_scope->prefix << '\n';
1366+
std::cout << "scope: " << cpp_typecheck.cpp_scopes.current_scope().prefix
1367+
<< '\n';
13681368
#endif
13691369

13701370
bool qualified=cpp_name.is_qualified();
@@ -1517,11 +1517,11 @@ exprt cpp_typecheck_resolvet::resolve(
15171517

15181518
filter(identifiers, want);
15191519

1520-
#if 0
1521-
std::cout << "P0 " << base_name << " " << identifiers.size() << "\n";
1520+
#ifdef DEBUG
1521+
std::cout << "P0 " << base_name << " " << identifiers.size() << '\n';
15221522
show_identifiers(base_name, identifiers, std::cout);
1523-
std::cout << "\n";
1524-
#endif
1523+
std::cout << '\n';
1524+
#endif
15251525

15261526
exprt result;
15271527

@@ -1530,20 +1530,20 @@ exprt cpp_typecheck_resolvet::resolve(
15301530

15311531
remove_templates(new_identifiers);
15321532

1533-
#if 0
1534-
std::cout << "P1 " << base_name << " " << new_identifiers.size() << "\n";
1533+
#ifdef DEBUG
1534+
std::cout << "P1 " << base_name << " " << new_identifiers.size() << '\n';
15351535
show_identifiers(base_name, new_identifiers, std::cout);
1536-
std::cout << "\n";
1537-
#endif
1536+
std::cout << '\n';
1537+
#endif
15381538

15391539
// we only want _exact_ matches, without templates!
15401540
exact_match_functions(new_identifiers, fargs);
15411541

1542-
#if 0
1543-
std::cout << "P2 " << base_name << " " << new_identifiers.size() << "\n";
1542+
#ifdef DEBUG
1543+
std::cout << "P2 " << base_name << " " << new_identifiers.size() << '\n';
15441544
show_identifiers(base_name, new_identifiers, std::cout);
1545-
std::cout << "\n";
1546-
#endif
1545+
std::cout << '\n';
1546+
#endif
15471547

15481548
// no exact matches? Try again with function template guessing.
15491549
if(new_identifiers.empty())
@@ -1560,20 +1560,20 @@ exprt cpp_typecheck_resolvet::resolve(
15601560

15611561
disambiguate_functions(new_identifiers, fargs);
15621562

1563-
#if 0
1564-
std::cout << "P3 " << base_name << " " << new_identifiers.size() << "\n";
1563+
#ifdef DEBUG
1564+
std::cout << "P3 " << base_name << " " << new_identifiers.size() << '\n';
15651565
show_identifiers(base_name, new_identifiers, std::cout);
1566-
std::cout << "\n";
1567-
#endif
1566+
std::cout << '\n';
1567+
#endif
15681568
}
15691569

15701570
remove_duplicates(new_identifiers);
15711571

1572-
#if 0
1573-
std::cout << "P4 " << base_name << " " << new_identifiers.size() << "\n";
1572+
#ifdef DEBUG
1573+
std::cout << "P4 " << base_name << " " << new_identifiers.size() << '\n';
15741574
show_identifiers(base_name, new_identifiers, std::cout);
1575-
std::cout << "\n";
1576-
#endif
1575+
std::cout << '\n';
1576+
#endif
15771577

15781578
if(new_identifiers.size()==1)
15791579
{
@@ -1601,20 +1601,20 @@ exprt cpp_typecheck_resolvet::resolve(
16011601
<< "' does not uniquely resolve:\n";
16021602
show_identifiers(base_name, new_identifiers, cpp_typecheck.error());
16031603

1604-
#if 0
1604+
#ifdef DEBUG
16051605
exprt e1=*new_identifiers.begin();
16061606
exprt e2=*(++new_identifiers.begin());
1607-
cpp_typecheck.str << "e1==e2: " << (e1==e2) << '\n';
1608-
cpp_typecheck.str << "e1.type==e2.type: " << (e1.type()==e2.type())
1609-
<< '\n';
1610-
cpp_typecheck.str << "e1.id()==e2.id(): " << (e1.id()==e2.id())
1611-
<< '\n';
1612-
cpp_typecheck.str << "e1.iden==e2.iden: "
1613-
<< (e1.get(ID_identifier)==e2.get(ID_identifier))
1614-
<< '\n';
1615-
cpp_typecheck.str << "e1.iden:: " << e1.get(ID_identifier) << '\n';
1616-
cpp_typecheck.str << "e2.iden:: " << e2.get(ID_identifier) << '\n';
1617-
#endif
1607+
cpp_typecheck.error() << "e1==e2: " << (e1 == e2) << '\n';
1608+
cpp_typecheck.error()
1609+
<< "e1.type==e2.type: " << (e1.type() == e2.type()) << '\n';
1610+
cpp_typecheck.error()
1611+
<< "e1.id()==e2.id(): " << (e1.id() == e2.id()) << '\n';
1612+
cpp_typecheck.error()
1613+
<< "e1.iden==e2.iden: "
1614+
<< (e1.get(ID_identifier) == e2.get(ID_identifier)) << '\n';
1615+
cpp_typecheck.error() << "e1.iden:: " << e1.get(ID_identifier) << '\n';
1616+
cpp_typecheck.error() << "e2.iden:: " << e2.get(ID_identifier) << '\n';
1617+
#endif
16181618
}
16191619

16201620
if(fargs.in_use)

0 commit comments

Comments
 (0)