]> granicus.if.org Git - re2c/commitdiff
Started adding "--skeleton" switch.
authorUlya Trofimovich <skvadrik@gmail.com>
Fri, 27 Mar 2015 21:35:49 +0000 (21:35 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Fri, 27 Mar 2015 21:35:49 +0000 (21:35 +0000)
re2c/Makefile.am
re2c/bootstrap/scanner.cc
re2c/code_names.cc [new file with mode: 0644]
re2c/code_names.h [changed mode: 0755->0644]
re2c/globals.h
re2c/main.cc
re2c/scanner.re

index bc9d07a7d81f5c1cc3a0933aa3f4f52abfb41c9f..b1e88b2c976fe755e3be629bc8047631db17607c 100755 (executable)
@@ -2,7 +2,8 @@
 
 bin_PROGRAMS = re2c
 win_BINARIES = $(WINBUILDDIR)/re2c.exe
-re2c_SOURCES = code.cc dfa.cc go_construct.cc go_destruct.cc go_emit.cc go_used_labels.cc main.cc parser.cc actions.cc scanner.re substr.cc range.cc \
+re2c_SOURCES = code.cc code_names.cc dfa.cc go_construct.cc go_destruct.cc go_emit.cc go_used_labels.cc \
+       main.cc parser.cc actions.cc scanner.re substr.cc range.cc \
        translate.cc scanner.cc mbo_getopt.cc print.cc input.cc input_api.cc output.cc \
        enc.cc utf8.cc utf8_range.cc utf8_regexp.cc utf16.cc utf16_range.cc utf16_regexp.cc range_suffix.cc \
        basics.h code.h code_names.h dfa.h go.h enc.h indent.h input.h input_api.h free_list.h globals.h ins.h \
index fcdc2f92b5c60b653ee912245dabbfd76ac4de9d..d70696eaf0b5ae6b3107e4ff098a2bac27246699 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.14.1.dev on Mon Mar  2 13:32:16 2015*/
+/* Generated by re2c 0.14.1.dev on Fri Mar 27 16:37:18 2015*/
 #include <stdlib.h>
 #include <string.h>
 #include <iostream>
@@ -103,7 +103,7 @@ echo:
        }
        ++YYCURSOR;
        {
-                                       if (!ignore_eoc && !DFlag)
+                                       if (!(ignore_eoc || DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok) - 1);
                                                // -1 so we don't write out the \0
@@ -132,7 +132,7 @@ yy7:
                                        {
                                                ignore_cnt++;
                                        }
-                                       else if (!DFlag)
+                                       else if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok));
                                        }
@@ -245,7 +245,7 @@ yy32:
                                        {
                                                fatal("found standard 're2c' block while using -r flag");
                                        }
-                                       if (!DFlag)
+                                       if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok));
                                        }
@@ -272,7 +272,7 @@ yy34:
                                                fatal("found 'use:re2c' block without -r flag");
                                        }
                                        reuse();
-                                       if (!DFlag)
+                                       if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(&cursor[-11]) - (const char*)(tok));
                                        }
@@ -294,7 +294,7 @@ yy42:
        if (yych != 'c') goto yy12;
        ++YYCURSOR;
        {
-                                       if (!DFlag)
+                                       if (!(DFlag || flag_skeleton))
                                        {
                                                out.insert_yymaxfill ();
                                        }
@@ -378,7 +378,7 @@ yy74:
        {
                                        tok = pos = cursor;
                                        ignore_eoc = true;
-                                       if (!DFlag)
+                                       if (!(DFlag || flag_skeleton))
                                        {
                                                out.insert_line_info ();
                                                out << "\n";
@@ -405,7 +405,7 @@ yy85:
                                                ignore_eoc = false;
                                                ignore_cnt = 0;
                                        }
-                                       else if (!DFlag)
+                                       else if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok));
                                        }
@@ -428,7 +428,7 @@ yy87:
                                                ignore_eoc = false;
                                                ignore_cnt = 0;
                                        }
-                                       else if (!DFlag)
+                                       else if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok));
                                        }
diff --git a/re2c/code_names.cc b/re2c/code_names.cc
new file mode 100644 (file)
index 0000000..93668ac
--- /dev/null
@@ -0,0 +1,21 @@
+#include "code_names.h"
+#include "globals.h"
+
+namespace re2c
+{
+
+std::string& CodeNames::operator [] (const char * what)
+{
+       CodeNames::iterator it = find(std::string(what));
+       
+       if (it == end() || flag_skeleton)
+       {
+               return insert(std::make_pair(std::string(what), std::string(what))).first->second;
+       }
+       else
+       {
+               return it->second;
+       }
+}
+
+} // end namespace re2c
old mode 100755 (executable)
new mode 100644 (file)
index 4813530..00b30b0
@@ -14,20 +14,6 @@ public:
        std::string& operator [] (const char * what);
 };
 
