CBMC
ctokenit.h
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 #ifndef CPROVER_CRANGLER_CTOKENIT_H
13 #define CPROVER_CRANGLER_CTOKENIT_H
14 
15 #include "cscanner.h"
16 
17 class ctokenitt
18 {
19 public:
20  using tokenst = std::vector<ctokent>;
21 
22  explicit ctokenitt(const tokenst &__tokens) : tokens(__tokens)
23  {
24  }
25 
26  explicit operator bool() const
27  {
28  return !eof();
29  }
30 
31  bool eof() const
32  {
33  return pos >= tokens.size();
34  }
35 
36  ctokenitt &operator+=(std::size_t offset)
37  {
38  pos += offset;
39  return *this;
40  }
41 
42  ctokenitt operator++(int); // postfix ++
43 
44  const ctokent &operator*() const;
45 
46  const ctokent *operator->() const
47  {
48  return &**this;
49  }
50 
51  tokenst::const_iterator cit() const
52  {
53  return tokens.begin() + pos;
54  }
55 
56  bool operator!=(const ctokenitt &other) const
57  {
58  return pos != other.pos;
59  }
60 
61 protected:
62  const tokenst &tokens;
63  std::size_t pos = 0;
64 };
65 
66 ctokenitt match_bracket(ctokenitt, char open, char close);
68 match_bracket(ctokenitt, char open, char close, ctokenitt::tokenst &dest);
69 
70 #endif // CPROVER_CRANGLER_CTOKENIT_H
ctokenitt::ctokenitt
ctokenitt(const tokenst &__tokens)
Definition: ctokenit.h:22
ctokenitt
Definition: ctokenit.h:17
cscanner.h
ctokenitt::operator++
ctokenitt operator++(int)
Definition: ctokenit.cpp:25
ctokenitt::operator!=
bool operator!=(const ctokenitt &other) const
Definition: ctokenit.h:56
ctokenitt::operator+=
ctokenitt & operator+=(std::size_t offset)
Definition: ctokenit.h:36
match_bracket
ctokenitt match_bracket(ctokenitt, char open, char close)
Definition: ctokenit.cpp:33
ctokent
Definition: ctoken.h:18
ctokenitt::operator->
const ctokent * operator->() const
Definition: ctokenit.h:46
ctokenitt::eof
bool eof() const
Definition: ctokenit.h:31
ctokenitt::operator*
const ctokent & operator*() const
Definition: ctokenit.cpp:19
ctokenitt::tokens
const tokenst & tokens
Definition: ctokenit.h:62
ctokenitt::cit
tokenst::const_iterator cit() const
Definition: ctokenit.h:51
ctokenitt::tokenst
std::vector< ctokent > tokenst
Definition: ctokenit.h:20
ctokenitt::pos
std::size_t pos
Definition: ctokenit.h:63