src
opt.h
Go to the documentation of this file.
1 #ifndef _RE2C_CONF_OPT_
2 #define _RE2C_CONF_OPT_
3 
4 #include "src/util/c99_stdint.h"
5 #include <stddef.h>
6 #include <string>
7 
9 #include "src/ir/dfa/dfa.h"
12 #include "src/util/forbid_copy.h"
13 
14 namespace re2c
15 {
16 
17 #define RE2C_OPTS \
18  /* target */ \
19  OPT1 (opt_t::target_t, target, CODE) \
20  /* fingerprint */ \
21  OPT (bool, bNoGenerationDate, false) \
22  OPT (bool, version, true) \
23  /* regular expressions */ \
24  OPT (Enc, encoding, Enc ()) \
25  OPT (bool, bCaseInsensitive, false) \
26  OPT (bool, bCaseInverted, false) \
27  OPT (empty_class_policy_t, empty_class_policy, EMPTY_CLASS_MATCH_EMPTY) \
28  /* conditions */ \
29  OPT (bool, cFlag, false) \
30  OPT (bool, tFlag, false) \
31  OPT (const char *, header_file, NULL) \
32  OPT (std::string, yycondtype, "YYCONDTYPE") \
33  OPT (std::string, cond_get, "YYGETCONDITION") \
34  OPT (bool, cond_get_naked, false) \
35  OPT (std::string, cond_set, "YYSETCONDITION" ) \
36  OPT (std::string, cond_set_arg, "@@" ) \
37  OPT (bool, cond_set_naked, false ) \
38  OPT (std::string, yyctable, "yyctable") \
39  OPT (std::string, condPrefix, "yyc_") \
40  OPT (std::string, condEnumPrefix, "yyc") \
41  OPT (std::string, condDivider, "/* *********************************** */") \
42  OPT (std::string, condDividerParam, "@@") \
43  OPT (std::string, condGoto, "goto @@;") \
44  OPT (std::string, condGotoParam, "@@") \
45  /* states */ \
46  OPT (bool, fFlag, false) \
47  OPT (std::string, state_get, "YYGETSTATE") \
48  OPT (bool, state_get_naked, false) \
49  OPT (std::string, state_set, "YYSETSTATE") \
50  OPT (std::string, state_set_arg, "@@") \
51  OPT (bool, state_set_naked, false) \
52  OPT (std::string, yyfilllabel, "yyFillLabel") \
53  OPT (std::string, yynext, "yyNext") \
54  OPT (std::string, yyaccept, "yyaccept") \
55  OPT (bool, bUseStateAbort, false) \
56  OPT (bool, bUseStateNext, false) \
57  /* reuse */ \
58  OPT (bool, rFlag, false) \
59  /* partial flex syntax support */ \
60  OPT (bool, FFlag, false) \
61  /* code generation */ \
62  OPT (bool, sFlag, false) \
63  OPT (bool, bFlag, false) \
64  OPT (std::string, yybm, "yybm") \
65  OPT (bool, yybmHexTable, false) \
66  OPT (bool, gFlag, false) \
67  OPT (std::string, yytarget, "yytarget") \
68  OPT (uint32_t, cGotoThreshold, 9) \
69  /* formatting */ \
70  OPT (uint32_t, topIndent, 0) \
71  OPT (std::string, indString, "\t") \
72  /* input API */ \
73  OPT (InputAPI, input_api, InputAPI ()) \
74  OPT (std::string, yycursor, "YYCURSOR") \
75  OPT (std::string, yymarker, "YYMARKER") \
76  OPT (std::string, yyctxmarker, "YYCTXMARKER") \
77  OPT (std::string, yylimit, "YYLIMIT") \
78  OPT (std::string, yypeek, "YYPEEK") \
79  OPT (std::string, yyskip, "YYSKIP") \
80  OPT (std::string, yybackup, "YYBACKUP") \
81  OPT (std::string, yybackupctx, "YYBACKUPCTX") \
82  OPT (std::string, yyrestore, "YYRESTORE") \
83  OPT (std::string, yyrestorectx, "YYRESTORECTX") \
84  OPT (std::string, yylessthan, "YYLESSTHAN") \
85  /* #line directives */ \
86  OPT (bool, iFlag, false) \
87  /* debug */ \
88  OPT (bool, dFlag, false) \
89  OPT (std::string, yydebug, "YYDEBUG") \
90  /* yych */ \
91  OPT (std::string, yyctype, "YYCTYPE") \
92  OPT (std::string, yych, "yych") \
93  OPT (bool, bEmitYYCh, true) \
94  OPT (bool, yychConversion, false) \
95  /* YYFILL */ \
96  OPT (std::string, fill, "YYFILL") \
97  OPT (bool, fill_use, true) \
98  OPT (bool, fill_check, true) \
99  OPT (std::string, fill_arg, "@@") \
100  OPT (bool, fill_arg_use, true) \
101  OPT (bool, fill_naked, false) \
102  /* labels */ \
103  OPT (std::string, labelPrefix, "yy") \
104  /* internals */ \
105  OPT (dfa_minimization_t, dfa_minimization, DFA_MINIMIZATION_MOORE)
106 
107 struct opt_t
108 {
109  enum target_t
110  {
114  };
115 
116 #define OPT1 OPT
117 #define OPT(type, name, value) type name;
119 #undef OPT1
120 #undef OPT
121 
122  opt_t ();
123  opt_t (const opt_t & opt);
124  opt_t & operator = (const opt_t & opt);
125  void fix ();
126 };
127 
128 class useropt_t;
130 {
131  opt_t real;
132  useropt_t & user;
133 public:
134  realopt_t (useropt_t & opt);
135  const opt_t * operator -> ();
136  void sync ();
137 };
138 
140 {
141  opt_t opt;
142  bool diverge;
143 public:
144  useropt_t ();
145  opt_t * operator -> ();
146  friend void realopt_t::sync ();
147 };
148 
149 struct Opt
150 {
151  static const opt_t baseopt;
152 
153  const char * source_file;
154  const char * output_file;
155 
156 private:
157  useropt_t useropt;
158  realopt_t realopt;
159 
160 public:
161  Opt ()
162  : source_file (NULL)
163  , output_file (NULL)
164  , useropt ()
165  , realopt (useropt)
166  {}
167 
168  // read-only access, forces options syncronization
169  const opt_t * operator -> ()
170  {
171  return realopt.operator -> ();
172  }
173 
174  bool source (const char * s);
175  bool output (const char * s);
176 
177  // Inplace configurations are applied immediately when parsed.
178  // This is very bad: first, re2c behaviour is changed in the middle
179  // of the block; second, config is resynced too often (every
180  // attempt to read config that has been updated results in
181  // automatic resync). It is much better to set all options at once.
182  bool set_encoding (Enc::type_t t) { return useropt->encoding.set (t); }
183  void unset_encoding (Enc::type_t t) { useropt->encoding.unset (t); }
185  void set_input_api (InputAPI::type_t t) { useropt->input_api.set (t); }
186 #define OPT1 OPT
187 #define OPT(type, name, value) void set_##name (type arg) { useropt->name = arg; }
189 #undef OPT1
190 #undef OPT
191 
192  // helpers
193  std::string yychConversion ()
194  {
195  return realopt->yychConversion
196  ? "(" + realopt->yyctype + ")"
197  : "";
198  }
199 
200  // bad temporary hacks, should be fixed by proper scoping of config (parts).
201  void reset_encoding (const Enc & enc);
202  void reset_mapCodeName ();
203 
204  FORBID_COPY (Opt);
205 };
206 
208 {
209  OK,
212 };
213 
214 parse_opts_t parse_opts (char ** argv, Opt & opts);
215 
216 } // namespace re2c
217 
218 #endif // _RE2C_CONF_OPT_
Opt()
Definition: opt.h:161
void unset(type_t)
Definition: enc.h:179
void unset_encoding(Enc::type_t t)
Definition: opt.h:183
parse_opts_t
Definition: opt.h:207
void sync()
Definition: opt.cc:243
bool source(const char *s)
Definition: opt.cc:266
bool set(type_t t)
Definition: enc.h:166
static const opt_t baseopt
Definition: opt.h:151
const char * output_file
Definition: opt.h:154
InputAPI input_api
Definition: opt.h:118
FORBID_COPY(Opt)
void reset_mapCodeName()
Definition: opt.cc:299
std::string yychConversion()
Definition: opt.h:193
Definition: opt.h:149
void reset_encoding(const Enc &enc)
Definition: opt.cc:294
opt_t()
Definition: opt.cc:9
Definition: enc.h:38
bool set_encoding(Enc::type_t t)
Definition: opt.h:182
Enc encoding
Definition: opt.h:118
policy_t
Definition: enc.h:52
void set(type_t t)
Definition: input_api.cc:20
#define RE2C_OPTS
Definition: opt.h:17
void set_encoding_policy(Enc::policy_t p)
Definition: opt.h:184
Definition: opt.h:209
target_t
Definition: opt.h:109
bool yychConversion
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
void set_input_api(InputAPI::type_t t)
Definition: opt.h:185
const opt_t * operator->()
Definition: opt.h:169
bool output(const char *s)
Definition: opt.cc:280
realopt_t(useropt_t &opt)
Definition: opt.cc:232
const opt_t * operator->()
Definition: opt.cc:237
opt_t & operator=(const opt_t &opt)
Definition: opt.cc:25
void setPolicy(policy_t t)
Definition: enc.h:190
Definition: bitmap.cc:10
type_t
Definition: enc.h:42
opt_t * operator->()
Definition: opt.cc:258
void fix()
Definition: opt.cc:35
parse_opts_t parse_opts(char **argv, Opt &opts)
std::string yyctype
Definition: opt.h:118
const char * source_file
Definition: opt.h:153