#include "src/ir/regexp/regexp_cat.h"
#include "src/ir/regexp/regexp_close.h"
#include "src/ir/regexp/regexp_null.h"
-#include "src/codegen/emit.h" // genTypes
#include "src/globals.h"
#include "src/parse/code.h"
#include "src/parse/extop.h"
}
static counter_t<rule_rank_t> rank_counter;
+static std::vector<std::string> condnames;
static re2c::RegExpMap specMap;
static RegExp *spec = NULL, *specNone = NULL;
static RuleOpList specStar;
if (itRE != specMap.end())
{
- itRE->second.second = mkAlt(itRE->second.second, rule);
+ itRE->second = mkAlt(itRE->second, rule);
}
else
{
- size_t nIndex = specMap.size() + 1; // 0 is reserved for "0"-spec
- assert( nIndex < 1u << 31);
- specMap[*it] = std::make_pair(int(nIndex), rule);
+ specMap[*it] = rule;
+ condnames.push_back (*it);
}
}
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 227, 227, 229, 233, 237, 246, 255, 259, 263,
- 272, 277, 282, 287, 292, 297, 302, 310, 314, 320,
- 324, 328, 334, 338, 344, 357, 362, 370, 375, 379,
- 384, 388, 392, 396, 402, 406, 410, 414, 421, 430,
- 439, 443, 449, 454, 460, 464, 470, 478, 483, 489,
- 495, 505, 517, 523, 531, 534, 541, 547, 557, 560,
- 568, 571, 578, 582, 589, 593, 600, 604, 611, 615,
- 630, 650, 654, 658, 662, 669, 679, 683
+ 0, 226, 226, 228, 232, 236, 245, 254, 258, 262,
+ 271, 276, 281, 286, 291, 296, 301, 309, 313, 319,
+ 323, 327, 333, 337, 343, 356, 361, 369, 374, 378,
+ 383, 387, 391, 395, 401, 405, 409, 413, 420, 429,
+ 438, 442, 448, 453, 459, 463, 469, 477, 482, 488,
+ 494, 504, 516, 522, 530, 533, 540, 546, 556, 559,
+ 567, 570, 577, 581, 588, 592, 599, 603, 610, 614,
+ 629, 649, 653, 657, 661, 668, 678, 682
};
#endif
// but compile it separately because of RegExp::PRIVATE attribute
for (it = specMap.begin(); it != specMap.end(); ++it)
{
- assert(it->second.second);
+ assert(it->second);
for (RuleOpList::const_iterator itOp = specStar.begin(); itOp != specStar.end(); ++itOp)
{
- it->second.second = mkAlt(*itOp, it->second.second);
+ it->second = mkAlt(*itOp, it->second);
}
}
}
if (specNone)
{
- // After merging star rules merge none code to specmap
- // this simplifies some stuff.
+ specMap["0"] = specNone;
// Note that "0" inserts first, which is important.
- specMap["0"] = std::make_pair(0, specNone);
- }
- else
- {
- // We reserved 0 for specNone but it is not present,
- // so we can decrease all specs.
- for (it = specMap.begin(); it != specMap.end(); ++it)
- {
- it->second.first--;
- }
+ condnames.insert (condnames.begin (), "0");
}
+ o.types = condnames;
}
size_t nCount = specMap.size();
for (it = specMap.begin(); it != specMap.end(); ++it)
{
- assert(it->second.second);
+ assert(it->second);
if (parseMode != Scanner::Reuse)
{
if (itRuleDefault != ruleDefaultMap.end())
{
RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), *(itRuleDefault->second), rank_counter.next (), RegExp::SHARED, NULL);
- it->second.second = it->second.second ? mkAlt(def, it->second.second) : def;
+ it->second = it->second ? mkAlt(def, it->second) : def;
}
else
{
if (itRuleDefault != ruleDefaultMap.end())
{
RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), *(itRuleDefault->second), rank_counter.next (), RegExp::SHARED, NULL);
- it->second.second = it->second.second ? mkAlt(def, it->second.second) : def;
+ it->second = it->second ? mkAlt(def, it->second) : def;
}
}
- dfa_map[it->first] = genCode(it->second.second, o, topIndent, it->first);
+ dfa_map[it->first] = genCode(it->second, o, topIndent, it->first);
}
if (parseMode != Scanner::Rules && dfa_map.find(it->first) != dfa_map.end())
{
- dfa_map[it->first]->emit(o, topIndent, &specMap, it->first, !--nCount, bPrologBrace);
+ dfa_map[it->first]->emit(o, topIndent, it->first, !--nCount, bPrologBrace);
}
}
-
- genTypes (o, specMap);
}
else
{
}
if (parseMode != Scanner::Rules && dfa_map.find("") != dfa_map.end())
{
- dfa_map[""]->emit(o, topIndent, NULL, "", 0, bPrologBrace);
+ dfa_map[""]->emit(o, topIndent, "", 0, bPrologBrace);
}
}
}
RangeSuffix::freeList.clear();
Code::freelist.clear();
symbol_table.clear ();
+ condnames.clear ();
specMap.clear();
specStar.clear();
specNone = NULL;
// helpers
void genGoTo (OutputFile & o, uint32_t ind, const State * from, const State * to, bool & readCh);
-void genTypes (Output &, const RegExpMap &);
template<typename _Ty> std::string replaceParam (std::string str, const std::string & param, const _Ty & value)
{
{
static std::string genGetCondition ();
-static void genCondGotoSub (OutputFile & o, uint32_t ind, RegExpIndices & vCondList, uint32_t cMin, uint32_t cMax);
-static void genCondTable (OutputFile & o, uint32_t ind, const RegExpMap & specMap);
-static void genCondGoto (OutputFile & o, uint32_t ind, const RegExpMap & specMap);
+static void genCondGotoSub (OutputFile & o, uint32_t ind, const std::vector<std::string> & condnames, uint32_t cMin, uint32_t cMax);
+static void genCondTable (OutputFile & o, uint32_t ind, const std::vector<std::string> & condnames);
+static void genCondGoto (OutputFile & o, uint32_t ind, const std::vector<std::string> & condnames);
static void emit_state (OutputFile & o, uint32_t ind, const State * s, bool used_label);
std::string genGetCondition()
}
}
-void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const std::string& condName, bool isLastCond, bool& bPrologBrace)
+void DFA::emit(Output & output, uint32_t& ind, const std::string& condName, bool isLastCond, bool& bPrologBrace)
{
OutputFile & o = output.source;
else if ((!fFlag && o.get_used_yyaccept ())
|| (!fFlag && bEmitYYCh)
|| (bFlag && !cFlag && BitMap::first)
- || (cFlag && !bWroteCondCheck && gFlag && specMap)
+ || (cFlag && !bWroteCondCheck && gFlag)
|| (fFlag && !bWroteGetState && gFlag)
)
{
}
if (bProlog)
{
- if (cFlag && !bWroteCondCheck && gFlag && specMap)
+ if (cFlag && !bWroteCondCheck && gFlag)
{
- genCondTable(o, ind, *specMap);
+ genCondTable(o, ind, output.types);
}
o.insert_state_goto (ind);
if (cFlag && !DFlag)
}
}
o.write_user_start_label ();
- if (cFlag && !bWroteCondCheck && specMap)
+ if (cFlag && !bWroteCondCheck)
{
- genCondGoto(o, ind, *specMap);
+ genCondGoto(o, ind, output.types);
}
}
}
}
-void genCondTable(OutputFile & o, uint32_t ind, const RegExpMap& specMap)
+void genCondTable(OutputFile & o, uint32_t ind, const std::vector<std::string> & condnames)
{
- const uint32_t specMap_size = static_cast<uint32_t> (specMap.size ());
- RegExpIndices vCondList(specMap_size);
-
- for(RegExpMap::const_iterator itSpec = specMap.begin(); itSpec != specMap.end(); ++itSpec)
+ const size_t conds = condnames.size ();
+ o << indent(ind++) << "static void *" << mapCodeName["yyctable"] << "[" << conds << "] = {\n";
+ for (size_t i = 0; i < conds; ++i)
{
- vCondList[itSpec->second.first] = itSpec->first;
- }
-
- o << indent(ind++) << "static void *" << mapCodeName["yyctable"] << "[" << specMap_size << "] = {\n";
-
- for(RegExpIndices::const_iterator it = vCondList.begin(); it != vCondList.end(); ++it)
- {
- o << indent(ind) << "&&" << condPrefix << *it << ",\n";
+ o << indent(ind) << "&&" << condPrefix << condnames[i] << ",\n";
}
o << indent(--ind) << "};\n";
}
-void genCondGotoSub(OutputFile & o, uint32_t ind, RegExpIndices& vCondList, uint32_t cMin, uint32_t cMax)
+void genCondGotoSub(OutputFile & o, uint32_t ind, const std::vector<std::string> & condnames, uint32_t cMin, uint32_t cMax)
{
if (cMin == cMax)
{
- o << indent(ind) << "goto " << condPrefix << vCondList[cMin] << ";\n";
+ o << indent(ind) << "goto " << condPrefix << condnames[cMin] << ";\n";
}
else
{
uint32_t cMid = cMin + ((cMax - cMin + 1) / 2);
o << indent(ind) << "if (" << genGetCondition() << " < " << cMid << ") {\n";
- genCondGotoSub(o, ind + 1, vCondList, cMin, cMid - 1);
+ genCondGotoSub(o, ind + 1, condnames, cMin, cMid - 1);
o << indent(ind) << "} else {\n";
- genCondGotoSub(o, ind + 1, vCondList, cMid, cMax);
+ genCondGotoSub(o, ind + 1, condnames, cMid, cMax);
o << indent(ind) << "}\n";
}
}
-void genCondGoto(OutputFile & o, uint32_t ind, const RegExpMap& specMap)
+void genCondGoto(OutputFile & o, uint32_t ind, const std::vector<std::string> & condnames)
{
if (gFlag)
{
}
else
{
+ const size_t conds = condnames.size ();
if (sFlag)
{
- RegExpIndices vCondList(specMap.size());
-
- for(RegExpMap::const_iterator it = specMap.begin(); it != specMap.end(); ++it)
- {
- vCondList[it->second.first] = it->first;
- }
- genCondGotoSub(o, ind, vCondList, 0, static_cast<uint32_t> (vCondList.size()) - 1);
+ genCondGotoSub(o, ind, condnames, 0, static_cast<uint32_t> (conds) - 1);
}
else if (DFlag)
{
- for(RegExpMap::const_iterator it = specMap.begin(); it != specMap.end(); ++it)
+ for (size_t i = 0; i < conds; ++i)
{
- o << "0 -> " << it->first << " [label=\"state=" << it->first << "\"]\n";
+ const std::string cond = condnames[i];
+ o << "0 -> " << cond << " [label=\"state=" << cond << "\"]\n";
}
}
else
{
o << indent(ind) << "switch (" << genGetCondition() << ") {\n";
-
- for(RegExpMap::const_iterator it = specMap.begin(); it != specMap.end(); ++it)
+ for (size_t i = 0; i < conds; ++i)
{
- o << indent(ind) << "case " << condEnumPrefix << it->first << ": goto " << condPrefix << it->first << ";\n";
+ const std::string & cond = condnames[i];
+ o << indent(ind) << "case " << condEnumPrefix << cond << ": goto " << condPrefix << cond << ";\n";
}
o << indent(ind) << "}\n";
}
bWroteCondCheck = true;
}
-void genTypes(Output & output, const RegExpMap& specMap)
-{
- output.types.resize (specMap.size());
- for(RegExpMap::const_iterator itSpecMap = specMap.begin(); itSpecMap != specMap.end(); ++itSpecMap)
- {
- // If an entry is < 0 then we did the 0/empty correction twice.
- assert(itSpecMap->second.first >= 0);
- output.types[itSpecMap->second.first] = itSpecMap->first;
- }
-}
-
} // end namespace re2c
return u;
}
+OutputFile & operator << (OutputFile & u, uint64_t n)
+{
+ u.stream () << n;
+ return u;
+}
+
OutputFile & operator << (OutputFile & u, const std::string & s)
{
u.stream () << s;
void write_user_start_label ();
friend OutputFile & operator << (OutputFile & o, char c);
friend OutputFile & operator << (OutputFile & o, uint32_t n);
+ friend OutputFile & operator << (OutputFile & o, uint64_t n);
friend OutputFile & operator << (OutputFile & o, const std::string & s);
friend OutputFile & operator << (OutputFile & o, const char * s);
friend OutputFile & operator << (OutputFile & o, label_t l);
namespace re2c
{
-typedef std::map<std::string, std::pair<int, RegExp *> > RegExpMap;
-
class DFA
{
public:
void findBaseState ();
void prepare (OutputFile & o, uint32_t &, const std::string & cond);
void count_used_labels (std::set<label_t> & used, label_t prolog, label_t start, bool force_start) const;
- void emit (Output &, uint32_t &, const RegExpMap *, const std::string &, bool, bool &);
+ void emit (Output &, uint32_t &, const std::string &, bool, bool &);
friend std::ostream & operator << (std::ostream &, const DFA &);
typedef std::set<std::string> CondList;
typedef std::list<RuleOp*> RuleOpList;
+typedef std::map<std::string, RegExp *> RegExpMap;
typedef std::map<std::string, std::pair<uint32_t, std::string> > SetupMap;
typedef std::map<std::string, const Code *> DefaultMap;
typedef std::map<std::string, RegExp *> symbol_table_t;
#include "src/ir/regexp/regexp_cat.h"
#include "src/ir/regexp/regexp_close.h"
#include "src/ir/regexp/regexp_null.h"
-#include "src/codegen/emit.h" // genTypes
#include "src/globals.h"
#include "src/parse/code.h"
#include "src/parse/extop.h"
}
static counter_t<rule_rank_t> rank_counter;
+static std::vector<std::string> condnames;
static re2c::RegExpMap specMap;
static RegExp *spec = NULL, *specNone = NULL;
static RuleOpList specStar;
if (itRE != specMap.end())
{
- itRE->second.second = mkAlt(itRE->second.second, rule);
+ itRE->second = mkAlt(itRE->second, rule);
}
else
{
- size_t nIndex = specMap.size() + 1; // 0 is reserved for "0"-spec
- assert( nIndex < 1u << 31);
- specMap[*it] = std::make_pair(int(nIndex), rule);
+ specMap[*it] = rule;
+ condnames.push_back (*it);
}
}
// but compile it separately because of RegExp::PRIVATE attribute
for (it = specMap.begin(); it != specMap.end(); ++it)
{
- assert(it->second.second);
+ assert(it->second);
for (RuleOpList::const_iterator itOp = specStar.begin(); itOp != specStar.end(); ++itOp)
{
- it->second.second = mkAlt(*itOp, it->second.second);
+ it->second = mkAlt(*itOp, it->second);
}
}
}
if (specNone)
{
- // After merging star rules merge none code to specmap
- // this simplifies some stuff.
+ specMap["0"] = specNone;
// Note that "0" inserts first, which is important.
- specMap["0"] = std::make_pair(0, specNone);
- }
- else
- {
- // We reserved 0 for specNone but it is not present,
- // so we can decrease all specs.
- for (it = specMap.begin(); it != specMap.end(); ++it)
- {
- it->second.first--;
- }
+ condnames.insert (condnames.begin (), "0");
}
+ o.types = condnames;
}
size_t nCount = specMap.size();
for (it = specMap.begin(); it != specMap.end(); ++it)
{
- assert(it->second.second);
+ assert(it->second);
if (parseMode != Scanner::Reuse)
{
if (itRuleDefault != ruleDefaultMap.end())
{
RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), *(itRuleDefault->second), rank_counter.next (), RegExp::SHARED, NULL);
- it->second.second = it->second.second ? mkAlt(def, it->second.second) : def;
+ it->second = it->second ? mkAlt(def, it->second) : def;
}
else
{
if (itRuleDefault != ruleDefaultMap.end())
{
RuleOp * def = new RuleOp(in->mkDefault(), new NullOp(), *(itRuleDefault->second), rank_counter.next (), RegExp::SHARED, NULL);
- it->second.second = it->second.second ? mkAlt(def, it->second.second) : def;
+ it->second = it->second ? mkAlt(def, it->second) : def;
}
}
- dfa_map[it->first] = genCode(it->second.second, o, topIndent, it->first);
+ dfa_map[it->first] = genCode(it->second, o, topIndent, it->first);
}
if (parseMode != Scanner::Rules && dfa_map.find(it->first) != dfa_map.end())
{
- dfa_map[it->first]->emit(o, topIndent, &specMap, it->first, !--nCount, bPrologBrace);
+ dfa_map[it->first]->emit(o, topIndent, it->first, !--nCount, bPrologBrace);
}
}
-
- genTypes (o, specMap);
}
else
{
}
if (parseMode != Scanner::Rules && dfa_map.find("") != dfa_map.end())
{
- dfa_map[""]->emit(o, topIndent, NULL, "", 0, bPrologBrace);
+ dfa_map[""]->emit(o, topIndent, "", 0, bPrologBrace);
}
}
}
RangeSuffix::freeList.clear();
Code::freelist.clear();
symbol_table.clear ();
+ condnames.clear ();
specMap.clear();
specStar.clear();
specNone = NULL;
yy0:
switch (s->cond) {
- case EStateComment: goto yyc_Comment;
case EStateNormal: goto yyc_Normal;
+ case EStateComment: goto yyc_Comment;
case EStateSkiptoeol: goto yyc_Skiptoeol;
case EStateString: goto yyc_String;
}
digraph re2c {
0 -> INITIAL [label="state=INITIAL"]
-0 -> ST_DOUBLE_QUOTES [label="state=ST_DOUBLE_QUOTES"]
0 -> ST_OFFSET [label="state=ST_OFFSET"]
-0 -> ST_RAW [label="state=ST_RAW"]
-0 -> ST_SECTION_RAW [label="state=ST_SECTION_RAW"]
0 -> ST_SECTION_VALUE [label="state=ST_SECTION_VALUE"]
0 -> ST_VALUE [label="state=ST_VALUE"]
+0 -> ST_SECTION_RAW [label="state=ST_SECTION_RAW"]
+0 -> ST_DOUBLE_QUOTES [label="state=ST_DOUBLE_QUOTES"]
0 -> ST_VARNAME [label="state=ST_VARNAME"]
+0 -> ST_RAW [label="state=ST_RAW"]
/* *********************************** */
INITIAL -> 2
2 -> 3 [label="[0x00-0x08][0x0B-0x0C][0x0E-0x1F][#][0-9][A-E][G-M][P-S][U-X][Z][\\][_-e][g-m][p-s][u-x][z][0x7F-0xFF]"]
unsigned int yyaccept = 0;
switch (YYGETCONDITION()) {
case yycINITIAL: goto yyc_INITIAL;
- case yycST_DOUBLE_QUOTES: goto yyc_ST_DOUBLE_QUOTES;
case yycST_OFFSET: goto yyc_ST_OFFSET;
- case yycST_RAW: goto yyc_ST_RAW;
- case yycST_SECTION_RAW: goto yyc_ST_SECTION_RAW;
case yycST_SECTION_VALUE: goto yyc_ST_SECTION_VALUE;
case yycST_VALUE: goto yyc_ST_VALUE;
+ case yycST_SECTION_RAW: goto yyc_ST_SECTION_RAW;
+ case yycST_DOUBLE_QUOTES: goto yyc_ST_DOUBLE_QUOTES;
case yycST_VARNAME: goto yyc_ST_VARNAME;
+ case yycST_RAW: goto yyc_ST_RAW;
}
/* *********************************** */
yyc_INITIAL:
digraph re2c {
-0 -> INITIAL [label="state=INITIAL"]
+0 -> ST_IN_SCRIPTING [label="state=ST_IN_SCRIPTING"]
+0 -> ST_LOOKING_FOR_PROPERTY [label="state=ST_LOOKING_FOR_PROPERTY"]
0 -> ST_BACKQUOTE [label="state=ST_BACKQUOTE"]
0 -> ST_DOUBLE_QUOTES [label="state=ST_DOUBLE_QUOTES"]
-0 -> ST_END_HEREDOC [label="state=ST_END_HEREDOC"]
0 -> ST_HEREDOC [label="state=ST_HEREDOC"]
-0 -> ST_IN_SCRIPTING [label="state=ST_IN_SCRIPTING"]
-0 -> ST_LOOKING_FOR_PROPERTY [label="state=ST_LOOKING_FOR_PROPERTY"]
0 -> ST_LOOKING_FOR_VARNAME [label="state=ST_LOOKING_FOR_VARNAME"]
-0 -> ST_NOWDOC [label="state=ST_NOWDOC"]
0 -> ST_VAR_OFFSET [label="state=ST_VAR_OFFSET"]
+0 -> INITIAL [label="state=INITIAL"]
+0 -> ST_END_HEREDOC [label="state=ST_END_HEREDOC"]
+0 -> ST_NOWDOC [label="state=ST_NOWDOC"]
/* *********************************** */
INITIAL -> 2
2 -> 5 [label="[0x00-;][=-0xFF]"]