stage3/lvalue_check.cc
changeset 512 f915ab676d7e
parent 510 9317e04c1dde
child 513 99aa36a77703
equal deleted inserted replaced
511:b22ae67d8003 512:f915ab676d7e
    73 
    73 
    74 #include <strings.h>
    74 #include <strings.h>
    75 /* No writing to iterator variables (used in FOR loops) inside the loop itself */
    75 /* No writing to iterator variables (used in FOR loops) inside the loop itself */
    76 void lvalue_check_c::check_assignment_to_controlvar(symbol_c *lvalue) {
    76 void lvalue_check_c::check_assignment_to_controlvar(symbol_c *lvalue) {
    77 	for (unsigned int i = 0; i < control_variables.size(); i++) {
    77 	for (unsigned int i = 0; i < control_variables.size(); i++) {
    78 		symbolic_variable_c *cvar = (symbolic_variable_c *)control_variables[i];
    78 		token_c *lvalue_name = get_var_name_c::get_name(lvalue);
    79 		if (strcasecmp(((identifier_c *)((symbolic_variable_c *)lvalue)->var_name)->value, ((identifier_c *)((symbolic_variable_c *)cvar)->var_name)->value) == 0) {
    79 		if (compare_identifiers(lvalue_name, control_variables[i]) == 0) {
    80 			STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FOR control variable are not be allowed.");
    80 			STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FOR control variable is not allowed.");
    81 			break;
    81 			break;
    82 		}
    82 		}
    83 	}
    83 	}
    84 }
    84 }
    85 
    85 
   272 
   272 
   273 /********************************/
   273 /********************************/
   274 /* B 3.2.4 Iteration Statements */
   274 /* B 3.2.4 Iteration Statements */
   275 /********************************/
   275 /********************************/
   276 void *lvalue_check_c::visit(for_statement_c *symbol) {
   276 void *lvalue_check_c::visit(for_statement_c *symbol) {
   277 	control_variables.push_back(symbol->control_variable);
   277 	control_variables.push_back(get_var_name_c::get_name(symbol->control_variable));
   278 	symbol->statement_list->accept(*this);
   278 	symbol->statement_list->accept(*this);
   279 	control_variables.pop_back();
   279 	control_variables.pop_back();
   280 	return NULL;
   280 	return NULL;
   281 }
   281 }
   282 
   282