diff -r 63b52a8a12f3 -r 3037bb7e8a82 absyntax_utils/absyntax_utils.cc --- a/absyntax_utils/absyntax_utils.cc Wed Jul 06 12:19:30 2011 +0200 +++ b/absyntax_utils/absyntax_utils.cc Sat Jul 09 14:05:53 2011 +0100 @@ -117,15 +117,26 @@ /* A symbol table with all user declared type definitions... */ /* Note that function block types and program types have their * own symbol tables, so do not get placed in this symbol table! + * + * The symbol_c * associated to the value will point to the data type declaration. */ symbol_c null_symbol4; symtable_c type_symtable; /* A symbol table with all values declared for enumerated type... */ -/* Note that if the value is defined multiple times the value +/* Notes: + * - if the value is defined multiple times the value * is the null pointer. - */ -symtable_c enumerated_value_symtable; + * + * - The stored symbol_c * associated to the value points to the enumerated_type_name + * (i.e. the name of the enumerated data type) in which the the value/identifier + * is used/declared. + * + * - We could re-use the null_symbol4 object, but it is safer to use a distinct object + * (i.e. it might make it easier to find strange bugs). + */ +symbol_c null_symbol5; +symtable_c enumerated_value_symtable; /***********************************************************************/ @@ -214,11 +225,25 @@ if (symbol->type != NULL) ERROR; symbol_c *value_type = enumerated_value_symtable.find_value(symbol->value); - if (value_type == current_enumerated_type) ERROR; + /* NOTE: The following condition checks whether the same identifier is used more than once + * when defining the enumerated values of the type declaration of the new enumerated type. + * If this occurs, then the program beeing compiled contains a semantic error, which + * must be caught and reported by the semantic analyser. However, since + * this code is run before the semantic analyser, we must not yet raise the ERROR (internal + * compiler error message). + * For this reason, the follosing check is commented out. + */ + /* if (value_type == current_enumerated_type) ERROR; */ if (value_type == enumerated_value_symtable.end_value()) + /* This identifier has not yet been used in any previous declaration of an enumeration data type. + * so we add it to the symbol table. + */ enumerated_value_symtable.insert(symbol->value, current_enumerated_type); else if (value_type != NULL) + /* This identifier has already been used in a previous declaration of an enumeration data type. + * so we set the symbol in symbol table pointing to NULL. + */ enumerated_value_symtable.set(symbol->value, NULL); } return NULL;