blob: e92552ed95b8e2b2694fd51e35f6d9d2a63c7334 [file] [log] [blame]
Aaron Ballman611d2e42016-02-19 14:03:20 +00001//===--- FloatLoopCounter.cpp - clang-tidy---------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "FloatLoopCounter.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13
14using namespace clang::ast_matchers;
15
16namespace clang {
17namespace tidy {
18namespace cert {
19
20void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
21 Finder->addMatcher(
22 forStmt(hasIncrement(expr(hasType(realFloatingPointType())))).bind("for"),
23 this);
24}
25
26void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
27 const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
28
29 diag(FS->getInc()->getExprLoc(), "loop induction expression should not have "
30 "floating-point type");
31}
32
33} // namespace cert
34} // namespace tidy
35} // namespace clang