summaryrefslogtreecommitdiffstats
path: root/src/tools/qlalr/cppgenerator.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-05-02 19:56:29 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-07-02 22:27:11 +0200
commitdce7dbecb0135501eb8641c8f5ec8e98bddc808c (patch)
treeef3da870c951e5c838dde1ceb680d7d53b56c3ed /src/tools/qlalr/cppgenerator.cpp
parent13997cccc9dd9a1242b7707b5e934deae84d253a (diff)
qlalr: replace QLinkedList with std::list
This is in preparation of deprecating QLinkedList. Most is straight-forward, except where operator+ was used on linked-list iterators. In one case, replaced this with std::next, in the other, with prefix increments, since the advancement was always equal to the loop control variable. Since advancing a linked-list iterator is a linear operation, this removes a source of quadratic complexity. Another obstacle was the overloaded op< set, which was in the Qt namespace while the iterator is from std and the payload, as before, was global. This breaks ADL, so move these operators to namespace std. This violates the standard, but the functions are tagged with our distinct types, so it shouldn't cause any trouble. Change-Id: Ifec0a927bfdabb002838cdf86fb8d23b32a38ff7 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/tools/qlalr/cppgenerator.cpp')
-rw-r--r--src/tools/qlalr/cppgenerator.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/tools/qlalr/cppgenerator.cpp b/src/tools/qlalr/cppgenerator.cpp
index ee17be041e..95f70dc988 100644
--- a/src/tools/qlalr/cppgenerator.cpp
+++ b/src/tools/qlalr/cppgenerator.cpp
@@ -36,6 +36,8 @@
#include <QtCore/qfile.h>
#include <QtCore/qmap.h>
+#include <iterator>
+
namespace {
void generateSeparator(int i, QTextStream &out)
@@ -126,7 +128,7 @@ QString CppGenerator::endIncludeGuard(const QString &fileName)
void CppGenerator::operator () ()
{
// action table...
- state_count = aut.states.size ();
+ state_count = static_cast<int>(aut.states.size());
terminal_count = static_cast<int>(grammar.terminals.size());
non_terminal_count = static_cast<int>(grammar.non_terminals.size());
@@ -156,7 +158,7 @@ void CppGenerator::operator () ()
if (grammar.isNonTerminal (a.key ()))
{
- Q_ASSERT (symbol >= terminal_count && symbol < grammar.names.size ());
+ Q_ASSERT(symbol >= terminal_count && symbol < static_cast<int>(grammar.names.size()));
GOTO (q, symbol - terminal_count) = r;
}
@@ -245,7 +247,7 @@ void CppGenerator::operator () ()
<< Qt::endl;
}
- QBitArray used_rules (grammar.rules.count ());
+ QBitArray used_rules{static_cast<int>(grammar.rules.size())};
int q = 0;
for (StatePointer state = aut.states.begin (); state != aut.states.end (); ++state, ++q)
@@ -259,12 +261,11 @@ void CppGenerator::operator () ()
}
}
- for (int i = 0; i < used_rules.count (); ++i)
+ auto rule = grammar.rules.begin();
+ for (int i = 0; i < used_rules.count (); ++i, ++rule)
{
if (! used_rules.testBit (i))
{
- RulePointer rule = grammar.rules.begin () + i;
-
if (rule != grammar.goal)
qerr() << "*** Warning: Rule ``" << *rule << "'' is useless!" << Qt::endl;
}
@@ -280,7 +281,7 @@ void CppGenerator::operator () ()
if (u >= 0)
continue;
- RulePointer rule = grammar.rules.begin () + (- u - 1);
+ RulePointer rule = std::next(grammar.rules.begin(), - u - 1);
if (state->defaultReduce == rule)
u = 0;
@@ -619,7 +620,7 @@ void CppGenerator::generateImpl (QTextStream &out)
out << "const int " << grammar.table_name << "::rule_index [] = {";
idx = 0;
- int offset = 0;
+ size_t offset = 0;
for (RulePointer rule = grammar.rules.begin (); rule != grammar.rules.end (); ++rule, ++idx)
{
generateSeparator(idx, out);