]> granicus.if.org Git - re2c/commitdiff
Improved label generation with EOF rule (removed unused and added missing labels).
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 6 Mar 2019 21:47:49 +0000 (21:47 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 6 Mar 2019 21:47:49 +0000 (21:47 +0000)
12 files changed:
re2c/src/codegen/emit_action.cc
re2c/src/codegen/emit_dfa.cc
re2c/src/codegen/go.h
re2c/src/codegen/go_construct.cc
re2c/src/codegen/go_used_labels.cc
re2c/test/eof/eof_01.i--eager-skip.c
re2c/test/eof/eof_01.i.c
re2c/test/eof/eof_02.i.c
re2c/test/eof/eof_03.i.c
re2c/test/eof/eof_04.i8.c
re2c/test/eof/nonblocking_push.fi.c
re2c/test/eof/utf8_any.i.c

index 4869f866cecfd92b31d6555389d938e525119fba..b25370b2b39fcb0e7108313511813dc955ef7386 100644 (file)
@@ -241,15 +241,16 @@ void need(Output &o, uint32_t ind, size_t some)
 void gen_rescan_label(Output &o, const State *s)
 {
     const opt_t *opts = o.block().opts;
-
-    if (opts->eof == NOEOF || endstate(s)) return;
-
-    o.wstring(opts->labelPrefix).wlabel(s->label).ws("_:\n");
-
-    if (opts->fFlag) {
+    if (opts->eof == NOEOF || endstate(s)) {
+        ; // no rescan label
+    }
+    else if (opts->fFlag) {
         o.wstring(opts->yyfilllabel).wu32(o.fill_index).ws(":\n");
         ++o.fill_index;
     }
+    else {
+        o.wstring(opts->labelPrefix).wlabel(s->label).ws("_:\n");
+    }
 }
 
 void gen_goto_case(Output &o, uint32_t ind, const State *from, const State *to,
@@ -566,6 +567,7 @@ bool endstate(const State *s)
     // usually 'end' states are final states (not all final states are 'end'
     // states), but sometimes 'end' state happens to be initial non-accepting
     // state, e.g. in case of rule '[]'
+    DASSERT(s->go.nSpans > 0);
     const Action::type_t &a = s->go.span[0].to->action.type;
     return s->go.nSpans == 1
         && (a == Action::RULE || a == Action::ACCEPT);
index 17101147a0331e7a89b13066a12a4cddf12ddd5c..f81b8e4c1904026ab79cea0f43916a5c52fa4586 100644 (file)
@@ -31,9 +31,6 @@ static void emit_eof(Output &, uint32_t, const Code*);
 void emit_state (Output & o, uint32_t ind, const State * s, bool used_label)
 {
     const opt_t *opts = o.block().opts;
-    used_label |= opts->eof != NOEOF
-        && (s->action.type == Action::MOVE
-            || s->action.type == Action::INITIAL);
     if (used_label)
     {
         o.wstring(opts->labelPrefix).wlabel(s->label).ws(":\n");
index 86ddc3acdc740ebb5347f59b31308222a5432ae2..469a5038443039ed8820fa65a0cbdff7e94bb399 100644 (file)
@@ -85,6 +85,7 @@ struct Linear
 
     size_t nbranches;
     Branch *branches;
+    const State *def;
 
     Linear(const Span *s, uint32_t n, const State *next, bool skip, uint32_t eof);
     ~Linear();
index a328b792fdcfece6c164c652b5600f331ddc254e..dc74282af7871c8c9fa2cde9ee8fe68f02e6c0cc 100644 (file)
@@ -111,6 +111,7 @@ Linear::Linear(const Span *s, uint32_t n, const State *next
     , bool skip, uint32_t eof)
     : nbranches(0)
     , branches(new Branch[n])
+    , def(eof == NOEOF ? NULL : next)
 {
     for (;;) {
         if (n == 1 && s[0].to == next) {
index a3cc5c955e4ab45115a0a6e823c8b9167ff77f94..7b53240fde38f15ecac1ccafb6c090eb217e6838 100644 (file)
@@ -32,6 +32,9 @@ void Linear::used_labels (std::set<label_t> & used) const
             used.insert(to->label);
         }
     }
+    if (def) {
+        used.insert(def->label);
+    }
 }
 
 void If::used_labels (std::set<label_t> & used) const
index 1857cd2acbe0dfb69be74f5a4fa6b15364b0cf32..2fe31ff4965f06d25eaa2d4be92c1a1148574d22 100644 (file)
@@ -49,7 +49,6 @@ static bool lex(input_t & in, unsigned int &count)
         
 {
        char yych;
-yy1:
 yy1_:
        yych = *in.cur++;
        switch (yych) {
@@ -134,7 +133,6 @@ yy3:
 yy4:
 yy4_:
        yych = *in.cur;
-yy5:
        switch (yych) {
        case '\n':
                ++in.cur;
@@ -149,9 +147,7 @@ yy6:
        { continue; }
 yy7:
 yy7_:
-       yych = *in.cur;
-yy8:
-       ++in.cur;
+       yych = *in.cur++;
        switch (yych) {
        case '"':       goto yy26;
        case '\\':      goto yy28;
@@ -164,9 +160,7 @@ yy8:
        }
 yy9:
 yy9_:
-       yych = *in.cur;
-yy10:
-       ++in.cur;
+       yych = *in.cur++;
        switch (yych) {
        case '\'':      goto yy29;
        case '\\':      goto yy31;
index 3f700f2bcd09145fde2a4fdc51551b51c9de5905..e9e262627c4fcf41306bad1349a662108034d822 100644 (file)
@@ -49,7 +49,6 @@ static bool lex(input_t & in, unsigned int &count)
         
 {
        char yych;
-yy1:
 yy1_:
        yych = *in.cur;
        switch (yych) {
@@ -136,7 +135,6 @@ yy4:
        ++in.cur;
 yy4_:
        yych = *in.cur;
-yy5:
        switch (yych) {
        case '\n':      goto yy4;
        default:
@@ -151,7 +149,6 @@ yy7:
        ++in.cur;
 yy7_:
        yych = *in.cur;
-yy8:
        switch (yych) {
        case '"':       goto yy26;
        case '\\':      goto yy28;
@@ -166,7 +163,6 @@ yy9:
        ++in.cur;
 yy9_:
        yych = *in.cur;
-yy10:
        switch (yych) {
        case '\'':      goto yy29;
        case '\\':      goto yy31;
index 72c1cc0fe4adcad95be9d79015072b53aabe340c..fb1d39951f3ccb316a1f5bdbdf23d528ba5bc8b5 100644 (file)
@@ -49,7 +49,6 @@ static bool lex(input_t & in, unsigned int &count)
         
 {
        char yych;
-yy1:
 yy1_:
        yych = *in.cur;
        switch (yych) {
@@ -78,7 +77,6 @@ yy4:
        ++in.cur;
 yy4_:
        yych = *in.cur;
-yy5:
        switch (yych) {
        case '\n':      goto yy4;
        default:
@@ -93,7 +91,6 @@ yy7:
        ++in.cur;
 yy7_:
        yych = *in.cur;
-yy8:
        switch (yych) {
        case '0':
        case '1':
index d1911156b17fca83938201504a6e958144f4d5cc..6d1b591471fe03d89108561997606ffc1e006e4a 100644 (file)
@@ -49,7 +49,6 @@ static bool lex(input_t & in, unsigned int &count)
         
 {
        char yych;
-yy1:
 yy1_:
        yych = *in.cur;
        switch (yych) {
@@ -78,7 +77,6 @@ yy4:
        ++in.cur;
 yy4_:
        yych = *in.cur;
-yy5:
        switch (yych) {
        case '\n':      goto yy4;
        default:
@@ -93,7 +91,6 @@ yy7:
        ++in.cur;
 yy7_:
        yych = *in.cur;
-yy8:
        switch (yych) {
        case '0':
        case '1':
index fdc8e242b2a9874229dbe664418ceb059bd494db..80df5908639c4a98a232342e9df254eeed0aa50e 100644 (file)
@@ -54,7 +54,6 @@ static bool lex(input_t & in, unsigned int &count)
 {
        uint8_t yych;
        unsigned int yyaccept = 0;
-yy1:
 yy1_:
        yych = *in.cur;
        switch (yych) {
@@ -249,7 +248,6 @@ yy2:
        in.mar = ++in.cur;
 yy2_:
        yych = *in.cur;
-yy3:
        switch (yych) {
        case 0x00:
        case 0x01:
@@ -441,7 +439,6 @@ yy5:
        ++in.cur;
 yy5_:
        yych = *in.cur;
-yy6:
        switch (yych) {
        case '\n':      goto yy5;
        default:
index 197cb810523d41d3ba1263e0d8ee4ebea4dd9879..3caaedddc146c0a12c3ea689fd6379598e1e48e1 100644 (file)
@@ -118,9 +118,7 @@ case 20: goto yyFillLabel20;
 
 
 
-yy1:
 yy0:
-yy1_:
 yyFillLabel0:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -194,10 +192,8 @@ yy4:
        { printf("< Unexpected character >%c<\n", in.yych); return FAIL; }
 yy6:
        ++in.cur;
-yy6_:
 yyFillLabel1:
        in.yych = *in.cur;
-yy7:
        switch (in.yych) {
        case '\n':
        case ' ':       goto yy6;
@@ -212,7 +208,6 @@ yy8:
        { printf("< whitespace\n");                         return WHITESPACE; }
 yy9:
        ++in.cur;
-yy9_:
 yyFillLabel2:
        in.yych = *in.cur;
 yy10:
@@ -280,7 +275,6 @@ yy11:
        { printf("< word\n");                               return WORD; }
 yy12:
        ++in.cur;
-yy12_:
 yyFillLabel3:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -295,7 +289,6 @@ yyFillLabel3:
        }
 yy13:
        ++in.cur;
-yy13_:
 yyFillLabel4:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -310,7 +303,6 @@ yyFillLabel4:
        }
 yy14:
        ++in.cur;
-yy14_:
 yyFillLabel5:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -325,7 +317,6 @@ yyFillLabel5:
        }
 yy15:
        ++in.cur;
-yy15_:
 yyFillLabel6:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -340,7 +331,6 @@ yyFillLabel6:
        }
 yy16:
        in.mark = ++in.cur;
-yy16_:
 yyFillLabel7:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -355,7 +345,6 @@ yyFillLabel7:
        }
 yy17:
        ++in.cur;
-yy17_:
 yyFillLabel8:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -372,7 +361,6 @@ yy18:
        goto yy11;
 yy19:
        ++in.cur;
-yy19_:
 yyFillLabel9:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -386,7 +374,6 @@ yyFillLabel9:
        }
 yy20:
        ++in.cur;
-yy20_:
 yyFillLabel10:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -400,7 +387,6 @@ yyFillLabel10:
        }
 yy21:
        ++in.cur;
-yy21_:
 yyFillLabel11:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -414,7 +400,6 @@ yyFillLabel11:
        }
 yy22:
        ++in.cur;
-yy22_:
 yyFillLabel12:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -428,7 +413,6 @@ yyFillLabel12:
        }
 yy23:
        ++in.cur;
-yy23_:
 yyFillLabel13:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -442,7 +426,6 @@ yyFillLabel13:
        }
 yy24:
        ++in.cur;
-yy24_:
 yyFillLabel14:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -456,7 +439,6 @@ yyFillLabel14:
        }
 yy25:
        ++in.cur;
-yy25_:
 yyFillLabel15:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -470,7 +452,6 @@ yyFillLabel15:
        }
 yy26:
        ++in.cur;
-yy26_:
 yyFillLabel16:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -484,7 +465,6 @@ yyFillLabel16:
        }
 yy27:
        ++in.cur;
-yy27_:
 yyFillLabel17:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -498,7 +478,6 @@ yyFillLabel17:
        }
 yy28:
        ++in.cur;
-yy28_:
 yyFillLabel18:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -512,7 +491,6 @@ yyFillLabel18:
        }
 yy29:
        ++in.cur;
-yy29_:
 yyFillLabel19:
        in.yych = *in.cur;
        switch (in.yych) {
@@ -526,7 +504,6 @@ yyFillLabel19:
        }
 yy30:
        ++in.cur;
-yy30_:
 yyFillLabel20:
        in.yych = *in.cur;
        switch (in.yych) {
index e4702f54066512a25942aa58a689c3dfbac09473..3bcae18901aa18c029c36765097da4719732299d 100644 (file)
@@ -1395,7 +1395,6 @@ static Result lex1_simple(uint8_t *cur, uint8_t* end, uint8_t* /* unused */)
     
 {
        uint8_t yych;
-yy31:
 yy31_:
        yych = *cur;
        switch (yych) {