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>
This commit is contained in:
Mårten Nordheim 2023-03-22 17:36:59 +01:00
parent 59fa008275
commit c5c3a7e0db
3 changed files with 30 additions and 4 deletions

View File

@ -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);
}
}
}
}

View File

@ -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;

View File

@ -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)