diff --git a/src/cpp/cpp_declaration.cpp b/src/cpp/cpp_declaration.cpp index a01afe82aa3..42fdb2d44c3 100644 --- a/src/cpp/cpp_declaration.cpp +++ b/src/cpp/cpp_declaration.cpp @@ -15,17 +15,17 @@ Author: Daniel Kroening, kroening@cs.cmu.edu void cpp_declarationt::output(std::ostream &out) const { - out << "is_template: " << is_template() << "\n"; - out << "storage: " << storage_spec().pretty() << "\n"; - out << "template_type: " << template_type().pretty() << "\n"; - out << "type: " << type().pretty() << "\n"; + out << "is_template: " << is_template() << '\n'; + out << "storage: " << storage_spec().pretty() << '\n'; + out << "template_type: " << template_type().pretty() << '\n'; + out << "type: " << type().pretty() << '\n'; - out << "Declarators:" << "\n"; + out << "Declarators:" << '\n'; for(const auto &it : declarators()) { it.output(out); - out << "\n"; + out << '\n'; } } diff --git a/src/cpp/cpp_declarator.cpp b/src/cpp/cpp_declarator.cpp index e348309dc47..6a146f328d9 100644 --- a/src/cpp/cpp_declarator.cpp +++ b/src/cpp/cpp_declarator.cpp @@ -18,11 +18,11 @@ Author: Daniel Kroening, kroening@cs.cmu.edu void cpp_declaratort::output(std::ostream &out) const { - out << " name: " << name().pretty() << "\n"; - out << " type: " << type().pretty() << "\n"; - out << " value: " << value().pretty() << "\n"; - out << " init_args: " << init_args().pretty() << "\n"; - out << " method_qualifier: " << method_qualifier().pretty() << "\n"; + out << " name: " << name().pretty() << '\n'; + out << " type: " << type().pretty() << '\n'; + out << " value: " << value().pretty() << '\n'; + out << " init_args: " << init_args().pretty() << '\n'; + out << " method_qualifier: " << method_qualifier().pretty() << '\n'; } typet cpp_declaratort::merge_type(const typet &declaration_type) const diff --git a/src/cpp/cpp_declarator_converter.cpp b/src/cpp/cpp_declarator_converter.cpp index 13b9f4821ac..4f58318c421 100644 --- a/src/cpp/cpp_declarator_converter.cpp +++ b/src/cpp/cpp_declarator_converter.cpp @@ -344,20 +344,24 @@ void cpp_declarator_convertert::handle_initializer( } else { - #if 0 - cpp_typecheck.error().source_location=declarator.name()); +#if 0 + cpp_typecheck.error().source_location=source_location; if(is_code) - cpp_typecheck.str << "body of function `" + { + cpp_typecheck.error() << "body of function `" << symbol.display_name() - << "' has already been defined"; + << "' has already been defined" << messaget::eom; + } else - cpp_typecheck.str << "symbol `" + { + cpp_typecheck.error() << "symbol `" << symbol.display_name() - << "' already has an initializer"; + << "' already has an initializer" << messaget::eom; + } throw 0; - #endif +#endif } } diff --git a/src/cpp/cpp_namespace_spec.cpp b/src/cpp/cpp_namespace_spec.cpp index 2254f2b7d34..e24164c08a4 100644 --- a/src/cpp/cpp_namespace_spec.cpp +++ b/src/cpp/cpp_namespace_spec.cpp @@ -17,5 +17,5 @@ Author: Daniel Kroening, kroening@cs.cmu.edu void cpp_namespace_spect::output(std::ostream &out) const { - out << " namespace: " << get_namespace() << "\n"; + out << " namespace: " << get_namespace() << '\n'; } diff --git a/src/cpp/cpp_scopes.cpp b/src/cpp/cpp_scopes.cpp index 71a6b1edfbf..aa7ea8c6a99 100644 --- a/src/cpp/cpp_scopes.cpp +++ b/src/cpp/cpp_scopes.cpp @@ -76,7 +76,7 @@ void cpp_scopest::print_current(std::ostream &out) const do { scope->print_fields(out); - out << "\n"; + out << '\n'; scope=&scope->get_parent(); } while(!scope->is_root_scope()); diff --git a/src/cpp/cpp_typecheck.cpp b/src/cpp/cpp_typecheck.cpp index f5076cb4abc..bd76880f14d 100644 --- a/src/cpp/cpp_typecheck.cpp +++ b/src/cpp/cpp_typecheck.cpp @@ -337,8 +337,11 @@ bool cpp_typecheckt::contains_cpp_name(const exprt &expr) { if(expr.id() == ID_cpp_name || expr.id() == ID_cpp_declaration) return true; - forall_operands(it, expr) - if(contains_cpp_name(*it)) + + for(const exprt &op : expr.operands()) + { + if(contains_cpp_name(op)) return true; + } return false; } diff --git a/src/cpp/cpp_typecheck_compound_type.cpp b/src/cpp/cpp_typecheck_compound_type.cpp index ebaa795f453..d9e0fe6fa85 100644 --- a/src/cpp/cpp_typecheck_compound_type.cpp +++ b/src/cpp/cpp_typecheck_compound_type.cpp @@ -1325,12 +1325,9 @@ void cpp_typecheckt::typecheck_member_function( if(symbol_table.move(symbol, new_symbol)) { error().source_location=symbol.location; - error() << "failed to insert new method symbol: " - << symbol.name << "\n" - << "name of previous symbol: " - << new_symbol->name << "\n" - << "location of previous symbol: " - << new_symbol->location << eom; + error() << "failed to insert new method symbol: " << symbol.name << '\n' + << "name of previous symbol: " << new_symbol->name << '\n' + << "location of previous symbol: " << new_symbol->location << eom; throw 0; } diff --git a/src/cpp/cpp_typecheck_declaration.cpp b/src/cpp/cpp_typecheck_declaration.cpp index 800b494859b..1a221e29254 100644 --- a/src/cpp/cpp_typecheck_declaration.cpp +++ b/src/cpp/cpp_typecheck_declaration.cpp @@ -6,7 +6,6 @@ Author: Daniel Kroening, kroening@cs.cmu.edu \********************************************************************/ - /// \file /// C++ Language Type Checking diff --git a/src/cpp/cpp_typecheck_expr.cpp b/src/cpp/cpp_typecheck_expr.cpp index e924a77baf1..3ee7d3756d3 100644 --- a/src/cpp/cpp_typecheck_expr.cpp +++ b/src/cpp/cpp_typecheck_expr.cpp @@ -2344,7 +2344,7 @@ void cpp_typecheckt::typecheck_method_application( static_cast(template_args)); add_method_body(&method_symbol); #ifdef DEBUG - std::cout << "MAP for " << symbol << ":" << std::endl; + std::cout << "MAP for " << symbol << ":\n"; template_map.print(std::cout); #endif } diff --git a/src/cpp/cpp_typecheck_method_bodies.cpp b/src/cpp/cpp_typecheck_method_bodies.cpp index 53427c23121..e8389d721be 100644 --- a/src/cpp/cpp_typecheck_method_bodies.cpp +++ b/src/cpp/cpp_typecheck_method_bodies.cpp @@ -37,9 +37,9 @@ void cpp_typecheckt::typecheck_method_bodies() continue; #ifdef DEBUG - std::cout << "convert_method_body: " << method_symbol.name << std::endl; - std::cout << " is_not_nil: " << body.is_not_nil() << std::endl; - std::cout << " !is_zero: " << (!body.is_zero()) << std::endl; + std::cout << "convert_method_body: " << method_symbol.name << '\n'; + std::cout << " is_not_nil: " << body.is_not_nil() << '\n'; + std::cout << " !is_zero: " << (!body.is_zero()) << '\n'; #endif if(body.is_not_nil() && !body.is_zero()) convert_function(method_symbol); @@ -51,22 +51,18 @@ void cpp_typecheckt::typecheck_method_bodies() void cpp_typecheckt::add_method_body(symbolt *_method_symbol) { #ifdef DEBUG - std::cout << "add_method_body: " << _method_symbol->name << std::endl; + std::cout << "add_method_body: " << _method_symbol->name << '\n'; #endif - - // We have to prevent the same method to be added multiple times - // otherwise we get duplicated symbol prefixes - if(methods_seen.find(_method_symbol->name) != methods_seen.end()) + // Converting a method body might add method bodies for methods that we have + // already analyzed. Adding the same method more than once causes duplicated + // symbol prefixes, therefore we have to keep track. + if(methods_seen.insert(_method_symbol->name).second) { + method_bodies.push_back( + method_bodyt(_method_symbol, template_map, instantiation_stack)); + } #ifdef DEBUG - std::cout << " already exists" << std::endl; + else + std::cout << " already exists\n"; #endif - return; - } - method_bodies.push_back( - method_bodyt(_method_symbol, template_map, instantiation_stack)); - - // Converting a method body might add method bodies for methods - // that we have already analyzed. Hence, we have to keep track. - methods_seen.insert(_method_symbol->name); } diff --git a/src/cpp/cpp_typecheck_resolve.cpp b/src/cpp/cpp_typecheck_resolve.cpp index 529a5703f9b..6590838142d 100644 --- a/src/cpp/cpp_typecheck_resolve.cpp +++ b/src/cpp/cpp_typecheck_resolve.cpp @@ -183,7 +183,7 @@ exprt cpp_typecheck_resolvet::convert_template_parameter( const cpp_idt &identifier) { #ifdef DEBUG - std::cout << "RESOLVE MAP:" << std::endl; + std::cout << "RESOLVE MAP:\n"; cpp_typecheck.template_map.print(std::cout); #endif @@ -1183,8 +1183,8 @@ struct_tag_typet cpp_typecheck_resolvet::disambiguate_template_classes( if(instance.type.id()!=ID_struct) { cpp_typecheck.error().source_location=source_location; - cpp_typecheck.str << "template `" - << base_name << "' is not a class"; + cpp_typecheck.error() << "template `" + << base_name << "' is not a class" << messaget::eom; throw 0; } @@ -1360,11 +1360,11 @@ exprt cpp_typecheck_resolvet::resolve( resolve_scope(cpp_name, base_name, template_args); #ifdef DEBUG - std::cout << "base name: " << base_name << std::endl; - std::cout << "template args: " << template_args.pretty() << std::endl; - std::cout << "original-scope: " << original_scope->prefix << std::endl; - std::cout << "scope: " - << cpp_typecheck.cpp_scopes.current_scope().prefix << std::endl; + std::cout << "base name: " << base_name << '\n'; + std::cout << "template args: " << template_args.pretty() << '\n'; + std::cout << "original-scope: " << original_scope->prefix << '\n'; + std::cout << "scope: " << cpp_typecheck.cpp_scopes.current_scope().prefix + << '\n'; #endif bool qualified=cpp_name.is_qualified(); @@ -1517,11 +1517,11 @@ exprt cpp_typecheck_resolvet::resolve( filter(identifiers, want); - #if 0 - std::cout << "P0 " << base_name << " " << identifiers.size() << "\n"; +#ifdef DEBUG + std::cout << "P0 " << base_name << " " << identifiers.size() << '\n'; show_identifiers(base_name, identifiers, std::cout); - std::cout << "\n"; - #endif + std::cout << '\n'; +#endif exprt result; @@ -1530,20 +1530,20 @@ exprt cpp_typecheck_resolvet::resolve( remove_templates(new_identifiers); - #if 0 - std::cout << "P1 " << base_name << " " << new_identifiers.size() << "\n"; +#ifdef DEBUG + std::cout << "P1 " << base_name << " " << new_identifiers.size() << '\n'; show_identifiers(base_name, new_identifiers, std::cout); - std::cout << "\n"; - #endif + std::cout << '\n'; +#endif // we only want _exact_ matches, without templates! exact_match_functions(new_identifiers, fargs); - #if 0 - std::cout << "P2 " << base_name << " " << new_identifiers.size() << "\n"; +#ifdef DEBUG + std::cout << "P2 " << base_name << " " << new_identifiers.size() << '\n'; show_identifiers(base_name, new_identifiers, std::cout); - std::cout << "\n"; - #endif + std::cout << '\n'; +#endif // no exact matches? Try again with function template guessing. if(new_identifiers.empty()) @@ -1560,20 +1560,20 @@ exprt cpp_typecheck_resolvet::resolve( disambiguate_functions(new_identifiers, fargs); - #if 0 - std::cout << "P3 " << base_name << " " << new_identifiers.size() << "\n"; +#ifdef DEBUG + std::cout << "P3 " << base_name << " " << new_identifiers.size() << '\n'; show_identifiers(base_name, new_identifiers, std::cout); - std::cout << "\n"; - #endif + std::cout << '\n'; +#endif } remove_duplicates(new_identifiers); - #if 0 - std::cout << "P4 " << base_name << " " << new_identifiers.size() << "\n"; +#ifdef DEBUG + std::cout << "P4 " << base_name << " " << new_identifiers.size() << '\n'; show_identifiers(base_name, new_identifiers, std::cout); - std::cout << "\n"; - #endif + std::cout << '\n'; +#endif if(new_identifiers.size()==1) { @@ -1601,20 +1601,20 @@ exprt cpp_typecheck_resolvet::resolve( << "' does not uniquely resolve:\n"; show_identifiers(base_name, new_identifiers, cpp_typecheck.error()); - #if 0 +#ifdef DEBUG exprt e1=*new_identifiers.begin(); exprt e2=*(++new_identifiers.begin()); - cpp_typecheck.str << "e1==e2: " << (e1==e2) << '\n'; - cpp_typecheck.str << "e1.type==e2.type: " << (e1.type()==e2.type()) - << '\n'; - cpp_typecheck.str << "e1.id()==e2.id(): " << (e1.id()==e2.id()) - << '\n'; - cpp_typecheck.str << "e1.iden==e2.iden: " - << (e1.get(ID_identifier)==e2.get(ID_identifier)) - << '\n'; - cpp_typecheck.str << "e1.iden:: " << e1.get(ID_identifier) << '\n'; - cpp_typecheck.str << "e2.iden:: " << e2.get(ID_identifier) << '\n'; - #endif + cpp_typecheck.error() << "e1==e2: " << (e1 == e2) << '\n'; + cpp_typecheck.error() + << "e1.type==e2.type: " << (e1.type() == e2.type()) << '\n'; + cpp_typecheck.error() + << "e1.id()==e2.id(): " << (e1.id() == e2.id()) << '\n'; + cpp_typecheck.error() + << "e1.iden==e2.iden: " + << (e1.get(ID_identifier) == e2.get(ID_identifier)) << '\n'; + cpp_typecheck.error() << "e1.iden:: " << e1.get(ID_identifier) << '\n'; + cpp_typecheck.error() << "e2.iden:: " << e2.get(ID_identifier) << '\n'; +#endif } if(fargs.in_use) diff --git a/src/cpp/parse.cpp b/src/cpp/parse.cpp index 31057fe8cd6..7de7d52e1ae 100644 --- a/src/cpp/parse.cpp +++ b/src/cpp/parse.cpp @@ -190,10 +190,8 @@ void new_scopet::print_rec(std::ostream &out, unsigned indent) const it!=id_map.end(); it++) { - out << std::string(indent, ' ') - << it->first << ": " - << kind2string(it->second.kind) - << "\n"; + out << std::string(indent, ' ') << it->first << ": " + << kind2string(it->second.kind) << '\n'; it->second.print_rec(out, indent+2); } } @@ -1455,7 +1453,7 @@ bool Parser::rDeclaration(cpp_declarationt &declaration) #ifdef DEBUG std::cout << std::string(__indent, ' ') << "Parser::rDeclaration 6 " << t - << "\n"; + << '\n'; #endif if(cv_q.is_not_nil() && @@ -1537,7 +1535,7 @@ bool Parser::rIntegralDeclaration( indenter _i; std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 1 token: " - << static_cast(lex.LookAhead(0)) << "\n"; + << static_cast(lex.LookAhead(0)) << '\n'; #endif if(!optCvQualify(cv_q)) @@ -1593,9 +1591,8 @@ bool Parser::rIntegralDeclaration( default: #ifdef DEBUG - std::cout << std::string(__indent, ' ') - << "Parser::rIntegralDeclaration 6 " - << lex.LookAhead(0) << "\n"; + std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 6 " + << lex.LookAhead(0) << '\n'; #endif if(!rDeclarators(declaration.declarators(), true)) @@ -1858,7 +1855,7 @@ bool Parser::isConstructorDecl() #ifdef DEBUG indenter _i; std::cout << std::string(__indent, ' ') << "Parser::isConstructorDecl " - << lex.LookAhead(0) << " "<< lex.LookAhead(1) << "\n"; + << lex.LookAhead(0) << " " << lex.LookAhead(1) << '\n'; #endif if(lex.LookAhead(0)!='(') @@ -3261,8 +3258,8 @@ bool Parser::optPtrOperator(typet &ptrs) int t=lex.LookAhead(0); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optPtrOperator 2 " - << t << "\n"; + std::cout << std::string(__indent, ' ') << "Parser::optPtrOperator 2 " << t + << '\n'; #endif if(t=='*') @@ -3514,7 +3511,7 @@ bool Parser::rName(irept &name) #ifdef DEBUG std::cout << std::string(__indent, ' ') << "Parser::rName 2 " - << lex.LookAhead(0) << "\n"; + << lex.LookAhead(0) << '\n'; #endif switch(lex.LookAhead(0)) @@ -7283,7 +7280,7 @@ optionalt Parser::rStatement() #ifdef DEBUG indenter _i; std::cout << std::string(__indent, ' ') << "Parser::rStatement 0 " - << lex.LookAhead(0) << "\n"; + << lex.LookAhead(0) << '\n'; #endif switch(k=lex.LookAhead(0)) @@ -8113,7 +8110,7 @@ optionalt Parser::rExprStatement() #ifdef DEBUG std::cout << std::string(__indent, ' ') << "Parser::rExprStatement 5 " - << lex.LookAhead(0) << "\n"; + << lex.LookAhead(0) << '\n'; #endif if(lex.get_token(tk)!=';') @@ -8212,7 +8209,7 @@ optionalt Parser::rDeclarationStatement() #ifdef DEBUG std::cout << std::string(__indent, ' ') - << "Parser::rDeclarationStatement 3 " << t << "\n"; + << "Parser::rDeclarationStatement 3 " << t << '\n'; #endif if(cv_q.is_not_nil() &&