From: Ulya Trofimovich Date: Sun, 19 Apr 2015 22:11:32 +0000 (+0100) Subject: Continued adding "--skeleton" switch. X-Git-Tag: 0.15~296 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8b5ac322f70a4cece185ce01e9c534744673d6a;p=re2c Continued adding "--skeleton" switch. Code cleanup. --- diff --git a/re2c/skeleton.cc b/re2c/skeleton.cc index 3377086e..5967d275 100644 --- a/re2c/skeleton.cc +++ b/re2c/skeleton.cc @@ -138,28 +138,6 @@ void generate_data (DataFile & o, uint ind, SkeletonState * s, const std::vector } */ -void update (Path & p, const SkeletonState * s) -{ - if (s->rule != ~0u) - { - p.length = p.chars.size (); - p.rule = s->rule; - } -} - -void append (Path & p1, const Path & p2) -{ - if (p2.rule != ~0u) - { - p1.length = p1.chars.size () + p2.length; - p1.rule = p2.rule; - } - for (uint i = 0; i < p2.chars.size (); ++i) - { - p1.chars.push_back (p2.chars[i]); - } -} - void generate (SkeletonState * s, const std::vector & prefixes, std::vector & results) { if (s == NULL) @@ -178,7 +156,7 @@ void generate (SkeletonState * s, const std::vector & prefixes, std::vecto std::vector zs (prefixes); for (uint i = 0; i < zs.size (); ++i) { - append (zs[i], * s->path); + zs[i].append (s->path); } generate (NULL, zs, results); } @@ -196,14 +174,13 @@ void generate (SkeletonState * s, const std::vector & prefixes, std::vecto for (uint j = 0; j < i->second.size (); ++j, ++in) { zs.push_back (prefixes[in % in_arrows]); - update (zs[j], s); - zs[j].chars.push_back (i->second[j]); + zs[j].extend (s->rule, i->second[j]); } generate (i->first, zs, results); if (s->path == NULL && i->first->path != NULL) { s->path = new Path (std::vector (1, i->second[0]), 0, s->rule); - append (* s->path, * i->first->path); + s->path->append (i->first->path); } } } diff --git a/re2c/skeleton.h b/re2c/skeleton.h index 85d18766..28dc261e 100644 --- a/re2c/skeleton.h +++ b/re2c/skeleton.h @@ -20,6 +20,27 @@ struct Path , length (l) , rule (r) {} + inline void extend (uint r, uint c) + { + if (r != ~0u) + { + length = chars.size (); + rule = r; + } + chars.push_back (c); + } + inline void append (const Path * p) + { + if (p->rule != ~0u) + { + length = chars.size () + p->length; + rule = p->rule; + } + for (uint i = 0; i < p->chars.size (); ++i) + { + chars.push_back (p->chars[i]); + } + } }; struct SkeletonState @@ -63,8 +84,6 @@ struct Skeleton unsigned long count_data (SkeletonState * s, unsigned long count); void skeleton_emit_prolog (OutputFile & o, uint ind, const char * data_name); void skeleton_emit_epilog (OutputFile & o, uint ind); -void update (Path & p, const SkeletonState * s); -void append (Path & p1, const Path * p2); void generate (SkeletonState * s, const std::vector & prefixes, std::vector & results); } // namespace re2c