From 7b65087eabf9bd233a899723f662665ee5867378 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 21 Apr 2016 10:04:58 +0200 Subject: move stylepolice plugin into store/ seems std::regex is not too well supported yet, at least in libstdc++-4.8 Change-Id: Ib9feb33d2f197d40fc67dc93468aa2f7dae05bac --- compilerplugins/clang/store/stylepolice.cxx | 80 +++++++++++++++++++++++++++++ compilerplugins/clang/stylepolice.cxx | 80 ----------------------------- 2 files changed, 80 insertions(+), 80 deletions(-) create mode 100644 compilerplugins/clang/store/stylepolice.cxx delete mode 100644 compilerplugins/clang/stylepolice.cxx (limited to 'compilerplugins') diff --git a/compilerplugins/clang/store/stylepolice.cxx b/compilerplugins/clang/store/stylepolice.cxx new file mode 100644 index 000000000000..96b5f72c00a7 --- /dev/null +++ b/compilerplugins/clang/store/stylepolice.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +#include "compat.hxx" +#include "plugin.hxx" + +// Check for some basic naming mismatches which make the code harder to read + +namespace { + +static const std::regex aMemberRegex("^m([abnprsx]?[A-Z]|[_][a-zA-Z])"); + +class StylePolice : + public RecursiveASTVisitor, public loplugin::Plugin +{ +public: + explicit StylePolice(InstantiationData const & data): Plugin(data) {} + + virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + + bool VisitVarDecl(const VarDecl *); +private: + StringRef getFilename(SourceLocation loc); +}; + +StringRef StylePolice::getFilename(SourceLocation loc) +{ + SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(loc); + StringRef name { compiler.getSourceManager().getFilename(spellingLocation) }; + return name; +} + +bool StylePolice::VisitVarDecl(const VarDecl * varDecl) +{ + if (ignoreLocation(varDecl)) { + return true; + } + StringRef aFileName = getFilename(varDecl->getLocStart()); + std::string name = varDecl->getName(); + + // these names appear to be taken from some scientific paper + if (aFileName == SRCDIR "/scaddins/source/analysis/bessel.cxx" ) { + return true; + } + // lots of places where we are storing a "method id" here + if (aFileName.startswith(SRCDIR "/connectivity/source/drivers/jdbc") && name.compare(0,3,"mID") == 0) { + return true; + } + + if (!varDecl->isLocalVarDecl()) { + return true; + } + + if (std::regex_search(name, aMemberRegex)) + { + report( + DiagnosticsEngine::Warning, + "this local variable follows our member field naming convention, which is confusing", + varDecl->getLocation()) + << varDecl->getType() << varDecl->getSourceRange(); + } + return true; +} + + +loplugin::Plugin::Registration< StylePolice > X("stylepolice"); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/stylepolice.cxx b/compilerplugins/clang/stylepolice.cxx deleted file mode 100644 index 96b5f72c00a7..000000000000 --- a/compilerplugins/clang/stylepolice.cxx +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include -#include -#include - -#include "compat.hxx" -#include "plugin.hxx" - -// Check for some basic naming mismatches which make the code harder to read - -namespace { - -static const std::regex aMemberRegex("^m([abnprsx]?[A-Z]|[_][a-zA-Z])"); - -class StylePolice : - public RecursiveASTVisitor, public loplugin::Plugin -{ -public: - explicit StylePolice(InstantiationData const & data): Plugin(data) {} - - virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } - - bool VisitVarDecl(const VarDecl *); -private: - StringRef getFilename(SourceLocation loc); -}; - -StringRef StylePolice::getFilename(SourceLocation loc) -{ - SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(loc); - StringRef name { compiler.getSourceManager().getFilename(spellingLocation) }; - return name; -} - -bool StylePolice::VisitVarDecl(const VarDecl * varDecl) -{ - if (ignoreLocation(varDecl)) { - return true; - } - StringRef aFileName = getFilename(varDecl->getLocStart()); - std::string name = varDecl->getName(); - - // these names appear to be taken from some scientific paper - if (aFileName == SRCDIR "/scaddins/source/analysis/bessel.cxx" ) { - return true; - } - // lots of places where we are storing a "method id" here - if (aFileName.startswith(SRCDIR "/connectivity/source/drivers/jdbc") && name.compare(0,3,"mID") == 0) { - return true; - } - - if (!varDecl->isLocalVarDecl()) { - return true; - } - - if (std::regex_search(name, aMemberRegex)) - { - report( - DiagnosticsEngine::Warning, - "this local variable follows our member field naming convention, which is confusing", - varDecl->getLocation()) - << varDecl->getType() << varDecl->getSourceRange(); - } - return true; -} - - -loplugin::Plugin::Registration< StylePolice > X("stylepolice"); - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit