for (accept_t::const_iterator it = accept.begin(); it != accept.end(); ++it)
{
o << indent(ind) << "&&" << labelPrefix << it->second->label << ",\n";
- vUsedLabels.insert(it->second->label);
}
o << indent(--ind) << "};\n";
o << indent(ind) << "goto *" << mapCodeName["yytarget"] << "[" << mapCodeName["yyaccept"] << "];\n";
}
o << indent(ind) << "goto " << labelPrefix << to->label << ";\n";
- vUsedLabels.insert(to->label);
}
void State::emit(Output & output, uint32_t ind, bool &readCh, const std::string& condName) const
{
OutputFile & o = output.source;
- if (vUsedLabels.count(label))
+ if (!DFlag)
{
- o << labelPrefix << label << ":\n";
- }
- if (dFlag && (action.type != Action::INITIAL))
- {
- o << indent(ind) << mapCodeName["YYDEBUG"] << "(" << label << ", " << input_api.expr_peek () << ");\n";
- }
- if (isPreCtxt && !DFlag)
- {
- o << input_api.stmt_backupctx (ind);
+ if (vUsedLabels.count(label))
+ {
+ o << labelPrefix << label << ":\n";
+ }
+ if (dFlag && (action.type != Action::INITIAL))
+ {
+ o << indent(ind) << mapCodeName["YYDEBUG"] << "(" << label << ", " << input_api.expr_peek () << ");\n";
+ }
+ if (isPreCtxt)
+ {
+ o << input_api.stmt_backupctx (ind);
+ }
}
emit_action (action, o, ind, readCh, this, condName);
}
{
s->go.used_labels ();
}
+ for (accept_t::const_iterator it = accept_map.begin(); it != accept_map.end(); ++it)
+ {
+ vUsedLabels.insert(it->second->label);
+ }
// Save 'next_fill_index' and compute information about code generation
// while writing to null device.
}
uint32_t nSaves = 0;
- saves = new uint32_t[nRules];
+ uint32_t * saves = new uint32_t[nRules];
memset(saves, ~0, (nRules)*sizeof(*saves));
// mark backtracking points
}
// insert actions
- rules = new State * [nRules];
-
+ State ** rules = new State * [nRules];
memset(rules, 0, (nRules)*sizeof(*rules));
State *accept = NULL;
if (accfixup)
{
- accfixup->action.set_accept (nRules, saves, rules);
+ for (uint32_t i = 0; i < nRules; ++i)
+ {
+ if (saves[i] != ~0u)
+ {
+ accept_map[saves[i]] = rules[i];
+ }
+ }
+ accfixup->action.set_accept (&accept_map);
}
+ delete [] saves;
+ delete [] rules;
// split ``base'' states into two parts
for (s = head; s; s = s->next)
{
Initial * initial;
uint32_t save;
- accept_t * accept;
+ const accept_t * accept;
const RuleOp * rule;
} info;
clear ();
type = MOVE;
}
- void set_accept (uint32_t rules_count, uint32_t * saves, State * const * rules)
+ void set_accept (const accept_t * accept)
{
clear ();
type = ACCEPT;
- info.accept = new accept_t ();
- for (uint32_t i = 0; i < rules_count; ++i)
- {
- if (saves[i] != ~0u)
- {
- (* info.accept)[saves[i]] = rules[i];
- }
- }
+ info.accept = accept;
}
void set_rule (const RuleOp * const rule)
{
case INITIAL:
delete info.initial;
break;
- case ACCEPT:
- delete info.accept;
- break;
case MATCH:
case SAVE:
case MOVE:
+ case ACCEPT:
case RULE:
break;
}
, free_ins(ins)
, free_rep(rep)
, bSaveOnHead (false)
- , saves (NULL)
- , rules (NULL)
+ , accept_map ()
{
Ins **work = new Ins * [ni + 1];
}
delete [] free_ins;
delete [] free_rep;
- delete [] saves;
- delete [] rules;
}
void DFA::addState(State **a, State *s)
protected:
bool bSaveOnHead;
- uint32_t * saves;
- State ** rules;
+ accept_t accept_map;
public:
DFA (Ins *, uint32_t, uint32_t, uint32_t, const Char *);