src
opt.cc
Go to the documentation of this file.
1 #include "src/conf/msg.h"
2 #include "src/conf/opt.h"
3 
4 namespace re2c
5 {
6 
8 
10 #define OPT1(type, name, value) : name (value)
11 #define OPT(type, name, value) , name (value)
12  RE2C_OPTS
13 #undef OPT1
14 #undef OPT
15 {}
16 
17 opt_t::opt_t (const opt_t & opt)
18 #define OPT1(type, name, value) : name (opt.name)
19 #define OPT(type, name, value) , name (opt.name)
20  RE2C_OPTS
21 #undef OPT1
22 #undef OPT
23 {}
24 
26 {
27 #define OPT1 OPT
28 #define OPT(type, name, value) name = opt.name;
29  RE2C_OPTS
30 #undef OPT1
31 #undef OPT
32  return *this;
33 }
34 
35 void opt_t::fix ()
36 {
37  // some options either make no sense or must have fixed value
38  // with current target: reset them to default
39  switch (target)
40  {
41  case DOT:
42  // default code generation options
47  // default environment-insensitive formatting
49  // fallthrough
50  case SKELETON:
51  // default line information
53  // default environment-sensitive formatting
58  // default environment bindings
110  break;
111  default:
112  break;
113  }
114 
115  if (bCaseInsensitive)
116  {
118  }
119 
120  // respect hierarchy
121  if (!cFlag)
122  {
138  }
139  if (!fFlag)
140  {
151  }
152  if (!bFlag)
153  {
156  }
157  if (!gFlag)
158  {
161  }
162  if (input_api.type () != InputAPI::DEFAULT)
163  {
168  }
169  if (input_api.type () != InputAPI::CUSTOM)
170  {
178  }
179  if (!dFlag)
180  {
182  }
183  if (!fill_use)
184  {
190  }
191 
192  // force individual options
193  switch (target)
194  {
195  case DOT:
196  iFlag = true;
197  break;
198  case SKELETON:
199  iFlag = true;
201  indString = " ";
202  topIndent = 2;
203  break;
204  default:
205  break;
206  }
207  switch (encoding.type ())
208  {
209  case Enc::UCS2:
210  case Enc::UTF16:
211  case Enc::UTF32:
212  sFlag = true;
213  break;
214  default:
215  break;
216  }
217  if (bFlag)
218  {
219  sFlag = true;
220  }
221  if (gFlag)
222  {
223  bFlag = true;
224  sFlag = true;
225  }
226  if (header_file != NULL)
227  {
228  tFlag = true;
229  }
230 }
231 
233  : real ()
234  , user (opt)
235 {}
236 
238 {
239  sync ();
240  return ℜ
241 }
242 
244 {
245  if (user.diverge)
246  {
247  real = user.opt;
248  real.fix ();
249  user.diverge = false;
250  }
251 }
252 
254  : opt ()
255  , diverge (true)
256 {}
257 
259 {
260  diverge = true;
261  return &opt;
262 }
263 
264 const opt_t Opt::baseopt;
265 
266 bool Opt::source (const char * s)
267 {
268  if (source_file)
269  {
270  error ("multiple source files: %s, %s", source_file, s);
271  return false;
272  }
273  else
274  {
275  source_file = s;
276  return true;
277  }
278 }
279 
280 bool Opt::output (const char * s)
281 {
282  if (output_file)
283  {
284  error ("multiple output files: %s, %s", output_file, s);
285  return false;
286  }
287  else
288  {
289  output_file = s;
290  return true;
291  }
292 }
293 
294 void Opt::reset_encoding (const Enc & enc)
295 {
296  useropt->encoding = enc;
297 }
298 
300 {
301  // historically arranged set of names
302  // no actual reason why these particular options should be reset
303  useropt->cond_get = Opt::baseopt.cond_get;
304  useropt->cond_set = Opt::baseopt.cond_set;
305  useropt->fill = Opt::baseopt.fill;
306  useropt->state_get = Opt::baseopt.state_get;
307  useropt->state_set = Opt::baseopt.state_set;
308  useropt->yybackup = Opt::baseopt.yybackup;
309  useropt->yybackupctx = Opt::baseopt.yybackupctx;
310  useropt->yycondtype = Opt::baseopt.yycondtype;
311  useropt->yyctxmarker = Opt::baseopt.yyctxmarker;
312  useropt->yyctype = Opt::baseopt.yyctype;
313  useropt->yycursor = Opt::baseopt.yycursor;
314  useropt->yydebug = Opt::baseopt.yydebug;
315  useropt->yylessthan = Opt::baseopt.yylessthan;
316  useropt->yylimit = Opt::baseopt.yylimit;
317  useropt->yymarker = Opt::baseopt.yymarker;
318  useropt->yypeek = Opt::baseopt.yypeek;
319  useropt->yyrestore = Opt::baseopt.yyrestore;
320  useropt->yyrestorectx = Opt::baseopt.yyrestorectx;
321  useropt->yyskip = Opt::baseopt.yyskip;
322  useropt->yyfilllabel = Opt::baseopt.yyfilllabel;
323  useropt->yynext = Opt::baseopt.yynext;
324  useropt->yyaccept = Opt::baseopt.yyaccept;
325  useropt->yybm = Opt::baseopt.yybm;
326  useropt->yych = Opt::baseopt.yych;
327  useropt->yyctable = Opt::baseopt.yyctable;
328  useropt->yytarget = Opt::baseopt.yytarget;
329 }
330 
331 } // namespace re2c
bool bFlag
Definition: opt.h:118
bool tFlag
Definition: opt.h:118
void sync()
Definition: opt.cc:243
std::string indString
Definition: opt.h:118
std::string yyrestore
Definition: opt.h:118
bool source(const char *s)
Definition: opt.cc:266
void error(const char *fmt,...)
Definition: msg.cc:10
static const opt_t baseopt
Definition: opt.h:151
std::string condPrefix
Definition: opt.h:118
bool cond_set_naked
Definition: opt.h:118
const char * output_file
Definition: opt.h:154
std::string yytarget
Definition: opt.h:118
std::string yycondtype
Definition: opt.h:118
type_t type() const
Definition: enc.h:185
bool state_get_naked
Definition: opt.h:118
bool bCaseInsensitive
Definition: opt.h:118
std::string yyskip
Definition: opt.h:118
std::string cond_get
Definition: opt.h:118
InputAPI input_api
Definition: opt.h:118
bool fill_naked
Definition: opt.h:118
std::string yylimit
Definition: opt.h:118
std::string yych
Definition: opt.h:118
std::string condDivider
Definition: opt.h:118
std::string yybm
Definition: opt.h:118
std::string yybackup
Definition: opt.h:118
void reset_mapCodeName()
Definition: opt.cc:299
std::string yycursor
Definition: opt.h:118
const char * header_file
Definition: opt.h:118
bool cFlag
Definition: opt.h:118
bool bUseStateNext
Definition: opt.h:118
std::string yylessthan
Definition: opt.h:118
std::string yynext
Definition: opt.h:118
std::string yypeek
Definition: opt.h:118
Definition: opt.h:149
bool sFlag
Definition: opt.h:118
bool dFlag
Definition: opt.h:118
void reset_encoding(const Enc &enc)
Definition: opt.cc:294
uint32_t topIndent
Definition: opt.h:118
std::string condEnumPrefix
Definition: opt.h:118
opt_t()
Definition: opt.cc:9
bool bUseStateAbort
Definition: opt.h:118
bool iFlag
Definition: opt.h:118
std::string cond_set
Definition: opt.h:118
bool cond_get_naked
Definition: opt.h:118
uint32_t cGotoThreshold
Definition: opt.h:118
opt_t::target_t target
Definition: opt.h:118
Definition: enc.h:38
bool fill_use
Definition: opt.h:118
bool gFlag
Definition: opt.h:118
std::string yyctable
Definition: opt.h:118
std::string state_set
Definition: opt.h:118
Enc encoding
Definition: opt.h:118
void set(type_t t)
Definition: input_api.cc:20
#define RE2C_OPTS
Definition: opt.h:17
std::string fill_arg
Definition: opt.h:118
std::string yyaccept
Definition: opt.h:118
std::string labelPrefix
Definition: opt.h:118
std::string yybackupctx
Definition: opt.h:118
bool fFlag
Definition: opt.h:118
bool state_set_naked
Definition: opt.h:118
bool yychConversion
Definition: opt.h:118
Opt opts
Definition: opt.cc:7
type_t type() const
Definition: input_api.cc:15
std::string yyrestorectx
Definition: opt.h:118
std::string yydebug
Definition: opt.h:118
std::string state_set_arg
Definition: opt.h:118
std::string fill
Definition: opt.h:118
std::string yyctxmarker
Definition: opt.h:118
std::string condGotoParam
Definition: opt.h:118
std::string yymarker
Definition: opt.h:118
std::string state_get
Definition: opt.h:118
bool output(const char *s)
Definition: opt.cc:280
bool yybmHexTable
Definition: opt.h:118
realopt_t(useropt_t &opt)
Definition: opt.cc:232
std::string yyfilllabel
Definition: opt.h:118
const opt_t * operator->()
Definition: opt.cc:237
opt_t & operator=(const opt_t &opt)
Definition: opt.cc:25
std::string condGoto
Definition: opt.h:118
bool fill_arg_use
Definition: opt.h:118
bool bEmitYYCh
Definition: opt.h:118
std::string cond_set_arg
Definition: opt.h:118
bool bCaseInverted
Definition: opt.h:118
Definition: bitmap.cc:10
opt_t * operator->()
Definition: opt.cc:258
void fix()
Definition: opt.cc:35
bool fill_check
Definition: opt.h:118
std::string condDividerParam
Definition: opt.h:118
std::string yyctype
Definition: opt.h:118
const char * source_file
Definition: opt.h:153