401 if (debug) std::cout << "[" << l_expr->candidate_datatypes.size() << "," << r_expr->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
401 if (debug) std::cout << "[" << l_expr->candidate_datatypes.size() << "," << r_expr->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
402 return NULL; |
402 return NULL; |
403 } |
403 } |
404 |
404 |
405 |
405 |
|
406 |
406 /* handle a binary ST expression, like '+', '-', etc... */ |
407 /* handle a binary ST expression, like '+', '-', etc... */ |
407 void *fill_candidate_datatypes_c::handle_binary_expression(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) { |
408 void *fill_candidate_datatypes_c::handle_binary_expression(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) { |
408 l_expr->accept(*this); |
409 l_expr->accept(*this); |
409 r_expr->accept(*this); |
410 r_expr->accept(*this); |
410 return handle_binary_operator(widen_table, symbol, l_expr, r_expr); |
411 return handle_binary_operator(widen_table, symbol, l_expr, r_expr); |
411 } |
412 } |
412 |
413 |
|
414 |
|
415 |
|
416 /* handle the two equality comparison operations, i.e. = (euqal) and != (not equal) */ |
|
417 /* This function is special, as it will also allow enumeration data types to be compared, with the result being a BOOL data type! |
|
418 * This possibility os not expressed in the 'widening' tables, so we need to hard code it here |
|
419 */ |
|
420 void *fill_candidate_datatypes_c::handle_equality_comparison(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) { |
|
421 search_base_type_c search_base_type; |
|
422 handle_binary_expression(widen_table, symbol, l_expr, r_expr); |
|
423 for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++) |
|
424 for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++) { |
|
425 if ((l_expr->candidate_datatypes[i] == r_expr->candidate_datatypes[j]) && search_base_type.type_is_enumerated(l_expr->candidate_datatypes[i])) |
|
426 add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name); |
|
427 } |
|
428 return NULL; |
|
429 } |
413 |
430 |
414 |
431 |
415 |
432 |
416 /* a helper function... */ |
433 /* a helper function... */ |
417 symbol_c *fill_candidate_datatypes_c::base_type(symbol_c *symbol) { |
434 symbol_c *fill_candidate_datatypes_c::base_type(symbol_c *symbol) { |
1317 /* B.3 - Language ST (Structured Text) */ |
1334 /* B.3 - Language ST (Structured Text) */ |
1318 /***************************************/ |
1335 /***************************************/ |
1319 /***********************/ |
1336 /***********************/ |
1320 /* B 3.1 - Expressions */ |
1337 /* B 3.1 - Expressions */ |
1321 /***********************/ |
1338 /***********************/ |
1322 void *fill_candidate_datatypes_c::visit( or_expression_c *symbol) {return handle_binary_expression(widen_OR_table, symbol, symbol->l_exp, symbol->r_exp);} |
1339 void *fill_candidate_datatypes_c::visit( or_expression_c *symbol) {return handle_binary_expression (widen_OR_table, symbol, symbol->l_exp, symbol->r_exp);} |
1323 void *fill_candidate_datatypes_c::visit( xor_expression_c *symbol) {return handle_binary_expression(widen_XOR_table, symbol, symbol->l_exp, symbol->r_exp);} |
1340 void *fill_candidate_datatypes_c::visit( xor_expression_c *symbol) {return handle_binary_expression (widen_XOR_table, symbol, symbol->l_exp, symbol->r_exp);} |
1324 void *fill_candidate_datatypes_c::visit( and_expression_c *symbol) {return handle_binary_expression(widen_AND_table, symbol, symbol->l_exp, symbol->r_exp);} |
1341 void *fill_candidate_datatypes_c::visit( and_expression_c *symbol) {return handle_binary_expression (widen_AND_table, symbol, symbol->l_exp, symbol->r_exp);} |
1325 |
1342 |
1326 void *fill_candidate_datatypes_c::visit( equ_expression_c *symbol) {return handle_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1343 void *fill_candidate_datatypes_c::visit( equ_expression_c *symbol) {return handle_equality_comparison(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1327 void *fill_candidate_datatypes_c::visit(notequ_expression_c *symbol) {return handle_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1344 void *fill_candidate_datatypes_c::visit(notequ_expression_c *symbol) {return handle_equality_comparison(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1328 void *fill_candidate_datatypes_c::visit( lt_expression_c *symbol) {return handle_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1345 void *fill_candidate_datatypes_c::visit( lt_expression_c *symbol) {return handle_binary_expression (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1329 void *fill_candidate_datatypes_c::visit( gt_expression_c *symbol) {return handle_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1346 void *fill_candidate_datatypes_c::visit( gt_expression_c *symbol) {return handle_binary_expression (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1330 void *fill_candidate_datatypes_c::visit( le_expression_c *symbol) {return handle_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1347 void *fill_candidate_datatypes_c::visit( le_expression_c *symbol) {return handle_binary_expression (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1331 void *fill_candidate_datatypes_c::visit( ge_expression_c *symbol) {return handle_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1348 void *fill_candidate_datatypes_c::visit( ge_expression_c *symbol) {return handle_binary_expression (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);} |
1332 |
1349 |
1333 |
1350 void *fill_candidate_datatypes_c::visit( add_expression_c *symbol) {return handle_binary_expression (widen_ADD_table, symbol, symbol->l_exp, symbol->r_exp);} |
1334 void *fill_candidate_datatypes_c::visit( add_expression_c *symbol) {return handle_binary_expression(widen_ADD_table, symbol, symbol->l_exp, symbol->r_exp);} |
1351 void *fill_candidate_datatypes_c::visit( sub_expression_c *symbol) {return handle_binary_expression (widen_SUB_table, symbol, symbol->l_exp, symbol->r_exp);} |
1335 void *fill_candidate_datatypes_c::visit( sub_expression_c *symbol) {return handle_binary_expression(widen_SUB_table, symbol, symbol->l_exp, symbol->r_exp);} |
1352 void *fill_candidate_datatypes_c::visit( mul_expression_c *symbol) {return handle_binary_expression (widen_MUL_table, symbol, symbol->l_exp, symbol->r_exp);} |
1336 void *fill_candidate_datatypes_c::visit( mul_expression_c *symbol) {return handle_binary_expression(widen_MUL_table, symbol, symbol->l_exp, symbol->r_exp);} |
1353 void *fill_candidate_datatypes_c::visit( div_expression_c *symbol) {return handle_binary_expression (widen_DIV_table, symbol, symbol->l_exp, symbol->r_exp);} |
1337 void *fill_candidate_datatypes_c::visit( div_expression_c *symbol) {return handle_binary_expression(widen_DIV_table, symbol, symbol->l_exp, symbol->r_exp);} |
1354 void *fill_candidate_datatypes_c::visit( mod_expression_c *symbol) {return handle_binary_expression (widen_MOD_table, symbol, symbol->l_exp, symbol->r_exp);} |
1338 void *fill_candidate_datatypes_c::visit( mod_expression_c *symbol) {return handle_binary_expression(widen_MOD_table, symbol, symbol->l_exp, symbol->r_exp);} |
1355 void *fill_candidate_datatypes_c::visit( power_expression_c *symbol) {return handle_binary_expression (widen_EXPT_table, symbol, symbol->l_exp, symbol->r_exp);} |
1339 void *fill_candidate_datatypes_c::visit(power_expression_c *symbol) {return handle_binary_expression(widen_EXPT_table, symbol, symbol->l_exp, symbol->r_exp);} |
|
1340 |
1356 |
1341 |
1357 |
1342 void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) { |
1358 void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) { |
1343 /* NOTE: The standard defines the syntax for this 'negation' operation, but |
1359 /* NOTE: The standard defines the syntax for this 'negation' operation, but |
1344 * does not define the its semantics. |
1360 * does not define the its semantics. |