2019-03-25 20:36:30 +08:00
|
|
|
//===--- ClangTidyCheck.h - clang-tidy --------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYCHECK_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYCHECK_H
|
|
|
|
|
|
|
|
#include "ClangTidyDiagnosticConsumer.h"
|
|
|
|
#include "ClangTidyOptions.h"
|
|
|
|
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2020-04-08 02:53:52 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2019-03-25 20:36:30 +08:00
|
|
|
#include <type_traits>
|
2020-06-29 23:05:51 +08:00
|
|
|
#include <utility>
|
2019-03-25 20:36:30 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
class CompilerInstance;
|
2020-06-29 23:05:51 +08:00
|
|
|
class SourceManager;
|
2019-03-25 20:36:30 +08:00
|
|
|
|
|
|
|
namespace tidy {
|
|
|
|
|
2020-07-11 17:10:59 +08:00
|
|
|
/// This class should be specialized by any enum type that needs to be converted
|
|
|
|
/// to and from an \ref llvm::StringRef.
|
|
|
|
template <class T> struct OptionEnumMapping {
|
|
|
|
// Specializations of this struct must implement this function.
|
|
|
|
static ArrayRef<std::pair<T, StringRef>> getEnumMapping() = delete;
|
|
|
|
};
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Base class for all clang-tidy checks.
|
2019-03-25 20:36:30 +08:00
|
|
|
///
|
|
|
|
/// To implement a ``ClangTidyCheck``, write a subclass and override some of the
|
|
|
|
/// base class's methods. E.g. to implement a check that validates namespace
|
|
|
|
/// declarations, override ``registerMatchers``:
|
|
|
|
///
|
|
|
|
/// ~~~{.cpp}
|
|
|
|
/// void registerMatchers(ast_matchers::MatchFinder *Finder) override {
|
|
|
|
/// Finder->addMatcher(namespaceDecl().bind("namespace"), this);
|
|
|
|
/// }
|
|
|
|
/// ~~~
|
|
|
|
///
|
|
|
|
/// and then override ``check(const MatchResult &Result)`` to do the actual
|
|
|
|
/// check for each match.
|
|
|
|
///
|
|
|
|
/// A new ``ClangTidyCheck`` instance is created per translation unit.
|
|
|
|
///
|
|
|
|
/// FIXME: Figure out whether carrying information from one TU to another is
|
|
|
|
/// useful/necessary.
|
|
|
|
class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
|
|
|
|
public:
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Initializes the check with \p CheckName and \p Context.
|
2019-03-25 20:36:30 +08:00
|
|
|
///
|
|
|
|
/// Derived classes must implement the constructor with this signature or
|
|
|
|
/// delegate it. If a check needs to read options, it can do this in the
|
|
|
|
/// constructor using the Options.get() methods below.
|
|
|
|
ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context);
|
|
|
|
|
[clang-tidy] Added virtual isLanguageVersionSupported to ClangTidyCheck
Summary:
Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=45045 | Tune inspections to a specific C++ standard. ]]
Moves the isLanguageVersionSupported virtual function from `MakeSmartPtrCheck` to the base `ClangTidyCheck` class.
This will disable registering matchers or pp callbacks on unsupported language versions for a check.
Having it as a standalone function is cleaner than manually disabling the check in the register function and should hopefully
encourage check developers to actually restrict the check based on language version.
As an added bonus this could enable automatic detection of what language version a check runs on for the purpose of documentation generation
Reviewers: aaron.ballman, gribozavr2, Eugene.Zelenko, JonasToth, alexfh, hokein
Reviewed By: gribozavr2
Subscribers: xazax.hun, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75289
2020-02-28 21:03:30 +08:00
|
|
|
/// Override this to disable registering matchers and PP callbacks if an
|
|
|
|
/// invalid language version is being used.
|
|
|
|
///
|
|
|
|
/// For example if a check is examining overloaded functions then this should
|
|
|
|
/// be overridden to return false when the CPlusPlus flag is not set in
|
|
|
|
/// \p LangOpts.
|
|
|
|
virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Override this to register ``PPCallbacks`` in the preprocessor.
|
2019-03-25 20:36:30 +08:00
|
|
|
///
|
|
|
|
/// This should be used for clang-tidy checks that analyze preprocessor-
|
|
|
|
/// dependent properties, e.g. include directives and macro definitions.
|
|
|
|
///
|
[clang-tidy] Added virtual isLanguageVersionSupported to ClangTidyCheck
Summary:
Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=45045 | Tune inspections to a specific C++ standard. ]]
Moves the isLanguageVersionSupported virtual function from `MakeSmartPtrCheck` to the base `ClangTidyCheck` class.
This will disable registering matchers or pp callbacks on unsupported language versions for a check.
Having it as a standalone function is cleaner than manually disabling the check in the register function and should hopefully
encourage check developers to actually restrict the check based on language version.
As an added bonus this could enable automatic detection of what language version a check runs on for the purpose of documentation generation
Reviewers: aaron.ballman, gribozavr2, Eugene.Zelenko, JonasToth, alexfh, hokein
Reviewed By: gribozavr2
Subscribers: xazax.hun, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75289
2020-02-28 21:03:30 +08:00
|
|
|
/// This will only be executed if the function isLanguageVersionSupported
|
|
|
|
/// returns true.
|
|
|
|
///
|
2019-03-25 20:36:30 +08:00
|
|
|
/// There are two Preprocessors to choose from that differ in how they handle
|
|
|
|
/// modular #includes:
|
|
|
|
/// - PP is the real Preprocessor. It doesn't walk into modular #includes and
|
|
|
|
/// thus doesn't generate PPCallbacks for their contents.
|
|
|
|
/// - ModuleExpanderPP preprocesses the whole translation unit in the
|
|
|
|
/// non-modular mode, which allows it to generate PPCallbacks not only for
|
|
|
|
/// the main file and textual headers, but also for all transitively
|
|
|
|
/// included modular headers when the analysis runs with modules enabled.
|
|
|
|
/// When modules are not enabled ModuleExpanderPP just points to the real
|
|
|
|
/// preprocessor.
|
|
|
|
virtual void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
|
|
|
|
Preprocessor *ModuleExpanderPP) {}
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Override this to register AST matchers with \p Finder.
|
2019-03-25 20:36:30 +08:00
|
|
|
///
|
|
|
|
/// This should be used by clang-tidy checks that analyze code properties that
|
|
|
|
/// dependent on AST knowledge.
|
|
|
|
///
|
|
|
|
/// You can register as many matchers as necessary with \p Finder. Usually,
|
|
|
|
/// "this" will be used as callback, but you can also specify other callback
|
|
|
|
/// classes. Thereby, different matchers can trigger different callbacks.
|
|
|
|
///
|
[clang-tidy] Added virtual isLanguageVersionSupported to ClangTidyCheck
Summary:
Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=45045 | Tune inspections to a specific C++ standard. ]]
Moves the isLanguageVersionSupported virtual function from `MakeSmartPtrCheck` to the base `ClangTidyCheck` class.
This will disable registering matchers or pp callbacks on unsupported language versions for a check.
Having it as a standalone function is cleaner than manually disabling the check in the register function and should hopefully
encourage check developers to actually restrict the check based on language version.
As an added bonus this could enable automatic detection of what language version a check runs on for the purpose of documentation generation
Reviewers: aaron.ballman, gribozavr2, Eugene.Zelenko, JonasToth, alexfh, hokein
Reviewed By: gribozavr2
Subscribers: xazax.hun, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75289
2020-02-28 21:03:30 +08:00
|
|
|
/// This will only be executed if the function isLanguageVersionSupported
|
|
|
|
/// returns true.
|
|
|
|
///
|
2019-03-25 20:36:30 +08:00
|
|
|
/// If you need to merge information between the different matchers, you can
|
|
|
|
/// store these as members of the derived class. However, note that all
|
|
|
|
/// matches occur in the order of the AST traversal.
|
|
|
|
virtual void registerMatchers(ast_matchers::MatchFinder *Finder) {}
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// ``ClangTidyChecks`` that register ASTMatchers should do the actual
|
2019-03-25 20:36:30 +08:00
|
|
|
/// work in here.
|
|
|
|
virtual void check(const ast_matchers::MatchFinder::MatchResult &Result) {}
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Add a diagnostic with the check's name.
|
2019-03-25 20:36:30 +08:00
|
|
|
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description,
|
|
|
|
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
|
|
|
|
|
2020-12-09 04:28:42 +08:00
|
|
|
/// Add a diagnostic with the check's name.
|
|
|
|
DiagnosticBuilder diag(StringRef Description,
|
|
|
|
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
|
|
|
|
|
|
|
|
/// Adds a diagnostic to report errors in the check's configuration.
|
|
|
|
DiagnosticBuilder
|
|
|
|
configurationDiag(StringRef Description,
|
|
|
|
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Should store all options supported by this check with their
|
2019-03-25 20:36:30 +08:00
|
|
|
/// current values or default values for options that haven't been overridden.
|
|
|
|
///
|
|
|
|
/// The check should use ``Options.store()`` to store each option it supports
|
|
|
|
/// whether it has the default value or it has been overridden.
|
|
|
|
virtual void storeOptions(ClangTidyOptions::OptionMap &Options) {}
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Provides access to the ``ClangTidyCheck`` options via check-local
|
2019-03-25 20:36:30 +08:00
|
|
|
/// names.
|
|
|
|
///
|
|
|
|
/// Methods of this class prepend ``CheckName + "."`` to translate check-local
|
|
|
|
/// option names to global option names.
|
|
|
|
class OptionsView {
|
2021-03-02 01:55:16 +08:00
|
|
|
void diagnoseBadIntegerOption(const Twine &Lookup,
|
|
|
|
StringRef Unparsed) const;
|
|
|
|
void diagnoseBadBooleanOption(const Twine &Lookup,
|
|
|
|
StringRef Unparsed) const;
|
|
|
|
void diagnoseBadEnumOption(const Twine &Lookup, StringRef Unparsed,
|
|
|
|
StringRef Suggestion = StringRef()) const;
|
|
|
|
|
2019-03-25 20:36:30 +08:00
|
|
|
public:
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Initializes the instance using \p CheckName + "." as a prefix.
|
2019-03-25 20:36:30 +08:00
|
|
|
OptionsView(StringRef CheckName,
|
2020-12-09 04:28:42 +08:00
|
|
|
const ClangTidyOptions::OptionMap &CheckOptions,
|
|
|
|
ClangTidyContext *Context);
|
2019-03-25 20:36:30 +08:00
|
|
|
|
2020-04-08 02:53:52 +08:00
|
|
|
/// Read a named option from the ``Context``.
|
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from the
|
2021-03-02 01:55:16 +08:00
|
|
|
/// ``CheckOptions``. If the corresponding key is not present, return
|
|
|
|
/// ``None``.
|
|
|
|
llvm::Optional<std::string> get(StringRef LocalName) const;
|
2020-04-08 02:53:52 +08:00
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Read a named option from the ``Context``.
|
2019-03-25 20:36:30 +08:00
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from the
|
|
|
|
/// ``CheckOptions``. If the corresponding key is not present, returns
|
|
|
|
/// \p Default.
|
2021-03-02 01:55:16 +08:00
|
|
|
std::string get(StringRef LocalName, StringRef Default) const;
|
2020-04-08 02:53:52 +08:00
|
|
|
|
|
|
|
/// Read a named option from the ``Context``.
|
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from local or
|
|
|
|
/// global ``CheckOptions``. Gets local option first. If local is not
|
|
|
|
/// present, falls back to get global option. If global option is not
|
2021-03-02 01:55:16 +08:00
|
|
|
/// present either, return ``None``.
|
|
|
|
llvm::Optional<std::string> getLocalOrGlobal(StringRef LocalName) const;
|
2019-03-25 20:36:30 +08:00
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Read a named option from the ``Context``.
|
2019-03-25 20:36:30 +08:00
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from local or
|
|
|
|
/// global ``CheckOptions``. Gets local option first. If local is not
|
|
|
|
/// present, falls back to get global option. If global option is not
|
2020-04-08 02:53:52 +08:00
|
|
|
/// present either, returns \p Default.
|
2021-03-02 01:55:16 +08:00
|
|
|
std::string getLocalOrGlobal(StringRef LocalName, StringRef Default) const;
|
2019-03-25 20:36:30 +08:00
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Read a named option from the ``Context`` and parse it as an
|
2019-03-25 20:36:30 +08:00
|
|
|
/// integral type ``T``.
|
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from the
|
2021-03-02 01:55:16 +08:00
|
|
|
/// ``CheckOptions``. If the corresponding key is not present, return
|
|
|
|
/// ``None``.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a ``T``, emit a
|
|
|
|
/// diagnostic and return ``None``.
|
2020-04-08 02:53:52 +08:00
|
|
|
template <typename T>
|
2021-03-02 01:55:16 +08:00
|
|
|
std::enable_if_t<std::is_integral<T>::value, llvm::Optional<T>>
|
2020-04-08 02:53:52 +08:00
|
|
|
get(StringRef LocalName) const {
|
2021-03-02 01:55:16 +08:00
|
|
|
if (llvm::Optional<std::string> Value = get(LocalName)) {
|
2020-04-08 02:53:52 +08:00
|
|
|
T Result{};
|
|
|
|
if (!StringRef(*Value).getAsInteger(10, Result))
|
|
|
|
return Result;
|
2021-03-02 01:55:16 +08:00
|
|
|
diagnoseBadIntegerOption(NamePrefix + LocalName, *Value);
|
|
|
|
}
|
|
|
|
return None;
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Read a named option from the ``Context`` and parse it as an
|
|
|
|
/// integral type ``T``.
|
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from the
|
2021-03-02 01:55:16 +08:00
|
|
|
/// ``CheckOptions``. If the corresponding key is not present, return
|
|
|
|
/// \p Default.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a ``T``, emit a
|
|
|
|
/// diagnostic and return \p Default.
|
2019-03-25 20:36:30 +08:00
|
|
|
template <typename T>
|
Use std::foo_t rather than std::foo in LLVM.
Summary: C++14 migration. No functional change.
Reviewers: bkramer, JDevlieghere, lebedev.ri
Subscribers: MatzeB, hiraditya, jkorous, dexonsmith, arphaman, kadircet, lebedev.ri, usaxena95, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D74384
2020-02-11 12:33:08 +08:00
|
|
|
std::enable_if_t<std::is_integral<T>::value, T> get(StringRef LocalName,
|
|
|
|
T Default) const {
|
2021-03-02 01:55:16 +08:00
|
|
|
return get<T>(LocalName).getValueOr(Default);
|
2019-03-25 20:36:30 +08:00
|
|
|
}
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Read a named option from the ``Context`` and parse it as an
|
2019-03-25 20:36:30 +08:00
|
|
|
/// integral type ``T``.
|
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from local or
|
|
|
|
/// global ``CheckOptions``. Gets local option first. If local is not
|
|
|
|
/// present, falls back to get global option. If global option is not
|
2021-03-02 01:55:16 +08:00
|
|
|
/// present either, return ``None``.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a ``T``, emit a
|
|
|
|
/// diagnostic and return ``None``.
|
2020-04-08 02:53:52 +08:00
|
|
|
template <typename T>
|
2021-03-02 01:55:16 +08:00
|
|
|
std::enable_if_t<std::is_integral<T>::value, llvm::Optional<T>>
|
2020-04-08 02:53:52 +08:00
|
|
|
getLocalOrGlobal(StringRef LocalName) const {
|
2021-03-02 01:55:16 +08:00
|
|
|
llvm::Optional<std::string> ValueOr = get(LocalName);
|
2020-04-08 02:53:52 +08:00
|
|
|
bool IsGlobal = false;
|
|
|
|
if (!ValueOr) {
|
|
|
|
IsGlobal = true;
|
|
|
|
ValueOr = getLocalOrGlobal(LocalName);
|
|
|
|
if (!ValueOr)
|
2021-03-02 01:55:16 +08:00
|
|
|
return None;
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
T Result{};
|
|
|
|
if (!StringRef(*ValueOr).getAsInteger(10, Result))
|
|
|
|
return Result;
|
2021-03-02 01:55:16 +08:00
|
|
|
diagnoseBadIntegerOption(
|
|
|
|
IsGlobal ? Twine(LocalName) : NamePrefix + LocalName, *ValueOr);
|
|
|
|
return None;
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Read a named option from the ``Context`` and parse it as an
|
|
|
|
/// integral type ``T``.
|
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from local or
|
|
|
|
/// global ``CheckOptions``. Gets local option first. If local is not
|
|
|
|
/// present, falls back to get global option. If global option is not
|
2021-03-02 01:55:16 +08:00
|
|
|
/// present either, return \p Default.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a ``T``, emit a
|
|
|
|
/// diagnostic and return \p Default.
|
2019-03-25 20:36:30 +08:00
|
|
|
template <typename T>
|
Use std::foo_t rather than std::foo in LLVM.
Summary: C++14 migration. No functional change.
Reviewers: bkramer, JDevlieghere, lebedev.ri
Subscribers: MatzeB, hiraditya, jkorous, dexonsmith, arphaman, kadircet, lebedev.ri, usaxena95, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D74384
2020-02-11 12:33:08 +08:00
|
|
|
std::enable_if_t<std::is_integral<T>::value, T>
|
2019-03-25 20:36:30 +08:00
|
|
|
getLocalOrGlobal(StringRef LocalName, T Default) const {
|
2021-03-02 01:55:16 +08:00
|
|
|
return getLocalOrGlobal<T>(LocalName).getValueOr(Default);
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Read a named option from the ``Context`` and parse it as an
|
2020-07-11 17:10:59 +08:00
|
|
|
/// enum type ``T``.
|
2020-04-08 02:53:52 +08:00
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from the
|
2021-03-02 01:55:16 +08:00
|
|
|
/// ``CheckOptions``. If the corresponding key is not present, return
|
|
|
|
/// ``None``.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a ``T``, emit a
|
|
|
|
/// diagnostic and return ``None``.
|
2020-07-11 17:10:59 +08:00
|
|
|
///
|
|
|
|
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
|
|
|
|
/// supply the mapping required to convert between ``T`` and a string.
|
2020-04-08 02:53:52 +08:00
|
|
|
template <typename T>
|
2021-03-02 01:55:16 +08:00
|
|
|
std::enable_if_t<std::is_enum<T>::value, llvm::Optional<T>>
|
2020-07-28 21:52:32 +08:00
|
|
|
get(StringRef LocalName, bool IgnoreCase = false) const {
|
2021-03-02 01:55:16 +08:00
|
|
|
if (llvm::Optional<int64_t> ValueOr =
|
2020-07-11 17:10:59 +08:00
|
|
|
getEnumInt(LocalName, typeEraseMapping<T>(), false, IgnoreCase))
|
2020-04-08 02:53:52 +08:00
|
|
|
return static_cast<T>(*ValueOr);
|
2021-03-02 01:55:16 +08:00
|
|
|
return None;
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Read a named option from the ``Context`` and parse it as an
|
2020-07-11 17:10:59 +08:00
|
|
|
/// enum type ``T``.
|
2020-04-08 02:53:52 +08:00
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from the
|
2021-03-02 01:55:16 +08:00
|
|
|
/// ``CheckOptions``. If the corresponding key is not present, return
|
|
|
|
/// \p Default.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a ``T``, emit a
|
|
|
|
/// diagnostic and return \p Default.
|
2020-07-11 17:10:59 +08:00
|
|
|
///
|
|
|
|
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
|
|
|
|
/// supply the mapping required to convert between ``T`` and a string.
|
2020-04-08 02:53:52 +08:00
|
|
|
template <typename T>
|
|
|
|
std::enable_if_t<std::is_enum<T>::value, T>
|
2020-07-28 21:52:32 +08:00
|
|
|
get(StringRef LocalName, T Default, bool IgnoreCase = false) const {
|
2021-03-02 01:55:16 +08:00
|
|
|
return get<T>(LocalName, IgnoreCase).getValueOr(Default);
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Read a named option from the ``Context`` and parse it as an
|
2020-07-11 17:10:59 +08:00
|
|
|
/// enum type ``T``.
|
2020-04-08 02:53:52 +08:00
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from local or
|
|
|
|
/// global ``CheckOptions``. Gets local option first. If local is not
|
|
|
|
/// present, falls back to get global option. If global option is not
|
2021-03-02 01:55:16 +08:00
|
|
|
/// present either, returns ``None``.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a ``T``, emit a
|
|
|
|
/// diagnostic and return ``None``.
|
2020-07-11 17:10:59 +08:00
|
|
|
///
|
|
|
|
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
|
|
|
|
/// supply the mapping required to convert between ``T`` and a string.
|
2020-04-08 02:53:52 +08:00
|
|
|
template <typename T>
|
2021-03-02 01:55:16 +08:00
|
|
|
std::enable_if_t<std::is_enum<T>::value, llvm::Optional<T>>
|
2020-07-28 21:52:32 +08:00
|
|
|
getLocalOrGlobal(StringRef LocalName, bool IgnoreCase = false) const {
|
2021-03-02 01:55:16 +08:00
|
|
|
if (llvm::Optional<int64_t> ValueOr =
|
2020-07-11 17:10:59 +08:00
|
|
|
getEnumInt(LocalName, typeEraseMapping<T>(), true, IgnoreCase))
|
2020-04-08 02:53:52 +08:00
|
|
|
return static_cast<T>(*ValueOr);
|
2021-03-02 01:55:16 +08:00
|
|
|
return None;
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Read a named option from the ``Context`` and parse it as an
|
2020-07-11 17:10:59 +08:00
|
|
|
/// enum type ``T``.
|
2020-04-08 02:53:52 +08:00
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from local or
|
|
|
|
/// global ``CheckOptions``. Gets local option first. If local is not
|
|
|
|
/// present, falls back to get global option. If global option is not
|
2021-03-02 01:55:16 +08:00
|
|
|
/// present either return \p Default.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a ``T``, emit a
|
|
|
|
/// diagnostic and return \p Default.
|
2020-07-11 17:10:59 +08:00
|
|
|
///
|
|
|
|
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
|
|
|
|
/// supply the mapping required to convert between ``T`` and a string.
|
2020-04-08 02:53:52 +08:00
|
|
|
template <typename T>
|
|
|
|
std::enable_if_t<std::is_enum<T>::value, T>
|
2020-07-28 21:52:32 +08:00
|
|
|
getLocalOrGlobal(StringRef LocalName, T Default,
|
|
|
|
bool IgnoreCase = false) const {
|
2021-03-02 01:55:16 +08:00
|
|
|
return getLocalOrGlobal<T>(LocalName, IgnoreCase).getValueOr(Default);
|
2020-08-01 08:45:33 +08:00
|
|
|
}
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Stores an option with the check-local name \p LocalName with
|
2019-03-25 20:36:30 +08:00
|
|
|
/// string value \p Value to \p Options.
|
|
|
|
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
|
|
|
|
StringRef Value) const;
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Stores an option with the check-local name \p LocalName with
|
2020-07-15 05:19:36 +08:00
|
|
|
/// integer value \p Value to \p Options.
|
|
|
|
template <typename T>
|
|
|
|
std::enable_if_t<std::is_integral<T>::value>
|
|
|
|
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
|
|
|
|
T Value) const {
|
|
|
|
storeInt(Options, LocalName, Value);
|
|
|
|
}
|
2019-03-25 20:36:30 +08:00
|
|
|
|
2020-04-08 02:53:52 +08:00
|
|
|
/// Stores an option with the check-local name \p LocalName as the string
|
2020-07-11 17:10:59 +08:00
|
|
|
/// representation of the Enum \p Value to \p Options.
|
|
|
|
///
|
|
|
|
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
|
|
|
|
/// supply the mapping required to convert between ``T`` and a string.
|
2020-04-08 02:53:52 +08:00
|
|
|
template <typename T>
|
|
|
|
std::enable_if_t<std::is_enum<T>::value>
|
2020-07-28 21:52:32 +08:00
|
|
|
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
|
|
|
|
T Value) const {
|
2020-07-11 17:10:59 +08:00
|
|
|
ArrayRef<std::pair<T, StringRef>> Mapping =
|
|
|
|
OptionEnumMapping<T>::getEnumMapping();
|
2020-04-08 02:53:52 +08:00
|
|
|
auto Iter = llvm::find_if(
|
2020-07-11 17:10:59 +08:00
|
|
|
Mapping, [&](const std::pair<T, StringRef> &NameAndEnum) {
|
|
|
|
return NameAndEnum.first == Value;
|
2020-04-08 02:53:52 +08:00
|
|
|
});
|
|
|
|
assert(Iter != Mapping.end() && "Unknown Case Value");
|
2020-07-11 17:10:59 +08:00
|
|
|
store(Options, LocalName, Iter->second);
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
|
2019-03-25 20:36:30 +08:00
|
|
|
private:
|
2020-07-11 17:10:59 +08:00
|
|
|
using NameAndValue = std::pair<int64_t, StringRef>;
|
2020-04-08 02:53:52 +08:00
|
|
|
|
2021-03-02 01:55:16 +08:00
|
|
|
llvm::Optional<int64_t> getEnumInt(StringRef LocalName,
|
2020-04-08 02:53:52 +08:00
|
|
|
ArrayRef<NameAndValue> Mapping,
|
2020-07-28 21:52:32 +08:00
|
|
|
bool CheckGlobal, bool IgnoreCase) const;
|
2020-04-08 02:53:52 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::enable_if_t<std::is_enum<T>::value, std::vector<NameAndValue>>
|
2020-07-28 21:52:32 +08:00
|
|
|
typeEraseMapping() const {
|
2020-07-11 17:10:59 +08:00
|
|
|
ArrayRef<std::pair<T, StringRef>> Mapping =
|
|
|
|
OptionEnumMapping<T>::getEnumMapping();
|
2020-04-08 02:53:52 +08:00
|
|
|
std::vector<NameAndValue> Result;
|
|
|
|
Result.reserve(Mapping.size());
|
|
|
|
for (auto &MappedItem : Mapping) {
|
2020-07-11 17:10:59 +08:00
|
|
|
Result.emplace_back(static_cast<int64_t>(MappedItem.first),
|
|
|
|
MappedItem.second);
|
2020-04-08 02:53:52 +08:00
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-07-15 05:19:36 +08:00
|
|
|
void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
|
|
|
|
int64_t Value) const;
|
|
|
|
|
2020-04-08 02:53:52 +08:00
|
|
|
|
2019-03-25 20:36:30 +08:00
|
|
|
std::string NamePrefix;
|
|
|
|
const ClangTidyOptions::OptionMap &CheckOptions;
|
2020-12-09 04:28:42 +08:00
|
|
|
ClangTidyContext *Context;
|
2019-03-25 20:36:30 +08:00
|
|
|
};
|
|
|
|
|
2019-06-14 03:05:02 +08:00
|
|
|
private:
|
|
|
|
void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
|
|
|
StringRef getID() const override { return CheckName; }
|
|
|
|
std::string CheckName;
|
|
|
|
ClangTidyContext *Context;
|
|
|
|
|
|
|
|
protected:
|
2019-03-25 20:36:30 +08:00
|
|
|
OptionsView Options;
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Returns the main file name of the current translation unit.
|
2019-03-25 20:36:30 +08:00
|
|
|
StringRef getCurrentMainFile() const { return Context->getCurrentFile(); }
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Returns the language options from the context.
|
2019-04-02 19:31:56 +08:00
|
|
|
const LangOptions &getLangOpts() const { return Context->getLangOpts(); }
|
2019-03-25 20:36:30 +08:00
|
|
|
};
|
|
|
|
|
2020-04-08 04:30:29 +08:00
|
|
|
/// Read a named option from the ``Context`` and parse it as a bool.
|
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from the
|
2021-03-02 01:55:16 +08:00
|
|
|
/// ``CheckOptions``. If the corresponding key is not present, return
|
|
|
|
/// ``None``.
|
|
|
|
///
|
|
|
|
/// If the corresponding key can't be parsed as a bool, emit a
|
|
|
|
/// diagnostic and return ``None``.
|
2020-04-08 04:30:29 +08:00
|
|
|
template <>
|
2021-03-02 01:55:16 +08:00
|
|
|
llvm::Optional<bool>
|
2020-04-08 04:30:29 +08:00
|
|
|
ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const;
|
|
|
|
|
|
|
|
/// Read a named option from the ``Context`` and parse it as a bool.
|
|
|
|
///
|
|
|
|
/// Reads the option with the check-local name \p LocalName from the
|
2021-03-02 01:55:16 +08:00
|
|
|
/// ``CheckOptions``. If the corresponding key is not present, return
|
|
|
|
/// \p Default.
|
2020-04-08 04:30:29 +08:00
|
|
|
///
|
2021-03-02 01:55:16 +08:00
|
|
|
/// If the corresponding key can't be parsed as a bool, emit a
|
|
|
|
/// diagnostic and return \p Default.
|
2020-04-08 04:30:29 +08:00
|
|
|
template <>
|
2021-03-02 01:55:16 +08:00
|
|
|
llvm::Optional<bool>
|
2020-04-08 04:30:29 +08:00
|
|
|
ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName) const;
|
|
|
|
|
2020-07-15 05:19:36 +08:00
|
|
|
/// Stores an option with the check-local name \p LocalName with
|
|
|
|
/// bool value \p Value to \p Options.
|
|
|
|
template <>
|
|
|
|
void ClangTidyCheck::OptionsView::store<bool>(
|
|
|
|
ClangTidyOptions::OptionMap &Options, StringRef LocalName,
|
|
|
|
bool Value) const;
|
|
|
|
|
2020-08-01 08:45:33 +08:00
|
|
|
|
2019-03-25 20:36:30 +08:00
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYCHECK_H
|