2014-10-03 03:09:56 +08:00
|
|
|
//===--- BracesAroundStatementsCheck.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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-10-15 18:51:57 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_BRACESAROUNDSTATEMENTSCHECK_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_BRACESAROUNDSTATEMENTSCHECK_H
|
2014-10-03 03:09:56 +08:00
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
2014-10-15 18:51:57 +08:00
|
|
|
namespace readability {
|
2014-10-03 03:09:56 +08:00
|
|
|
|
2014-10-13 20:46:22 +08:00
|
|
|
/// \brief Checks that bodies of 'if' statements and loops ('for', 'range-for',
|
|
|
|
/// 'do-while', and 'while') are inside braces
|
|
|
|
///
|
|
|
|
/// Before:
|
|
|
|
/// if (condition)
|
|
|
|
/// statement;
|
|
|
|
///
|
|
|
|
/// After:
|
|
|
|
/// if (condition) {
|
|
|
|
/// statement;
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// Additionally, one can define an option `ShortStatementLines` defining the
|
|
|
|
/// minimal number of lines that the statement should have in order to trigger
|
|
|
|
/// this check.
|
|
|
|
/// The number of lines is counted from the end of condition or initial keyword
|
|
|
|
/// (do/else) until the last line of the inner statement.
|
|
|
|
/// Default value 0 means that braces will be added to all statements (not
|
|
|
|
/// having them already).
|
2014-10-03 03:09:56 +08:00
|
|
|
class BracesAroundStatementsCheck : public ClangTidyCheck {
|
|
|
|
public:
|
2014-10-13 20:46:22 +08:00
|
|
|
BracesAroundStatementsCheck(StringRef Name, ClangTidyContext *Context);
|
|
|
|
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
|
2014-10-03 03:09:56 +08:00
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
|
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
2015-06-05 00:36:58 +08:00
|
|
|
void onEndOfTranslationUnit() override;
|
2014-10-03 03:09:56 +08:00
|
|
|
|
|
|
|
private:
|
2015-03-31 21:53:03 +08:00
|
|
|
bool checkStmt(const ast_matchers::MatchFinder::MatchResult &Result,
|
2014-10-03 03:09:56 +08:00
|
|
|
const Stmt *S, SourceLocation StartLoc,
|
2015-06-05 00:36:58 +08:00
|
|
|
SourceLocation EndLocHint = SourceLocation());
|
2014-10-03 03:09:56 +08:00
|
|
|
template <typename IfOrWhileStmt>
|
|
|
|
SourceLocation findRParenLoc(const IfOrWhileStmt *S, const SourceManager &SM,
|
|
|
|
const ASTContext *Context);
|
2014-10-13 20:46:22 +08:00
|
|
|
|
|
|
|
private:
|
2015-06-05 00:36:58 +08:00
|
|
|
std::set<const Stmt*> ForceBracesStmts;
|
2014-10-13 20:46:22 +08:00
|
|
|
const unsigned ShortStatementLines;
|
2014-10-03 03:09:56 +08:00
|
|
|
};
|
|
|
|
|
2014-10-15 18:51:57 +08:00
|
|
|
} // namespace readability
|
2014-10-03 03:09:56 +08:00
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
2014-10-15 18:51:57 +08:00
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_BRACESAROUNDSTATEMENTSCHECK_H
|