]> granicus.if.org Git - re2c/commitdiff
Changed '-Wcondition-order' to warn even if 'YYSETCONDITION' is used.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 15 Sep 2015 10:51:36 +0000 (11:51 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 15 Sep 2015 10:51:36 +0000 (11:51 +0100)
Tests 'condtype_yysetcondition.c{s,g}.re' show the reason why I changed
how '-Wcondition-order' works in presence of 'YYSETCONDITION' calls:
programs generated from these tests work differently depending on
condition numbering. Explicit use of condition names cannot guarantee
that these explicit names were generated by re2c (and not hardcoded as
in these examples).

re2c/src/codegen/emit_action.cc
re2c/src/codegen/emit_dfa.cc
re2c/test/condition_11.cg.c
re2c/test/condition_13.cg.c
re2c/test/condtype_yysetcondition.cg.c
re2c/test/condtype_yysetcondition.cg.re
re2c/test/condtype_yysetcondition.cs.c
re2c/test/condtype_yysetcondition.cs.re
re2c/test/php20150211_json_scanner.igc.c

index 64b9d93e7b2526fe3a17307ffec768205ce557a1..a20badda596c6599c7cec1062f71cfa4061d1fa8 100644 (file)
@@ -363,7 +363,6 @@ void genYYFill(OutputFile & o, uint32_t need)
 
 void genSetCondition(OutputFile & o, uint32_t ind, const std::string& newcond)
 {
-       o.warn_condition_order = false; // see note [condition order]
        if (bUseYYSetConditionParam)
        {
                o << indent(ind) << mapCodeName["YYSETCONDITION"] << "(" << condEnumPrefix << newcond << ");\n";
index 3f91e1f85e284e17710e9f8ac0b4ace996967e20..1f524b3d0f7ffa8717c1fa264d2116db44090aa8 100644 (file)
@@ -294,8 +294,9 @@ void genCondGotoSub(OutputFile & o, uint32_t ind, const std::vector<std::string>
  *
  * re2c warns about implicit assumptions about condition order, unless:
  *     - condition type is defined with 'types:re2c' or '-t, --type-header'
- *     - condition names are explicitly used in dispatch or YYSETCONDITION
- *     - dispatch shrinks to single unconditional jump
+ *     - dispatch is independent of condition order: either it uses
+ *       explicit condition names or there's only one condition and
+ *       dispatch shrinks to unconditional jump
  */
 void genCondGoto(OutputFile & o, uint32_t ind, const std::vector<std::string> & condnames)
 {
index e7745afb42e86021ab2403996d39f09924f27cee..6f252ef4868b4214f09dda2f41b6e2913e322587 100644 (file)
@@ -1,6 +1,7 @@
 re2c: warning: line 3: rule matches empty string [-Wmatch-empty-string]
 re2c: warning: line 9: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
 re2c: warning: line 9: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 9: looks like you use hardcoded numbers instead of autogenerated condition names: better add '/*!types:re2c*/' directive or '-t, --type-header' option and don't rely on fixed condition order. [-Wcondition-order]
 /* Generated by re2c */
 #line 1 "condition_11.cg.re"
 
index 09f198a2cbecd0f0fc4a4d501d825ff37f3d82df..305b05f676ffb6bbc5f9a2bdfaf29271d55264e3 100644 (file)
@@ -1,6 +1,7 @@
 re2c: warning: line 3: rule matches empty string [-Wmatch-empty-string]
 re2c: warning: line 9: control flow in condition 'r1' is undefined for strings that match '[\x0-\x30\x33-\x60\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
 re2c: warning: line 9: control flow in condition 'r2' is undefined for strings that match '[\x0-\x30\x33-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 9: looks like you use hardcoded numbers instead of autogenerated condition names: better add '/*!types:re2c*/' directive or '-t, --type-header' option and don't rely on fixed condition order. [-Wcondition-order]
 /* Generated by re2c */
 #line 1 "condition_13.cg.re"
 
index b8ba95819f0d17fd697c4038062bb76e2cc6c168..a10216b37300e8c71ef31794ca1b1a7d6e256fe2 100644 (file)
@@ -1,42 +1,58 @@
-re2c: warning: line 11: control flow in condition 'a' is undefined for strings that match '[\x0-\x60\x62-\xFF]', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 11: control flow in condition 'b' is undefined for strings that match '[\x0-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 28: looks like you use hardcoded numbers instead of autogenerated condition names: better add '/*!types:re2c*/' directive or '-t, --type-header' option and don't rely on fixed condition order. [-Wcondition-order]
 /* Generated by re2c */
 #line 1 "condtype_yysetcondition.cg.re"
+#include <stdio.h>
+
+// changing this to '#if 1' changes program behaviour
+#if 0
+#    define yyca 1
+#    define yycb 0
+#else
+#    define yyca 0
+#    define yycb 1
+#endif
+
 int main ()
 {
-       YYCONDTYPE cond;
-       char * YYCURSOR;
+       int cond = yyca;
+       char * YYCURSOR = "aaaaaaaabb";
+#define YYSETCONDITION(c) cond = c
 #define YYGETCONDITION() cond
+       for (;;)
+       {
 
-#line 10 "<stdout>"
+#line 24 "<stdout>"
 {
        unsigned char yych;
        static void *yyctable[2] = {
-               &&yyc_a,
                &&yyc_b,
+               &&yyc_a,
        };
        goto *yyctable[YYGETCONDITION()];
 /* *********************************** */
 yyc_a:
        yych = *YYCURSOR;
-       if (yych == 'a') goto yy4;
-yy4:
+       if (yych != 'a') goto yy5;
+       ++YYCURSOR;
+#line 26 "condtype_yysetcondition.cg.re"
+       { printf ("a\n");      continue; }
+#line 39 "<stdout>"
+yy5:
        ++YYCURSOR;
        YYSETCONDITION(yycb);
-#line 9 "condtype_yysetcondition.cg.re"
-       {}
-#line 27 "<stdout>"
+#line 27 "condtype_yysetcondition.cg.re"
+       { printf ("a => b\n"); continue; }
+#line 45 "<stdout>"
 /* *********************************** */
 yyc_b:
        yych = *YYCURSOR;
-       if (yych == 'b') goto yy9;
-yy9:
        ++YYCURSOR;
-#line 10 "condtype_yysetcondition.cg.re"
-       {}
-#line 36 "<stdout>"
+#line 24 "condtype_yysetcondition.cg.re"
+       { printf ("b\n"); break; }
+#line 52 "<stdout>"
 }
-#line 11 "condtype_yysetcondition.cg.re"
+#line 28 "condtype_yysetcondition.cg.re"
 
+       }
        return 0;
 }
index ed9175c3ee5d177d3875c44145974893033bcd08..54d16177ab3623722a1c38eedeeb57b556429768 100644 (file)
@@ -1,13 +1,31 @@
+#include <stdio.h>
+
+// changing this to '#if 1' changes program behaviour
+#if 0
+#    define yyca 1
+#    define yycb 0
+#else
+#    define yyca 0
+#    define yycb 1
+#endif
+
 int main ()
 {
-       YYCONDTYPE cond;
-       char * YYCURSOR;
+       int cond = yyca;
+       char * YYCURSOR = "aaaaaaaabb";
+#define YYSETCONDITION(c) cond = c
 #define YYGETCONDITION() cond
+       for (;;)
+       {
 /*!re2c
        re2c:yyfill:enable = 0;
        re2c:define:YYCTYPE = "unsigned char";
-       <a> "a" => b {}
-       <b> "b"      {}
+
+       <b> [^] { printf ("b\n"); break; }
+
+       <a> "a"       { printf ("a\n");      continue; }
+       <a> [^a] => b { printf ("a => b\n"); continue; }
 */
+       }
        return 0;
 }
index 867334b5304b607b5d4610e7f8cbd4331b82ba14..569dbafe17af44bd64d00cfa1b234a3a4da4864c 100644 (file)
@@ -1,42 +1,58 @@
-re2c: warning: line 11: control flow in condition 'a' is undefined for strings that match '[\x0-\x60\x62-\xFF]', use default rule '*' [-Wundefined-control-flow]
-re2c: warning: line 11: control flow in condition 'b' is undefined for strings that match '[\x0-\x61\x63-\xFF]', use default rule '*' [-Wundefined-control-flow]
+re2c: warning: line 28: looks like you use hardcoded numbers instead of autogenerated condition names: better add '/*!types:re2c*/' directive or '-t, --type-header' option and don't rely on fixed condition order. [-Wcondition-order]
 /* Generated by re2c */
 #line 1 "condtype_yysetcondition.cs.re"
+#include <stdio.h>
+
+// changing this to '#if 1' changes program behaviour
+#if 0
+#    define yyca 1
+#    define yycb 0
+#else
+#    define yyca 0
+#    define yycb 1
+#endif
+
 int main ()
 {
-       YYCONDTYPE cond;
-       char * YYCURSOR;
+       int cond = yyca;
+       char * YYCURSOR = "aaaaaaaabb";
+#define YYSETCONDITION(c) cond = c
 #define YYGETCONDITION() cond
+       for (;;)
+       {
 
-#line 10 "<stdout>"
+#line 24 "<stdout>"
 {
        unsigned char yych;
        if (YYGETCONDITION() < 1) {
-               goto yyc_a;
-       } else {
                goto yyc_b;
+       } else {
+               goto yyc_a;
        }
 /* *********************************** */
 yyc_a:
        yych = *YYCURSOR;
-       if (yych == 'a') goto yy4;
-yy4:
+       if (yych != 'a') goto yy5;
+       ++YYCURSOR;
+#line 26 "condtype_yysetcondition.cs.re"
+       { printf ("a\n");      continue; }
+#line 39 "<stdout>"
+yy5:
        ++YYCURSOR;
        YYSETCONDITION(yycb);
-#line 9 "condtype_yysetcondition.cs.re"
-       {}
-#line 27 "<stdout>"
+#line 27 "condtype_yysetcondition.cs.re"
+       { printf ("a => b\n"); continue; }
+#line 45 "<stdout>"
 /* *********************************** */
 yyc_b:
        yych = *YYCURSOR;
-       if (yych == 'b') goto yy9;
-yy9:
        ++YYCURSOR;
-#line 10 "condtype_yysetcondition.cs.re"
-       {}
-#line 36 "<stdout>"
+#line 24 "condtype_yysetcondition.cs.re"
+       { printf ("b\n"); break; }
+#line 52 "<stdout>"
 }
-#line 11 "condtype_yysetcondition.cs.re"
+#line 28 "condtype_yysetcondition.cs.re"
 
+       }
        return 0;
 }
index ed9175c3ee5d177d3875c44145974893033bcd08..54d16177ab3623722a1c38eedeeb57b556429768 100644 (file)
@@ -1,13 +1,31 @@
+#include <stdio.h>
+
+// changing this to '#if 1' changes program behaviour
+#if 0
+#    define yyca 1
+#    define yycb 0
+#else
+#    define yyca 0
+#    define yycb 1
+#endif
+
 int main ()
 {
-       YYCONDTYPE cond;
-       char * YYCURSOR;
+       int cond = yyca;
+       char * YYCURSOR = "aaaaaaaabb";
+#define YYSETCONDITION(c) cond = c
 #define YYGETCONDITION() cond
+       for (;;)
+       {
 /*!re2c
        re2c:yyfill:enable = 0;
        re2c:define:YYCTYPE = "unsigned char";
-       <a> "a" => b {}
-       <b> "b"      {}
+
+       <b> [^] { printf ("b\n"); break; }
+
+       <a> "a"       { printf ("a\n");      continue; }
+       <a> [^a] => b { printf ("a => b\n"); continue; }
 */
+       }
        return 0;
 }
index aa1765f47e0e350c421e86ad23508c6c21dee554..296bac319c7a050a9872bf4b3f80af59fb5c68e5 100644 (file)
@@ -1,3 +1,4 @@
+re2c: warning: line 340: looks like you use hardcoded numbers instead of autogenerated condition names: better add '/*!types:re2c*/' directive or '-t, --type-header' option and don't rely on fixed condition order. [-Wcondition-order]
 /* Generated by re2c */
 /*
   +----------------------------------------------------------------------+