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:
parent
59fa008275
commit
c5c3a7e0db
@ -193,7 +193,15 @@ void CppGenerator::operator () ()
|
|||||||
{
|
{
|
||||||
if (shift_reduce_conflict_count != grammar.expected_shift_reduce
|
if (shift_reduce_conflict_count != grammar.expected_shift_reduce
|
||||||
|| reduce_reduce_conflict_count != grammar.expected_reduce_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)
|
if (verbose)
|
||||||
qout() << Qt::endl << "*** Conflicts: " << shift_reduce_conflict_count << " shift/reduce, " << reduce_reduce_conflict_count << " reduce/reduce" << Qt::endl
|
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 (! used_rules.testBit (i))
|
||||||
{
|
{
|
||||||
if (rule != grammar.goal)
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ public:
|
|||||||
aut (aut),
|
aut (aut),
|
||||||
verbose (verbose),
|
verbose (verbose),
|
||||||
debug_info (false),
|
debug_info (false),
|
||||||
copyright (false) {}
|
copyright (false),
|
||||||
|
warnings_are_errors(false) {}
|
||||||
|
|
||||||
void operator () ();
|
void operator () ();
|
||||||
|
|
||||||
@ -29,6 +30,8 @@ public:
|
|||||||
|
|
||||||
void setCopyright (bool t) { copyright = t; }
|
void setCopyright (bool t) { copyright = t; }
|
||||||
|
|
||||||
|
void setWarningsAreErrors (bool e) { warnings_are_errors = e; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generateDecl (QTextStream &out);
|
void generateDecl (QTextStream &out);
|
||||||
void generateImpl (QTextStream &out);
|
void generateImpl (QTextStream &out);
|
||||||
@ -51,6 +54,7 @@ private:
|
|||||||
int non_terminal_count;
|
int non_terminal_count;
|
||||||
bool debug_info;
|
bool debug_info;
|
||||||
bool copyright;
|
bool copyright;
|
||||||
|
bool warnings_are_errors;
|
||||||
Compress compressed_action;
|
Compress compressed_action;
|
||||||
Compress compressed_goto;
|
Compress compressed_goto;
|
||||||
QList<int> count;
|
QList<int> count;
|
||||||
|
@ -28,7 +28,8 @@ static void help_me ()
|
|||||||
<< " --no-debug\t\tno debug information" << Qt::endl
|
<< " --no-debug\t\tno debug information" << Qt::endl
|
||||||
<< " --no-lines\t\tno #line directives" << Qt::endl
|
<< " --no-lines\t\tno #line directives" << Qt::endl
|
||||||
<< " --dot\t\t\tgenerate a graph" << 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;
|
<< Qt::endl;
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
@ -42,6 +43,7 @@ int main (int argc, char *argv[])
|
|||||||
bool no_lines = false;
|
bool no_lines = false;
|
||||||
bool debug_info = true;
|
bool debug_info = true;
|
||||||
bool qt_copyright = false;
|
bool qt_copyright = false;
|
||||||
|
bool warnings_are_errors = false;
|
||||||
QString file_name;
|
QString file_name;
|
||||||
|
|
||||||
const QStringList args = app.arguments().mid(1);
|
const QStringList args = app.arguments().mid(1);
|
||||||
@ -64,6 +66,9 @@ int main (int argc, char *argv[])
|
|||||||
else if (arg == "--qt"_L1)
|
else if (arg == "--qt"_L1)
|
||||||
qt_copyright = true;
|
qt_copyright = true;
|
||||||
|
|
||||||
|
else if (arg == "--exit-on-warn"_L1)
|
||||||
|
warnings_are_errors = true;
|
||||||
|
|
||||||
else if (file_name.isEmpty ())
|
else if (file_name.isEmpty ())
|
||||||
file_name = arg;
|
file_name = arg;
|
||||||
|
|
||||||
@ -104,6 +109,7 @@ int main (int argc, char *argv[])
|
|||||||
CppGenerator gen (p, grammar, aut, generate_report);
|
CppGenerator gen (p, grammar, aut, generate_report);
|
||||||
gen.setDebugInfo (debug_info);
|
gen.setDebugInfo (debug_info);
|
||||||
gen.setCopyright (qt_copyright);
|
gen.setCopyright (qt_copyright);
|
||||||
|
gen.setWarningsAreErrors (warnings_are_errors);
|
||||||
gen ();
|
gen ();
|
||||||
|
|
||||||
if (generate_dot)
|
if (generate_dot)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user