1218887Sdim//== SubEngine.h - Interface of the subengine of CoreEngine --------*- C++ -*-//
2218887Sdim//
3218887Sdim//                     The LLVM Compiler Infrastructure
4218887Sdim//
5218887Sdim// This file is distributed under the University of Illinois Open Source
6218887Sdim// License. See LICENSE.TXT for details.
7218887Sdim//
8218887Sdim//===----------------------------------------------------------------------===//
9218887Sdim//
10218887Sdim// This file defines the interface of a subengine of the CoreEngine.
11218887Sdim//
12218887Sdim//===----------------------------------------------------------------------===//
13218887Sdim#ifndef LLVM_CLANG_GR_SUBENGINE_H
14218887Sdim#define LLVM_CLANG_GR_SUBENGINE_H
15218887Sdim
16218887Sdim#include "clang/Analysis/ProgramPoint.h"
17218887Sdim#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
18223017Sdim#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
19218887Sdim
20218887Sdimnamespace clang {
21218887Sdim
22218887Sdimclass CFGBlock;
23218887Sdimclass CFGElement;
24218887Sdimclass LocationContext;
25218887Sdimclass Stmt;
26218887Sdim
27218887Sdimnamespace ento {
28218887Sdim
29234353Sdimstruct NodeBuilderContext;
30218887Sdimclass AnalysisManager;
31218887Sdimclass ExplodedNodeSet;
32218887Sdimclass ExplodedNode;
33226633Sdimclass ProgramState;
34226633Sdimclass ProgramStateManager;
35218887Sdimclass BlockCounter;
36218887Sdimclass BranchNodeBuilder;
37218887Sdimclass IndirectGotoNodeBuilder;
38218887Sdimclass SwitchNodeBuilder;
39218887Sdimclass EndOfFunctionNodeBuilder;
40234353Sdimclass NodeBuilderWithSinks;
41218887Sdimclass MemRegion;
42218887Sdim
43218887Sdimclass SubEngine {
44234353Sdim  virtual void anchor();
45218887Sdimpublic:
46218887Sdim  virtual ~SubEngine() {}
47218887Sdim
48234353Sdim  virtual ProgramStateRef getInitialState(const LocationContext *InitLoc) = 0;
49218887Sdim
50218887Sdim  virtual AnalysisManager &getAnalysisManager() = 0;
51218887Sdim
52226633Sdim  virtual ProgramStateManager &getStateManager() = 0;
53218887Sdim
54218887Sdim  /// Called by CoreEngine. Used to generate new successor
55218887Sdim  /// nodes by processing the 'effects' of a block-level statement.
56234353Sdim  virtual void processCFGElement(const CFGElement E, ExplodedNode* Pred,
57234353Sdim                                 unsigned StmtIdx, NodeBuilderContext *Ctx)=0;
58218887Sdim
59218887Sdim  /// Called by CoreEngine when it starts processing a CFGBlock.  The
60218887Sdim  /// SubEngine is expected to populate dstNodes with new nodes representing
61218887Sdim  /// updated analysis state, or generate no nodes at all if it doesn't.
62234353Sdim  virtual void processCFGBlockEntrance(const BlockEdge &L,
63243830Sdim                                       NodeBuilderWithSinks &nodeBuilder,
64243830Sdim                                       ExplodedNode *Pred) = 0;
65218887Sdim
66218887Sdim  /// Called by CoreEngine.  Used to generate successor
67218887Sdim  ///  nodes by processing the 'effects' of a branch condition.
68226633Sdim  virtual void processBranch(const Stmt *Condition, const Stmt *Term,
69234353Sdim                             NodeBuilderContext& BuilderCtx,
70234353Sdim                             ExplodedNode *Pred,
71234353Sdim                             ExplodedNodeSet &Dst,
72234353Sdim                             const CFGBlock *DstT,
73234353Sdim                             const CFGBlock *DstF) = 0;
74218887Sdim
75249423Sdim  /// Called by CoreEngine.  Used to processing branching behavior
76249423Sdim  /// at static initalizers.
77249423Sdim  virtual void processStaticInitializer(const DeclStmt *DS,
78249423Sdim                                        NodeBuilderContext& BuilderCtx,
79249423Sdim                                        ExplodedNode *Pred,
80249423Sdim                                        ExplodedNodeSet &Dst,
81249423Sdim                                        const CFGBlock *DstT,
82249423Sdim                                        const CFGBlock *DstF) = 0;
83249423Sdim
84218887Sdim  /// Called by CoreEngine.  Used to generate successor
85218887Sdim  /// nodes by processing the 'effects' of a computed goto jump.
86218887Sdim  virtual void processIndirectGoto(IndirectGotoNodeBuilder& builder) = 0;
87218887Sdim
88218887Sdim  /// Called by CoreEngine.  Used to generate successor
89218887Sdim  /// nodes by processing the 'effects' of a switch statement.
90218887Sdim  virtual void processSwitch(SwitchNodeBuilder& builder) = 0;
91218887Sdim
92218887Sdim  /// Called by CoreEngine.  Used to generate end-of-path
93218887Sdim  /// nodes when the control reaches the end of a function.
94243830Sdim  virtual void processEndOfFunction(NodeBuilderContext& BC,
95243830Sdim                                    ExplodedNode *Pred) = 0;
96218887Sdim
97218887Sdim  // Generate the entry node of the callee.
98234353Sdim  virtual void processCallEnter(CallEnter CE, ExplodedNode *Pred) = 0;
99218887Sdim
100218887Sdim  // Generate the first post callsite node.
101234353Sdim  virtual void processCallExit(ExplodedNode *Pred) = 0;
102218887Sdim
103218887Sdim  /// Called by ConstraintManager. Used to call checker-specific
104218887Sdim  /// logic for handling assumptions on symbolic values.
105234353Sdim  virtual ProgramStateRef processAssume(ProgramStateRef state,
106218887Sdim                                       SVal cond, bool assumption) = 0;
107218887Sdim
108226633Sdim  /// wantsRegionChangeUpdate - Called by ProgramStateManager to determine if a
109218887Sdim  ///  region change should trigger a processRegionChanges update.
110234353Sdim  virtual bool wantsRegionChangeUpdate(ProgramStateRef state) = 0;
111218887Sdim
112234353Sdim  /// processRegionChanges - Called by ProgramStateManager whenever a change is
113234353Sdim  /// made to the store. Used to update checkers that track region values.
114234353Sdim  virtual ProgramStateRef
115234353Sdim  processRegionChanges(ProgramStateRef state,
116249423Sdim                       const InvalidatedSymbols *invalidated,
117226633Sdim                       ArrayRef<const MemRegion *> ExplicitRegions,
118234353Sdim                       ArrayRef<const MemRegion *> Regions,
119239462Sdim                       const CallEvent *Call) = 0;
120218887Sdim
121223017Sdim
122234353Sdim  inline ProgramStateRef
123234353Sdim  processRegionChange(ProgramStateRef state,
124223017Sdim                      const MemRegion* MR) {
125234353Sdim    return processRegionChanges(state, 0, MR, MR, 0);
126218887Sdim  }
127218887Sdim
128249423Sdim  virtual ProgramStateRef
129249423Sdim  processPointerEscapedOnBind(ProgramStateRef State, SVal Loc, SVal Val) = 0;
130249423Sdim
131249423Sdim  virtual ProgramStateRef
132249423Sdim  notifyCheckersOfPointerEscape(ProgramStateRef State,
133249423Sdim                           const InvalidatedSymbols *Invalidated,
134249423Sdim                           ArrayRef<const MemRegion *> ExplicitRegions,
135249423Sdim                           ArrayRef<const MemRegion *> Regions,
136249423Sdim                           const CallEvent *Call,
137249423Sdim                           bool IsConst = false) = 0;
138249423Sdim
139226633Sdim  /// printState - Called by ProgramStateManager to print checker-specific data.
140234353Sdim  virtual void printState(raw_ostream &Out, ProgramStateRef State,
141226633Sdim                          const char *NL, const char *Sep) = 0;
142226633Sdim
143218887Sdim  /// Called by CoreEngine when the analysis worklist is either empty or the
144218887Sdim  //  maximum number of analysis steps have been reached.
145218887Sdim  virtual void processEndWorklist(bool hasWorkRemaining) = 0;
146218887Sdim};
147218887Sdim
148218887Sdim} // end GR namespace
149218887Sdim
150218887Sdim} // end clang namespace
151218887Sdim
152218887Sdim#endif
153