90 current_initialization_count = 0; |
90 current_initialization_count = 0; |
91 array_base_type = array_default_value = array_default_initialization = NULL; |
91 array_base_type = array_default_value = array_default_initialization = NULL; |
92 |
92 |
93 current_mode = arraysize_am; |
93 current_mode = arraysize_am; |
94 array_specification->accept(*this); |
94 array_specification->accept(*this); |
|
95 } |
|
96 |
|
97 void set_array_default_initialisation(symbol_c *array_initialization) { |
|
98 array_default_initialization = array_initialization; |
95 } |
99 } |
96 |
100 |
97 void init_array(symbol_c *var1_list, symbol_c *array_specification, symbol_c *array_initialization) { |
101 void init_array(symbol_c *var1_list, symbol_c *array_specification, symbol_c *array_initialization) { |
98 int i; |
102 int i; |
99 |
103 |
419 void *visit(structure_element_declaration_c *symbol) { |
423 void *visit(structure_element_declaration_c *symbol) { |
420 element_count++; |
424 element_count++; |
421 if (next_element == element_count) { |
425 if (next_element == element_count) { |
422 current_element_default_value = spec_init_sperator_c::get_init(symbol->spec_init); |
426 current_element_default_value = spec_init_sperator_c::get_init(symbol->spec_init); |
423 current_element_type = spec_init_sperator_c::get_spec(symbol->spec_init); |
427 current_element_type = spec_init_sperator_c::get_spec(symbol->spec_init); |
|
428 if (current_element_type == NULL) ERROR; |
424 return symbol->structure_element_name; |
429 return symbol->structure_element_name; |
425 } |
430 } |
426 /* not yet the desired element... */ |
431 /* not yet the desired element... */ |
427 return NULL; |
432 return NULL; |
428 } |
433 } |
498 structureinitialization_mode_t current_mode; |
503 structureinitialization_mode_t current_mode; |
499 |
504 |
500 private: |
505 private: |
501 symbol_c* structure_type_decl; |
506 symbol_c* structure_type_decl; |
502 symbol_c* current_element_type; |
507 symbol_c* current_element_type; |
|
508 symbol_c* current_element_default_value; |
503 |
509 |
504 public: |
510 public: |
505 generate_c_structure_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {} |
511 generate_c_structure_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {} |
506 ~generate_c_structure_initialization_c(void) {} |
512 ~generate_c_structure_initialization_c(void) {} |
507 |
513 |
508 void init_structure_default(symbol_c *structure_type_name) { |
514 void init_structure_default(symbol_c *structure_type_name) { |
509 structure_type_decl = NULL; |
515 structure_type_decl = NULL; |
510 current_element_type = NULL; |
516 current_element_type = NULL; |
|
517 current_element_default_value = NULL; |
511 |
518 |
512 current_mode = initdefault_sm; |
519 current_mode = initdefault_sm; |
513 structure_type_name->accept(*this); |
520 structure_type_name->accept(*this); |
514 } |
521 } |
515 |
522 |
602 structure_init_element_iterator_c structure_init_element_iterator(symbol); |
609 structure_init_element_iterator_c structure_init_element_iterator(symbol); |
603 for(int i = 1; (element_name = structure_iterator.next()) != NULL; i++) { |
610 for(int i = 1; (element_name = structure_iterator.next()) != NULL; i++) { |
604 if (i > 1) |
611 if (i > 1) |
605 s4o.print(","); |
612 s4o.print(","); |
606 |
613 |
|
614 current_element_type = structure_iterator.element_type(); |
|
615 if (current_element_type == NULL) ERROR; |
|
616 |
|
617 /* Check whether default value specified in structure declaration...*/ |
|
618 current_element_default_value = structure_iterator.default_value(); |
|
619 |
607 /* Get the value from an initialization */ |
620 /* Get the value from an initialization */ |
608 symbol_c *element_value = structure_init_element_iterator.search(element_name); |
621 symbol_c *element_value = structure_init_element_iterator.search(element_name); |
609 |
622 |
610 if (element_value == NULL) { |
623 if (element_value == NULL) { |
611 /* No value given for parameter, so we must use the default... */ |
624 /* No value given for parameter, so we must use the default... */ |
612 /* First check whether default value specified in function declaration...*/ |
625 element_value = current_element_default_value; |
613 element_value = structure_iterator.default_value(); |
|
614 current_element_type = structure_iterator.element_type(); |
|
615 } |
626 } |
616 |
627 |
617 if (element_value == NULL) { |
628 if (element_value == NULL) { |
618 if (current_element_type == NULL) ERROR; |
|
619 |
|
620 /* If not, get the default value of this variable's type */ |
629 /* If not, get the default value of this variable's type */ |
621 element_value = (symbol_c *)current_element_type->accept(*type_initial_value_c::instance()); |
630 element_value = (symbol_c *)current_element_type->accept(*type_initial_value_c::instance()); |
622 } |
631 } |
623 |
632 |
624 if (element_value == NULL) ERROR; |
633 if (element_value == NULL) ERROR; |
642 /* helper symbol for array_initialization */ |
651 /* helper symbol for array_initialization */ |
643 /* array_initial_elements_list ',' array_initial_elements */ |
652 /* array_initial_elements_list ',' array_initial_elements */ |
644 void *visit(array_initial_elements_list_c *symbol) { |
653 void *visit(array_initial_elements_list_c *symbol) { |
645 generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
654 generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
646 array_initialization->init_array_size(current_element_type); |
655 array_initialization->init_array_size(current_element_type); |
|
656 if (current_element_default_value != NULL) |
|
657 array_initialization->set_array_default_initialisation(current_element_default_value); |
647 array_initialization->init_array_values(symbol); |
658 array_initialization->init_array_values(symbol); |
648 delete array_initialization; |
659 delete array_initialization; |
649 return NULL; |
660 return NULL; |
650 } |
661 } |
651 |
662 |