From a3e4bc9d52322e4cbdaaef80decd02e7ceb2a672 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Fri, 27 Mar 2015 21:35:49 +0000 Subject: [PATCH] Started adding "--skeleton" switch. --- re2c/Makefile.am | 3 ++- re2c/bootstrap/scanner.cc | 18 +++++++++--------- re2c/code_names.cc | 21 +++++++++++++++++++++ re2c/code_names.h | 14 -------------- re2c/globals.h | 1 + re2c/main.cc | 14 ++++++++++++-- re2c/scanner.re | 16 ++++++++-------- 7 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 re2c/code_names.cc mode change 100755 => 100644 re2c/code_names.h diff --git a/re2c/Makefile.am b/re2c/Makefile.am index bc9d07a7..b1e88b2c 100755 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -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 \ diff --git a/re2c/bootstrap/scanner.cc b/re2c/bootstrap/scanner.cc index fcdc2f92..d70696ea 100644 --- a/re2c/bootstrap/scanner.cc +++ b/re2c/bootstrap/scanner.cc @@ -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 #include #include @@ -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 index 00000000..93668acb --- /dev/null +++ b/re2c/code_names.cc @@ -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 diff --git a/re2c/code_names.h b/re2c/code_names.h old mode 100755 new mode 100644 index 4813530a..00b30b07 --- a/re2c/code_names.h +++ b/re2c/code_names.h @@ -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 diff --git a/re2c/globals.h b/re2c/globals.h index 51718164..b1feab48 100644 --- a/re2c/globals.h +++ b/re2c/globals.h @@ -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; diff --git a/re2c/main.cc b/re2c/main.cc index b4cee085..0c43f17e 100644 --- a/re2c/main.cc +++ b/re2c/main.cc @@ -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; } diff --git a/re2c/scanner.re b/re2c/scanner.re index f07a88cb..2afcb17b 100644 --- a/re2c/scanner.re +++ b/re2c/scanner.re @@ -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 -- 2.40.0