stage4/generate_cc/generate_cc_vardecl.cc
changeset 23 d5b55ac4efe6
parent 17 38754701ac41
child 26 fd67f54e64e1
equal deleted inserted replaced
22:08bcc40be1fa 23:d5b55ac4efe6
   271 
   271 
   272     /* Actually produce the output where variables are declared... */
   272     /* Actually produce the output where variables are declared... */
   273     /* Note that located variables are the exception, they
   273     /* Note that located variables are the exception, they
   274      * being declared in the located_var_decl_c visitor...
   274      * being declared in the located_var_decl_c visitor...
   275      */
   275      */
   276     void *declare_variables(symbol_c *symbol) {
   276     void *declare_variables(symbol_c *symbol, bool is_fb = false) {
   277       list_c *list = dynamic_cast<list_c *>(symbol);
   277       list_c *list = dynamic_cast<list_c *>(symbol);
   278       /* should NEVER EVER occur!! */
   278       /* should NEVER EVER occur!! */
   279       if (list == NULL) ERROR;
   279       if (list == NULL) ERROR;
   280 
   280 
   281       /* now to produce the c equivalent... */
   281       /* now to produce the c equivalent... */
   286           s4o.print(s4o.indent_spaces);
   286           s4o.print(s4o.indent_spaces);
   287           if (wanted_varformat != init_vf) {
   287           if (wanted_varformat != init_vf) {
   288             this->current_var_type_symbol->accept(*this);
   288             this->current_var_type_symbol->accept(*this);
   289             s4o.print(" ");
   289             s4o.print(" ");
   290           }
   290           }
   291           this->print_variable_prefix();
   291           print_variable_prefix();
   292           list->elements[i]->accept(*this);
   292           list->elements[i]->accept(*this);
   293           if (wanted_varformat != local_vf) {
   293           if (wanted_varformat != local_vf) {
   294             if (this->current_var_init_symbol != NULL) {
   294             if (this->current_var_init_symbol != NULL) {
   295               s4o.print(" = ");
   295               s4o.print(" = ");
   296               this->current_var_init_symbol->accept(*this);
   296               this->current_var_init_symbol->accept(*this);
   321         }
   321         }
   322       }
   322       }
   323 
   323 
   324       if (wanted_varformat == constructorinit_vf) {
   324       if (wanted_varformat == constructorinit_vf) {
   325         for(int i = 0; i < list->n; i++) {
   325         for(int i = 0; i < list->n; i++) {
   326           if (this->current_var_init_symbol != NULL) {
   326           if (is_fb) {
   327             s4o.print(nv->get());
   327             s4o.print(nv->get());
       
   328             this->current_var_type_symbol->accept(*this);
       
   329             s4o.print(FB_INIT_SUFFIX);
       
   330             s4o.print("(");
       
   331             this->print_variable_prefix();
   328             list->elements[i]->accept(*this);
   332             list->elements[i]->accept(*this);
   329             s4o.print("(");
   333             s4o.print(");");
       
   334           }
       
   335           else if (this->current_var_init_symbol != NULL) {
       
   336             s4o.print(nv->get());
       
   337             this->print_variable_prefix();
       
   338             list->elements[i]->accept(*this);
       
   339             s4o.print(" = ");
   330             this->current_var_init_symbol->accept(*this);
   340             this->current_var_init_symbol->accept(*this);
   331             s4o.print(")");
   341             s4o.print(";");
   332           }
   342           }
   333         }
   343         }
   334       }
   344       }
   335 
   345 
   336       return NULL;
   346       return NULL;
   360         globalnamespace = scope;
   370         globalnamespace = scope;
   361 
   371 
   362       finterface_var_count = 0;
   372       finterface_var_count = 0;
   363 
   373 
   364       switch (wanted_varformat) {
   374       switch (wanted_varformat) {
   365         case constructorinit_vf: nv = new next_var_c(": ", ", "); break;
   375         case constructorinit_vf: nv = new next_var_c("", "\n"+s4o.indent_spaces); break;
   366         case finterface_vf:      /* fall through... */
   376         case finterface_vf:      /* fall through... */
   367         case localinit_vf:       /* fall through... */
   377         case localinit_vf:       /* fall through... */
   368         case local_vf:           nv = new next_var_c("", ", "); break;
   378         case local_vf:           nv = new next_var_c("", ", "); break;
   369         default:                 nv = NULL;
   379         default:                 nv = NULL;
   370       } /* switch() */
   380       } /* switch() */
   560 }
   570 }
   561 
   571 
   562 /* fb_name_list ',' fb_name */
   572 /* fb_name_list ',' fb_name */
   563 void *visit(fb_name_list_c *symbol) {
   573 void *visit(fb_name_list_c *symbol) {
   564   TRACE("fb_name_list_c");
   574   TRACE("fb_name_list_c");
   565   declare_variables(symbol);
   575   declare_variables(symbol, true);
   566   return NULL;
   576   return NULL;
   567 }
   577 }
   568 
   578 
   569 
   579 
   570 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
   580 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
   828   /* now to produce the c equivalent... */
   838   /* now to produce the c equivalent... */
   829   switch (wanted_varformat) {
   839   switch (wanted_varformat) {
   830     case local_vf:
   840     case local_vf:
   831     case localinit_vf:
   841     case localinit_vf:
   832       s4o.print(s4o.indent_spaces);
   842       s4o.print(s4o.indent_spaces);
   833       s4o.print("__ext_ref_c<");
       
   834       this->current_var_type_symbol->accept(*this);
   843       this->current_var_type_symbol->accept(*this);
   835       s4o.print("> &");
   844       s4o.print(" *");
   836       symbol->global_var_name->accept(*this);
   845       symbol->global_var_name->accept(*this);
   837       if ((wanted_varformat == localinit_vf) &&
   846       if ((wanted_varformat == localinit_vf) &&
   838           (this->current_var_init_symbol != NULL)) {
   847           (this->current_var_init_symbol != NULL)) {
   839         s4o.print(" = ");
   848         s4o.print(" = ");
   840         this->current_var_init_symbol->accept(*this);
   849         this->current_var_init_symbol->accept(*this);
   842       s4o.print(";\n");
   851       s4o.print(";\n");
   843       break;
   852       break;
   844 
   853 
   845     case constructorinit_vf:
   854     case constructorinit_vf:
   846       s4o.print(nv->get());
   855       s4o.print(nv->get());
       
   856       s4o.print("{extern ");
   847       symbol->global_var_name->accept(*this);
   857       symbol->global_var_name->accept(*this);
   848       s4o.print("(*");
   858       s4o.print(";");
       
   859       print_variable_prefix();
   849       symbol->global_var_name->accept(*this);
   860       symbol->global_var_name->accept(*this);
   850       s4o.print(")");
   861       s4o.print(" = &");
       
   862       symbol->global_var_name->accept(*this);
       
   863       s4o.print(";}");
   851       break;
   864       break;
   852 
   865 
   853     case finterface_vf:
   866     case finterface_vf:
   854       finterface_var_count++;
   867       finterface_var_count++;
   855       s4o.print(nv->get());
   868       s4o.print(nv->get());
   856       s4o.print("__ext_ref_c<");
       
   857       this->current_var_type_symbol->accept(*this);
   869       this->current_var_type_symbol->accept(*this);
   858       s4o.print("> *");
   870       s4o.print(" *");
   859       symbol->global_var_name->accept(*this);
   871       symbol->global_var_name->accept(*this);
   860       break;
   872       break;
   861 
   873 
   862     default:
   874     default:
   863       ERROR;
   875       ERROR;
  1438       case function_param_iterator_c::direction_inout:
  1450       case function_param_iterator_c::direction_inout:
  1439         /* ignore them all!! */
  1451         /* ignore them all!! */
  1440         break;
  1452         break;
  1441 
  1453 
  1442       case function_param_iterator_c::direction_extref:
  1454       case function_param_iterator_c::direction_extref:
       
  1455 #if 0
  1443         if (param_value == NULL)
  1456         if (param_value == NULL)
  1444 	  /* This is illegal in ST and IL languages.
  1457 	  /* This is illegal in ST and IL languages.
  1445 	   * All variables declared in a VAR_EXTERNAL __must__
  1458 	   * All variables declared in a VAR_EXTERNAL __must__
  1446 	   * be initialised to reference a specific VAR_GLOBAL variable!!
  1459 	   * be initialised to reference a specific VAR_GLOBAL variable!!
  1447 	   *
  1460 	   *
  1450 	   */
  1463 	   */
  1451 	  ERROR;
  1464 	  ERROR;
  1452         s4o.print(nv->get());
  1465         s4o.print(nv->get());
  1453         s4o.print("&");
  1466         s4o.print("&");
  1454         param_value->accept(*this);
  1467         param_value->accept(*this);
       
  1468 #endif
  1455 	break;
  1469 	break;
  1456 #if 0
  1470 #if 0
  1457         if (param_value == NULL) {
  1471         if (param_value == NULL) {
  1458 	  /* no parameter value given, so we pass a previously declared temporary variable. */
  1472 	  /* no parameter value given, so we pass a previously declared temporary variable. */
  1459           std::string *temp_var_name = temp_var_name_factory.new_name();
  1473           std::string *temp_var_name = temp_var_name_factory.new_name();