Sunday, January 4, 2015

Token – Type Member

The token constructors each contain calls to the table static instance function so that the set token or set token code function can be called.  These two table functions set the code, type and data type of the token.  Now that tokens always contain a code (and later a table entry pointer), the type and data type members will be the same as the table entry (with one exception for data type).  So it is not necessary for the token to contain these members.

The type member was removed from the token class (the data type member will have to wait until that one exception is eliminated).  The type and is type access functions were modified to read from the table using a new table access function (which for now uses the code to get the table entry pointer).  The set type access function was removed as it was only used when the token was created.  A type access function was added to the table entry class.

These changes required some refactoring of header files.  The token header file include statement in the table file needed to be removed since the token header file needs to access the table entry.  The table header file include statement was removed from the token header file.  This required the Type enumeration to be moved from the token class to the table header file.  This enumeration was not renamed since it will soon be replaced with the new code type enumeration.

[branch table commit 68593c2dde]

Parser – Table Instance Member

From the last change, most uses of the table instance reference member of the parser class was removed; replaced with use of static table functions.  The last two uses were for setting of the code (plus type and data type) for constant tokens.  For constant string tokens, the setting of the token code was moved to the token constructor for string constants.

The other use of the table instance was for number constants also in the main function operator function of the parser, but with some statements to determine from the desired data type what the data type of the number constant should be and whether to set the Integer Constant sub-code.  These statements and the setting of the code of the token were moved to the token constructors for integer and double constants.

For integer constant tokens, the data type is set to integer unless the desired data type is double.  There is no need to for the Integer Constant sub-code since the constant is an integer.  For double constant tokens, if the value is within the integer range, the Integer Constant is only set if the desired data type is not an integer or double.  If the desired data type is indeterminate (Number or Any) then the data type of the token is set to Double.  For values outside the integer range, the data type is set to Double.

The table instance reference member was removed since it was no longer being used.  The remaining parser constructor was only initializing the input string stream member, so it was moved to and made in-line in the header file.

[branch table commit b89a1b663b]

Parser – Table Entry Pointers

Before the code enumeration (and token type enumeration) can be replaced with the new code type enumeration, uses of the code enumeration type need to be replaced with the use of table entry pointers.  This will be done on different parts at a time adding table entry class access functions as needed.

This process was started by changing the table find functions from returning a code enumerator to a table entry pointer (returning a null pointer to indicate no table entry was found).  Only the parser routines were using the find functions, so the get identifier and get operator functions were updated to use table entry pointers instead of a code enumerator.

A few table entry access functions were added to support the parser changes including the code, is code, name, has flag and alternate functions.  For now the code function simply returns an index value of the entry by subtracting the base of the table entries array.  This function is temporary.  The is code function checks if the table entry is for a particular code.  For now it compares to the code function return value, but eventually will compare to the code member that  will be added to the table entry.  The alternate function is similar to the alternate code function but returns a table entry pointer.

The code argument of the two token constructors for codes were changed to table entry pointers.  For now they just access the code function of the table entry.  The immediate goal is to change the interfaces and later to change the underlying code when the token code member is replaced with a table entry pointer.  The token constructor taking a code was temporarily left (though the unneeded arguments were removed) for use by the translator routines.

The table entry class was made a friend class of the table class (specifically so the alternate member function can access the static alternate member of the table class).  Eventually, the table entry and table classes will be combined into a single class.

[branch table commit 78f0b39780]