1 //== Environment.h - Map from Stmt* to Locations/Values ---------*- 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 defined the Environment and EnvironmentManager classes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_GR_ENVIRONMENT_H
15 #define LLVM_CLANG_GR_ENVIRONMENT_H
17 #include "clang/StaticAnalyzer/PathSensitive/Store.h"
18 #include "clang/StaticAnalyzer/PathSensitive/SVals.h"
19 #include "llvm/ADT/ImmutableMap.h"
27 class EnvironmentManager
;
30 /// Environment - An immutable map from Stmts to their current
31 /// symbolic values (SVals).
35 friend class EnvironmentManager
;
38 typedef llvm::ImmutableMap
<const Stmt
*,SVal
> BindingsTy
;
41 BindingsTy ExprBindings
;
43 Environment(BindingsTy eb
)
46 SVal
lookupExpr(const Stmt
* E
) const;
49 typedef BindingsTy::iterator iterator
;
50 iterator
begin() const { return ExprBindings
.begin(); }
51 iterator
end() const { return ExprBindings
.end(); }
54 /// GetSVal - Fetches the current binding of the expression in the
56 SVal
getSVal(const Stmt
* Ex
, SValBuilder
& svalBuilder
) const;
58 /// Profile - Profile the contents of an Environment object for use
60 static void Profile(llvm::FoldingSetNodeID
& ID
, const Environment
* env
) {
61 env
->ExprBindings
.Profile(ID
);
64 /// Profile - Used to profile the contents of this object for inclusion
66 void Profile(llvm::FoldingSetNodeID
& ID
) const {
70 bool operator==(const Environment
& RHS
) const {
71 return ExprBindings
== RHS
.ExprBindings
;
75 class EnvironmentManager
{
77 typedef Environment::BindingsTy::Factory FactoryTy
;
81 EnvironmentManager(llvm::BumpPtrAllocator
& Allocator
) : F(Allocator
) {}
82 ~EnvironmentManager() {}
84 Environment
getInitialEnvironment() {
85 return Environment(F
.getEmptyMap());
88 /// Bind the value 'V' to the statement 'S'.
89 Environment
bindExpr(Environment Env
, const Stmt
*S
, SVal V
,
92 /// Bind the location 'location' and value 'V' to the statement 'S'. This
93 /// is used when simulating loads/stores.
94 Environment
bindExprAndLocation(Environment Env
, const Stmt
*S
, SVal location
,
97 Environment
RemoveDeadBindings(Environment Env
,
98 SymbolReaper
&SymReaper
, const GRState
*ST
,
99 llvm::SmallVectorImpl
<const MemRegion
*>& RegionRoots
);
102 } // end GR namespace
104 } // end clang namespace