stage3/fill_candidate_datatypes.cc
changeset 938 31e3b3f2eff1
parent 936 0f7bcc160568
child 939 5074236fb3c4
equal deleted inserted replaced
937:887e7d90445a 938:31e3b3f2eff1
  1168 
  1168 
  1169 /*********************/
  1169 /*********************/
  1170 /* B 1.4 - Variables */
  1170 /* B 1.4 - Variables */
  1171 /*********************/
  1171 /*********************/
  1172 void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
  1172 void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
  1173 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol)); /* will only add if non NULL */
  1173 	/*  NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class!
       
  1174 	 *        Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm
       
  1175 	 *        in this fill_candidate_datatypes_c itself!
       
  1176 	 *        This is needed because we need to know in which scope (i.e. the datatype of the recor_variable in a structtured_variable_c)
       
  1177 	 *        we will search for the field_variable of the structured_variable_c
       
  1178 	 */
       
  1179 	symbol->datatype = search_varfb_instance_type->get_basetype_decl(symbol); // Do the narrow algorithm in this fill_candidate_datatypes_c!!
       
  1180 	add_datatype_to_candidate_list(symbol, symbol->datatype); /* will only add if non NULL */
  1174 	if (debug) std::cout << "VAR [" << symbol->candidate_datatypes.size() << "]\n";
  1181 	if (debug) std::cout << "VAR [" << symbol->candidate_datatypes.size() << "]\n";
  1175 	return NULL;
  1182 	return NULL;
  1176 }
  1183 }
  1177 
  1184 
  1178 
  1185 
  1209 	/* get the declaration of the data type __stored__ in the array... */
  1216 	/* get the declaration of the data type __stored__ in the array... */
  1210 	/* if we were to want the data type of the array itself, then we should call_param_name
  1217 	/* if we were to want the data type of the array itself, then we should call_param_name
  1211 	 * search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable)
  1218 	 * search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable)
  1212 	 */
  1219 	 */
  1213 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));   /* will only add if non NULL */
  1220 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));   /* will only add if non NULL */
  1214 	
  1221 
       
  1222 	/*  NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class!
       
  1223 	 *        Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm
       
  1224 	 *        in this fill_candidate_datatypes_c itself!
       
  1225 	 *        This is needed because we need to know in which scope (i.e. the datatype of the recor_variable in a structtured_variable_c)
       
  1226 	 *        we will search for the field_variable of the structured_variable_c
       
  1227 	 */
       
  1228 	if (symbol->candidate_datatypes.size() == 1)
       
  1229 	  // narrow the symbol->datatype for this strcutured_variable as explained above!
       
  1230 	  symbol->datatype = symbol->candidate_datatypes[0];
       
  1231 
  1215 	/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */
  1232 	/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */
  1216 	symbol->subscript_list->accept(*this);
  1233 	symbol->subscript_list->accept(*this);
  1217 
  1234 
  1218 	/* recursively call the subscripted_variable. We need to do this since the array variable may be stored inside a structured
  1235 	/* recursively call the subscripted_variable. We need to do this since the array variable may be stored inside a structured
  1219 	 * variable (i.e. if it is an element inside a struct), in which case we want to recursively visit every element of the struct,
  1236 	 * variable (i.e. if it is an element inside a struct), in which case we want to recursively visit every element of the struct,
  1250  *           Code handling a structured_variable_c must take
  1267  *           Code handling a structured_variable_c must take
  1251  *           this into account!
  1268  *           this into account!
  1252  */
  1269  */
  1253 // SYM_REF2(structured_variable_c, record_variable, field_selector)
  1270 // SYM_REF2(structured_variable_c, record_variable, field_selector)
  1254 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
  1271 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
  1255 	/* NOTE: We do not need to recursively determine the data types of each field_selector, as the search_varfb_instance_type
  1272 	/* Remember that a structured variable may be stored inside an array (e.g. arrayvar[33].elem1)
  1256 	 * will do that for us. So we determine the candidate datatypes only for the full structured_variable.
       
  1257 	 */
       
  1258 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));  /* will only add if non NULL */
       
  1259 	/* However, we do need to visit each record type recursively!
       
  1260 	 * Remember that a structured variable may be stored inside an array (e.g. arrayvar[33].elem1)
       
  1261 	 * The array subscripts may contain a complex expression (e.g. arrayvar[ varx + 33].elem1) whose datatype must be correctly determined!
  1273 	 * The array subscripts may contain a complex expression (e.g. arrayvar[ varx + 33].elem1) whose datatype must be correctly determined!
  1262 	 * The expression, may even contain a function call to an overloaded function!
  1274 	 * The expression, may even contain a function call to an overloaded function!
  1263 	 *      (e.g.  arrayvar[ varx + TRUNC(realvar)].elem1)
  1275 	 *      (e.g.  arrayvar[ varx + TRUNC(realvar)].elem1)
  1264 	 */
  1276 	 */
  1265 	symbol->record_variable->accept(*this);
  1277 	symbol->record_variable->accept(*this);
       
  1278 	
       
  1279 	/*  NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class!
       
  1280 	 *        Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm
       
  1281 	 *        in this fill_candidate_datatypes_c itself!
       
  1282 	 *        This is needed because we need to know in which scope (i.e. the datatype of the recor_variable in a structtured_variable_c)
       
  1283 	 *        we will search for the field_variable of the structured_variable_c
       
  1284 	 */
       
  1285 	if (NULL != symbol->record_variable->datatype) 
       
  1286 	  // We relly on the fact that we have already narrowed the symbol->datatype for the record variable, and use it as the scope in which the filed_variable is declared!
       
  1287 	  add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(get_datatype_info_c::get_struct_field_type_id(symbol->record_variable->datatype, symbol->field_selector)));  /* will only add if non NULL */
       
  1288 	if (symbol->candidate_datatypes.size() == 1)
       
  1289 	  // narrow the symbol->datatype for this strcutured_variable as explained above!
       
  1290 	  symbol->datatype = symbol->candidate_datatypes[0];
  1266 	return NULL;
  1291 	return NULL;
  1267 }
  1292 }
  1268 
  1293 
  1269 
  1294 
  1270 
  1295 
  1915     /* canonical/base datatype of REF_TO types (see search_base_type_c ...)                */ 
  1940     /* canonical/base datatype of REF_TO types (see search_base_type_c ...)                */ 
  1916     ref_spec_c *ref_spec = dynamic_cast<ref_spec_c *>(symbol->exp->candidate_datatypes[i]);
  1941     ref_spec_c *ref_spec = dynamic_cast<ref_spec_c *>(symbol->exp->candidate_datatypes[i]);
  1917     
  1942     
  1918     if (NULL != ref_spec)
  1943     if (NULL != ref_spec)
  1919       add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(ref_spec->type_name));
  1944       add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(ref_spec->type_name));
       
  1945     
  1920   }
  1946   }
       
  1947 
       
  1948   /*  NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class!
       
  1949    *        Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm
       
  1950    *        in this fill_candidate_datatypes_c itself!
       
  1951    *        This is needed because we need to know in which scope (i.e. the datatype of the recor_variable in a structtured_variable_c)
       
  1952    *        we will search for the field_variable of the structured_variable_c
       
  1953    * 
       
  1954    *        Since the deref_operator_c may be used inside structures, we must narrow it here, if possible!
       
  1955    */
       
  1956   if (symbol->candidate_datatypes.size() == 1)
       
  1957     // narrow the symbol->datatype for this symbol as explained above!
       
  1958     symbol->datatype = symbol->candidate_datatypes[0];
  1921   
  1959   
  1922   return NULL;
  1960   return NULL;
  1923 }
  1961 }
  1924 
  1962 
  1925 
  1963