1414 var_list->accept(*this); |
1414 var_list->accept(*this); |
1415 fixed_init_value_ = false; |
1415 fixed_init_value_ = false; |
1416 return NULL; |
1416 return NULL; |
1417 } |
1417 } |
1418 |
1418 |
|
1419 |
|
1420 #include <algorithm> // std::find |
1419 void *constant_propagation_c::handle_var_list_decl(symbol_c *var_list, symbol_c *type_decl, bool is_global_var) { |
1421 void *constant_propagation_c::handle_var_list_decl(symbol_c *var_list, symbol_c *type_decl, bool is_global_var) { |
1420 type_decl->accept(*this); // Do constant folding of the initial value, and literals in subranges! (we will probably be doing this multiple times for the same init value, but this is safe as the cvalue is idem-potent) |
1422 type_decl->accept(*this); // Do constant folding of the initial value, and literals in subranges! (we will probably be doing this multiple times for the same init value, but this is safe as the cvalue is idem-potent) |
1421 symbol_c *init_value = type_initial_value_c::get(type_decl); |
1423 symbol_c *init_value = type_initial_value_c::get(type_decl); |
1422 |
1424 |
1423 /* There are two main possibilities here: either we are instantiating FBs, or some other variable. |
1425 /* There are two main possibilities here: either we are instantiating FBs, or some other variable. |
1439 // Handle the situation (1) mentioned above, i.e. handle the instantiation of FBs. |
1441 // Handle the situation (1) mentioned above, i.e. handle the instantiation of FBs. |
1440 // ------------------------------------------------------------------------------- |
1442 // ------------------------------------------------------------------------------- |
1441 // Remmeber that in this case we will recursively visit the FB type declaration!! |
1443 // Remmeber that in this case we will recursively visit the FB type declaration!! |
1442 function_block_declaration_c *fb_type = itr->second; |
1444 function_block_declaration_c *fb_type = itr->second; |
1443 if (NULL == fb_type) ERROR; // syntax parsing should not allow this! |
1445 if (NULL == fb_type) ERROR; // syntax parsing should not allow this! |
1444 // TODO: detect whether we are already currently visiting this exact same FB declaration (possible with -p option), so we do not get into an infinite loop!! |
1446 // WARNING: Before calling fb_type->accept(*this), we must first determine whether we are already currently visiting this exact |
1445 fb_type->accept(*this); |
1447 // same FB declaration (possible with -p option), so we do not get into an infinite loop!! |
|
1448 // NOTE: We use the std::find() standard algorithm, since the std::stack and std::deque do not have the find() member function. |
|
1449 // We could alternatively use a std::set instead of std::deque, but then it would not be evident that insertion and deletion |
|
1450 // of fb_types follows a push() and pop() algorithm typical of stacks. |
|
1451 if (std::find(fbs_currently_being_visited.begin(), fbs_currently_being_visited.end(), fb_type) == fbs_currently_being_visited.end()) { |
|
1452 // The fb_type is not in the fbs_currently_being_visited stack, so we push it onto the stack, and then visit it!! |
|
1453 fbs_currently_being_visited.push_back(fb_type); |
|
1454 fb_type->accept(*this); |
|
1455 fbs_currently_being_visited.pop_back(); |
|
1456 } |
1446 return NULL; |
1457 return NULL; |
1447 } |
1458 } |
1448 |
1459 |
1449 // Handle the situation (2) mentioned above, i.e. handle the instantiation of non-FB variables. |
1460 // Handle the situation (2) mentioned above, i.e. handle the instantiation of non-FB variables. |
1450 // -------------------------------------------------------------------------------------------- |
1461 // -------------------------------------------------------------------------------------------- |