]> granicus.if.org Git - re2c/commitdiff
Prepare to separate user config and effective config.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 22 Sep 2015 12:15:31 +0000 (13:15 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 22 Sep 2015 12:15:31 +0000 (13:15 +0100)
re2c/bootstrap/src/conf/parse_opts.cc
re2c/bootstrap/src/parse/parser.cc
re2c/src/codegen/emit_action.cc
re2c/src/codegen/input_api.cc
re2c/src/codegen/input_api.h
re2c/src/conf/opt.cc
re2c/src/conf/opt.h
re2c/src/conf/parse_opts.re
re2c/src/globals.h
re2c/src/main.cc
re2c/src/parse/parser.ypp

index 57cd8eef075bfbd048c4d2c39ce6c0c08a127309..f5f5567a06f2bfcdc7c9313190e4f021872e5713 100644 (file)
@@ -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 <stdio.h>
 
@@ -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;
        }
 
index c71a808dee42201411cb4072ffdd8b7b87685aaa..68dc33dc7a8fd7c0ad4de0d8c12466ba2f3353fe 100644 (file)
@@ -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 = "";
                                                }
                                        }
 
index ec1a7d2aefab526d2cc738bfa742723a7002e509..1ee5fd218f454760ec4a6417feb9032097fd483d 100644 (file)
@@ -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";
index 297b2cc1ee2ea9005a752932f5efc082a9c63658..fb0d69af1fb7eb87c74ba7222977b99bdbe6d82a 100644 (file)
@@ -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;
index cd3fac8c8d4420f5f4345d55748029a1ae952ac1..4018cc0ca7747c952e5d3cd199ae8eb800dfa9e0 100644 (file)
@@ -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 ();
index 484505716bbb7ee68b40b4913dec8faddc24388f..00dcdb8762705d2778c8e5858e8c0c881fd3ef47 100644 (file)
@@ -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
index 161014b277e6c3ed9a0b81b06ded4bc5b6aaafdb..7aa8bbd973a1f4c39804e5e9ff9a30b25c64af5c 100644 (file)
 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 ();
index 51604a6b5a1db591b11c220e5ffd6cbb19689d09..c1f20231ab96d434f01313e3ce20e4e3225bd3b5 100644 (file)
@@ -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;
        }
 
index d653651913462324ed1af1ed37b4cb6efbde0e72..b2ea67ae0eb3c3c890705f576b9185fc95075b00 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _RE2C_GLOBALS_
 #define _RE2C_GLOBALS_
 
+#include <string>
+
 #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;
index d9bbcc9ba7a15f85aac40103d716c71c85fdc213..ea934da3a3a56da6c7ff9402b4ab1e20a4d14886 100644 (file)
@@ -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
 
index 581a75fb351705c364a07981474cb4cd11a340b1..34297b0dfe3d12f563d3c57cdea84047cf864501 100644 (file)
@@ -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 = "";
                                                }
                                        }