File indexing completed on 2026-05-10 08:36:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_IDDEPENDENTBACKWARDBRANCHCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_IDDEPENDENTBACKWARDBRANCHCHECK_H
0011
0012 #include "../ClangTidyCheck.h"
0013
0014 namespace clang::tidy::altera {
0015
0016
0017
0018
0019
0020
0021
0022 class IdDependentBackwardBranchCheck : public ClangTidyCheck {
0023 private:
0024 enum LoopType { UnknownLoop = -1, DoLoop = 0, WhileLoop = 1, ForLoop = 2 };
0025
0026 struct IdDependencyRecord {
0027 IdDependencyRecord(const VarDecl *Declaration, SourceLocation Location,
0028 const llvm::Twine &Message)
0029 : VariableDeclaration(Declaration), Location(Location),
0030 Message(Message.str()) {}
0031 IdDependencyRecord(const FieldDecl *Declaration, SourceLocation Location,
0032 const llvm::Twine &Message)
0033 : FieldDeclaration(Declaration), Location(Location),
0034 Message(Message.str()) {}
0035 IdDependencyRecord() = default;
0036 const VarDecl *VariableDeclaration = nullptr;
0037 const FieldDecl *FieldDeclaration = nullptr;
0038 SourceLocation Location;
0039 std::string Message;
0040 };
0041
0042 std::map<const VarDecl *, IdDependencyRecord> IdDepVarsMap;
0043
0044 std::map<const FieldDecl *, IdDependencyRecord> IdDepFieldsMap;
0045
0046
0047 IdDependencyRecord *hasIdDepVar(const Expr *Expression);
0048
0049
0050 IdDependencyRecord *hasIdDepField(const Expr *Expression);
0051
0052
0053 void saveIdDepVar(const Stmt *Statement, const VarDecl *Variable);
0054
0055
0056 void saveIdDepField(const Stmt *Statement, const FieldDecl *Field);
0057
0058
0059 void saveIdDepVarFromReference(const DeclRefExpr *RefExpr,
0060 const MemberExpr *MemExpr,
0061 const VarDecl *PotentialVar);
0062
0063
0064 void saveIdDepFieldFromReference(const DeclRefExpr *RefExpr,
0065 const MemberExpr *MemExpr,
0066 const FieldDecl *PotentialField);
0067
0068 LoopType getLoopType(const Stmt *Loop);
0069
0070 public:
0071 IdDependentBackwardBranchCheck(StringRef Name, ClangTidyContext *Context)
0072 : ClangTidyCheck(Name, Context) {}
0073 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0074 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0075 };
0076
0077 }
0078
0079 #endif