-
Notifications
You must be signed in to change notification settings - Fork 2
/
pp_tokens_range.hh
70 lines (58 loc) · 1.8 KB
/
pp_tokens_range.hh
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
/*
* Copyright (C) 2019 SUSE Software Solutions Germany GmbH
*
* This file is part of klp-ccp.
*
* klp-ccp is free software: you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* klp-ccp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with klp-ccp. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PP_TOKENS_RANGE_HH
#define PP_TOKENS_RANGE_HH
#include <limits>
#include <cassert>
#ifdef DEBUG_PARSER
#include <iostream>
#endif
namespace klp
{
namespace ccp
{
typedef std::size_t pp_token_index;
struct pp_tokens_range
{
pp_tokens_range() noexcept
: begin(std::numeric_limits<pp_token_index>::max()),
end(0)
{}
pp_tokens_range(const pp_token_index _begin,
const pp_token_index _end) noexcept
: begin(_begin), end(_end)
{
assert(begin <= end);
}
bool operator==(const pp_tokens_range &op) const noexcept
{ return (this->begin == op.begin && this->end == op.end); }
bool operator!=(const pp_tokens_range &op) const noexcept
{ return !(*this == op); }
bool operator<(const pp_tokens_range &op) const noexcept
{ return this->end <= op.begin; }
bool is_contained_in(const pp_tokens_range &r) const noexcept
{ return this->begin >= r.begin && this->end <= r.end; }
pp_token_index begin;
pp_token_index end;
};
#ifdef DEBUG_PARSER
std::ostream& operator<<(std::ostream &o, const pp_tokens_range &r);
#endif
}
}
#endif