stage4/generate_c/generate_c_vardecl.cc
changeset 793 268bf4ca5fa1
parent 762 a3d917474ae4
parent 706 31553c22f318
child 805 b737cfc92614
equal deleted inserted replaced
785:b08167f156a1 793:268bf4ca5fa1
    24 
    24 
    25 #include <limits>  // required for std::numeric_limits<XXX>
    25 #include <limits>  // required for std::numeric_limits<XXX>
    26 
    26 
    27 class initialization_analyzer_c: public null_visitor_c {
    27 class initialization_analyzer_c: public null_visitor_c {
    28   public:
    28   public:
    29 	typedef enum {
    29     typedef enum {
    30 	  simple_it,
    30       simple_it,
    31 	  array_it,
    31       array_it,
    32 	  struct_it
    32       struct_it
    33 	} initialization_type_t;
    33     } initialization_type_t;
    34 
    34 
    35   private:
    35   private:
    36 
    36 
    37 	initialization_type_t current_type;
    37     initialization_type_t current_type;
    38 
    38 
    39   public:
    39   public:
    40 	initialization_analyzer_c(symbol_c* symbol) {
    40     initialization_analyzer_c(symbol_c* symbol) {
    41 	  current_type = simple_it;
    41       current_type = simple_it;
    42       symbol->accept(*this);
    42       symbol->accept(*this);
    43 	}
    43     }
    44 	~initialization_analyzer_c(void) {}
    44     ~initialization_analyzer_c(void) {}
    45 
    45 
    46 	initialization_type_t get_initialization_type(void) {
    46     initialization_type_t get_initialization_type(void) {
    47 	  return current_type;
    47       return current_type;
    48 	}
    48     }
    49 
    49 
    50 	void *visit(array_initial_elements_list_c *symbol) {
    50     void *visit(array_initial_elements_list_c *symbol) {
    51       current_type = array_it;
    51       current_type = array_it;
    52       return NULL;
    52       return NULL;
    53 	}
    53     }
    54 
    54 
    55     void *visit(structure_element_initialization_list_c *symbol) {
    55     void *visit(structure_element_initialization_list_c *symbol) {
    56       current_type = struct_it;
    56       current_type = struct_it;
    57       return NULL;
    57       return NULL;
    58     }
    58     }
    90       current_initialization_count = 0;
    90       current_initialization_count = 0;
    91       array_base_type = array_default_value = array_default_initialization = NULL;
    91       array_base_type = array_default_value = array_default_initialization = NULL;
    92       
    92       
    93       current_mode = arraysize_am;
    93       current_mode = arraysize_am;
    94       array_specification->accept(*this);
    94       array_specification->accept(*this);
       
    95     }
       
    96 
       
    97     void set_array_default_initialisation(symbol_c *array_initialization) {
       
    98       array_default_initialization = array_initialization;
    95     }
    99     }
    96 
   100 
    97     void init_array(symbol_c *var1_list, symbol_c *array_specification, symbol_c *array_initialization) {
   101     void init_array(symbol_c *var1_list, symbol_c *array_specification, symbol_c *array_initialization) {
    98       int i;
   102       int i;
    99       
   103       
   248             }
   252             }
   249             else {
   253             else {
   250               array_initial_elements_c *array_initial_element = dynamic_cast<array_initial_elements_c *>(symbol->elements[i]);
   254               array_initial_elements_c *array_initial_element = dynamic_cast<array_initial_elements_c *>(symbol->elements[i]);
   251             
   255             
   252               if (array_initial_element != NULL) {
   256               if (array_initial_element != NULL) {
   253             	  symbol->elements[i]->accept(*this);
   257                 symbol->elements[i]->accept(*this);
   254               }
   258               }
   255             }
   259             }
   256             current_initialization_count++;
   260             current_initialization_count++;
   257           }
   261           }
   258           break;
   262           break;
   267     void *visit(array_initial_elements_c *symbol) {
   271     void *visit(array_initial_elements_c *symbol) {
   268       unsigned long long int initial_element_count;
   272       unsigned long long int initial_element_count;
   269  
   273  
   270       /* This code assumes that unsigned long long int is >= uint64_t */
   274       /* This code assumes that unsigned long long int is >= uint64_t */
   271       if (std::numeric_limits< uint64_t >::max() > std::numeric_limits< unsigned long long int >::max()) 
   275       if (std::numeric_limits< uint64_t >::max() > std::numeric_limits< unsigned long long int >::max()) 
   272 	ERROR_MSG("Assertion (sizeof(uint64_t) > sizeof(unsigned long long int)) failed! Compiler cannot execute correctly on the current platform!");
   276         ERROR_MSG("Assertion (sizeof(uint64_t) > sizeof(unsigned long long int)) failed! Compiler cannot execute correctly on the current platform!");
   273       
   277       
   274       switch (current_mode) {
   278       switch (current_mode) {
   275         case initializationvalue_am:
   279         case initializationvalue_am:
   276           if      (VALID_CVALUE( int64, symbol->integer) && (GET_CVALUE( int64, symbol->integer) >= 0))
   280           if      (VALID_CVALUE( int64, symbol->integer) && (GET_CVALUE( int64, symbol->integer) >= 0))
   277             initial_element_count = GET_CVALUE( int64, symbol->integer);
   281             initial_element_count = GET_CVALUE( int64, symbol->integer);
   419     void *visit(structure_element_declaration_c *symbol) {
   423     void *visit(structure_element_declaration_c *symbol) {
   420       element_count++;
   424       element_count++;
   421       if (next_element == element_count) {
   425       if (next_element == element_count) {
   422         current_element_default_value = spec_init_sperator_c::get_init(symbol->spec_init);
   426         current_element_default_value = spec_init_sperator_c::get_init(symbol->spec_init);
   423         current_element_type = spec_init_sperator_c::get_spec(symbol->spec_init);
   427         current_element_type = spec_init_sperator_c::get_spec(symbol->spec_init);
       
   428         if (current_element_type == NULL) ERROR;
   424         return symbol->structure_element_name;
   429         return symbol->structure_element_name;
   425       }
   430       }
   426       /* not yet the desired element... */
   431       /* not yet the desired element... */
   427       return NULL;
   432       return NULL;
   428     }
   433     }
   498     structureinitialization_mode_t current_mode;
   503     structureinitialization_mode_t current_mode;
   499     
   504     
   500   private:
   505   private:
   501     symbol_c* structure_type_decl;
   506     symbol_c* structure_type_decl;
   502     symbol_c* current_element_type;
   507     symbol_c* current_element_type;
       
   508     symbol_c* current_element_default_value;
   503 
   509 
   504   public:
   510   public:
   505     generate_c_structure_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {}
   511     generate_c_structure_initialization_c(stage4out_c *s4o_ptr): generate_c_typedecl_c(s4o_ptr) {}
   506     ~generate_c_structure_initialization_c(void) {}
   512     ~generate_c_structure_initialization_c(void) {}
   507 
   513 
   508     void init_structure_default(symbol_c *structure_type_name) {
   514     void init_structure_default(symbol_c *structure_type_name) {
   509       structure_type_decl = NULL;
   515       structure_type_decl = NULL;
   510       current_element_type = NULL;
   516       current_element_type = NULL;
       
   517       current_element_default_value = NULL;
   511       
   518       
   512       current_mode = initdefault_sm;
   519       current_mode = initdefault_sm;
   513       structure_type_name->accept(*this);
   520       structure_type_name->accept(*this);
   514     }
   521     }
   515 
   522 
   602       structure_init_element_iterator_c structure_init_element_iterator(symbol);
   609       structure_init_element_iterator_c structure_init_element_iterator(symbol);
   603       for(int i = 1; (element_name = structure_iterator.next()) != NULL; i++) {
   610       for(int i = 1; (element_name = structure_iterator.next()) != NULL; i++) {
   604         if (i > 1)
   611         if (i > 1)
   605           s4o.print(",");
   612           s4o.print(",");
   606         
   613         
       
   614         current_element_type = structure_iterator.element_type();
       
   615         if (current_element_type == NULL) ERROR;
       
   616 
       
   617         /* Check whether default value specified in structure declaration...*/
       
   618         current_element_default_value = structure_iterator.default_value();
       
   619 
   607         /* Get the value from an initialization */
   620         /* Get the value from an initialization */
   608         symbol_c *element_value = structure_init_element_iterator.search(element_name);
   621         symbol_c *element_value = structure_init_element_iterator.search(element_name);
   609         
   622         
   610         if (element_value == NULL) {
   623         if (element_value == NULL) {
   611           /* No value given for parameter, so we must use the default... */
   624           /* No value given for parameter, so we must use the default... */
   612           /* First check whether default value specified in function declaration...*/
   625           element_value = current_element_default_value;
   613           element_value = structure_iterator.default_value();
       
   614           current_element_type = structure_iterator.element_type();
       
   615         }
   626         }
   616         
   627         
   617         if (element_value == NULL) {
   628         if (element_value == NULL) {
   618           if (current_element_type == NULL) ERROR;
       
   619           
       
   620           /* If not, get the default value of this variable's type */
   629           /* If not, get the default value of this variable's type */
   621           element_value = type_initial_value_c::get(current_element_type);
   630           element_value = type_initial_value_c::get(current_element_type);
   622         }
   631         }
   623         
   632         
   624         if (element_value == NULL) ERROR;
   633         if (element_value == NULL) ERROR;
   642     /* helper symbol for array_initialization */
   651     /* helper symbol for array_initialization */
   643     /* array_initial_elements_list ',' array_initial_elements */
   652     /* array_initial_elements_list ',' array_initial_elements */
   644     void *visit(array_initial_elements_list_c *symbol) {
   653     void *visit(array_initial_elements_list_c *symbol) {
   645       generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
   654       generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
   646       array_initialization->init_array_size(current_element_type);
   655       array_initialization->init_array_size(current_element_type);
       
   656       if (current_element_default_value != NULL)
       
   657         array_initialization->set_array_default_initialisation(current_element_default_value);
   647       array_initialization->init_array_values(symbol);
   658       array_initialization->init_array_values(symbol);
   648       delete array_initialization;
   659       delete array_initialization;
   649       return NULL;
   660       return NULL;
   650     }
   661     }
   651 
   662 
   898      * declared.
   909      * declared.
   899      */
   910      */
   900     symbol_c *globalnamespace;
   911     symbol_c *globalnamespace;
   901 
   912 
   902     void *print_retain(void) {
   913     void *print_retain(void) {
   903 	  s4o.print(",");
   914       s4o.print(",");
   904       switch (current_varqualifier) {
   915       switch (current_varqualifier) {
   905 		case retain_vq:
   916         case retain_vq:
   906           s4o.print("1");
   917           s4o.print("1");
   907           break;
   918           break;
   908         case non_retain_vq:
   919         case non_retain_vq:
   909           s4o.print("0");
   920           s4o.print("0");
   910           break;
   921           break;
   911 		default:
   922         default:
   912 		  s4o.print("retain");
   923           s4o.print("retain");
   913 		  break;
   924           break;
   914       }
   925       }
   915       return NULL;
   926       return NULL;
   916     }
   927     }
   917 
   928 
   918     /* Actually produce the output where variables are declared... */
   929     /* Actually produce the output where variables are declared... */
   930           (wanted_varformat == init_vf) ||
   941           (wanted_varformat == init_vf) ||
   931           (wanted_varformat == localinit_vf)) {
   942           (wanted_varformat == localinit_vf)) {
   932         for(int i = 0; i < list->n; i++) {
   943         for(int i = 0; i < list->n; i++) {
   933           s4o.print(s4o.indent_spaces);
   944           s4o.print(s4o.indent_spaces);
   934           if (wanted_varformat == local_vf) {
   945           if (wanted_varformat == local_vf) {
   935         	if (!is_fb) {
   946             if (!is_fb) {
   936         	  s4o.print(DECLARE_VAR);
   947               s4o.print(DECLARE_VAR);
   937         	  s4o.print("(");
   948               s4o.print("(");
   938         	}
   949             }
   939         	this->current_var_type_symbol->accept(*this);
   950             this->current_var_type_symbol->accept(*this);
   940         	if (is_fb)
   951             if (is_fb)
   941         	  s4o.print(" ");
   952               s4o.print(" ");
   942         	else
   953             else
   943         	  s4o.print(",");
   954               s4o.print(",");
   944         	print_variable_prefix();
   955             print_variable_prefix();
   945           }
   956           }
   946           else if (wanted_varformat == localinit_vf) {
   957           else if (wanted_varformat == localinit_vf) {
   947         	this->current_var_type_symbol->accept(*this);
   958             this->current_var_type_symbol->accept(*this);
   948             s4o.print(" ");
   959             s4o.print(" ");
   949             print_variable_prefix();
   960             print_variable_prefix();
   950           }
   961           }
   951           else if (wanted_varformat == init_vf) {
   962           else if (wanted_varformat == init_vf) {
   952         	s4o.print(SET_VAR);
   963             s4o.print(SET_VAR);
   953         	s4o.print("(");
   964             s4o.print("(");
   954         	print_variable_prefix();
   965             print_variable_prefix();
   955         	s4o.print(",");
   966             s4o.print(",");
   956           }
   967           }
   957           list->elements[i]->accept(*this);
   968           list->elements[i]->accept(*this);
   958           if (wanted_varformat != local_vf) {
   969           if (wanted_varformat != local_vf) {
   959         	if (wanted_varformat == localinit_vf &&
   970             if (wanted_varformat == localinit_vf &&
   960         		(current_vartype & inoutput_vt) != 0) {
   971                 (current_vartype & inoutput_vt) != 0) {
   961               s4o.print(";\n");
   972               s4o.print(";\n");
   962               s4o.print(s4o.indent_spaces);
   973               s4o.print(s4o.indent_spaces);
   963               s4o.print("if (__");
   974               s4o.print("if (__");
   964               list->elements[i]->accept(*this);
   975               list->elements[i]->accept(*this);
   965               s4o.print(" != NULL) {\n");
   976               s4o.print(" != NULL) {\n");
   986               s4o.print(" = temp;\n");
   997               s4o.print(" = temp;\n");
   987               s4o.indent_left();
   998               s4o.indent_left();
   988               s4o.print(s4o.indent_spaces);
   999               s4o.print(s4o.indent_spaces);
   989               s4o.print("}\n");
  1000               s4o.print("}\n");
   990             }
  1001             }
   991         	else if (wanted_varformat == init_vf) {
  1002             else if (wanted_varformat == init_vf) {
   992         	  s4o.print(",");
  1003               s4o.print(",");
   993         	  this->current_var_init_symbol->accept(*this);
  1004               this->current_var_init_symbol->accept(*this);
   994         	  s4o.print(");\n");
  1005               s4o.print(");\n");
   995         	}
  1006             }
   996         	else {
  1007             else {
   997         	  if (this->current_var_init_symbol != NULL) {
  1008               if (this->current_var_init_symbol != NULL) {
   998                 s4o.print(" = ");
  1009                 s4o.print(" = ");
   999                 this->current_var_init_symbol->accept(*this);
  1010                 this->current_var_init_symbol->accept(*this);
  1000               }
  1011               }
  1001               s4o.print(";\n");
  1012               s4o.print(";\n");
  1002             }
  1013             }
  1003           }
  1014           }
  1004           else if (is_fb)
  1015           else if (is_fb)
  1005         	s4o.print(";\n");
  1016             s4o.print(";\n");
  1006           else
  1017           else
  1007             s4o.print(")\n");
  1018             s4o.print(")\n");
  1008         }
  1019         }
  1009       }
  1020       }
  1010 
  1021 
  1264     if ((wanted_varformat == local_vf) ||
  1275     if ((wanted_varformat == local_vf) ||
  1265         (wanted_varformat == init_vf) ||
  1276         (wanted_varformat == init_vf) ||
  1266         (wanted_varformat == localinit_vf)) {
  1277         (wanted_varformat == localinit_vf)) {
  1267       s4o.print(s4o.indent_spaces);
  1278       s4o.print(s4o.indent_spaces);
  1268       if (wanted_varformat == local_vf) {
  1279       if (wanted_varformat == local_vf) {
  1269     	s4o.print(DECLARE_VAR);
  1280         s4o.print(DECLARE_VAR);
  1270     	s4o.print("(");
  1281         s4o.print("(");
  1271     	symbol->type->accept(*this);
  1282         symbol->type->accept(*this);
  1272         s4o.print(",");
  1283         s4o.print(",");
  1273       }
  1284       }
  1274       else if (wanted_varformat == localinit_vf) {
  1285       else if (wanted_varformat == localinit_vf) {
  1275         symbol->type->accept(*this);
  1286         symbol->type->accept(*this);
  1276         s4o.print(" ");
  1287         s4o.print(" ");
  1277       }
  1288       }
  1278       print_variable_prefix();
  1289       print_variable_prefix();
  1279       symbol->name->accept(*this);
  1290       symbol->name->accept(*this);
  1280       if (wanted_varformat == local_vf)
  1291       if (wanted_varformat == local_vf)
  1281     	s4o.print(")\n");
  1292         s4o.print(")\n");
  1282       else {
  1293       else {
  1283         s4o.print(" = ");
  1294         s4o.print(" = ");
  1284         symbol->value->accept(*this);
  1295         symbol->value->accept(*this);
  1285         s4o.print(";\n");
  1296         s4o.print(";\n");
  1286       }
  1297       }
  1322     if ((wanted_varformat == local_vf) ||
  1333     if ((wanted_varformat == local_vf) ||
  1323         (wanted_varformat == init_vf) ||
  1334         (wanted_varformat == init_vf) ||
  1324         (wanted_varformat == localinit_vf)) {
  1335         (wanted_varformat == localinit_vf)) {
  1325       s4o.print(s4o.indent_spaces);
  1336       s4o.print(s4o.indent_spaces);
  1326       if (wanted_varformat == local_vf) {
  1337       if (wanted_varformat == local_vf) {
  1327     	s4o.print(DECLARE_VAR);
  1338         s4o.print(DECLARE_VAR);
  1328     	s4o.print("(");
  1339         s4o.print("(");
  1329         symbol->type->accept(*this);
  1340         symbol->type->accept(*this);
  1330         s4o.print(",");
  1341         s4o.print(",");
  1331       }
  1342       }
  1332       else if (wanted_varformat == localinit_vf) {
  1343       else if (wanted_varformat == localinit_vf) {
  1333         symbol->type->accept(*this);
  1344         symbol->type->accept(*this);
  1334         s4o.print(" ");
  1345         s4o.print(" ");
  1335       }
  1346       }
  1336       print_variable_prefix();
  1347       print_variable_prefix();
  1337       symbol->name->accept(*this);
  1348       symbol->name->accept(*this);
  1338       if (wanted_varformat == local_vf)
  1349       if (wanted_varformat == local_vf)
  1339     	s4o.print(")\n");
  1350         s4o.print(")\n");
  1340       else
  1351       else
  1341     	s4o.print(" = __BOOL_LITERAL(TRUE);\n");
  1352         s4o.print(" = __BOOL_LITERAL(TRUE);\n");
  1342     }
  1353     }
  1343 
  1354 
  1344     if (wanted_varformat == foutputassign_vf) {
  1355     if (wanted_varformat == foutputassign_vf) {
  1345       s4o.print(s4o.indent_spaces + "if (__");
  1356       s4o.print(s4o.indent_spaces + "if (__");
  1346       symbol->name->accept(*this);
  1357       symbol->name->accept(*this);
  1567   return NULL;
  1578   return NULL;
  1568 }
  1579 }
  1569 
  1580 
  1570 void *visit(array_initial_elements_list_c *symbol) {
  1581 void *visit(array_initial_elements_list_c *symbol) {
  1571   if (wanted_varformat == localinit_vf || wanted_varformat == constructorinit_vf) {
  1582   if (wanted_varformat == localinit_vf || wanted_varformat == constructorinit_vf) {
  1572 	generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
  1583     generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o);
  1573 	array_initialization->init_array_size(this->current_var_type_symbol);
  1584     array_initialization->init_array_size(this->current_var_type_symbol);
  1574 	array_initialization->init_array_values(this->current_var_init_symbol);
  1585     array_initialization->init_array_values(this->current_var_init_symbol);
  1575 	delete array_initialization;
  1586     delete array_initialization;
  1576   }
  1587   }
  1577   return NULL;
  1588   return NULL;
  1578 }
  1589 }
  1579 
  1590 
  1580 /*  var1_list ':' structure_type_name */
  1591 /*  var1_list ':' structure_type_name */
  1612 void *visit(structure_element_initialization_list_c *symbol) {
  1623 void *visit(structure_element_initialization_list_c *symbol) {
  1613   if (wanted_varformat == localinit_vf || wanted_varformat == constructorinit_vf) {
  1624   if (wanted_varformat == localinit_vf || wanted_varformat == constructorinit_vf) {
  1614     generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o);
  1625     generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o);
  1615     structure_initialization->init_structure_default(this->current_var_type_symbol);
  1626     structure_initialization->init_structure_default(this->current_var_type_symbol);
  1616     structure_initialization->init_structure_values(this->current_var_init_symbol);
  1627     structure_initialization->init_structure_values(this->current_var_init_symbol);
  1617 	delete structure_initialization;
  1628     delete structure_initialization;
  1618   }
  1629   }
  1619   return NULL;
  1630   return NULL;
  1620 }
  1631 }
  1621 
  1632 
  1622 /* VAR [CONSTANT] var_init_decl_list END_VAR */
  1633 /* VAR [CONSTANT] var_init_decl_list END_VAR */
  1727       else
  1738       else
  1728         symbol->location->accept(*this);
  1739         symbol->location->accept(*this);
  1729       print_retain();
  1740       print_retain();
  1730       s4o.print(")\n");
  1741       s4o.print(")\n");
  1731       if (this->current_var_init_symbol != NULL) {
  1742       if (this->current_var_init_symbol != NULL) {
  1732     	s4o.print(s4o.indent_spaces);
  1743         s4o.print(s4o.indent_spaces);
  1733     	s4o.print(INIT_LOCATED_VALUE);
  1744         s4o.print(INIT_LOCATED_VALUE);
  1734     	s4o.print("(");
  1745         s4o.print("(");
  1735     	print_variable_prefix();
  1746         print_variable_prefix();
  1736     	if (symbol->variable_name != NULL)
  1747         if (symbol->variable_name != NULL)
  1737           symbol->variable_name->accept(*this);
  1748           symbol->variable_name->accept(*this);
  1738         else
  1749         else
  1739           symbol->location->accept(*this);
  1750           symbol->location->accept(*this);
  1740     	s4o.print(",");
  1751         s4o.print(",");
  1741         this->current_var_init_symbol->accept(*this);
  1752         this->current_var_init_symbol->accept(*this);
  1742         s4o.print(")");
  1753         s4o.print(")");
  1743       }
  1754       }
  1744       break;
  1755       break;
  1745 
  1756 
  1835   /* Start off by setting the current_var_type_symbol and
  1846   /* Start off by setting the current_var_type_symbol and
  1836    * current_var_init_symbol private variables...
  1847    * current_var_init_symbol private variables...
  1837    */
  1848    */
  1838   this->current_var_type_symbol = symbol->specification;
  1849   this->current_var_type_symbol = symbol->specification;
  1839   this->current_var_init_symbol = NULL;
  1850   this->current_var_init_symbol = NULL;
       
  1851   bool is_fb = type_is_fb(this->current_var_type_symbol);
  1840 
  1852 
  1841   /* now to produce the c equivalent... */
  1853   /* now to produce the c equivalent... */
  1842   switch (wanted_varformat) {
  1854   switch (wanted_varformat) {
  1843     case local_vf:
  1855     case local_vf:
  1844     case localinit_vf:
  1856     case localinit_vf:
  1845       s4o.print(s4o.indent_spaces);
  1857       s4o.print(s4o.indent_spaces);
  1846       s4o.print(DECLARE_EXTERNAL);
  1858       if (is_fb)
       
  1859         s4o.print(DECLARE_EXTERNAL_FB);
       
  1860       else
       
  1861         s4o.print(DECLARE_EXTERNAL);
  1847       s4o.print("(");
  1862       s4o.print("(");
  1848       this->current_var_type_symbol->accept(*this);
  1863       this->current_var_type_symbol->accept(*this);
  1849       s4o.print(",");
  1864       s4o.print(",");
  1850       symbol->global_var_name->accept(*this);
  1865       symbol->global_var_name->accept(*this);
  1851       s4o.print(")\n");
  1866       s4o.print(")\n");
  1852       break;
  1867       break;
  1853 
  1868 
  1854     case constructorinit_vf:
  1869     case constructorinit_vf:
  1855       s4o.print(nv->get());
  1870       s4o.print(nv->get());
  1856       s4o.print(INIT_EXTERNAL);
  1871       if (is_fb)
       
  1872         s4o.print(INIT_EXTERNAL_FB);
       
  1873       else
       
  1874         s4o.print(INIT_EXTERNAL);
  1857       s4o.print("(");
  1875       s4o.print("(");
  1858       this->current_var_type_symbol->accept(*this);
  1876       this->current_var_type_symbol->accept(*this);
  1859       s4o.print(",");
  1877       s4o.print(",");
  1860       symbol->global_var_name->accept(*this);
  1878       symbol->global_var_name->accept(*this);
  1861       s4o.print(",");
  1879       s4o.print(",");
  1980       }
  1998       }
  1981       break;
  1999       break;
  1982 
  2000 
  1983     case constructorinit_vf:
  2001     case constructorinit_vf:
  1984       if (symbol->global_var_name != NULL) {
  2002       if (symbol->global_var_name != NULL) {
  1985     	s4o.print(nv->get());
  2003         s4o.print(nv->get());
  1986     	s4o.print(INIT_GLOBAL_LOCATED);
  2004         s4o.print(INIT_GLOBAL_LOCATED);
  1987     	s4o.print("(");
  2005         s4o.print("(");
  1988     	if (this->resource_name != NULL) {
  2006         if (this->resource_name != NULL) {
  1989     	  this->resource_name->accept(*this);
  2007           this->resource_name->accept(*this);
  1990     	}
  2008         }
  1991         s4o.print(",");
  2009         s4o.print(",");
  1992         symbol->global_var_name->accept(*this);
  2010         symbol->global_var_name->accept(*this);
  1993       	s4o.print(",");
  2011         s4o.print(",");
  1994       	symbol->location->accept(*this);
  2012         symbol->location->accept(*this);
  1995         print_retain();
  2013         print_retain();
  1996       	s4o.print(")");
  2014         s4o.print(")");
  1997       }
  2015       }
  1998       if (this->current_var_init_symbol != NULL) {
  2016       if (this->current_var_init_symbol != NULL) {
  1999 	    s4o.print(nv->get());
  2017         s4o.print(nv->get());
  2000 	    s4o.print(INIT_GLOBAL);
  2018         s4o.print(INIT_GLOBAL);
  2001 	    s4o.print("(");
  2019         s4o.print("(");
  2002 	    this->current_var_type_symbol->accept(*this);
  2020         this->current_var_type_symbol->accept(*this);
  2003 	    s4o.print(",");
  2021         s4o.print(",");
  2004 	    if (symbol->global_var_name != NULL)
  2022         if (symbol->global_var_name != NULL)
  2005 		  symbol->global_var_name->accept(*this);
  2023           symbol->global_var_name->accept(*this);
  2006 	    else
  2024         else
  2007 		  symbol->location->accept(*this);
  2025 	      symbol->location->accept(*this);
  2008 	    s4o.print(",");
  2026         s4o.print(",");
  2009 	    s4o.print(INITIAL_VALUE);
  2027         s4o.print(INITIAL_VALUE);
  2010 	    s4o.print("(");
  2028         s4o.print("(");
  2011 	    this->current_var_init_symbol->accept(*this);
  2029         this->current_var_init_symbol->accept(*this);
  2012 	    s4o.print(")");
  2030         s4o.print(")");
  2013 	    print_retain();
  2031         print_retain();
  2014 	    s4o.print(")");
  2032         s4o.print(")");
  2015       }
  2033       }
  2016       break;
  2034       break;
  2017     
  2035     
  2018     case globalprototype_vf:
  2036     case globalprototype_vf:
  2019       s4o.print(s4o.indent_spaces);
  2037       s4o.print(s4o.indent_spaces);
  2020       s4o.print(DECLARE_GLOBAL_PROTOTYPE);
  2038       s4o.print(DECLARE_GLOBAL_PROTOTYPE);
  2021 	  s4o.print("(");
  2039       s4o.print("(");
  2022 	  this->current_var_type_symbol->accept(*this);
  2040       this->current_var_type_symbol->accept(*this);
  2023 	  s4o.print(",");
  2041       s4o.print(",");
  2024 	  if (symbol->global_var_name != NULL)
  2042       if (symbol->global_var_name != NULL)
  2025 		symbol->global_var_name->accept(*this);
  2043         symbol->global_var_name->accept(*this);
  2026 	  else
  2044       else
  2027 		symbol->location->accept(*this);
  2045         symbol->location->accept(*this);
  2028 	  s4o.print(")\n");
  2046       s4o.print(")\n");
  2029       break;
  2047       break;
  2030     
  2048     
  2031     default:
  2049     default:
  2032       ERROR;
  2050       ERROR;
  2033   } /* switch() */
  2051   } /* switch() */
  2048 /*| global_var_list ',' global_var_name */
  2066 /*| global_var_list ',' global_var_name */
  2049 //SYM_LIST(global_var_list_c)
  2067 //SYM_LIST(global_var_list_c)
  2050 void *visit(global_var_list_c *symbol) {
  2068 void *visit(global_var_list_c *symbol) {
  2051   TRACE("global_var_list_c");
  2069   TRACE("global_var_list_c");
  2052   list_c *list = dynamic_cast<list_c *>(symbol);
  2070   list_c *list = dynamic_cast<list_c *>(symbol);
       
  2071   bool is_fb = type_is_fb(this->current_var_type_symbol);
  2053   /* should NEVER EVER occur!! */
  2072   /* should NEVER EVER occur!! */
  2054   if (list == NULL) ERROR;
  2073   if (list == NULL) ERROR;
  2055 
  2074 
  2056   /* now to produce the c equivalent... */
  2075   /* now to produce the c equivalent... */
  2057   switch (wanted_varformat) {
  2076   switch (wanted_varformat) {
  2058     case local_vf:
  2077     case local_vf:
  2059     case localinit_vf:
  2078     case localinit_vf:
  2060       for(int i = 0; i < list->n; i++) {
  2079       for(int i = 0; i < list->n; i++) {
  2061     	s4o.print(s4o.indent_spaces);
  2080         s4o.print(s4o.indent_spaces);
  2062     	s4o.print(DECLARE_GLOBAL);
  2081         if (is_fb)
  2063     	s4o.print("(");
  2082           s4o.print(DECLARE_GLOBAL_FB);
       
  2083         else
       
  2084           s4o.print(DECLARE_GLOBAL);
       
  2085         s4o.print("(");
  2064         this->current_var_type_symbol->accept(*this);
  2086         this->current_var_type_symbol->accept(*this);
  2065         s4o.print(",");
  2087         s4o.print(",");
  2066         if(this->resource_name != NULL)
  2088         if(this->resource_name != NULL)
  2067             this->resource_name->accept(*this);
  2089             this->resource_name->accept(*this);
  2068         s4o.print(",");
  2090         s4o.print(",");
  2070         s4o.print(")\n");
  2092         s4o.print(")\n");
  2071       }
  2093       }
  2072       break;
  2094       break;
  2073 
  2095 
  2074     case constructorinit_vf:
  2096     case constructorinit_vf:
  2075       if (this->current_var_init_symbol != NULL) {
  2097       if (this->current_var_init_symbol != NULL || is_fb) {
  2076         for(int i = 0; i < list->n; i++) {
  2098         for(int i = 0; i < list->n; i++) {
  2077           s4o.print(nv->get());
  2099           s4o.print(nv->get());
  2078 
  2100 
  2079           s4o.print(INIT_GLOBAL);
  2101           if (is_fb)
       
  2102             s4o.print(INIT_GLOBAL_FB);
       
  2103           else
       
  2104             s4o.print(INIT_GLOBAL);
  2080           s4o.print("(");
  2105           s4o.print("(");
  2081           this->current_var_type_symbol->accept(*this);
  2106           this->current_var_type_symbol->accept(*this);
  2082           s4o.print(",");
  2107           s4o.print(",");
  2083           list->elements[i]->accept(*this);
  2108           list->elements[i]->accept(*this);
  2084           s4o.print(",");
  2109           if (this->current_var_init_symbol != NULL) {
  2085           s4o.print(INITIAL_VALUE);
  2110             s4o.print(",");
  2086           s4o.print("(");
  2111             s4o.print(INITIAL_VALUE);
  2087           this->current_var_init_symbol->accept(*this);
  2112             s4o.print("(");
  2088           s4o.print(")");
  2113             this->current_var_init_symbol->accept(*this);
       
  2114             s4o.print(")");
       
  2115           }
  2089           print_retain();
  2116           print_retain();
  2090           s4o.print(")");
  2117           s4o.print(")");
  2091 #if 0
  2118 #if 0
  2092  	  /* The following code would be for globalinit_vf !!
  2119       /* The following code would be for globalinit_vf !!
  2093 	   * But it is not currently required...
  2120        * But it is not currently required...
  2094 	   */
  2121        */
  2095 	  s4o.print(s4o.indent_spaces + "__ext_element_c<");
  2122       s4o.print(s4o.indent_spaces + "__ext_element_c<");
  2096           this->current_var_type_symbol->accept(*this);
  2123           this->current_var_type_symbol->accept(*this);
  2097           s4o.print("> ");
  2124           s4o.print("> ");
  2098           if (this->globalnamespace != NULL) {
  2125           if (this->globalnamespace != NULL) {
  2099             this->globalnamespace->accept(*this);
  2126             this->globalnamespace->accept(*this);
  2100             s4o.print("::");
  2127             s4o.print("::");
  2106             s4o.print("__ext_element_c<");
  2133             s4o.print("__ext_element_c<");
  2107             this->current_var_type_symbol->accept(*this);
  2134             this->current_var_type_symbol->accept(*this);
  2108             s4o.print(">(");
  2135             s4o.print(">(");
  2109             this->current_var_init_symbol->accept(*this);
  2136             this->current_var_init_symbol->accept(*this);
  2110             s4o.print(")");
  2137             s4o.print(")");
  2111 	  }
  2138       }
  2112           s4o.print(";\n");
  2139           s4o.print(";\n");
  2113 #endif
  2140 #endif
  2114         }
  2141         }
  2115       }
  2142       }
  2116       break;
  2143       break;
  2513         break;
  2540         break;
  2514 
  2541 
  2515       case function_param_iterator_c::direction_extref:
  2542       case function_param_iterator_c::direction_extref:
  2516 #if 0
  2543 #if 0
  2517         if (param_value == NULL)
  2544         if (param_value == NULL)
  2518 	  /* This is illegal in ST and IL languages.
  2545       /* This is illegal in ST and IL languages.
  2519 	   * All variables declared in a VAR_EXTERNAL __must__
  2546        * All variables declared in a VAR_EXTERNAL __must__
  2520 	   * be initialised to reference a specific VAR_GLOBAL variable!!
  2547        * be initialised to reference a specific VAR_GLOBAL variable!!
  2521 	   *
  2548        *
  2522 	   * The semantic checker should have caught this, we check again just the
  2549        * The semantic checker should have caught this, we check again just the
  2523 	   * same (especially since the semantic checker has not yet been written!).
  2550        * same (especially since the semantic checker has not yet been written!).
  2524 	   */
  2551        */
  2525 	  ERROR;
  2552       ERROR;
  2526         s4o.print(nv->get());
  2553         s4o.print(nv->get());
  2527         s4o.print("&");
  2554         s4o.print("&");
  2528         param_value->accept(*this);
  2555         param_value->accept(*this);
  2529 #endif
  2556 #endif
  2530 	break;
  2557     break;
  2531     } /* switch */
  2558     } /* switch */
  2532   } /* for(...) */
  2559   } /* for(...) */
  2533 
  2560 
  2534   // symbol->parameter_assignment->accept(*this);
  2561   // symbol->parameter_assignment->accept(*this);
  2535   s4o.print(")");
  2562   s4o.print(")");