cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
ctokenit.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: C Token Iterator
4
5
Author: Daniel Kroening, dkr@amazon.com
6
7
\*******************************************************************/
8
11
12
#include "
ctokenit.h
"
13
14
#include <
util/exception_utils.h
>
15
#include <
util/invariant.h
>
16
17
#include <algorithm>
18
19
const
ctokent
&
ctokenitt::operator*
()
const
20
{
21
PRECONDITION
(!
eof
());
22
return
tokens
[
pos
];
23
}
24
25
ctokenitt
ctokenitt::operator++
(
int
)
// NOLINT(*)
26
{
27
PRECONDITION
(!
eof
());
28
auto
pre_increment = *
this
;
// copy
29
pos
++;
30
return
pre_increment;
31
}
32
33
ctokenitt
match_bracket
(
ctokenitt
t,
char
open,
char
close)
34
{
35
if
(!t)
36
return
t;
37
38
// skip whitespace, if any
39
while
(t && (
is_ws
(*t) ||
is_comment
(*t) ||
is_preprocessor_directive
(*t)))
40
t++;
41
42
if
(*t != open)
43
return
t;
44
45
std::size_t bracket_count = 0;
46
while
(
true
)
47
{
48
if
(!t)
49
throw
invalid_input_exceptiont
(
"expected "
+ std::string(1, close));
50
51
const
auto
&token = *(t++);
52
53
if
(token == open)
54
bracket_count++;
55
else
if
(token == close)
56
{
57
bracket_count--;
58
if
(bracket_count == 0)
59
return
t;
// done
60
}
61
}
62
}
63
64
ctokenitt
65
match_bracket
(
ctokenitt
t,
char
open,
char
close,
ctokenitt::tokenst
&dest)
66
{
67
auto
end =
match_bracket
(t, open, close);
68
std::copy(t.
cit
(), end.cit(), dest.end());
69
return
end;
70
}
ctokenitt
Definition
ctokenit.h:20
ctokenitt::cit
tokenst::const_iterator cit() const
Definition
ctokenit.h:53
ctokenitt::pos
std::size_t pos
Definition
ctokenit.h:65
ctokenitt::eof
bool eof() const
Definition
ctokenit.h:33
ctokenitt::operator++
ctokenitt operator++(int)
Definition
ctokenit.cpp:25
ctokenitt::operator*
const ctokent & operator*() const
Definition
ctokenit.cpp:19
ctokenitt::tokenst
std::vector< ctokent > tokenst
Definition
ctokenit.h:22
ctokenitt::tokens
const tokenst & tokens
Definition
ctokenit.h:64
ctokenitt::ctokenitt
ctokenitt(const tokenst &__tokens)
Definition
ctokenit.h:24
ctokent
Definition
ctoken.h:19
invalid_input_exceptiont
Thrown when user-provided input cannot be processed.
Definition
exception_utils.h:163
is_comment
static bool is_comment(const ctokent &t)
Definition
ctoken.h:93
is_preprocessor_directive
static bool is_preprocessor_directive(const ctokent &t)
Definition
ctoken.h:98
is_ws
static bool is_ws(const ctokent &t)
Definition
ctoken.h:83
match_bracket
ctokenitt match_bracket(ctokenitt t, char open, char close)
Definition
ctokenit.cpp:33
ctokenit.h
ctokenit
exception_utils.h
invariant.h
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
crangler
ctokenit.cpp
Generated by
1.17.0