Adding some comments, and removing a check for a semantic error in code being compiled.
authorMario de Sousa <msousa@fe.up.pt>
Sat, 09 Jul 2011 14:05:53 +0100
changeset 338 3037bb7e8a82
parent 334 63b52a8a12f3
child 339 06b561479e46
Adding some comments, and removing a check for a semantic error in code being compiled.
absyntax_utils/absyntax_utils.cc
absyntax_utils/absyntax_utils.hh
--- 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<symbol_c *, &null_symbol4> 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<symbol_c *, &null_symbol4> 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<symbol_c *, &null_symbol5> 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;
--- 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<symbol_c *, &null_symbol4> 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<symbol_c *, &null_symbol4> enumerated_value_symtable;
+extern symbol_c null_symbol5;
+extern symtable_c<symbol_c *, &null_symbol5> enumerated_value_symtable;
 
 
 /***********************************************************************/