From e86c36700d4d4cc0e362dec2e42fcb8e65207ae9 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 15 Sep 2015 10:45:19 +0100 Subject: [PATCH] More accurate handling of default rule for '--skeleton'. --- re2c/src/codegen/skeleton/generate_code.cc | 6 +----- re2c/src/codegen/skeleton/generate_data.cc | 6 +++++- re2c/src/codegen/skeleton/skeleton.cc | 15 +++++++++++++++ re2c/src/codegen/skeleton/skeleton.h | 4 ++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/re2c/src/codegen/skeleton/generate_code.cc b/re2c/src/codegen/skeleton/generate_code.cc index 7d849229..47083942 100644 --- a/re2c/src/codegen/skeleton/generate_code.cc +++ b/re2c/src/codegen/skeleton/generate_code.cc @@ -28,11 +28,7 @@ static void exact_uint (OutputFile & o, size_t width) void Skeleton::emit_prolog (OutputFile & o, uint32_t maxfill) const { - const uint32_t default_rule = sizeof_key == 1 - ? UINT8_MAX - : sizeof_key == 2 - ? UINT16_MAX - : UINT32_MAX; + const uint32_t default_rule = maxkey (); o << "\n" << "#include "; o << "\n" << "#include // malloc, free"; diff --git a/re2c/src/codegen/skeleton/generate_data.cc b/re2c/src/codegen/skeleton/generate_data.cc index 625b7047..b7b691dc 100644 --- a/re2c/src/codegen/skeleton/generate_data.cc +++ b/re2c/src/codegen/skeleton/generate_data.cc @@ -246,13 +246,17 @@ void Skeleton::emit_data (const char * fname) template static void keygen (FILE * f, size_t count, size_t len, size_t len_match, rule_rank_t match) { + const key_t m = match.is_none () + ? Skeleton::maxkey () + : static_cast (match.uint32 ()); + const size_t keys_size = 3 * count; key_t * keys = new key_t [keys_size]; for (uint32_t i = 0; i < keys_size;) { keys[i++] = static_cast (len); keys[i++] = static_cast (len_match); - keys[i++] = static_cast (match.uint32 ()); + keys[i++] = m; } fwrite (keys, sizeof (key_t), keys_size, f); delete [] keys; diff --git a/re2c/src/codegen/skeleton/skeleton.cc b/re2c/src/codegen/skeleton/skeleton.cc index 616ada98..ae41fb63 100644 --- a/re2c/src/codegen/skeleton/skeleton.cc +++ b/re2c/src/codegen/skeleton/skeleton.cc @@ -118,4 +118,19 @@ Skeleton::~Skeleton () delete [] nodes; } +template <> uint32_t Skeleton::maxkey () { return UINT32_MAX; } +template <> uint16_t Skeleton::maxkey () { return UINT16_MAX; } +template <> uint8_t Skeleton::maxkey () { return UINT8_MAX; } + +uint32_t Skeleton::maxkey () const +{ + switch (sizeof_key) + { + default: // shouldn't happen + case 4: return maxkey (); + case 2: return maxkey (); + case 1: return maxkey (); + } +} + } // namespace re2c diff --git a/re2c/src/codegen/skeleton/skeleton.h b/re2c/src/codegen/skeleton/skeleton.h index cab3b21e..804e6479 100644 --- a/re2c/src/codegen/skeleton/skeleton.h +++ b/re2c/src/codegen/skeleton/skeleton.h @@ -75,6 +75,10 @@ struct Skeleton static void emit_epilog (OutputFile & o); static void emit_action (OutputFile & o, uint32_t ind, rule_rank_t rank); + template + static key_t maxkey (); + uint32_t maxkey () const; + private: template void generate_paths_cunit_key (FILE * input, FILE * keys); -- 2.40.0