From abc40ff29c17a25b6f1c98e49b63ae7abb3d81c9 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Mon, 11 May 2015 17:46:26 +0100 Subject: [PATCH] Reduced "src/codegen/print.h" dependency for some unrelated files. This is the first part of effort to reduce the total number of interdependencies between different files. "src/codegen/print.h" contains some pretty-printing functions mostly used for code generation. There two other cases where. these functions can also be useful: 1. debug: it's not yet well developed, just some messy chunks of code that are commented out 2. error messages: character pretty-printing is not actually very useful, since error messages mostly contain printable characters (pieces of user-supplied input) From the above I conclude that non-codegen files don't really need "src/codegen/print.h". If this will change, I'll consider moving this functions to src/util. --- re2c/bootstrap/scanner.cc | 8 ++------ re2c/src/dfa/actions.cc | 18 ++++++------------ re2c/src/dfa/dfa.cc | 1 - re2c/src/parse/scanner.re | 6 +----- re2c/src/util/range.cc | 17 ----------------- re2c/src/util/range.h | 8 -------- 6 files changed, 9 insertions(+), 49 deletions(-) diff --git a/re2c/bootstrap/scanner.cc b/re2c/bootstrap/scanner.cc index a90292ea..9908d3aa 100644 --- a/re2c/bootstrap/scanner.cc +++ b/re2c/bootstrap/scanner.cc @@ -1,10 +1,9 @@ -/* Generated by re2c 0.14.1.dev on Mon May 11 13:39:25 2015*/ +/* Generated by re2c 0.14.1.dev on Mon May 11 17:45:17 2015*/ #include #include #include #include -#include "src/codegen/print.h" #include "src/dfa/dfa.h" #include "src/globals.h" #include "src/parse/parser.h" @@ -674,10 +673,7 @@ yy112: ++YYCURSOR; yy113: { - std::ostringstream msg; - msg << "unexpected character: "; - prtChOrHex(msg, *tok); - fatal(msg.str().c_str()); + fatalf("unexpected character: '%c'", *tok); goto scan; } yy114: diff --git a/re2c/src/dfa/actions.cc b/re2c/src/dfa/actions.cc index 6beb3a81..bb0adbcf 100644 --- a/re2c/src/dfa/actions.cc +++ b/re2c/src/dfa/actions.cc @@ -5,7 +5,6 @@ #include #include -#include "src/codegen/print.h" #include "src/codegen/skeleton/skeleton.h" #include "src/dfa/dfa.h" #include "src/dfa/encoding/utf16/utf16_regexp.h" @@ -56,7 +55,9 @@ const Ins* showIns(std::ostream &o, const Ins &i, const Ins &base) o << "match "; for (; ret < (Ins*) i.i.link; ++ret) - prtCh(o, ret->c.value); + { + o << "\\x" << std::hex << ret->c.value; + } break; } @@ -1051,15 +1052,7 @@ smart_ptr genCode(RegExp *re, Output & output, uint32_t ind) { CharSet cs; re->split(cs); - - /*for(uint32_t k = 0; k < encoding.nCodeUnits();) - { - uint32_t j; - for(j = k; ++k < encoding.nCodeUnits() && cs.rep[k] == cs.rep[j];); - printSpan(std::cerr, j, k); - std::cerr << "\t" << cs.rep[j] - &cs.ptn[0] << std::endl; - }*/ - + Char *rep = new Char[encoding.nCodeUnits()]; for (uint32_t j = 0; j < encoding.nCodeUnits(); ++j) @@ -1081,7 +1074,8 @@ smart_ptr genCode(RegExp *re, Output & output, uint32_t ind) optimize(ins); /* - for (const Ins *inst = &ins[0]; inst < &ins[size]; ) { + for (const Ins *inst = &ins[0]; inst < &ins[size]; ) + { inst = showIns(std::cout, *inst, ins[0]); } */ diff --git a/re2c/src/dfa/dfa.cc b/re2c/src/dfa/dfa.cc index dde45840..de490e5e 100644 --- a/re2c/src/dfa/dfa.cc +++ b/re2c/src/dfa/dfa.cc @@ -2,7 +2,6 @@ #include #include -#include "src/codegen/print.h" #include "src/dfa/dfa.h" #include "src/globals.h" #include "src/util/substr.h" diff --git a/re2c/src/parse/scanner.re b/re2c/src/parse/scanner.re index 6b7332a9..206ebe4b 100644 --- a/re2c/src/parse/scanner.re +++ b/re2c/src/parse/scanner.re @@ -3,7 +3,6 @@ #include #include -#include "src/codegen/print.h" #include "src/dfa/dfa.h" #include "src/globals.h" #include "src/parse/parser.h" @@ -420,10 +419,7 @@ scan: } * { - std::ostringstream msg; - msg << "unexpected character: "; - prtChOrHex(msg, *tok); - fatal(msg.str().c_str()); + fatalf("unexpected character: '%c'", *tok); goto scan; } */ diff --git a/re2c/src/util/range.cc b/re2c/src/util/range.cc index 73dc2fc3..f815ea57 100644 --- a/re2c/src/util/range.cc +++ b/re2c/src/util/range.cc @@ -1,25 +1,8 @@ -#include "src/codegen/print.h" #include "src/util/range.h" namespace re2c { -std::ostream& operator<<(std::ostream &o, const Range &r) -{ - if ((r.ub - r.lb) == 1) - { - prtCh(o, r.lb); - } - else - { - prtCh(o, r.lb); - o << "-"; - prtCh(o, r.ub - 1); - } - - return o << r.next; -} - Range *doUnion(Range *r1, Range *r2) { if (r1 == NULL) diff --git a/re2c/src/util/range.h b/re2c/src/util/range.h index ed1478d9..56128178 100644 --- a/re2c/src/util/range.h +++ b/re2c/src/util/range.h @@ -33,16 +33,8 @@ public: { vFreeList.erase(this); } - - friend std::ostream& operator<<(std::ostream&, const Range&); - friend std::ostream& operator<<(std::ostream&, const Range*); }; -inline std::ostream& operator<<(std::ostream &o, const Range *r) -{ - return r ? o << *r : o; -} - Range *doUnion(Range *r1, Range *r2); Range *doDiff(Range *r1, Range *r2); -- 2.49.0