Implicitly expand argument packs when performing template argument
[clang.git] / include / clang / Checker / PathSensitive / GRStateTrait.h
blob25be33f0285f4b5ff795082189a15e31d900ebfe
1 //==- GRStateTrait.h - Partial implementations of GRStateTrait -----*- 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 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_ANALYSIS_GRSTATETRAIT_H
18 #define LLVM_CLANG_ANALYSIS_GRSTATETRAIT_H
20 namespace llvm {
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;
28 namespace clang {
29 template <typename T> struct GRStatePartialTrait;
31 // Partial-specialization for ImmutableMap.
33 template <typename Key, typename Data, typename Info>
34 struct GRStatePartialTrait< llvm::ImmutableMap<Key,Data,Info> > {
35 typedef llvm::ImmutableMap<Key,Data,Info> data_type;
36 typedef typename data_type::Factory& context_type;
37 typedef Key key_type;
38 typedef Data value_type;
39 typedef const value_type* lookup_type;
41 static inline data_type MakeData(void* const* p) {
42 return p ? data_type((typename data_type::TreeTy*) *p) : data_type(0);
44 static inline void* MakeVoidPtr(data_type B) {
45 return B.getRoot();
47 static lookup_type Lookup(data_type B, key_type K) {
48 return B.lookup(K);
50 static data_type Set(data_type B, key_type K, value_type E,context_type F){
51 return F.add(B, K, E);
54 static data_type Remove(data_type B, key_type K, context_type F) {
55 return F.remove(B, K);
58 static inline context_type MakeContext(void* p) {
59 return *((typename data_type::Factory*) p);
62 static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
63 return new typename data_type::Factory(Alloc);
66 static void DeleteContext(void* Ctx) {
67 delete (typename data_type::Factory*) Ctx;
72 // Partial-specialization for ImmutableSet.
74 template <typename Key, typename Info>
75 struct GRStatePartialTrait< llvm::ImmutableSet<Key,Info> > {
76 typedef llvm::ImmutableSet<Key,Info> data_type;
77 typedef typename data_type::Factory& context_type;
78 typedef Key key_type;
80 static inline data_type MakeData(void* const* p) {
81 return p ? data_type((typename data_type::TreeTy*) *p) : data_type(0);
84 static inline void* MakeVoidPtr(data_type B) {
85 return B.getRoot();
88 static data_type Add(data_type B, key_type K, context_type F) {
89 return F.add(B, K);
92 static data_type Remove(data_type B, key_type K, context_type F) {
93 return F.remove(B, K);
96 static bool Contains(data_type B, key_type K) {
97 return B.contains(K);
100 static inline context_type MakeContext(void* p) {
101 return *((typename data_type::Factory*) p);
104 static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
105 return new typename data_type::Factory(Alloc);
108 static void DeleteContext(void* Ctx) {
109 delete (typename data_type::Factory*) Ctx;
113 // Partial-specialization for ImmutableList.
115 template <typename T>
116 struct GRStatePartialTrait< llvm::ImmutableList<T> > {
117 typedef llvm::ImmutableList<T> data_type;
118 typedef T key_type;
119 typedef typename data_type::Factory& context_type;
121 static data_type Add(data_type L, key_type K, context_type F) {
122 return F.add(K, L);
125 static inline data_type MakeData(void* const* p) {
126 return p ? data_type((const llvm::ImmutableListImpl<T>*) *p)
127 : data_type(0);
130 static inline void* MakeVoidPtr(data_type D) {
131 return (void*) D.getInternalPointer();
134 static inline context_type MakeContext(void* p) {
135 return *((typename data_type::Factory*) p);
138 static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
139 return new typename data_type::Factory(Alloc);
142 static void DeleteContext(void* Ctx) {
143 delete (typename data_type::Factory*) Ctx;
146 } // end clang namespace
148 #endif