SRC_HDR = \
$(srcdir)/src/codegen/bitmap.h \
$(srcdir)/src/codegen/code_names.h \
+ $(srcdir)/src/codegen/dfa_emit.h \
$(srcdir)/src/codegen/go.h \
$(srcdir)/src/codegen/indent.h \
$(srcdir)/src/codegen/input_api.h \
#include "config.h"
#include "src/dfa/dfa.h"
+#include "src/codegen/dfa_emit.h" // genTypes
#include "src/globals.h"
#include "src/parse/parser.h"
#include "src/util/c99_stdint.h"
/* Line 189 of yacc.c */
-#line 219 "./parser.cc"
+#line 220 "./parser.cc"
/* Enabling traces. */
#ifndef YYDEBUG
{
/* Line 214 of yacc.c */
-#line 149 "../src/parse/parser.ypp"
+#line 150 "../src/parse/parser.ypp"
re2c::Symbol *symbol;
re2c::RegExp *regexp;
/* Line 214 of yacc.c */
-#line 283 "./parser.cc"
+#line 284 "./parser.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
/* Line 264 of yacc.c */
-#line 295 "./parser.cc"
+#line 296 "./parser.cc"
#ifdef short
# undef short
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 178, 178, 180, 184, 188, 197, 206, 210, 214,
- 220, 228, 237, 246, 250, 255, 260, 266, 270, 278,
- 286, 291, 297, 303, 315, 327, 333, 341, 344, 351,
- 356, 365, 368, 376, 379, 386, 390, 397, 401, 412,
- 416, 423, 427, 442, 449, 453, 457, 461, 468, 476,
- 480, 484
+ 0, 179, 179, 181, 185, 189, 198, 207, 211, 215,
+ 221, 229, 238, 247, 251, 256, 261, 267, 271, 279,
+ 287, 292, 298, 304, 316, 328, 334, 342, 345, 352,
+ 357, 366, 369, 377, 380, 387, 391, 398, 402, 413,
+ 417, 424, 428, 443, 450, 454, 458, 462, 469, 477,
+ 481, 485
};
#endif
case 2:
/* Line 1464 of yacc.c */
-#line 178 "../src/parse/parser.ypp"
+#line 179 "../src/parse/parser.ypp"
{
;}
break;
case 3:
/* Line 1464 of yacc.c */
-#line 181 "../src/parse/parser.ypp"
+#line 182 "../src/parse/parser.ypp"
{
foundRules = true;
;}
case 5:
/* Line 1464 of yacc.c */
-#line 189 "../src/parse/parser.ypp"
+#line 190 "../src/parse/parser.ypp"
{
if ((yyvsp[(1) - (4)].symbol)->re)
{
case 6:
/* Line 1464 of yacc.c */
-#line 198 "../src/parse/parser.ypp"
+#line 199 "../src/parse/parser.ypp"
{
if ((yyvsp[(1) - (2)].symbol)->re)
{
case 7:
/* Line 1464 of yacc.c */
-#line 207 "../src/parse/parser.ypp"
+#line 208 "../src/parse/parser.ypp"
{
in->fatal("trailing contexts are not allowed in named definitions");
;}
case 8:
/* Line 1464 of yacc.c */
-#line 211 "../src/parse/parser.ypp"
+#line 212 "../src/parse/parser.ypp"
{
in->fatal("trailing contexts are not allowed in named definitions");
;}
case 9:
/* Line 1464 of yacc.c */
-#line 215 "../src/parse/parser.ypp"
+#line 216 "../src/parse/parser.ypp"
{
in->config(*(yyvsp[(1) - (4)].str), *(yyvsp[(3) - (4)].str));
delete (yyvsp[(1) - (4)].str);
case 10:
/* Line 1464 of yacc.c */
-#line 221 "../src/parse/parser.ypp"
+#line 222 "../src/parse/parser.ypp"
{
in->config(*(yyvsp[(1) - (4)].str), (yyvsp[(3) - (4)].number));
delete (yyvsp[(1) - (4)].str);
case 11:
/* Line 1464 of yacc.c */
-#line 229 "../src/parse/parser.ypp"
+#line 230 "../src/parse/parser.ypp"
{
if (cFlag)
{
case 12:
/* Line 1464 of yacc.c */
-#line 238 "../src/parse/parser.ypp"
+#line 239 "../src/parse/parser.ypp"
{
if (cFlag)
in->fatal("condition or '<*>' required when using -c switch");
case 13:
/* Line 1464 of yacc.c */
-#line 247 "../src/parse/parser.ypp"
+#line 248 "../src/parse/parser.ypp"
{
context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(6) - (7)].str), (yyvsp[(7) - (7)].token));
;}
case 14:
/* Line 1464 of yacc.c */
-#line 251 "../src/parse/parser.ypp"
+#line 252 "../src/parse/parser.ypp"
{
assert((yyvsp[(7) - (7)].str));
context_rule((yyvsp[(2) - (7)].clist), (yyvsp[(4) - (7)].regexp), (yyvsp[(5) - (7)].regexp), (yyvsp[(7) - (7)].str), NULL);
case 15:
/* Line 1464 of yacc.c */
-#line 256 "../src/parse/parser.ypp"
+#line 257 "../src/parse/parser.ypp"
{
context_none((yyvsp[(2) - (6)].clist));
delete (yyvsp[(5) - (6)].str);
case 16:
/* Line 1464 of yacc.c */
-#line 261 "../src/parse/parser.ypp"
+#line 262 "../src/parse/parser.ypp"
{
assert((yyvsp[(6) - (6)].str));
context_none((yyvsp[(2) - (6)].clist));
case 17:
/* Line 1464 of yacc.c */
-#line 267 "../src/parse/parser.ypp"
+#line 268 "../src/parse/parser.ypp"
{
default_rule((yyvsp[(2) - (5)].clist), (yyvsp[(5) - (5)].token));
;}
case 18:
/* Line 1464 of yacc.c */
-#line 271 "../src/parse/parser.ypp"
+#line 272 "../src/parse/parser.ypp"
{
context_check(NULL);
Token *token = new Token((yyvsp[(7) - (7)].token), (yyvsp[(7) - (7)].token)->source, (yyvsp[(7) - (7)].token)->line, (yyvsp[(6) - (7)].str));
case 19:
/* Line 1464 of yacc.c */
-#line 279 "../src/parse/parser.ypp"
+#line 280 "../src/parse/parser.ypp"
{
assert((yyvsp[(7) - (7)].str));
context_check(NULL);
case 20:
/* Line 1464 of yacc.c */
-#line 287 "../src/parse/parser.ypp"
+#line 288 "../src/parse/parser.ypp"
{
context_none(NULL);
delete (yyvsp[(5) - (6)].str);
case 21:
/* Line 1464 of yacc.c */
-#line 292 "../src/parse/parser.ypp"
+#line 293 "../src/parse/parser.ypp"
{
assert((yyvsp[(6) - (6)].str));
context_none(NULL);
case 22:
/* Line 1464 of yacc.c */
-#line 298 "../src/parse/parser.ypp"
+#line 299 "../src/parse/parser.ypp"
{
CondList *clist = new CondList();
clist->insert("*");
case 23:
/* Line 1464 of yacc.c */
-#line 304 "../src/parse/parser.ypp"
+#line 305 "../src/parse/parser.ypp"
{
context_check(NULL);
if (specNone)
case 24:
/* Line 1464 of yacc.c */
-#line 316 "../src/parse/parser.ypp"
+#line 317 "../src/parse/parser.ypp"
{
assert((yyvsp[(3) - (3)].str));
context_check(NULL);
case 25:
/* Line 1464 of yacc.c */
-#line 328 "../src/parse/parser.ypp"
+#line 329 "../src/parse/parser.ypp"
{
CondList *clist = new CondList();
clist->insert("*");
case 26:
/* Line 1464 of yacc.c */
-#line 334 "../src/parse/parser.ypp"
+#line 335 "../src/parse/parser.ypp"
{
setup_rule((yyvsp[(2) - (4)].clist), (yyvsp[(4) - (4)].token));
;}
case 27:
/* Line 1464 of yacc.c */
-#line 341 "../src/parse/parser.ypp"
+#line 342 "../src/parse/parser.ypp"
{
in->fatal("unnamed condition not supported");
;}
case 28:
/* Line 1464 of yacc.c */
-#line 345 "../src/parse/parser.ypp"
+#line 346 "../src/parse/parser.ypp"
{
(yyval.clist) = (yyvsp[(1) - (1)].clist);
;}
case 29:
/* Line 1464 of yacc.c */
-#line 352 "../src/parse/parser.ypp"
+#line 353 "../src/parse/parser.ypp"
{
(yyval.clist) = new CondList();
(yyval.clist)->insert((yyvsp[(1) - (1)].symbol)->GetName().to_string());
case 30:
/* Line 1464 of yacc.c */
-#line 357 "../src/parse/parser.ypp"
+#line 358 "../src/parse/parser.ypp"
{
(yyvsp[(1) - (3)].clist)->insert((yyvsp[(3) - (3)].symbol)->GetName().to_string());
(yyval.clist) = (yyvsp[(1) - (3)].clist);
case 31:
/* Line 1464 of yacc.c */
-#line 365 "../src/parse/parser.ypp"
+#line 366 "../src/parse/parser.ypp"
{
(yyval.str) = NULL;
;}
case 32:
/* Line 1464 of yacc.c */
-#line 369 "../src/parse/parser.ypp"
+#line 370 "../src/parse/parser.ypp"
{
(yyval.str) = new Str((yyvsp[(3) - (3)].symbol)->GetName().to_string().c_str());
;}
case 33:
/* Line 1464 of yacc.c */
-#line 376 "../src/parse/parser.ypp"
+#line 377 "../src/parse/parser.ypp"
{
(yyval.regexp) = new NullOp;
;}
case 34:
/* Line 1464 of yacc.c */
-#line 380 "../src/parse/parser.ypp"
+#line 381 "../src/parse/parser.ypp"
{
(yyval.regexp) = (yyvsp[(2) - (2)].regexp);
;}
case 35:
/* Line 1464 of yacc.c */
-#line 387 "../src/parse/parser.ypp"
+#line 388 "../src/parse/parser.ypp"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
;}
case 36:
/* Line 1464 of yacc.c */
-#line 391 "../src/parse/parser.ypp"
+#line 392 "../src/parse/parser.ypp"
{
(yyval.regexp) = mkAlt((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp));
;}
case 37:
/* Line 1464 of yacc.c */
-#line 398 "../src/parse/parser.ypp"
+#line 399 "../src/parse/parser.ypp"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
;}
case 38:
/* Line 1464 of yacc.c */
-#line 402 "../src/parse/parser.ypp"
+#line 403 "../src/parse/parser.ypp"
{
(yyval.regexp) = mkDiff((yyvsp[(1) - (3)].regexp), (yyvsp[(3) - (3)].regexp));
if(!(yyval.regexp))
case 39:
/* Line 1464 of yacc.c */
-#line 413 "../src/parse/parser.ypp"
+#line 414 "../src/parse/parser.ypp"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
;}
case 40:
/* Line 1464 of yacc.c */
-#line 417 "../src/parse/parser.ypp"
+#line 418 "../src/parse/parser.ypp"
{
(yyval.regexp) = new CatOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].regexp));
;}
case 41:
/* Line 1464 of yacc.c */
-#line 424 "../src/parse/parser.ypp"
+#line 425 "../src/parse/parser.ypp"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
;}
case 42:
/* Line 1464 of yacc.c */
-#line 428 "../src/parse/parser.ypp"
+#line 429 "../src/parse/parser.ypp"
{
switch((yyvsp[(2) - (2)].op))
{
case 43:
/* Line 1464 of yacc.c */
-#line 443 "../src/parse/parser.ypp"
+#line 444 "../src/parse/parser.ypp"
{
(yyval.regexp) = new CloseVOp((yyvsp[(1) - (2)].regexp), (yyvsp[(2) - (2)].extop).minsize, (yyvsp[(2) - (2)].extop).maxsize);
;}
case 44:
/* Line 1464 of yacc.c */
-#line 450 "../src/parse/parser.ypp"
+#line 451 "../src/parse/parser.ypp"
{
(yyval.op) = (yyvsp[(1) - (1)].op);
;}
case 45:
/* Line 1464 of yacc.c */
-#line 454 "../src/parse/parser.ypp"
+#line 455 "../src/parse/parser.ypp"
{
(yyval.op) = (yyvsp[(1) - (1)].op);
;}
case 46:
/* Line 1464 of yacc.c */
-#line 458 "../src/parse/parser.ypp"
+#line 459 "../src/parse/parser.ypp"
{
(yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*';
;}
case 47:
/* Line 1464 of yacc.c */
-#line 462 "../src/parse/parser.ypp"
+#line 463 "../src/parse/parser.ypp"
{
(yyval.op) = ((yyvsp[(1) - (2)].op) == (yyvsp[(2) - (2)].op)) ? (yyvsp[(1) - (2)].op) : '*';
;}
case 48:
/* Line 1464 of yacc.c */
-#line 469 "../src/parse/parser.ypp"
+#line 470 "../src/parse/parser.ypp"
{
if(!(yyvsp[(1) - (1)].symbol)->re)
{
case 49:
/* Line 1464 of yacc.c */
-#line 477 "../src/parse/parser.ypp"
+#line 478 "../src/parse/parser.ypp"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
;}
case 50:
/* Line 1464 of yacc.c */
-#line 481 "../src/parse/parser.ypp"
+#line 482 "../src/parse/parser.ypp"
{
(yyval.regexp) = (yyvsp[(1) - (1)].regexp);
;}
case 51:
/* Line 1464 of yacc.c */
-#line 485 "../src/parse/parser.ypp"
+#line 486 "../src/parse/parser.ypp"
{
(yyval.regexp) = (yyvsp[(2) - (3)].regexp);
;}
/* Line 1464 of yacc.c */
-#line 2095 "./parser.cc"
+#line 2096 "./parser.cc"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
/* Line 1684 of yacc.c */
-#line 490 "../src/parse/parser.ypp"
+#line 491 "../src/parse/parser.ypp"
extern "C" {
{
/* Line 1685 of yacc.c */
-#line 149 "../src/parse/parser.ypp"
+#line 150 "../src/parse/parser.ypp"
re2c::Symbol *symbol;
re2c::RegExp *regexp;
#include <assert.h>
#include "src/codegen/bitmap.h"
+#include "src/codegen/dfa_emit.h"
#include "src/codegen/go.h"
#include "src/codegen/indent.h"
#include "src/codegen/input_api.h"
namespace re2c
{
-// there must be at least one span in list; all spans must cover
-// same range
-
-template<typename _Ty>
-std::string replaceParam(std::string str, const std::string& param, const _Ty& value)
-{
- std::ostringstream strValue;
-
- strValue << value;
-
- std::string::size_type pos;
-
- while((pos = str.find(param)) != std::string::npos)
- {
- str.replace(pos, param.length(), strValue.str());
- }
-
- return str;
-}
-
-static void genYYFill(OutputFile & o, uint32_t, uint32_t need)
+void genYYFill(OutputFile & o, uint32_t, uint32_t need)
{
if (bUseYYFillParam)
{
}
}
-static std::string genGetState()
-{
- if (bUseYYGetStateNaked)
- {
- return mapCodeName["YYGETSTATE"];
- }
- else
- {
- return mapCodeName["YYGETSTATE"] + "()";
- }
-}
-
-static std::string genGetCondition()
+std::string genGetCondition()
{
if (bUseYYGetConditionNaked)
{
}
}
-static void genSetCondition(OutputFile & o, uint32_t ind, const std::string& newcond)
+void genSetCondition(OutputFile & o, uint32_t ind, const std::string& newcond)
{
if (bUseYYSetConditionParam)
{
}
}
-static void genGoTo(OutputFile & o, uint32_t ind, const State *from, const State *to, bool & readCh)
+void genGoTo(OutputFile & o, uint32_t ind, const State *from, const State *to, bool & readCh)
{
if (DFlag)
{
vUsedLabels.insert(to->label);
}
-static void need(OutputFile & o, uint32_t ind, uint32_t n, bool & readCh, bool bSetMarker)
+void need(OutputFile & o, uint32_t ind, uint32_t n, bool & readCh, bool bSetMarker)
{
if (DFlag)
{
bUseStartLabel = false;
}
-static void output_state_goto_sub (std::ostream & o, uint32_t ind, uint32_t start_label, int cMin, int cMax)
-{
- if (cMin == cMax)
- {
- if (cMin == -1)
- {
- o << indent(ind) << "goto " << labelPrefix << start_label << ";\n";
- }
- else
- {
- o << indent(ind) << "goto " << mapCodeName["yyFillLabel"] << cMin << ";\n";
- }
- }
- else
- {
- int cMid = cMin + ((cMax - cMin + 1) / 2);
-
- o << indent(ind) << "if (" << genGetState() << " < " << cMid << ") {\n";
- output_state_goto_sub (o, ind + 1, start_label, cMin, cMid - 1);
- o << indent(ind) << "} else {\n";
- output_state_goto_sub (o, ind + 1, start_label, cMid, cMax);
- o << indent(ind) << "}\n";
- }
-}
-
-void output_state_goto (std::ostream & o, uint32_t ind, uint32_t start_label)
-{
- if (gFlag)
- {
- o << indent(ind++) << "static void *" << mapCodeName["yystable"] << "[" << "] = {\n";
-
- for (size_t i=0; i<last_fill_index; ++i)
- {
- o << indent(ind) << "&&" << mapCodeName["yyFillLabel"] << i << ",\n";
- }
-
- o << indent(--ind) << "};\n";
- o << "\n";
-
- o << indent(ind) << "if (" << genGetState();
- if (bUseStateAbort)
- {
- o << " == -1) {\n";
- }
- else
- {
- o << " < 0) {\n";
- }
- o << indent(++ind) << "goto " << labelPrefix << start_label << ";\n";
- if (bUseStateAbort)
- {
- o << indent(--ind) << "} else if (" << genGetState() << " < -1) {\n";
- o << indent(++ind) << "abort();\n";
- }
- o << indent(--ind) << "}\n";
-
- o << indent(ind) << "goto *" << mapCodeName["yystable"] << "[" << genGetState() << "];\n";
-
- }
- else if (bFlag)
- {
- output_state_goto_sub (o, ind, start_label, -1, last_fill_index-1);
- if (bUseStateAbort)
- {
- o << indent(ind) << "abort();\n";
- }
- }
- else
- {
- o << indent(ind) << "switch (" << genGetState() << ") {\n";
- if (bUseStateAbort)
- {
- o << indent(ind) << "default: abort();\n";
- o << indent(ind) << "case -1: goto " << labelPrefix << start_label << ";\n";
- }
- else
- {
- o << indent(ind) << "default: goto " << labelPrefix << start_label << ";\n";
- }
-
- for (size_t i=0; i<last_fill_index; ++i)
- {
- o << indent(ind) << "case " << i << ": goto " << mapCodeName["yyFillLabel"] << i << ";\n";
- }
-
- o << indent(ind) << "}\n";
- }
- if (bUseStateNext)
- {
- o << mapCodeName["yyNext"] << ":\n";
- }
-}
-
void genCondTable(OutputFile & o, uint32_t ind, const RegExpMap& specMap)
{
if (cFlag && !bWroteCondCheck && gFlag && specMap.size())
}
}
-static void genCondGotoSub(OutputFile & o, uint32_t ind, RegExpIndices& vCondList, uint32_t cMin, uint32_t cMax)
+void genCondGotoSub(OutputFile & o, uint32_t ind, RegExpIndices& vCondList, uint32_t cMin, uint32_t cMax)
{
if (cMin == cMax)
{
}
}
-void output_yyaccept_init (std::ostream & o, uint32_t ind, bool used_yyaccept)
-{
- if (used_yyaccept)
- {
- o << indent (ind) << "unsigned int " << mapCodeName["yyaccept"] << " = 0;\n";
- }
-}
-
-void output_yyaccept_selector (std::ostream & o, uint32_t ind, bool used_yyaccept, uint32_t yyaccept_selector)
-{
- if (used_yyaccept)
- {
- o << indent (ind) << mapCodeName["yyaccept"] << " = " << yyaccept_selector << ";\n";
- }
-}
-
-void output_yymaxfill (std::ostream & o, uint32_t max_fill)
-{
- o << "#define YYMAXFILL " << max_fill << "\n";
-}
-
-void output_line_info (std::ostream & o, uint32_t line_number, const char * file_name)
-{
- if (!iFlag)
- {
- o << "#line " << line_number << " \"" << file_name << "\"\n";
- }
-}
-
-void output_types (std::ostream & o, uint32_t ind, const std::vector<std::string> & types)
-{
- o << indent (ind++) << "enum " << mapCodeName["YYCONDTYPE"] << " {\n";
- for (unsigned int i = 0; i < types.size (); ++i)
- {
- o << indent (ind) << condEnumPrefix << types[i] << ",\n";
- }
- o << indent (--ind) << "};\n";
-}
-
-void output_version_time (std::ostream & o)
-{
- o << "/* Generated by re2c " PACKAGE_VERSION;
- if (!bNoGenerationDate)
- {
- o << " on ";
- time_t now = time (NULL);
- o.write (ctime (&now), 24);
- }
- o << "*/" << "\n";
-}
-
} // end namespace re2c
--- /dev/null
+#ifndef __DFA_EMIT__
+#define __DFA_EMIT__
+
+#include "src/codegen/output.h"
+#include "src/dfa/dfa.h"
+
+namespace re2c {
+
+class DFA;
+
+typedef std::vector<std::string> RegExpIndices;
+
+void genCondTable (OutputFile &, uint32_t, const RegExpMap &);
+void genCondGoto (OutputFile &, uint32_t, const RegExpMap &);
+void genTypes (Output &, const RegExpMap &);
+
+// helpers
+void genYYFill (OutputFile & o, uint32_t, uint32_t need);
+std::string genGetCondition ();
+void genSetCondition (OutputFile & o, uint32_t ind, const std::string & newcond);
+void genGoTo (OutputFile & o, uint32_t ind, const State * from, const State * to, bool & readCh);
+void need (OutputFile & o, uint32_t ind, uint32_t n, bool & readCh, bool bSetMarker);
+void genCondGotoSub (OutputFile & o, uint32_t ind, RegExpIndices & vCondList, uint32_t cMin, uint32_t cMax);
+
+template<typename _Ty>
+std::string replaceParam (std::string str, const std::string & param, const _Ty & value)
+{
+ std::ostringstream strValue;
+ strValue << value;
+ std::string::size_type pos;
+ while((pos = str.find(param)) != std::string::npos)
+ {
+ str.replace(pos, param.length(), strValue.str());
+ }
+ return str;
+}
+
+} // namespace re2c
+
+#endif // __DFA_EMIT__
#include <iomanip>
#include <stdio.h>
+#include <string.h>
+#include "src/codegen/indent.h"
#include "src/codegen/output.h"
#include "src/codegen/print.h"
-#include "src/dfa/re.h"
+#include "src/globals.h"
+#include "src/util/substr.h" // operator << for Str
namespace re2c
{
header.emit (types);
}
+void output_state_goto_sub (std::ostream & o, uint32_t ind, uint32_t start_label, int cMin, int cMax)
+{
+ if (cMin == cMax)
+ {
+ if (cMin == -1)
+ {
+ o << indent(ind) << "goto " << labelPrefix << start_label << ";\n";
+ }
+ else
+ {
+ o << indent(ind) << "goto " << mapCodeName["yyFillLabel"] << cMin << ";\n";
+ }
+ }
+ else
+ {
+ int cMid = cMin + ((cMax - cMin + 1) / 2);
+
+ o << indent(ind) << "if (" << output_get_state() << " < " << cMid << ") {\n";
+ output_state_goto_sub (o, ind + 1, start_label, cMin, cMid - 1);
+ o << indent(ind) << "} else {\n";
+ output_state_goto_sub (o, ind + 1, start_label, cMid, cMax);
+ o << indent(ind) << "}\n";
+ }
+}
+
+void output_state_goto (std::ostream & o, uint32_t ind, uint32_t start_label)
+{
+ if (gFlag)
+ {
+ o << indent(ind++) << "static void *" << mapCodeName["yystable"] << "[" << "] = {\n";
+
+ for (size_t i=0; i<last_fill_index; ++i)
+ {
+ o << indent(ind) << "&&" << mapCodeName["yyFillLabel"] << i << ",\n";
+ }
+
+ o << indent(--ind) << "};\n";
+ o << "\n";
+
+ o << indent(ind) << "if (" << output_get_state();
+ if (bUseStateAbort)
+ {
+ o << " == -1) {\n";
+ }
+ else
+ {
+ o << " < 0) {\n";
+ }
+ o << indent(++ind) << "goto " << labelPrefix << start_label << ";\n";
+ if (bUseStateAbort)
+ {
+ o << indent(--ind) << "} else if (" << output_get_state() << " < -1) {\n";
+ o << indent(++ind) << "abort();\n";
+ }
+ o << indent(--ind) << "}\n";
+
+ o << indent(ind) << "goto *" << mapCodeName["yystable"] << "[" << output_get_state() << "];\n";
+
+ }
+ else if (bFlag)
+ {
+ output_state_goto_sub (o, ind, start_label, -1, last_fill_index-1);
+ if (bUseStateAbort)
+ {
+ o << indent(ind) << "abort();\n";
+ }
+ }
+ else
+ {
+ o << indent(ind) << "switch (" << output_get_state() << ") {\n";
+ if (bUseStateAbort)
+ {
+ o << indent(ind) << "default: abort();\n";
+ o << indent(ind) << "case -1: goto " << labelPrefix << start_label << ";\n";
+ }
+ else
+ {
+ o << indent(ind) << "default: goto " << labelPrefix << start_label << ";\n";
+ }
+
+ for (size_t i=0; i<last_fill_index; ++i)
+ {
+ o << indent(ind) << "case " << i << ": goto " << mapCodeName["yyFillLabel"] << i << ";\n";
+ }
+
+ o << indent(ind) << "}\n";
+ }
+ if (bUseStateNext)
+ {
+ o << mapCodeName["yyNext"] << ":\n";
+ }
+}
+
+void output_yyaccept_init (std::ostream & o, uint32_t ind, bool used_yyaccept)
+{
+ if (used_yyaccept)
+ {
+ o << indent (ind) << "unsigned int " << mapCodeName["yyaccept"] << " = 0;\n";
+ }
+}
+
+void output_yyaccept_selector (std::ostream & o, uint32_t ind, bool used_yyaccept, uint32_t yyaccept_selector)
+{
+ if (used_yyaccept)
+ {
+ o << indent (ind) << mapCodeName["yyaccept"] << " = " << yyaccept_selector << ";\n";
+ }
+}
+
+void output_yymaxfill (std::ostream & o, uint32_t max_fill)
+{
+ o << "#define YYMAXFILL " << max_fill << "\n";
+}
+
+void output_line_info (std::ostream & o, uint32_t line_number, const char * file_name)
+{
+ if (!iFlag)
+ {
+ o << "#line " << line_number << " \"" << file_name << "\"\n";
+ }
+}
+
+void output_types (std::ostream & o, uint32_t ind, const std::vector<std::string> & types)
+{
+ o << indent (ind++) << "enum " << mapCodeName["YYCONDTYPE"] << " {\n";
+ for (unsigned int i = 0; i < types.size (); ++i)
+ {
+ o << indent (ind) << condEnumPrefix << types[i] << ",\n";
+ }
+ o << indent (--ind) << "};\n";
+}
+
+void output_version_time (std::ostream & o)
+{
+ o << "/* Generated by re2c " PACKAGE_VERSION;
+ if (!bNoGenerationDate)
+ {
+ o << " on ";
+ time_t now = time (NULL);
+ o.write (ctime (&now), 24);
+ }
+ o << "*/" << "\n";
+}
+
+std::string output_get_state ()
+{
+ if (bUseYYGetStateNaked)
+ {
+ return mapCodeName["YYGETSTATE"];
+ }
+ else
+ {
+ return mapCodeName["YYGETSTATE"] + "()";
+ }
+}
+
} // namespace re2c
~Output ();
};
+void output_line_info (std::ostream &, uint32_t, const char *);
+void output_state_goto (std::ostream &, uint32_t, uint32_t);
+void output_types (std::ostream &, uint32_t, const std::vector<std::string> &);
+void output_version_time (std::ostream &);
+void output_yyaccept_init (std::ostream &, uint32_t, bool);
+void output_yyaccept_selector (std::ostream &, uint32_t, bool, uint32_t);
+void output_yymaxfill (std::ostream &, uint32_t);
+
+// helpers
+void output_state_goto_sub (std::ostream & o, uint32_t ind, uint32_t start_label, int cMin, int cMax);
+std::string output_get_state ();
+
} // namespace re2c
#endif // _output_h
#include "src/codegen/go.h"
#include "src/dfa/re.h"
+#include "src/util/smart_ptr.h"
namespace re2c
{
#endif
};
+typedef std::map<std::string, std::pair<int, RegExp *> > RegExpMap;
+
class DFA
{
#endif
};
+smart_ptr<DFA> genCode (RegExp *, Output &, uint32_t);
+
inline Action::Action(State *s) : state(s), type(NONE)
{
delete s->action;
#include <vector>
#include <string>
-#include "src/codegen/output.h"
#include "src/dfa/ins.h"
#include "src/globals.h"
#include "src/parse/token.h"
#include "src/util/range.h"
-#include "src/util/smart_ptr.h"
#include "src/util/free_list.h"
namespace re2c
#endif
};
-typedef std::set<std::string> CondList;
-typedef std::pair<int, RegExp*> NRegExp;
-typedef std::map<std::string, NRegExp> RegExpMap;
-typedef std::vector<std::string> RegExpIndices;
-typedef std::list<RuleOp*> RuleOpList;
-typedef std::pair<uint32_t, std::string> LineCode;
-typedef std::map<std::string, LineCode> SetupMap;
-typedef std::map<std::string, Token*> DefaultMap;
-
-class DFA;
-
-extern smart_ptr<DFA> genCode(RegExp*, Output & output, uint32_t ind);
-extern void genCondTable(OutputFile &, uint32_t, const RegExpMap&);
-extern void genCondGoto(OutputFile &, uint32_t, const RegExpMap&);
-extern void genTypes(Output &, const RegExpMap&);
-
-extern void output_state_goto (std::ostream &, uint32_t, uint32_t);
-extern void output_types (std::ostream &, uint32_t, const std::vector<std::string> &);
-extern void output_version_time (std::ostream &);
-extern void output_yyaccept_init (std::ostream &, uint32_t, bool);
-extern void output_yyaccept_selector (std::ostream &, uint32_t, bool, uint32_t);
-extern void output_yymaxfill (std::ostream &, uint32_t);
-extern void output_line_info (std::ostream &, uint32_t, const char *);
-
extern RegExp *mkDiff(RegExp*, RegExp*);
extern RegExp *mkAlt(RegExp*, RegExp*);
extern void parse(Scanner &, Output &);
extern void parse_cleanup();
+typedef std::set<std::string> CondList;
+typedef std::list<RuleOp*> RuleOpList;
+typedef std::map<std::string, std::pair<uint32_t, std::string> > SetupMap;
+typedef std::map<std::string, Token*> DefaultMap;
+
} // end namespace re2c
#endif
#include "config.h"
#include "src/dfa/dfa.h"
+#include "src/codegen/dfa_emit.h" // genTypes
#include "src/globals.h"
#include "src/parse/parser.h"
#include "src/util/c99_stdint.h"