]> granicus.if.org Git - re2c/commitdiff
Hided 'OutputFile' structure.
authorUlya Trofimovich <skvadrik@gmail.com>
Mon, 2 Mar 2015 13:54:11 +0000 (13:54 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Mon, 2 Mar 2015 13:54:11 +0000 (13:54 +0000)
re2c/bootstrap/parser.cc
re2c/bootstrap/scanner.cc
re2c/code.cc
re2c/output.cc
re2c/output.h
re2c/parser.y
re2c/re.h
re2c/scanner.re

index 5bfba40d97071d7c3229d1e6c88c9f514819cd39..edae1746cd2d3f9223f3fbf954692229d1d6d156 100644 (file)
@@ -2233,8 +2233,8 @@ void parse(Scanner& i, Output & o)
 
        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;
        
@@ -2407,7 +2407,7 @@ void parse(Scanner& i, Output & o)
                                }
                        }
                }
-               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;
        }
index ea7dbc5df01e0569b32ce28856dc059004ca42fc..fcdc2f92b5c60b653ee912245dabbfd76ac4de9d 100644 (file)
@@ -1,4 +1,4 @@
-/* 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>
@@ -384,7 +384,7 @@ yy74:
                                                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;
                                }
@@ -400,7 +400,7 @@ yy85:
                                                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;
@@ -423,7 +423,7 @@ yy87:
                                        {
                                                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;
index b7d828b6556cc325c1a04bafb195c93472dd190e..2dd7239d9819d2cea744463e42c525ca11b56a00 100644 (file)
@@ -298,11 +298,11 @@ void BitMap::gen(OutputFile & o, uint ind, uint lb, uint ub)
 
                                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  << ", ";
                        }
@@ -346,7 +346,7 @@ static void genIf(OutputFile & o, uint ind, const char *cmp, uint v, bool &readC
        }
 
        o << " " << cmp << " ";
-       prtChOrHex(o.fragment (), v);
+       o.write_char_hex (v);
        o << ") ";
 }
 
@@ -707,7 +707,7 @@ void Rule::emit(Output & output, uint ind, bool &, const std::string& condName)
                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)
        {
@@ -820,17 +820,17 @@ static void printDotCharInterval(OutputFile & o, uint lastPrintableChar, uint ch
                                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 << "]";
@@ -874,7 +874,7 @@ static bool genCases(OutputFile & o, uint ind, uint lb, Span *s, bool &newLine,
                                else
                                {
                                        o << indent(ind) << "case ";
-                                       prtChOrHex(o.fragment (), lb);
+                                       o.write_char_hex (lb);
                                        o << ":";
                                        if (dFlag && encoding.is(Enc::EBCDIC))
                                        {
@@ -1248,7 +1248,7 @@ void Go::genGoto(OutputFile & o, uint ind, const State *from, const State *next,
                                        o << "if (" << mapCodeName["yybm"] << "[" << b->i << "+" << sYych << "] & ";
                                        if (yybmHexTable)
                                        {
-                                               prtHex(o.fragment (), b->m);
+                                               o.write_hex (b->m);
                                        }
                                        else
                                        {
@@ -1908,7 +1908,7 @@ void DFA::emit(Output & output, uint& ind, const RegExpMap* specMap, const std::
        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)
        {
@@ -1933,9 +1933,8 @@ static void output_state_goto_sub (OutputFragment & o, uint ind, uint start_labe
        }
 }
 
-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";
@@ -2094,23 +2093,23 @@ void genTypes(Output & output, const RegExpMap& specMap)
        }
 }
 
-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";
 }
index e4e18357d511545044e8102ee0a38ef201068ef3..2ef17419d77386665d868e0aa83aaf22dbab0f66 100644 (file)
@@ -2,15 +2,23 @@
 #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)
        {
@@ -71,43 +79,62 @@ OutputFile::~OutputFile ()
        }
 }
 
-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;
 }
 
@@ -195,25 +222,25 @@ void OutputFile::emit
                                        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 ();
                        }
index 4379ee3936179bdce3dff472d7a8839daf437cb4..7bed5802d7b51ae7f60b7d6a320a7e1f634c7f28 100644 (file)
@@ -12,16 +12,7 @@ namespace re2c
 
 struct Str;
 
-struct Setw
-{
-       uint width;
-
-       Setw (uint n)
-               : width (n)
-       {}
-};
-
-struct OutputFragment : public std::ostringstream
+struct OutputFragment
 {
        enum type_t
                { CODE
@@ -40,16 +31,11 @@ struct OutputFragment : public std::ostringstream
        };
 
        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 ();
 };
 
@@ -66,24 +52,33 @@ struct OutputFile
 {
        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;
@@ -91,6 +86,7 @@ private:
        std::vector<OutputBlock *> blocks;
        uint prolog_label;
 
+       std::ostream & stream ();
        void insert_code ();
 };
 
index 5766befa1658155e4595263fb4f4f78c4693ac19..3a9d050d6768b82016a7aa74f2f40effc3f4d698 100644 (file)
@@ -513,8 +513,8 @@ void parse(Scanner& i, Output & o)
 
        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;
        
@@ -687,7 +687,7 @@ void parse(Scanner& i, Output & o)
                                }
                        }
                }
-               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;
        }
index 3a61330facbd2794638dbb5cb657684c629af9c0..9605fb6aee7a5f5de18001efdf852bc8927b4ce0 100644 (file)
--- a/re2c/re.h
+++ b/re2c/re.h
@@ -396,12 +396,12 @@ extern void genCondTable(OutputFile &, uint, const RegExpMap&);
 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*);
index f1c9c8bb7d8eae06cf7ce6377323cf96903c775a..f07a88cb6a2e4d3bcdc5a9ddbbd593b18bf55d9b 100644 (file)
@@ -130,7 +130,7 @@ echo:
                                                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;
                                }
@@ -140,7 +140,7 @@ 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;
@@ -158,7 +158,7 @@ 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;