# HG changeset patch # User Mario de Sousa # Date 1310216753 -3600 # Node ID 3037bb7e8a821cef52142083b7ba17ae4ed987b6 # Parent 63b52a8a12f38988d773ec91649983b1bf2d330a Adding some comments, and removing a check for a semantic error in code being compiled. 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; diff -r 63b52a8a12f3 -r 3037bb7e8a82 absyntax_utils/absyntax_utils.hh --- a/absyntax_utils/absyntax_utils.hh Wed Jul 06 12:19:30 2011 +0200 +++ b/absyntax_utils/absyntax_utils.hh Sat Jul 09 14:05:53 2011 +0100 @@ -70,15 +70,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. */ extern symbol_c null_symbol4; extern 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. + * + * - 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). */ -extern symtable_c enumerated_value_symtable; +extern symbol_c null_symbol5; +extern symtable_c enumerated_value_symtable; /***********************************************************************/