stage3/fill_candidate_datatypes.cc
changeset 827 e3800aff352c
parent 813 0630cc31569f
child 834 783ef40344dd
equal deleted inserted replaced
826:1e6bf9839ece 827:e3800aff352c
  1110 void *fill_candidate_datatypes_c::visit(array_variable_c *symbol) {
  1110 void *fill_candidate_datatypes_c::visit(array_variable_c *symbol) {
  1111 	/* get the declaration of the data type __stored__ in the array... */
  1111 	/* get the declaration of the data type __stored__ in the array... */
  1112 	/* if we were to want the data type of the array itself, then we should call_param_name
  1112 	/* if we were to want the data type of the array itself, then we should call_param_name
  1113 	 * search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable)
  1113 	 * search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable)
  1114 	 */
  1114 	 */
  1115 	symbol_c *result = search_varfb_instance_type->get_basetype_decl(symbol);
  1115 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));   /* will only add if non NULL */
  1116 	if (NULL != result) add_datatype_to_candidate_list(symbol, result);
       
  1117 	
  1116 	
  1118 	/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */
  1117 	/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */
  1119 	symbol->subscript_list->accept(*this);
  1118 	symbol->subscript_list->accept(*this);
       
  1119 
       
  1120 	/* recursively call the subscripted_variable. We need to do this since the array variable may be stored inside a structured
       
  1121 	 * variable (i.e. if it is an element inside a struct), in which case we want to recursively visit every element of the struct,
       
  1122 	 * as it may contain more arrays whose subscripts must also be visited!
       
  1123 	 * e.g.   structvar.a1[v1+2].b1.c1[v2+3].d1
       
  1124 	 *        TYPE
       
  1125 	 *           d_s: STRUCT d1: int; d2: int;
       
  1126 	 *           d_a: ARRAY [1..3] OF d_s;  
       
  1127 	 *           c_s: STRUCT c1: d_a; c2: d_a;
       
  1128 	 *           b_s: STRUCT b1: c_s; b2: c_s;
       
  1129 	 *           b_a: ARRAY [1..3] OF b_s;  
       
  1130 	 *           a_s: STRUCT a1: b_a; a2: b_a;
       
  1131 	 *        END_TYPE 
       
  1132 	 *        VAR
       
  1133 	 *          structvar: a_s;
       
  1134 	 *        END_VAR
       
  1135 	 */
       
  1136 	symbol->subscripted_variable->accept(*this);
  1120 
  1137 
  1121 	if (debug) std::cout << "ARRAY_VAR [" << symbol->candidate_datatypes.size() << "]\n";	
  1138 	if (debug) std::cout << "ARRAY_VAR [" << symbol->candidate_datatypes.size() << "]\n";	
  1122 	return NULL;
  1139 	return NULL;
  1123 }
  1140 }
  1124 
  1141 
  1134  *           may be accessed as fields of a structured variable!
  1151  *           may be accessed as fields of a structured variable!
  1135  *           Code handling a structured_variable_c must take
  1152  *           Code handling a structured_variable_c must take
  1136  *           this into account!
  1153  *           this into account!
  1137  */
  1154  */
  1138 // SYM_REF2(structured_variable_c, record_variable, field_selector)
  1155 // SYM_REF2(structured_variable_c, record_variable, field_selector)
  1139 /* NOTE: We do not need to recursively determine the data types of each field_selector, as the search_varfb_instance_type
       
  1140  * will do that for us. So we determine the candidate datatypes only for the full structured_variable.
       
  1141  */
       
  1142 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
  1156 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
       
  1157 	/* NOTE: We do not need to recursively determine the data types of each field_selector, as the search_varfb_instance_type
       
  1158 	 * will do that for us. So we determine the candidate datatypes only for the full structured_variable.
       
  1159 	 */
  1143 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));  /* will only add if non NULL */
  1160 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));  /* will only add if non NULL */
       
  1161 	/* However, we do need to visit each record type recursively!
       
  1162 	 * Remember that a structured variable may be stored inside an array (e.g. arrayvar[33].elem1)
       
  1163 	 * The array subscripts may contain a complex expression (e.g. arrayvar[ varx + 33].elem1) whose datatype must be correctly determined!
       
  1164 	 * The expression, may even contain a function call to an overloaded function!
       
  1165 	 *      (e.g.  arrayvar[ varx + TRUNC(realvar)].elem1)
       
  1166 	 */
       
  1167 	symbol->record_variable->accept(*this);
  1144 	return NULL;
  1168 	return NULL;
  1145 }
  1169 }
  1146 
  1170 
  1147 
  1171 
  1148 
  1172