2015-08-19 19:15:36 +08:00
|
|
|
//===--- IdentifierNamingCheck.h - clang-tidy -------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2015-08-19 19:15:36 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IDENTIFIERNAMINGCHECK_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IDENTIFIERNAMINGCHECK_H
|
|
|
|
|
2020-01-17 05:29:19 +08:00
|
|
|
#include "../utils/RenamerClangTidyCheck.h"
|
2015-08-19 19:15:36 +08:00
|
|
|
namespace clang {
|
2016-06-17 17:25:24 +08:00
|
|
|
|
|
|
|
class MacroInfo;
|
|
|
|
|
2015-08-19 19:15:36 +08:00
|
|
|
namespace tidy {
|
|
|
|
namespace readability {
|
|
|
|
|
2015-08-28 02:01:58 +08:00
|
|
|
/// Checks for identifiers naming style mismatch.
|
|
|
|
///
|
|
|
|
/// This check will try to enforce coding guidelines on the identifiers naming.
|
|
|
|
/// It supports `lower_case`, `UPPER_CASE`, `camelBack` and `CamelCase` casing
|
|
|
|
/// and tries to convert from one to another if a mismatch is detected.
|
|
|
|
///
|
|
|
|
/// It also supports a fixed prefix and suffix that will be prepended or
|
|
|
|
/// appended to the identifiers, regardless of the casing.
|
|
|
|
///
|
|
|
|
/// Many configuration options are available, in order to be able to create
|
|
|
|
/// different rules for different kind of identifier. In general, the
|
|
|
|
/// rules are falling back to a more generic rule if the specific case is not
|
|
|
|
/// configured.
|
2020-01-17 05:29:19 +08:00
|
|
|
class IdentifierNamingCheck final : public RenamerClangTidyCheck {
|
2015-08-19 19:15:36 +08:00
|
|
|
public:
|
|
|
|
IdentifierNamingCheck(StringRef Name, ClangTidyContext *Context);
|
2019-09-26 21:47:29 +08:00
|
|
|
~IdentifierNamingCheck();
|
2015-08-19 19:15:36 +08:00
|
|
|
|
|
|
|
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
|
|
|
|
|
|
|
|
enum CaseType {
|
|
|
|
CT_AnyCase = 0,
|
|
|
|
CT_LowerCase,
|
|
|
|
CT_CamelBack,
|
|
|
|
CT_UpperCase,
|
|
|
|
CT_CamelCase,
|
2016-07-20 20:28:38 +08:00
|
|
|
CT_CamelSnakeCase,
|
|
|
|
CT_CamelSnakeBack
|
2015-08-19 19:15:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NamingStyle {
|
2017-03-22 20:49:58 +08:00
|
|
|
NamingStyle() = default;
|
2015-08-19 19:15:36 +08:00
|
|
|
|
2017-03-22 20:50:05 +08:00
|
|
|
NamingStyle(llvm::Optional<CaseType> Case, const std::string &Prefix,
|
2015-08-19 19:15:36 +08:00
|
|
|
const std::string &Suffix)
|
|
|
|
: Case(Case), Prefix(Prefix), Suffix(Suffix) {}
|
|
|
|
|
2017-03-22 20:49:58 +08:00
|
|
|
llvm::Optional<CaseType> Case;
|
2015-08-19 19:15:36 +08:00
|
|
|
std::string Prefix;
|
|
|
|
std::string Suffix;
|
|
|
|
};
|
|
|
|
|
2015-09-28 16:59:12 +08:00
|
|
|
private:
|
2020-01-17 05:29:19 +08:00
|
|
|
llvm::Optional<FailureInfo>
|
|
|
|
GetDeclFailureInfo(const NamedDecl *Decl,
|
|
|
|
const SourceManager &SM) const override;
|
|
|
|
llvm::Optional<FailureInfo>
|
|
|
|
GetMacroFailureInfo(const Token &MacroNameTok,
|
|
|
|
const SourceManager &SM) const override;
|
|
|
|
DiagInfo GetDiagInfo(const NamingCheckId &ID,
|
|
|
|
const NamingCheckFailure &Failure) const override;
|
|
|
|
|
2017-03-22 20:50:05 +08:00
|
|
|
std::vector<llvm::Optional<NamingStyle>> NamingStyles;
|
[clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions
Summary:
Typically most main functions have the signature:
```
int main(int argc, char *argv[])
```
To stick with convention when renaming parameters we should ignore the `argc` and `argv` names even if the parameter style says they should be renamed. This patch addresses this by checking all ParmVarDecls if they form part of a function with a signature that matches main `int name(int argc, char * argv[], (optional char *env[]))`
Reviewers: aaron.ballman, JonasToth, alexfh, hokein
Reviewed By: aaron.ballman
Subscribers: Mordante, merge_guards_bot, xazax.hun, kristof.beyls, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D73098
2020-01-28 07:46:53 +08:00
|
|
|
const bool IgnoreFailedSplit;
|
|
|
|
const bool IgnoreMainLikeFunctions;
|
2015-08-19 19:15:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace readability
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IDENTIFIERNAMINGCHECK_H
|