summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2023-03-22 17:36:59 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2023-03-31 14:10:03 +0200
commitc5c3a7e0db75e0e8a41a2b99ab40c7d803bc905c (patch)
treea9a7c521dfc0a5a1374c1b0112423d7c1257d4fb
parent59fa008275ae2e05d99329dce2839201f7e992ed (diff)
qlalr: add option to error out on warning
By erroring out we can ensure that new warnings are not accidentally introduced and merged. As a drive-by: fix indentation of the --qt option. "--dot" needs three tabs, so "--qt" definitely needs it too. Fixes: QTBUG-108119 Change-Id: I56107c0744957293338080cf37350f1e1c743093 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Kai Köhne <kai.koehne@qt.io>
-rw-r--r--src/tools/qlalr/cppgenerator.cpp20
-rw-r--r--src/tools/qlalr/cppgenerator.h6
-rw-r--r--src/tools/qlalr/main.cpp8
3 files changed, 30 insertions, 4 deletions
diff --git a/src/tools/qlalr/cppgenerator.cpp b/src/tools/qlalr/cppgenerator.cpp
index 3c4264737e..c859df366d 100644
--- a/src/tools/qlalr/cppgenerator.cpp
+++ b/src/tools/qlalr/cppgenerator.cpp
@@ -193,7 +193,15 @@ void CppGenerator::operator () ()
{
if (shift_reduce_conflict_count != grammar.expected_shift_reduce
|| reduce_reduce_conflict_count != grammar.expected_reduce_reduce)
- qerr() << "*** Conflicts: " << shift_reduce_conflict_count << " shift/reduce, " << reduce_reduce_conflict_count << " reduce/reduce" << Qt::endl;
+ {
+ qerr() << "*** Conflicts: " << shift_reduce_conflict_count << " shift/reduce, " << reduce_reduce_conflict_count << " reduce/reduce" << Qt::endl;
+ if (warnings_are_errors)
+ {
+ qerr() << "qlalr: error: warning occurred, treating as error due to "
+ "--exit-on-warn." << Qt::endl;
+ exit(2);
+ }
+ }
if (verbose)
qout() << Qt::endl << "*** Conflicts: " << shift_reduce_conflict_count << " shift/reduce, " << reduce_reduce_conflict_count << " reduce/reduce" << Qt::endl
@@ -220,7 +228,15 @@ void CppGenerator::operator () ()
if (! used_rules.testBit (i))
{
if (rule != grammar.goal)
- qerr() << "*** Warning: Rule ``" << *rule << "'' is useless!" << Qt::endl;
+ {
+ qerr() << "*** Warning: Rule ``" << *rule << "'' is useless!" << Qt::endl;
+ if (warnings_are_errors)
+ {
+ qerr() << "qlalr: error: warning occurred, treating as error due to "
+ "--exit-on-warn." << Qt::endl;
+ exit(2);
+ }
+ }
}
}
diff --git a/src/tools/qlalr/cppgenerator.h b/src/tools/qlalr/cppgenerator.h
index b83dc1396c..66ae781be4 100644
--- a/src/tools/qlalr/cppgenerator.h
+++ b/src/tools/qlalr/cppgenerator.h
@@ -20,7 +20,8 @@ public:
aut (aut),
verbose (verbose),
debug_info (false),
- copyright (false) {}
+ copyright (false),
+ warnings_are_errors(false) {}
void operator () ();
@@ -29,6 +30,8 @@ public:
void setCopyright (bool t) { copyright = t; }
+ void setWarningsAreErrors (bool e) { warnings_are_errors = e; }
+
private:
void generateDecl (QTextStream &out);
void generateImpl (QTextStream &out);
@@ -51,6 +54,7 @@ private:
int non_terminal_count;
bool debug_info;
bool copyright;
+ bool warnings_are_errors;
Compress compressed_action;
Compress compressed_goto;
QList<int> count;
diff --git a/src/tools/qlalr/main.cpp b/src/tools/qlalr/main.cpp
index 8d339173ec..04ae54d986 100644
--- a/src/tools/qlalr/main.cpp
+++ b/src/tools/qlalr/main.cpp
@@ -28,7 +28,8 @@ static void help_me ()
<< " --no-debug\t\tno debug information" << Qt::endl
<< " --no-lines\t\tno #line directives" << Qt::endl
<< " --dot\t\t\tgenerate a graph" << Qt::endl
- << " --qt\t\tadd the Qt copyright header and Qt-specific types and macros" << Qt::endl
+ << " --qt\t\t\tadd the Qt copyright header and Qt-specific types and macros" << Qt::endl
+ << " --exit-on-warn\texit with status code 2 on warning" << Qt::endl
<< Qt::endl;
exit (0);
}
@@ -42,6 +43,7 @@ int main (int argc, char *argv[])
bool no_lines = false;
bool debug_info = true;
bool qt_copyright = false;
+ bool warnings_are_errors = false;
QString file_name;
const QStringList args = app.arguments().mid(1);
@@ -64,6 +66,9 @@ int main (int argc, char *argv[])
else if (arg == "--qt"_L1)
qt_copyright = true;
+ else if (arg == "--exit-on-warn"_L1)
+ warnings_are_errors = true;
+
else if (file_name.isEmpty ())
file_name = arg;
@@ -104,6 +109,7 @@ int main (int argc, char *argv[])
CppGenerator gen (p, grammar, aut, generate_report);
gen.setDebugInfo (debug_info);
gen.setCopyright (qt_copyright);
+ gen.setWarningsAreErrors (warnings_are_errors);
gen ();
if (generate_dot)