Thursday, February 26, 2015

Table Class Hierarchy – Refactoring

The class hierarchies for operand class and the PRINT and INPUT commands were implemented some what differently.  For the operand classes, the integer and string data type entry classes were based on the double data type entry class, where as with PRINT and INPUT, intermediate classes were implemented with the three data type classes based on them.  For their debug names, the operand instances specified theirs, where as the PRINT and INPUT theirs in the constructors.  There was still also an undesirable amount of duplication.

The main and data type parts of the debug names for the operand, PRINT and INPUT entries were separated (more details below).  To reduce some of the duplication in the operand table entry classes, two small structures were added to hold non-common entry data:
Base Information - contains the code, name and table flags for the entry
Type Information - contains the second name (used for the debug data type name) and a pointer to an expression information instance
There is a Base Information structure constant for each main category of operand (constant, variable and variable reference) and there is a Type Information structure constant for each data type (double, integer and string).  The appropriate constants are passed from the operand entry constructor to the Operand class constructor where the values of these structures along with the No Name table flag (see below) and precedence value are passed to the base table constructor.  The names of these structures will probably be renamed as similar structures will be used for the operator and function entries.  The updated class simplified hierarchy is shown in this diagram (compared to initial diagram here):
Table
  └── Operand
          ├── Rem [remCommand, remOperator]
          ├── ConstDbl [constDbl]
          ├── CosntInt [constInt]
          ── CosntStr [constStr]
          ── VarDbl [varDbl]
          ├── VarInt [varInt]
          ├── VarStr [varStr]
          ── VarRefDbl [varRefDbl]
          ├── VarRefInt [varRefInt]
          └── VarRefStr [varRefStr]
A mentioned above, the debug names of these codes were separated into the first and second names.  The data type debug names were changed from Int and Str to % and $ to be consistent with those of the operators and functions (the debug name for Dbl is no character).  For example, VarInt is now Var%.  A similar change was made to Print Item, Input Assign, and Input Parse (for example, PrintDbl and PrintStr are now PrintItem and  PrintItem$).  The expected test results were updated accordingly.

The Hidden table flag was renamed to the No Name flag.  While the Hidden was used in the Convert Integer and Convert Double entries, this flag was not checked anywhere.  The No Name flag is used during entry initialization to prevent entries with this flag from being added to the Name To Entry lookup map since they now contain the main debug name for the entries with operands.  Since the name field is no longer blank for these entries, the parser was changed from checking for a blank name to using the is code with operand access function.   

[branch table commit 1598427319]

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