SubEngine.h revision 1aae01a8308d2f8e31adab3f4d7ac35543aac680
1//== SubEngine.h - Interface of the subengine of CoreEngine --------*- C++ -*-//
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//
10// This file defines the interface of a subengine of the CoreEngine.
11//
12//===----------------------------------------------------------------------===//
13#ifndef LLVM_CLANG_GR_SUBENGINE_H
14#define LLVM_CLANG_GR_SUBENGINE_H
15
16#include "clang/Analysis/ProgramPoint.h"
17#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
18#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
19
20namespace clang {
21
22class CFGBlock;
23class CFGElement;
24class LocationContext;
25class Stmt;
26
27namespace ento {
28
29template <typename PP> class GenericNodeBuilder;
30struct NodeBuilderContext;
31class AnalysisManager;
32class ExplodedNodeSet;
33class ExplodedNode;
34class ProgramState;
35class ProgramStateManager;
36class BlockCounter;
37class StmtNodeBuilder;
38class BranchNodeBuilder;
39class IndirectGotoNodeBuilder;
40class SwitchNodeBuilder;
41class EndOfFunctionNodeBuilder;
42class CallEnterNodeBuilder;
43class CallExitNodeBuilder;
44class MemRegion;
45
46class SubEngine {
47public:
48  virtual ~SubEngine() {}
49
50  virtual const ProgramState *getInitialState(const LocationContext *InitLoc) = 0;
51
52  virtual AnalysisManager &getAnalysisManager() = 0;
53
54  virtual ProgramStateManager &getStateManager() = 0;
55
56  /// Called by CoreEngine. Used to generate new successor
57  /// nodes by processing the 'effects' of a block-level statement.
58  virtual void processCFGElement(const CFGElement E, StmtNodeBuilder& builder,
59                                 ExplodedNode* Pred)=0;
60
61  /// Called by CoreEngine when it starts processing a CFGBlock.  The
62  /// SubEngine is expected to populate dstNodes with new nodes representing
63  /// updated analysis state, or generate no nodes at all if it doesn't.
64  virtual void processCFGBlockEntrance(ExplodedNodeSet &dstNodes,
65                            GenericNodeBuilder<BlockEntrance> &nodeBuilder) = 0;
66
67  /// Called by CoreEngine.  Used to generate successor
68  ///  nodes by processing the 'effects' of a branch condition.
69  virtual void processBranch(const Stmt *Condition, const Stmt *Term,
70                             NodeBuilderContext& BuilderCtx,
71                             ExplodedNode *Pred,
72                             ExplodedNodeSet &Dst,
73                             const CFGBlock *DstT,
74                             const CFGBlock *DstF) = 0;
75
76  /// Called by CoreEngine.  Used to generate successor
77  /// nodes by processing the 'effects' of a computed goto jump.
78  virtual void processIndirectGoto(IndirectGotoNodeBuilder& builder) = 0;
79
80  /// Called by CoreEngine.  Used to generate successor
81  /// nodes by processing the 'effects' of a switch statement.
82  virtual void processSwitch(SwitchNodeBuilder& builder) = 0;
83
84  /// Called by CoreEngine.  Used to generate end-of-path
85  /// nodes when the control reaches the end of a function.
86  virtual void processEndOfFunction(EndOfFunctionNodeBuilder& builder) = 0;
87
88  // Generate the entry node of the callee.
89  virtual void processCallEnter(CallEnterNodeBuilder &builder) = 0;
90
91  // Generate the first post callsite node.
92  virtual void processCallExit(CallExitNodeBuilder &builder) = 0;
93
94  /// Called by ConstraintManager. Used to call checker-specific
95  /// logic for handling assumptions on symbolic values.
96  virtual const ProgramState *processAssume(const ProgramState *state,
97                                       SVal cond, bool assumption) = 0;
98
99  /// wantsRegionChangeUpdate - Called by ProgramStateManager to determine if a
100  ///  region change should trigger a processRegionChanges update.
101  virtual bool wantsRegionChangeUpdate(const ProgramState *state) = 0;
102
103  /// processRegionChanges - Called by ProgramStateManager whenever a change is made
104  ///  to the store. Used to update checkers that track region values.
105  virtual const ProgramState *
106  processRegionChanges(const ProgramState *state,
107                       const StoreManager::InvalidatedSymbols *invalidated,
108                       ArrayRef<const MemRegion *> ExplicitRegions,
109                       ArrayRef<const MemRegion *> Regions) = 0;
110
111
112  inline const ProgramState *
113  processRegionChange(const ProgramState *state,
114                      const MemRegion* MR) {
115    return processRegionChanges(state, 0, MR, MR);
116  }
117
118  /// printState - Called by ProgramStateManager to print checker-specific data.
119  virtual void printState(raw_ostream &Out, const ProgramState *State,
120                          const char *NL, const char *Sep) = 0;
121
122  /// Called by CoreEngine when the analysis worklist is either empty or the
123  //  maximum number of analysis steps have been reached.
124  virtual void processEndWorklist(bool hasWorkRemaining) = 0;
125};
126
127} // end GR namespace
128
129} // end clang namespace
130
131#endif
132