, bool & readCh
, const State * const s
, const std::string & condName
- , const std::set<uint32_t> & used_labels
+ , const std::set<label_t> & used_labels
);
// helpers
static void need (OutputFile & o, uint32_t ind, bool & readCh, uint32_t n, bool bSetMarker);
static void emit_match (OutputFile & o, uint32_t ind, bool & readCh, const State * const s);
-static void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const Initial & init, const std::set<uint32_t> & used_labels);
+static void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const Initial & init, const std::set<label_t> & used_labels);
static void emit_save (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, uint32_t save);
static void emit_accept_binary (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accept, uint32_t l, uint32_t r);
static void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accept);
, bool & readCh
, const State * const s
, const std::string & condName
- , const std::set<uint32_t> & used_labels
+ , const std::set<label_t> & used_labels
)
{
switch (action.type)
}
}
-void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const Initial & initial, const std::set<uint32_t> & used_labels)
+void emit_initial (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const Initial & initial, const std::set<label_t> & used_labels)
{
if (DFlag)
{
{
o << labelPrefix << initial.label << ":\n";
}
- else if (!initial.label)
+ else if (initial.label == label_counter_t::FIRST)
{
o << "\n";
}
}
}
-void DFA::count_used_labels (std::set<uint32_t> & used, uint32_t start, uint32_t initial, bool force_start) const
+void DFA::count_used_labels (std::set<label_t> & used, label_t start, label_t initial, bool force_start) const
{
// In '-f' mode, default state is always state 0
if (fFlag)
{
- used.insert (Label::FIRST_LABEL);
+ used.insert (label_counter_t::FIRST);
}
if (force_start)
{
// start_label points to the beginning of current re2c block
// (prior to condition dispatch in '-c' mode)
// it can forced by configuration 're2c:startlabel = <integer>;'
- uint32_t start_label = o.label.new_label ();
+ label_t start_label = o.label_counter.next ();
// initial_label points to the beginning of DFA
// in '-c' mode this is NOT equal to start_label
- uint32_t initial_label = bProlog && cFlag
- ? o.label.new_label ()
+ label_t initial_label = bProlog && cFlag
+ ? o.label_counter.next ()
: start_label;
for (State * s = head; s; s = s->next)
{
- s->label = o.label.new_label ();
+ s->label = o.label_counter.next ();
}
- std::set<uint32_t> used_labels;
+ std::set<label_t> used_labels;
count_used_labels (used_labels, start_label, initial_label, o.get_force_start_label ());
head->action.set_initial (initial_label, bSaveOnHead);
Cases (const Span * s, uint32_t n);
~Cases ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
FORBID_COPY (Cases);
};
Binary (const Span * s, uint32_t n, const State * next);
~Binary ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
FORBID_COPY (Binary);
};
Linear (const Span * s, uint32_t n, const State * next);
~Linear ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
};
struct If
If (type_t t, const Span * sp, uint32_t nsp, const State * next);
~If ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
};
struct SwitchIf
SwitchIf (const Span * sp, uint32_t nsp, const State * next);
~SwitchIf ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
};
struct GoBitmap
GoBitmap (const Span * span, uint32_t nSpans, const Span * hspan, uint32_t hSpans, const BitMap * bm, const State * bm_state, const State * next);
~GoBitmap ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
FORBID_COPY (GoBitmap);
};
CpgotoTable (const Span * span, uint32_t nSpans);
~CpgotoTable ();
void emit (OutputFile & o, uint32_t ind);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
private:
- uint32_t max_label ();
+ label_t max_label () const;
FORBID_COPY (CpgotoTable);
};
Cpgoto (const Span * span, uint32_t nSpans, const Span * hspan, uint32_t hSpans, const State * next);
~Cpgoto ();
void emit (OutputFile & o, uint32_t ind, bool & readCh);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
FORBID_COPY (Cpgoto);
};
~Go ();
void init (const State * from);
void emit (OutputFile & o, uint32_t ind, bool & readCh);
- void used_labels (std::set<uint32_t> & used);
+ void used_labels (std::set<label_t> & used);
Go (const Go & g)
: nSpans (g.nSpans)
namespace re2c
{
-static uint32_t digits (uint32_t n);
static void output_if (OutputFile & o, uint32_t ind, bool & readCh, const std::string & compare, uint32_t value);
-static void output_goto (OutputFile & o, uint32_t ind, bool & readCh, uint32_t to);
+static void output_goto (OutputFile & o, uint32_t ind, bool & readCh, label_t to);
static std::string output_yych (bool & readCh);
static std::string output_hgo (OutputFile & o, uint32_t ind, bool & readCh, SwitchIf * hgo);
-uint32_t digits (uint32_t n)
-{
- uint32_t digits = 0;
- while (n /= 10) ++digits;
- return digits;
-}
-
std::string output_yych (bool & readCh)
{
if (readCh)
o << ") ";
}
-void output_goto (OutputFile & o, uint32_t ind, bool & readCh, uint32_t to)
+void output_goto (OutputFile & o, uint32_t ind, bool & readCh, label_t to)
{
if (readCh)
{
}
}
-uint32_t CpgotoTable::max_label ()
+label_t CpgotoTable::max_label () const
{
- uint32_t max = 0;
+ label_t max = label_counter_t::FIRST;
for (uint32_t i = 0; i < TABLE_SIZE; ++i)
{
- if (table[i]->label > max)
+ if (max < table[i]->label)
{
max = table[i]->label;
};
{
o << indent (ind) << "static void *" << mapCodeName["yytarget"] << "[256] = {\n";
o << indent (++ind);
- const uint32_t max_digits = digits (max_label ());
+ const uint32_t max_digits = width (max_label ());
for (uint32_t i = 0; i < TABLE_SIZE; ++i)
{
o << "&&" << labelPrefix << table[i]->label;
}
else
{
- const uint32_t padding = max_digits - digits (table[i]->label) + 1;
+ const uint32_t padding = max_digits - width (table[i]->label) + 1;
o << "," << std::string (padding, ' ');
}
}
namespace re2c
{
-void Cases::used_labels (std::set<uint32_t> & used)
+void Cases::used_labels (std::set<label_t> & used)
{
for (uint32_t i = 0; i < cases_size; ++i)
{
}
}
-void Binary::used_labels (std::set<uint32_t> & used)
+void Binary::used_labels (std::set<label_t> & used)
{
thn->used_labels (used);
els->used_labels (used);
}
-void Linear::used_labels (std::set<uint32_t> & used)
+void Linear::used_labels (std::set<label_t> & used)
{
for (uint32_t i = 0; i < branches.size (); ++i)
{
}
}
-void If::used_labels (std::set<uint32_t> & used)
+void If::used_labels (std::set<label_t> & used)
{
switch (type)
{
}
}
-void SwitchIf::used_labels (std::set<uint32_t> & used)
+void SwitchIf::used_labels (std::set<label_t> & used)
{
switch (type)
{
}
}
-void GoBitmap::used_labels (std::set<uint32_t> & used)
+void GoBitmap::used_labels (std::set<label_t> & used)
{
if (hgo != NULL)
{
}
}
-void CpgotoTable::used_labels (std::set<uint32_t> & used)
+void CpgotoTable::used_labels (std::set<label_t> & used)
{
for (uint32_t i = 0; i < TABLE_SIZE; ++i)
{
}
}
-void Cpgoto::used_labels (std::set<uint32_t> & used)
+void Cpgoto::used_labels (std::set<label_t> & used)
{
if (hgo != NULL)
{
table->used_labels (used);
}
-void Go::used_labels (std::set<uint32_t> & used)
+void Go::used_labels (std::set<label_t> & used)
{
switch (type)
{
+#include <ostream>
+
#include "src/codegen/label.h"
namespace re2c {
-const uint32_t Label::FIRST_LABEL = 0;
+const label_t label_counter_t::FIRST (0);
+
+std::ostream & operator << (std::ostream & o, label_t l)
+{
+ o << l.value;
+ return o;
+}
+
+bool operator < (const label_t & l1, const label_t & l2)
+{
+ return l1.value < l2.value;
+}
+
+bool operator == (const label_t & l1, const label_t & l2)
+{
+ return l1.value == l2.value;
+}
+
+uint32_t width (label_t l)
+{
+ uint32_t digits = 0;
+ while (l.value /= 10) ++digits;
+ return digits;
+}
} // namespace re2c
#ifndef __LABEL__
#define __LABEL__
+#include <iosfwd>
+
#include "src/util/c99_stdint.h"
namespace re2c {
-class Label
+class label_t
+{
+ uint32_t value;
+ explicit label_t (uint32_t v)
+ : value (v)
+ {}
+ friend class label_counter_t;
+ friend std::ostream & operator << (std::ostream & o, label_t l);
+ friend bool operator < (const label_t & l1, const label_t & l2);
+ friend bool operator == (const label_t & l1, const label_t & l2);
+ friend uint32_t width (label_t l);
+};
+
+class label_counter_t
{
public:
- static const uint32_t FIRST_LABEL;
+ static const label_t FIRST;
private:
- uint32_t next;
+ label_t label;
public:
- Label ()
- : next (FIRST_LABEL)
+ label_counter_t ()
+ : label (FIRST)
{}
- uint32_t new_label ()
+ label_t next ()
{
- return next++;
+ label_t l = label;
+ ++label.value;
+ return l;
}
void reset ()
{
- next = FIRST_LABEL;
+ label = FIRST;
}
};
: file_name (fn)
, file (NULL)
, blocks ()
- , label ()
+ , label_counter ()
{
new_block ();
}
return u;
}
+OutputFile & operator << (OutputFile & u, label_t l)
+{
+ u.stream () << l;
+ return u;
+}
+
void OutputFile::insert_code ()
{
blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::CODE, 0));
std::vector<OutputBlock *> blocks;
public:
- Label label;
+ label_counter_t label_counter;
private:
std::ostream & stream ();
friend OutputFile & operator << (OutputFile & o, uint32_t n);
friend OutputFile & operator << (OutputFile & o, const std::string & s);
friend OutputFile & operator << (OutputFile & o, const char * s);
+ friend OutputFile & operator << (OutputFile & o, label_t l);
void insert_line_info ();
void insert_state_goto (uint32_t ind);
#include <map>
+#include "src/codegen/label.h"
#include "src/util/c99_stdint.h"
namespace re2c
struct Initial
{
- uint32_t label;
+ label_t label;
bool setMarker;
- inline Initial (uint32_t l, bool b)
+ inline Initial (label_t l, bool b)
: label (l)
, setMarker (b)
{}
{
clear ();
}
- void set_initial (uint32_t label, bool used_marker)
+ void set_initial (label_t label, bool used_marker)
{
clear ();
type = INITIAL;
void findSCCs ();
void findBaseState ();
void prepare (uint32_t &);
- void count_used_labels (std::set<uint32_t> & used, uint32_t prolog, uint32_t start, bool force_start) const;
+ void count_used_labels (std::set<label_t> & used, label_t prolog, label_t start, bool force_start) const;
void emit (Output &, uint32_t &, const RegExpMap *, const std::string &, bool, bool &);
friend std::ostream & operator << (std::ostream &, const DFA &);
class State
{
public:
- uint32_t label;
+ label_t label;
RuleOp * rule;
State * next;
State * link;
Action action;
State ()
- : label (0)
+ : label (label_counter_t::FIRST)
, rule (NULL)
, next (0)
, link (NULL)
void Scanner::reuse()
{
- out.label.reset ();
+ out.label_counter.reset ();
last_fill_index = 0;
bWroteGetState = false;
bWroteCondCheck = false;