Saturday, April 20, 2013

Program Model – Error List

The next not so small increment to implement the error highlighting was the addition of an error list to the program model that will hold information about each error in the program.  A new ErrorList class was implemented based on the QList class of the new ErrorItem class, which will contain the type of error (translator or encoder), line number, column, length and error message.

The errors in the list will be kept in order by line number, which allows finding an error by line number quickly by using a binary search.  This class contains a find function with the binary search routine, which returns the index of the line number if found or the nearest error for a line number less than the line number being searched for.  The nearest error location is used insert a new error into the list.

The program model update function, which receives program updates, was expanded into several new functions.  The update function now calls the new update line function for changed, deleted and inserted lines.  The remaining purpose of the update function is to call the appropriate triggers to update the program view.

The new update line function first compiles the line (change and insert), which for now just translates the line.  For a change, if line has not changed, returns an indication that no change occurred, otherwise the line is replaced and the new set error function is called.  For an insert, new set error function is called and the line is inserted into the program.  For a delete, the new remove error function is called, the program line is deleted.

The new set error function (called for change and insert) first determines if the line has an error.  If the line does not have an error, any current error (change only) is removed by the new remove error function.  If a changed line had an error and still has an error, the old error is replaced with the new error.  If the line has a new error, the error is inserted into the error list.  The rest of the errors in the list are also adjusted - if a new error was inserted, the error index of the program line for each error is incremented; and if a new line is being inserted, the line number of each error is incremented.

The new remove error function (called for change and delete) determines in the line has an error, which is removed from the error list if it does.  The rest of the errors in the list are also adjusted - if an error was deleted, the error index of the program line for each error is decremented; and if a line is being deleted, the line number of each error is decremented.

[commit 7c94dd4630]