]> granicus.if.org Git - re2c/commitdiff
Code cleanup.
authorUlya Trofimovich <skvadrik@gmail.com>
Sat, 14 May 2016 14:34:54 +0000 (15:34 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Sat, 14 May 2016 14:34:54 +0000 (15:34 +0100)
re2c/bootstrap/src/codegen/subst_tags.cc
re2c/src/codegen/input_api.cc
re2c/src/codegen/input_api.h
re2c/src/codegen/subst_tags.re

index 211fcc99524935d785d641836219f264c7685386..78c34bb94d7ceb6548224b372393eb053bd029c0 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.16 on Fri May 13 14:25:27 2016 */
+/* Generated by re2c 0.16 on Sat May 14 15:27:19 2016 */
 #line 1 "../src/codegen/subst_tags.re"
 #include "src/codegen/emit.h"
 #include "src/codegen/input_api.h"
@@ -113,18 +113,19 @@ yy7:
        {
                        const std::string name((base + yytag1name), head);
                        for (size_t i = ltag; i < htag; ++i) {
-                               if (name == *tags[i].name) {
+                               const Tag &t = tags[i];
+                               if (name == *t.name) {
                                        result.append(tail, base);
-                                       result.append(opts->input_api.expr_tag(tags, i));
+                                       result.append(opts->input_api.expr_tag(tags, t));
                                        tail = head;
                                        break;
                                }
                        }
                        goto loop;
                }
-#line 126 "src/codegen/subst_tags.cc"
+#line 127 "src/codegen/subst_tags.cc"
 }
-#line 53 "../src/codegen/subst_tags.re"
+#line 54 "../src/codegen/subst_tags.re"
 
 }
 
index 95f37c0ba236562fe30b5e9bf63d9d1e41baee3a..f4e97fbe4f2b8afe8f001c973d8d17401486ef74 100644 (file)
@@ -129,40 +129,31 @@ std::string InputAPI::stmt_dist (uint32_t ind, const bool *mask,
        return s + expr_dist() + ";\n";
 }
 
-std::string InputAPI::expr_tag_var(const std::string &expr) const
+std::string InputAPI::expr_tag(const std::valarray<Tag> &tags, const Tag &tag) const
 {
-       switch (type_) {
-               case DEFAULT: return "(" + opts->yyctxmarker + " + " + expr + ")";
-               case CUSTOM:  return opts->tags_yytag + "(" + expr + ")";
-               default:      assert(false);
-       }
-}
+       std::string expr;
 
-std::string InputAPI::expr_tag(const std::valarray<Tag> &tags, size_t idx) const
-{
-       const Tag &t = tags[idx];
-       if (t.type == Tag::VAR) {
-               const Tag &o = tags[t.var.orig];
-               return expr_tag_var(vartag_expr(o.name, o.rule));
-       } else if (t.fix.base != Tag::NONE) {
-               const Tag &o = tags[tags[t.fix.base].var.orig];
-               std::ostringstream s;
-               s << "(" << vartag_expr(o.name, o.rule) << " - " << t.fix.dist << ")";
-               return expr_tag_var(s.str());
+       if (tag.type == Tag::VAR) {
+               const Tag &orig = tags[tag.var.orig];
+               expr = vartag_expr(orig.name, orig.rule);
        } else {
-               std::ostringstream s;
-               switch (type_) {
-                       case DEFAULT:
+               const std::string dist = to_string(tag.fix.dist);
+               if (tag.fix.base == Tag::NONE) {
+                       if (type_ == DEFAULT) {
                                // optimize '(YYCTXMARKER + ((YYCURSOR - YCTXMARKER) - yyctx))'
                                // to       '(YYCURSOR - yytag)'
-                               s << "(" << opts->yycursor << " - " << t.fix.dist << ")";
-                               break;
-                       case CUSTOM:
-                               s << opts->tags_yytag << "(" << opts->tags_yydist << "() - " << t.fix.dist << ")";
-                               break;
+                               return "(" + opts->yycursor + " - " + dist + ")";
+                       }
+                       expr = opts->tags_yydist + "() - " + dist;
+               } else {
+                       const Tag &orig = tags[tags[tag.fix.base].var.orig];
+                       expr = "(" + vartag_expr(orig.name, orig.rule) + " - " + dist + ")";
                }
-               return s.str();
        }
+
+       return (type_ == DEFAULT)
+               ? "(" + opts->yyctxmarker + " + " + expr + ")"
+               : opts->tags_yytag + "(" + expr + ")";
 }
 
 std::string InputAPI::stmt_restore (uint32_t ind) const
index 8fee2c640770ed8f832809692794b1c6a3c1724c..4ed39cfe9992efb4e0ac8a1efcd6dd04ca99d738 100644 (file)
@@ -35,7 +35,7 @@ public:
        std::string expr_dist () const;
        std::string stmt_dist (uint32_t ind, const bool *tagmask,
                const std::valarray<Tag> &tags) const;
-       std::string expr_tag(const std::valarray<Tag> &tags, size_t idx) const;
+       std::string expr_tag(const std::valarray<Tag> &tags, const Tag &tag) const;
        std::string stmt_restore (uint32_t ind) const;
        std::string stmt_restorectx(uint32_t ind,
                const std::valarray<Tag> &tags, const Tag &tag, bool basetag) const;
@@ -45,9 +45,6 @@ public:
        std::string stmt_skip_backup_peek (uint32_t ind) const;
        std::string expr_lessthan_one () const;
        std::string expr_lessthan (size_t n) const;
-
-private:
-       std::string expr_tag_var(const std::string &expr) const;
 };
 
 } // end namespace re2c
index 81f2804800aea946bc3632b7c16ce570d1197436..a760deecdb7c095a1382afee2d93a25d8a131deb 100644 (file)
@@ -41,9 +41,10 @@ std::string subst_tags(const std::string &action,
                "@" @name [a-zA-Z0-9_]+ {
                        const std::string name(@name, head);
                        for (size_t i = ltag; i < htag; ++i) {
-                               if (name == *tags[i].name) {
+                               const Tag &t = tags[i];
+                               if (name == *t.name) {
                                        result.append(tail, base);
-                                       result.append(opts->input_api.expr_tag(tags, i));
+                                       result.append(opts->input_api.expr_tag(tags, t));
                                        tail = head;
                                        break;
                                }