1168 |
1169 |
1169 /*********************/ |
1170 /*********************/ |
1170 /* B 1.4 - Variables */ |
1171 /* B 1.4 - Variables */ |
1171 /*********************/ |
1172 /*********************/ |
1172 void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) { |
1173 void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) { |
|
1174 symbol->scope = current_scope; // the scope in which this variable was declared! |
1173 /* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
1175 /* 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 |
1176 * Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
1175 * in this fill_candidate_datatypes_c itself! |
1177 * 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 record_variable in a structtured_variable_c) |
1178 * This is needed because we need to know in which scope (i.e. the datatype of the record_variable in a structtured_variable_c) |
1177 * we will search for the field_variable of the structured_variable_c. Similarly, it is also used to determine the datatype |
1179 * we will search for the field_variable of the structured_variable_c. Similarly, it is also used to determine the datatype |
1229 * VAR |
1231 * VAR |
1230 * structvar: a_s; |
1232 * structvar: a_s; |
1231 * END_VAR |
1233 * END_VAR |
1232 */ |
1234 */ |
1233 symbol->subscripted_variable->accept(*this); |
1235 symbol->subscripted_variable->accept(*this); |
1234 |
1236 // the scope in which this variable was declared! It will be the same as the subscripted variable (a symbolic_variable_ !) |
|
1237 symbol->scope = symbol->subscripted_variable->scope; |
|
1238 if (NULL == symbol->scope) ERROR; |
|
1239 |
|
1240 /* get the declaration of the data type __stored__ in the array... */ |
1235 add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(get_datatype_info_c::get_array_storedtype_id(symbol->subscripted_variable->datatype))); /* will only add if non NULL */ |
1241 add_datatype_to_candidate_list(symbol, search_base_type_c::get_basetype_decl(get_datatype_info_c::get_array_storedtype_id(symbol->subscripted_variable->datatype))); /* will only add if non NULL */ |
1236 |
1242 |
1237 /* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
1243 /* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
1238 * Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
1244 * Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
1239 * in this fill_candidate_datatypes_c itself! |
1245 * in this fill_candidate_datatypes_c itself! |
1271 * The array subscripts may contain a complex expression (e.g. arrayvar[ varx + 33].elem1) whose datatype must be correctly determined! |
1277 * The array subscripts may contain a complex expression (e.g. arrayvar[ varx + 33].elem1) whose datatype must be correctly determined! |
1272 * The expression, may even contain a function call to an overloaded function! |
1278 * The expression, may even contain a function call to an overloaded function! |
1273 * (e.g. arrayvar[ varx + TRUNC(realvar)].elem1) |
1279 * (e.g. arrayvar[ varx + TRUNC(realvar)].elem1) |
1274 */ |
1280 */ |
1275 symbol->record_variable->accept(*this); |
1281 symbol->record_variable->accept(*this); |
|
1282 symbol->scope = symbol->record_variable->datatype; // the scope in which this variable was declared! Will be used in stage4 |
1276 |
1283 |
1277 /* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
1284 /* NOTE: We need to fully determine the datatype of each element in the structured_variable inside this fill_candidate_datatypes class! |
1278 * Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
1285 * Basically, for variables (be they symbolic_variable, structured_variable, array_variable), we do the narrow algorithm |
1279 * in this fill_candidate_datatypes_c itself! |
1286 * in this fill_candidate_datatypes_c itself! |
1280 * This is needed because we need to know in which scope (i.e. the datatype of the record_variable in a structtured_variable_c) |
1287 * This is needed because we need to know in which scope (i.e. the datatype of the record_variable in a structtured_variable_c) |
1410 /* B 1.5.1 Functions */ |
1417 /* B 1.5.1 Functions */ |
1411 /*********************/ |
1418 /*********************/ |
1412 void *fill_candidate_datatypes_c::visit(function_declaration_c *symbol) { |
1419 void *fill_candidate_datatypes_c::visit(function_declaration_c *symbol) { |
1413 if (debug) printf("Filling candidate data types list of function %s\n", ((token_c *)(symbol->derived_function_name))->value); |
1420 if (debug) printf("Filling candidate data types list of function %s\n", ((token_c *)(symbol->derived_function_name))->value); |
1414 local_enumerated_value_symtable.reset(); |
1421 local_enumerated_value_symtable.reset(); |
|
1422 current_scope = symbol; |
1415 symbol->var_declarations_list->accept(populate_enumvalue_symtable); |
1423 symbol->var_declarations_list->accept(populate_enumvalue_symtable); |
1416 |
1424 |
1417 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
1425 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
1418 symbol->var_declarations_list->accept(*this); |
1426 symbol->var_declarations_list->accept(*this); |
1419 symbol->function_body->accept(*this); |
1427 symbol->function_body->accept(*this); |
1420 delete search_var_instance_decl; |
1428 delete search_var_instance_decl; |
1421 search_var_instance_decl = NULL; |
1429 search_var_instance_decl = NULL; |
1422 |
1430 |
|
1431 current_scope = NULL; |
1423 local_enumerated_value_symtable.reset(); |
1432 local_enumerated_value_symtable.reset(); |
1424 return NULL; |
1433 return NULL; |
1425 } |
1434 } |
1426 |
1435 |
1427 /***************************/ |
1436 /***************************/ |
1428 /* B 1.5.2 Function blocks */ |
1437 /* B 1.5.2 Function blocks */ |
1429 /***************************/ |
1438 /***************************/ |
1430 void *fill_candidate_datatypes_c::visit(function_block_declaration_c *symbol) { |
1439 void *fill_candidate_datatypes_c::visit(function_block_declaration_c *symbol) { |
1431 if (debug) printf("Filling candidate data types list of FB %s\n", ((token_c *)(symbol->fblock_name))->value); |
1440 if (debug) printf("Filling candidate data types list of FB %s\n", ((token_c *)(symbol->fblock_name))->value); |
1432 local_enumerated_value_symtable.reset(); |
1441 local_enumerated_value_symtable.reset(); |
|
1442 current_scope = symbol; |
1433 symbol->var_declarations->accept(populate_enumvalue_symtable); |
1443 symbol->var_declarations->accept(populate_enumvalue_symtable); |
1434 |
1444 |
1435 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
1445 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
1436 symbol->var_declarations->accept(*this); |
1446 symbol->var_declarations->accept(*this); |
1437 symbol->fblock_body->accept(*this); |
1447 symbol->fblock_body->accept(*this); |
1438 delete search_var_instance_decl; |
1448 delete search_var_instance_decl; |
1439 search_var_instance_decl = NULL; |
1449 search_var_instance_decl = NULL; |
1440 |
1450 |
|
1451 current_scope = NULL; |
1441 local_enumerated_value_symtable.reset(); |
1452 local_enumerated_value_symtable.reset(); |
1442 |
1453 |
1443 /* The FB declaration itself may be used as a dataype! We now do the fill algorithm considering |
1454 /* The FB declaration itself may be used as a dataype! We now do the fill algorithm considering |
1444 * function_block_declaration_c a data type declaration... |
1455 * function_block_declaration_c a data type declaration... |
1445 */ |
1456 */ |
1452 /* B 1.5.3 - Programs */ |
1463 /* B 1.5.3 - Programs */ |
1453 /**********************/ |
1464 /**********************/ |
1454 void *fill_candidate_datatypes_c::visit(program_declaration_c *symbol) { |
1465 void *fill_candidate_datatypes_c::visit(program_declaration_c *symbol) { |
1455 if (debug) printf("Filling candidate data types list in program %s\n", ((token_c *)(symbol->program_type_name))->value); |
1466 if (debug) printf("Filling candidate data types list in program %s\n", ((token_c *)(symbol->program_type_name))->value); |
1456 local_enumerated_value_symtable.reset(); |
1467 local_enumerated_value_symtable.reset(); |
|
1468 current_scope = symbol; |
1457 symbol->var_declarations->accept(populate_enumvalue_symtable); |
1469 symbol->var_declarations->accept(populate_enumvalue_symtable); |
1458 |
1470 |
1459 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
1471 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
1460 symbol->var_declarations->accept(*this); |
1472 symbol->var_declarations->accept(*this); |
1461 symbol->function_block_body->accept(*this); |
1473 symbol->function_block_body->accept(*this); |
1462 delete search_var_instance_decl; |
1474 delete search_var_instance_decl; |
1463 search_var_instance_decl = NULL; |
1475 search_var_instance_decl = NULL; |
1464 |
1476 |
|
1477 current_scope = NULL; |
1465 local_enumerated_value_symtable.reset(); |
1478 local_enumerated_value_symtable.reset(); |
1466 return NULL; |
1479 return NULL; |
1467 } |
1480 } |
1468 |
1481 |
1469 /********************************************/ |
1482 /********************************************/ |