From: Ulya Trofimovich Date: Mon, 15 Jun 2015 14:39:29 +0000 (+0100) Subject: Construct non-NULL regexps from NULL ranges (for variable-length encodings). X-Git-Tag: 0.15~207 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50802e46966089b3a843496722879c9b5f50fa43;p=re2c Construct non-NULL regexps from NULL ranges (for variable-length encodings). NULL range represents empty range: range union and difference functions return NULL for empty ranges. Thus NULL can be passed to functions that construct regexp from range ('MatchOp', 'UTF8Range' and 'UTF16Range'). All these functions must behave return non-NULL for NULL ranges, since further code relies on this. --- diff --git a/re2c/src/ir/regexp/encoding/range_suffix.cc b/re2c/src/ir/regexp/encoding/range_suffix.cc index 96615927..87898491 100644 --- a/re2c/src/ir/regexp/encoding/range_suffix.cc +++ b/re2c/src/ir/regexp/encoding/range_suffix.cc @@ -4,8 +4,17 @@ namespace re2c { +static RegExp * emit (RangeSuffix * p, RegExp * re); + free_list RangeSuffix::freeList; +RegExp * to_regexp (RangeSuffix * p) +{ + return p + ? emit (p, NULL) + : new MatchOp (NULL); +} + /* * Build regexp from suffix tree. */ diff --git a/re2c/src/ir/regexp/encoding/range_suffix.h b/re2c/src/ir/regexp/encoding/range_suffix.h index 93008977..f4c0e96b 100644 --- a/re2c/src/ir/regexp/encoding/range_suffix.h +++ b/re2c/src/ir/regexp/encoding/range_suffix.h @@ -33,7 +33,7 @@ public: FORBID_COPY (RangeSuffix); }; -RegExp * emit(RangeSuffix * p, RegExp * re); +RegExp * to_regexp (RangeSuffix * p); } // namespace re2c diff --git a/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.cc b/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.cc index 8b7e2bd5..49522657 100644 --- a/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.cc +++ b/re2c/src/ir/regexp/encoding/utf16/utf16_regexp.cc @@ -29,7 +29,7 @@ RegExp * UTF16Range(const Range * r) RangeSuffix * root = NULL; for (; r != NULL; r = r->next ()) UTF16splitByRuneLength(root, r->lower (), r->upper () - 1); - return emit(root, NULL); + return to_regexp (root); } } // namespace re2c diff --git a/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.cc b/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.cc index 1372211f..084755fa 100644 --- a/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.cc +++ b/re2c/src/ir/regexp/encoding/utf8/utf8_regexp.cc @@ -27,7 +27,7 @@ RegExp * UTF8Range(const Range * r) RangeSuffix * root = NULL; for (; r != NULL; r = r->next ()) UTF8splitByRuneLength(root, r->lower (), r->upper () - 1); - return emit(root, NULL); + return to_regexp (root); } } // namespace re2c