-inline std::string& CodeNames::operator [] (const char * what)
-{
-       CodeNames::iterator it = find(std::string(what));
-       
-       if (it != end())
-       {
-               return it->second;
-       }
-       else
-       {
-               return insert(std::make_pair(std::string(what), std::string(what))).first->second;
-       }
-}
-
 } // end namespace re2c
 
 #endif
index 5171816406d8144f75b3547a8a2a6293588d3f9c..b1feab48b54dbe38d3dfcbad7b3e013c4a2b0928 100644 (file)
@@ -26,6 +26,7 @@ extern bool iFlag;
 extern bool rFlag;
 extern bool sFlag;
 extern bool tFlag;
+extern bool flag_skeleton;
 
 extern bool bNoGenerationDate;
 extern bool bUsedYYMarker;
index b4cee085102ce32495f2cf060c913e1201f8fd07..0c43f17e0e3b9f78fb76b74b2d85024281eaeb46 100644 (file)
@@ -30,6 +30,7 @@ bool iFlag = false;
 bool rFlag = false;
 bool sFlag = false;
 bool tFlag = false;
+bool flag_skeleton = false;
 
 bool bNoGenerationDate = false;
 bool bUsedYYBitmap  = false;
@@ -117,6 +118,7 @@ static const mbo_opt_struct OPTIONS[] =
        mbo_opt_struct(12,  0, "case-inverted"),
        mbo_opt_struct(13,  1, "encoding-policy"),
        mbo_opt_struct(14,  1, "input"),
+       mbo_opt_struct(15,  0, "skeleton"),
        mbo_opt_struct('-', 0, NULL) /* end of args */
 };
 
@@ -206,6 +208,10 @@ static void usage()
        "\n"
        "--input i               Specify re2c input API.\n"
        "                        i can be one of the following: default, custom.\n"
+       "\n"
+       "--skeleton              Instead of embedding re2c-generated code into C/C++ source,\n"
+       "                        generate a self-contained program for the same DFA.\n"
+       "                        Most useful for correctness and performance testing.\n"
        ;
 }
 
@@ -399,6 +405,10 @@ int main(int argc, char *argv[])
                                return 1;
                        }
                        break;
+
+                       case 15:
+                       flag_skeleton = true;
+                       break;
                }
        }
 
@@ -408,9 +418,9 @@ int main(int argc, char *argv[])
                return 2;
        }
 
-       if (DFlag && (bFlag || dFlag || sFlag))
+       if (DFlag && (bFlag || dFlag || sFlag || flag_skeleton))
        {
-               std::cerr << "re2c: error: Cannot combine -D with -b, -d  or -s switches\n";
+               std::cerr << "re2c: error: Cannot combine -D with -b, -d, -s or --skeleton switches\n";
                return 2;
        }
 
index f07a88cb6a2e4d3bcdc5a9ddbbd593b18bf55d9b..2afcb17b3eb19f2f164a2cb0bdcfffc64473f79d 100644 (file)
@@ -69,7 +69,7 @@ echo:
                                        {
                                                fatal("found standard 're2c' block while using -r flag");
                                        }
-                                       if (!DFlag)
+                                       if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(&cursor[-7]) - (const char*)(tok));
                                        }
@@ -94,7 +94,7 @@ echo:
                                                fatal("found 'use:re2c' block without -r flag");
                                        }
                                        reuse();
-                                       if (!DFlag)
+                                       if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(&cursor[-11]) - (const char*)(tok));
                                        }
@@ -102,7 +102,7 @@ echo:
                                        RETURN(Reuse);
                                }
        "/*!max:re2c" {
-                                       if (!DFlag)
+                                       if (!(DFlag || flag_skeleton))
                                        {
                                                out.insert_yymaxfill ();
                                        }
@@ -124,7 +124,7 @@ echo:
        "/*!types:re2c" {
                                        tok = pos = cursor;
                                        ignore_eoc = true;
-                                       if (!DFlag)
+                                       if (!(DFlag || flag_skeleton))
                                        {
                                                out.insert_line_info ();
                                                out << "\n";
@@ -145,7 +145,7 @@ echo:
                                                ignore_eoc = false;
                                                ignore_cnt = 0;
                                        }
-                                       else if (!DFlag)
+                                       else if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok));
                                        }
@@ -163,7 +163,7 @@ echo:
                                                ignore_eoc = false;
                                                ignore_cnt = 0;
                                        }
-                                       else if (!DFlag)
+                                       else if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok));
                                        }
@@ -179,7 +179,7 @@ echo:
                                        {
                                                ignore_cnt++;
                                        }
-                                       else if (!DFlag)
+                                       else if (!(DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok));
                                        }
@@ -188,7 +188,7 @@ echo:
                                        goto echo;
                                }
        zero            {
-                                       if (!ignore_eoc && !DFlag)
+                                       if (!(ignore_eoc || DFlag || flag_skeleton))
                                        {
                                                out.write((const char*)(tok), (const char*)(cursor) - (const char*)(tok) - 1);
                                                // -1 so we don't write out the \0