summaryrefslogtreecommitdiffstats
path: root/src/tools/qlalr/cppgenerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/qlalr/cppgenerator.cpp')
-rw-r--r--src/tools/qlalr/cppgenerator.cpp146
1 files changed, 69 insertions, 77 deletions
diff --git a/src/tools/qlalr/cppgenerator.cpp b/src/tools/qlalr/cppgenerator.cpp
index 7efe94a5c2..f12917f0eb 100644
--- a/src/tools/qlalr/cppgenerator.cpp
+++ b/src/tools/qlalr/cppgenerator.cpp
@@ -1,30 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QLALR module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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"
@@ -35,9 +12,12 @@
#include <QtCore/qtextstream.h>
#include <QtCore/qfile.h>
#include <QtCore/qmap.h>
+#include <QtCore/private/qconfig_p.h>
#include <iterator>
+using namespace Qt::StringLiterals;
+
namespace {
void generateSeparator(int i, QTextStream &out)
@@ -61,43 +41,19 @@ void generateList(const QList<int> &list, QTextStream &out)
}
}
-
+// REUSE-IgnoreStart
QString CppGenerator::copyrightHeader() const
{
- return QLatin1String(
- "/****************************************************************************\n"
- "**\n"
- "** Copyright (C) 2016 The Qt Company Ltd.\n"
- "** Contact: https://www.qt.io/licensing/\n"
- "**\n"
- "** This file is part of the Qt Toolkit.\n"
- "**\n"
- "** $QT_BEGIN_LICENSE:GPL-EXCEPT$\n"
- "** Commercial License Usage\n"
- "** Licensees holding valid commercial Qt licenses may use this file in\n"
- "** accordance with the commercial license agreement provided with the\n"
- "** Software or, alternatively, in accordance with the terms contained in\n"
- "** a written agreement between you and The Qt Company. For licensing terms\n"
- "** and conditions see https://www.qt.io/terms-conditions. For further\n"
- "** information use the contact form at https://www.qt.io/contact-us.\n"
- "**\n"
- "** GNU General Public License Usage\n"
- "** Alternatively, this file may be used under the terms of the GNU\n"
- "** General Public License version 3 as published by the Free Software\n"
- "** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT\n"
- "** included in the packaging of this file. Please review the following\n"
- "** information to ensure the GNU General Public License requirements will\n"
- "** be met: https://www.gnu.org/licenses/gpl-3.0.html.\n"
- "**\n"
- "** $QT_END_LICENSE$\n"
- "**\n"
- "****************************************************************************/\n"
- "\n");
+ return
+ "// " 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
{
- return QLatin1String(
+ return
"//\n"
"// W A R N I N G\n"
"// -------------\n"
@@ -107,12 +63,12 @@ QString CppGenerator::privateCopyrightHeader() const
"// version without notice, or even be removed.\n"
"//\n"
"// We mean it.\n"
- "//\n");
+ "//\n"_L1;
}
QString CppGenerator::startIncludeGuard(const QString &fileName)
{
- const QString normalized(QString(fileName).replace(QLatin1Char('.'), QLatin1Char('_')).toUpper());
+ const QString normalized(QString(fileName).replace(u'.', u'_').toUpper());
return QString::fromLatin1("#ifndef %1\n"
"#define %2\n").arg(normalized, normalized);
@@ -120,7 +76,7 @@ QString CppGenerator::startIncludeGuard(const QString &fileName)
QString CppGenerator::endIncludeGuard(const QString &fileName)
{
- const QString normalized(QString(fileName).replace(QLatin1Char('.'), QLatin1Char('_')).toUpper());
+ const QString normalized(QString(fileName).replace(u'.', u'_').toUpper());
return QString::fromLatin1("#endif // %1\n").arg(normalized);
}
@@ -240,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
@@ -262,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);
+ }
+ }
}
}
@@ -374,12 +346,17 @@ void CppGenerator::operator () ()
}
// default behaviour
- QString declFileName = grammar.table_name.toLower () + QLatin1String("_p.h");
- QString bitsFileName = grammar.table_name.toLower () + QLatin1String(".cpp");
+ QString declFileName = grammar.table_name.toLower () + "_p.h"_L1;
+ QString bitsFileName = grammar.table_name.toLower () + ".cpp"_L1;
{ // 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 ('_'));
@@ -411,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
@@ -432,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();
}
@@ -440,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();
}
@@ -448,9 +440,9 @@ void CppGenerator::operator () ()
QString CppGenerator::debugInfoProt() const
{
- QString prot = QLatin1String("QLALR_NO_");
+ QString prot = "QLALR_NO_"_L1;
prot += grammar.table_name.toUpper();
- prot += QLatin1String("_DEBUG_INFO");
+ prot += "_DEBUG_INFO"_L1;
return prot;
}
@@ -461,16 +453,16 @@ 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);
- if (name == QLatin1String ("$end"))
- name = QLatin1String ("EOF_SYMBOL");
+ if (name == "$end"_L1)
+ name = "EOF_SYMBOL"_L1;
- else if (name == QLatin1String ("$accept"))
- name = QLatin1String ("ACCEPT_SYMBOL");
+ else if (name == "$accept"_L1)
+ name = "ACCEPT_SYMBOL"_L1;
else
name.prepend (grammar.token_prefix);