stage3/narrow_candidate_datatypes.cc
changeset 889 5f380b99e95e
parent 873 dea39ef02847
child 895 f824bf8e1579
--- a/stage3/narrow_candidate_datatypes.cc	Fri Apr 04 16:21:55 2014 +0100
+++ b/stage3/narrow_candidate_datatypes.cc	Tue Apr 08 14:35:31 2014 +0100
@@ -70,6 +70,7 @@
 	fake_prev_il_instruction = NULL;
 	current_il_instruction   = NULL;
 	il_operand = NULL;
+	current_scope = NULL;
 }
 
 narrow_candidate_datatypes_c::~narrow_candidate_datatypes_c(void) {
@@ -651,6 +652,7 @@
 /*********************/
 // SYM_REF1(symbolic_variable_c, var_name)
 void *narrow_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
+	symbol->scope = current_scope;  // the scope in which this variable was declared!
 	symbol->var_name->datatype = symbol->datatype;
 	return NULL;
 }
@@ -674,6 +676,8 @@
 	if (symbol->subscripted_variable->candidate_datatypes.size() == 1)
 	  symbol->subscripted_variable->datatype = symbol->subscripted_variable->candidate_datatypes[0]; // set the datatype
 
+	// the scope in which this variable was declared! It will be the same as the subscripted variable (a symbolic_variable_ !)
+	symbol->scope = symbol->subscripted_variable->scope;	
 	return NULL;
 }
 
@@ -708,6 +712,7 @@
 	if (symbol->record_variable->candidate_datatypes.size() == 1)
 	  symbol->record_variable->datatype = symbol->record_variable->candidate_datatypes[0]; // set the datatype
 
+	symbol->scope = symbol->record_variable->datatype;	// the scope in which this variable was declared!
 	return NULL;
 }
 
@@ -764,12 +769,14 @@
 	symbol->type_name->datatype = search_base_type_c::get_basetype_decl(symbol->type_name);
 	symbol->datatype = symbol->type_name->datatype;
 	
+	current_scope = symbol;	
 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
 	symbol->var_declarations_list->accept(*this);
 	if (debug) printf("Narrowing candidate data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
 	symbol->function_body->accept(*this);
 	delete search_varfb_instance_type;
 	search_varfb_instance_type = NULL;
+	current_scope = NULL;	
 	return NULL;
 }
 
@@ -777,13 +784,15 @@
 /* B 1.5.2 Function blocks */
 /***************************/
 void *narrow_candidate_datatypes_c::visit(function_block_declaration_c *symbol) {
+	current_scope = symbol;	
 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
 	symbol->var_declarations->accept(*this);
 	if (debug) printf("Narrowing candidate data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
 	symbol->fblock_body->accept(*this);
 	delete search_varfb_instance_type;
 	search_varfb_instance_type = NULL;
-	
+	current_scope = NULL;	
+
 	// A FB declaration can also be used as a Datatype! We now do the narrow algorithm considering it as such!
 	if (symbol->candidate_datatypes.size() == 1)
 		symbol->datatype = symbol->candidate_datatypes[0];
@@ -794,12 +803,14 @@
 /* B 1.5.3 Programs */
 /********************/
 void *narrow_candidate_datatypes_c::visit(program_declaration_c *symbol) {
+	current_scope = symbol;	
 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
 	symbol->var_declarations->accept(*this);
 	if (debug) printf("Narrowing candidate data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value);
 	symbol->function_block_body->accept(*this);
 	delete search_varfb_instance_type;
 	search_varfb_instance_type = NULL;
+	current_scope = NULL;	
 	return NULL;
 }