]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngineBuilders.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / include / clang / StaticAnalyzer / Core / PathSensitive / ExprEngineBuilders.h
1 //===-- ExprEngineBuilders.h - "Builder" classes for ExprEngine ---*- 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 smart builder "references" which are used to marshal
11 //  builders between ExprEngine objects and their related components.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_GR_EXPRENGINE_BUILDERS
16 #define LLVM_CLANG_GR_EXPRENGINE_BUILDERS
17 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
18 #include "clang/Analysis/Support/SaveAndRestore.h"
19
20 namespace clang {
21
22 namespace ento {
23
24 class StmtNodeBuilderRef {
25   ExplodedNodeSet &Dst;
26   StmtNodeBuilder &B;
27   ExprEngine& Eng;
28   ExplodedNode *Pred;
29   const ProgramState *state;
30   const Stmt *stmt;
31   const unsigned OldSize;
32   const bool AutoCreateNode;
33   SaveAndRestore<bool> OldSink;
34   SaveOr OldHasGen;
35
36 private:
37   friend class ExprEngine;
38
39   StmtNodeBuilderRef(); // do not implement
40   void operator=(const StmtNodeBuilderRef&); // do not implement
41
42   StmtNodeBuilderRef(ExplodedNodeSet &dst,
43                        StmtNodeBuilder &builder,
44                        ExprEngine& eng,
45                        ExplodedNode *pred,
46                        const ProgramState *st,
47                        const Stmt *s, bool auto_create_node)
48   : Dst(dst), B(builder), Eng(eng), Pred(pred),
49     state(st), stmt(s), OldSize(Dst.size()), AutoCreateNode(auto_create_node),
50     OldSink(B.BuildSinks), OldHasGen(B.hasGeneratedNode) {}
51
52 public:
53
54   ~StmtNodeBuilderRef() {
55     // Handle the case where no nodes where generated.  Auto-generate that
56     // contains the updated state if we aren't generating sinks.
57     if (!B.BuildSinks && Dst.size() == OldSize && !B.hasGeneratedNode) {
58       if (AutoCreateNode)
59         B.MakeNode(Dst, const_cast<Stmt*>(stmt), Pred, state);
60       else
61         Dst.Add(Pred);
62     }
63   }
64
65   const ProgramState *getState() { return state; }
66
67   ProgramStateManager& getStateManager() {
68     return Eng.getStateManager();
69   }
70
71   ExplodedNode *MakeNode(const ProgramState *state) {
72     return B.MakeNode(Dst, const_cast<Stmt*>(stmt), Pred, state);
73   }
74 };
75
76 } // end GR namespace
77
78 } // end clang namespace
79
80 #endif