]> granicus.if.org Git - re2c/commitdiff
Moved dispatch on fixed/variable tags inside of tag-printing function.
authorUlya Trofimovich <skvadrik@gmail.com>
Fri, 13 May 2016 13:35:10 +0000 (14:35 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Fri, 13 May 2016 13:35:10 +0000 (14:35 +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 1cf27ee182d5d87eeec007cffa64686695d17e1f..211fcc99524935d785d641836219f264c7685386 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.16 on Fri May 13 13:49:35 2016 */
+/* Generated by re2c 0.16 on Fri May 13 14:25:27 2016 */
 #line 1 "../src/codegen/subst_tags.re"
 #include "src/codegen/emit.h"
 #include "src/codegen/input_api.h"
@@ -113,21 +113,18 @@ yy7:
        {
                        const std::string name((base + yytag1name), head);
                        for (size_t i = ltag; i < htag; ++i) {
-                               const Tag &t = tags[i];
-                               if (name == *t.name) {
+                               if (name == *tags[i].name) {
                                        result.append(tail, base);
-                                       result.append(t.type == Tag::VAR
-                                               ? opts->input_api.expr_tag(vartag_expr(t.name, t.rule))
-                                               : opts->input_api.expr_tag_fix(t, tags));
+                                       result.append(opts->input_api.expr_tag(tags, i));
                                        tail = head;
                                        break;
                                }
                        }
                        goto loop;
                }
-#line 129 "src/codegen/subst_tags.cc"
+#line 126 "src/codegen/subst_tags.cc"
 }
-#line 56 "../src/codegen/subst_tags.re"
+#line 53 "../src/codegen/subst_tags.re"
 
 }
 
index b61269d41b0668aeded5dc99a79a02b56162254f..b02e1c851155e6f7ba28dbc872314e3b32354d0e 100644 (file)
@@ -121,34 +121,38 @@ std::string InputAPI::stmt_dist (uint32_t ind, const bool *mask,
        return s + expr_dist() + ";\n";
 }
 
-std::string InputAPI::expr_tag(const std::string &var) const
+std::string InputAPI::expr_tag_var(const std::string &expr) const
 {
        switch (type_) {
-               case DEFAULT: return "(" + opts->yyctxmarker + " + " + var + ")";
-               case CUSTOM:  return opts->tags_yytag + "(" + var + ")";
+               case DEFAULT: return "(" + opts->yyctxmarker + " + " + expr + ")";
+               case CUSTOM:  return opts->tags_yytag + "(" + expr + ")";
                default:      assert(false);
        }
 }
 
-std::string InputAPI::expr_tag_fix(const Tag &tag, const std::valarray<Tag> &tags) const
+std::string InputAPI::expr_tag(const std::valarray<Tag> &tags, size_t idx) const
 {
-       std::ostringstream s;
-       if (tag.fix.base == Tag::NONE) {
+       const Tag &t = tags[idx];
+       if (t.type == Tag::VAR) {
+               return expr_tag_var(vartag_expr(t.name, t.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());
+       } else {
+               std::ostringstream s;
                switch (type_) {
                        case DEFAULT:
                                // optimize '(YYCTXMARKER + ((YYCURSOR - YCTXMARKER) - yyctx))'
                                // to       '(YYCURSOR - yytag)'
-                               s << "(" << opts->yycursor << " - " << tag.fix.dist << ")";
+                               s << "(" << opts->yycursor << " - " << t.fix.dist << ")";
                                break;
                        case CUSTOM:
-                               s << opts->tags_yytag << "(" << opts->tags_yydist << "() - " << tag.fix.dist << ")";
+                               s << opts->tags_yytag << "(" << opts->tags_yydist << "() - " << t.fix.dist << ")";
                                break;
                }
                return s.str();
-       } else {
-               const Tag &t = tags[tags[tag.fix.base].var.orig];
-               s << "(" << vartag_expr(t.name, t.rule) << " - " << tag.fix.dist << ")";
-               return expr_tag(s.str());
        }
 }
 
index b05f991160ed55a1ba407513e9ca14ff59192e0d..e698f896f0166db98d427b5d8e8c6b2972d08c7c 100644 (file)
@@ -35,8 +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::string &var) const;
-       std::string expr_tag_fix(const Tag &tag, const std::valarray<Tag> &tags) const;
+       std::string expr_tag(const std::valarray<Tag> &tags, size_t idx) const;
        std::string stmt_restore (uint32_t ind) const;
        std::string stmt_restorectx_fix (uint32_t ind, size_t dist) const;
        std::string stmt_restorectx_var (uint32_t ind) const;
@@ -47,6 +46,9 @@ 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 940aa8a8a7e774f9b242f04def902750c50938ad..81f2804800aea946bc3632b7c16ce570d1197436 100644 (file)
@@ -41,12 +41,9 @@ 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) {
-                               const Tag &t = tags[i];
-                               if (name == *t.name) {
+                               if (name == *tags[i].name) {
                                        result.append(tail, base);
-                                       result.append(t.type == Tag::VAR
-                                               ? opts->input_api.expr_tag(vartag_expr(t.name, t.rule))
-                                               : opts->input_api.expr_tag_fix(t, tags));
+                                       result.append(opts->input_api.expr_tag(tags, i));
                                        tail = head;
                                        break;
                                }