Fix semantic verification of enumerated data types.
authorMario de Sousa <msousa@fe.up.pt>
Sat, 29 Oct 2011 18:56:25 +0100
changeset 386 606443ffd589
parent 385 450d684013dc
child 387 db368e53133c
Fix semantic verification of enumerated data types.
absyntax_utils/search_constant_type.cc
stage3/visit_expression_type.cc
--- a/absyntax_utils/search_constant_type.cc	Fri Oct 28 10:25:07 2011 +0100
+++ b/absyntax_utils/search_constant_type.cc	Sat Oct 29 18:56:25 2011 +0100
@@ -124,13 +124,13 @@
 /* B 1.3.3 - Derived data types */
 /********************************/
 void *search_constant_type_c::visit(enumerated_value_c *symbol) {
-	if (symbol->type != NULL)
-		return (void *)(symbol->type);
+  if (symbol->type != NULL)
+    return (void *)(symbol->type);
 
-	symbol_c *value_type = enumerated_value_symtable.find_value(symbol->value);
-	if (value_type == enumerated_value_symtable.end_value()) ERROR;
-
-	return (void *)value_type;
+  symbol_c *value_type = enumerated_value_symtable.find_value(symbol->value);
+  if (value_type == enumerated_value_symtable.end_value())
+    return NULL;
+  return (void *)value_type;
 }
 
 real_type_name_c     search_constant_type_c::real_type_name;
--- a/stage3/visit_expression_type.cc	Fri Oct 28 10:25:07 2011 +0100
+++ b/stage3/visit_expression_type.cc	Sat Oct 29 18:56:25 2011 +0100
@@ -2076,9 +2076,9 @@
   } // if (debug)
 
   if        (NULL == left_type) {
-    STAGE3_ERROR(symbol->l_exp, symbol->l_exp, "Could not determine data type of expression (undefined variable or strcuture element?).\n");
+    STAGE3_ERROR(symbol->l_exp, symbol->l_exp, "Could not determine data type of expression (undefined variable, constant, or structure element?).\n");
   } else if (NULL == right_type) {
-    STAGE3_ERROR(symbol->r_exp, symbol->r_exp, "Could not determine data type of expression (undefined variable or strcuture element?).\n");
+    STAGE3_ERROR(symbol->r_exp, symbol->r_exp, "Could not determine data type of expression (undefined variable, constant, or structure element?).\n");
   } else if (!is_valid_assignment(left_type, right_type))
     STAGE3_ERROR(symbol, symbol, "data type mismatch in assignment statement!\n");