src/util/range.h \
src/util/smart_ptr.h \
src/util/substr.h \
+ src/util/uniq_vector.h \
src/util/wrap_iterator.h
SRC = \
src/codegen/bitmap.cc \
genGoTo(o, 0, s, accepts[i], readCh);
}
o << indent(ind) << "default:\t";
- genGoTo(o, 0, s, accepts.back (), readCh);
+ genGoTo(o, 0, s, accepts[accepts_size - 1], readCh);
o << indent(ind) << "}\n";
}
}
else
{
// no need to write if statement here since there is only case 0.
- genGoTo(o, ind, s, accepts.front (), readCh);
+ genGoTo(o, ind, s, accepts[0], readCh);
}
}
}
{
s->go.used_labels (used);
}
- for (accept_t::const_iterator i = accepts.begin (); i != accepts.end (); ++i)
+ for (uint32_t i = 0; i < accepts.size (); ++i)
{
- used.insert ((*i)->label);
+ used.insert (accepts[i]->label);
}
// must go last: it needs the set of used labels
if (used.count (head->label))
findSCCs();
head->link = head;
- uint32_t nRules = 0;
-
for (State * s = head; s; s = s->next)
{
s->depth = maxDist(s);
{
max_fill = s->depth;
}
- if (s->rule && s->rule->accept >= nRules)
- {
- nRules = s->rule->accept + 1;
- }
}
// create rule states
- State ** rules = new State * [nRules];
- memset(rules, 0, (nRules)*sizeof(*rules));
+ std::map<uint32_t, State *> rules;
for (State * s = head; s; s = s->next)
{
if (s->rule)
{
- if (!rules[s->rule->accept])
+ if (rules.find (s->rule->accept) == rules.end ())
{
State *n = new State;
n->action.set_rule (s->rule);
// find backup states and create accept state (if needed)
if (default_state)
{
- uint32_t nSaves = 0;
- uint32_t * saves = new uint32_t[nRules];
- memset(saves, ~0, (nRules)*sizeof(*saves));
for (State * s = head; s; s = s->next)
{
if (s->rule)
{
if (!s->go.span[i].to->rule && s->go.span[i].to->action.type != Action::RULE)
{
- if (saves[s->rule->accept] == ~0u)
- {
- saves[s->rule->accept] = nSaves++;
- accepts.push_back (rules[s->rule->accept]);
- }
- s->action.set_save (saves[s->rule->accept]);
+ const uint32_t accept = accepts.find_or_add (rules[s->rule->accept]);
+ s->action.set_save (accept);
}
}
}
}
- delete [] saves;
if (accepts.size () > 1)
{
o.set_used_yyaccept ();
}
default_state->action.set_accept (&accepts);
}
- delete [] rules;
// split ``base'' states into two parts
for (State * s = head; s; s = s->next)
#include "src/codegen/label.h"
#include "src/util/c99_stdint.h"
+#include "src/util/uniq_vector.h"
namespace re2c
{
{}
};
-typedef std::vector<const State *> accept_t;
+typedef uniq_vector_t<const State *> accept_t;
class Action
{
--- /dev/null
+#ifndef __UNIQ_VECTOR__
+#define __UNIQ_VECTOR__
+
+#include <vector>
+
+#include "src/util/c99_stdint.h"
+
+namespace re2c
+{
+
+// wrapper over std::vector
+// O(n) lookup
+// O(n^2) insertion
+template <typename value_t>
+class uniq_vector_t
+{
+ typedef std::vector<value_t> elems_t;
+ elems_t elems;
+public:
+ uniq_vector_t ()
+ : elems ()
+ {}
+ uint32_t size () const
+ {
+ return elems.size ();
+ }
+ const value_t & operator [] (uint32_t i) const
+ {
+ return elems[i];
+ }
+ uint32_t find_or_add (const value_t & v)
+ {
+ const uint32_t size = elems.size ();
+ for (uint32_t i = 0; i < size; ++i)
+ {
+ if (elems[i] == v)
+ {
+ return i;
+ }
+ }
+ elems.push_back (v);
+ return size;
+ }
+};
+
+} // namespace re2c
+
+#endif // __UNIQ_VECTOR__