9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_IDDEPENDENTBACKWARDBRANCHCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_IDDEPENDENTBACKWARDBRANCHCHECK_H
12#include "../ClangTidyCheck.h"
24 enum LoopType { UnknownLoop = -1, DoLoop = 0, WhileLoop = 1, ForLoop = 2 };
26 struct IdDependencyRecord {
27 IdDependencyRecord(
const VarDecl *Declaration, SourceLocation
Location,
28 const llvm::Twine &Message)
30 Message(Message.str()) {}
31 IdDependencyRecord(
const FieldDecl *Declaration, SourceLocation
Location,
32 const llvm::Twine &Message)
34 Message(Message.str()) {}
35 IdDependencyRecord() =
default;
36 const VarDecl *VariableDeclaration =
nullptr;
37 const FieldDecl *FieldDeclaration =
nullptr;
42 std::map<const VarDecl *, IdDependencyRecord> IdDepVarsMap;
44 std::map<const FieldDecl *, IdDependencyRecord> IdDepFieldsMap;
47 IdDependencyRecord *hasIdDepVar(
const Expr *Expression);
50 IdDependencyRecord *hasIdDepField(
const Expr *Expression);
53 void saveIdDepVar(
const Stmt *Statement,
const VarDecl *Variable);
56 void saveIdDepField(
const Stmt *Statement,
const FieldDecl *
Field);
59 void saveIdDepVarFromReference(
const DeclRefExpr *RefExpr,
60 const MemberExpr *MemExpr,
61 const VarDecl *PotentialVar);
64 void saveIdDepFieldFromReference(
const DeclRefExpr *RefExpr,
65 const MemberExpr *MemExpr,
66 const FieldDecl *PotentialField);
68 LoopType getLoopType(
const Stmt *Loop);
74 void check(
const ast_matchers::MatchFinder::MatchResult &Result)
override;
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Finds ID-dependent variables and fields used within loops, and warns of their usage.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
IdDependentBackwardBranchCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.