stage4/generate_c/generate_c_vardecl.cc
changeset 998 694127983aa4
parent 971 8aee27d46208
child 1035 0a58b2720976
equal deleted inserted replaced
996:c752b113237b 998:694127983aa4
   907     symbol_c *current_var_init_symbol;
   907     symbol_c *current_var_init_symbol;
   908     void update_type_init(symbol_c *symbol /* a spec_init_c, subrange_spec_init_c, etc... */ ) {
   908     void update_type_init(symbol_c *symbol /* a spec_init_c, subrange_spec_init_c, etc... */ ) {
   909       this->current_var_type_symbol = spec_init_sperator_c::get_spec(symbol);
   909       this->current_var_type_symbol = spec_init_sperator_c::get_spec(symbol);
   910       this->current_var_init_symbol = spec_init_sperator_c::get_init(symbol);
   910       this->current_var_init_symbol = spec_init_sperator_c::get_init(symbol);
   911       if (NULL == this->current_var_type_symbol) ERROR;
   911       if (NULL == this->current_var_type_symbol) ERROR;
   912       if (NULL == this->current_var_type_symbol->datatype) {debug_c::print(this->current_var_type_symbol); ERROR;}
       
   913       if (get_datatype_info_c::is_array(this->current_var_type_symbol))
       
   914         this->current_var_type_symbol = this->current_var_type_symbol->datatype; 
       
   915       if (NULL == this->current_var_type_symbol) ERROR;
       
   916       if (NULL == this->current_var_init_symbol) {
   912       if (NULL == this->current_var_init_symbol) {
   917         /* We try to find the data type's default value... */
   913         /* We try to find the data type's default value... */
   918         this->current_var_init_symbol = type_initial_value_c::get(this->current_var_type_symbol);
   914         this->current_var_init_symbol = type_initial_value_c::get(this->current_var_type_symbol);
   919       /* Note that Function Block 'data types' do not have a default value, so we cannot abort if no default value is found! */
   915       /* Note that Function Block 'data types' do not have a default value, so we cannot abort if no default value is found! */
   920       /*
   916       /*
   921       if (NULL == this->current_var_init_symbol)
   917       if (NULL == this->current_var_init_symbol)
   922         ERROR;
   918         ERROR;
   923       */
   919       */
   924       }
   920       }
       
   921       /* When handling arrays we must make sure that we use the base datatype, since arrays use an aliased name in the C code!
       
   922        *   This is done using a stage4 annotation (on the base datatype class) named "generate_c_annotaton__implicit_type_id"
       
   923        *   Note that we do this only _after_ determining the initial value, since in principle the derived array could have
       
   924        *   a default initial different to the base array datatype!
       
   925        */
       
   926       if (NULL == this->current_var_type_symbol->datatype) {debug_c::print(this->current_var_type_symbol); ERROR;}
       
   927       if (get_datatype_info_c::is_array(this->current_var_type_symbol))
       
   928         this->current_var_type_symbol = this->current_var_type_symbol->datatype; 
       
   929       if (NULL == this->current_var_type_symbol) ERROR;      
   925     }
   930     }
   926 
   931 
   927     void void_type_init(void) {
   932     void void_type_init(void) {
   928       this->current_var_type_symbol = NULL;
   933       this->current_var_type_symbol = NULL;
   929       this->current_var_init_symbol = NULL;
   934       this->current_var_init_symbol = NULL;
  1427    */
  1432    */
  1428 
  1433 
  1429   /* Start off by setting the current_var_type_symbol and
  1434   /* Start off by setting the current_var_type_symbol and
  1430    * current_var_init_symbol private variables...
  1435    * current_var_init_symbol private variables...
  1431    */
  1436    */
  1432   if (NULL == symbol->array_spec_init->datatype) ERROR;
  1437   update_type_init(symbol->array_spec_init);
  1433   update_type_init(symbol->array_spec_init->datatype); // we want to print the name of the base datatype, and nt the derived datatype, so we use '->datatype'!
       
  1434 
  1438 
  1435   /* now to produce the c equivalent... */
  1439   /* now to produce the c equivalent... */
  1436   if (wanted_varformat == constructorinit_vf) {
  1440   if (wanted_varformat == constructorinit_vf) {
  1437     generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
  1441     generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
  1438     array_initialization->set_variable_prefix(get_variable_prefix());
  1442     array_initialization->set_variable_prefix(get_variable_prefix());
  1570    */
  1574    */
  1571 
  1575 
  1572   /* Start off by setting the current_var_type_symbol and
  1576   /* Start off by setting the current_var_type_symbol and
  1573    * current_var_init_symbol private variables...
  1577    * current_var_init_symbol private variables...
  1574    */
  1578    */
  1575   if (symbol->array_specification->datatype == NULL) {debug_c::print(symbol->array_specification); ERROR;}
  1579   update_type_init(symbol->array_specification);
  1576   update_type_init(symbol->array_specification->datatype); // we want to print the name of the base datatype, and nt the derived datatype, so we use '->datatype'!
       
  1577 
  1580 
  1578   /* now to produce the c equivalent... */
  1581   /* now to produce the c equivalent... */
  1579   if (wanted_varformat == constructorinit_vf) {
  1582   if (wanted_varformat == constructorinit_vf) {
  1580     generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
  1583     generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
  1581     array_initialization->set_variable_prefix(get_variable_prefix());
  1584     array_initialization->set_variable_prefix(get_variable_prefix());