stage3/fill_candidate_datatypes.cc
changeset 502 a6211f73690b
parent 490 29f6ab0bf954
child 523 773303b7f31f
equal deleted inserted replaced
501:19bc099215d8 502:a6211f73690b
   520 /* B 1.3 - Data types */
   520 /* B 1.3 - Data types */
   521 /**********************/
   521 /**********************/
   522 /********************************/
   522 /********************************/
   523 /* B 1.3.3 - Derived data types */
   523 /* B 1.3.3 - Derived data types */
   524 /********************************/
   524 /********************************/
       
   525 
       
   526 /* simple_specification ASSIGN constant */
       
   527 // SYM_REF2(simple_spec_init_c, simple_specification, constant)
       
   528 void *fill_candidate_datatypes_c::visit(simple_spec_init_c *symbol) {
       
   529 	if (NULL != symbol->constant) symbol->constant->accept(*this);
       
   530 	add_datatype_to_candidate_list(symbol->simple_specification, base_type(symbol->simple_specification));
       
   531 	symbol->candidate_datatypes = symbol->simple_specification->candidate_datatypes;
       
   532 	/* NOTE: Even if the constant and the type are of incompatible data types, we let the
       
   533 	 *       simple_spec_init_c object inherit the data type of the type declaration (simple_specification)
       
   534 	 *       This will let us produce more informative error messages when checking data type compatibility
       
   535 	 *       with located variables (AT %QW3.4 : WORD).
       
   536 	 */
       
   537 	// if (NULL != symbol->constant) intersect_candidate_datatype_list(symbol /*origin, dest.*/, symbol->constant /*with*/);
       
   538 	return NULL;
       
   539 }
       
   540 
   525 /*  signed_integer DOTDOT signed_integer */
   541 /*  signed_integer DOTDOT signed_integer */
   526 // SYM_REF2(subrange_c, lower_limit, upper_limit)
   542 // SYM_REF2(subrange_c, lower_limit, upper_limit)
   527 void *fill_candidate_datatypes_c::visit(subrange_c *symbol) {
   543 void *fill_candidate_datatypes_c::visit(subrange_c *symbol) {
   528 	symbol->lower_limit->accept(*this);
   544 	symbol->lower_limit->accept(*this);
   529 	symbol->upper_limit->accept(*this);
   545 	symbol->upper_limit->accept(*this);
   572 void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
   588 void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
   573 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol)); /* will only add if non NULL */
   589 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol)); /* will only add if non NULL */
   574 	if (debug) std::cout << "VAR [" << symbol->candidate_datatypes.size() << "]\n";
   590 	if (debug) std::cout << "VAR [" << symbol->candidate_datatypes.size() << "]\n";
   575 	return NULL;
   591 	return NULL;
   576 }
   592 }
       
   593 
   577 
   594 
   578 /********************************************/
   595 /********************************************/
   579 /* B 1.4.1 - Directly Represented Variables */
   596 /* B 1.4.1 - Directly Represented Variables */
   580 /********************************************/
   597 /********************************************/
   581 void *fill_candidate_datatypes_c::visit(direct_variable_c *symbol) {
   598 void *fill_candidate_datatypes_c::visit(direct_variable_c *symbol) {
   586 	/* if (symbol->value == NULL) ERROR;
   603 	/* if (symbol->value == NULL) ERROR;
   587 	 * if (symbol->value[0] == '\0') ERROR;
   604 	 * if (symbol->value[0] == '\0') ERROR;
   588 	 * if (symbol->value[1] == '\0') ERROR;
   605 	 * if (symbol->value[1] == '\0') ERROR;
   589 	 */
   606 	 */
   590 	switch (symbol->value[2]) {
   607 	switch (symbol->value[2]) {
   591 		case 'X': /* bit   -  1 bit  */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name);  break;
   608 		case 'x': case 'X': /* bit   -  1 bit  */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name);  break;
   592 		case 'B': /* byte  -  8 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::byte_type_name);  break;
   609 		case 'b': case 'B': /* byte  -  8 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::byte_type_name);  break;
   593 		case 'W': /* word  - 16 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::word_type_name);  break;
   610 		case 'w': case 'W': /* word  - 16 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::word_type_name);  break;
   594 		case 'D': /* dword - 32 bits */	add_datatype_to_candidate_list(symbol, &search_constant_type_c::dword_type_name); break;
   611 		case 'd': case 'D': /* dword - 32 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::dword_type_name); break;
   595 		case 'L': /* lword - 64 bits */	add_datatype_to_candidate_list(symbol, &search_constant_type_c::lword_type_name); break;
   612 		case 'l': case 'L': /* lword - 64 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::lword_type_name); break;
   596         	          /* if none of the above, then the empty string was used <=> boolean */
   613         	          /* if none of the above, then the empty string was used <=> boolean */
   597 		default:                        add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name);  break;
   614 		default:                        add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name);  break;
   598 	}
   615 	}
   599 	return NULL;
   616 	return NULL;
   600 }
   617 }
   638  */
   655  */
   639 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
   656 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
   640 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));  /* will only add if non NULL */
   657 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));  /* will only add if non NULL */
   641 	return NULL;
   658 	return NULL;
   642 }
   659 }
       
   660 
       
   661 
       
   662 
       
   663 /******************************************/
       
   664 /* B 1.4.3 - Declaration & Initialisation */
       
   665 /******************************************/
       
   666 
       
   667 void *fill_candidate_datatypes_c::visit(var1_list_c *symbol) {
       
   668 #if 0   /* We don't really need to set the datatype of each variable. We just check the declaration itself! */
       
   669   for(int i = 0; i < symbol->n; i++) {
       
   670     add_datatype_to_candidate_list(symbol->elements[i], search_varfb_instance_type->get_basetype_decl(symbol->elements[i])); /* will only add if non NULL */
       
   671   }
       
   672 #endif
       
   673   return NULL;
       
   674 }  
       
   675 
       
   676 
       
   677 /*  AT direct_variable */
       
   678 // SYM_REF1(location_c, direct_variable)
       
   679 void *fill_candidate_datatypes_c::visit(location_c *symbol) {
       
   680 	symbol->direct_variable->accept(*this);
       
   681 	symbol->candidate_datatypes = symbol->direct_variable->candidate_datatypes;
       
   682 	return NULL;
       
   683 }
       
   684 
       
   685 
       
   686 /*  [variable_name] location ':' located_var_spec_init */
       
   687 /* variable_name -> may be NULL ! */
       
   688 // SYM_REF3(located_var_decl_c, variable_name, location, located_var_spec_init)
       
   689 void *fill_candidate_datatypes_c::visit(located_var_decl_c *symbol) {
       
   690   symbol->located_var_spec_init->accept(*this);
       
   691   symbol->location->accept(*this);
       
   692   symbol->variable_name->candidate_datatypes = symbol->location->candidate_datatypes;
       
   693   intersect_candidate_datatype_list(symbol->variable_name /*origin, dest.*/, symbol->located_var_spec_init /*with*/);
       
   694   return NULL;
       
   695 }  
       
   696 
       
   697 
       
   698 
       
   699 
   643 
   700 
   644 /************************************/
   701 /************************************/
   645 /* B 1.5 Program organization units */
   702 /* B 1.5 Program organization units */
   646 /************************************/
   703 /************************************/
   647 /*********************/
   704 /*********************/