stage4/generate_c/generate_c_st.cc
changeset 897 8c3e91c385f5
parent 889 5f380b99e95e
child 909 8b2a31dea131
equal deleted inserted replaced
896:c1cf7259160d 897:8c3e91c385f5
   209     fb_symbol->accept(*this);
   209     fb_symbol->accept(*this);
   210     s4o.print(".,");
   210     s4o.print(".,");
   211     symbol->accept(*this);
   211     symbol->accept(*this);
   212     s4o.print(",");
   212     s4o.print(",");
   213     s4o.print(",");    
   213     s4o.print(",");    
   214   }
   214   } else {
   215   else {
       
   216     print_variable_prefix();
   215     print_variable_prefix();
   217     s4o.print(",");    
   216     s4o.print(",");    
   218     wanted_variablegeneration = complextype_base_vg;
   217     wanted_variablegeneration = complextype_base_vg;
   219     symbol->accept(*this);
   218     symbol->accept(*this);
   220     s4o.print(",");
   219     s4o.print(",");
   332 void *visit(structured_variable_c *symbol) {
   331 void *visit(structured_variable_c *symbol) {
   333   TRACE("structured_variable_c");
   332   TRACE("structured_variable_c");
   334   switch (wanted_variablegeneration) {
   333   switch (wanted_variablegeneration) {
   335     case complextype_base_vg:
   334     case complextype_base_vg:
   336       symbol->record_variable->accept(*this);
   335       symbol->record_variable->accept(*this);
   337       if ( get_datatype_info_c::is_function_block(symbol->record_variable->datatype)) {
   336       /* NOTE: The following test includes a special case for SFC Steps. They are currently mapped onto a C data structure
       
   337        *        that does not follow the standard IEC_<typename> pattern used for user defined structure datatypes 
       
   338        *        (i.e. it does not include the 'values' and 'flag' structure 
       
   339        *        elements that are tested by __GET_VAR and __SET_VAR acessor macros defined in acessor.h). However, the
       
   340        *        STEP.T and STEP.X elements of this step structure are of the IEC_BOOL and IEC_TIME datatypes, and are 
       
   341        *        actually structures that do have the 'value' and 'flags' elements. So, it is safe to say that any  variable
       
   342        *        that is a STEPname is not of a complex type, as its .T and .X elements are and can later be safely accessed
       
   343        *        using the __SET_VAR and __GET_VAR macros.
       
   344        * 
       
   345        *        For the above reason, a STEP must be handled as a FB, i.e. it does NOT contain the 'flags' and 'value' elements!
       
   346        */
       
   347       if (   get_datatype_info_c::is_function_block(symbol->record_variable->datatype)
       
   348           || get_datatype_info_c::is_sfc_step      (symbol->record_variable->datatype)) {
   338         if (NULL == symbol->record_variable->scope) ERROR;
   349         if (NULL == symbol->record_variable->scope) ERROR;
   339         search_var_instance_decl_c search_var_instance_decl(symbol->record_variable->scope);
   350         search_var_instance_decl_c search_var_instance_decl(symbol->record_variable->scope);
   340         if (search_var_instance_decl_c::external_vt == search_var_instance_decl.get_vartype(get_var_name_c::get_last_field(symbol->record_variable)))
   351         if (search_var_instance_decl_c::external_vt == search_var_instance_decl.get_vartype(get_var_name_c::get_last_field(symbol->record_variable)))
   341           s4o.print("->");
   352           s4o.print("->");
   342         else  
   353         else  
   344         symbol->field_selector->accept(*this);
   355         symbol->field_selector->accept(*this);
   345       }
   356       }
   346       break;
   357       break;
   347     case complextype_suffix_vg:
   358     case complextype_suffix_vg:
   348       symbol->record_variable->accept(*this);
   359       symbol->record_variable->accept(*this);
   349       if (!get_datatype_info_c::is_function_block(symbol->record_variable->datatype)) { // if the record variable is not a FB, then it will certainly be a structure!
   360       // the following condition MUST be a negation of the above condition used in the 'case complextype_base_vg:'
       
   361       if (!(   get_datatype_info_c::is_function_block(symbol->record_variable->datatype)     // if the record variable is not a FB... 
       
   362             || get_datatype_info_c::is_sfc_step      (symbol->record_variable->datatype))) { // ...nor an SFC step name, then it will certainly be a structure!
   350         s4o.print(".");
   363         s4o.print(".");
   351         symbol->field_selector->accept(*this);
   364         symbol->field_selector->accept(*this);
   352       }
   365       }
   353       break;
   366       break;
   354     default:
   367     default: