stage3/constant_folding.cc
changeset 970 0ede7ca157e2
parent 969 706a152731ab
child 973 f86d5d6bb04e
equal deleted inserted replaced
969:706a152731ab 970:0ede7ca157e2
  1043 }
  1043 }
  1044 
  1044 
  1045 void *constant_folding_c::handle_var_list_decl(symbol_c *var_list, symbol_c *type_decl) {
  1045 void *constant_folding_c::handle_var_list_decl(symbol_c *var_list, symbol_c *type_decl) {
  1046   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)
  1046   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)
  1047   symbol_c *init_value = type_initial_value_c::get(type_decl);  
  1047   symbol_c *init_value = type_initial_value_c::get(type_decl);  
  1048   if (NULL == init_value)   {debug_c::print(type_decl); return NULL;} // this is probably a FB datatype, for which no initial value exists! Do nothing and return.
  1048   if (NULL == init_value)   {return NULL;} // this is probably a FB datatype, for which no initial value exists! Do nothing and return.
  1049   init_value->accept(*this); // necessary when handling default initial values, that were not constant folded in the call type_decl->accept(*this)
  1049   init_value->accept(*this); // necessary when handling default initial values, that were not constant folded in the call type_decl->accept(*this)
  1050   
  1050   
  1051   list_c *list = dynamic_cast<list_c *>(var_list);
  1051   list_c *list = dynamic_cast<list_c *>(var_list);
  1052   if (NULL == list) ERROR;
  1052   if (NULL == list) ERROR;
  1053   for (int i = 0; i < list->n; i++) {
  1053   for (int i = 0; i < list->n; i++) {
  1326 	return NULL;
  1326 	return NULL;
  1327 }
  1327 }
  1328 
  1328 
  1329 /*  VAR_TEMP temp_var_decl_list END_VAR */
  1329 /*  VAR_TEMP temp_var_decl_list END_VAR */
  1330 // SYM_REF1(temp_var_decls_c, var_decl_list)
  1330 // SYM_REF1(temp_var_decls_c, var_decl_list)
  1331 void *constant_folding_c::visit(temp_var_decls_c *symbol) {debug_c::print(symbol); return handle_var_decl(symbol->var_decl_list, true);}
  1331 void *constant_folding_c::visit(temp_var_decls_c *symbol) {return handle_var_decl(symbol->var_decl_list, true);}
  1332 
  1332 
  1333 /* intermediate helper symbol for temp_var_decls */
  1333 /* intermediate helper symbol for temp_var_decls */
  1334 // SYM_LIST(temp_var_decls_list_c)
  1334 // SYM_LIST(temp_var_decls_list_c)
  1335 
  1335 
  1336 /*  VAR NON_RETAIN var_init_decl_list END_VAR */
  1336 /*  VAR NON_RETAIN var_init_decl_list END_VAR */
  1337 // SYM_REF1(non_retentive_var_decls_c, var_decl_list)
  1337 // SYM_REF1(non_retentive_var_decls_c, var_decl_list)
  1338 // NOTE: non_retentive_var_decls_c is only used inside FBs and Programs, so it is safe to call with fixed_init_value_ = false 
  1338 // NOTE: non_retentive_var_decls_c is only used inside FBs and Programs, so it is safe to call with fixed_init_value_ = false 
  1339 void *constant_folding_c::visit(non_retentive_var_decls_c *symbol) {debug_c::print(symbol); return handle_var_decl(symbol->var_decl_list, false);}
  1339 void *constant_folding_c::visit(non_retentive_var_decls_c *symbol) {return handle_var_decl(symbol->var_decl_list, false);}
  1340 
  1340 
  1341 
  1341 
  1342 /**********************/
  1342 /**********************/
  1343 /* B 1.5.3 - Programs */
  1343 /* B 1.5.3 - Programs */
  1344 /**********************/
  1344 /**********************/