clang-tools 22.0.0git
AvoidDoWhileCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "AvoidDoWhileCheck.h"
10#include "clang/ASTMatchers/ASTMatchFinder.h"
11
12using namespace clang::ast_matchers;
13
15
17 : ClangTidyCheck(Name, Context),
18 IgnoreMacros(Options.get("IgnoreMacros", false)) {}
19
21 Options.store(Opts, "IgnoreMacros", IgnoreMacros);
22}
23
24void AvoidDoWhileCheck::registerMatchers(MatchFinder *Finder) {
25 Finder->addMatcher(doStmt().bind("x"), this);
26}
27
28void AvoidDoWhileCheck::check(const MatchFinder::MatchResult &Result) {
29 if (const auto *MatchedDecl = Result.Nodes.getNodeAs<DoStmt>("x")) {
30 if (IgnoreMacros && MatchedDecl->getBeginLoc().isMacroID())
31 return;
32 diag(MatchedDecl->getBeginLoc(), "avoid do-while loops");
33 }
34}
35
36} // namespace clang::tidy::cppcoreguidelines
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
AvoidDoWhileCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
llvm::StringMap< ClangTidyValue > OptionMap