stage4/generate_cc/generate_cc_vardecl.cc
changeset 28 5b170c9ce134
parent 26 fd67f54e64e1
child 41 8998c8b24b60
equal deleted inserted replaced
27:667721cf52c5 28:5b170c9ce134
   733       break;
   733       break;
   734 
   734 
   735     case constructorinit_vf:
   735     case constructorinit_vf:
   736       s4o.print(nv->get());
   736       s4o.print(nv->get());
   737       s4o.print("{extern ");
   737       s4o.print("{extern ");
       
   738       this->current_var_type_symbol->accept(*this);
       
   739       s4o.print(" ");
   738       symbol->location->accept(*this);
   740       symbol->location->accept(*this);
   739       s4o.print(";");
   741       s4o.print("; ");
   740       print_variable_prefix();
   742       print_variable_prefix();
   741       if (symbol->variable_name != NULL)
   743       if (symbol->variable_name != NULL)
   742         symbol->variable_name->accept(*this);
   744         symbol->variable_name->accept(*this);
   743       else
   745       else
   744         symbol->location->accept(*this);
   746         symbol->location->accept(*this);
   856       break;
   858       break;
   857 
   859 
   858     case constructorinit_vf:
   860     case constructorinit_vf:
   859       s4o.print(nv->get());
   861       s4o.print(nv->get());
   860       s4o.print("{extern ");
   862       s4o.print("{extern ");
       
   863       this->current_var_type_symbol->accept(*this);
       
   864       s4o.print(" ");
   861       symbol->global_var_name->accept(*this);
   865       symbol->global_var_name->accept(*this);
   862       s4o.print(";");
   866       s4o.print("; ");
   863       print_variable_prefix();
   867       print_variable_prefix();
   864       symbol->global_var_name->accept(*this);
   868       symbol->global_var_name->accept(*this);
   865       s4o.print(" = ");
   869       s4o.print(" = ");
   866       symbol->global_var_name->accept(*this);
   870       symbol->global_var_name->accept(*this);
   867       s4o.print(";}");
   871       s4o.print(";}");
   964        * Nevertheless, this construct never occurs inside a Function Block, but
   968        * Nevertheless, this construct never occurs inside a Function Block, but
   965        * only inside a configuration. In this case, only a single instance will
   969        * only inside a configuration. In this case, only a single instance will
   966        * be created, directly at startup, so it is not necessary that the variables
   970        * be created, directly at startup, so it is not necessary that the variables
   967        * be declared static.
   971        * be declared static.
   968        */
   972        */
   969       s4o.print(s4o.indent_spaces + "__plc_pt_c<");
   973       s4o.print(s4o.indent_spaces);
   970       this->current_var_type_symbol->accept(*this);
   974       if (symbol->global_var_name != NULL) {
   971       s4o.print(", 8*sizeof(");
   975         s4o.print("{extern ");
   972       this->current_var_type_symbol->accept(*this);
   976         this->current_var_type_symbol->accept(*this);
   973       s4o.print(")> ");
   977         s4o.print(" ");
   974       if (symbol->global_var_name != NULL)
   978         symbol->location->accept(*this);
       
   979         s4o.print("; ");
       
   980         this->current_var_type_symbol->accept(*this);
       
   981         s4o.print(" *");
   975         symbol->global_var_name->accept(*this);
   982         symbol->global_var_name->accept(*this);
       
   983         s4o.print(" = &");
       
   984         symbol->location->accept(*this);
       
   985         s4o.print(";}\n");
       
   986       }
       
   987       break;
       
   988 
       
   989     case constructorinit_vf:
       
   990       s4o.print(nv->get());
       
   991       
       
   992       if (symbol->global_var_name != NULL) {
       
   993         s4o.print("*");
       
   994         symbol->global_var_name->accept(*this);
       
   995       }
   976       else
   996       else
   977         symbol->location->accept(*this);
   997         symbol->location->accept(*this);
   978       s4o.print(";\n");
   998       s4o.print(" = ");
   979       break;
       
   980 
       
   981     case constructorinit_vf:
       
   982       s4o.print(nv->get());
       
   983       if (symbol->global_var_name != NULL)
       
   984         symbol->global_var_name->accept(*this);
       
   985       else
       
   986         symbol->location->accept(*this);
       
   987       s4o.print("(\"");
       
   988       symbol->location->accept(*this);
       
   989       s4o.print("\"");
       
   990       if (this->current_var_init_symbol != NULL) {
   999       if (this->current_var_init_symbol != NULL) {
   991         s4o.print(", ");
       
   992         this->current_var_init_symbol->accept(*this);
  1000         this->current_var_init_symbol->accept(*this);
   993       }
  1001       }
   994       s4o.print(")");
  1002       s4o.print(";");
   995       break;
  1003       break;
   996 
  1004 
   997     default:
  1005     default:
   998       ERROR;
  1006       ERROR;
   999   } /* switch() */
  1007   } /* switch() */
  1023   switch (wanted_varformat) {
  1031   switch (wanted_varformat) {
  1024     case local_vf:
  1032     case local_vf:
  1025     case localinit_vf:
  1033     case localinit_vf:
  1026       for(int i = 0; i < list->n; i++) {
  1034       for(int i = 0; i < list->n; i++) {
  1027         s4o.print(s4o.indent_spaces);
  1035         s4o.print(s4o.indent_spaces);
  1028         s4o.print("__ext_element_c<");
       
  1029         this->current_var_type_symbol->accept(*this);
  1036         this->current_var_type_symbol->accept(*this);
  1030         s4o.print("> ");
  1037         s4o.print(" __");
  1031         list->elements[i]->accept(*this);
  1038         list->elements[i]->accept(*this);
       
  1039         s4o.print(";\n");
       
  1040         this->current_var_type_symbol->accept(*this);
       
  1041         s4o.print(" *");
       
  1042         list->elements[i]->accept(*this);
       
  1043         s4o.print(" = &__");
       
  1044         list->elements[i]->accept(*this);
       
  1045 #if 0
  1032         if (wanted_varformat == localinit_vf) {
  1046         if (wanted_varformat == localinit_vf) {
  1033           if (this->current_var_init_symbol != NULL) {
  1047           if (this->current_var_init_symbol != NULL) {
  1034             s4o.print(" = ");
  1048             s4o.print(" = ");
  1035             this->current_var_init_symbol->accept(*this);
  1049             this->current_var_init_symbol->accept(*this);
  1036           }
  1050           }
  1037         }
  1051         }
       
  1052 #endif
  1038         s4o.print(";\n");
  1053         s4o.print(";\n");
  1039       }
  1054       }
  1040       break;
  1055       break;
  1041 
  1056 
  1042     case constructorinit_vf:
  1057     case constructorinit_vf:
  1043       if (this->current_var_init_symbol != NULL) {
  1058       if (this->current_var_init_symbol != NULL) {
  1044         for(int i = 0; i < list->n; i++) {
  1059         for(int i = 0; i < list->n; i++) {
  1045           s4o.print(nv->get());
  1060           s4o.print(nv->get());
  1046 
  1061 
       
  1062           s4o.print("*");
  1047           list->elements[i]->accept(*this);
  1063           list->elements[i]->accept(*this);
  1048           s4o.print("(");
  1064           s4o.print(" = ");
  1049           this->current_var_init_symbol->accept(*this);
  1065           this->current_var_init_symbol->accept(*this);
  1050           s4o.print(")");
  1066           s4o.print(";");
  1051 #if 0
  1067 #if 0
  1052  	  /* The following code would be for globalinit_vf !!
  1068  	  /* The following code would be for globalinit_vf !!
  1053 	   * But it is not currently required...
  1069 	   * But it is not currently required...
  1054 	   */
  1070 	   */
  1055 	  s4o.print(s4o.indent_spaces + "__ext_element_c<");
  1071 	  s4o.print(s4o.indent_spaces + "__ext_element_c<");