summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/Range.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2013-06-17 22:51:50 +0000
committerEnrico Granata <egranata@apple.com>2013-06-17 22:51:50 +0000
commit7594f14f7d685c0347d32aab9e10f19f1aabbc41 (patch)
tree4968fa055cec683086b3006bb66fb54c0170299a /lldb/source/Utility/Range.cpp
parent2dcbdc0606b5eeec43bf13c79f0116979b37c1f7 (diff)
downloadbcm5719-llvm-7594f14f7d685c0347d32aab9e10f19f1aabbc41.tar.gz
bcm5719-llvm-7594f14f7d685c0347d32aab9e10f19f1aabbc41.zip
<rdar://problem/14134716>
This is a rewrite of the command history facility of LLDB It takes the history management out of the CommandInterpreter into its own CommandHistory class It reimplements the command history command to allow more combinations of options to work correctly (e.g. com hist -c 1 -s 5) It adds a new --wipe (-w) option to command history to allow clearing the history on demand It extends the lldbtest runCmd: and expect: methods to allow adding commands to history if need be It adds a test case for the reimplemented facility llvm-svn: 184140
Diffstat (limited to 'lldb/source/Utility/Range.cpp')
-rw-r--r--lldb/source/Utility/Range.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/lldb/source/Utility/Range.cpp b/lldb/source/Utility/Range.cpp
new file mode 100644
index 00000000000..158d1e729d4
--- /dev/null
+++ b/lldb/source/Utility/Range.cpp
@@ -0,0 +1,103 @@
+//===--------------------- Range.cpp -----------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Utility/Range.h"
+
+using namespace lldb_utility;
+
+Range::Range (const Range& rng) :
+m_low(rng.m_low),
+m_high(rng.m_high)
+{
+ InitRange();
+}
+
+Range::Range (Range::ValueType low,
+ Range::ValueType high) :
+m_low(low),
+m_high(high)
+{
+ InitRange();
+}
+
+void
+Range::InitRange ()
+{
+ if (m_low == OPEN_END)
+ {
+ if (m_high == OPEN_END)
+ m_low = 0;
+ else
+ {
+ // make an empty range
+ m_low = 1;
+ m_high = 0;
+ }
+ }
+}
+
+Range&
+Range::operator = (const Range& rhs)
+{
+ if (&rhs != this)
+ {
+ this->m_low = rhs.m_low;
+ this->m_high = rhs.m_high;
+ }
+ return *this;
+}
+
+void
+Range::Flip ()
+{
+ std::swap(m_high, m_low);
+}
+
+void
+Range::Intersection (const Range& other)
+{
+ m_low = std::max(m_low,other.m_low);
+ m_high = std::min(m_high,other.m_high);
+}
+
+void
+Range::Union (const Range& other)
+{
+ m_low = std::min(m_low,other.m_low);
+ m_high = std::max(m_high,other.m_high);
+}
+
+void
+Range::Iterate (RangeCallback callback)
+{
+ ValueType counter = m_low;
+ while (counter <= m_high)
+ {
+ bool should_continue = callback(counter);
+ if (!should_continue)
+ return;
+ counter++;
+ }
+}
+
+bool
+Range::IsEmpty ()
+{
+ return (m_low > m_high);
+}
+
+Range::ValueType
+Range::GetSize ()
+{
+ if (m_high == OPEN_END)
+ return OPEN_END;
+ if (m_high >= m_low)
+ return m_high - m_low + 1;
+ return 0;
+}
OpenPOWER on IntegriCloud