I misinterpreted how the compiler generates code for switch statements (caused by looking at disassembled output instead of assembler output of the compiler). The compiler does not generate an if-elseif chain in circumstances where it doesn't simplify a switch statement to an array of return values (when the return values are simple types as previously described).
The compiler still generates an array for a switch statement, but instead of an array of return values (of simple types), it generates an array of pointers. Each pointer is the address to the code for the case. During run-time, the processor indexes on the expression of the switch into this array and jumps to the address. While this is not space efficient, it is run-time efficient.
Unfortunately, for the token status enumeration, a single C style string constants cannot be used because each must be the result of the tr() translation function. This was not necessary for the other enumeration to string functions because these are only used for testing (translation is not necessary).
The switch statement for converting a token status enumerator was put into the message function of the Token class. This function previously returned an element from the static message array (which was removed). The status enumeration was put into the Token class as an enumeration class therefore requiring the Token::Status:: scoping prefix on the status enumerators. The _TokenStatus suffix was removed from each (the bug statuses did not have this prefix, but now require the scoping prefix).
The generation of the token status enumeration was removed from the auto-generation awk script and the token source file was removed as a dependency to the auto-generated enumerations header file. Several of the token status enumerators were not being used and were removed. The only auto-generated code remaining is for the code enumeration and the code enumerator to code name array. These will be handled later when the Table class is redesigned.
[branch cpp11 commit cfed68f09b]
Thursday, August 21, 2014
Subscribe to:
Post Comments (Atom)
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.)