in = &i;
- output_version_time (o.source.fragment ());
- output_line_info (o.source.fragment (), in->get_cline (), in->get_fname ().c_str ());
+ o.source.write_version_time ();
+ o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ());
Enc encodingOld = encoding;
}
}
}
- output_line_info (o.source.fragment (), in->get_cline (), in->get_fname ().c_str ());
+ o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ());
/* restore original char handling mode*/
encoding = encodingOld;
}
-/* Generated by re2c 0.14.1.dev on Fri Feb 27 16:41:28 2015*/
+/* Generated by re2c 0.14.1.dev on Mon Mar 2 13:32:16 2015*/
#include <stdlib.h>
#include <string.h>
#include <iostream>
out << "\n";
out.insert_types ();
out << "\n";
- output_line_info (out.fragment (), cline, get_fname ().c_str ());
+ out.write_line_info (cline, get_fname ().c_str ());
}
goto echo;
}
if (ignore_cnt)
{
out << "\n";
- output_line_info (out.fragment (), cline, get_fname ().c_str ());
+ out.write_line_info (cline, get_fname ().c_str ());
}
ignore_eoc = false;
ignore_cnt = 0;
{
if (ignore_cnt)
{
- output_line_info (out.fragment (), cline, get_fname ().c_str ());
+ out.write_line_info (cline, get_fname ().c_str ());
}
ignore_eoc = false;
ignore_cnt = 0;
if (yybmHexTable)
{
- prtHex(o.fragment (), bm[j]);
+ o.write_hex (bm[j]);
}
else
{
- o << Setw (3) << (uint)bm[j];
+ o.write_uint_width (bm[j], 3);
}
o << ", ";
}
}
o << " " << cmp << " ";
- prtChOrHex(o.fragment (), v);
+ o.write_char_hex (v);
o << ") ";
}
o << indent(ind) << yySetupRule << "\n";
}
- output_line_info (o.fragment (), rule->code->line, rule->code->source.c_str ());
+ o.write_line_info (rule->code->line, rule->code->source.c_str ());
o << indent(ind);
if (rule->code->autogen)
{
o << "]\n";
o << from->label << " -> " << to->label;
o << " [label=";
- prtChOrHex(o.fragment (), ++chr);
+ o.write_char_hex (++chr);
}
}
else
{
- prtChOrHex(o.fragment (), chr);
+ o.write_char_hex (chr);
}
}
else
{
- prtChOrHex(o.fragment (), chr);
+ o.write_char_hex (chr);
}
o << "]";
else
{
o << indent(ind) << "case ";
- prtChOrHex(o.fragment (), lb);
+ o.write_char_hex (lb);
o << ":";
if (dFlag && encoding.is(Enc::EBCDIC))
{
o << "if (" << mapCodeName["yybm"] << "[" << b->i << "+" << sYych << "] & ";
if (yybmHexTable)
{
- prtHex(o.fragment (), b->m);
+ o.write_hex (b->m);
}
else
{
bUseStartLabel = false;
}
-static void output_state_goto_sub (OutputFragment & o, uint ind, uint start_label, int cMin, int cMax)
+static void output_state_goto_sub (std::ostream & o, uint ind, uint start_label, int cMin, int cMax)
{
if (cMin == cMax)
{
}
}
-void output_state_goto (OutputFragment & o, uint start_label)
+void output_state_goto (std::ostream & o, uint ind, uint start_label)
{
- uint ind = o.indent;
if (gFlag)
{
o << indent(ind++) << "static void *" << mapCodeName["yystable"] << "[" << "] = {\n";
}
}
-void output_yyaccept_init (OutputFragment & o, bool used_yyaccept)
+void output_yyaccept_init (std::ostream & o, uint ind, bool used_yyaccept)
{
if (used_yyaccept)
{
- o << indent (o.indent) << "unsigned int " << mapCodeName["yyaccept"] << " = 0;\n";
+ o << indent (ind) << "unsigned int " << mapCodeName["yyaccept"] << " = 0;\n";
}
}
-void output_yyaccept_selector (OutputFragment & o, bool used_yyaccept)
+void output_yyaccept_selector (std::ostream & o, uint ind, bool used_yyaccept, uint yyaccept_selector)
{
if (used_yyaccept)
{
- o << indent (o.indent) << mapCodeName["yyaccept"] << " = " << o.info.yyaccept_selector << ";\n";
+ o << indent (ind) << mapCodeName["yyaccept"] << " = " << yyaccept_selector << ";\n";
}
}
-void output_yymaxfill (OutputFragment & o, uint max_fill)
+void output_yymaxfill (std::ostream & o, uint max_fill)
{
o << "#define YYMAXFILL " << max_fill << "\n";
}
#include <stdio.h>
#include "output.h"
+#include "print.h"
#include "re.h"
namespace re2c
{
+OutputFragment::OutputFragment (type_t t, uint i)
+ : type (t)
+ , stream ()
+ , info ()
+ , indent (i)
+{}
+
uint OutputFragment::count_lines ()
{
uint lines = 0;
- const std::string content = str ();
+ const std::string content = stream.str ();
const char * p = content.c_str ();
for (uint i = 0; i < content.size (); ++i)
{
}
}
-OutputFragment & OutputFile::fragment ()
+std::ostream & OutputFile::stream ()
{
- return * blocks.back ()->fragments.back ();
+ return blocks.back ()->fragments.back ()->stream;
}
void OutputFile::write (const char * s, std::streamsize n)
{
- fragment ().write (s, n);
+ stream ().write (s, n);
+}
+
+void OutputFile::write_hex (uint n)
+{
+ prtHex (stream (), n);
+}
+
+void OutputFile::write_char_hex (uint n)
+{
+ prtChOrHex (stream (), n);
+}
+
+void OutputFile::write_uint_width (uint n, uint w)
+{
+ stream () << std::setw (w) << n;
+}
+
+void OutputFile::write_line_info (uint l, const char * fn)
+{
+ output_line_info (stream (), l, fn);
+}
+
+void OutputFile::write_version_time ()
+{
+ output_version_time (stream ());
}
OutputFile & operator << (OutputFile & u, uint n)
{
- u.fragment () << n;
+ u.stream () << n;
return u;
}
OutputFile & operator << (OutputFile & u, const std::string & s)
{
- u.fragment () << s;
+ u.stream () << s;
return u;
}
OutputFile & operator << (OutputFile & u, const char * s)
{
- u.fragment () << s;
+ u.stream () << s;
return u;
}
OutputFile & operator << (OutputFile & u, const Str & s)
{
- u.fragment () << s;
- return u;
-}
-
-OutputFile & operator << (OutputFile & u, const Setw & s)
-{
- u.fragment () << std::setw (s.width);
+ u.stream () << s;
return u;
}
case OutputFragment::CODE:
break;
case OutputFragment::LINE_INFO:
- output_line_info (f, line_count + 1, file_name);
+ output_line_info (f.stream, line_count + 1, file_name);
break;
case OutputFragment::STATE_GOTO:
- output_state_goto (f, prolog_label);
+ output_state_goto (f.stream, f.indent, prolog_label);
break;
case OutputFragment::TYPES:
- output_types (f, f.indent, types);
+ output_types (f.stream, f.indent, types);
break;
case OutputFragment::YYACCEPT_INIT:
- output_yyaccept_init (f, b.used_yyaccept);
+ output_yyaccept_init (f.stream, f.indent, b.used_yyaccept);
break;
case OutputFragment::YYACCEPT_SELECTOR:
- output_yyaccept_selector (f, b.used_yyaccept);
+ output_yyaccept_selector (f.stream, f.indent, b.used_yyaccept, f.info.yyaccept_selector);
break;
case OutputFragment::YYMAXFILL:
- output_yymaxfill (f, max_fill);
+ output_yymaxfill (f.stream, max_fill);
break;
}
- std::string content = f.str ();
+ std::string content = f.stream.str ();
fwrite (content.c_str (), 1, content.size (), file);
line_count += f.count_lines ();
}
struct Str;
-struct Setw
-{
- uint width;
-
- Setw (uint n)
- : width (n)
- {}
-};
-
-struct OutputFragment : public std::ostringstream
+struct OutputFragment
{
enum type_t
{ CODE
};
type_t type;
+ std::ostringstream stream;
info_t info;
uint indent;
- OutputFragment (type_t t, uint i)
- : std::ostringstream ()
- , type (t)
- , info ()
- , indent (i)
- {}
-
+ OutputFragment (type_t t, uint i);
uint count_lines ();
};
{
OutputFile (const char * fn);
~OutputFile ();
+
bool open ();
- OutputFragment & fragment ();
+
+ void new_block ();
+
void write (const char * s, std::streamsize n);
+ void write_hex (uint n);
+ void write_char_hex (uint n);
+ void write_uint_width (uint n, uint w);
+ void write_line_info (uint l, const char * fn);
+ void write_version_time ();
+ friend OutputFile & operator << (OutputFile & o, uint n);
+ friend OutputFile & operator << (OutputFile & o, const std::string & s);
+ friend OutputFile & operator << (OutputFile & o, const char * s);
+ friend OutputFile & operator << (OutputFile & o, const Str & s);
+
void insert_line_info ();
void insert_state_goto (uint ind, uint start_label);
void insert_types ();
void insert_yyaccept_init (uint ind);
void insert_yyaccept_selector (uint ind, uint selector);
void insert_yymaxfill ();
- void new_block ();
+
void set_used_yyaccept ();
bool get_used_yyaccept () const;
+
void emit (const std::vector<std::string> & types, uint max_fill);
- friend OutputFile & operator << (OutputFile & o, uint n);
- friend OutputFile & operator << (OutputFile & o, const std::string & s);
- friend OutputFile & operator << (OutputFile & o, const char * s);
- friend OutputFile & operator << (OutputFile & o, const Str & s);
- friend OutputFile & operator << (OutputFile & o, const Setw & s);
private:
const char * file_name;
std::vector<OutputBlock *> blocks;
uint prolog_label;
+ std::ostream & stream ();
void insert_code ();
};
in = &i;
- output_version_time (o.source.fragment ());
- output_line_info (o.source.fragment (), in->get_cline (), in->get_fname ().c_str ());
+ o.source.write_version_time ();
+ o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ());
Enc encodingOld = encoding;
}
}
}
- output_line_info (o.source.fragment (), in->get_cline (), in->get_fname ().c_str ());
+ o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ());
/* restore original char handling mode*/
encoding = encodingOld;
}
extern void genCondGoto(OutputFile &, uint, const RegExpMap&);
extern void genTypes(Output &, const RegExpMap&);
-extern void output_state_goto (OutputFragment &, uint);
+extern void output_state_goto (std::ostream &, uint, uint);
extern void output_types (std::ostream &, uint, const std::vector<std::string> &);
extern void output_version_time (std::ostream &);
-extern void output_yyaccept_init (OutputFragment &, bool);
-extern void output_yyaccept_selector (OutputFragment &, bool);
-extern void output_yymaxfill (OutputFragment &, uint);
+extern void output_yyaccept_init (std::ostream &, uint, bool);
+extern void output_yyaccept_selector (std::ostream &, uint, bool, uint);
+extern void output_yymaxfill (std::ostream &, uint);
extern void output_line_info (std::ostream &, uint, const char *);
extern RegExp *mkDiff(RegExp*, RegExp*);
out << "\n";
out.insert_types ();
out << "\n";
- output_line_info (out.fragment (), cline, get_fname ().c_str ());
+ out.write_line_info (cline, get_fname ().c_str ());
}
goto echo;
}
{
if (ignore_cnt)
{
- output_line_info (out.fragment (), cline, get_fname ().c_str ());
+ out.write_line_info (cline, get_fname ().c_str ());
}
ignore_eoc = false;
ignore_cnt = 0;
if (ignore_cnt)
{
out << "\n";
- output_line_info (out.fragment (), cline, get_fname ().c_str ());
+ out.write_line_info (cline, get_fname ().c_str ());
}
ignore_eoc = false;
ignore_cnt = 0;