Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
authormjsousa
Sat, 25 Oct 2014 11:21:40 +0100
changeset 940 61e2bdae5899
parent 939 5074236fb3c4
child 941 c2ef93412407
Filling of symbol->scope annotation moved from narrow to fill_candidate_datatypes_c (became possible because narrowing of struct, array and symbolic variables is now done directly in fill_candidate_datatypes_c)
stage3/fill_candidate_datatypes.cc
stage3/fill_candidate_datatypes.hh
stage3/narrow_candidate_datatypes.cc
stage3/narrow_candidate_datatypes.hh
--- a/stage3/fill_candidate_datatypes.cc	Sat Oct 25 11:15:55 2014 +0100
+++ b/stage3/fill_candidate_datatypes.cc	Sat Oct 25 11:21:40 2014 +0100
@@ -273,6 +273,7 @@
 	prev_il_instruction = NULL;
 	search_var_instance_decl = NULL;
 	current_enumerated_spec_type = NULL;
+	current_scope = NULL;
 }
 
 fill_candidate_datatypes_c::~fill_candidate_datatypes_c(void) {
@@ -1170,6 +1171,7 @@
 /* B 1.4 - Variables */
 /*********************/
 void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
+	symbol->scope = current_scope;  // the scope in which this variable was declared!
 	/*  NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class!
 	 *        Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm
 	 *        in this fill_candidate_datatypes_c itself!
@@ -1231,7 +1233,11 @@
 	 *        END_VAR
 	 */
 	symbol->subscripted_variable->accept(*this);
-
+	// 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;
+	if (NULL == symbol->scope) ERROR;
+
+	/* get the declaration of the data type __stored__ in the array... */
 	add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(get_datatype_info_c::get_array_storedtype_id(symbol->subscripted_variable->datatype)));   /* will only add if non NULL */
 
 	/*  NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class!
@@ -1273,6 +1279,7 @@
 	 *      (e.g.  arrayvar[ varx + TRUNC(realvar)].elem1)
 	 */
 	symbol->record_variable->accept(*this);
+	symbol->scope = symbol->record_variable->datatype;	// the scope in which this variable was declared! Will be used in stage4
 	
 	/*  NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class!
 	 *        Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm
@@ -1412,6 +1419,7 @@
 void *fill_candidate_datatypes_c::visit(function_declaration_c *symbol) {
 	if (debug) printf("Filling candidate data types list of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
 	local_enumerated_value_symtable.reset();
+	current_scope = symbol;	
 	symbol->var_declarations_list->accept(populate_enumvalue_symtable);
 
 	search_var_instance_decl = new search_var_instance_decl_c(symbol);
@@ -1420,6 +1428,7 @@
 	delete search_var_instance_decl;
 	search_var_instance_decl = NULL;
 
+	current_scope = NULL;	
 	local_enumerated_value_symtable.reset();
 	return NULL;
 }
@@ -1430,6 +1439,7 @@
 void *fill_candidate_datatypes_c::visit(function_block_declaration_c *symbol) {
 	if (debug) printf("Filling candidate data types list of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
 	local_enumerated_value_symtable.reset();
+	current_scope = symbol;	
 	symbol->var_declarations->accept(populate_enumvalue_symtable);
 
 	search_var_instance_decl = new search_var_instance_decl_c(symbol);
@@ -1438,6 +1448,7 @@
 	delete search_var_instance_decl;
 	search_var_instance_decl = NULL;
 
+	current_scope = NULL;	
 	local_enumerated_value_symtable.reset();
 	
 	/* The FB declaration itself may be used as a dataype! We now do the fill algorithm considering 
@@ -1454,6 +1465,7 @@
 void *fill_candidate_datatypes_c::visit(program_declaration_c *symbol) {
 	if (debug) printf("Filling candidate data types list in program %s\n", ((token_c *)(symbol->program_type_name))->value);
 	local_enumerated_value_symtable.reset();
+	current_scope = symbol;	
 	symbol->var_declarations->accept(populate_enumvalue_symtable);
 	
 	search_var_instance_decl = new search_var_instance_decl_c(symbol);
@@ -1462,6 +1474,7 @@
 	delete search_var_instance_decl;
 	search_var_instance_decl = NULL;
 
+	current_scope = NULL;	
 	local_enumerated_value_symtable.reset();
 	return NULL;
 }
--- a/stage3/fill_candidate_datatypes.hh	Sat Oct 25 11:15:55 2014 +0100
+++ b/stage3/fill_candidate_datatypes.hh	Sat Oct 25 11:21:40 2014 +0100
@@ -78,6 +78,8 @@
      */
     symbol_c *current_enumerated_spec_type;
     
+    /* pointer to the Function, FB, or Program currently being analysed */
+    symbol_c *current_scope;
     /* Pointer to the previous IL instruction, which contains the current data type (actually, the list of candidate data types) of the data stored in the IL stack, i.e. the default variable, a.k.a. accumulator */
     symbol_c *prev_il_instruction;
     /* the current IL operand being analyzed */
--- a/stage3/narrow_candidate_datatypes.cc	Sat Oct 25 11:15:55 2014 +0100
+++ b/stage3/narrow_candidate_datatypes.cc	Sat Oct 25 11:21:40 2014 +0100
@@ -70,7 +70,6 @@
 	fake_prev_il_instruction = NULL;
 	current_il_instruction   = NULL;
 	il_operand = NULL;
-	current_scope = NULL;
 }
 
 narrow_candidate_datatypes_c::~narrow_candidate_datatypes_c(void) {
@@ -683,7 +682,6 @@
 /*********************/
 // 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;
 }
@@ -707,8 +705,6 @@
 	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;
 }
 
@@ -743,7 +739,6 @@
 	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;
 }
 
@@ -800,14 +795,12 @@
 	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;
 }
 
@@ -815,14 +808,12 @@
 /* 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)
@@ -834,14 +825,12 @@
 /* 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;
 }
 
--- a/stage3/narrow_candidate_datatypes.hh	Sat Oct 25 11:15:55 2014 +0100
+++ b/stage3/narrow_candidate_datatypes.hh	Sat Oct 25 11:21:40 2014 +0100
@@ -65,7 +65,6 @@
 
   private:
     search_varfb_instance_type_c *search_varfb_instance_type;
-    symbol_c *current_scope;
     symbol_c *il_operand;
     il_instruction_c *fake_prev_il_instruction;
     il_instruction_c   *current_il_instruction;