qlalr: eradicate all Q_FOREACH loops
... by replacing them with C++11 range-for, or, for loops over .values(), with explicit iterator loops over the result of equal_range(). Some fixes here and there to get to mark containers const for iteration, without having to resort to qAsConst(). Didn't work everywhere. Change-Id: Ibc0e71d3b208d118f06e16741af47261ef4b9e15 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
cf9d112d7a
commit
956021dbfc
@ -166,7 +166,7 @@ void Compress::operator () (int *table, int row_count, int column_count)
|
|||||||
#ifndef QLALR_NO_CHECK_SORTED_TABLE
|
#ifndef QLALR_NO_CHECK_SORTED_TABLE
|
||||||
int previous_zeros = INT_MAX;
|
int previous_zeros = INT_MAX;
|
||||||
|
|
||||||
foreach (UncompressedRow row, sortedTable)
|
for (const UncompressedRow &row : qAsConst(sortedTable))
|
||||||
{
|
{
|
||||||
int zeros = row.count (0);
|
int zeros = row.count (0);
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ void Compress::operator () (int *table, int row_count, int column_count)
|
|||||||
|
|
||||||
index.fill (-999999, row_count);
|
index.fill (-999999, row_count);
|
||||||
|
|
||||||
foreach (const UncompressedRow &row, sortedTable)
|
for (const UncompressedRow &row : qAsConst(sortedTable))
|
||||||
{
|
{
|
||||||
int first_token = std::distance (row.begin (), row.beginNonZeros ());
|
int first_token = std::distance (row.begin (), row.beginNonZeros ());
|
||||||
QVector<int>::iterator pos = info.begin ();
|
QVector<int>::iterator pos = info.begin ();
|
||||||
@ -252,7 +252,7 @@ void Compress::operator () (int *table, int row_count, int column_count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
foreach (UncompressedRow row, sortedTable)
|
for (const UncompressedRow &row : qAsConst(sortedTable))
|
||||||
{
|
{
|
||||||
int i = row.index ();
|
int i = row.index ();
|
||||||
Q_ASSERT (i < sortedTable.size ());
|
Q_ASSERT (i < sortedTable.size ());
|
||||||
|
@ -159,12 +159,12 @@ void CppGenerator::operator () ()
|
|||||||
|
|
||||||
int r = aut.id (item->rule);
|
int r = aut.id (item->rule);
|
||||||
|
|
||||||
NameSet lookaheads = aut.lookaheads.value (item);
|
const NameSet lookaheads = aut.lookaheads.value (item);
|
||||||
|
|
||||||
if (item->rule == grammar.goal)
|
if (item->rule == grammar.goal)
|
||||||
accept_state = q;
|
accept_state = q;
|
||||||
|
|
||||||
foreach (const Name &s, lookaheads)
|
for (const Name &s : lookaheads)
|
||||||
{
|
{
|
||||||
int &u = ACTION (q, aut.id (s));
|
int &u = ACTION (q, aut.id (s));
|
||||||
|
|
||||||
@ -448,7 +448,7 @@ void CppGenerator::generateDecl (QTextStream &out)
|
|||||||
<< "public:" << endl
|
<< "public:" << endl
|
||||||
<< " enum VariousConstants {" << endl;
|
<< " enum VariousConstants {" << endl;
|
||||||
|
|
||||||
foreach (Name t, grammar.terminals)
|
for (Name t : qAsConst(grammar.terminals))
|
||||||
{
|
{
|
||||||
QString name = *t;
|
QString name = *t;
|
||||||
int value = std::distance (grammar.names.begin (), t);
|
int value = std::distance (grammar.names.begin (), t);
|
||||||
@ -606,7 +606,7 @@ void CppGenerator::generateImpl (QTextStream &out)
|
|||||||
out << endl << "#ifndef " << prot << endl;
|
out << endl << "#ifndef " << prot << endl;
|
||||||
out << "const int " << grammar.table_name << "::rule_info [] = {";
|
out << "const int " << grammar.table_name << "::rule_info [] = {";
|
||||||
idx = 0;
|
idx = 0;
|
||||||
for (RulePointer rule = grammar.rules.begin (); rule != grammar.rules.end (); ++rule, ++idx)
|
for (auto rule = grammar.rules.cbegin (); rule != grammar.rules.cend (); ++rule, ++idx)
|
||||||
{
|
{
|
||||||
out << endl << " ";
|
out << endl << " ";
|
||||||
|
|
||||||
@ -617,7 +617,7 @@ void CppGenerator::generateImpl (QTextStream &out)
|
|||||||
|
|
||||||
out << name_ids.value(rule->lhs);
|
out << name_ids.value(rule->lhs);
|
||||||
|
|
||||||
foreach (const Name &n, rule->rhs)
|
for (const Name &n : rule->rhs)
|
||||||
out << ", " << name_ids.value (n);
|
out << ", " << name_ids.value (n);
|
||||||
}
|
}
|
||||||
out << "};" << endl << endl;
|
out << "};" << endl << endl;
|
||||||
|
@ -410,8 +410,10 @@ void Automaton::buildLookbackSets ()
|
|||||||
if (! _M_grammar->isNonTerminal (A))
|
if (! _M_grammar->isNonTerminal (A))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (const RulePointer &rule, _M_grammar->rule_map.values (A))
|
const auto range = qAsConst(_M_grammar->rule_map).equal_range(A);
|
||||||
|
for (auto it = range.first; it != range.second; ++it)
|
||||||
{
|
{
|
||||||
|
const RulePointer &rule = *it;
|
||||||
StatePointer q = p;
|
StatePointer q = p;
|
||||||
|
|
||||||
for (NameList::iterator dot = rule->rhs.begin (); dot != rule->rhs.end (); ++dot)
|
for (NameList::iterator dot = rule->rhs.begin (); dot != rule->rhs.end (); ++dot)
|
||||||
@ -603,8 +605,10 @@ void Automaton::buildIncludesDigraph ()
|
|||||||
if (! _M_grammar->isNonTerminal (name))
|
if (! _M_grammar->isNonTerminal (name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (const RulePointer &rule, _M_grammar->rule_map.values (name))
|
const auto range = qAsConst(_M_grammar->rule_map).equal_range(name);
|
||||||
|
for (auto it = range.first; it != range.second; ++it)
|
||||||
{
|
{
|
||||||
|
const RulePointer &rule = *it;
|
||||||
StatePointer p = pp;
|
StatePointer p = pp;
|
||||||
|
|
||||||
for (NameList::iterator A = rule->rhs.begin (); A != rule->rhs.end (); ++A)
|
for (NameList::iterator A = rule->rhs.begin (); A != rule->rhs.end (); ++A)
|
||||||
|
@ -67,10 +67,8 @@ int main (int argc, char *argv[])
|
|||||||
bool qt_copyright = false;
|
bool qt_copyright = false;
|
||||||
QString file_name = 0;
|
QString file_name = 0;
|
||||||
|
|
||||||
QStringList args = app.arguments ();
|
const QStringList args = app.arguments().mid(1);
|
||||||
args.removeFirst ();
|
for (const QString &arg : args) {
|
||||||
|
|
||||||
foreach (const QString &arg, args) {
|
|
||||||
if (arg == QLatin1String ("-h") || arg == QLatin1String ("--help"))
|
if (arg == QLatin1String ("-h") || arg == QLatin1String ("--help"))
|
||||||
help_me ();
|
help_me ();
|
||||||
|
|
||||||
|
@ -86,7 +86,8 @@ void ParseTable::operator () (Automaton *aut)
|
|||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
foreach (const Name &la, aut->lookaheads.value (item))
|
const auto lookaheads = aut->lookaheads.value(item);
|
||||||
|
for (const Name &la : lookaheads)
|
||||||
out << " " << *la << " reduce using rule " << aut->id (item->rule) << " (" << *item->rule->lhs << ")" << endl;
|
out << " " << *la << " reduce using rule " << aut->id (item->rule) << " (" << *item->rule->lhs << ")" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user