diff options
Diffstat (limited to 'src/tools/qlalr/cppgenerator.cpp')
-rw-r--r-- | src/tools/qlalr/cppgenerator.cpp | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/src/tools/qlalr/cppgenerator.cpp b/src/tools/qlalr/cppgenerator.cpp index a41aa87835..f12917f0eb 100644 --- a/src/tools/qlalr/cppgenerator.cpp +++ b/src/tools/qlalr/cppgenerator.cpp @@ -1,5 +1,7 @@ +// REUSE-IgnoreStart // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// REUSE-IgnoreEnd #include "cppgenerator.h" @@ -10,6 +12,7 @@ #include <QtCore/qtextstream.h> #include <QtCore/qfile.h> #include <QtCore/qmap.h> +#include <QtCore/private/qconfig_p.h> #include <iterator> @@ -38,14 +41,15 @@ void generateList(const QList<int> &list, QTextStream &out) } } - +// REUSE-IgnoreStart QString CppGenerator::copyrightHeader() const { return - "// Copyright (C) 2016 The Qt Company Ltd.\n" + "// " QT_COPYRIGHT "\n" "// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0\n" "\n"_L1; } +// REUSE-IgnoreEnd QString CppGenerator::privateCopyrightHeader() const { @@ -192,7 +196,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 @@ -214,12 +226,20 @@ void CppGenerator::operator () () } auto rule = grammar.rules.begin(); - for (int i = 0; i < used_rules.count (); ++i, ++rule) + for (int i = 0; i < used_rules.size(); ++i, ++rule) { 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); + } + } } } @@ -331,7 +351,12 @@ void CppGenerator::operator () () { // decls... QFile f (declFileName); - f.open (QFile::WriteOnly); + if (! f.open (QFile::WriteOnly)) + { + fprintf (stderr, "*** cannot create %s: %s\n", + qPrintable(declFileName), qPrintable(f.errorString())); + return; + } QTextStream out (&f); QString prot = declFileName.toUpper ().replace (QLatin1Char ('.'), QLatin1Char ('_')); @@ -363,7 +388,12 @@ void CppGenerator::operator () () { // bits... QFile f (bitsFileName); - f.open (QFile::WriteOnly); + if (! f.open (QFile::WriteOnly)) + { + fprintf (stderr, "*** cannot create %s: %s\n", + qPrintable(bitsFileName), qPrintable(f.errorString())); + return; + } QTextStream out (&f); // copyright headers must come first, otherwise the headers tests will fail @@ -384,7 +414,12 @@ void CppGenerator::operator () () if (! grammar.decl_file_name.isEmpty ()) { QFile f (grammar.decl_file_name); - f.open (QFile::WriteOnly); + if (! f.open (QFile::WriteOnly)) + { + fprintf (stderr, "*** cannot create %s: %s\n", + qPrintable(grammar.decl_file_name), qPrintable(f.errorString())); + return; + } QTextStream out (&f); out << p.decls(); } @@ -392,7 +427,12 @@ void CppGenerator::operator () () if (! grammar.impl_file_name.isEmpty ()) { QFile f (grammar.impl_file_name); - f.open (QFile::WriteOnly); + if (! f.open (QFile::WriteOnly)) + { + fprintf (stderr, "*** cannot create %s: %s\n", + qPrintable(grammar.impl_file_name), qPrintable(f.errorString())); + return; + } QTextStream out (&f); out << p.impls(); } @@ -413,7 +453,7 @@ void CppGenerator::generateDecl (QTextStream &out) << "public:" << Qt::endl << " enum VariousConstants {" << Qt::endl; - for (const Name &t : qAsConst(grammar.terminals)) + for (const Name &t : std::as_const(grammar.terminals)) { QString name = *t; int value = std::distance (grammar.names.begin (), t); |