Ideally these access functions would be inline for efficiency. The reason these changes were not made was that in order to be inline, the table class needs to be defined before the table entry class, but the table entry class needs to be defined before the table class. Using forward declarations may have solved this issue. This would not be necessary if the two classes were merged and since they were going to be merged, no effort was used to solve this issue.
With the two classes merged, these access functions could be implemented. The necessary access functions for the expected data type, alternate, name to entry, and code to entry maps were added and callers were updated accordingly. The table class scope was eliminated from the erector class functions. The erector add to code map and two add to expected data type functions were moved back to the table class since both were passed entry pointers.
Several of the existing access functions were renamed for improved readability. One of the access functions, the alternate count function, was only called from one location in the translator and was used to determine if the unary operator in the token has an alternate binary operator. This section of code looked like this (note the comments and magic numbers):
// check if code has a binary operatorThis function was renamed to the has binary operator function. Several constant expressions (integers) were added for predefined operand indexes for use with the various alternate access functions so magic numbers are not used. With the renamed access function and constant expressions, the resulting code is much more readable (note the absence of comments):
if (m_token->alternateCount(1) > 0) {
m_token->setFirstAlternate(1); // change to binary operator
}
if (m_token->hasBinaryOperator()) {[branch table commit 03140858b0]
m_token->setToFirstAlternate(BinaryOperator);
}
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.)