| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_IDDEPENDENTBACKWARDBRANCHCHECK_H |
| 10 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_IDDEPENDENTBACKWARDBRANCHCHECK_H |
| 11 |
|
| 12 |
#include "../ClangTidyCheck.h" |
| 13 |
|
| 14 |
namespace clang::tidy::altera { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
class IdDependentBackwardBranchCheck : public ClangTidyCheck { |
| 23 |
private: |
| 24 |
enum LoopType { UnknownLoop = -1, DoLoop = 0, WhileLoop = 1, ForLoop = 2 }; |
| 25 |
|
| 26 |
struct IdDependencyRecord { |
| 27 |
IdDependencyRecord(const VarDecl *Declaration, SourceLocation Location, |
| 28 |
const llvm::Twine &Message) |
| 29 |
: VariableDeclaration(Declaration), Location(Location), |
| 30 |
Message(Message.str()) {} |
| 31 |
IdDependencyRecord(const FieldDecl *Declaration, SourceLocation Location, |
| 32 |
const llvm::Twine &Message) |
| 33 |
: FieldDeclaration(Declaration), Location(Location), |
| 34 |
Message(Message.str()) {} |
| 35 |
IdDependencyRecord() = default; |
| 36 |
const VarDecl *VariableDeclaration = nullptr; |
| 37 |
const FieldDecl *FieldDeclaration = nullptr; |
| 38 |
SourceLocation Location; |
| 39 |
std::string Message; |
| 40 |
}; |
| 41 |
|
| 42 |
std::map<const VarDecl *, IdDependencyRecord> IdDepVarsMap; |
| 43 |
|
| 44 |
std::map<const FieldDecl *, IdDependencyRecord> IdDepFieldsMap; |
| 45 |
|
| 46 |
|
| 47 |
IdDependencyRecord *hasIdDepVar(const Expr *Expression); |
| 48 |
|
| 49 |
|
| 50 |
IdDependencyRecord *hasIdDepField(const Expr *Expression); |
| 51 |
|
| 52 |
|
| 53 |
void saveIdDepVar(const Stmt *Statement, const VarDecl *Variable); |
| 54 |
|
| 55 |
|
| 56 |
void saveIdDepField(const Stmt *Statement, const FieldDecl *Field); |
| 57 |
|
| 58 |
|
| 59 |
void saveIdDepVarFromReference(const DeclRefExpr *RefExpr, |
| 60 |
const MemberExpr *MemExpr, |
| 61 |
const VarDecl *PotentialVar); |
| 62 |
|
| 63 |
|
| 64 |
void saveIdDepFieldFromReference(const DeclRefExpr *RefExpr, |
| 65 |
const MemberExpr *MemExpr, |
| 66 |
const FieldDecl *PotentialField); |
| 67 |
|
| 68 |
LoopType getLoopType(const Stmt *Loop); |
| 69 |
|
| 70 |
public: |
| 71 |
IdDependentBackwardBranchCheck(StringRef Name, ClangTidyContext *Context) |
| 72 |
: ClangTidyCheck(Name, Context) {} |
| 73 |
void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 74 |
void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 75 |
}; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
#endif |