Fixing check for assingment to FOR control variables.
authorMario de Sousa <msousa@fe.up.pt>
Mon, 16 Apr 2012 15:17:24 +0100
changeset 512 f915ab676d7e
parent 511 b22ae67d8003
child 513 99aa36a77703
Fixing check for assingment to FOR control variables.
stage3/lvalue_check.cc
stage3/lvalue_check.hh
--- a/stage3/lvalue_check.cc	Mon Apr 16 15:10:31 2012 +0100
+++ b/stage3/lvalue_check.cc	Mon Apr 16 15:17:24 2012 +0100
@@ -75,9 +75,9 @@
 /* No writing to iterator variables (used in FOR loops) inside the loop itself */
 void lvalue_check_c::check_assignment_to_controlvar(symbol_c *lvalue) {
 	for (unsigned int i = 0; i < control_variables.size(); i++) {
-		symbolic_variable_c *cvar = (symbolic_variable_c *)control_variables[i];
-		if (strcasecmp(((identifier_c *)((symbolic_variable_c *)lvalue)->var_name)->value, ((identifier_c *)((symbolic_variable_c *)cvar)->var_name)->value) == 0) {
-			STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FOR control variable are not be allowed.");
+		token_c *lvalue_name = get_var_name_c::get_name(lvalue);
+		if (compare_identifiers(lvalue_name, control_variables[i]) == 0) {
+			STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FOR control variable is not allowed.");
 			break;
 		}
 	}
@@ -274,7 +274,7 @@
 /* B 3.2.4 Iteration Statements */
 /********************************/
 void *lvalue_check_c::visit(for_statement_c *symbol) {
-	control_variables.push_back(symbol->control_variable);
+	control_variables.push_back(get_var_name_c::get_name(symbol->control_variable));
 	symbol->statement_list->accept(*this);
 	control_variables.pop_back();
 	return NULL;
--- a/stage3/lvalue_check.hh	Mon Apr 16 15:10:31 2012 +0100
+++ b/stage3/lvalue_check.hh	Mon Apr 16 15:17:24 2012 +0100
@@ -49,7 +49,7 @@
     search_base_type_c search_base_type;
     int error_count;
     int current_display_error_level;
-    std::vector <symbol_c *> control_variables;
+    std::vector <token_c *> control_variables;
 
     void verify_is_lvalue              (symbol_c *lvalue);
     void check_assignment_to_controlvar(symbol_c *lvalue);