From f79bdaf1fae14d7028bb1670ec8a674ff2026491 Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Wed, 6 Oct 2021 21:45:40 +0200 Subject: drop 'using namespace std' in compilerplugins Change-Id: I12b4e32b9561657bdbe062b5fb7c18e2ef6ce601 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123196 Tested-by: Jenkins Reviewed-by: Julien Nabet --- compilerplugins/clang/sharedvisitor/analyzer.cxx | 86 +++++++++++------------ compilerplugins/clang/sharedvisitor/generator.cxx | 78 ++++++++++---------- 2 files changed, 80 insertions(+), 84 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/sharedvisitor/analyzer.cxx b/compilerplugins/clang/sharedvisitor/analyzer.cxx index ea519abb0d95..381bd03759ed 100644 --- a/compilerplugins/clang/sharedvisitor/analyzer.cxx +++ b/compilerplugins/clang/sharedvisitor/analyzer.cxx @@ -26,8 +26,6 @@ #include "../check.hxx" #include "../check.cxx" -using namespace std; - using namespace clang; using namespace llvm; @@ -36,8 +34,8 @@ using namespace loplugin; // Info about a Traverse* function in a plugin. struct TraverseFunctionInfo { - string name; - string argument; + std::string name; + std::string argument; bool hasPre = false; bool hasPost = false; }; @@ -50,7 +48,7 @@ struct TraverseFunctionInfoLess } }; -static set< TraverseFunctionInfo, TraverseFunctionInfoLess > traverseFunctions; +static std::set< TraverseFunctionInfo, TraverseFunctionInfoLess > traverseFunctions; class CheckFileVisitor : public RecursiveASTVisitor< CheckFileVisitor > @@ -100,7 +98,7 @@ static TraverseFunctionInfo findOrCreateTraverseFunctionInfo( StringRef name ) auto foundInfo = traverseFunctions.find( info ); if( foundInfo != traverseFunctions.end()) { - info = move( *foundInfo ); + info = std::move( *foundInfo ); traverseFunctions.erase( foundInfo ); } return info; @@ -116,10 +114,10 @@ bool CheckFileVisitor::VisitCXXRecordDecl( CXXRecordDecl* decl ) if( decl->getName() == "FilteringPlugin" || decl->getName() == "FilteringRewritePlugin" ) return true; - cout << "# This file is autogenerated. Do not modify." << endl; - cout << "# Generated by compilerplugins/clang/sharedvisitor/analyzer.cxx ." << endl; - cout << "InfoVersion:1" << endl; - cout << "ClassName:" << decl->getName().str() << endl; + std::cout << "# This file is autogenerated. Do not modify." << std::endl; + std::cout << "# Generated by compilerplugins/clang/sharedvisitor/analyzer.cxx ." << std::endl; + std::cout << "InfoVersion:1" << std::endl; + std::cout << "ClassName:" << decl->getName().str() << std::endl; traverseFunctions.clear(); for( const CXXMethodDecl* method : decl->methods()) { @@ -131,18 +129,18 @@ bool CheckFileVisitor::VisitCXXRecordDecl( CXXRecordDecl* decl ) { if( method->getNumParams() == 1 ) { - cout << "VisitFunctionStart" << endl; - cout << "VisitFunctionName:" << method->getName().str() << endl; - cout << "VisitFunctionArgument:" + std::cout << "VisitFunctionStart" << std::endl; + std::cout << "VisitFunctionName:" << method->getName().str() << std::endl; + std::cout << "VisitFunctionArgument:" << unqualifyPointeeType( method->getParamDecl( 0 )->getTypeSourceInfo()->getType()).getAsString() - << endl; - cout << "VisitFunctionEnd" << endl; + << std::endl; + std::cout << "VisitFunctionEnd" << std::endl; } else { - cerr << "Unhandled Visit* function: " << decl->getName().str() - << "::" << method->getName().str() << endl; + std::cerr << "Unhandled Visit* function: " << decl->getName().str() + << "::" << method->getName().str() << std::endl; abort(); } } @@ -152,12 +150,12 @@ bool CheckFileVisitor::VisitCXXRecordDecl( CXXRecordDecl* decl ) { TraverseFunctionInfo traverseInfo = findOrCreateTraverseFunctionInfo( method->getName()); traverseInfo.argument = method->getParamDecl( 0 )->getTypeSourceInfo()->getType().getAsString(); - traverseFunctions.insert( move( traverseInfo )); + traverseFunctions.insert( std::move( traverseInfo )); } else { - cerr << "Unhandled Traverse* function: " << decl->getName().str() - << "::" << method->getName().str() << endl; + std::cerr << "Unhandled Traverse* function: " << decl->getName().str() + << "::" << method->getName().str() << std::endl; abort(); } } @@ -165,37 +163,37 @@ bool CheckFileVisitor::VisitCXXRecordDecl( CXXRecordDecl* decl ) { TraverseFunctionInfo traverseInfo = findOrCreateTraverseFunctionInfo( method->getName().substr( 3 )); traverseInfo.hasPre = true; - traverseFunctions.insert( move( traverseInfo )); + traverseFunctions.insert( std::move( traverseInfo )); } else if( method->getName().startswith( "PostTraverse" )) { TraverseFunctionInfo traverseInfo = findOrCreateTraverseFunctionInfo( method->getName().substr( 4 )); traverseInfo.hasPost = true; - traverseFunctions.insert( move( traverseInfo )); + traverseFunctions.insert( std::move( traverseInfo )); } else if( method->getName() == "shouldVisitTemplateInstantiations" ) - cout << "ShouldVisitTemplateInstantiations:1" << endl; + std::cout << "ShouldVisitTemplateInstantiations:1" << std::endl; else if (method->getName() == "shouldVisitImplicitCode") - cout << "ShouldVisitImplicitCode:1" << endl; + std::cout << "ShouldVisitImplicitCode:1" << std::endl; else if( method->getName().startswith( "WalkUp" )) { - cerr << "WalkUp function not supported for shared visitor: " << decl->getName().str() - << "::" << method->getName().str() << endl; + std::cerr << "WalkUp function not supported for shared visitor: " << decl->getName().str() + << "::" << method->getName().str() << std::endl; abort(); } } for( const auto& traverseFunction : traverseFunctions ) { - cout << "TraverseFunctionStart" << endl; - cout << "TraverseFunctionName:" << traverseFunction.name << endl; - cout << "TraverseFunctionArgument:" << traverseFunction.argument << endl; - cout << "TraverseFunctionHasPre:" << traverseFunction.hasPre << endl; - cout << "TraverseFunctionHasPost:" << traverseFunction.hasPost << endl; - cout << "TraverseFunctionEnd" << endl; + std::cout << "TraverseFunctionStart" << std::endl; + std::cout << "TraverseFunctionName:" << traverseFunction.name << std::endl; + std::cout << "TraverseFunctionArgument:" << traverseFunction.argument << std::endl; + std::cout << "TraverseFunctionHasPre:" << traverseFunction.hasPre << std::endl; + std::cout << "TraverseFunctionHasPost:" << traverseFunction.hasPost << std::endl; + std::cout << "TraverseFunctionEnd" << std::endl; } - cout << "InfoEnd" << endl; + std::cout << "InfoEnd" << std::endl; foundSomething = true; return true; } @@ -220,23 +218,23 @@ class FindNamedClassAction : public ASTFrontendAction { public: - virtual unique_ptr CreateASTConsumer( CompilerInstance&, StringRef ) override + virtual std::unique_ptr CreateASTConsumer( CompilerInstance&, StringRef ) override { - return unique_ptr( new FindNamedClassConsumer ); + return std::unique_ptr( new FindNamedClassConsumer ); } }; -string readSourceFile( const char* filename ) +std::string readSourceFile( const char* filename ) { - string contents; - ifstream stream( filename ); + std::string contents; + std::ifstream stream( filename ); if( !stream ) { - cerr << "Failed to open: " << filename << endl; + std::cerr << "Failed to open: " << filename << std::endl; exit( 1 ); } - string line; + std::string line; bool hasIfdef = false; while( getline( stream, line )) { @@ -253,7 +251,7 @@ string readSourceFile( const char* filename ) int main(int argc, char** argv) { - vector< string > args; + std::vector< std::string > args; int i = 1; for( ; i < argc; ++ i ) { @@ -281,7 +279,7 @@ int main(int argc, char** argv) }); for( ; i < argc; ++ i ) { - string contents = readSourceFile(argv[i]); + std::string contents = readSourceFile(argv[i]); if( contents.empty()) continue; foundSomething = false; @@ -291,13 +289,13 @@ int main(int argc, char** argv) if( !tooling::runToolOnCodeWithArgs( new FindNamedClassAction, contents, args, argv[ i ] )) #endif { - cerr << "Failed to analyze: " << argv[ i ] << endl; + std::cerr << "Failed to analyze: " << argv[ i ] << std::endl; return 2; } if( !foundSomething ) { // there's #ifndef LO_CLANG_SHARED_PLUGINS in the source, but no class matched - cerr << "Failed to find code: " << argv[ i ] << endl; + std::cerr << "Failed to find code: " << argv[ i ] << std::endl; return 2; } } diff --git a/compilerplugins/clang/sharedvisitor/generator.cxx b/compilerplugins/clang/sharedvisitor/generator.cxx index 62c0798a4801..ca5d2743cb69 100644 --- a/compilerplugins/clang/sharedvisitor/generator.cxx +++ b/compilerplugins/clang/sharedvisitor/generator.cxx @@ -17,21 +17,19 @@ #include #include -using namespace std; - // Info about a Visit* function in a plugin. struct VisitFunctionInfo { - string name; - string argument; + std::string name; + std::string argument; }; // Info about a Traverse* function in a plugin. struct TraverseFunctionInfo { - string name; - string argument; + std::string name; + std::string argument; bool hasPre = false; bool hasPost = false; }; @@ -56,13 +54,13 @@ struct TraverseFunctionInfoLess // Information about each LO plugin. struct PluginInfo { - string className; // e.g. "BadStatics" - string variableName; // e.g. "badStatics" - string lowercaseName; + std::string className; // e.g. "BadStatics" + std::string variableName; // e.g. "badStatics" + std::string lowercaseName; bool shouldVisitTemplateInstantiations; bool shouldVisitImplicitCode; - set< VisitFunctionInfo, VisitFunctionInfoLess > visitFunctions; - set< TraverseFunctionInfo, TraverseFunctionInfoLess > traverseFunctions; + std::set< VisitFunctionInfo, VisitFunctionInfoLess > visitFunctions; + std::set< TraverseFunctionInfo, TraverseFunctionInfoLess > traverseFunctions; }; // We need separate visitors for shouldVisitTemplateInstantiations and shouldVisitImplicitCode, @@ -82,14 +80,14 @@ const int Plugin_End = PluginVisitTemplatesImplicit + 1; static const char* const pluginTypeNames[ Plugin_End ] = { "Basic", "VisitTemplates", "VisitImplicit", "VisitTemplatesImplicit" }; -static vector< PluginInfo > plugins[ Plugin_End ]; +static std::vector< PluginInfo > plugins[ Plugin_End ]; void generateVisitor( PluginType type ); void generate() { - ostream& output = cout; + std::ostream& output = std::cout; output << "// This file is autogenerated. Do not modify.\n" "// Generated by compilerplugins/clang/sharedvisitor/generator.cxx .\n" @@ -113,7 +111,7 @@ void generate() output << "\n"; for( const auto& pluginGroup : plugins ) for( const PluginInfo& plugin : pluginGroup ) - output << "#include \"" << plugin.lowercaseName << ".cxx\"" << endl; + output << "#include \"" << plugin.lowercaseName << ".cxx\"" << std::endl; output << "\n"; output << "#undef RecursiveASTVisitor\n"; output << "#undef FilteringPlugin\n"; @@ -140,7 +138,7 @@ void generateVisitor( PluginType type ) { if( plugins[ type ].empty()) return; - ostream& output = cout; + std::ostream& output = std::cout; output << "\n" "class SharedRecursiveASTVisitor" << pluginTypeNames[ type ] << "\n" @@ -218,7 +216,7 @@ void generateVisitor( PluginType type ) if( type == PluginVisitImplicit || type == PluginVisitTemplatesImplicit ) output << "bool shouldVisitImplicitCode() const { return true; }\n"; - set< VisitFunctionInfo, VisitFunctionInfoLess > visitFunctions; + std::set< VisitFunctionInfo, VisitFunctionInfoLess > visitFunctions; for( const PluginInfo& plugin : plugins[ type ] ) for( const VisitFunctionInfo& visit : plugin.visitFunctions ) visitFunctions.insert( visit ); @@ -247,7 +245,7 @@ void generateVisitor( PluginType type ) " }\n"; } - set< TraverseFunctionInfo, TraverseFunctionInfoLess > traverseFunctions; + std::set< TraverseFunctionInfo, TraverseFunctionInfoLess > traverseFunctions; for( const PluginInfo& plugin : plugins[ type ] ) for( const TraverseFunctionInfo& traverse : plugin.traverseFunctions ) traverseFunctions.insert( traverse ); @@ -334,36 +332,36 @@ void generateVisitor( PluginType type ) "\n"; } -static string getValue( const string& line, const char* tag ) +static std::string getValue( const std::string& line, const char* tag ) { size_t taglen = strlen( tag ); if( line.size() < taglen + 2 ) - return string(); + return std::string(); if( line.compare( 0, taglen, tag ) != 0 ) - return string(); + return std::string(); if( line[ taglen ] != ':' ) - return string(); + return std::string(); return line.substr( taglen + 1 ); } -static bool readFile( const string& fileName ) +static bool readFile( const std::string& fileName ) { - ifstream file( fileName ); + std::ifstream file( fileName ); if( !file ) { - cerr << "Cannot open file " << fileName << endl; + std::cerr << "Cannot open file " << fileName << std::endl; return false; } PluginInfo pluginInfo; - string line; + std::string line; do { getline( file, line ); } while( !line.empty() && line[ 0 ] == '#' ); - string version = getValue( line, "InfoVersion" ); + std::string version = getValue( line, "InfoVersion" ); if( version != "1" ) { - cerr << "Incorrect version '" << version << "' in " << fileName << endl; + std::cerr << "Incorrect version '" << version << "' in " << fileName << std::endl; return false; } getline( file, line ); @@ -379,11 +377,11 @@ static bool readFile( const string& fileName ) bool endOk = false; for(;;) { - string line; + std::string line; getline( file, line ); if( file.eof() || !file ) { - cerr << "Unexpected end of file" << endl; + std::cerr << "Unexpected end of file" << std::endl; return false; } if( line.empty()) @@ -403,10 +401,10 @@ static bool readFile( const string& fileName ) getline( file, line ); if( line != "VisitFunctionEnd" ) { - cerr << "Missing VisitFunctionEnd" << endl; + std::cerr << "Missing VisitFunctionEnd" << std::endl; return false; } - pluginInfo.visitFunctions.insert( move( visitInfo )); + pluginInfo.visitFunctions.insert( std::move( visitInfo )); } else if( line == "TraverseFunctionStart" ) { @@ -422,14 +420,14 @@ static bool readFile( const string& fileName ) getline( file, line ); if( line != "TraverseFunctionEnd" ) { - cerr << "Missing TraverseFunctionEnd" << endl; + std::cerr << "Missing TraverseFunctionEnd" << std::endl; return false; } - pluginInfo.traverseFunctions.insert( move( traverseInfo )); + pluginInfo.traverseFunctions.insert( std::move( traverseInfo )); } else { - string value; + std::string value; value = getValue( line, "ShouldVisitTemplateInstantiations" ); if( value == "1" ) pluginInfo.shouldVisitTemplateInstantiations = true; @@ -440,7 +438,7 @@ static bool readFile( const string& fileName ) pluginInfo.shouldVisitImplicitCode = true; else { - cerr << "Unknown line " << line << endl; + std::cerr << "Unknown line " << line << std::endl; return false; } } @@ -451,13 +449,13 @@ static bool readFile( const string& fileName ) (void)endOk; if( pluginInfo.shouldVisitTemplateInstantiations && pluginInfo.shouldVisitImplicitCode ) - plugins[ PluginVisitTemplatesImplicit ].push_back( move( pluginInfo )); + plugins[ PluginVisitTemplatesImplicit ].push_back( std::move( pluginInfo )); else if( pluginInfo.shouldVisitTemplateInstantiations ) - plugins[ PluginVisitTemplates ].push_back( move( pluginInfo )); + plugins[ PluginVisitTemplates ].push_back( std::move( pluginInfo )); else if( pluginInfo.shouldVisitImplicitCode ) - plugins[ PluginVisitImplicit ].push_back( move( pluginInfo )); + plugins[ PluginVisitImplicit ].push_back( std::move( pluginInfo )); else - plugins[ PluginBasic ].push_back( move( pluginInfo )); + plugins[ PluginBasic ].push_back( std::move( pluginInfo )); return true; } @@ -468,7 +466,7 @@ int main(int argc, char** argv) { if( !readFile( argv[ i ] )) { - cerr << "Error reading " << argv[ i ] << endl; + std::cerr << "Error reading " << argv[ i ] << std::endl; return 1; } } -- cgit