Sunday, August 17, 2014

Size of Data Types Enumerator

The size of enumerator was removed but it was used for the dimension of two arrays.  Both of these arrays were two dimensional, so some sort of compound map would have been needed.  Instead, simple switch statements and conditional operators were used.  This should be nearly as efficient as an array as the compiler may generate a lookup table for a switch and this is not in highly critical code so absolute efficiency is not required.

The first array was used to obtain a conversion code needed to convert the data type in a token to the desired data type.  The conversion code obtained could be a null code representing no conversion needed or an invalid code representing a data type that can't be converted.

This array was used by the convert code and find code functions in the Table class.  The convert code function was modified to process the two data types directly using compound switch statements (the first on the token data type, and the second on the needed data type).  The find code function used the array for a data type in a token with the needed data type and so was changed to simply call the convert code function instead.

The second used of the size of enumerator was to dimension the an array used in the expected error status function of the Translator class.  This array was dimensioned for the number of data types and the number of reference types (none, variable, variable or defined function, or all) and used to obtain a token error status when a reference is expected but not found.  This function was changed to use a compound switch statement (the first on the data type, and the second on the reference type or the tertiary operator was used where a second switch was overkill).  The size of enumerator for the reference enumerator was only used for this array and was also removed.

[branch cpp11 commit 4183a87f74]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)