stage4/generate_c/generate_c_vardecl.cc
changeset 145 72ae82e65dbc
parent 138 8b32fd4d0194
child 146 eef5e62048c7
equal deleted inserted replaced
144:0ee0055a8ffe 145:72ae82e65dbc
   399      *
   399      *
   400      *                e.g.
   400      *                e.g.
   401      *                __plc_pt_c<INT, 8*sizeof(INT)> START_P::loc = __plc_pt_c<INT, 8*sizeof(INT)>("I2");
   401      *                __plc_pt_c<INT, 8*sizeof(INT)> START_P::loc = __plc_pt_c<INT, 8*sizeof(INT)>("I2");
   402      */
   402      */
   403     typedef enum {finterface_vf,
   403     typedef enum {finterface_vf,
   404                     local_vf,
   404                   foutputdecl_vf,
   405 		    localinit_vf,
   405                   foutputassign_vf,
   406 		    init_vf,
   406                   local_vf,
   407 		    constructorinit_vf,
   407 		              localinit_vf,
   408 		    globalinit_vf
   408 		              init_vf,
   409 		   } varformat_t;
   409 		              constructorinit_vf,
       
   410 		              globalinit_vf
       
   411 		             } varformat_t;
   410 
   412 
   411 
   413 
   412   private:
   414   private:
   413     generate_c_array_initialization_c *generate_c_array_initialization;
   415     generate_c_array_initialization_c *generate_c_array_initialization;
   414     
   416     
   511           finterface_var_count++;
   513           finterface_var_count++;
   512           s4o.print(nv->get());
   514           s4o.print(nv->get());
   513           s4o.print("\n" + s4o.indent_spaces);
   515           s4o.print("\n" + s4o.indent_spaces);
   514           this->current_var_type_symbol->accept(*this);
   516           this->current_var_type_symbol->accept(*this);
   515           if ((current_vartype & (output_vt | inoutput_vt)) != 0)
   517           if ((current_vartype & (output_vt | inoutput_vt)) != 0)
   516             s4o.print(" &");
   518             s4o.print(" *__");
   517           else
   519           else
   518             s4o.print(" ");
   520             s4o.print(" ");
   519           list->elements[i]->accept(*this);
   521           list->elements[i]->accept(*this);
   520           /* We do not print the initial value at function declaration!
   522           /* We do not print the initial value at function declaration!
   521            * It is up to the caller to pass the correct default value
   523            * It is up to the caller to pass the correct default value
   522            * if none is specified in the ST source code
   524            * if none is specified in the ST source code
   523            */
   525            */
   524           /* if (this->current_var_init_symbol != NULL) {
   526           /* if (this->current_var_init_symbol != NULL) {
   525                s4o.print(" = "); this->current_var_init_symbol->accept(*this);}
   527                s4o.print(" = "); this->current_var_init_symbol->accept(*this);}
   526            */
   528            */
       
   529         }
       
   530       }
       
   531 
       
   532       if (wanted_varformat == foutputdecl_vf) {
       
   533         for(int i = 0; i < list->n; i++) {
       
   534           if ((current_vartype & (output_vt | inoutput_vt)) != 0) {
       
   535             s4o.print(s4o.indent_spaces);
       
   536             this->current_var_type_symbol->accept(*this);
       
   537             s4o.print(" ");
       
   538             list->elements[i]->accept(*this);
       
   539             s4o.print(";\n");
       
   540           }
       
   541         }
       
   542       }
       
   543 
       
   544       if (wanted_varformat == foutputassign_vf) {
       
   545         for(int i = 0; i < list->n; i++) {
       
   546           if ((current_vartype & (output_vt | inoutput_vt)) != 0) {
       
   547             s4o.print(s4o.indent_spaces + "if (__");
       
   548             list->elements[i]->accept(*this);
       
   549             s4o.print(" != NULL) {\n");
       
   550             s4o.indent_right();
       
   551             s4o.print(s4o.indent_spaces + "*__");
       
   552             list->elements[i]->accept(*this);
       
   553             s4o.print(" = ");
       
   554             list->elements[i]->accept(*this);
       
   555             s4o.print(";\n");
       
   556             s4o.indent_left();
       
   557             s4o.print(s4o.indent_spaces + "}\n");
       
   558           }
   527         }
   559         }
   528       }
   560       }
   529 
   561 
   530       if (wanted_varformat == constructorinit_vf) {
   562       if (wanted_varformat == constructorinit_vf) {
   531         for(int i = 0; i < list->n; i++) {
   563         for(int i = 0; i < list->n; i++) {