[Libreoffice-commits] core.git: compilerplugins/clang
Noel Grandin
noel.grandin at collabora.co.uk
Tue Jun 20 08:28:24 UTC 2017
compilerplugins/clang/bodynotinblock.hxx | 2
compilerplugins/clang/checkconfigmacros.cxx | 2
compilerplugins/clang/constantparam.cxx | 4
compilerplugins/clang/countusersofdefaultparams.cxx | 4
compilerplugins/clang/expandablemethods.cxx | 4
compilerplugins/clang/externandnotdefined.cxx | 2
compilerplugins/clang/inlinefields.cxx | 4
compilerplugins/clang/memoryvar.cxx | 1
compilerplugins/clang/mergeclasses.cxx | 4
compilerplugins/clang/plugin.cxx | 197 ++++++++--------
compilerplugins/clang/plugin.hxx | 241 +++++++++-----------
compilerplugins/clang/pluginhandler.cxx | 141 +++++------
compilerplugins/clang/pluginhandler.hxx | 56 ++--
compilerplugins/clang/sallogareas.cxx | 8
compilerplugins/clang/sallogareas.hxx | 4
compilerplugins/clang/sfxpoolitem.cxx | 2
compilerplugins/clang/singlevalfields.cxx | 4
compilerplugins/clang/unnecessaryvirtual.cxx | 4
compilerplugins/clang/unusedenumconstants.cxx | 4
compilerplugins/clang/unusedfields.cxx | 4
compilerplugins/clang/unusedfieldsremove.cxx | 5
compilerplugins/clang/unusedmethods.cxx | 4
22 files changed, 341 insertions(+), 360 deletions(-)
New commits:
commit 4c0198b02c4a514bc61772d8c671c47c9553fd7a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Jun 20 10:26:46 2017 +0200
reformat some loplugin code
to match our more normal conventions.
Also drop the 'using std' and some other cruft
Change-Id: I02ef81c5427188bc03a20b157a57a900a9d7bf0d
diff --git a/compilerplugins/clang/bodynotinblock.hxx b/compilerplugins/clang/bodynotinblock.hxx
index e79060b8a073..872c46b32352 100644
--- a/compilerplugins/clang/bodynotinblock.hxx
+++ b/compilerplugins/clang/bodynotinblock.hxx
@@ -29,7 +29,7 @@ class BodyNotInBlock
bool VisitForStmt( const ForStmt* stmt );
bool VisitCXXForRangeStmt( const CXXForRangeStmt* stmt );
private:
- typedef vector< const Stmt* > StmtParents;
+ typedef std::vector< const Stmt* > StmtParents;
void checkBody( const Stmt* body, SourceLocation stmtLocation, int stmtType, bool dontGoUp = false );
};
diff --git a/compilerplugins/clang/checkconfigmacros.cxx b/compilerplugins/clang/checkconfigmacros.cxx
index d42adb08cc67..46cb35a450c3 100644
--- a/compilerplugins/clang/checkconfigmacros.cxx
+++ b/compilerplugins/clang/checkconfigmacros.cxx
@@ -48,7 +48,7 @@ class CheckConfigMacros
enum { isPPCallback = true };
private:
void checkMacro( const Token& macroToken, SourceLocation location );
- std::set< string > configMacros;
+ std::set< std::string > configMacros;
};
CheckConfigMacros::CheckConfigMacros( const InstantiationData& data )
diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx
index 5f80b80358f3..376d9df9731d 100644
--- a/compilerplugins/clang/constantparam.cxx
+++ b/compilerplugins/clang/constantparam.cxx
@@ -77,8 +77,8 @@ public:
for (const MyCallSiteInfo & s : callSet)
output += s.returnType + "\t" + s.nameAndParams + "\t" + s.sourceLocation + "\t"
+ s.paramName + "\t" + s.paramType + "\t" + s.callValue + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.constantparam.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.constantparam.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/countusersofdefaultparams.cxx b/compilerplugins/clang/countusersofdefaultparams.cxx
index d17377bc6bd6..648351a0891f 100644
--- a/compilerplugins/clang/countusersofdefaultparams.cxx
+++ b/compilerplugins/clang/countusersofdefaultparams.cxx
@@ -73,8 +73,8 @@ public:
output += "defn:\t" + s.access + "\t" + s.returnType + "\t" + s.nameAndParams + "\t" + s.sourceLocation + "\n";
for (const MyCallInfo & s : callSet)
output += "call:\t" + s.returnType + "\t" + s.nameAndParams + "\t" + s.sourceLocationOfCall + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.countusersofdefaultparams.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.countusersofdefaultparams.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/expandablemethods.cxx b/compilerplugins/clang/expandablemethods.cxx
index a5a2dfda2278..958d563d0adb 100644
--- a/compilerplugins/clang/expandablemethods.cxx
+++ b/compilerplugins/clang/expandablemethods.cxx
@@ -80,8 +80,8 @@ public:
output += "large:\t" + s.returnType + "\t" + s.nameAndParams + "\n";
for (const MyFuncInfo & s : addressOfSet)
output += "addrof:\t" + s.returnType + "\t" + s.nameAndParams + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.expandablemethods.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.expandablemethods.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/externandnotdefined.cxx b/compilerplugins/clang/externandnotdefined.cxx
index 2558ec62684d..b15a1c28a06b 100644
--- a/compilerplugins/clang/externandnotdefined.cxx
+++ b/compilerplugins/clang/externandnotdefined.cxx
@@ -45,7 +45,7 @@ bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl * functionDecl) {
return true;
}
// this is the bison/flex C API, it has to be defined this way
- string functionName = functionDecl->getNameAsString();
+ std::string functionName = functionDecl->getNameAsString();
if (functionName == "yyerror" || functionName == "YYWarning" || functionName == "yyparse" || functionName == "yylex") {
return true;
}
diff --git a/compilerplugins/clang/inlinefields.cxx b/compilerplugins/clang/inlinefields.cxx
index e663c118ed22..5ffb93080e3e 100644
--- a/compilerplugins/clang/inlinefields.cxx
+++ b/compilerplugins/clang/inlinefields.cxx
@@ -82,8 +82,8 @@ public:
output += "deletedInDestructor:\t" + s.parentClass + "\t" + s.fieldName + "\n";
for (const MyFieldInfo & s : newedInConstructorSet)
output += "newedInConstructor:\t" + s.parentClass + "\t" + s.fieldName + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.inlinefields.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.inlinefields.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/memoryvar.cxx b/compilerplugins/clang/memoryvar.cxx
index 708e58cc3a50..3b480660ed3f 100644
--- a/compilerplugins/clang/memoryvar.cxx
+++ b/compilerplugins/clang/memoryvar.cxx
@@ -101,7 +101,6 @@ bool MemoryVar::TraverseFunctionDecl(FunctionDecl * decl)
"delete called here",
maVarDeleteSourceRangeMap[varLoc].getBegin())
<< maVarDeleteSourceRangeMap[varLoc];
- cout << "xxxx " << aFileName.str() << endl;
}
return true;
}
diff --git a/compilerplugins/clang/mergeclasses.cxx b/compilerplugins/clang/mergeclasses.cxx
index a3ba0cc95d21..90c5cbe72d5e 100644
--- a/compilerplugins/clang/mergeclasses.cxx
+++ b/compilerplugins/clang/mergeclasses.cxx
@@ -65,8 +65,8 @@ public:
output += "has-subclass:\t" + s.first + "\t" + s.second + "\n";
for (const std::pair<std::string,std::string> & s : definitionMap)
output += "definition:\t" + s.first + "\t" + s.second + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.mergeclasses.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.mergeclasses.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index ea646d29da89..66e22d507818 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -28,16 +28,16 @@ namespace loplugin
Plugin::Plugin( const InstantiationData& data )
: compiler( data.compiler ), handler( data.handler ), name( data.name )
- {
- }
+{
+}
DiagnosticBuilder Plugin::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ) const
- {
+{
return handler.report( level, name, message, compiler, loc );
- }
+}
bool Plugin::ignoreLocation( SourceLocation loc )
- {
+{
SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( loc );
if( compiler.getSourceManager().isInSystemHeader( expansionLoc ))
return true;
@@ -68,19 +68,19 @@ bool Plugin::ignoreLocation( SourceLocation loc )
}
std::string s(bufferName);
normalizeDotDotInFilePath(s);
- if (hasPathnamePrefix(s, WORKDIR)) {
+ if (hasPathnamePrefix(s, WORKDIR))
return true;
- }
}
if( hasPathnamePrefix(bufferName, BUILDDIR)
|| hasPathnamePrefix(bufferName, SRCDIR) )
return false; // ok
return true;
- }
+}
void Plugin::normalizeDotDotInFilePath( std::string & s )
+{
+ for (std::string::size_type i = 0;;)
{
- for (std::string::size_type i = 0;;) {
i = s.find("/.", i);
if (i == std::string::npos) {
break;
@@ -94,7 +94,8 @@ void Plugin::normalizeDotDotInFilePath( std::string & s )
break;
}
auto j = s.rfind('/', i - 1);
- if (j == std::string::npos) {
+ if (j == std::string::npos)
+ {
// BBB/..[/CCC] -> BBB/..[/CCC] (instead of BBB/../CCC ->
// CCC, to avoid wrong ../../CCC -> CCC; relative paths
// shouldn't happen anyway, and even if they did, wouldn't
@@ -108,34 +109,34 @@ void Plugin::normalizeDotDotInFilePath( std::string & s )
i += 2;
}
}
- }
+}
void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault )
- {
+{
PluginHandler::registerPlugin( create, optionName, isPPCallback, byDefault );
- }
+}
-unordered_map< const Stmt*, const Stmt* > Plugin::parents;
+std::unordered_map< const Stmt*, const Stmt* > Plugin::parents;
const Stmt* Plugin::parentStmt( const Stmt* stmt )
- {
+{
if( parents.empty())
buildParents( compiler );
//if(parents.count(stmt)!=1)stmt->dump();
//assert( parents.count( stmt ) == 1 );
return parents[ stmt ];
- }
+}
Stmt* Plugin::parentStmt( Stmt* stmt )
- {
+{
if( parents.empty())
buildParents( compiler );
//assert( parents.count( stmt ) == 1 );
return const_cast< Stmt* >( parents[ stmt ] );
- }
+}
static const Decl* getDeclContext(ASTContext& context, const Stmt* stmt)
- {
+{
auto it = context.getParents(*stmt).begin();
if (it == context.getParents(*stmt).end())
@@ -150,19 +151,20 @@ static const Decl* getDeclContext(ASTContext& context, const Stmt* stmt)
return getDeclContext(context, aStmt);
return nullptr;
- }
+}
const FunctionDecl* Plugin::parentFunctionDecl( const Stmt* stmt )
- {
+{
const Decl *decl = getDeclContext(compiler.getASTContext(), stmt);
if (decl)
return static_cast<const FunctionDecl*>(decl->getNonClosureContext());
return nullptr;
- }
+}
-bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const {
+bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const
+{
StringRef name {
compiler.getSourceManager().getFilename(spellingLocation) };
return compiler.getSourceManager().isInMainFile(spellingLocation)
@@ -181,7 +183,8 @@ bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const {
|| hasPathnamePrefix(name, SRCDIR "/include/uno/"));
}
-bool Plugin::isInUnoIncludeFile(const FunctionDecl* functionDecl) const {
+bool Plugin::isInUnoIncludeFile(const FunctionDecl* functionDecl) const
+{
return isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()));
}
@@ -190,167 +193,167 @@ namespace
{
class ParentBuilder
: public RecursiveASTVisitor< ParentBuilder >
- {
- public:
- bool VisitFunctionDecl( const FunctionDecl* function );
- bool VisitObjCMethodDecl( const ObjCMethodDecl* method );
- void walk( const Stmt* stmt );
- bool shouldVisitTemplateInstantiations () const { return true; }
- unordered_map< const Stmt*, const Stmt* >* parents;
- };
+{
+public:
+ bool VisitFunctionDecl( const FunctionDecl* function );
+ bool VisitObjCMethodDecl( const ObjCMethodDecl* method );
+ void walk( const Stmt* stmt );
+ bool shouldVisitTemplateInstantiations () const { return true; }
+ std::unordered_map< const Stmt*, const Stmt* >* parents;
+};
bool ParentBuilder::VisitFunctionDecl( const FunctionDecl* function )
- {
+{
// if( ignoreLocation( declaration ))
// return true; ???
if( function->doesThisDeclarationHaveABody())
- {
+ {
const Stmt* body = function->getBody();
(*parents)[ body ] = NULL; // no parent
walk( body );
- }
+ }
if( const CXXConstructorDecl* ctor = dyn_cast< CXXConstructorDecl >( function ))
- {
+ {
for( CXXConstructorDecl::init_const_iterator it = ctor->init_begin();
it != ctor->init_end();
++it )
- {
+ {
const Expr* init_expression = (*it)->getInit();
(*parents)[ init_expression ] = NULL;
walk( init_expression );
- }
}
- return true;
}
+ return true;
+}
bool ParentBuilder::VisitObjCMethodDecl( const ObjCMethodDecl* method )
- {
+{
// if( ignoreLocation( declaration ))
// return true; ???
if( method->hasBody())
- {
+ {
const Stmt* body = method->getBody();
(*parents)[ body ] = NULL; // no parent
walk( body );
- }
- return true;
}
+ return true;
+}
void ParentBuilder::walk( const Stmt* stmt )
- {
+{
for( ConstStmtIterator it = stmt->child_begin();
it != stmt->child_end();
++it )
- {
+ {
if( *it != NULL )
- {
+ {
(*parents)[ *it ] = stmt;
walk( *it );
- }
}
}
+}
} // namespace
void Plugin::buildParents( CompilerInstance& compiler )
- {
+{
assert( parents.empty());
ParentBuilder builder;
builder.parents = &parents;
builder.TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
- }
+}
SourceLocation Plugin::locationAfterToken( SourceLocation location )
- {
+{
return Lexer::getLocForEndOfToken( location, 0, compiler.getSourceManager(), compiler.getLangOpts());
- }
+}
bool Plugin::isUnitTestMode()
- {
+{
return PluginHandler::isUnitTestMode();
- }
+}
RewritePlugin::RewritePlugin( const InstantiationData& data )
: Plugin( data )
, rewriter( data.rewriter )
- {
- }
+{
+}
bool RewritePlugin::insertText( SourceLocation Loc, StringRef Str, bool InsertAfter, bool indentNewLines )
- {
+{
assert( rewriter );
if (wouldRewriteWorkdir(Loc))
return false;
if( rewriter->InsertText( Loc, Str, InsertAfter, indentNewLines ))
return reportEditFailure( Loc );
return true;
- }
+}
bool RewritePlugin::insertTextAfter( SourceLocation Loc, StringRef Str )
- {
+{
assert( rewriter );
if (wouldRewriteWorkdir(Loc))
return false;
if( rewriter->InsertTextAfter( Loc, Str ))
return reportEditFailure( Loc );
return true;
- }
+}
bool RewritePlugin::insertTextAfterToken( SourceLocation Loc, StringRef Str )
- {
+{
assert( rewriter );
if (wouldRewriteWorkdir(Loc))
return false;
if( rewriter->InsertTextAfterToken( Loc, Str ))
return reportEditFailure( Loc );
return true;
- }
+}
bool RewritePlugin::insertTextBefore( SourceLocation Loc, StringRef Str )
- {
+{
assert( rewriter );
if (wouldRewriteWorkdir(Loc))
return false;
if( rewriter->InsertTextBefore( Loc, Str ))
return reportEditFailure( Loc );
return true;
- }
+}
bool RewritePlugin::removeText( SourceLocation Start, unsigned Length, RewriteOptions opts )
- {
+{
CharSourceRange range( SourceRange( Start, Start.getLocWithOffset( Length )), false );
return removeText( range, opts );
- }
+}
bool RewritePlugin::removeText( SourceRange range, RewriteOptions opts )
- {
+{
return removeText( CharSourceRange( range, true ), opts );
- }
+}
bool RewritePlugin::removeText( CharSourceRange range, RewriteOptions opts )
- {
+{
assert( rewriter );
if (wouldRewriteWorkdir(range.getBegin()))
return false;
if( rewriter->getRangeSize( range, opts ) == -1 )
return reportEditFailure( range.getBegin());
if( !handler.addRemoval( range.getBegin() ) )
- {
+ {
report( DiagnosticsEngine::Warning, "double code removal, possible plugin error", range.getBegin());
return true;
- }
+ }
if( opts.flags & RemoveWholeStatement || opts.flags & RemoveAllWhitespace )
- {
+ {
if( !adjustRangeForOptions( &range, opts ))
return reportEditFailure( range.getBegin());
- }
+ }
if( rewriter->RemoveText( range, opts ))
return reportEditFailure( range.getBegin());
return true;
- }
+}
bool RewritePlugin::adjustRangeForOptions( CharSourceRange* range, RewriteOptions opts )
- {
+{
assert( rewriter );
SourceManager& SM = rewriter->getSourceMgr();
SourceLocation fileStartLoc = SM.getLocForStartOfFile( SM.getFileID( range->getBegin()));
@@ -379,67 +382,68 @@ bool RewritePlugin::adjustRangeForOptions( CharSourceRange* range, RewriteOption
while( *endPos == ' ' || *endPos == '\t' )
++endPos;
if( opts.flags & RemoveWholeStatement )
- {
+ {
if( *endPos == ';' )
++endPos;
else
return false;
- }
+ }
*range = CharSourceRange( SourceRange( range->getBegin().getLocWithOffset( startPos - startBuf + 1 ),
locationEnd.getLocWithOffset( endPos - endBuf )), false );
return true;
- }
+}
bool RewritePlugin::replaceText( SourceLocation Start, unsigned OrigLength, StringRef NewStr )
- {
+{
assert( rewriter );
if (wouldRewriteWorkdir(Start))
return false;
if( OrigLength != 0 && !handler.addRemoval( Start ) )
- {
+ {
report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", Start );
return true;
- }
+ }
if( rewriter->ReplaceText( Start, OrigLength, NewStr ))
return reportEditFailure( Start );
return true;
- }
+}
bool RewritePlugin::replaceText( SourceRange range, StringRef NewStr )
- {
+{
assert( rewriter );
if (wouldRewriteWorkdir(range.getBegin()))
return false;
if( rewriter->getRangeSize( range ) == -1 )
return reportEditFailure( range.getBegin());
if( !handler.addRemoval( range.getBegin() ) )
- {
+ {
report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", range.getBegin());
return true;
- }
+ }
if( rewriter->ReplaceText( range, NewStr ))
return reportEditFailure( range.getBegin());
return true;
- }
+}
bool RewritePlugin::replaceText( SourceRange range, SourceRange replacementRange )
- {
+{
assert( rewriter );
if (wouldRewriteWorkdir(range.getBegin()))
return false;
if( rewriter->getRangeSize( range ) == -1 )
return reportEditFailure( range.getBegin());
if( !handler.addRemoval( range.getBegin() ) )
- {
+ {
report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", range.getBegin());
return true;
- }
+ }
if( rewriter->ReplaceText( range, replacementRange ))
return reportEditFailure( range.getBegin());
return true;
- }
+}
-bool RewritePlugin::wouldRewriteWorkdir(SourceLocation loc) {
+bool RewritePlugin::wouldRewriteWorkdir(SourceLocation loc)
+{
if (loc.isInvalid() || loc.isMacroID()) {
return false;
}
@@ -450,10 +454,10 @@ bool RewritePlugin::wouldRewriteWorkdir(SourceLocation loc) {
}
bool RewritePlugin::reportEditFailure( SourceLocation loc )
- {
+{
report( DiagnosticsEngine::Warning, "cannot perform source modification (macro expansion involved?)", loc );
return false;
- }
+}
namespace {
@@ -464,7 +468,8 @@ template<typename Fn> bool checkPathname(
return true;
}
#if defined _WIN32
- for (std::size_t n = 0;;) {
+ for (std::size_t n = 0;;)
+ {
std::size_t n1 = pathname.find('\\', n);
if (n1 >= against.size()) {
return check(pathname.substr(n), against.substr(n));
@@ -482,13 +487,15 @@ template<typename Fn> bool checkPathname(
}
-bool hasPathnamePrefix(StringRef pathname, StringRef prefix) {
+bool hasPathnamePrefix(StringRef pathname, StringRef prefix)
+{
return checkPathname(
pathname, prefix,
[](StringRef p, StringRef a) { return p.startswith(a); });
}
-bool isSamePathname(StringRef pathname, StringRef other) {
+bool isSamePathname(StringRef pathname, StringRef other)
+{
return checkPathname(
pathname, other, [](StringRef p, StringRef a) { return p == a; });
}
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index 5651b2ff02ca..92f796f0f7c8 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -26,7 +26,6 @@
using namespace clang;
using namespace llvm;
-using namespace std;
namespace loplugin
{
@@ -40,55 +39,56 @@ class PluginHandler;
use Plugin::Registration.
*/
class Plugin
+{
+public:
+ struct InstantiationData
{
- public:
- struct InstantiationData
- {
- const char* name;
- PluginHandler& handler;
- CompilerInstance& compiler;
- Rewriter* rewriter;
- };
- explicit Plugin( const InstantiationData& data );
- virtual ~Plugin();
- virtual void run() = 0;
- template< typename T > class Registration;
- enum { isPPCallback = false };
- // Returns location right after the end of the token that starts at the given location.
- SourceLocation locationAfterToken( SourceLocation location );
- protected:
- DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation()) const;
- bool ignoreLocation( SourceLocation loc );
- bool ignoreLocation( const Decl* decl );
- bool ignoreLocation( const Stmt* stmt );
- CompilerInstance& compiler;
- PluginHandler& handler;
- /**
- Returns the parent of the given AST node. Clang's internal AST representation doesn't provide this information,
- it can only provide children, but getting the parent is often useful for inspecting a part of the AST.
- */
- const Stmt* parentStmt( const Stmt* stmt );
- Stmt* parentStmt( Stmt* stmt );
- const FunctionDecl* parentFunctionDecl( const Stmt* stmt );
- /**
- Checks if the location is inside an UNO file, more specifically, if it forms part of the URE stable interface,
- which is not allowed to be changed.
- */
- bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
- bool isInUnoIncludeFile(const FunctionDecl*) const;
-
- static void normalizeDotDotInFilePath(std::string&);
-
- static bool isUnitTestMode();
- private:
- static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
- template< typename T > static Plugin* createHelper( const InstantiationData& data );
- enum { isRewriter = false };
const char* name;
- static unordered_map< const Stmt*, const Stmt* > parents;
- static void buildParents( CompilerInstance& compiler );
+ PluginHandler& handler;
+ CompilerInstance& compiler;
+ Rewriter* rewriter;
};
+ explicit Plugin( const InstantiationData& data );
+ virtual ~Plugin() {}
+ virtual void run() = 0;
+ template< typename T > class Registration;
+ enum { isPPCallback = false };
+ // Returns location right after the end of the token that starts at the given location.
+ SourceLocation locationAfterToken( SourceLocation location );
+protected:
+ DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation()) const;
+ bool ignoreLocation( SourceLocation loc );
+ bool ignoreLocation( const Decl* decl );
+ bool ignoreLocation( const Stmt* stmt );
+ CompilerInstance& compiler;
+ PluginHandler& handler;
+ /**
+ Returns the parent of the given AST node. Clang's internal AST representation doesn't provide this information,
+ it can only provide children, but getting the parent is often useful for inspecting a part of the AST.
+ */
+ const Stmt* parentStmt( const Stmt* stmt );
+ Stmt* parentStmt( Stmt* stmt );
+ const FunctionDecl* parentFunctionDecl( const Stmt* stmt );
+ /**
+ Checks if the location is inside an UNO file, more specifically, if it forms part of the URE stable interface,
+ which is not allowed to be changed.
+ */
+ bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
+ bool isInUnoIncludeFile(const FunctionDecl*) const;
+
+ static void normalizeDotDotInFilePath(std::string&);
+
+ static bool isUnitTestMode();
+private:
+ static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
+ template< typename T > static Plugin* createHelper( const InstantiationData& data );
+ enum { isRewriter = false };
+ const char* name;
+ static std::unordered_map< const Stmt*, const Stmt* > parents;
+ static void buildParents( CompilerInstance& compiler );
+};
+
/**
Base class for rewriter plugins.
@@ -96,57 +96,57 @@ class Plugin
*/
class RewritePlugin
: public Plugin
+{
+public:
+ explicit RewritePlugin( const InstantiationData& data );
+protected:
+ enum RewriteOption
{
- public:
- explicit RewritePlugin( const InstantiationData& data );
- protected:
- enum RewriteOption
- {
- // This enum allows passing just 'RemoveLineIfEmpty' to functions below.
- // If the resulting line would be completely empty, it'll be removed.
- RemoveLineIfEmpty = 1 << 0,
- // Use this to remove the declaration/statement as a whole, i.e. all whitespace before the statement
- // and the trailing semicolon (is not part of the AST element range itself).
- // The trailing semicolon must be present.
- RemoveWholeStatement = 1 << 1,
- // Removes also all whitespace preceding and following the expression (completely, so that
- // the preceding and following tokens would be right next to each other, follow with insertText( " " )
- // if this is not wanted). Despite the name, indentation whitespace is not removed.
- RemoveAllWhitespace = 1 << 2
- };
- struct RewriteOptions
- : public Rewriter::RewriteOptions
- {
- RewriteOptions();
- explicit RewriteOptions( RewriteOption option );
- const int flags;
- };
- // syntactic sugar to be able to write 'RemoveLineIfEmpty | RemoveWholeStatement'
- friend RewriteOption operator|( RewriteOption option1, RewriteOption option2 );
- // These following insert/remove/replaceText functions map to functions
- // in clang::Rewriter, with these differences:
- // - they (more intuitively) return false on failure rather than true
- // - they report a warning when the change cannot be done
- // - There are more options for easier removal of surroundings of a statement/expression.
- bool insertText( SourceLocation Loc, StringRef Str,
- bool InsertAfter = true, bool indentNewLines = false );
- bool insertTextAfter( SourceLocation Loc, StringRef Str );
- bool insertTextAfterToken( SourceLocation Loc, StringRef Str );
- bool insertTextBefore( SourceLocation Loc, StringRef Str );
- bool removeText( SourceLocation Start, unsigned Length, RewriteOptions opts = RewriteOptions());
- bool removeText( CharSourceRange range, RewriteOptions opts = RewriteOptions());
- bool removeText( SourceRange range, RewriteOptions opts = RewriteOptions());
- bool replaceText( SourceLocation Start, unsigned OrigLength, StringRef NewStr );
- bool replaceText( SourceRange range, StringRef NewStr );
- bool replaceText( SourceRange range, SourceRange replacementRange );
- Rewriter* rewriter;
- private:
- template< typename T > friend class Plugin::Registration;
- enum { isRewriter = true };
- bool wouldRewriteWorkdir(SourceLocation loc);
- bool reportEditFailure( SourceLocation loc );
- bool adjustRangeForOptions( CharSourceRange* range, RewriteOptions options );
+ // This enum allows passing just 'RemoveLineIfEmpty' to functions below.
+ // If the resulting line would be completely empty, it'll be removed.
+ RemoveLineIfEmpty = 1 << 0,
+ // Use this to remove the declaration/statement as a whole, i.e. all whitespace before the statement
+ // and the trailing semicolon (is not part of the AST element range itself).
+ // The trailing semicolon must be present.
+ RemoveWholeStatement = 1 << 1,
+ // Removes also all whitespace preceding and following the expression (completely, so that
+ // the preceding and following tokens would be right next to each other, follow with insertText( " " )
+ // if this is not wanted). Despite the name, indentation whitespace is not removed.
+ RemoveAllWhitespace = 1 << 2
};
+ struct RewriteOptions
+ : public Rewriter::RewriteOptions
+ {
+ RewriteOptions() : flags( 0 ) {}
+ explicit RewriteOptions( RewriteOption option );
+ const int flags;
+ };
+ // syntactic sugar to be able to write 'RemoveLineIfEmpty | RemoveWholeStatement'
+ friend RewriteOption operator|( RewriteOption option1, RewriteOption option2 );
+ // These following insert/remove/replaceText functions map to functions
+ // in clang::Rewriter, with these differences:
+ // - they (more intuitively) return false on failure rather than true
+ // - they report a warning when the change cannot be done
+ // - There are more options for easier removal of surroundings of a statement/expression.
+ bool insertText( SourceLocation Loc, StringRef Str,
+ bool InsertAfter = true, bool indentNewLines = false );
+ bool insertTextAfter( SourceLocation Loc, StringRef Str );
+ bool insertTextAfterToken( SourceLocation Loc, StringRef Str );
+ bool insertTextBefore( SourceLocation Loc, StringRef Str );
+ bool removeText( SourceLocation Start, unsigned Length, RewriteOptions opts = RewriteOptions());
+ bool removeText( CharSourceRange range, RewriteOptions opts = RewriteOptions());
+ bool removeText( SourceRange range, RewriteOptions opts = RewriteOptions());
+ bool replaceText( SourceLocation Start, unsigned OrigLength, StringRef NewStr );
+ bool replaceText( SourceRange range, StringRef NewStr );
+ bool replaceText( SourceRange range, SourceRange replacementRange );
+ Rewriter* rewriter;
+private:
+ template< typename T > friend class Plugin::Registration;
+ enum { isRewriter = true };
+ bool wouldRewriteWorkdir(SourceLocation loc);
+ bool reportEditFailure( SourceLocation loc );
+ bool adjustRangeForOptions( CharSourceRange* range, RewriteOptions options );
+};
/**
Plugin registration helper.
@@ -161,69 +161,58 @@ class RewritePlugin
*/
template< typename T >
class Plugin::Registration
- {
- public:
- Registration( const char* optionName, bool byDefault = !T::isRewriter );
- };
+{
+public:
+ Registration( const char* optionName, bool byDefault = !T::isRewriter );
+};
class RegistrationCreate
- {
- public:
- template< typename T, bool > static T* create( const Plugin::InstantiationData& data );
- };
-
-inline
-Plugin::~Plugin()
- {
- }
+{
+public:
+ template< typename T, bool > static T* create( const Plugin::InstantiationData& data );
+};
inline
bool Plugin::ignoreLocation( const Decl* decl )
- {
+{
return ignoreLocation( decl->getLocation());
- }
+}
inline
bool Plugin::ignoreLocation( const Stmt* stmt )
- {
+{
// Invalid location can happen at least for ImplicitCastExpr of
// ImplicitParam 'self' in Objective C method declarations:
return stmt->getLocStart().isValid() && ignoreLocation( stmt->getLocStart());
- }
+}
template< typename T >
Plugin* Plugin::createHelper( const InstantiationData& data )
- {
+ {
return new T( data );
- }
+}
template< typename T >
inline
Plugin::Registration< T >::Registration( const char* optionName, bool byDefault )
- {
+{
registerPlugin( &T::template createHelper< T >, optionName, T::isPPCallback, byDefault );
- }
-
-inline
-RewritePlugin::RewriteOptions::RewriteOptions()
- : flags( 0 )
- {
- }
+}
inline
RewritePlugin::RewriteOptions::RewriteOptions( RewriteOption option )
: flags( option )
- {
+{
// Note that 'flags' stores also RemoveLineIfEmpty, it must be kept in sync with the base class.
if( flags & RewritePlugin::RemoveLineIfEmpty )
this->RemoveLineIfEmpty = true;
- }
+}
inline
RewritePlugin::RewriteOption operator|( RewritePlugin::RewriteOption option1, RewritePlugin::RewriteOption option2 )
- {
+{
return static_cast< RewritePlugin::RewriteOption >( int( option1 ) | int( option2 ));
- }
+}
// Same as pathname.startswith(prefix), except on Windows, where pathname (but
// not prefix) may also contain backslashes:
diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx
index 7c42d14f3056..c61477594395 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -25,32 +25,27 @@
#include <unistd.h>
#endif
-/*
+/**
This source file manages all plugin actions. It is not necessary to modify this
file when adding new actions.
*/
-namespace
+static bool isPrefix( const std::string& prefix, const std::string& full)
{
-
-bool isPrefix( const string& prefix, const string& full)
- {
return full.compare(0, prefix.size(), prefix) == 0;
- }
-
}
namespace loplugin
{
struct PluginData
- {
+{
Plugin* (*create)( const Plugin::InstantiationData& );
Plugin* object;
const char* optionName;
bool isPPCallback;
bool byDefault;
- };
+};
const int MAX_PLUGINS = 100;
static PluginData plugins[ MAX_PLUGINS ];
@@ -58,14 +53,14 @@ static int pluginCount = 0;
static bool bPluginObjectsCreated = false;
static bool unitTestMode = false;
-PluginHandler::PluginHandler( CompilerInstance& compiler, const vector< string >& args )
+PluginHandler::PluginHandler( CompilerInstance& compiler, const std::vector< std::string >& args )
: compiler( compiler )
, rewriter( compiler.getSourceManager(), compiler.getLangOpts())
, scope( "mainfile" )
, warningsAsErrors( false )
- {
- set< string > rewriters;
- for( string const & arg : args )
+{
+ std::set< std::string > rewriters;
+ for( std::string const & arg : args )
{
if( arg.size() >= 2 && arg[ 0 ] == '-' && arg[ 1 ] == '-' )
handleOption( arg.substr( 2 ));
@@ -74,58 +69,54 @@ PluginHandler::PluginHandler( CompilerInstance& compiler, const vector< string >
}
createPlugins( rewriters );
bPluginObjectsCreated = true;
- }
+}
PluginHandler::~PluginHandler()
- {
- for( int i = 0;
- i < pluginCount;
- ++i )
+{
+ for( int i = 0; i < pluginCount; ++i )
if( plugins[ i ].object != NULL )
- {
+ {
// PPCallbacks is owned by preprocessor object, don't delete those
if( !plugins[ i ].isPPCallback )
delete plugins[ i ].object;
- }
- }
+ }
+}
bool PluginHandler::isUnitTestMode()
- {
+{
return unitTestMode;
- }
+}
-void PluginHandler::handleOption( const string& option )
- {
+void PluginHandler::handleOption( const std::string& option )
+{
if( option.substr( 0, 6 ) == "scope=" )
- {
+ {
scope = option.substr( 6 );
if( scope == "mainfile" || scope == "all" )
; // ok
else
- {
+ {
struct stat st;
if( stat(( SRCDIR "/" + scope ).c_str(), &st ) != 0 || !S_ISDIR( st.st_mode ))
report( DiagnosticsEngine::Fatal, "unknown scope %0 (no such module directory)" ) << scope;
- }
}
+ }
else if( option.substr( 0, 14 ) == "warnings-only=" )
- {
+ {
warningsOnly = option.substr(14);
- }
+ }
else if( option == "warnings-as-errors" )
warningsAsErrors = true;
else if( option == "unit-test-mode" )
unitTestMode = true;
else
report( DiagnosticsEngine::Fatal, "unknown option %0" ) << option;
- }
+}
-void PluginHandler::createPlugins( set< string > rewriters )
+void PluginHandler::createPlugins( std::set< std::string > rewriters )
+{
+ for( int i = 0; i < pluginCount; ++i )
{
- for( int i = 0;
- i < pluginCount;
- ++i )
- {
const char* name = plugins[i].optionName;
if( rewriters.erase( name ) != 0 )
plugins[ i ].object = plugins[ i ].create( Plugin::InstantiationData { name, *this, compiler, &rewriter } );
@@ -133,13 +124,13 @@ void PluginHandler::createPlugins( set< string > rewriters )
plugins[ i ].object = plugins[ i ].create( Plugin::InstantiationData { name, *this, compiler, NULL } );
else if( unitTestMode && strcmp(name, "unusedmethodsremove") != 0 && strcmp(name, "unusedfieldsremove") != 0)
plugins[ i ].object = plugins[ i ].create( Plugin::InstantiationData { name, *this, compiler, NULL } );
- }
+ }
for( auto r: rewriters )
report( DiagnosticsEngine::Fatal, "unknown plugin tool %0" ) << r;
- }
+}
void PluginHandler::registerPlugin( Plugin* (*create)( const Plugin::InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault )
- {
+{
assert( !bPluginObjectsCreated );
assert( pluginCount < MAX_PLUGINS );
plugins[ pluginCount ].create = create;
@@ -148,42 +139,42 @@ void PluginHandler::registerPlugin( Plugin* (*create)( const Plugin::Instantiati
plugins[ pluginCount ].isPPCallback = isPPCallback;
plugins[ pluginCount ].byDefault = byDefault;
++pluginCount;
- }
+}
DiagnosticBuilder PluginHandler::report( DiagnosticsEngine::Level level, const char* plugin, StringRef message, CompilerInstance& compiler,
SourceLocation loc )
- {
+{
DiagnosticsEngine& diag = compiler.getDiagnostics();
// Do some mappings (e.g. for -Werror) that clang does not do for custom messages for some reason.
if( level == DiagnosticsEngine::Warning && ((diag.getWarningsAsErrors() && (plugin == nullptr || plugin != warningsOnly)) || warningsAsErrors))
level = DiagnosticsEngine::Error;
if( level == DiagnosticsEngine::Error && diag.getErrorsAsFatal())
level = DiagnosticsEngine::Fatal;
- string fullMessage = ( message + " [loplugin" ).str();
+ std::string fullMessage = ( message + " [loplugin" ).str();
if( plugin )
- {
+ {
fullMessage += ":";
fullMessage += plugin;
- }
+ }
fullMessage += "]";
if( loc.isValid())
return diag.Report( loc, compat::getCustomDiagID(diag, level, fullMessage) );
else
return diag.Report( compat::getCustomDiagID(diag, level, fullMessage) );
- }
+}
DiagnosticBuilder PluginHandler::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc )
- {
+{
return report( level, nullptr, message, compiler, loc );
- }
+}
bool PluginHandler::addRemoval( SourceLocation loc )
- {
+{
return removals.insert( loc ).second;
- }
+}
void PluginHandler::HandleTranslationUnit( ASTContext& context )
- {
+{
if( context.getDiagnostics().hasErrorOccurred())
return;
StringRef const mainFileName = context.getSourceManager().getFileEntryForID(context.getSourceManager().getMainFileID())->getName();
@@ -194,18 +185,16 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
return;
}
- for( int i = 0;
- i < pluginCount;
- ++i )
- {
+ for( int i = 0; i < pluginCount; ++i )
+ {
if( plugins[ i ].object != NULL )
- {
+ {
// When in unit-test mode, ignore plugins whose names don't match the filename of the test,
// so that we only generate warnings for the plugin that we want to test.
if (!unitTestMode || mainFileName.find(plugins[ i ].optionName) != StringRef::npos)
plugins[ i ].object->run();
- }
}
+ }
#if defined _WIN32
//TODO: make the call to 'rename' work on Windows (where the renamed-to
// original file is probably still held open somehow):
@@ -214,7 +203,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
for( Rewriter::buffer_iterator it = rewriter.buffer_begin();
it != rewriter.buffer_end();
++it )
- {
+ {
const FileEntry* e = context.getSourceManager().getFileEntryForID( it->first );
if( e == NULL )
continue; // Failed modification because of a macro expansion?
@@ -222,7 +211,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
most probably doesn't matter (generated files in workdir).
The order here is important, as INSTDIR and WORKDIR are often in SRCDIR/BUILDDIR,
and BUILDDIR is sometimes in SRCDIR. */
- string modifyFile;
+ std::string modifyFile;
const char* pathWarning = NULL;
bool bSkip = false;
StringRef const name = e->getName();
@@ -233,25 +222,25 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
else if( name.startswith(SRCDIR "/") )
; // ok
else
- {
+ {
pathWarning = "modified source in unknown location, not modifying : %0";
bSkip = true;
- }
+ }
if( modifyFile.empty())
modifyFile = name;
// Check whether the modified file is in the wanted scope
if( scope == "mainfile" )
- {
+ {
if( it->first != context.getSourceManager().getMainFileID())
continue;
- }
+ }
else if( scope == "all" )
; // ok
else // scope is module
- {
+ {
if( !( isPrefix( SRCDIR "/" + scope + "/", modifyFile ) || isPrefix( SRCDIR "/include/" + scope + "/", modifyFile ) ) )
continue;
- }
+ }
// Warn only now, so that files not in scope do not cause warnings.
if( pathWarning != NULL )
report( DiagnosticsEngine::Warning, pathWarning ) << name;
@@ -259,43 +248,43 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
continue;
char* filename = new char[ modifyFile.length() + 100 ];
sprintf( filename, "%s.new.%d", modifyFile.c_str(), getpid());
- string error;
+ std::string error;
bool bOk = false;
std::unique_ptr<raw_fd_ostream> ostream(
compat::create_raw_fd_ostream(filename, error) );
if( error.empty())
- {
+ {
it->second.write( *ostream );
ostream->close();
if( !ostream->has_error() && rename( filename, modifyFile.c_str()) == 0 )
bOk = true;
- }
+ }
ostream->clear_error();
unlink( filename );
if( !bOk )
report( DiagnosticsEngine::Error, "cannot write modified source to %0 (%1)" ) << modifyFile << error;
delete[] filename;
- }
-#endif
}
+#endif
+ }
#if CLANG_VERSION >= 30600
std::unique_ptr<ASTConsumer> LibreOfficeAction::CreateASTConsumer( CompilerInstance& Compiler, StringRef )
- {
+{
return llvm::make_unique<PluginHandler>( Compiler, _args );
- }
+}
#else
ASTConsumer* LibreOfficeAction::CreateASTConsumer( CompilerInstance& Compiler, StringRef )
- {
+{
return new PluginHandler( Compiler, _args );
- }
+}
#endif
-bool LibreOfficeAction::ParseArgs( const CompilerInstance&, const vector< string >& args )
- {
+bool LibreOfficeAction::ParseArgs( const CompilerInstance&, const std::vector< std::string >& args )
+{
_args = args;
return true;
- }
+}
static FrontendPluginRegistry::Add< loplugin::LibreOfficeAction > X( "loplugin", "LibreOffice compile check plugin" );
diff --git a/compilerplugins/clang/pluginhandler.hxx b/compilerplugins/clang/pluginhandler.hxx
index 222cb258e80f..9c3d0a49c839 100644
--- a/compilerplugins/clang/pluginhandler.hxx
+++ b/compilerplugins/clang/pluginhandler.hxx
@@ -28,45 +28,45 @@ namespace loplugin
*/
class PluginHandler
: public ASTConsumer
- {
- public:
- PluginHandler( CompilerInstance& compiler, const vector< string >& args );
- virtual ~PluginHandler();
- virtual void HandleTranslationUnit( ASTContext& context ) override;
- static void registerPlugin( Plugin* (*create)( const Plugin::InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
- DiagnosticBuilder report( DiagnosticsEngine::Level level, const char * plugin, StringRef message,
+{
+public:
+ PluginHandler( CompilerInstance& compiler, const std::vector< std::string >& args );
+ virtual ~PluginHandler();
+ virtual void HandleTranslationUnit( ASTContext& context ) override;
+ static void registerPlugin( Plugin* (*create)( const Plugin::InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
+ DiagnosticBuilder report( DiagnosticsEngine::Level level, const char * plugin, StringRef message,
CompilerInstance& compiler, SourceLocation loc = SourceLocation());
- bool addRemoval( SourceLocation loc );
- static bool isUnitTestMode();
- private:
- void handleOption( const string& option );
- void createPlugins( set< string > rewriters );
- DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
- CompilerInstance& compiler;
- Rewriter rewriter;
- set< SourceLocation > removals;
- string scope;
- string warningsOnly;
- bool warningsAsErrors;
- };
+ bool addRemoval( SourceLocation loc );
+ static bool isUnitTestMode();
+private:
+ void handleOption( const std::string& option );
+ void createPlugins( std::set< std::string > rewriters );
+ DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
+ CompilerInstance& compiler;
+ Rewriter rewriter;
+ std::set< SourceLocation > removals;
+ std::string scope;
+ std::string warningsOnly;
+ bool warningsAsErrors;
+};
/**
The Clang plugin class, just forwards to PluginHandler.
*/
class LibreOfficeAction
: public PluginASTAction
- {
- public:
+{
+public:
#if CLANG_VERSION >= 30600
- virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
+ virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
#else
- virtual ASTConsumer* CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
+ virtual ASTConsumer* CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
#endif
- virtual bool ParseArgs( const CompilerInstance& CI, const vector< string >& args );
- private:
- vector< string > _args;
- };
+ virtual bool ParseArgs( const CompilerInstance& CI, const std::vector< std::string >& args );
+private:
+ std::vector< std::string > _args;
+};
} // namespace
diff --git a/compilerplugins/clang/sallogareas.cxx b/compilerplugins/clang/sallogareas.cxx
index e6c2997263da..98cafb596fd5 100644
--- a/compilerplugins/clang/sallogareas.cxx
+++ b/compilerplugins/clang/sallogareas.cxx
@@ -202,18 +202,18 @@ bad:
void SalLogAreas::readLogAreas()
{
- ifstream is( SRCDIR "/include/sal/log-areas.dox" );
+ std::ifstream is( SRCDIR "/include/sal/log-areas.dox" );
while( is.good())
{
- string line;
+ std::string line;
getline( is, line );
size_t pos = line.find( "@li @c " );
- if( pos != string::npos )
+ if( pos != std::string::npos )
{
pos += strlen( "@li @c " );
size_t end = line.find( ' ', pos );
std::string area;
- if( end == string::npos )
+ if( end == std::string::npos )
area = line.substr( pos );
else if( pos != end )
area = line.substr( pos, end - pos );
diff --git a/compilerplugins/clang/sallogareas.hxx b/compilerplugins/clang/sallogareas.hxx
index 9133ed69a111..9cb035069e10 100644
--- a/compilerplugins/clang/sallogareas.hxx
+++ b/compilerplugins/clang/sallogareas.hxx
@@ -34,9 +34,9 @@ class SalLogAreas
void readLogAreas();
const FunctionDecl* inFunction;
SourceLocation lastSalDetailLogStreamMacro;
- set< string > logAreas;
+ std::set< std::string > logAreas;
#if 0
- string firstSeenLogArea;
+ std::string firstSeenLogArea;
SourceLocation firstSeenLocation;
#endif
};
diff --git a/compilerplugins/clang/sfxpoolitem.cxx b/compilerplugins/clang/sfxpoolitem.cxx
index 1f723ba107c0..bac6cf361fd4 100644
--- a/compilerplugins/clang/sfxpoolitem.cxx
+++ b/compilerplugins/clang/sfxpoolitem.cxx
@@ -94,7 +94,7 @@ bool isDerivedFromSwMsgPoolItem(const CXXRecordDecl *decl) {
return false;
}
-bool endsWith(const string& a, const string& b) {
+bool endsWith(const std::string& a, const std::string& b) {
if (b.size() > a.size()) return false;
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
}
diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx
index e096b7f96178..5ccadf55a6b1 100644
--- a/compilerplugins/clang/singlevalfields.cxx
+++ b/compilerplugins/clang/singlevalfields.cxx
@@ -84,8 +84,8 @@ public:
output += "asgn:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.value + "\n";
for (const MyFieldInfo & s : definitionSet)
output += "defn:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.sourceLocation + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.singlevalfields.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.singlevalfields.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/unnecessaryvirtual.cxx b/compilerplugins/clang/unnecessaryvirtual.cxx
index ee3d8eced8fe..2655968c8b7c 100644
--- a/compilerplugins/clang/unnecessaryvirtual.cxx
+++ b/compilerplugins/clang/unnecessaryvirtual.cxx
@@ -66,8 +66,8 @@ public:
output += "definition:\t" + s.name + "\t" + s.sourceLocation + "\n";
for (const std::string & s : overridingSet)
output += "overriding:\t" + s + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.unnecessaryvirtual.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.unnecessaryvirtual.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/unusedenumconstants.cxx b/compilerplugins/clang/unusedenumconstants.cxx
index ac4b5c07fa45..a2f052339e84 100644
--- a/compilerplugins/clang/unusedenumconstants.cxx
+++ b/compilerplugins/clang/unusedenumconstants.cxx
@@ -77,8 +77,8 @@ public:
output += "write:\t" + s.parentClass + "\t" + s.fieldName + "\n";
for (const MyFieldInfo & s : readSet)
output += "read:\t" + s.parentClass + "\t" + s.fieldName + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.unusedenumconstants.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.unusedenumconstants.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx
index d12cd19e275f..07eecf2b6771 100644
--- a/compilerplugins/clang/unusedfields.cxx
+++ b/compilerplugins/clang/unusedfields.cxx
@@ -106,8 +106,8 @@ void UnusedFields::run()
{
output += "definition:\t" + s.access + "\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.fieldType + "\t" + s.sourceLocation + "\n";
}
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.unusedfields.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.unusedfields.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
diff --git a/compilerplugins/clang/unusedfieldsremove.cxx b/compilerplugins/clang/unusedfieldsremove.cxx
index afe937df0ecd..ab2359e430a4 100644
--- a/compilerplugins/clang/unusedfieldsremove.cxx
+++ b/compilerplugins/clang/unusedfieldsremove.cxx
@@ -72,11 +72,8 @@ UnusedFieldsRemove::~UnusedFieldsRemove()
std::string niceName(const FieldDecl* fieldDecl)
{
- std::string s = fieldDecl->getParent()->getQualifiedNameAsString() + " " +
+ return fieldDecl->getParent()->getQualifiedNameAsString() + " " +
fieldDecl->getNameAsString();
- if (s.find("m_xExternalProgress") != std::string::npos)
- cout << s << endl;
- return s;
}
bool UnusedFieldsRemove::VisitFieldDecl( const FieldDecl* fieldDecl )
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx
index 6a2d8d2ca2b4..881427fcfd9b 100644
--- a/compilerplugins/clang/unusedmethods.cxx
+++ b/compilerplugins/clang/unusedmethods.cxx
@@ -100,8 +100,8 @@ public:
// for the "method can be private" analysis
for (const MyFuncInfo & s : calledFromOutsideSet)
output += "outside:\t" + s.returnType + "\t" + s.nameAndParams + "\n";
- ofstream myfile;
- myfile.open( SRCDIR "/loplugin.unusedmethods.log", ios::app | ios::out);
+ std::ofstream myfile;
+ myfile.open( SRCDIR "/loplugin.unusedmethods.log", std::ios::app | std::ios::out);
myfile << output;
myfile.close();
}
More information about the Libreoffice-commits
mailing list