]> granicus.if.org Git - re2c/commitdiff
Continued adding "--skeleton" switch.
authorUlya Trofimovich <skvadrik@gmail.com>
Sun, 19 Apr 2015 22:11:32 +0000 (23:11 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Sun, 19 Apr 2015 22:11:32 +0000 (23:11 +0100)
Code cleanup.

re2c/skeleton.cc
re2c/skeleton.h

index 3377086e71d9d895cf4b8988c8bf65151ca85632..5967d275d0d891e1fdefc390258c48a0d105be4a 100644 (file)
@@ -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<Path> & prefixes, std::vector<Path> & results)
 {
        if (s == NULL)
@@ -178,7 +156,7 @@ void generate (SkeletonState * s, const std::vector<Path> & prefixes, std::vecto
                        std::vector<Path> 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<Path> & 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<uint> (1, i->second[0]), 0, s->rule);
-                                       append (* s->path, * i->first->path);
+                                       s->path->append (i->first->path);
                                }
                        }
                }
index 85d18766eb8f3fbf211554c44c5843348299d257..28dc261ea330db19659d21048c4cf8333faa3b06 100644 (file)
@@ -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<Path> & prefixes, std::vector<Path> & results);
 
 } // namespace re2c