]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/History.h
MFV r319744,r319745: 8269 dtrace stddev aggregation is normalized incorrectly
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / History.h
1 //===-- History.h -----------------------------------------------*- 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 #ifndef lldb_History_h_
11 #define lldb_History_h_
12
13 // C Includes
14 #include <stdint.h>
15
16 // C++ Includes
17 #include <mutex>
18 #include <stack>
19 #include <string>
20
21 // Other libraries and framework includes
22 // Project includes
23 #include "lldb/lldb-public.h"
24
25 namespace lldb_private {
26
27 //----------------------------------------------------------------------
28 /// @class HistorySource History.h "lldb/Core/History.h"
29 /// @brief A class that defines history events.
30 //----------------------------------------------------------------------
31
32 class HistorySource {
33 public:
34   typedef const void *HistoryEvent;
35
36   HistorySource() : m_mutex(), m_events() {}
37
38   virtual ~HistorySource() {}
39
40   // Create a new history event. Subclasses should use any data or members
41   // in the subclass of this class to produce a history event and push it
42   // onto the end of the history stack.
43
44   virtual HistoryEvent CreateHistoryEvent() = 0;
45
46   virtual void DeleteHistoryEvent(HistoryEvent event) = 0;
47
48   virtual void DumpHistoryEvent(Stream &strm, HistoryEvent event) = 0;
49
50   virtual size_t GetHistoryEventCount() = 0;
51
52   virtual HistoryEvent GetHistoryEventAtIndex(uint32_t idx) = 0;
53
54   virtual HistoryEvent GetCurrentHistoryEvent() = 0;
55
56   // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
57   virtual int CompareHistoryEvents(const HistoryEvent lhs,
58                                    const HistoryEvent rhs) = 0;
59
60   virtual bool IsCurrentHistoryEvent(const HistoryEvent event) = 0;
61
62 private:
63   typedef std::stack<HistoryEvent> collection;
64
65   std::recursive_mutex m_mutex;
66   collection m_events;
67
68   DISALLOW_COPY_AND_ASSIGN(HistorySource);
69 };
70
71 //----------------------------------------------------------------------
72 /// @class HistorySourceUInt History.h "lldb/Core/History.h"
73 /// @brief A class that defines history events that are represented by
74 /// unsigned integers.
75 ///
76 /// Any history event that is defined by a unique monotonically
77 /// increasing unsigned integer
78 //----------------------------------------------------------------------
79
80 class HistorySourceUInt : public HistorySource {
81   HistorySourceUInt(const char *id_name, uintptr_t start_value = 0u)
82       : HistorySource(), m_name(id_name), m_curr_id(start_value) {}
83
84   ~HistorySourceUInt() override {}
85
86   // Create a new history event. Subclasses should use any data or members
87   // in the subclass of this class to produce a history event and push it
88   // onto the end of the history stack.
89
90   HistoryEvent CreateHistoryEvent() override {
91     ++m_curr_id;
92     return (HistoryEvent)m_curr_id;
93   }
94
95   void DeleteHistoryEvent(HistoryEvent event) override {
96     // Nothing to delete, the event contains the integer
97   }
98
99   void DumpHistoryEvent(Stream &strm, HistoryEvent event) override;
100
101   size_t GetHistoryEventCount() override { return m_curr_id; }
102
103   HistoryEvent GetHistoryEventAtIndex(uint32_t idx) override {
104     return (HistoryEvent)((uintptr_t)idx);
105   }
106
107   HistoryEvent GetCurrentHistoryEvent() override {
108     return (HistoryEvent)m_curr_id;
109   }
110
111   // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
112   int CompareHistoryEvents(const HistoryEvent lhs,
113                            const HistoryEvent rhs) override {
114     uintptr_t lhs_uint = (uintptr_t)lhs;
115     uintptr_t rhs_uint = (uintptr_t)rhs;
116     if (lhs_uint < rhs_uint)
117       return -1;
118     if (lhs_uint > rhs_uint)
119       return +1;
120     return 0;
121   }
122
123   bool IsCurrentHistoryEvent(const HistoryEvent event) override {
124     return (uintptr_t)event == m_curr_id;
125   }
126
127 protected:
128   std::string m_name;  // The name of the history unsigned integer
129   uintptr_t m_curr_id; // The current value of the history unsigned unteger
130 };
131
132 } // namespace lldb_private
133
134 #endif // lldb_History_h_