summaryrefslogtreecommitdiffstats
path: root/include/clang/Analysis/PathSensitive/GRStateTrait.h
blob: ce43cda31e9e54a44ea26ddcc2c731a0170a7318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//==- GRStateTrait.h - Partial implementations of GRStateTrait -----*- C++ -*-//
//             
//                     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
//  the class GRStateTrait<>.  GRStateTrait<> is used by GRState to implement
//  set/get methods for mapulating a GRState's generic data map.
//
//===----------------------------------------------------------------------===//


#ifndef LLVM_CLANG_ANALYSIS_GRSTATETRAIT_H
#define LLVM_CLANG_ANALYSIS_GRSTATETRAIT_H

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 {
  template <typename T> struct GRStatePartialTrait;
  
  // Partial-specialization for ImmutableMap.
  
  template <typename Key, typename Data, typename Info>
  struct GRStatePartialTrait< llvm::ImmutableMap<Key,Data,Info> > {
    typedef llvm::ImmutableMap<Key,Data,Info> data_type;
    typedef typename data_type::Factory&      context_type;  
    typedef Key                               key_type;
    typedef Data                              value_type;
    typedef const value_type*                 lookup_type;
    
    static inline data_type MakeData(void* const* p) {
      return p ? data_type((typename data_type::TreeTy*) *p) : data_type(0);
    }  
    static inline void* MakeVoidPtr(data_type B) {
      return B.getRoot();
    }  
    static lookup_type Lookup(data_type B, key_type K) {
      return B.lookup(K);
    }  
    static data_type Set(data_type B, key_type K, value_type E,context_type F){
      return F.Add(B, K, E);
    }
    
    static data_type Remove(data_type B, key_type K, context_type F) {
      return F.Remove(B, K);
    }
    
    static inline context_type MakeContext(void* p) {
      return *((typename data_type::Factory*) p);
    }
    
    static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
      return new typename data_type::Factory(Alloc);      
    }
    
    static void DeleteContext(void* Ctx) {
      delete (typename data_type::Factory*) Ctx;
    }      
  };
  
  
  // Partial-specialization for ImmutableSet.
  
  template <typename Key, typename Info>
  struct GRStatePartialTrait< llvm::ImmutableSet<Key,Info> > {
    typedef llvm::ImmutableSet<Key,Info>      data_type;
    typedef typename data_type::Factory&      context_type;  
    typedef Key                               key_type;
    
    static inline data_type MakeData(void* const* p) {
      return p ? data_type((typename data_type::TreeTy*) *p) : data_type(0);
    }  

    static inline void* MakeVoidPtr(data_type B) {
      return B.getRoot();
    }

    static data_type Add(data_type B, key_type K, context_type F) {
      return F.Add(B, K);
    }
    
    static data_type Remove(data_type B, key_type K, context_type F) {
      return F.Remove(B, K);
    }
    
    static bool Contains(data_type B, key_type K) {
      return B.contains(K);
    }
    
    static inline context_type MakeContext(void* p) {
      return *((typename data_type::Factory*) p);
    }
    
    static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
      return new typename data_type::Factory(Alloc);      
    }
    
    static void DeleteContext(void* Ctx) {
      delete (typename data_type::Factory*) Ctx;
    }      
  };
    
  // Partial-specialization for ImmutableList.
  
  template <typename T>
  struct GRStatePartialTrait< llvm::ImmutableList<T> > {
    typedef llvm::ImmutableList<T>            data_type;
    typedef T                                 key_type;
    typedef typename data_type::Factory&      context_type;  
    
    static data_type Add(data_type L, key_type K, context_type F) {
      return F.Add(K, L);
    }
    
    static inline data_type MakeData(void* const* p) {
      return p ? data_type((const llvm::ImmutableListImpl<T>*) *p) 
               : data_type(0);
    }  
    
    static inline void* MakeVoidPtr(data_type D) {
      return  (void*) D.getInternalPointer();
    }  
    
    static inline context_type MakeContext(void* p) {
      return *((typename data_type::Factory*) p);
    }
    
    static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
      return new typename data_type::Factory(Alloc);      
    }
    
    static void DeleteContext(void* Ctx) {
      delete (typename data_type::Factory*) Ctx;
    }      
  };
} // end clang namespace

#endif
OpenPOWER on IntegriCloud