1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 public RecursiveASTVisitor
<StringConcat
>, public loplugin::Plugin
18 explicit StringConcat(InstantiationData
const & data
): Plugin(data
) {}
21 { TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl()); }
23 bool VisitCallExpr(CallExpr
const * expr
);
26 bool StringConcat::VisitCallExpr(CallExpr
const * expr
) {
27 if (ignoreLocation(expr
)) {
30 FunctionDecl
const * fdecl
= expr
->getDirectCallee();
31 if (fdecl
== nullptr) {
34 OverloadedOperatorKind oo
= fdecl
->getOverloadedOperator();
35 if ((oo
!= OverloadedOperatorKind::OO_Plus
36 && oo
!= OverloadedOperatorKind::OO_LessLess
)
37 || fdecl
->getNumParams() != 2 || expr
->getNumArgs() != 2
38 || !isa
<StringLiteral
>(expr
->getArg(1)->IgnoreParenImpCasts()))
42 CallExpr
const * left
= dyn_cast
<CallExpr
>(
43 expr
->getArg(0)->IgnoreParenImpCasts());
44 if (left
== nullptr) {
47 FunctionDecl
const * ldecl
= left
->getDirectCallee();
48 if (ldecl
== nullptr) {
51 OverloadedOperatorKind loo
= ldecl
->getOverloadedOperator();
52 if ((loo
!= OverloadedOperatorKind::OO_Plus
53 && loo
!= OverloadedOperatorKind::OO_LessLess
)
54 || ldecl
->getNumParams() != 2 || left
->getNumArgs() != 2
55 || !isa
<StringLiteral
>(left
->getArg(1)->IgnoreParenImpCasts()))
60 compiler
.getSourceManager().getFilename(
61 compiler
.getSourceManager().getSpellingLoc(expr
->getLocStart())) };
62 if (name
== SRCDIR
"/sal/qa/rtl/strings/test_ostring_concat.cxx"
63 || name
== SRCDIR
"/sal/qa/rtl/strings/test_oustring_concat.cxx")
67 CXXOperatorCallExpr
const * op
= dyn_cast
<CXXOperatorCallExpr
>(expr
);
69 DiagnosticsEngine::Warning
,
70 "replace '%0' between string literals with juxtaposition",
71 op
== nullptr ? expr
->getExprLoc() : op
->getOperatorLoc())
72 << (oo
== OverloadedOperatorKind::OO_Plus
? "+" : "<<")
74 left
->getArg(1)->getLocStart(), expr
->getArg(1)->getLocEnd());
78 loplugin::Plugin::Registration
<StringConcat
> X("stringconcat");
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */