Skip to content

Commit

Permalink
dictionary: replaced debug text function with put stream operator
Browse files Browse the repository at this point in the history
removed the dictionary class debug text function and replaced it with a
nearly identical function in the tester class source file that overloads
the put stream operator ("<<") for a dictionary pointer except that is
outputs directly to the output stream argument (instead of appending to
a local string), and returns the output stream reference (instead of the
string in the string stream); however, the new function no longer
outputs the header string (the caller does this now)

removed the program model dictionaries debug test function and put this
functionality in the test class run function where the function was
called from (and outputs the header for each dictionary)
  • Loading branch information
thunder422 committed Oct 9, 2014
1 parent 1f2483e commit 1cbe8e4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 58 deletions.
38 changes: 0 additions & 38 deletions dictionary.cpp
Expand Up @@ -95,44 +95,6 @@ int Dictionary::remove(uint16_t index)
}


QString Dictionary::debugText(const QString header)
{
QString string {QString("\n%1:\n").arg(header)};
for (size_t i {}; i < m_iterator.size(); i++)
{
if (m_iterator[i] != m_keyMap.end())
{
auto iterator = m_iterator[i];
string.append(QString("%1: %2 |%3|\n").arg(i)
.arg(iterator->second.m_useCount)
.arg(QString::fromStdString(iterator->first)));
}
}
string.append("Free:");
if (m_freeStack.empty())
{
string.append(" none");
}
else
{
std::stack<uint16_t> tempStack = m_freeStack;
while (!tempStack.empty())
{
int index {tempStack.top()};
tempStack.pop();
string.append(QString(" %1").arg(index));
if (m_iterator[index] != m_keyMap.end())
{
string.append(QString("|%1|")
.arg(QString::fromStdString(m_iterator[index]->first)));
}
}
}
string.append("\n");
return string;
}


////////////////////////////////////////////////////////////////////////////////
// //
// INFORMATION DICTIONARY FUNCTIONS //
Expand Down
7 changes: 4 additions & 3 deletions dictionary.h
Expand Up @@ -25,13 +25,12 @@
#ifndef DICTIONARY_H
#define DICTIONARY_H

#include <algorithm>
#include <memory>
#include <stack>
#include <unordered_map>
#include <vector>

#include <QString>

class Token;
using TokenPtr = std::shared_ptr<Token>;

Expand All @@ -58,7 +57,9 @@ class Dictionary
{
return m_iterator[index]->first;
}
QString debugText(const QString header);

friend std::ostream &operator<<(std::ostream &os,
const Dictionary *const dictionary);

private:
struct EntryValue
Expand Down
15 changes: 0 additions & 15 deletions programmodel.cpp
Expand Up @@ -148,21 +148,6 @@ QString ProgramModel::debugText(int lineIndex, bool fullInfo) const
}


// NOTE temporary function to return debug text of all the dictionary
QString ProgramModel::dictionariesDebugText(void)
{
QString string;

string.append(m_remDictionary->debugText("Remarks"));
string.append(m_constNumDictionary->debugText("Number Constants"));
string.append(m_constStrDictionary->debugText("String Constants"));
string.append(m_varDblDictionary->debugText("Double Variables"));
string.append(m_varIntDictionary->debugText("Integer Variables"));
string.append(m_varStrDictionary->debugText("String Variables"));
return string;
}


// function to return text for a given program line
QString ProgramModel::lineText(int lineIndex)
{
Expand Down
1 change: 0 additions & 1 deletion programmodel.h
Expand Up @@ -226,7 +226,6 @@ class ProgramModel : public QAbstractListModel
}
}
QString debugText(int lineIndex, bool fullInfo = false) const;
QString dictionariesDebugText(void);

// program model access functions
QString lineText(int lineIndex);
Expand Down
46 changes: 45 additions & 1 deletion test_ibcp.cpp
Expand Up @@ -203,6 +203,42 @@ std::ostream &operator<<(std::ostream &os, const RpnList &rpnList)
}


// overloaded output stream operator for abbreviated contents of rpn list
std::ostream &operator<<(std::ostream &os, const Dictionary *const dictionary)
{
for (size_t i {}; i < dictionary->m_iterator.size(); i++)
{
if (dictionary->m_iterator[i] != dictionary->m_keyMap.end())
{
auto iterator = dictionary->m_iterator[i];
os << i << ": " << iterator->second.m_useCount << " |"
<< iterator->first << "|\n";
}
}
os << "Free:";
if (dictionary->m_freeStack.empty())
{
os << " none";
}
else
{
std::stack<uint16_t> tempStack = dictionary->m_freeStack;
while (!tempStack.empty())
{
int index {tempStack.top()};
tempStack.pop();
os << ' ' << index;
if (dictionary->m_iterator[index] != dictionary->m_keyMap.end())
{
os << '|' << dictionary->m_iterator[index]->first << '|';
}
}
}
os << '\n';
return os;
}


// function to process a test input file specified on the command line
// or accept input lines from the user
Tester::Tester(const QStringList &args, std::ostream &cout) :
Expand Down Expand Up @@ -426,7 +462,15 @@ bool Tester::run(CommandLine *commandLine)
m_cout << i << ": "
<< m_programUnit->debugText(i, true).toStdString() << '\n';
}
m_cout << m_programUnit->dictionariesDebugText().toStdString();

m_cout << "\nRemarks:\n" << m_programUnit->remDictionary();
m_cout << "\nNumber Constants:\n"
<< m_programUnit->constNumDictionary();
m_cout << "\nString Constants:\n"
<< m_programUnit->constStrDictionary();
m_cout << "\nDouble Variables:\n" << m_programUnit->varDblDictionary();
m_cout << "\nInteger Variables:\n" << m_programUnit->varIntDictionary();
m_cout << "\nString Variables:\n" << m_programUnit->varStrDictionary();

if (m_recreate)
{
Expand Down

0 comments on commit 1cbe8e4

Please sign in to comment.