]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Utility/Range.cpp
MFV r323792: 8602 remove unused "dp_early_sync_tasks" field from "dsl_pool" structure
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Utility / Range.cpp
1 //===--------------------- Range.cpp -----------------------------*- 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 #include "lldb/Utility/Range.h"
11
12 #include <algorithm>
13 #include <utility>
14
15 using namespace lldb_utility;
16
17 Range::Range(const Range &rng) : m_low(rng.m_low), m_high(rng.m_high) {
18   InitRange();
19 }
20
21 Range::Range(Range::ValueType low, Range::ValueType high)
22     : m_low(low), m_high(high) {
23   InitRange();
24 }
25
26 void Range::InitRange() {
27   if (m_low == OPEN_END) {
28     if (m_high == OPEN_END)
29       m_low = 0;
30     else {
31       // make an empty range
32       m_low = 1;
33       m_high = 0;
34     }
35   }
36 }
37
38 Range &Range::operator=(const Range &rhs) {
39   if (&rhs != this) {
40     this->m_low = rhs.m_low;
41     this->m_high = rhs.m_high;
42   }
43   return *this;
44 }
45
46 void Range::Flip() { std::swap(m_high, m_low); }
47
48 void Range::Intersection(const Range &other) {
49   m_low = std::max(m_low, other.m_low);
50   m_high = std::min(m_high, other.m_high);
51 }
52
53 void Range::Union(const Range &other) {
54   m_low = std::min(m_low, other.m_low);
55   m_high = std::max(m_high, other.m_high);
56 }
57
58 void Range::Iterate(RangeCallback callback) {
59   ValueType counter = m_low;
60   while (counter <= m_high) {
61     bool should_continue = callback(counter);
62     if (!should_continue)
63       return;
64     counter++;
65   }
66 }
67
68 bool Range::IsEmpty() { return (m_low > m_high); }
69
70 Range::ValueType Range::GetSize() {
71   if (m_high == OPEN_END)
72     return OPEN_END;
73   if (m_high >= m_low)
74     return m_high - m_low + 1;
75   return 0;
76 }