src
input_api.cc
Go to the documentation of this file.
1 #include <sstream>
2 
4 #include "src/codegen/indent.h"
5 #include "src/conf/opt.h"
6 #include "src/globals.h"
7 
8 namespace re2c
9 {
10 
12  : type_ (DEFAULT)
13 {}
14 
16 {
17  return type_;
18 }
19 
21 {
22  type_ = t;
23 }
24 
25 std::string InputAPI::expr_peek () const
26 {
27  std::string s;
28  switch (type_)
29  {
30  case DEFAULT:
31  s = "*" + opts->yycursor;
32  break;
33  case CUSTOM:
34  s = opts->yypeek + " ()";
35  break;
36  }
37  return s;
38 }
39 
40 std::string InputAPI::expr_peek_save () const
41 {
42  return opts->yych + " = " + opts.yychConversion () + expr_peek ();
43 }
44 
45 std::string InputAPI::stmt_peek (uint32_t ind) const
46 {
47  return indent (ind) + expr_peek_save () + ";\n";
48 }
49 
50 std::string InputAPI::stmt_skip (uint32_t ind) const
51 {
52  std::string s;
53  switch (type_)
54  {
55  case DEFAULT:
56  s = "++" + opts->yycursor;
57  break;
58  case CUSTOM:
59  s = opts->yyskip + " ()";
60  break;
61  }
62  return indent (ind) + s + ";\n";
63 }
64 
65 std::string InputAPI::stmt_backup (uint32_t ind) const
66 {
67  std::string s;
68  switch (type_)
69  {
70  case DEFAULT:
71  s = opts->yymarker + " = " + opts->yycursor;
72  break;
73  case CUSTOM:
74  s = opts->yybackup + " ()";
75  break;
76  }
77  return indent (ind) + s + ";\n";
78 }
79 
80 std::string InputAPI::stmt_backupctx (uint32_t ind) const
81 {
82  std::string s;
83  switch (type_)
84  {
85  case DEFAULT:
86  s = opts->yyctxmarker + " = " + opts->yycursor;
87  break;
88  case CUSTOM:
89  s = opts->yybackupctx + " ()";
90  break;
91  }
92  return indent (ind) + s + ";\n";
93 }
94 
95 std::string InputAPI::stmt_restore (uint32_t ind) const
96 {
97  std::string s;
98  switch (type_)
99  {
100  case DEFAULT:
101  s = opts->yycursor + " = " + opts->yymarker;
102  break;
103  case CUSTOM:
104  s = opts->yyrestore + " ()";
105  break;
106  }
107  return indent (ind) + s + ";\n";
108 }
109 
110 std::string InputAPI::stmt_restorectx (uint32_t ind) const
111 {
112  std::string s;
113  switch (type_)
114  {
115  case DEFAULT:
116  s = indent (ind) + opts->yycursor + " = " + opts->yyctxmarker + ";\n";
117  break;
118  case CUSTOM:
119  s = indent (ind) + opts->yyrestorectx + " ();\n";
120  break;
121  }
122  return s;
123 }
124 
125 std::string InputAPI::stmt_skip_peek (uint32_t ind) const
126 {
127  return type_ == DEFAULT
128  ? indent (ind) + opts->yych + " = " + opts.yychConversion () + "*++" + opts->yycursor + ";\n"
129  : stmt_skip (ind) + stmt_peek (ind);
130 }
131 
132 std::string InputAPI::stmt_skip_backup (uint32_t ind) const
133 {
134  return type_ == DEFAULT
135  ? indent (ind) + opts->yymarker + " = ++" + opts->yycursor + ";\n"
136  : stmt_skip (ind) + stmt_backup (ind);
137 }
138 
139 std::string InputAPI::stmt_backup_peek (uint32_t ind) const
140 {
141  return type_ == DEFAULT
142  ? indent (ind) + opts->yych + " = " + opts.yychConversion () + "*(" + opts->yymarker + " = " + opts->yycursor + ");\n"
143  : stmt_backup (ind) + stmt_peek (ind);
144 }
145 
146 std::string InputAPI::stmt_skip_backup_peek (uint32_t ind) const
147 {
148  return type_ == DEFAULT
149  ? indent (ind) + opts->yych + " = " + opts.yychConversion () + "*(" + opts->yymarker + " = ++" + opts->yycursor + ");\n"
150  : stmt_skip (ind) + stmt_backup (ind) + stmt_peek (ind);
151 }
152 
153 std::string InputAPI::expr_lessthan_one () const
154 {
155  return type_ == DEFAULT
156  ? opts->yylimit + " <= " + opts->yycursor
157  : expr_lessthan (1);
158 }
159 
160 std::string InputAPI::expr_lessthan (size_t n) const
161 {
162  std::ostringstream s;
163  switch (type_)
164  {
165  case DEFAULT:
166  s << "(" << opts->yylimit << " - " << opts->yycursor << ") < " << n;
167  break;
168  case CUSTOM:
169  s << opts->yylessthan << " (" << n << ")";
170  break;
171  }
172  return s.str ();
173 }
174 
175 } // end namespace re2c
std::string yyrestore
Definition: opt.h:118
std::string expr_peek() const
Definition: input_api.cc:25
std::string indent(uint32_t ind)
Definition: indent.h:11
std::string stmt_restorectx(uint32_t ind) const
Definition: input_api.cc:110
std::string yyskip
Definition: opt.h:118
std::string yylimit
Definition: opt.h:118
std::string yych
Definition: opt.h:118
std::string stmt_skip_backup(uint32_t ind) const
Definition: input_api.cc:132
std::string yybackup
Definition: opt.h:118
std::string expr_peek_save() const
Definition: input_api.cc:40
std::string stmt_restore(uint32_t ind) const
Definition: input_api.cc:95
std::string yycursor
Definition: opt.h:118
std::string expr_lessthan_one() const
Definition: input_api.cc:153
std::string yylessthan
Definition: opt.h:118
std::string stmt_backup_peek(uint32_t ind) const
Definition: input_api.cc:139
std::string yychConversion()
Definition: opt.h:193
std::string yypeek
Definition: opt.h:118
void set(type_t t)
Definition: input_api.cc:20
std::string stmt_skip(uint32_t ind) const
Definition: input_api.cc:50
std::string stmt_skip_peek(uint32_t ind) const
Definition: input_api.cc:125
std::string yybackupctx
Definition: opt.h:118
std::string stmt_backupctx(uint32_t ind) const
Definition: input_api.cc:80
std::string stmt_backup(uint32_t ind) const
Definition: input_api.cc:65
Opt opts
Definition: opt.cc:7
type_t type() const
Definition: input_api.cc:15
std::string yyrestorectx
Definition: opt.h:118
std::string stmt_peek(uint32_t ind) const
Definition: input_api.cc:45
std::string yyctxmarker
Definition: opt.h:118
std::string yymarker
Definition: opt.h:118
std::string expr_lessthan(size_t n) const
Definition: input_api.cc:160
Definition: bitmap.cc:10
std::string stmt_skip_backup_peek(uint32_t ind) const
Definition: input_api.cc:146