CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ctoken.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: C Token
4
5Author: Daniel Kroening, dkr@amazon.com
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_CRANGLER_CTOKEN_H
13#define CPROVER_CRANGLER_CTOKEN_H
14
15#include <iosfwd>
16#include <string>
17
19{
20public:
21 using kindt = enum {
23 INT_LIT,
31 WS,
35 };
36
38
39 // could be string_view, after C++17
40 std::string text;
41
42 std::size_t line_number = 0;
43
44 ctokent() = default;
45
46 ctokent(kindt _kind, std::string _text) : kind(_kind), text(std::move(_text))
47 {
48 }
49
50 void output(std::ostream &) const;
51
52 bool operator==(const char *other_text) const
53 {
54 return text == other_text;
55 }
56
57 bool operator==(char some_char) const
58 {
59 return text == std::string(1, some_char);
60 }
61
62 bool operator!=(char some_char) const
63 {
64 return text != std::string(1, some_char);
65 }
66};
67
68static inline bool is_identifier(const ctokent &t)
69{
70 return t.kind == ctokent::IDENTIFIER;
71}
72
73static inline bool is_separator(const ctokent &t)
74{
75 return t.kind == ctokent::SEPARATOR;
76}
77
78static inline bool is_operator(const ctokent &t)
79{
80 return t.kind == ctokent::OPERATOR;
81}
82
83static inline bool is_ws(const ctokent &t)
84{
85 return t.kind == ctokent::WS;
86}
87
88static inline bool is_eof(const ctokent &t)
89{
90 return t.kind == ctokent::END_OF_FILE;
91}
92
93static inline bool is_comment(const ctokent &t)
94{
95 return t.kind == ctokent::C_COMMENT || t.kind == ctokent::CPP_COMMENT;
96}
97
98static inline bool is_preprocessor_directive(const ctokent &t)
99{
100 return t.kind == ctokent::PREPROCESSOR_DIRECTIVE;
101}
102
103std::ostream &operator<<(std::ostream &, const ctokent &);
104
105#endif // CPROVER_CRANGLER_CTOKEN_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
std::size_t line_number
Definition ctoken.h:42
bool operator==(char some_char) const
Definition ctoken.h:57
void output(std::ostream &) const
Definition ctoken.cpp:16
bool operator!=(char some_char) const
Definition ctoken.h:62
ctokent()=default
bool operator==(const char *other_text) const
Definition ctoken.h:52
ctokent(kindt _kind, std::string _text)
Definition ctoken.h:46
kindt kind
Definition ctoken.h:37
std::string text
Definition ctoken.h:40
static bool is_identifier(const ctokent &t)
Definition ctoken.h:68
static bool is_operator(const ctokent &t)
Definition ctoken.h:78
std::ostream & operator<<(std::ostream &, const ctokent &)
Definition ctoken.cpp:64
static bool is_separator(const ctokent &t)
Definition ctoken.h:73
static bool is_comment(const ctokent &t)
Definition ctoken.h:93
static bool is_preprocessor_directive(const ctokent &t)
Definition ctoken.h:98
static bool is_ws(const ctokent &t)
Definition ctoken.h:83
static bool is_eof(const ctokent &t)
Definition ctoken.h:88
STL namespace.