]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Environment.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / include / clang / StaticAnalyzer / Core / PathSensitive / Environment.h
1 //== Environment.h - Map from Stmt* to Locations/Values ---------*- 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 defined the Environment and EnvironmentManager classes.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_GR_ENVIRONMENT_H
15 #define LLVM_CLANG_GR_ENVIRONMENT_H
16
17 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
19 #include "llvm/ADT/ImmutableMap.h"
20
21 namespace clang {
22
23 class LiveVariables;
24
25 namespace ento {
26
27 class EnvironmentManager;
28 class SValBuilder;
29
30 /// Environment - An immutable map from Stmts to their current
31 ///  symbolic values (SVals).
32 ///
33 class Environment {
34 private:
35   friend class EnvironmentManager;
36
37   // Type definitions.
38   typedef llvm::ImmutableMap<const Stmt*,SVal> BindingsTy;
39
40   // Data.
41   BindingsTy ExprBindings;
42
43   Environment(BindingsTy eb)
44     : ExprBindings(eb) {}
45
46   SVal lookupExpr(const Stmt* E) const;
47
48 public:
49   typedef BindingsTy::iterator iterator;
50   iterator begin() const { return ExprBindings.begin(); }
51   iterator end() const { return ExprBindings.end(); }
52
53
54   /// getSVal - Fetches the current binding of the expression in the
55   ///  Environment.
56   SVal getSVal(const Stmt* Ex, SValBuilder& svalBuilder,
57                bool useOnlyDirectBindings = false) const;
58
59   /// Profile - Profile the contents of an Environment object for use
60   ///  in a FoldingSet.
61   static void Profile(llvm::FoldingSetNodeID& ID, const Environment* env) {
62     env->ExprBindings.Profile(ID);
63   }
64
65   /// Profile - Used to profile the contents of this object for inclusion
66   ///  in a FoldingSet.
67   void Profile(llvm::FoldingSetNodeID& ID) const {
68     Profile(ID, this);
69   }
70
71   bool operator==(const Environment& RHS) const {
72     return ExprBindings == RHS.ExprBindings;
73   }
74 };
75
76 class EnvironmentManager {
77 private:
78   typedef Environment::BindingsTy::Factory FactoryTy;
79   FactoryTy F;
80
81 public:
82   EnvironmentManager(llvm::BumpPtrAllocator& Allocator) : F(Allocator) {}
83   ~EnvironmentManager() {}
84
85   Environment getInitialEnvironment() {
86     return Environment(F.getEmptyMap());
87   }
88
89   /// Bind the value 'V' to the statement 'S'.
90   Environment bindExpr(Environment Env, const Stmt *S, SVal V,
91                        bool Invalidate);
92   
93   /// Bind the location 'location' and value 'V' to the statement 'S'.  This
94   /// is used when simulating loads/stores.
95   Environment bindExprAndLocation(Environment Env, const Stmt *S, SVal location,
96                                   SVal V);
97
98   Environment removeDeadBindings(Environment Env,
99                                  SymbolReaper &SymReaper, const GRState *ST,
100                           llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
101 };
102
103 } // end GR namespace
104
105 } // end clang namespace
106
107 #endif