stage3/narrow_candidate_datatypes.cc
changeset 889 5f380b99e95e
parent 873 dea39ef02847
child 895 f824bf8e1579
equal deleted inserted replaced
888:4893e6b11b25 889:5f380b99e95e
    68 narrow_candidate_datatypes_c::narrow_candidate_datatypes_c(symbol_c *ignore) {
    68 narrow_candidate_datatypes_c::narrow_candidate_datatypes_c(symbol_c *ignore) {
    69 	search_varfb_instance_type = NULL;
    69 	search_varfb_instance_type = NULL;
    70 	fake_prev_il_instruction = NULL;
    70 	fake_prev_il_instruction = NULL;
    71 	current_il_instruction   = NULL;
    71 	current_il_instruction   = NULL;
    72 	il_operand = NULL;
    72 	il_operand = NULL;
       
    73 	current_scope = NULL;
    73 }
    74 }
    74 
    75 
    75 narrow_candidate_datatypes_c::~narrow_candidate_datatypes_c(void) {
    76 narrow_candidate_datatypes_c::~narrow_candidate_datatypes_c(void) {
    76 }
    77 }
    77 
    78 
   649 /*********************/
   650 /*********************/
   650 /* B 1.4 - Variables */
   651 /* B 1.4 - Variables */
   651 /*********************/
   652 /*********************/
   652 // SYM_REF1(symbolic_variable_c, var_name)
   653 // SYM_REF1(symbolic_variable_c, var_name)
   653 void *narrow_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
   654 void *narrow_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
       
   655 	symbol->scope = current_scope;  // the scope in which this variable was declared!
   654 	symbol->var_name->datatype = symbol->datatype;
   656 	symbol->var_name->datatype = symbol->datatype;
   655 	return NULL;
   657 	return NULL;
   656 }
   658 }
   657 /********************************************/
   659 /********************************************/
   658 /* B 1.4.1 - Directly Represented Variables */
   660 /* B 1.4.1 - Directly Represented Variables */
   672 	symbol->subscripted_variable->accept(*this); // visit recursively
   674 	symbol->subscripted_variable->accept(*this); // visit recursively
   673 
   675 
   674 	if (symbol->subscripted_variable->candidate_datatypes.size() == 1)
   676 	if (symbol->subscripted_variable->candidate_datatypes.size() == 1)
   675 	  symbol->subscripted_variable->datatype = symbol->subscripted_variable->candidate_datatypes[0]; // set the datatype
   677 	  symbol->subscripted_variable->datatype = symbol->subscripted_variable->candidate_datatypes[0]; // set the datatype
   676 
   678 
       
   679 	// the scope in which this variable was declared! It will be the same as the subscripted variable (a symbolic_variable_ !)
       
   680 	symbol->scope = symbol->subscripted_variable->scope;	
   677 	return NULL;
   681 	return NULL;
   678 }
   682 }
   679 
   683 
   680 
   684 
   681 /* subscript_list ',' subscript */
   685 /* subscript_list ',' subscript */
   706 	symbol->record_variable->accept(*this); // visit recursively
   710 	symbol->record_variable->accept(*this); // visit recursively
   707 
   711 
   708 	if (symbol->record_variable->candidate_datatypes.size() == 1)
   712 	if (symbol->record_variable->candidate_datatypes.size() == 1)
   709 	  symbol->record_variable->datatype = symbol->record_variable->candidate_datatypes[0]; // set the datatype
   713 	  symbol->record_variable->datatype = symbol->record_variable->candidate_datatypes[0]; // set the datatype
   710 
   714 
       
   715 	symbol->scope = symbol->record_variable->datatype;	// the scope in which this variable was declared!
   711 	return NULL;
   716 	return NULL;
   712 }
   717 }
   713 
   718 
   714 
   719 
   715 /******************************************/
   720 /******************************************/
   762 void *narrow_candidate_datatypes_c::visit(function_declaration_c *symbol) {
   767 void *narrow_candidate_datatypes_c::visit(function_declaration_c *symbol) {
   763 	/* set the function_declaration_c->datatype to the datatype returned by the function! */
   768 	/* set the function_declaration_c->datatype to the datatype returned by the function! */
   764 	symbol->type_name->datatype = search_base_type_c::get_basetype_decl(symbol->type_name);
   769 	symbol->type_name->datatype = search_base_type_c::get_basetype_decl(symbol->type_name);
   765 	symbol->datatype = symbol->type_name->datatype;
   770 	symbol->datatype = symbol->type_name->datatype;
   766 	
   771 	
       
   772 	current_scope = symbol;	
   767 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
   773 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
   768 	symbol->var_declarations_list->accept(*this);
   774 	symbol->var_declarations_list->accept(*this);
   769 	if (debug) printf("Narrowing candidate data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
   775 	if (debug) printf("Narrowing candidate data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
   770 	symbol->function_body->accept(*this);
   776 	symbol->function_body->accept(*this);
   771 	delete search_varfb_instance_type;
   777 	delete search_varfb_instance_type;
   772 	search_varfb_instance_type = NULL;
   778 	search_varfb_instance_type = NULL;
       
   779 	current_scope = NULL;	
   773 	return NULL;
   780 	return NULL;
   774 }
   781 }
   775 
   782 
   776 /***************************/
   783 /***************************/
   777 /* B 1.5.2 Function blocks */
   784 /* B 1.5.2 Function blocks */
   778 /***************************/
   785 /***************************/
   779 void *narrow_candidate_datatypes_c::visit(function_block_declaration_c *symbol) {
   786 void *narrow_candidate_datatypes_c::visit(function_block_declaration_c *symbol) {
       
   787 	current_scope = symbol;	
   780 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
   788 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
   781 	symbol->var_declarations->accept(*this);
   789 	symbol->var_declarations->accept(*this);
   782 	if (debug) printf("Narrowing candidate data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
   790 	if (debug) printf("Narrowing candidate data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
   783 	symbol->fblock_body->accept(*this);
   791 	symbol->fblock_body->accept(*this);
   784 	delete search_varfb_instance_type;
   792 	delete search_varfb_instance_type;
   785 	search_varfb_instance_type = NULL;
   793 	search_varfb_instance_type = NULL;
   786 	
   794 	current_scope = NULL;	
       
   795 
   787 	// A FB declaration can also be used as a Datatype! We now do the narrow algorithm considering it as such!
   796 	// A FB declaration can also be used as a Datatype! We now do the narrow algorithm considering it as such!
   788 	if (symbol->candidate_datatypes.size() == 1)
   797 	if (symbol->candidate_datatypes.size() == 1)
   789 		symbol->datatype = symbol->candidate_datatypes[0];
   798 		symbol->datatype = symbol->candidate_datatypes[0];
   790 	return NULL;
   799 	return NULL;
   791 }
   800 }
   792 
   801 
   793 /********************/
   802 /********************/
   794 /* B 1.5.3 Programs */
   803 /* B 1.5.3 Programs */
   795 /********************/
   804 /********************/
   796 void *narrow_candidate_datatypes_c::visit(program_declaration_c *symbol) {
   805 void *narrow_candidate_datatypes_c::visit(program_declaration_c *symbol) {
       
   806 	current_scope = symbol;	
   797 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
   807 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
   798 	symbol->var_declarations->accept(*this);
   808 	symbol->var_declarations->accept(*this);
   799 	if (debug) printf("Narrowing candidate data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value);
   809 	if (debug) printf("Narrowing candidate data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value);
   800 	symbol->function_block_body->accept(*this);
   810 	symbol->function_block_body->accept(*this);
   801 	delete search_varfb_instance_type;
   811 	delete search_varfb_instance_type;
   802 	search_varfb_instance_type = NULL;
   812 	search_varfb_instance_type = NULL;
       
   813 	current_scope = NULL;	
   803 	return NULL;
   814 	return NULL;
   804 }
   815 }
   805 
   816 
   806 /********************************************/
   817 /********************************************/
   807 /* B 1.6 Sequential function chart elements */
   818 /* B 1.6 Sequential function chart elements */