236 symbol_c *get_datatype_info_c::get_id(symbol_c *datatype) { |
236 symbol_c *get_datatype_info_c::get_id(symbol_c *datatype) { |
237 return get_datatype_id_c::get_id(datatype); |
237 return get_datatype_id_c::get_id(datatype); |
238 } |
238 } |
239 |
239 |
240 |
240 |
|
241 /* Returns true if both datatypes are identicial. |
|
242 * WARING: When handling REF_TO datatypes, it may return 'true' even though |
|
243 * the datatypes are not identicial. This occurs when at least one of the |
|
244 * datatypes if a ref_to_any_c, which os equivalent to a (void *), and the |
|
245 * other datatype is any REF_TO datatype (including a ref_to_any_c). |
|
246 */ |
241 bool get_datatype_info_c::is_type_equal(symbol_c *first_type, symbol_c *second_type) { |
247 bool get_datatype_info_c::is_type_equal(symbol_c *first_type, symbol_c *second_type) { |
242 if ((NULL == first_type) || (NULL == second_type)) {return false;} |
248 if (!is_type_valid( first_type)) {return false;} |
243 if (typeid(* first_type) == typeid(invalid_type_name_c)) {return false;} |
249 if (!is_type_valid(second_type)) {return false;} |
244 if (typeid(*second_type) == typeid(invalid_type_name_c)) {return false;} |
250 |
245 |
251 /* GENERIC DATATYPES */ |
|
252 /* For the moment, we only support the ANY generic datatype! */ |
|
253 if ((is_ANY_generic_type( first_type)) || |
|
254 (is_ANY_generic_type(second_type))) {return true;} |
|
255 |
246 /* ANY_ELEMENTARY */ |
256 /* ANY_ELEMENTARY */ |
247 if ((is_ANY_ELEMENTARY(first_type)) && |
257 if ((is_ANY_ELEMENTARY(first_type)) && |
248 (typeid(*first_type) == typeid(*second_type))) {return true;} |
258 (typeid(*first_type) == typeid(*second_type))) {return true;} |
249 |
259 |
250 /* ANY_DERIVED */ |
260 /* ANY_DERIVED */ |
251 if (is_ref_to(first_type) && is_ref_to(second_type)) { |
261 if (is_ref_to(first_type) && is_ref_to(second_type)) { |
252 /* if either of them is the constant 'NULL' then we consider them 'equal', as NULL is compatible to a REF_TO any datatype! */ |
|
253 if (typeid(* first_type) == typeid(ref_value_null_literal_c)) {return true;} |
|
254 if (typeid(*second_type) == typeid(ref_value_null_literal_c)) {return true;} |
|
255 return is_type_equal(search_base_type_c::get_basetype_decl(get_ref_to(first_type )), |
262 return is_type_equal(search_base_type_c::get_basetype_decl(get_ref_to(first_type )), |
256 search_base_type_c::get_basetype_decl(get_ref_to(second_type))); |
263 search_base_type_c::get_basetype_decl(get_ref_to(second_type))); |
257 } |
264 } |
258 |
265 |
259 return (first_type == second_type); |
266 return (first_type == second_type); |
260 } |
267 } |
261 |
|
262 |
268 |
263 |
269 |
264 bool get_datatype_info_c::is_type_valid(symbol_c *type) { |
270 bool get_datatype_info_c::is_type_valid(symbol_c *type) { |
265 if (NULL == type) {return false;} |
271 if (NULL == type) {return false;} |
266 if (typeid(*type) == typeid(invalid_type_name_c)) {return false;} |
272 if (typeid(*type) == typeid(invalid_type_name_c)) {return false;} |
297 if (NULL == type_decl) {return false;} |
303 if (NULL == type_decl) {return false;} |
298 |
304 |
299 if (typeid(*type_decl) == typeid(ref_type_decl_c)) {return true;} /* identifier ':' ref_spec_init */ |
305 if (typeid(*type_decl) == typeid(ref_type_decl_c)) {return true;} /* identifier ':' ref_spec_init */ |
300 if (typeid(*type_decl) == typeid(ref_spec_init_c)) {return true;} /* ref_spec [ ASSIGN ref_initialization ]; */ |
306 if (typeid(*type_decl) == typeid(ref_spec_init_c)) {return true;} /* ref_spec [ ASSIGN ref_initialization ]; */ |
301 if (typeid(*type_decl) == typeid(ref_spec_c)) {return true;} /* REF_TO (non_generic_type_name | function_block_type_name) */ |
307 if (typeid(*type_decl) == typeid(ref_spec_c)) {return true;} /* REF_TO (non_generic_type_name | function_block_type_name) */ |
302 if (typeid(*type_decl) == typeid(ref_value_null_literal_c)) {return true;} /* REF_TO (non_generic_type_name | function_block_type_name) */ |
|
303 return false; |
308 return false; |
304 } |
309 } |
305 |
310 |
306 |
311 |
307 |
312 |
402 } |
407 } |
403 |
408 |
404 |
409 |
405 |
410 |
406 |
411 |
|
412 bool get_datatype_info_c::is_ANY_generic_type(symbol_c *type_symbol) { |
|
413 symbol_c *type_decl = search_base_type_c::get_basetype_decl(type_symbol); |
|
414 if (NULL == type_decl) {return false;} |
|
415 if (typeid(*type_decl) == typeid(generic_type_any_c)) {return true;} /* The ANY keyword! */ |
|
416 return false; |
|
417 } |
407 |
418 |
408 |
419 |
409 bool get_datatype_info_c::is_ANY_ELEMENTARY(symbol_c *type_symbol) { |
420 bool get_datatype_info_c::is_ANY_ELEMENTARY(symbol_c *type_symbol) { |
410 if (type_symbol == NULL) {return false;} |
421 if (type_symbol == NULL) {return false;} |
411 if (is_ANY_MAGNITUDE(type_symbol)) {return true;} |
422 if (is_ANY_MAGNITUDE(type_symbol)) {return true;} |