Sunday, January 11, 2015

Token – Conversion Handling

The table find code function was the one function taking a token pointer argument that was not modified with the rest of the table functions with a token argument since it did more than just access the code of the token.  It had two token arguments, the token being processed (operator, assignment, print item, and input assignment) and its operand token.

This function took no action if the operand data type matched the expected data type of the token.  If the operand was a constant, an attempt is made to change the constant to the expected data type if at the last operand and the token does not have the Use Constant As Is flag set.  If there is an alternate code of the token that matches that of the operand, the token is changed to that code.  Otherwise a hidden conversion code is obtained.  An error is thrown if the operand cannot be converted.

Since this function is acting on a token (or possibly two tokens), it made more sense for this function to be a member of the token class.  After moving it to the token class, it was renamed to the convert function.  With a lot going on in this function, some refactoring was performed to improve the readability and clarity of the code:
  • Added the is last operand access function to determine if an operand index is the last operand of the code in the token.
  • Renamed the convert constant function to change constant.  Also renamed its argument.
  • Added the change constant ignore error function, which calls the change constant function and catches an error that may be throw.
  • Renamed the convert code function to convert code entry.  Also renamed its argument.
  • Removed most of the comments as they were only restarting what appears in the code (this included the callers in the translator routines).
[branch table commit ce6adffc15]

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.)