}
}
-Move::Move(State *s) : Action(s)
-{
- ;
-}
-
void Move::emit(Output &, uint, bool &, const std::string&) const
{
;
}
-Accept::Accept(State *x, uint n, uint *s, State **r)
- : Action(x), nRules(n), saves(s), rules(r)
-{
- ;
-}
-
void Accept::genRuleMap()
{
for (uint i = 0; i < nRules; ++i)
}
}
-Rule::Rule(State *s, RuleOp *r) : Action(s), rule(r)
-{
- ;
-}
-
void Rule::emit(Output & output, uint ind, bool &, const std::string& condName) const
{
OutputFile & o = output.source;
static void generate_data (State * s, bool def, const std::vector<std::vector<uint> > & xs, std::vector<std::pair<std::vector<uint>, bool> > & ys)
{
- if (s->go.nSpans <= 1)
+ switch (s->action->type)
{
- for (uint i = 0; i < xs.size (); ++i)
- {
- ys.push_back (std::make_pair (std::vector<uint> (xs[i]), def));
- }
- }
- else if (s->generated)
- {
- return;
- }
- else
- {
- s->generated = true;
- for (uint i = 0; i < s->go.nSpans; ++i)
- {
- std::vector<std::vector<uint> > zs;
- for (uint j = 0; j < xs.size (); ++j)
+ case Action::NONE:
+ assert (false);
+ break;
+ case Action::RULE:
+ case Action::ACCEPT:
+ for (uint i = 0; i < xs.size (); ++i)
{
- std::vector<uint> z (xs[j]);
- z.push_back (s->go.span[i].ub - 1);
- zs.push_back (z);
+ ys.push_back (std::make_pair (std::vector<uint> (xs[i]), def));
+ if (!def)
+ {
+ ys.back ().first.pop_back ();
+ }
}
- generate_data (s->go.span[i].to, s->go.span[i].is_default, zs, ys);
- }
+ break;
+ case Action::MOVE:
+ if (!s->generated)
+ {
+ s->generated = true;
+ generate_data (s->go.span[0].to, s->go.span[0].is_default, xs, ys);
+ }
+ break;
+ case Action::MATCH:
+ case Action::ENTER:
+ case Action::INITIAL:
+ case Action::SAVE:
+ if (!s->generated)
+ {
+ s->generated = true;
+ for (uint i = 0; i < s->go.nSpans; ++i)
+ {
+ std::vector<std::vector<uint> > zs;
+ for (uint j = 0; j < xs.size (); ++j)
+ {
+ std::vector<uint> z (xs[j]);
+ z.push_back (s->go.span[i].ub - 1);
+ zs.push_back (z);
+ }
+ generate_data (s->go.span[i].to, s->go.span[i].is_default, zs, ys);
+ }
+ }
+ break;
}
}
{
OutputFile & o = output.source;
- if (flag_skeleton)
- {
- output_skeleton_prolog (output, ind);
- }
-
bool bProlog = (!cFlag || !bWroteCondCheck);
// In -c mode, the prolog needs its own label separate from start_label.
}
next_fill_index = save_fill_index;
+ if (flag_skeleton)
+ {
+ output_skeleton_prolog (output, ind);
+ }
// Generate prolog
if (bProlog)
{
{
o << indent(--ind) << "}\n";
}
+ if (flag_skeleton)
+ {
+ output_skeleton_epilog (o, ind);
+ }
// Cleanup
if (BitMap::first)
}
bUseStartLabel = false;
-
- if (flag_skeleton)
- {
- output_skeleton_epilog (o, ind);
- }
}
static void output_state_goto_sub (std::ostream & o, uint ind, uint start_label, int cMin, int cMax)
public:
State *state;
+ enum type_t
+ {
+ NONE,
+ MATCH,
+ ENTER,
+ INITIAL,
+ SAVE,
+ MOVE,
+ ACCEPT,
+ RULE
+ } type;
public:
Action(State*);
protected:
Action(const Action& oth)
: state(oth.state)
+ , type(oth.type)
{
}
Action& operator = (const Action& oth)
{
state = oth.state;
+ type = oth.type;
return *this;
}
#endif
#endif
};
-inline Action::Action(State *s) : state(s)
+inline Action::Action(State *s) : state(s), type(NONE)
{
delete s->action;
s->action = this;
}
inline Match::Match(State *s) : Action(s)
-{ }
+{
+ type = MATCH;
+}
inline bool Match::isMatch() const
{
}
inline Enter::Enter(State *s, uint l) : Action(s), label(l)
-{ }
+{
+ type = ENTER;
+}
inline Initial::Initial(State *s, uint l, bool b) : Enter(s, l), setMarker(b)
-{ }
+{
+ type = INITIAL;
+}
inline bool Initial::isInitial() const
{
}
inline Save::Save(State *s, uint i) : Match(s), selector(i)
-{ }
+{
+ type = SAVE;
+}
inline bool Save::isMatch() const
{
return false;
}
+inline Move::Move(State *s) : Action(s)
+{
+ type = MOVE;
+}
+
+inline Accept::Accept(State *x, uint n, uint *s, State **r)
+ : Action(x), nRules(n), saves(s), rules(r)
+{
+ type = ACCEPT;
+}
+
+inline Rule::Rule(State *s, RuleOp *r) : Action(s), rule(r)
+{
+ type = RULE;
+}
+
inline bool Rule::isRule() const
{
return true;