loplugin:stringconcat: Adapt to definition of OSL_THIS_FUNC on Windows

Change-Id: I9a2be8c4265095ff2ac5e2216cb08c35c9049bf8
This commit is contained in:
Stephan Bergmann
2016-12-18 14:11:58 +01:00
parent dbbd2c48b1
commit 9ed9ca611a

View File

@@ -36,10 +36,6 @@ Expr const * stripCtor(Expr const * expr) {
return e3->getArg(0)->IgnoreParenImpCasts();
}
bool isStringLiteral(Expr const * expr) {
return isa<clang::StringLiteral>(stripCtor(expr));
}
class StringConcat:
public RecursiveASTVisitor<StringConcat>, public loplugin::Plugin
{
@@ -50,6 +46,9 @@ public:
{ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
bool VisitCallExpr(CallExpr const * expr);
private:
bool isStringLiteral(Expr const * expr);
};
bool StringConcat::VisitCallExpr(CallExpr const * expr) {
@@ -109,6 +108,24 @@ bool StringConcat::VisitCallExpr(CallExpr const * expr) {
return true;
}
bool StringConcat::isStringLiteral(Expr const * expr) {
expr = stripCtor(expr);
if (!isa<clang::StringLiteral>(expr)) {
return false;
}
// OSL_THIS_FUNC may be defined as "" in include/osl/diagnose.h, so don't
// warn about expressions like 'SAL_INFO(..., OSL_THIS_FUNC << ":")' or
// 'OUString(OSL_THIS_FUNC) + ":"':
auto loc = expr->getLocStart();
while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
}
return !compiler.getSourceManager().isMacroBodyExpansion(loc)
|| (Lexer::getImmediateMacroName(
loc, compiler.getSourceManager(), compiler.getLangOpts())
!= "OSL_THIS_FUNC");
}
loplugin::Plugin::Registration<StringConcat> X("stringconcat");
}