Sunday, October 28, 2012

Qt Transition – Error Lists

The remaining item that uses the List class are the error lists generated by the Table class constructor (for errors detected in the table entries).  This constructor added errors to an error list, and at the end of the constructor, if there were any errors, the constructor threw an exception containing the pointer to the errors list.  The token initialization routine also previously threw an exception for any token status errors detected, but this code was removed when the enum.awk script was implemented to generate the token status enumeration and it detects any errors.

Because there were two types of errors and both were handling errors the same way, an Error template was implemented that could be used for both code (table) and token status errors.  This template also handled outputting the errors using a print function that was passed to it.  This design was also rather complicated.  I mentioned previously that Qt did not support exceptions, but this was not correct.  Qt can be used with exceptions, but none of the Qt classes and functions throw exceptions themselves.

Since the exception and error template design was complicated, it was removed.  For the table initialization to be able to return errors, the code was moved from the constructor to a new initialization function.  As for the error list to return, the QStringList class was used.  This class is a specialized list class, equivalent to QList<QString>.

Hit Continue... for details of the new table initialization implementation.  All lists have now been replaced with Qt equivalents.  The list.h header file was removed (along with the program that tested lists).  The next replacement will be the various stacks.

[commit a27e456222]

Qt Transition – Token Lists

There were two lists used to keep a list of allocated tokens and a list of tokens that were deleted multiple times.  These lists were used to detect token memory leaks (tokens not released).  To support this detection, the new and delete operators of the Token structure were overloaded.  In addition to allocating the memory (using regular new), the token was also added to the allocated list.  When deleted, the token was removed from the allocated list.  After processing a line, any tokens still in the allocated list was considered a leak.  Similarly the deleted token list kept track of any tokens that were deleted more than once.

Apparently, the Qt classes (including QList, QLinkedList and QVector) do not interface with overloaded new and delete functions (obscure compiler errors result).  Since another method is now being used to detect memory leaks (valgrind), this detection code is not essential.  The advantage of this code was that it would output the exact tokens that were not released or were deleted twice.  This was nice when the Translator was first implemented and debugged, but now that Translator code is fully working, this level of detail is probably (and hopefully) not necessary.  Therefore, these token lists were removed along with the overloaded new and delete operators.

[commit  d21d3d38ad]