clang API Documentation
00001 //== SubEngine.h - Interface of the subengine of CoreEngine --------*- C++ -*-// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the interface of a subengine of the CoreEngine. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 #ifndef LLVM_CLANG_GR_SUBENGINE_H 00014 #define LLVM_CLANG_GR_SUBENGINE_H 00015 00016 #include "clang/Analysis/ProgramPoint.h" 00017 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" 00018 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h" 00019 00020 namespace clang { 00021 00022 class CFGBlock; 00023 class CFGElement; 00024 class LocationContext; 00025 class Stmt; 00026 00027 namespace ento { 00028 00029 struct NodeBuilderContext; 00030 class AnalysisManager; 00031 class ExplodedNodeSet; 00032 class ExplodedNode; 00033 class ProgramState; 00034 class ProgramStateManager; 00035 class BlockCounter; 00036 class BranchNodeBuilder; 00037 class IndirectGotoNodeBuilder; 00038 class SwitchNodeBuilder; 00039 class EndOfFunctionNodeBuilder; 00040 class NodeBuilderWithSinks; 00041 class MemRegion; 00042 00043 class SubEngine { 00044 virtual void anchor(); 00045 public: 00046 virtual ~SubEngine() {} 00047 00048 virtual ProgramStateRef getInitialState(const LocationContext *InitLoc) = 0; 00049 00050 virtual AnalysisManager &getAnalysisManager() = 0; 00051 00052 virtual ProgramStateManager &getStateManager() = 0; 00053 00054 /// Called by CoreEngine. Used to generate new successor 00055 /// nodes by processing the 'effects' of a block-level statement. 00056 virtual void processCFGElement(const CFGElement E, ExplodedNode* Pred, 00057 unsigned StmtIdx, NodeBuilderContext *Ctx)=0; 00058 00059 /// Called by CoreEngine when it starts processing a CFGBlock. The 00060 /// SubEngine is expected to populate dstNodes with new nodes representing 00061 /// updated analysis state, or generate no nodes at all if it doesn't. 00062 virtual void processCFGBlockEntrance(const BlockEdge &L, 00063 NodeBuilderWithSinks &nodeBuilder) = 0; 00064 00065 /// Called by CoreEngine. Used to generate successor 00066 /// nodes by processing the 'effects' of a branch condition. 00067 virtual void processBranch(const Stmt *Condition, const Stmt *Term, 00068 NodeBuilderContext& BuilderCtx, 00069 ExplodedNode *Pred, 00070 ExplodedNodeSet &Dst, 00071 const CFGBlock *DstT, 00072 const CFGBlock *DstF) = 0; 00073 00074 /// Called by CoreEngine. Used to generate successor 00075 /// nodes by processing the 'effects' of a computed goto jump. 00076 virtual void processIndirectGoto(IndirectGotoNodeBuilder& builder) = 0; 00077 00078 /// Called by CoreEngine. Used to generate successor 00079 /// nodes by processing the 'effects' of a switch statement. 00080 virtual void processSwitch(SwitchNodeBuilder& builder) = 0; 00081 00082 /// Called by CoreEngine. Used to generate end-of-path 00083 /// nodes when the control reaches the end of a function. 00084 virtual void processEndOfFunction(NodeBuilderContext& BC) = 0; 00085 00086 // Generate the entry node of the callee. 00087 virtual void processCallEnter(CallEnter CE, ExplodedNode *Pred) = 0; 00088 00089 // Generate the first post callsite node. 00090 virtual void processCallExit(ExplodedNode *Pred) = 0; 00091 00092 /// Called by ConstraintManager. Used to call checker-specific 00093 /// logic for handling assumptions on symbolic values. 00094 virtual ProgramStateRef processAssume(ProgramStateRef state, 00095 SVal cond, bool assumption) = 0; 00096 00097 /// wantsRegionChangeUpdate - Called by ProgramStateManager to determine if a 00098 /// region change should trigger a processRegionChanges update. 00099 virtual bool wantsRegionChangeUpdate(ProgramStateRef state) = 0; 00100 00101 /// processRegionChanges - Called by ProgramStateManager whenever a change is 00102 /// made to the store. Used to update checkers that track region values. 00103 virtual ProgramStateRef 00104 processRegionChanges(ProgramStateRef state, 00105 const StoreManager::InvalidatedSymbols *invalidated, 00106 ArrayRef<const MemRegion *> ExplicitRegions, 00107 ArrayRef<const MemRegion *> Regions, 00108 const CallOrObjCMessage *Call) = 0; 00109 00110 00111 inline ProgramStateRef 00112 processRegionChange(ProgramStateRef state, 00113 const MemRegion* MR) { 00114 return processRegionChanges(state, 0, MR, MR, 0); 00115 } 00116 00117 /// printState - Called by ProgramStateManager to print checker-specific data. 00118 virtual void printState(raw_ostream &Out, ProgramStateRef State, 00119 const char *NL, const char *Sep) = 0; 00120 00121 /// Called by CoreEngine when the analysis worklist is either empty or the 00122 // maximum number of analysis steps have been reached. 00123 virtual void processEndWorklist(bool hasWorkRemaining) = 0; 00124 }; 00125 00126 } // end GR namespace 00127 00128 } // end clang namespace 00129 00130 #endif