clang  15.0.0git
ControlFlowContext.h
Go to the documentation of this file.
1 //===-- ControlFlowContext.h ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a ControlFlowContext class that is used by dataflow
10 // analyses that run over Control-Flow Graphs (CFGs).
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H
15 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H
16 
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/Stmt.h"
20 #include "clang/Analysis/CFG.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/Support/Error.h"
23 #include <memory>
24 #include <utility>
25 
26 namespace clang {
27 namespace dataflow {
28 
29 /// Holds CFG and other derived context that is needed to perform dataflow
30 /// analysis.
32 public:
33  /// Builds a ControlFlowContext from an AST node.
35  ASTContext *C);
36 
37  /// Returns the CFG that is stored in this context.
38  const CFG &getCFG() const { return *Cfg; }
39 
40  /// Returns a mapping from statements to basic blocks that contain them.
41  const llvm::DenseMap<const Stmt *, const CFGBlock *> &getStmtToBlock() const {
42  return StmtToBlock;
43  }
44 
45 private:
46  ControlFlowContext(std::unique_ptr<CFG> Cfg,
47  llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock)
48  : Cfg(std::move(Cfg)), StmtToBlock(std::move(StmtToBlock)) {}
49 
50  std::unique_ptr<CFG> Cfg;
51  llvm::DenseMap<const Stmt *, const CFGBlock *> StmtToBlock;
52 };
53 
54 } // namespace dataflow
55 } // namespace clang
56 
57 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H
clang::dataflow::ControlFlowContext::getStmtToBlock
const llvm::DenseMap< const Stmt *, const CFGBlock * > & getStmtToBlock() const
Returns a mapping from statements to basic blocks that contain them.
Definition: ControlFlowContext.h:41
llvm::Expected
Definition: LLVM.h:41
clang::CFG
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition: CFG.h:1225
Decl.h
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:208
ASTContext.h
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::dataflow::ControlFlowContext
Holds CFG and other derived context that is needed to perform dataflow analysis.
Definition: ControlFlowContext.h:31
clang::dataflow::ControlFlowContext::build
static llvm::Expected< ControlFlowContext > build(const Decl *D, Stmt *S, ASTContext *C)
Builds a ControlFlowContext from an AST node.
Definition: ControlFlowContext.cpp:48
std
Definition: Format.h:4296
clang
Definition: CalledOnceCheck.h:17
CFG.h
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
Stmt.h
clang::dataflow::ControlFlowContext::getCFG
const CFG & getCFG() const
Returns the CFG that is stored in this context.
Definition: ControlFlowContext.h:38