From 12b25c9588f7a86a87964f7cbe1fdc3c42be7f5c Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 22 Sep 2015 13:15:31 +0100 Subject: [PATCH] Prepare to separate user config and effective config. --- re2c/bootstrap/src/conf/parse_opts.cc | 15 +- re2c/bootstrap/src/parse/parser.cc | 6 +- re2c/src/codegen/emit_action.cc | 4 +- re2c/src/codegen/input_api.cc | 31 ++- re2c/src/codegen/input_api.h | 3 +- re2c/src/conf/opt.cc | 367 +++++++++++++++++++++++--- re2c/src/conf/opt.h | 78 ++---- re2c/src/conf/parse_opts.re | 13 +- re2c/src/globals.h | 3 + re2c/src/main.cc | 2 +- re2c/src/parse/parser.ypp | 6 +- 11 files changed, 397 insertions(+), 131 deletions(-) diff --git a/re2c/bootstrap/src/conf/parse_opts.cc b/re2c/bootstrap/src/conf/parse_opts.cc index 57cd8eef..f5f5567a 100644 --- a/re2c/bootstrap/src/conf/parse_opts.cc +++ b/re2c/bootstrap/src/conf/parse_opts.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.3 on Mon Sep 21 21:18:34 2015 */ +/* Generated by re2c 0.14.3 on Tue Sep 22 12:44:15 2015 */ #line 1 "../src/conf/parse_opts.re" #include @@ -1840,19 +1840,14 @@ yy621: end: - if (!opts.source_file) - { - error ("no source file"); - return EXIT_FAIL; - } - if (!opts.cFlag && opts.header_file) + if (!opts.apply ()) { - error ("can only output a header file when using -c switch"); return EXIT_FAIL; } - if (opts.DFlag && (opts.bFlag || opts.dFlag || opts.sFlag || opts.flag_skeleton)) + + if (!opts.source_file) { - error ("cannot combine -D with -b, -d, -s or --skeleton switches"); + error ("no source file"); return EXIT_FAIL; } diff --git a/re2c/bootstrap/src/parse/parser.cc b/re2c/bootstrap/src/parse/parser.cc index c71a808d..68dc33dc 100644 --- a/re2c/bootstrap/src/parse/parser.cc +++ b/re2c/bootstrap/src/parse/parser.cc @@ -2749,18 +2749,18 @@ void parse(Scanner& i, Output & o) itRuleSetup = ruleSetupMap.find(it->first); if (itRuleSetup != ruleSetupMap.end()) { - opts.yySetupRule = itRuleSetup->second.second; + yySetupRule = itRuleSetup->second.second; } else { itRuleSetup = ruleSetupMap.find("*"); if (itRuleSetup != ruleSetupMap.end()) { - opts.yySetupRule = itRuleSetup->second.second; + yySetupRule = itRuleSetup->second.second; } else { - opts.yySetupRule = ""; + yySetupRule = ""; } } diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index ec1a7d2a..1ee5fd21 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -263,9 +263,9 @@ void emit_rule (OutputFile & o, uint32_t ind, const State * const s, const RuleO if (rule->code) { - if (!opts.yySetupRule.empty ()) + if (!yySetupRule.empty ()) { - o << indent(ind) << opts.yySetupRule << "\n"; + o << indent(ind) << yySetupRule << "\n"; } o.write_line_info (rule->code->loc.line, rule->code->loc.filename.c_str ()); o << indent (ind) << rule->code->text << "\n"; diff --git a/re2c/src/codegen/input_api.cc b/re2c/src/codegen/input_api.cc index 297b2cc1..fb0d69af 100644 --- a/re2c/src/codegen/input_api.cc +++ b/re2c/src/codegen/input_api.cc @@ -7,15 +7,20 @@ namespace re2c { +InputAPI::type_t InputAPI::type () const +{ + return type_; +} + void InputAPI::set (type_t t) { - type = t; + type_ = t; } std::string InputAPI::expr_peek () { std::string s; - switch (type) + switch (type_) { case DEFAULT: s = "*" + opts.mapCodeName["YYCURSOR"]; @@ -40,7 +45,7 @@ std::string InputAPI::stmt_peek (uint32_t ind) std::string InputAPI::stmt_skip (uint32_t ind) { std::string s; - switch (type) + switch (type_) { case DEFAULT: s = "++" + opts.mapCodeName["YYCURSOR"]; @@ -55,7 +60,7 @@ std::string InputAPI::stmt_skip (uint32_t ind) std::string InputAPI::stmt_backup (uint32_t ind) { std::string s; - switch (type) + switch (type_) { case DEFAULT: s = opts.mapCodeName["YYMARKER"] + " = " + opts.mapCodeName["YYCURSOR"]; @@ -70,7 +75,7 @@ std::string InputAPI::stmt_backup (uint32_t ind) std::string InputAPI::stmt_backupctx (uint32_t ind) { std::string s; - switch (type) + switch (type_) { case DEFAULT: // backward compatibility: '+1' here instead of '++YYCURSOR;' in stmt_restorectx @@ -86,7 +91,7 @@ std::string InputAPI::stmt_backupctx (uint32_t ind) std::string InputAPI::stmt_restore (uint32_t ind) { std::string s; - switch (type) + switch (type_) { case DEFAULT: s = opts.mapCodeName["YYCURSOR"] + " = " + opts.mapCodeName["YYMARKER"]; @@ -101,7 +106,7 @@ std::string InputAPI::stmt_restore (uint32_t ind) std::string InputAPI::stmt_restorectx (uint32_t ind) { std::string s; - switch (type) + switch (type_) { case DEFAULT: // backward compatibility: 'no ++YYCURSOR;' here; instead '+1' in stmt_backupctx @@ -116,35 +121,35 @@ std::string InputAPI::stmt_restorectx (uint32_t ind) std::string InputAPI::stmt_skip_peek (uint32_t ind) { - return type == DEFAULT + return type_ == DEFAULT ? indent (ind) + opts.mapCodeName["yych"] + " = " + opts.yychConversion + "*++" + opts.mapCodeName["YYCURSOR"] + ";\n" : stmt_skip (ind) + stmt_peek (ind); } std::string InputAPI::stmt_skip_backup (uint32_t ind) { - return type == DEFAULT + return type_ == DEFAULT ? indent (ind) + opts.mapCodeName["YYMARKER"] + " = ++" + opts.mapCodeName["YYCURSOR"] + ";\n" : stmt_skip (ind) + stmt_backup (ind); } std::string InputAPI::stmt_backup_peek (uint32_t ind) { - return type == DEFAULT + return type_ == DEFAULT ? indent (ind) + opts.mapCodeName["yych"] + " = " + opts.yychConversion + "*(" + opts.mapCodeName["YYMARKER"] + " = " + opts.mapCodeName["YYCURSOR"] + ");\n" : stmt_backup (ind) + stmt_peek (ind); } std::string InputAPI::stmt_skip_backup_peek (uint32_t ind) { - return type == DEFAULT + return type_ == DEFAULT ? indent (ind) + opts.mapCodeName["yych"] + " = " + opts.yychConversion + "*(" + opts.mapCodeName["YYMARKER"] + " = ++" + opts.mapCodeName["YYCURSOR"] + ");\n" : stmt_skip (ind) + stmt_backup (ind) + stmt_peek (ind); } std::string InputAPI::expr_lessthan_one () { - return type == DEFAULT + return type_ == DEFAULT ? opts.mapCodeName["YYLIMIT"] + " <= " + opts.mapCodeName["YYCURSOR"] : expr_lessthan (1); } @@ -152,7 +157,7 @@ std::string InputAPI::expr_lessthan_one () std::string InputAPI::expr_lessthan (uint32_t n) { std::ostringstream s; - switch (type) + switch (type_) { case DEFAULT: s << "(" << opts.mapCodeName["YYLIMIT"] << " - " << opts.mapCodeName["YYCURSOR"] << ") < " << n; diff --git a/re2c/src/codegen/input_api.h b/re2c/src/codegen/input_api.h index cd3fac8c..4018cc0c 100644 --- a/re2c/src/codegen/input_api.h +++ b/re2c/src/codegen/input_api.h @@ -18,9 +18,10 @@ public: }; private: - type_t type; + type_t type_; public: + type_t type () const; void set (type_t t); std::string expr_peek (); std::string expr_peek_save (); diff --git a/re2c/src/conf/opt.cc b/re2c/src/conf/opt.cc index 48450571..00dcdb87 100644 --- a/re2c/src/conf/opt.cc +++ b/re2c/src/conf/opt.cc @@ -6,94 +6,393 @@ namespace re2c Opt opts; +opt_t::opt_t () + : bFlag (false) + , cFlag (false) + , dFlag (false) + , DFlag (false) + , fFlag (false) + , FFlag (false) + , gFlag (false) + , iFlag (false) + , rFlag (false) + , sFlag (false) + , tFlag (false) + , header_file (NULL) + , flag_skeleton (false) + , bNoGenerationDate (false) + , bEmitYYCh (true) + , bUseStateNext (false) + , bUseYYFill (true) + , bUseYYFillParam (true) + , bUseYYFillCheck (true) + , bUseYYFillNaked (false) + , bUseYYSetConditionParam (true) + , bUseYYGetConditionNaked (false) + , bUseYYSetStateParam (true) + , bUseYYSetStateNaked (false) + , bUseYYGetStateNaked (false) + , yybmHexTable (false) + , bUseStateAbort (false) + , bCaseInsensitive (false) + , bCaseInverted (false) + , cGotoThreshold (9) + , topIndent (0) + , indString ("\t") + , labelPrefix ("yy") + , condPrefix ("yyc_") + , condEnumPrefix ("yyc") + , condDivider ("/* *********************************** */") + , condDividerParam ("@@") + , condGoto ("goto @@;") + , condGotoParam ("@@") + , yychConversion ("") + , yyFillLength ("@@") + , yySetConditionParam ("@@") + , yySetStateParam ("@@") + , mapCodeName () + , encoding () + , input_api () + , empty_class_policy (EMPTY_CLASS_MATCH_EMPTY) +{} + +opt_t::opt_t (const opt_t & opt) + : bFlag (opt.bFlag) + , cFlag (opt.cFlag) + , dFlag (opt.dFlag) + , DFlag (opt.DFlag) + , fFlag (opt.fFlag) + , FFlag (opt.FFlag) + , gFlag (opt.gFlag) + , iFlag (opt.iFlag) + , rFlag (opt.rFlag) + , sFlag (opt.sFlag) + , tFlag (opt.tFlag) + , header_file (opt.header_file) + , flag_skeleton (opt.flag_skeleton) + , bNoGenerationDate (opt.bNoGenerationDate) + , bEmitYYCh (opt.bEmitYYCh) + , bUseStateNext (opt.bUseStateNext) + , bUseYYFill (opt.bUseYYFill) + , bUseYYFillParam (opt.bUseYYFillParam) + , bUseYYFillCheck (opt.bUseYYFillCheck) + , bUseYYFillNaked (opt.bUseYYFillNaked) + , bUseYYSetConditionParam (opt.bUseYYSetConditionParam) + , bUseYYGetConditionNaked (opt.bUseYYGetConditionNaked) + , bUseYYSetStateParam (opt.bUseYYSetStateParam) + , bUseYYSetStateNaked (opt.bUseYYSetStateNaked) + , bUseYYGetStateNaked (opt.bUseYYGetStateNaked) + , yybmHexTable (opt.yybmHexTable) + , bUseStateAbort (opt.bUseStateAbort) + , bCaseInsensitive (opt.bCaseInsensitive) + , bCaseInverted (opt.bCaseInverted) + , cGotoThreshold (opt.cGotoThreshold) + , topIndent (opt.topIndent) + , indString (opt.indString) + , labelPrefix (opt.labelPrefix) + , condPrefix (opt.condPrefix) + , condEnumPrefix (opt.condEnumPrefix) + , condDivider (opt.condDivider) + , condDividerParam (opt.condDividerParam) + , condGoto (opt.condGoto) + , condGotoParam (opt.condGotoParam) + , yychConversion (opt.yychConversion) + , yyFillLength (opt.yyFillLength) + , yySetConditionParam (opt.yySetConditionParam) + , yySetStateParam (opt.yySetStateParam) + , mapCodeName (opt.mapCodeName) + , encoding (opt.encoding) + , input_api (opt.input_api) + , empty_class_policy (opt.empty_class_policy) +{} + +opt_t & opt_t::operator = (const opt_t & opt) +{ + new (this) opt_t (opt); + return *this; +} + +bool Opt::apply () +{ + *((opt_t *) this) = useropt; + + // check groups of mutually exclusive options + if (DFlag && flag_skeleton) + { + error ("incompatible options: '-D, --emit-dot' and '--skeleton'"); + return false; + } + + // reset to default options that make no sense in current configuration + if (DFlag) + { + bFlag = baseopt.bFlag; + dFlag = baseopt.dFlag; + fFlag = baseopt.fFlag; + gFlag = baseopt.gFlag; + iFlag = baseopt.iFlag; + sFlag = baseopt.sFlag; + tFlag = baseopt.tFlag; + header_file = baseopt.header_file; + bEmitYYCh = baseopt.bEmitYYCh; + bUseStateNext = baseopt.bUseStateNext; + bUseYYFill = baseopt.bUseYYFill; + bUseYYFillParam = baseopt.bUseYYFillParam; + bUseYYFillCheck = baseopt.bUseYYFillCheck; + bUseYYFillNaked = baseopt.bUseYYFillNaked; + bUseYYSetConditionParam = baseopt.bUseYYSetConditionParam; + bUseYYGetConditionNaked = baseopt.bUseYYGetConditionNaked; + bUseYYSetStateParam = baseopt.bUseYYSetStateParam; + bUseYYSetStateNaked = baseopt.bUseYYSetStateNaked; + bUseYYGetStateNaked = baseopt.bUseYYGetStateNaked; + yybmHexTable = baseopt.yybmHexTable; + bUseStateAbort = baseopt.bUseStateAbort; + cGotoThreshold = baseopt.cGotoThreshold; + topIndent = baseopt.topIndent; + indString = baseopt.indString; + labelPrefix = baseopt.labelPrefix; + condPrefix = baseopt.condPrefix; + condEnumPrefix = baseopt.condEnumPrefix; + condDivider = baseopt.condDivider; + condDividerParam = baseopt.condDividerParam; + condGoto = baseopt.condGoto; + condGotoParam = baseopt.condGotoParam; + yychConversion = baseopt.yychConversion; + yyFillLength = baseopt.yyFillLength; + yySetConditionParam = baseopt.yySetConditionParam; + yySetStateParam = baseopt.yySetStateParam; + mapCodeName = baseopt.mapCodeName; + input_api = baseopt.input_api; + } + if (flag_skeleton) + { + dFlag = baseopt.dFlag; + fFlag = baseopt.fFlag; + iFlag = baseopt.iFlag; + tFlag = baseopt.tFlag; + header_file = baseopt.header_file; + bEmitYYCh = baseopt.bEmitYYCh; + bUseStateNext = baseopt.bUseStateNext; + bUseYYFill = baseopt.bUseYYFill; + bUseYYFillParam = baseopt.bUseYYFillParam; + bUseYYFillCheck = baseopt.bUseYYFillCheck; + bUseYYFillNaked = baseopt.bUseYYFillNaked; + bUseYYSetConditionParam = baseopt.bUseYYSetConditionParam; + bUseYYGetConditionNaked = baseopt.bUseYYGetConditionNaked; + bUseYYSetStateParam = baseopt.bUseYYSetStateParam; + bUseYYSetStateNaked = baseopt.bUseYYSetStateNaked; + bUseYYGetStateNaked = baseopt.bUseYYGetStateNaked; + bUseStateAbort = baseopt.bUseStateAbort; + topIndent = baseopt.topIndent; + indString = baseopt.indString; + labelPrefix = baseopt.labelPrefix; + condPrefix = baseopt.condPrefix; + condEnumPrefix = baseopt.condEnumPrefix; + condDivider = baseopt.condDivider; + condDividerParam = baseopt.condDividerParam; + condGoto = baseopt.condGoto; + condGotoParam = baseopt.condGotoParam; + yychConversion = baseopt.yychConversion; + yyFillLength = baseopt.yyFillLength; + yySetConditionParam = baseopt.yySetConditionParam; + yySetStateParam = baseopt.yySetStateParam; + mapCodeName = baseopt.mapCodeName; + input_api = baseopt.input_api; + } + if (bCaseInsensitive) + { + bCaseInverted = baseopt.bCaseInverted; + } + if (!cFlag) + { + tFlag = baseopt.tFlag; + header_file = baseopt.header_file; + bUseYYSetConditionParam = baseopt.bUseYYSetConditionParam; + bUseYYGetConditionNaked = baseopt.bUseYYGetConditionNaked; + condPrefix = baseopt.condPrefix; + condEnumPrefix = baseopt.condEnumPrefix; + condDivider = baseopt.condDivider; + condDividerParam = baseopt.condDividerParam; + condGoto = baseopt.condGoto; + condGotoParam = baseopt.condGotoParam; + yySetConditionParam = baseopt.yySetConditionParam; + mapCodeName.erase ("YYCONDTYPE"); + mapCodeName.erase ("YYGETCONDITION"); + mapCodeName.erase ("YYSETCONDITION"); + mapCodeName.erase ("yyctable"); + } + if (!fFlag) + { + bUseStateNext = baseopt.bUseStateNext; + bUseYYSetStateParam = baseopt.bUseYYSetStateParam; + bUseYYSetStateNaked = baseopt.bUseYYSetStateNaked; + bUseYYGetStateNaked = baseopt.bUseYYGetStateNaked; + bUseStateAbort = baseopt.bUseStateAbort; + yySetStateParam = baseopt.yySetStateParam; + mapCodeName.erase ("YYGETSTATE"); + mapCodeName.erase ("YYSETSTATE"); + mapCodeName.erase ("yyaccept"); + mapCodeName.erase ("yyFillLabel"); + mapCodeName.erase ("yyNext"); + } + if (!bFlag) + { + yybmHexTable = baseopt.yybmHexTable; + mapCodeName.erase ("yybm"); + } + if (!gFlag) + { + cGotoThreshold = baseopt.cGotoThreshold; + mapCodeName.erase ("yytarget"); + } + if (input_api.type () != InputAPI::DEFAULT) + { + mapCodeName.erase ("YYCURSOR"); + mapCodeName.erase ("YYMARKER"); + mapCodeName.erase ("YYCTXMARKER"); + mapCodeName.erase ("YYLIMIT"); + } + if (input_api.type () != InputAPI::CUSTOM) + { + mapCodeName.erase ("YYPEEK"); + mapCodeName.erase ("YYSKIP"); + mapCodeName.erase ("YYBACKUP"); + mapCodeName.erase ("YYBACKUPCTX"); + mapCodeName.erase ("YYRESTORE"); + mapCodeName.erase ("YYRESTORECTX"); + mapCodeName.erase ("YYLESSTHAN"); + } + if (!dFlag) + { + mapCodeName.erase ("YYDEBUG"); + } + + // force individual options + if (DFlag) + { + iFlag = true; + } + if (flag_skeleton) + { + iFlag = true; + input_api.set (InputAPI::CUSTOM); + indString = " "; + topIndent = 2; + } + if (encoding.type () == Enc::UCS2) + { + sFlag = true; + } + if (encoding.type () == Enc::UTF16) + { + sFlag = true; + } + if (encoding.type () == Enc::UTF32) + { + sFlag = true; + } + if (bFlag) + { + sFlag = true; + } + if (gFlag) + { + bFlag = true; + sFlag = true; + } + + return true; +} + void Opt::bit_vectors () { - bFlag = true; - sFlag = true; + useropt.bFlag = true; + useropt.sFlag = true; } void Opt::start_conditions () { - cFlag = true; + useropt.cFlag = true; } void Opt::debug_output () { - dFlag = true; + useropt.dFlag = true; } void Opt::emit_dot () { - DFlag = true; - iFlag = true; + useropt.DFlag = true; + useropt.iFlag = true; } void Opt::storable_state () { - fFlag = true; + useropt.fFlag = true; } void Opt::flex_syntax () { - FFlag = true; + useropt.FFlag = true; } void Opt::computed_gotos () { - gFlag = true; - bFlag = true; - sFlag = true; + useropt.gFlag = true; + useropt.bFlag = true; + useropt.sFlag = true; } void Opt::no_debug_info () { - iFlag = true; + useropt.iFlag = true; } void Opt::reusable () { - rFlag = true; + useropt.rFlag = true; } void Opt::nested_ifs () { - sFlag = true; + useropt.sFlag = true; } void Opt::no_generation_date () { - bNoGenerationDate = true; + useropt.bNoGenerationDate = true; } void Opt::case_insensitive () { - bCaseInsensitive = true; + useropt.bCaseInsensitive = true; } void Opt::case_inverted () { - bCaseInverted = true; + useropt.bCaseInverted = true; } void Opt::skeleton () { - flag_skeleton = true; - input_api.set (InputAPI::CUSTOM); + useropt.flag_skeleton = true; + useropt.iFlag = true; + useropt.input_api.set (InputAPI::CUSTOM); } void Opt::encoding_policy (Enc::policy_t p) { - encoding.setPolicy (p); + useropt.encoding.setPolicy (p); } void Opt::input (InputAPI::type_t i) { - input_api.set (i); + useropt.input_api.set (i); } void Opt::empty_class (empty_class_policy_t p) { - empty_class_policy = p; + useropt.empty_class_policy = p; } bool Opt::source (const char * s) @@ -126,45 +425,45 @@ bool Opt::output (const char * s) bool Opt::type_header (const char * s) { - if (header_file) + if (useropt.header_file) { - error ("multiple header files: %s, %s", header_file, s); + error ("multiple header files: %s, %s", useropt.header_file, s); return false; } else { - tFlag = true; - header_file = s; + useropt.tFlag = true; + useropt.header_file = s; return true; } } bool Opt::ecb () { - return encoding.set (Enc::EBCDIC); + return useropt.encoding.set (Enc::EBCDIC); } bool Opt::unicode () { - sFlag = true; - return encoding.set(Enc::UTF32); + useropt.sFlag = true; + return useropt.encoding.set(Enc::UTF32); } bool Opt::wide_chars () { - sFlag = true; - return encoding.set(Enc::UCS2); + useropt.sFlag = true; + return useropt.encoding.set(Enc::UCS2); } bool Opt::utf_16 () { - sFlag = true; - return encoding.set(Enc::UTF16); + useropt.sFlag = true; + return useropt.encoding.set(Enc::UTF16); } bool Opt::utf_8 () { - return encoding.set(Enc::UTF8); + return useropt.encoding.set(Enc::UTF8); } } // namespace re2c diff --git a/re2c/src/conf/opt.h b/re2c/src/conf/opt.h index 161014b2..7aa8bbd9 100644 --- a/re2c/src/conf/opt.h +++ b/re2c/src/conf/opt.h @@ -11,12 +11,8 @@ namespace re2c { -struct Opt +struct opt_t { - const char * source_file; - const char * output_file; - const char * header_file; - bool bFlag; bool cFlag; bool dFlag; @@ -28,6 +24,7 @@ struct Opt bool rFlag; bool sFlag; bool tFlag; + const char * header_file; bool flag_skeleton; bool bNoGenerationDate; bool bEmitYYCh; @@ -59,65 +56,36 @@ struct Opt std::string yyFillLength; std::string yySetConditionParam; std::string yySetStateParam; - std::string yySetupRule; CodeNames mapCodeName; Enc encoding; InputAPI input_api; empty_class_policy_t empty_class_policy; + opt_t (); + opt_t (const opt_t & opt); + opt_t & operator = (const opt_t & opt); +}; + +struct Opt : public opt_t +{ + const char * source_file; + const char * output_file; + +private: + const opt_t baseopt; + opt_t useropt; + +public: Opt () - : source_file (NULL) + : opt_t () + , source_file (NULL) , output_file (NULL) - , header_file (NULL) - , bFlag (false) - , cFlag (false) - , dFlag (false) - , DFlag (false) - , fFlag (false) - , FFlag (false) - , gFlag (false) - , iFlag (false) - , rFlag (false) - , sFlag (false) - , tFlag (false) - , flag_skeleton (false) - , bNoGenerationDate (false) - , bEmitYYCh (true) - , bUseStateNext (false) - , bUseYYFill (true) - , bUseYYFillParam (true) - , bUseYYFillCheck (true) - , bUseYYFillNaked (false) - , bUseYYSetConditionParam (true) - , bUseYYGetConditionNaked (false) - , bUseYYSetStateParam (true) - , bUseYYSetStateNaked (false) - , bUseYYGetStateNaked (false) - , yybmHexTable (false) - , bUseStateAbort (false) - , bCaseInsensitive (false) - , bCaseInverted (false) - , cGotoThreshold (9) - , topIndent (0) - , indString ("\t") - , labelPrefix ("yy") - , condPrefix ("yyc_") - , condEnumPrefix ("yyc") - , condDivider ("/* *********************************** */") - , condDividerParam ("@@") - , condGoto ("goto @@;") - , condGotoParam ("@@") - , yychConversion ("") - , yyFillLength ("@@") - , yySetConditionParam ("@@") - , yySetStateParam ("@@") - , yySetupRule ("") - , mapCodeName () - , encoding () - , input_api () - , empty_class_policy (EMPTY_CLASS_MATCH_EMPTY) + , baseopt () + , useropt () {} + bool apply (); + void bit_vectors (); void start_conditions (); void debug_output (); diff --git a/re2c/src/conf/parse_opts.re b/re2c/src/conf/parse_opts.re index 51604a6b..c1f20231 100644 --- a/re2c/src/conf/parse_opts.re +++ b/re2c/src/conf/parse_opts.re @@ -225,19 +225,14 @@ opt_empty_class: */ end: - if (!opts.source_file) - { - error ("no source file"); - return EXIT_FAIL; - } - if (!opts.cFlag && opts.header_file) + if (!opts.apply ()) { - error ("can only output a header file when using -c switch"); return EXIT_FAIL; } - if (opts.DFlag && (opts.bFlag || opts.dFlag || opts.sFlag || opts.flag_skeleton)) + + if (!opts.source_file) { - error ("cannot combine -D with -b, -d, -s or --skeleton switches"); + error ("no source file"); return EXIT_FAIL; } diff --git a/re2c/src/globals.h b/re2c/src/globals.h index d6536519..b2ea67ae 100644 --- a/re2c/src/globals.h +++ b/re2c/src/globals.h @@ -1,6 +1,8 @@ #ifndef _RE2C_GLOBALS_ #define _RE2C_GLOBALS_ +#include + #include "src/conf/opt.h" #include "src/conf/warn.h" #include "src/util/c99_stdint.h" @@ -12,6 +14,7 @@ extern bool bUsedYYBitmap; extern bool bWroteGetState; extern bool bWroteCondCheck; extern uint32_t last_fill_index; +extern std::string yySetupRule; extern Opt opts; extern Warn warn; diff --git a/re2c/src/main.cc b/re2c/src/main.cc index d9bbcc9b..ea934da3 100644 --- a/re2c/src/main.cc +++ b/re2c/src/main.cc @@ -11,7 +11,7 @@ bool bUsedYYBitmap = false; bool bWroteGetState = false; bool bWroteCondCheck = false; uint32_t last_fill_index = 0; -CodeNames mapCodeName; +std::string yySetupRule = ""; } // end namespace re2c diff --git a/re2c/src/parse/parser.ypp b/re2c/src/parse/parser.ypp index 581a75fb..34297b0d 100644 --- a/re2c/src/parse/parser.ypp +++ b/re2c/src/parse/parser.ypp @@ -884,18 +884,18 @@ void parse(Scanner& i, Output & o) itRuleSetup = ruleSetupMap.find(it->first); if (itRuleSetup != ruleSetupMap.end()) { - opts.yySetupRule = itRuleSetup->second.second; + yySetupRule = itRuleSetup->second.second; } else { itRuleSetup = ruleSetupMap.find("*"); if (itRuleSetup != ruleSetupMap.end()) { - opts.yySetupRule = itRuleSetup->second.second; + yySetupRule = itRuleSetup->second.second; } else { - opts.yySetupRule = ""; + yySetupRule = ""; } } -- 2.40.0