stage4/generate_c/generate_c_st.cc
changeset 897 8c3e91c385f5
parent 889 5f380b99e95e
child 909 8b2a31dea131
--- a/stage4/generate_c/generate_c_st.cc	Sat May 31 12:49:43 2014 +0100
+++ b/stage4/generate_c/generate_c_st.cc	Sat May 31 16:22:57 2014 +0100
@@ -211,8 +211,7 @@
     symbol->accept(*this);
     s4o.print(",");
     s4o.print(",");    
-  }
-  else {
+  } else {
     print_variable_prefix();
     s4o.print(",");    
     wanted_variablegeneration = complextype_base_vg;
@@ -334,7 +333,19 @@
   switch (wanted_variablegeneration) {
     case complextype_base_vg:
       symbol->record_variable->accept(*this);
-      if ( get_datatype_info_c::is_function_block(symbol->record_variable->datatype)) {
+      /* NOTE: The following test includes a special case for SFC Steps. They are currently mapped onto a C data structure
+       *        that does not follow the standard IEC_<typename> pattern used for user defined structure datatypes 
+       *        (i.e. it does not include the 'values' and 'flag' structure 
+       *        elements that are tested by __GET_VAR and __SET_VAR acessor macros defined in acessor.h). However, the
+       *        STEP.T and STEP.X elements of this step structure are of the IEC_BOOL and IEC_TIME datatypes, and are 
+       *        actually structures that do have the 'value' and 'flags' elements. So, it is safe to say that any  variable
+       *        that is a STEPname is not of a complex type, as its .T and .X elements are and can later be safely accessed
+       *        using the __SET_VAR and __GET_VAR macros.
+       * 
+       *        For the above reason, a STEP must be handled as a FB, i.e. it does NOT contain the 'flags' and 'value' elements!
+       */
+      if (   get_datatype_info_c::is_function_block(symbol->record_variable->datatype)
+          || get_datatype_info_c::is_sfc_step      (symbol->record_variable->datatype)) {
         if (NULL == symbol->record_variable->scope) ERROR;
         search_var_instance_decl_c search_var_instance_decl(symbol->record_variable->scope);
         if (search_var_instance_decl_c::external_vt == search_var_instance_decl.get_vartype(get_var_name_c::get_last_field(symbol->record_variable)))
@@ -346,7 +357,9 @@
       break;
     case complextype_suffix_vg:
       symbol->record_variable->accept(*this);
-      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!
+      // the following condition MUST be a negation of the above condition used in the 'case complextype_base_vg:'
+      if (!(   get_datatype_info_c::is_function_block(symbol->record_variable->datatype)     // if the record variable is not a FB... 
+            || get_datatype_info_c::is_sfc_step      (symbol->record_variable->datatype))) { // ...nor an SFC step name, then it will certainly be a structure!
         s4o.print(".");
         symbol->field_selector->accept(*this);
       }