-#include <string.h>
+#include <algorithm>
#include "src/ir/dfa/closure.h"
#include "src/ir/nfa/nfa.h"
}
prune_final_items(clos2, rules);
+
+ // sort closure: we need this to compare closures by hash
+ std::sort(clos2.begin(), clos2.end(), compare_by_rule);
}
/* note [epsilon-closures in tagged NFA]
inline clos_t();
inline clos_t(nfa_state_t *s, size_t i);
- static inline bool compare(const clos_t &c1, const clos_t &c2);
static inline bool final(const clos_t &c);
static inline bool not_final(const clos_t &c);
};
, tagidx(i)
{}
-bool clos_t::compare(const clos_t &c1, const clos_t &c2)
-{
- const nfa_state_t
- *s1 = c1.state,
- *s2 = c2.state;
- return s1 < s2
- || (s1 == s2 && c1.tagidx < c2.tagidx);
-}
-
bool clos_t::final(const clos_t &c)
{
return c.state->type == nfa_state_t::FIN;
return lookup.push(hash, new closure_t(clos));
}
-size_t find_state(closure_t &clos, clospool_t &clospool)
+size_t find_state(const closure_t &clos, clospool_t &clospool)
{
// empty closure corresponds to default state
if (clos.empty()) {
return dfa_t::NIL;
}
- // sort closure to allow comparison by hash and 'memcmp'
- std::sort(clos.begin(), clos.end(), clos_t::compare);
-
return clospool.insert(clos);
}
size_t insert(const closure_t &clos);
};
-size_t find_state(closure_t &clos, clospool_t &clospool);
+size_t find_state(const closure_t &clos, clospool_t &clospool);
} // namespace re2c