o << "\tgoto yy" << to->label << ";\n";
++oline;
+ vUsedLabels.append(to->label);
}
void genIf(std::ostream &o, char *cmp, uint v, bool &readCh)
void State::emit(std::ostream &o, bool &readCh)
{
- o << "yy" << label << ":";
+ if (vUsedLabels.contains(label))
+ {
+ o << "yy" << label << ":";
+ }
/* o << "\nfprintf(stderr, \"<" << label << ">\");\n";*/
action->emit(o, readCh);
}
s->go.span[0].to = move;
}
+class null_stream: public std::ostream
+{
+public:
+ null_stream()
+ : std::ostream(&ns)
+ {
+ }
+
+ null_stream& put(char_type)
+ {
+ // nothing to do
+ return *this;
+ }
+
+ null_stream& write(const char_type *, std::streamsize)
+ {
+ // nothing to do
+ return *this;
+ }
+
+protected:
+ class null_streambuf: public std::streambuf
+ {
+ public:
+ null_streambuf()
+ : std::streambuf()
+ {
+ }
+ };
+ null_streambuf ns;
+};
+
void DFA::emit(std::ostream &o)
{
static uint label = 0;
o << "\tgoto yy" << label << ";\n";
++oline;
+ vUsedLabels.append(label);
(void) new Enter(head, label++);
for (s = head; s; s = s->next)
s->label = label++;
}
+ null_stream noWhere;
+
+ unsigned int nOrgOline = oline;
+ for (s = head; s; s = s->next)
+ {
+ bool readCh = false;
+ s->emit(noWhere, readCh);
+ s->go.genGoto(noWhere, s, s->next, readCh);
+ }
+ oline = nOrgOline;
+
for (s = head; s; s = s->next)
{
bool readCh = false;
#define _globals_h
#include "basics.h"
+#include <list>
+#include <algorithm>
+
+template<typename _Ty>
+class label_list: protected std::list<_Ty>
+{
+public:
+ label_list()
+ : std::list<_Ty>()
+ {
+ }
+
+ void append(const _Ty &val)
+ {
+ push_back(val);
+ sort();
+ unique();
+ }
+
+ bool contains(const _Ty &val)
+ {
+ return std::find(begin(), end(), val) != end();
+ }
+};
namespace re2c
{
extern uchar *xlat, *talx;
+extern label_list<uint> vUsedLabels;
+
} // end namespace re2c
#endif