summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-04-27 09:22:13 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-04-28 09:31:16 +0000
commit43b4903db3e925c652e25c34362490f8adc9c5ec (patch)
treeaf12777b72d42280467e8cc19b914b2c7f4f3816 /compilerplugins
parent7d6308dad9f4a079d57719a6e3a9c4cebb47d051 (diff)
teach stylepolice plugin about ref-counted-pointer naming
Change-Id: I6e91d22fc1826038c05ddb6fc065563c6a250752 Reviewed-on: https://gerrit.libreoffice.org/24459 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stylepolice.cxx69
1 files changed, 58 insertions, 11 deletions
diff --git a/compilerplugins/clang/stylepolice.cxx b/compilerplugins/clang/stylepolice.cxx
index 3ae718c54712..c6f0e16e55fb 100644
--- a/compilerplugins/clang/stylepolice.cxx
+++ b/compilerplugins/clang/stylepolice.cxx
@@ -15,6 +15,10 @@
#include "plugin.hxx"
// Check for some basic naming mismatches which make the code harder to read
+//
+// This plugin is deliberately fairly lax, and only targets the most egregeriously faulty code,
+// since we have a broad range of styles in our code and we don't want to generate unnecessary
+// churn.
namespace {
@@ -53,6 +57,9 @@ bool isIdentifierLetter(char c) {
bool matchPointerVar(const std::string& s) {
return s.size() > 2 && s[0] == 'p' && isUpperLetter(s[1]);
}
+bool matchRefCountedPointerVar(const std::string& s) {
+ return s.size() > 2 && s[0] == 'x' && isUpperLetter(s[1]);
+}
bool matchMember(const std::string& s) {
return s.size() > 3 && s[0] == 'm'
&& ( ( strchr("abnprsx", s[1]) && isUpperLetter(s[2]) )
@@ -95,7 +102,12 @@ bool StylePolice::VisitVarDecl(const VarDecl * varDecl)
typeName = typeName.substr(6);
if (startswith(typeName, "class "))
typeName = typeName.substr(6);
+ if (startswith(typeName, "struct "))
+ typeName = typeName.substr(7);
std::string aOriginalTypeName = varDecl->getType().getAsString();
+ if (startswith(aOriginalTypeName, "const "))
+ aOriginalTypeName = aOriginalTypeName.substr(6);
+
if (!qt->isPointerType() && !qt->isArrayType() && !qt->isFunctionPointerType() && !qt->isMemberPointerType()
&& matchPointerVar(name)
&& !startswith(typeName, "boost::intrusive_ptr")
@@ -107,17 +119,11 @@ bool StylePolice::VisitVarDecl(const VarDecl * varDecl)
&& aOriginalTypeName != "GLXPixmap"
&& !startswith(typeName, "rtl::Reference")
&& !startswith(typeName, "ScopedVclPtr")
- && !startswith(typeName, "std::mem_fun")
- && !startswith(typeName, "std::__1::mem_fun")
- && !startswith(typeName, "std::shared_ptr")
- && !startswith(typeName, "std::__1::shared_ptr")
- && !startswith(typeName, "shared_ptr") // weird issue in slideshow
- && !startswith(typeName, "std::unique_ptr")
- && !startswith(typeName, "std::__1::unique_ptr")
- && !startswith(typeName, "unique_ptr") // weird issue in include/vcl/threadex.hxx
- && !startswith(typeName, "std::weak_ptr")
- && !startswith(typeName, "std::__1::weak_ptr")
- && !startswith(typeName, "struct _LOKDocViewPrivate")
+ && typeName.find("::mem_fun") == std::string::npos
+ && typeName.find("shared_ptr") == std::string::npos
+ && typeName.find("unique_ptr") == std::string::npos
+ && typeName.find("::weak_ptr") == std::string::npos
+ && !startswith(typeName, "_LOKDocViewPrivate")
&& !startswith(typeName, "sw::UnoCursorPointer")
&& !startswith(typeName, "tools::SvRef")
&& !startswith(typeName, "VclPtr")
@@ -138,6 +144,47 @@ bool StylePolice::VisitVarDecl(const VarDecl * varDecl)
<< typeName << aOriginalTypeName << varDecl->getSourceRange();
}
}
+
+
+ if (matchRefCountedPointerVar(name)
+ && !startswith(typeName, "boost::intrusive_ptr")
+ && !startswith(typeName, "com::sun::star::uno::Reference")
+ && !startswith(typeName, "com::sun::star::uno::Sequence")
+ && !startswith(typeName, "com::sun::star::uno::WeakReference")
+ && !startswith(typeName, "drawinglayer::primitive2d::Primitive2DContainer")
+ && !startswith(typeName, "drawinglayer::primitive3d::Primitive3DContainer")
+ && !startswith(typeName, "jfw::CXPathObjectPtr")
+ && !startswith(typeName, "_LOKDocViewPrivate")
+ && !startswith(typeName, "oox::dump::BinaryInputStreamRef")
+ && !startswith(typeName, "oox::drawingml::chart::ModelRef")
+ && !startswith(typeName, "rtl::Reference")
+ && !startswith(typeName, "Reference")
+ && !startswith(typeName, "SfxObjectShellLock")
+ && !startswith(typeName, "store::PageHolderObject")
+ && !startswith(typeName, "store::ResourceHolder")
+ && !startswith(typeName, "store::OStoreHandle")
+ && typeName.find("unique_ptr") == std::string::npos
+ && typeName.find("shared_ptr") == std::string::npos
+ && !startswith(typeName, "ScopedVclPtr")
+ && !startswith(typeName, "svt::EmbeddedObjectRef")
+ && !startswith(typeName, "tools::SvRef")
+ && !startswith(typeName, "tools::WeakReference")
+ && !startswith(typeName, "utl::SharedUNOComponent")
+ && !startswith(typeName, "VclPtr")
+ && !startswith(typeName, "vcl::DeleteOnDeinit")
+ && !startswith(typeName, "vcl::DeleteUnoReferenceOnDeinit")
+ // there are lots of coordinate/position vars that start with "x"
+ && !qt->isArithmeticType()
+ )
+ {
+ report(
+ DiagnosticsEngine::Warning,
+ "this local variable of type '%0' follows our ref-counted-pointer naming convention, but it is not a ref-counted-pointer, %1",
+ varDecl->getLocation())
+ << typeName << aOriginalTypeName << varDecl->getSourceRange();
+ }
+
+
return true;
}