summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-07-01 17:38:02 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-07-01 17:49:10 +0200
commit9263b101c39172cbcf04189c515bca80cb15f3aa (patch)
tree6afe725fda4f3e50fb89a69e16e642b0d41dbf62 /compilerplugins
parent485a7c880fd2675ff9c5fc792d4caae980b4535e (diff)
Activate the "suspicious cast to sal_Bool" parts of loplugin:salbool
Change-Id: I78a368ef2899b2462251b45a327fc7b1f31fe764
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/salbool.cxx (renamed from compilerplugins/clang/store/salbool.cxx)45
1 files changed, 28 insertions, 17 deletions
diff --git a/compilerplugins/clang/store/salbool.cxx b/compilerplugins/clang/salbool.cxx
index abef250cab5f..a3476be2d8de 100644
--- a/compilerplugins/clang/store/salbool.cxx
+++ b/compilerplugins/clang/salbool.cxx
@@ -9,6 +9,7 @@
#include <algorithm>
#include <cassert>
+#include <cstdlib>
#include <set>
#include <string>
@@ -106,7 +107,10 @@ class SalBool:
public RecursiveASTVisitor<SalBool>, public loplugin::RewritePlugin
{
public:
- explicit SalBool(InstantiationData const & data): RewritePlugin(data) {}
+ explicit SalBool(InstantiationData const & data):
+ RewritePlugin(data),
+ fullMode_(std::getenv("loplugin:salbool") != nullptr)
+ {}
virtual void run() override;
@@ -139,6 +143,7 @@ private:
bool rewrite(SourceLocation location);
+ bool fullMode_;
std::set<VarDecl const *> varDecls_;
};
@@ -178,7 +183,7 @@ void SalBool::run() {
}
}
}
- if (!rewrite(loc)) {
+ if (fullMode_ && !rewrite(loc)) {
report(
DiagnosticsEngine::Warning,
"VarDecl, use \"bool\" instead of \"sal_Bool\"", loc)
@@ -322,13 +327,15 @@ bool SalBool::VisitParmVarDecl(ParmVarDecl const * decl) {
// with a "mismatch" error before the rewriter had a chance
// to act upon the definition (but use the heuristic of
// assuming pure virtual functions do not have definitions):
- if (!((isInMainFile(
- compiler.getSourceManager().getSpellingLoc(
- dyn_cast<FunctionDecl>(
- decl->getDeclContext())
- ->getNameInfo().getLoc()))
- || f->isDefined() || f->isPure())
- && rewrite(loc)))
+ if (fullMode_
+ && !((compat::isInMainFile(
+ compiler.getSourceManager(),
+ compiler.getSourceManager().getSpellingLoc(
+ dyn_cast<FunctionDecl>(
+ decl->getDeclContext())
+ ->getNameInfo().getLoc()))
+ || f->isDefined() || f->isPure())
+ && rewrite(loc)))
{
report(
DiagnosticsEngine::Warning,
@@ -409,7 +416,7 @@ bool SalBool::VisitFieldDecl(FieldDecl const * decl) {
}
}
}
- if (!rewrite(loc)) {
+ if (fullMode_ && !rewrite(loc)) {
report(
DiagnosticsEngine::Warning,
"FieldDecl, use \"bool\" instead of \"sal_Bool\"", loc)
@@ -467,11 +474,13 @@ bool SalBool::VisitFunctionDecl(FunctionDecl const * decl) {
// rewriter had a chance to act upon the definition (but use the
// heuristic of assuming pure virtual functions do not have
// definitions):
- if (!((isInMainFile(
- compiler.getSourceManager().getSpellingLoc(
- decl->getNameInfo().getLoc()))
- || f->isDefined() || f->isPure())
- && rewrite(loc)))
+ if (fullMode_
+ && !((compat::isInMainFile(
+ compiler.getSourceManager(),
+ compiler.getSourceManager().getSpellingLoc(
+ decl->getNameInfo().getLoc()))
+ || f->isDefined() || f->isPure())
+ && rewrite(loc)))
{
report(
DiagnosticsEngine::Warning,
@@ -487,7 +496,9 @@ bool SalBool::VisitValueDecl(ValueDecl const * decl) {
if (ignoreLocation(decl)) {
return true;
}
- if (isSalBool(decl->getType()) && !rewrite(decl->getLocStart())) {
+ if (fullMode_ && isSalBool(decl->getType())
+ && !rewrite(decl->getLocStart()))
+ {
report(
DiagnosticsEngine::Warning,
"ValueDecl, use \"bool\" instead of \"sal_Bool\"",
@@ -498,7 +509,7 @@ bool SalBool::VisitValueDecl(ValueDecl const * decl) {
}
bool SalBool::isInSpecialMainFile(SourceLocation spellingLocation) const {
- return compat::isInMainFile(spellingLocation)
+ return compat::isInMainFile(compiler.getSourceManager(), spellingLocation)
&& (compiler.getSourceManager().getFilename(spellingLocation)
== SRCDIR "/cppu/qa/test_any.cxx");
}