clang-tools  7.0.0
ExprMutationAnalyzer.h
Go to the documentation of this file.
1 //===---------- ExprMutationAnalyzer.h - 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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPRMUTATIONANALYZER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPRMUTATIONANALYZER_H
11 
12 #include <type_traits>
13 
14 #include "clang/AST/AST.h"
15 #include "clang/ASTMatchers/ASTMatchers.h"
16 #include "llvm/ADT/DenseMap.h"
17 
18 namespace clang {
19 namespace tidy {
20 namespace utils {
21 
22 /// Analyzes whether any mutative operations are applied to an expression within
23 /// a given statement.
25 public:
26  ExprMutationAnalyzer(const Stmt *Stm, ASTContext *Context)
27  : Stm(Stm), Context(Context) {}
28 
29  bool isMutated(const Decl *Dec) { return findDeclMutation(Dec) != nullptr; }
30  bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; }
31  const Stmt *findMutation(const Expr *Exp);
32 
33 private:
34  bool isUnevaluated(const Expr *Exp);
35 
36  const Stmt *findExprMutation(ArrayRef<ast_matchers::BoundNodes> Matches);
37  const Stmt *findDeclMutation(ArrayRef<ast_matchers::BoundNodes> Matches);
38  const Stmt *findDeclMutation(const Decl *Dec);
39 
40  const Stmt *findDirectMutation(const Expr *Exp);
41  const Stmt *findMemberMutation(const Expr *Exp);
42  const Stmt *findArrayElementMutation(const Expr *Exp);
43  const Stmt *findCastMutation(const Expr *Exp);
44  const Stmt *findRangeLoopMutation(const Expr *Exp);
45  const Stmt *findReferenceMutation(const Expr *Exp);
46 
47  const Stmt *const Stm;
48  ASTContext *const Context;
49  llvm::DenseMap<const Expr *, const Stmt *> Results;
50 };
51 
52 } // namespace utils
53 } // namespace tidy
54 } // namespace clang
55 
56 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPRMUTATIONANALYZER_H
ExprMutationAnalyzer(const Stmt *Stm, ASTContext *Context)
const Stmt * findMutation(const Expr *Exp)
Analyzes whether any mutative operations are applied to an expression within a given statement...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//