2011-10-20 17:14:49 -04:00
|
|
|
//ProgramStateTrait.h - Partial implementations of ProgramStateTrait -*- C++ -*-
|
2009-10-14 14:03:49 -04:00
|
|
|
//
|
2009-06-02 13:58:47 -04:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
|
//
|
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
|
|
|
|
// This file defines partial implementations of template specializations of
|
2011-10-20 17:14:49 -04:00
|
|
|
// the class ProgramStateTrait<>. ProgramStateTrait<> is used by ProgramState
|
2012-04-14 10:01:31 -04:00
|
|
|
// to implement set/get methods for manipulating a ProgramState's
|
|
|
|
|
// generic data map.
|
2009-06-02 13:58:47 -04:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
#ifndef LLVM_CLANG_GR_PROGRAMSTATETRAIT_H
|
|
|
|
|
#define LLVM_CLANG_GR_PROGRAMSTATETRAIT_H
|
2009-06-02 13:58:47 -04:00
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
class BumpPtrAllocator;
|
|
|
|
|
template <typename K, typename D, typename I> class ImmutableMap;
|
|
|
|
|
template <typename K, typename I> class ImmutableSet;
|
|
|
|
|
template <typename T> class ImmutableList;
|
|
|
|
|
template <typename T> class ImmutableListImpl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace clang {
|
2011-02-20 08:06:31 -05:00
|
|
|
|
|
|
|
|
namespace ento {
|
2011-10-20 17:14:49 -04:00
|
|
|
template <typename T> struct ProgramStatePartialTrait;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
/// Declares a program state trait for type \p Type called \p Name, and
|
|
|
|
|
/// introduce a typedef named \c NameTy.
|
|
|
|
|
/// The macro should not be used inside namespaces, or for traits that must
|
|
|
|
|
/// be accessible from more than one translation unit.
|
|
|
|
|
#define REGISTER_TRAIT_WITH_PROGRAMSTATE(Name, Type) \
|
|
|
|
|
namespace { \
|
|
|
|
|
class Name {}; \
|
|
|
|
|
typedef Type Name ## Ty; \
|
|
|
|
|
} \
|
|
|
|
|
namespace clang { \
|
|
|
|
|
namespace ento { \
|
|
|
|
|
template <> \
|
|
|
|
|
struct ProgramStateTrait<Name> \
|
|
|
|
|
: public ProgramStatePartialTrait<Name ## Ty> { \
|
|
|
|
|
static void *GDMIndex() { static int Index; return &Index; } \
|
|
|
|
|
}; \
|
|
|
|
|
} \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
// Partial-specialization for ImmutableMap.
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
template <typename Key, typename Data, typename Info>
|
2011-10-20 17:14:49 -04:00
|
|
|
struct ProgramStatePartialTrait< llvm::ImmutableMap<Key,Data,Info> > {
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef llvm::ImmutableMap<Key,Data,Info> data_type;
|
2009-10-14 14:03:49 -04:00
|
|
|
typedef typename data_type::Factory& context_type;
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef Key key_type;
|
|
|
|
|
typedef Data value_type;
|
|
|
|
|
typedef const value_type* lookup_type;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline data_type MakeData(void *const* p) {
|
2009-06-02 13:58:47 -04:00
|
|
|
return p ? data_type((typename data_type::TreeTy*) *p) : data_type(0);
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline void *MakeVoidPtr(data_type B) {
|
2009-06-02 13:58:47 -04:00
|
|
|
return B.getRoot();
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2009-06-02 13:58:47 -04:00
|
|
|
static lookup_type Lookup(data_type B, key_type K) {
|
|
|
|
|
return B.lookup(K);
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2009-06-02 13:58:47 -04:00
|
|
|
static data_type Set(data_type B, key_type K, value_type E,context_type F){
|
2011-02-20 08:06:31 -05:00
|
|
|
return F.add(B, K, E);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static data_type Remove(data_type B, key_type K, context_type F) {
|
2011-02-20 08:06:31 -05:00
|
|
|
return F.remove(B, K);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline context_type MakeContext(void *p) {
|
2009-06-02 13:58:47 -04:00
|
|
|
return *((typename data_type::Factory*) p);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static void *CreateContext(llvm::BumpPtrAllocator& Alloc) {
|
2009-10-14 14:03:49 -04:00
|
|
|
return new typename data_type::Factory(Alloc);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static void DeleteContext(void *Ctx) {
|
2009-06-02 13:58:47 -04:00
|
|
|
delete (typename data_type::Factory*) Ctx;
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2009-06-02 13:58:47 -04:00
|
|
|
};
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
/// Helper for registering a map trait.
|
|
|
|
|
///
|
|
|
|
|
/// If the map type were written directly in the invocation of
|
|
|
|
|
/// REGISTER_TRAIT_WITH_PROGRAMSTATE, the comma in the template arguments
|
|
|
|
|
/// would be treated as a macro argument separator, which is wrong.
|
|
|
|
|
/// This allows the user to specify a map type in a way that the preprocessor
|
|
|
|
|
/// can deal with.
|
|
|
|
|
#define CLANG_ENTO_PROGRAMSTATE_MAP(Key, Value) llvm::ImmutableMap<Key, Value>
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
// Partial-specialization for ImmutableSet.
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
template <typename Key, typename Info>
|
2011-10-20 17:14:49 -04:00
|
|
|
struct ProgramStatePartialTrait< llvm::ImmutableSet<Key,Info> > {
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef llvm::ImmutableSet<Key,Info> data_type;
|
2009-10-14 14:03:49 -04:00
|
|
|
typedef typename data_type::Factory& context_type;
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef Key key_type;
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline data_type MakeData(void *const* p) {
|
2009-06-02 13:58:47 -04:00
|
|
|
return p ? data_type((typename data_type::TreeTy*) *p) : data_type(0);
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2009-06-02 13:58:47 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline void *MakeVoidPtr(data_type B) {
|
2009-06-02 13:58:47 -04:00
|
|
|
return B.getRoot();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static data_type Add(data_type B, key_type K, context_type F) {
|
2011-02-20 08:06:31 -05:00
|
|
|
return F.add(B, K);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static data_type Remove(data_type B, key_type K, context_type F) {
|
2011-02-20 08:06:31 -05:00
|
|
|
return F.remove(B, K);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static bool Contains(data_type B, key_type K) {
|
|
|
|
|
return B.contains(K);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline context_type MakeContext(void *p) {
|
2009-06-02 13:58:47 -04:00
|
|
|
return *((typename data_type::Factory*) p);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static void *CreateContext(llvm::BumpPtrAllocator& Alloc) {
|
2009-10-14 14:03:49 -04:00
|
|
|
return new typename data_type::Factory(Alloc);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static void DeleteContext(void *Ctx) {
|
2009-06-02 13:58:47 -04:00
|
|
|
delete (typename data_type::Factory*) Ctx;
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2009-06-02 13:58:47 -04:00
|
|
|
};
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2012-12-02 08:20:44 -05:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
// Partial-specialization for ImmutableList.
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
template <typename T>
|
2011-10-20 17:14:49 -04:00
|
|
|
struct ProgramStatePartialTrait< llvm::ImmutableList<T> > {
|
2009-06-02 13:58:47 -04:00
|
|
|
typedef llvm::ImmutableList<T> data_type;
|
|
|
|
|
typedef T key_type;
|
2009-10-14 14:03:49 -04:00
|
|
|
typedef typename data_type::Factory& context_type;
|
|
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
static data_type Add(data_type L, key_type K, context_type F) {
|
2011-02-20 08:06:31 -05:00
|
|
|
return F.add(K, L);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-07-17 11:40:56 -04:00
|
|
|
static bool Contains(data_type L, key_type K) {
|
|
|
|
|
return L.contains(K);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline data_type MakeData(void *const* p) {
|
2009-10-14 14:03:49 -04:00
|
|
|
return p ? data_type((const llvm::ImmutableListImpl<T>*) *p)
|
2009-06-02 13:58:47 -04:00
|
|
|
: data_type(0);
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
|
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline void *MakeVoidPtr(data_type D) {
|
2009-06-02 13:58:47 -04:00
|
|
|
return (void*) D.getInternalPointer();
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
|
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline context_type MakeContext(void *p) {
|
2009-06-02 13:58:47 -04:00
|
|
|
return *((typename data_type::Factory*) p);
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static void *CreateContext(llvm::BumpPtrAllocator& Alloc) {
|
2009-10-14 14:03:49 -04:00
|
|
|
return new typename data_type::Factory(Alloc);
|
2009-06-02 13:58:47 -04:00
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static void DeleteContext(void *Ctx) {
|
2009-06-02 13:58:47 -04:00
|
|
|
delete (typename data_type::Factory*) Ctx;
|
2009-10-14 14:03:49 -04:00
|
|
|
}
|
2009-06-02 13:58:47 -04:00
|
|
|
};
|
2012-12-02 08:20:44 -05:00
|
|
|
|
2011-02-20 08:06:31 -05:00
|
|
|
|
|
|
|
|
// Partial specialization for bool.
|
2011-10-20 17:14:49 -04:00
|
|
|
template <> struct ProgramStatePartialTrait<bool> {
|
2011-02-20 08:06:31 -05:00
|
|
|
typedef bool data_type;
|
|
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline data_type MakeData(void *const* p) {
|
2011-02-26 17:09:03 -05:00
|
|
|
return p ? (data_type) (uintptr_t) *p
|
|
|
|
|
: data_type();
|
|
|
|
|
}
|
|
|
|
|
static inline void *MakeVoidPtr(data_type d) {
|
|
|
|
|
return (void*) (uintptr_t) d;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Partial specialization for unsigned.
|
2011-10-20 17:14:49 -04:00
|
|
|
template <> struct ProgramStatePartialTrait<unsigned> {
|
2011-02-26 17:09:03 -05:00
|
|
|
typedef unsigned data_type;
|
|
|
|
|
|
2011-10-20 17:14:49 -04:00
|
|
|
static inline data_type MakeData(void *const* p) {
|
2011-02-26 17:09:03 -05:00
|
|
|
return p ? (data_type) (uintptr_t) *p
|
|
|
|
|
: data_type();
|
2011-02-20 08:06:31 -05:00
|
|
|
}
|
|
|
|
|
static inline void *MakeVoidPtr(data_type d) {
|
|
|
|
|
return (void*) (uintptr_t) d;
|
|
|
|
|
}
|
|
|
|
|
};
|
2012-04-14 10:01:31 -04:00
|
|
|
|
|
|
|
|
// Partial specialization for void*.
|
|
|
|
|
template <> struct ProgramStatePartialTrait<void*> {
|
|
|
|
|
typedef void *data_type;
|
|
|
|
|
|
|
|
|
|
static inline data_type MakeData(void *const* p) {
|
|
|
|
|
return p ? *p
|
|
|
|
|
: data_type();
|
|
|
|
|
}
|
|
|
|
|
static inline void *MakeVoidPtr(data_type d) {
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2011-02-20 08:06:31 -05:00
|
|
|
} // end GR namespace
|
|
|
|
|
|
2009-06-02 13:58:47 -04:00
|
|
|
} // end clang namespace
|
|
|
|
|
|
|
|
|
|
#endif
|