1 //== SubEngine.h - Interface of the subengine of CoreEngine --------*- C++ -*-//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface of a subengine of the CoreEngine.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_GR_SUBENGINE_H
14 #define LLVM_CLANG_GR_SUBENGINE_H
16 #include "clang/Analysis/ProgramPoint.h"
17 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
24 class LocationContext;
29 template <typename PP> class GenericNodeBuilder;
30 struct NodeBuilderContext;
31 class AnalysisManager;
32 class ExplodedNodeSet;
35 class ProgramStateManager;
37 class BranchNodeBuilder;
38 class IndirectGotoNodeBuilder;
39 class SwitchNodeBuilder;
40 class EndOfFunctionNodeBuilder;
41 class CallEnterNodeBuilder;
42 class CallExitNodeBuilder;
47 virtual ~SubEngine() {}
49 virtual const ProgramState *getInitialState(const LocationContext *InitLoc) = 0;
51 virtual AnalysisManager &getAnalysisManager() = 0;
53 virtual ProgramStateManager &getStateManager() = 0;
55 /// Called by CoreEngine. Used to generate new successor
56 /// nodes by processing the 'effects' of a block-level statement.
57 virtual void processCFGElement(const CFGElement E, ExplodedNode* Pred,
58 unsigned StmtIdx, NodeBuilderContext *Ctx)=0;
60 /// Called by CoreEngine when it starts processing a CFGBlock. The
61 /// SubEngine is expected to populate dstNodes with new nodes representing
62 /// updated analysis state, or generate no nodes at all if it doesn't.
63 virtual void processCFGBlockEntrance(ExplodedNodeSet &dstNodes,
64 GenericNodeBuilder<BlockEntrance> &nodeBuilder) = 0;
66 /// Called by CoreEngine. Used to generate successor
67 /// nodes by processing the 'effects' of a branch condition.
68 virtual void processBranch(const Stmt *Condition, const Stmt *Term,
69 NodeBuilderContext& BuilderCtx,
73 const CFGBlock *DstF) = 0;
75 /// Called by CoreEngine. Used to generate successor
76 /// nodes by processing the 'effects' of a computed goto jump.
77 virtual void processIndirectGoto(IndirectGotoNodeBuilder& builder) = 0;
79 /// Called by CoreEngine. Used to generate successor
80 /// nodes by processing the 'effects' of a switch statement.
81 virtual void processSwitch(SwitchNodeBuilder& builder) = 0;
83 /// Called by CoreEngine. Used to generate end-of-path
84 /// nodes when the control reaches the end of a function.
85 virtual void processEndOfFunction(EndOfFunctionNodeBuilder& builder) = 0;
87 // Generate the entry node of the callee.
88 virtual void processCallEnter(CallEnterNodeBuilder &builder) = 0;
90 // Generate the first post callsite node.
91 virtual void processCallExit(CallExitNodeBuilder &builder) = 0;
93 /// Called by ConstraintManager. Used to call checker-specific
94 /// logic for handling assumptions on symbolic values.
95 virtual const ProgramState *processAssume(const ProgramState *state,
96 SVal cond, bool assumption) = 0;
98 /// wantsRegionChangeUpdate - Called by ProgramStateManager to determine if a
99 /// region change should trigger a processRegionChanges update.
100 virtual bool wantsRegionChangeUpdate(const ProgramState *state) = 0;
102 /// processRegionChanges - Called by ProgramStateManager whenever a change is made
103 /// to the store. Used to update checkers that track region values.
104 virtual const ProgramState *
105 processRegionChanges(const ProgramState *state,
106 const StoreManager::InvalidatedSymbols *invalidated,
107 ArrayRef<const MemRegion *> ExplicitRegions,
108 ArrayRef<const MemRegion *> Regions) = 0;
111 inline const ProgramState *
112 processRegionChange(const ProgramState *state,
113 const MemRegion* MR) {
114 return processRegionChanges(state, 0, MR, MR);
117 /// printState - Called by ProgramStateManager to print checker-specific data.
118 virtual void printState(raw_ostream &Out, const ProgramState *State,
119 const char *NL, const char *Sep) = 0;
121 /// Called by CoreEngine when the analysis worklist is either empty or the
122 // maximum number of analysis steps have been reached.
123 virtual void processEndWorklist(bool hasWorkRemaining) = 0;
126 } // end GR namespace
128 } // end clang namespace