]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/FormatCache.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / FormatCache.h
1 //===-- FormatCache.h ---------------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef lldb_FormatCache_h_
12 #define lldb_FormatCache_h_
13
14 #include <map>
15 #include <mutex>
16
17 #include "lldb/Utility/ConstString.h"
18 #include "lldb/lldb-public.h"
19
20 namespace lldb_private {
21 class FormatCache {
22 private:
23   struct Entry {
24   private:
25     bool m_format_cached : 1;
26     bool m_summary_cached : 1;
27     bool m_synthetic_cached : 1;
28     bool m_validator_cached : 1;
29
30     lldb::TypeFormatImplSP m_format_sp;
31     lldb::TypeSummaryImplSP m_summary_sp;
32     lldb::SyntheticChildrenSP m_synthetic_sp;
33     lldb::TypeValidatorImplSP m_validator_sp;
34
35   public:
36     Entry();
37     Entry(lldb::TypeFormatImplSP);
38     Entry(lldb::TypeSummaryImplSP);
39     Entry(lldb::SyntheticChildrenSP);
40     Entry(lldb::TypeValidatorImplSP);
41     Entry(lldb::TypeFormatImplSP, lldb::TypeSummaryImplSP,
42           lldb::SyntheticChildrenSP, lldb::TypeValidatorImplSP);
43
44     bool IsFormatCached();
45
46     bool IsSummaryCached();
47
48     bool IsSyntheticCached();
49
50     bool IsValidatorCached();
51
52     lldb::TypeFormatImplSP GetFormat();
53
54     lldb::TypeSummaryImplSP GetSummary();
55
56     lldb::SyntheticChildrenSP GetSynthetic();
57
58     lldb::TypeValidatorImplSP GetValidator();
59
60     void SetFormat(lldb::TypeFormatImplSP);
61
62     void SetSummary(lldb::TypeSummaryImplSP);
63
64     void SetSynthetic(lldb::SyntheticChildrenSP);
65
66     void SetValidator(lldb::TypeValidatorImplSP);
67   };
68   typedef std::map<ConstString, Entry> CacheMap;
69   CacheMap m_map;
70   std::recursive_mutex m_mutex;
71
72   uint64_t m_cache_hits;
73   uint64_t m_cache_misses;
74
75   Entry &GetEntry(const ConstString &type);
76
77 public:
78   FormatCache();
79
80   bool GetFormat(const ConstString &type, lldb::TypeFormatImplSP &format_sp);
81
82   bool GetSummary(const ConstString &type, lldb::TypeSummaryImplSP &summary_sp);
83
84   bool GetSynthetic(const ConstString &type,
85                     lldb::SyntheticChildrenSP &synthetic_sp);
86
87   bool GetValidator(const ConstString &type,
88                     lldb::TypeValidatorImplSP &summary_sp);
89
90   void SetFormat(const ConstString &type, lldb::TypeFormatImplSP &format_sp);
91
92   void SetSummary(const ConstString &type, lldb::TypeSummaryImplSP &summary_sp);
93
94   void SetSynthetic(const ConstString &type,
95                     lldb::SyntheticChildrenSP &synthetic_sp);
96
97   void SetValidator(const ConstString &type,
98                     lldb::TypeValidatorImplSP &synthetic_sp);
99
100   void Clear();
101
102   uint64_t GetCacheHits() { return m_cache_hits; }
103
104   uint64_t GetCacheMisses() { return m_cache_misses; }
105 };
106 } // namespace lldb_private
107
108 #endif // lldb_FormatCache_h_