1 //==- GRStateTrait.h - Partial implementations of GRStateTrait -----*- 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 defines partial implementations of template specializations of
11 // the class GRStateTrait<>. GRStateTrait<> is used by GRState to implement
12 // set/get methods for mapulating a GRState's generic data map.
14 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CLANG_GR_GRSTATETRAIT_H
18 #define LLVM_CLANG_GR_GRSTATETRAIT_H
21 class BumpPtrAllocator;
22 template <typename K, typename D, typename I> class ImmutableMap;
23 template <typename K, typename I> class ImmutableSet;
24 template <typename T> class ImmutableList;
25 template <typename T> class ImmutableListImpl;
31 template <typename T> struct GRStatePartialTrait;
33 // Partial-specialization for ImmutableMap.
35 template <typename Key, typename Data, typename Info>
36 struct GRStatePartialTrait< llvm::ImmutableMap<Key,Data,Info> > {
37 typedef llvm::ImmutableMap<Key,Data,Info> data_type;
38 typedef typename data_type::Factory& context_type;
40 typedef Data value_type;
41 typedef const value_type* lookup_type;
43 static inline data_type MakeData(void* const* p) {
44 return p ? data_type((typename data_type::TreeTy*) *p) : data_type(0);
46 static inline void* MakeVoidPtr(data_type B) {
49 static lookup_type Lookup(data_type B, key_type K) {
52 static data_type Set(data_type B, key_type K, value_type E,context_type F){
53 return F.add(B, K, E);
56 static data_type Remove(data_type B, key_type K, context_type F) {
57 return F.remove(B, K);
60 static inline context_type MakeContext(void* p) {
61 return *((typename data_type::Factory*) p);
64 static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
65 return new typename data_type::Factory(Alloc);
68 static void DeleteContext(void* Ctx) {
69 delete (typename data_type::Factory*) Ctx;
74 // Partial-specialization for ImmutableSet.
76 template <typename Key, typename Info>
77 struct GRStatePartialTrait< llvm::ImmutableSet<Key,Info> > {
78 typedef llvm::ImmutableSet<Key,Info> data_type;
79 typedef typename data_type::Factory& context_type;
82 static inline data_type MakeData(void* const* p) {
83 return p ? data_type((typename data_type::TreeTy*) *p) : data_type(0);
86 static inline void* MakeVoidPtr(data_type B) {
90 static data_type Add(data_type B, key_type K, context_type F) {
94 static data_type Remove(data_type B, key_type K, context_type F) {
95 return F.remove(B, K);
98 static bool Contains(data_type B, key_type K) {
102 static inline context_type MakeContext(void* p) {
103 return *((typename data_type::Factory*) p);
106 static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
107 return new typename data_type::Factory(Alloc);
110 static void DeleteContext(void* Ctx) {
111 delete (typename data_type::Factory*) Ctx;
115 // Partial-specialization for ImmutableList.
117 template <typename T>
118 struct GRStatePartialTrait< llvm::ImmutableList<T> > {
119 typedef llvm::ImmutableList<T> data_type;
121 typedef typename data_type::Factory& context_type;
123 static data_type Add(data_type L, key_type K, context_type F) {
127 static bool Contains(data_type L, key_type K) {
128 return L.contains(K);
131 static inline data_type MakeData(void* const* p) {
132 return p ? data_type((const llvm::ImmutableListImpl<T>*) *p)
136 static inline void* MakeVoidPtr(data_type D) {
137 return (void*) D.getInternalPointer();
140 static inline context_type MakeContext(void* p) {
141 return *((typename data_type::Factory*) p);
144 static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
145 return new typename data_type::Factory(Alloc);
148 static void DeleteContext(void* Ctx) {
149 delete (typename data_type::Factory*) Ctx;
153 // Partial specialization for bool.
154 template <> struct GRStatePartialTrait<bool> {
155 typedef bool data_type;
157 static inline data_type MakeData(void* const* p) {
158 return p ? (data_type) (uintptr_t) *p
161 static inline void *MakeVoidPtr(data_type d) {
162 return (void*) (uintptr_t) d;
166 // Partial specialization for unsigned.
167 template <> struct GRStatePartialTrait<unsigned> {
168 typedef unsigned data_type;
170 static inline data_type MakeData(void* const* p) {
171 return p ? (data_type) (uintptr_t) *p
174 static inline void *MakeVoidPtr(data_type d) {
175 return (void*) (uintptr_t) d;
179 } // end GR namespace
181 } // end clang namespace