2014-04-29 23:20:10 +08:00
|
|
|
//===--- ClangTidyOptions.h - clang-tidy ------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANG_TIDY_OPTIONS_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANG_TIDY_OPTIONS_H
|
|
|
|
|
2014-06-05 21:31:45 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2014-05-05 22:54:47 +08:00
|
|
|
#include <string>
|
2014-06-13 00:53:02 +08:00
|
|
|
#include <system_error>
|
2014-05-23 00:07:11 +08:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-05-05 22:54:47 +08:00
|
|
|
|
2014-04-29 23:20:10 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
|
2014-06-05 21:31:45 +08:00
|
|
|
/// \brief Contains a list of line ranges in a single file.
|
2014-05-23 00:07:11 +08:00
|
|
|
struct FileFilter {
|
2014-06-05 21:31:45 +08:00
|
|
|
/// \brief File name.
|
2014-05-23 00:07:11 +08:00
|
|
|
std::string Name;
|
2014-06-05 21:31:45 +08:00
|
|
|
|
|
|
|
/// \brief LineRange is a pair<start, end> (inclusive).
|
2014-05-23 00:07:11 +08:00
|
|
|
typedef std::pair<unsigned, unsigned> LineRange;
|
2014-06-05 21:31:45 +08:00
|
|
|
|
|
|
|
/// \brief A list of line ranges in this file, for which we show warnings.
|
2014-05-23 00:07:11 +08:00
|
|
|
std::vector<LineRange> LineRanges;
|
|
|
|
};
|
|
|
|
|
2014-06-05 21:31:45 +08:00
|
|
|
/// \brief Global options. These options are neither stored nor read from
|
|
|
|
/// configuration files.
|
|
|
|
struct ClangTidyGlobalOptions {
|
2014-06-12 19:25:45 +08:00
|
|
|
/// \brief Output warnings from certain line ranges of certain files only.
|
|
|
|
/// If empty, no warnings will be filtered.
|
2014-06-05 21:31:45 +08:00
|
|
|
std::vector<FileFilter> LineFilter;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Contains options for clang-tidy. These options may be read from
|
|
|
|
/// configuration files, and may be different for different translation units.
|
2014-04-29 23:20:10 +08:00
|
|
|
struct ClangTidyOptions {
|
2014-06-05 21:31:45 +08:00
|
|
|
/// \brief Allow all checks and no headers by default.
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
ClangTidyOptions() : Checks("*"), AnalyzeTemporaryDtors(false) {}
|
2014-06-05 21:31:45 +08:00
|
|
|
|
|
|
|
/// \brief Checks filter.
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
std::string Checks;
|
2014-05-23 00:07:11 +08:00
|
|
|
|
2014-06-05 21:31:45 +08:00
|
|
|
/// \brief Output warnings from headers matching this filter. Warnings from
|
|
|
|
/// main files will always be displayed.
|
2014-05-05 22:54:47 +08:00
|
|
|
std::string HeaderFilterRegex;
|
2014-05-23 00:07:11 +08:00
|
|
|
|
2014-06-05 21:31:45 +08:00
|
|
|
/// \brief Turns on temporary destructor-based analysis.
|
2014-04-30 22:09:24 +08:00
|
|
|
bool AnalyzeTemporaryDtors;
|
2014-04-29 23:20:10 +08:00
|
|
|
};
|
|
|
|
|
2014-06-05 21:31:45 +08:00
|
|
|
/// \brief Abstract interface for retrieving various ClangTidy options.
|
|
|
|
class ClangTidyOptionsProvider {
|
|
|
|
public:
|
|
|
|
virtual ~ClangTidyOptionsProvider() {}
|
|
|
|
|
|
|
|
/// \brief Returns global options, which are independent of the file.
|
|
|
|
virtual const ClangTidyGlobalOptions &getGlobalOptions() = 0;
|
|
|
|
|
|
|
|
/// \brief Returns options applying to a specific translation unit with the
|
|
|
|
/// specified \p FileName.
|
|
|
|
virtual const ClangTidyOptions &getOptions(llvm::StringRef FileName) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Implementation of the \c ClangTidyOptionsProvider interface, which
|
|
|
|
/// returns the same options for all files.
|
|
|
|
class DefaultOptionsProvider : public ClangTidyOptionsProvider {
|
|
|
|
public:
|
|
|
|
DefaultOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions,
|
|
|
|
const ClangTidyOptions &Options)
|
|
|
|
: GlobalOptions(GlobalOptions), DefaultOptions(Options) {}
|
|
|
|
const ClangTidyGlobalOptions &getGlobalOptions() override {
|
|
|
|
return GlobalOptions;
|
|
|
|
}
|
|
|
|
const ClangTidyOptions &getOptions(llvm::StringRef) override {
|
|
|
|
return DefaultOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ClangTidyGlobalOptions GlobalOptions;
|
|
|
|
ClangTidyOptions DefaultOptions;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Parses LineFilter from JSON and stores it to the \p Options.
|
2014-06-12 21:32:11 +08:00
|
|
|
std::error_code parseLineFilter(const std::string &LineFilter,
|
|
|
|
clang::tidy::ClangTidyGlobalOptions &Options);
|
2014-06-05 21:31:45 +08:00
|
|
|
|
|
|
|
/// \brief Parses configuration from JSON and stores it to the \p Options.
|
2014-06-12 21:32:11 +08:00
|
|
|
std::error_code parseConfiguration(const std::string &Config,
|
|
|
|
clang::tidy::ClangTidyOptions &Options);
|
2014-05-23 00:07:11 +08:00
|
|
|
|
2014-04-29 23:20:10 +08:00
|
|
|
} // end namespace tidy
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANG_TIDY_OPTIONS_H
|