-/* Generated by re2c 0.16 on Sun Apr 3 08:30:42 2016 */
+/* Generated by re2c 0.16 on Tue Apr 5 23:00:02 2016 */
#line 1 "../src/parse/lex.re"
#include "src/util/c99_stdint.h"
#include <stddef.h>
-/* Generated by re2c 0.16 on Tue Apr 5 11:39:03 2016 */
+/* Generated by re2c 0.16 on Tue Apr 5 23:00:02 2016 */
#line 1 "../src/parse/lex_conf.re"
#include "src/util/c99_stdint.h"
#include <string>
if (yych == '=') goto yy334;
yy273:
#line 163 "../src/parse/lex_conf.re"
- { out.set_user_start_label (lex_conf_string ()); return; }
+ { out.block().user_start_label = lex_conf_string(); return; }
#line 1329 "src/parse/lex_conf.cc"
yy274:
yych = (unsigned char)*++cur;
yy396:
cur = ctx;
#line 162 "../src/parse/lex_conf.re"
- { out.set_force_start_label (lex_conf_bool()); return; }
+ { out.block().force_start_label = lex_conf_bool(); return; }
#line 1835 "src/parse/lex_conf.cc"
yy397:
++cur;
}
encodingOld = opts->encoding;
}
- o.source.set_block_line (in->get_cline ());
+ o.source.block().line = in->get_cline();
uint32_t ind = opts->topIndent;
if (opts->cFlag)
{
// Note that "0" inserts first, which is important.
condnames.insert (condnames.begin (), "0");
}
- o.types = condnames;
}
+ o.source.block().types = condnames;
size_t nCount = specMap.size();
void DFA::emit(Output & output, uint32_t& ind, bool isLastCond, bool& bPrologBrace)
{
- OutputFile & o = output.source;
+ OutputFile &o = output.source;
+ OutputBlock &ob = o.block();
std::set<std::string> ctxnames;
if (base_ctxmarker) {
ctxnames.insert(contexts[*i].name());
}
}
- output.contexts.insert(ctxnames.begin(), ctxnames.end());
+ ob.contexts.insert(ctxnames.begin(), ctxnames.end());
}
bool bProlog = (!opts->cFlag || !bWroteCondCheck);
s->label = o.label_counter.next ();
}
std::set<label_t> used_labels;
- count_used_labels (used_labels, start_label, initial_label, o.get_force_start_label ());
+ count_used_labels (used_labels, start_label, initial_label, ob.force_start_label);
head->action.set_initial (initial_label, head->action.type == Action::SAVE);
emit_end(*skeleton, o, need_backup, need_backupctx);
}
} else if (opts->target == opt_t::DOT) {
- emit_dot(o, isLastCond, output.types);
+ emit_dot(o, isLastCond, ob.types);
} else {
// Generate prolog
if (bProlog)
{
o.ws("\n").wdelay_line_info ();
- if ((!opts->fFlag && o.get_used_yyaccept ())
+ if ((!opts->fFlag && ob.used_yyaccept)
|| (!opts->fFlag && opts->bEmitYYCh)
|| (opts->bFlag && !opts->cFlag && BitMap::first)
|| (opts->cFlag && !bWroteCondCheck && opts->gFlag)
o.wind(ind).wstring(opts->yyctype).ws(" ").wstring(opts->yych).ws(";\n");
}
o.wdelay_yyaccept_init (ind);
- if (base_ctxmarker) {
- o.wdelay_contexts(ind, NULL);
- o.wstring(opts->input_api.stmt_backupctx(ind));
- }
+ o.wdelay_contexts(ind, NULL);
}
else
{
{
if (opts->cFlag && !bWroteCondCheck && opts->gFlag)
{
- genCondTable(o, ind, output.types);
+ genCondTable(o, ind, ob.types);
}
o.wdelay_state_goto (ind);
if (opts->cFlag)
o.wuser_start_label ();
if (opts->cFlag && !bWroteCondCheck)
{
- genCondGoto(o, ind, output.types);
+ genCondGoto(o, ind, ob.types);
}
}
if (opts->cFlag && !cond.empty())
}
o.wstring(opts->condPrefix).wstring(cond).ws(":\n");
}
+ if (base_ctxmarker) {
+ o.wstring(opts->input_api.stmt_backupctx(ind));
+ }
if (opts->cFlag && opts->bFlag && BitMap::first)
{
o.wind(ind++).ws("{\n");
, force_start_label (false)
, user_start_label ()
, line (0)
+ , types ()
+ , contexts ()
{
fragments.push_back (new OutputFragment (OutputFragment::CODE, 0));
}
}
}
+OutputBlock& OutputFile::block()
+{
+ return *blocks.back();
+}
+
std::ostream & OutputFile::stream ()
{
- return blocks.back ()->fragments.back ()->stream;
+ return block().fragments.back ()->stream;
}
OutputFile &OutputFile::wraw(const char *s, const char *e)
OutputFile & OutputFile::wuser_start_label ()
{
- const std::string label = blocks.back ()->user_start_label;
+ const std::string label = block().user_start_label;
if (!label.empty ())
{
wstring(label).ws(":\n");
void OutputFile::insert_code ()
{
- blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::CODE, 0));
+ block().fragments.push_back (new OutputFragment (OutputFragment::CODE, 0));
}
OutputFile &OutputFile::wdelay_contexts(uint32_t ind, const ConfContexts *cf)
OutputFile & OutputFile::wdelay_line_info ()
{
- blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::LINE_INFO, 0));
+ block().fragments.push_back (new OutputFragment (OutputFragment::LINE_INFO, 0));
insert_code ();
return *this;
}
{
if (opts->fFlag && !bWroteGetState)
{
- blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::STATE_GOTO, ind));
+ block().fragments.push_back (new OutputFragment (OutputFragment::STATE_GOTO, ind));
insert_code ();
bWroteGetState = true;
}
OutputFile & OutputFile::wdelay_types ()
{
warn_condition_order = false; // see note [condition order]
- blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::TYPES, 0));
+ block().fragments.push_back (new OutputFragment (OutputFragment::TYPES, 0));
insert_code ();
return *this;
}
OutputFile & OutputFile::wdelay_warn_condition_order ()
{
- blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::WARN_CONDITION_ORDER, 0));
+ block().fragments.push_back (new OutputFragment (OutputFragment::WARN_CONDITION_ORDER, 0));
insert_code ();
return *this;
}
OutputFile & OutputFile::wdelay_yyaccept_init (uint32_t ind)
{
- blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::YYACCEPT_INIT, ind));
+ block().fragments.push_back (new OutputFragment (OutputFragment::YYACCEPT_INIT, ind));
insert_code ();
return *this;
}
OutputFile & OutputFile::wdelay_yymaxfill ()
{
- blocks.back ()->fragments.push_back (new OutputFragment (OutputFragment::YYMAXFILL, 0));
+ block().fragments.push_back (new OutputFragment (OutputFragment::YYMAXFILL, 0));
insert_code ();
return *this;
}
-void OutputFile::set_used_yyaccept ()
-{
- blocks.back ()->used_yyaccept = true;
-}
-
-bool OutputFile::get_used_yyaccept () const
-{
- return blocks.back ()->used_yyaccept;
-}
-
-void OutputFile::set_force_start_label (bool force)
-{
- blocks.back ()->force_start_label = force;
-}
-
-void OutputFile::set_user_start_label (const std::string & label)
-{
- blocks.back ()->user_start_label = label;
-}
-
-bool OutputFile::get_force_start_label () const
+void OutputFile::new_block ()
{
- return blocks.back ()->force_start_label;
+ blocks.push_back (new OutputBlock ());
+ insert_code ();
}
-void OutputFile::set_block_line (uint32_t l)
+void OutputFile::global_lists(
+ uniq_vector_t<std::string> &types,
+ std::set<std::string> &contexts) const
{
- blocks.back ()->line = l;
-}
+ for (unsigned int i = 0; i < blocks.size(); ++i) {
-uint32_t OutputFile::get_block_line () const
-{
- return blocks.back ()->line;
-}
+ const std::vector<std::string> &ts = blocks[i]->types;
+ for (size_t j = 0; j < ts.size(); ++j) {
+ types.find_or_add(ts[j]);
+ }
-void OutputFile::new_block ()
-{
- blocks.push_back (new OutputBlock ());
- insert_code ();
+ const std::set<std::string> &cs = blocks[i]->contexts;
+ contexts.insert(cs.begin(), cs.end());
+ }
}
void OutputFile::emit(
- const std::vector<std::string> &types,
- const std::set<std::string> &contexts,
+ const uniq_vector_t<std::string> &global_types,
+ const std::set<std::string> &global_contexts,
size_t max_fill)
{
if (file != NULL)
break;
case OutputFragment::CONTEXTS:
if (f.contexts) {
- output_contexts(f.stream, *f.contexts, contexts);
+ output_contexts(f.stream, *f.contexts, global_contexts);
} else if (default_contexts) {
- output_contexts_default(f.stream, f.indent, contexts);
+ output_contexts_default(f.stream, f.indent, b.contexts);
}
break;
case OutputFragment::LINE_INFO:
output_state_goto (f.stream, f.indent, 0);
break;
case OutputFragment::TYPES:
- output_types (f.stream, f.indent, types);
+ output_types (f.stream, f.indent, global_types);
break;
case OutputFragment::WARN_CONDITION_ORDER:
if (warn_condition_order) // see note [condition order]
return file != NULL;
}
-void HeaderFile::emit (const std::vector<std::string> & types)
+void HeaderFile::emit(const uniq_vector_t<std::string> &types)
{
output_version_time (stream);
output_line_info (stream, 3, file_name);
stream << "\n";
- output_types (stream, 0, types);
+ output_types(stream, 0, types);
}
HeaderFile::~HeaderFile ()
Output::Output(const std::string &source_name, const std::string &header_name)
: source(source_name)
, header(header_name)
- , types()
, skeletons()
- , contexts()
, max_fill(1)
{}
{
if (!warn.error ())
{
- source.emit (types, contexts, max_fill);
- header.emit (types);
+ uniq_vector_t<std::string> types;
+ std::set<std::string> contexts;
+ source.global_lists(types, contexts);
+
+ source.emit(types, contexts, max_fill);
+ header.emit(types);
}
}
}
}
-void output_types (std::ostream & o, uint32_t ind, const std::vector<std::string> & types)
+void output_types(
+ std::ostream &o,
+ uint32_t ind,
+ const uniq_vector_t<std::string> &types)
{
- o << indent (ind++) << "enum " << opts->yycondtype << " {\n";
- for (unsigned int i = 0; i < types.size (); ++i)
- {
- o << indent (ind) << opts->condEnumPrefix << types[i] << ",\n";
+ o << indent(ind++) << "enum " << opts->yycondtype << " {\n";
+ for (size_t i = 0; i < types.size(); ++i) {
+ o << indent(ind) << opts->condEnumPrefix << types[i] << ",\n";
}
- o << indent (--ind) << "};\n";
+ o << indent(--ind) << "};\n";
}
void output_version_time (std::ostream & o)
#include "src/codegen/label.h"
#include "src/util/counter.h"
#include "src/util/forbid_copy.h"
+#include "src/util/uniq_vector.h"
namespace re2c
{
bool force_start_label;
std::string user_start_label;
uint32_t line;
+ std::vector<std::string> types;
+ std::set<std::string> contexts;
OutputBlock ();
~OutputBlock ();
~OutputFile ();
std::ostream & stream ();
+ OutputBlock &block();
void insert_code ();
bool open ();
void new_block ();
OutputFile & wdelay_yyaccept_init (uint32_t ind);
OutputFile & wdelay_yymaxfill ();
- void set_used_yyaccept ();
- bool get_used_yyaccept () const;
- void set_force_start_label (bool force);
- void set_user_start_label (const std::string & label);
- bool get_force_start_label () const;
- void set_block_line (uint32_t l);
- uint32_t get_block_line () const;
+ void global_lists(uniq_vector_t<std::string> &types,
+ std::set<std::string> &contexts) const;
- void emit(const std::vector<std::string> &types,
- const std::set<std::string> &contexts, size_t max_fill);
+ void emit(const uniq_vector_t<std::string> &global_types,
+ const std::set<std::string> &global_contexts, size_t max_fill);
FORBID_COPY (OutputFile);
};
HeaderFile(const std::string &fn);
~HeaderFile ();
bool open ();
- void emit (const std::vector<std::string> & types);
+ void emit(const uniq_vector_t<std::string> &types);
private:
std::ostringstream stream;
{
OutputFile source;
HeaderFile header;
- std::vector<std::string> types;
std::set<std::string> skeletons;
- std::set<std::string> contexts;
size_t max_fill;
Output(const std::string &source_name, const std::string &header_name);
const std::set<std::string> &contexts);
void output_line_info (std::ostream &, uint32_t, const std::string&);
void output_state_goto (std::ostream &, uint32_t, uint32_t);
-void output_types (std::ostream &, uint32_t, const std::vector<std::string> &);
+void output_types(std::ostream &o, uint32_t, const uniq_vector_t<std::string> &types);
void output_version_time (std::ostream &);
void output_yyaccept_init (std::ostream &, uint32_t, bool);
void output_yymaxfill (std::ostream &, size_t);
const std::string &cond,
uint32_t cunits)
{
- const uint32_t line = output.source.get_block_line();
+ const uint32_t line = output.source.block().line;
const std::string name = make_name(cond, line);
// The original set of code units (charset) might be very large.
output.max_fill = std::max (output.max_fill, adfa->max_fill);
if (adfa->need_accept)
{
- output.source.set_used_yyaccept ();
+ output.source.block().used_yyaccept = true;
}
return make_smart_ptr(adfa);
"labelprefix" { opts.set_labelPrefix (lex_conf_string ()); return; }
// try to lex number first, otherwize it would be lexed as a naked string
- "startlabel" / conf_assign number { out.set_force_start_label (lex_conf_bool()); return; }
- "startlabel" { out.set_user_start_label (lex_conf_string ()); return; }
+ "startlabel" / conf_assign number { out.block().force_start_label = lex_conf_bool(); return; }
+ "startlabel" { out.block().user_start_label = lex_conf_string(); return; }
// deprecated
"variable:yystable" { lex_conf_string (); return; }
}
encodingOld = opts->encoding;
}
- o.source.set_block_line (in->get_cline ());
+ o.source.block().line = in->get_cline();
uint32_t ind = opts->topIndent;
if (opts->cFlag)
{
// Note that "0" inserts first, which is important.
condnames.insert (condnames.begin (), "0");
}
- o.types = condnames;
}
+ o.source.block().types = condnames;
size_t nCount = specMap.size();
YYCTYPE yych;
long yyctx0;
long yyctx1;
- YYBACKUPCTX ();
switch (YYGETCONDITION()) {
case yycc1: goto yyc_c1;
}
/* *********************************** */
yyc_c1:
+ YYBACKUPCTX ();
if (YYLESSTHAN (3)) YYFILL(3);
yych = YYPEEK ();
switch (yych) {
YYCTYPE yych;
long yyctx0;
long yyctx1;
- YYCTXMARKER = YYCURSOR;
switch (YYGETCONDITION()) {
case yycc1: goto yyc_c1;
}
/* *********************************** */
yyc_c1:
+ YYCTXMARKER = YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR;
switch (yych) {
YYCTYPE yych;
long yyctx0;
long yyctx1;
- YYBACKUPCTX ();
switch (YYGETCONDITION()) {
case yycc1: goto yyc_c1;
case yycc2: goto yyc_c2;
}
/* *********************************** */
yyc_c1:
+ YYBACKUPCTX ();
if (YYLESSTHAN (3)) YYFILL(3);
yych = YYPEEK ();
switch (yych) {
YYCTYPE yych;
long yyctx0;
long yyctx1;
- YYCTXMARKER = YYCURSOR;
switch (YYGETCONDITION()) {
case yycc1: goto yyc_c1;
case yycc2: goto yyc_c2;
}
/* *********************************** */
yyc_c1:
+ YYCTXMARKER = YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR;
switch (yych) {
long yyctx0;
long yyctx1;
long yyctx3;
- YYCTXMARKER = YYCURSOR;
switch (YYGETCONDITION()) {
case yycc1: goto yyc_c1;
case yycc2: goto yyc_c2;
}
/* *********************************** */
yyc_c1:
+ YYCTXMARKER = YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR;
switch (yych) {
}
/* *********************************** */
yyc_c2:
+ YYCTXMARKER = YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR;
switch (yych) {