stage4/generate_c/generate_c_vardecl.cc
changeset 217 f5dfadf5de54
parent 202 da1a8186f86f
child 221 c6aed7e5f070
equal deleted inserted replaced
216:136d6ae70745 217:f5dfadf5de54
   886       if ((wanted_varformat == local_vf) ||
   886       if ((wanted_varformat == local_vf) ||
   887           (wanted_varformat == init_vf) ||
   887           (wanted_varformat == init_vf) ||
   888           (wanted_varformat == localinit_vf)) {
   888           (wanted_varformat == localinit_vf)) {
   889         for(int i = 0; i < list->n; i++) {
   889         for(int i = 0; i < list->n; i++) {
   890           s4o.print(s4o.indent_spaces);
   890           s4o.print(s4o.indent_spaces);
   891           if (wanted_varformat != init_vf) {
   891           if (wanted_varformat == local_vf) {
   892             this->current_var_type_symbol->accept(*this);
   892         	s4o.print(DECLARE_VAR);
       
   893         	s4o.print("(");
       
   894         	this->current_var_type_symbol->accept(*this);
       
   895             s4o.print(",");
       
   896           }
       
   897           else if (wanted_varformat == localinit_vf) {
       
   898         	this->current_var_type_symbol->accept(*this);
   893             s4o.print(" ");
   899             s4o.print(" ");
   894           }
   900           }
   895           print_variable_prefix();
   901           print_variable_prefix();
   896           list->elements[i]->accept(*this);
   902           list->elements[i]->accept(*this);
   897           if (wanted_varformat != local_vf) {
   903           if (wanted_varformat != local_vf) {
   898             if (this->current_var_init_symbol != NULL) {
   904             if (this->current_var_init_symbol != NULL) {
   899               s4o.print(" = ");
   905               s4o.print(" = ");
   900               this->current_var_init_symbol->accept(*this);
   906               this->current_var_init_symbol->accept(*this);
   901             }
   907             }
       
   908             s4o.print(";\n");
   902           }
   909           }
   903           s4o.print(";\n");
   910           else
       
   911         	s4o.print(")\n");
   904         }
   912         }
   905       }
   913       }
   906 
   914 
   907       if (wanted_varformat == finterface_vf) {
   915       if (wanted_varformat == finterface_vf) {
   908         for(int i = 0; i < list->n; i++) {
   916         for(int i = 0; i < list->n; i++) {
   954             list->elements[i]->accept(*this);
   962             list->elements[i]->accept(*this);
   955             s4o.print(");");
   963             s4o.print(");");
   956           }
   964           }
   957           else if (this->current_var_init_symbol != NULL) {
   965           else if (this->current_var_init_symbol != NULL) {
   958             s4o.print(nv->get());
   966             s4o.print(nv->get());
       
   967             s4o.print(INIT_VAR);
       
   968             s4o.print("(");
   959             this->print_variable_prefix();
   969             this->print_variable_prefix();
   960             list->elements[i]->accept(*this);
   970             list->elements[i]->accept(*this);
   961             s4o.print(" = ");
   971             s4o.print(",");
   962             this->current_var_init_symbol->accept(*this);
   972             this->current_var_init_symbol->accept(*this);
   963             s4o.print(";");
   973             s4o.print(")");
   964           }
   974           }
   965         }
   975         }
   966       }
   976       }
   967 
   977 
   968       return NULL;
   978       return NULL;
  1139 
  1149 
  1140     if ((wanted_varformat == local_vf) ||
  1150     if ((wanted_varformat == local_vf) ||
  1141         (wanted_varformat == init_vf) ||
  1151         (wanted_varformat == init_vf) ||
  1142         (wanted_varformat == localinit_vf)) {
  1152         (wanted_varformat == localinit_vf)) {
  1143       s4o.print(s4o.indent_spaces);
  1153       s4o.print(s4o.indent_spaces);
  1144       if (wanted_varformat != init_vf) {
  1154       if (wanted_varformat == local_vf) {
       
  1155     	s4o.print(DECLARE_VAR);
       
  1156     	s4o.print("(");
       
  1157     	symbol->type->accept(*this);
       
  1158         s4o.print(",");
       
  1159       }
       
  1160       else if (wanted_varformat == localinit_vf) {
  1145         symbol->type->accept(*this);
  1161         symbol->type->accept(*this);
  1146         s4o.print(" ");
  1162         s4o.print(" ");
  1147       }
  1163       }
  1148       print_variable_prefix();
  1164       print_variable_prefix();
  1149       symbol->name->accept(*this);
  1165       symbol->name->accept(*this);
  1150       if (wanted_varformat != local_vf) {
  1166       if (wanted_varformat == local_vf)
       
  1167     	s4o.print(")\n");
       
  1168       else {
  1151         s4o.print(" = ");
  1169         s4o.print(" = ");
  1152         symbol->value->accept(*this);
  1170         symbol->value->accept(*this);
  1153         s4o.print(";");
  1171         s4o.print(";\n");
  1154       }
  1172       }
  1155       s4o.print(";\n");
       
  1156     }
  1173     }
  1157 
  1174 
  1158     if (wanted_varformat == constructorinit_vf) {
  1175     if (wanted_varformat == constructorinit_vf) {
  1159       /* NOTE: I (Mario) think this is dead code - never gets executed. Must confirm it before deleting it... */
  1176       /* NOTE: I (Mario) think this is dead code - never gets executed. Must confirm it before deleting it... */
  1160       s4o.print(nv->get());
  1177       s4o.print(nv->get());
       
  1178       s4o.print(INIT_VAR);
       
  1179       s4o.print("(");
  1161       this->print_variable_prefix();
  1180       this->print_variable_prefix();
  1162       // s4o.print("EN = __BOOL_LITERAL(TRUE);");
  1181       // s4o.print("EN = __BOOL_LITERAL(TRUE);");
  1163       symbol->name->accept(*this);
  1182       symbol->name->accept(*this);
  1164       s4o.print(" = ");
  1183       s4o.print(",");
  1165       symbol->value->accept(*this);
  1184       symbol->value->accept(*this);
  1166       s4o.print(";");
  1185       s4o.print(")");
  1167     }
  1186     }
  1168   }
  1187   }
  1169   return NULL;
  1188   return NULL;
  1170 }
  1189 }
  1171 
  1190 
  1187 
  1206 
  1188     if ((wanted_varformat == local_vf) ||
  1207     if ((wanted_varformat == local_vf) ||
  1189         (wanted_varformat == init_vf) ||
  1208         (wanted_varformat == init_vf) ||
  1190         (wanted_varformat == localinit_vf)) {
  1209         (wanted_varformat == localinit_vf)) {
  1191       s4o.print(s4o.indent_spaces);
  1210       s4o.print(s4o.indent_spaces);
  1192       if (wanted_varformat != init_vf) {
  1211       if (wanted_varformat == local_vf) {
       
  1212     	s4o.print(DECLARE_VAR);
       
  1213     	s4o.print("(");
       
  1214         symbol->type->accept(*this);
       
  1215         s4o.print(",");
       
  1216       }
       
  1217       else if (wanted_varformat == localinit_vf) {
  1193         symbol->type->accept(*this);
  1218         symbol->type->accept(*this);
  1194         s4o.print(" ");
  1219         s4o.print(" ");
  1195       }
  1220       }
  1196       print_variable_prefix();
  1221       print_variable_prefix();
  1197       symbol->name->accept(*this);
  1222       symbol->name->accept(*this);
  1198       if (wanted_varformat != local_vf) {
  1223       if (wanted_varformat == local_vf)
  1199         s4o.print(" = __BOOL_LITERAL(TRUE);");
  1224     	s4o.print(")\n");
  1200       }
  1225       else
  1201       s4o.print(";\n");
  1226     	s4o.print(" = __BOOL_LITERAL(TRUE);\n");
  1202     }
  1227     }
  1203 
  1228 
  1204     if (wanted_varformat == foutputassign_vf) {
  1229     if (wanted_varformat == foutputassign_vf) {
  1205       s4o.print(s4o.indent_spaces + "if (__");
  1230       s4o.print(s4o.indent_spaces + "if (__");
  1206       symbol->name->accept(*this);
  1231       symbol->name->accept(*this);
  1216     }
  1241     }
  1217 
  1242 
  1218     if (wanted_varformat == constructorinit_vf) {
  1243     if (wanted_varformat == constructorinit_vf) {
  1219       /* NOTE: I (Mario) think this is dead code - never gets executed. Must confirm it before deleting it... */
  1244       /* NOTE: I (Mario) think this is dead code - never gets executed. Must confirm it before deleting it... */
  1220       s4o.print(nv->get());
  1245       s4o.print(nv->get());
       
  1246       s4o.print(INIT_VAR);
       
  1247       s4o.print("(");
  1221       this->print_variable_prefix();
  1248       this->print_variable_prefix();
  1222       // s4o.print("ENO = __BOOL_LITERAL(TRUE);");
  1249       // s4o.print("ENO = __BOOL_LITERAL(TRUE);");
  1223       symbol->name->accept(*this);
  1250       symbol->name->accept(*this);
  1224       s4o.print(" = __BOOL_LITERAL(TRUE);");
  1251       s4o.print(",__BOOL_LITERAL(TRUE))");
  1225     }
  1252     }
  1226   }
  1253   }
  1227   return NULL;
  1254   return NULL;
  1228 }
  1255 }
  1229 
  1256 
  1488 
  1515 
  1489   /* now to produce the c equivalent... */
  1516   /* now to produce the c equivalent... */
  1490   switch(wanted_varformat) {
  1517   switch(wanted_varformat) {
  1491     case local_vf:
  1518     case local_vf:
  1492       s4o.print(s4o.indent_spaces);
  1519       s4o.print(s4o.indent_spaces);
       
  1520       s4o.print(DECLARE_LOCATED);
       
  1521       s4o.print("(");
  1493       this->current_var_type_symbol->accept(*this);
  1522       this->current_var_type_symbol->accept(*this);
  1494       s4o.print(" *");
  1523       s4o.print(",");
  1495       if (symbol->variable_name != NULL)
  1524       if (symbol->variable_name != NULL)
  1496         symbol->variable_name->accept(*this);
  1525         symbol->variable_name->accept(*this);
  1497       else
  1526       else
  1498         symbol->location->accept(*this);
  1527         symbol->location->accept(*this);
  1499       s4o.print(";\n");
  1528       s4o.print(")\n");
  1500       break;
  1529       break;
  1501 
  1530 
  1502     case constructorinit_vf:
  1531     case constructorinit_vf:
  1503       s4o.print(nv->get());
  1532       s4o.print(nv->get());
  1504       s4o.print("{extern ");
  1533       s4o.print(INIT_LOCATED);
       
  1534       s4o.print("(");
  1505       this->current_var_type_symbol->accept(*this);
  1535       this->current_var_type_symbol->accept(*this);
  1506       s4o.print("* ");
  1536       s4o.print(",");
  1507       symbol->location->accept(*this);
  1537       symbol->location->accept(*this);
  1508       s4o.print("; ");
  1538       s4o.print(",");
  1509       print_variable_prefix();
       
  1510       if (symbol->variable_name != NULL)
  1539       if (symbol->variable_name != NULL)
  1511         symbol->variable_name->accept(*this);
  1540         symbol->variable_name->accept(*this);
  1512       else
  1541       else
  1513         symbol->location->accept(*this);
  1542         symbol->location->accept(*this);
  1514       s4o.print(" = ");
  1543       s4o.print(",");
  1515       symbol->location->accept(*this);
  1544       print_variable_prefix();
       
  1545       s4o.print(")\n");
  1516       if (this->current_var_init_symbol != NULL) {
  1546       if (this->current_var_init_symbol != NULL) {
  1517         s4o.print("; *");
  1547     	s4o.print(INIT_LOCATED_VALUE);
  1518         print_variable_prefix();
  1548     	s4o.print("(");
  1519         if (symbol->variable_name != NULL)
  1549     	if (symbol->variable_name != NULL)
  1520           symbol->variable_name->accept(*this);
  1550           symbol->variable_name->accept(*this);
  1521         else
  1551         else
  1522           symbol->location->accept(*this);
  1552           symbol->location->accept(*this);
  1523         s4o.print(" = ");
  1553     	s4o.print(",");
  1524         this->current_var_init_symbol->accept(*this);
  1554         this->current_var_init_symbol->accept(*this);
  1525       }
  1555         s4o.print(")\n");
  1526       s4o.print(";}");
  1556       }
  1527       break;
  1557       break;
  1528 
  1558 
  1529     case globalinit_vf:
  1559     case globalinit_vf:
  1530       s4o.print(s4o.indent_spaces + "__plc_pt_c<");
  1560       s4o.print(s4o.indent_spaces + "__plc_pt_c<");
  1531       this->current_var_type_symbol->accept(*this);
  1561       this->current_var_type_symbol->accept(*this);
  1621   /* now to produce the c equivalent... */
  1651   /* now to produce the c equivalent... */
  1622   switch (wanted_varformat) {
  1652   switch (wanted_varformat) {
  1623     case local_vf:
  1653     case local_vf:
  1624     case localinit_vf:
  1654     case localinit_vf:
  1625       s4o.print(s4o.indent_spaces);
  1655       s4o.print(s4o.indent_spaces);
       
  1656       s4o.print(DECLARE_EXTERNAL);
       
  1657       s4o.print("(");
  1626       this->current_var_type_symbol->accept(*this);
  1658       this->current_var_type_symbol->accept(*this);
  1627       s4o.print(" *");
  1659       s4o.print(",");
  1628       symbol->global_var_name->accept(*this);
  1660       symbol->global_var_name->accept(*this);
  1629       if ((wanted_varformat == localinit_vf) &&
  1661       s4o.print(")\n");
  1630           (this->current_var_init_symbol != NULL)) {
       
  1631         s4o.print(" = ");
       
  1632         this->current_var_init_symbol->accept(*this);
       
  1633       }
       
  1634       s4o.print(";\n");
       
  1635       break;
  1662       break;
  1636 
  1663 
  1637     case constructorinit_vf:
  1664     case constructorinit_vf:
  1638       s4o.print(nv->get());
  1665       s4o.print(nv->get());
  1639       s4o.print("{extern ");
  1666       s4o.print(INIT_EXTERNAL);
       
  1667       s4o.print("(");
  1640       this->current_var_type_symbol->accept(*this);
  1668       this->current_var_type_symbol->accept(*this);
  1641       s4o.print(" *");
  1669       s4o.print(",");
  1642       symbol->global_var_name->accept(*this);
  1670       symbol->global_var_name->accept(*this);
  1643       s4o.print("; ");
  1671       s4o.print(",");
  1644       print_variable_prefix();
  1672       print_variable_prefix();
  1645       symbol->global_var_name->accept(*this);
  1673       symbol->global_var_name->accept(*this);
  1646       s4o.print(" = ");
  1674       s4o.print(")");
  1647       symbol->global_var_name->accept(*this);
       
  1648       s4o.print(";}");
       
  1649       break;
  1675       break;
  1650 
  1676 
  1651     case finterface_vf:
  1677     case finterface_vf:
  1652       finterface_var_count++;
  1678       finterface_var_count++;
  1653       s4o.print(nv->get());
  1679       s4o.print(nv->get());
  1736 void *visit(global_var_spec_c *symbol) {
  1762 void *visit(global_var_spec_c *symbol) {
  1737   TRACE("global_var_spec_c");
  1763   TRACE("global_var_spec_c");
  1738   /* now to produce the c equivalent... */
  1764   /* now to produce the c equivalent... */
  1739   switch(wanted_varformat) {
  1765   switch(wanted_varformat) {
  1740     case local_vf:
  1766     case local_vf:
  1741       s4o.print("extern ");
  1767       s4o.print(s4o.indent_spaces);
       
  1768       s4o.print(DECLARE_GLOBAL_LOCATION);
       
  1769       s4o.print("(");
  1742       this->current_var_type_symbol->accept(*this);
  1770       this->current_var_type_symbol->accept(*this);
  1743       s4o.print("* ");
  1771       s4o.print(",");
  1744       symbol->location->accept(*this);
  1772       symbol->location->accept(*this);
  1745       s4o.print(";\n");
  1773       s4o.print(")\n");
  1746       if (symbol->global_var_name != NULL) {
  1774       if (symbol->global_var_name != NULL) {
  1747         s4o.print(s4o.indent_spaces);
  1775         s4o.print(s4o.indent_spaces);
       
  1776         s4o.print(DECLARE_GLOBAL_LOCATED);
       
  1777         s4o.print("(");
  1748         this->current_var_type_symbol->accept(*this);
  1778         this->current_var_type_symbol->accept(*this);
  1749         s4o.print(" *");
  1779         s4o.print(",");
  1750         if (this->resource_name != NULL) {
  1780         if (this->resource_name != NULL) {
  1751             this->resource_name->accept(*this);
  1781             this->resource_name->accept(*this);
  1752             s4o.print("__");
       
  1753         }
  1782         }
       
  1783         s4o.print(",");
  1754         symbol->global_var_name->accept(*this);
  1784         symbol->global_var_name->accept(*this);
  1755         s4o.print(";\n");
  1785         s4o.print(")\n");
  1756         if (this->resource_name != NULL) {
       
  1757             s4o.print(s4o.indent_spaces);
       
  1758             s4o.print("#define ");
       
  1759             symbol->global_var_name->accept(*this);
       
  1760             s4o.print(" ");
       
  1761             this->resource_name->accept(*this);
       
  1762             s4o.print("__");
       
  1763             symbol->global_var_name->accept(*this);
       
  1764             s4o.print("\n");
       
  1765         }
       
  1766       }
  1786       }
  1767       break;
  1787       break;
  1768 
  1788 
  1769     case constructorinit_vf:
  1789     case constructorinit_vf:
  1770       s4o.print(nv->get());
       
  1771       
       
  1772       if (symbol->global_var_name != NULL) {
  1790       if (symbol->global_var_name != NULL) {
       
  1791     	s4o.print(nv->get());
       
  1792     	s4o.print(s4o.indent_spaces);
       
  1793     	s4o.print(INIT_GLOBAL_LOCATED);
       
  1794     	s4o.print("(");
       
  1795     	if (this->resource_name != NULL) {
       
  1796     	  this->resource_name->accept(*this);
       
  1797     	}
       
  1798         s4o.print(",");
  1773         symbol->global_var_name->accept(*this);
  1799         symbol->global_var_name->accept(*this);
  1774       	s4o.print(" = ");
  1800       	s4o.print(",");
  1775       	symbol->location->accept(*this);
  1801       	symbol->location->accept(*this);
  1776       	s4o.print(";");
  1802       	s4o.print(")");
  1777         s4o.print(nv->get());
  1803       }
  1778       	s4o.print("*");
       
  1779         symbol->global_var_name->accept(*this);
       
  1780       }
       
  1781       else
       
  1782         symbol->location->accept(*this);
       
  1783       s4o.print(" = ");
       
  1784       if (this->current_var_init_symbol != NULL) {
  1804       if (this->current_var_init_symbol != NULL) {
  1785         this->current_var_init_symbol->accept(*this);
  1805 	    s4o.print(nv->get());
  1786       }
  1806 	    s4o.print(s4o.indent_spaces);
  1787       s4o.print(";");
  1807 	    s4o.print(INIT_GLOBAL);
       
  1808 	    s4o.print("(");
       
  1809 	    if (symbol->global_var_name != NULL)
       
  1810 		  symbol->global_var_name->accept(*this);
       
  1811 	    else
       
  1812 		  symbol->location->accept(*this);
       
  1813 	    s4o.print(",");
       
  1814 	    this->current_var_init_symbol->accept(*this);
       
  1815 	    s4o.print(")");
       
  1816       }
  1788       break;
  1817       break;
  1789 
  1818 
  1790     default:
  1819     default:
  1791       ERROR;
  1820       ERROR;
  1792   } /* switch() */
  1821   } /* switch() */
  1815   /* now to produce the c equivalent... */
  1844   /* now to produce the c equivalent... */
  1816   switch (wanted_varformat) {
  1845   switch (wanted_varformat) {
  1817     case local_vf:
  1846     case local_vf:
  1818     case localinit_vf:
  1847     case localinit_vf:
  1819       for(int i = 0; i < list->n; i++) {
  1848       for(int i = 0; i < list->n; i++) {
  1820         s4o.print(s4o.indent_spaces);
  1849     	s4o.print(s4o.indent_spaces);
       
  1850     	s4o.print(DECLARE_GLOBAL);
       
  1851     	s4o.print("(");
  1821         this->current_var_type_symbol->accept(*this);
  1852         this->current_var_type_symbol->accept(*this);
  1822         s4o.print(" ");
  1853         s4o.print(",");
  1823         if(this->resource_name != NULL)
  1854         if(this->resource_name != NULL)
  1824             this->resource_name->accept(*this);
  1855             this->resource_name->accept(*this);
  1825         s4o.print("__");
  1856         s4o.print(",");
  1826         list->elements[i]->accept(*this);
  1857         list->elements[i]->accept(*this);
  1827         s4o.print(";\n");
  1858         s4o.print(")\n");
  1828         if(this->resource_name != NULL)
       
  1829             s4o.print("static ");
       
  1830         this->current_var_type_symbol->accept(*this);
       
  1831         s4o.print(" *");
       
  1832         list->elements[i]->accept(*this);
       
  1833         s4o.print(" = &");
       
  1834         if(this->resource_name != NULL)
       
  1835             this->resource_name->accept(*this);
       
  1836         s4o.print("__");
       
  1837         list->elements[i]->accept(*this);
       
  1838 #if 0
       
  1839         if (wanted_varformat == localinit_vf) {
       
  1840           if (this->current_var_init_symbol != NULL) {
       
  1841             s4o.print(" = ");
       
  1842             this->current_var_init_symbol->accept(*this);
       
  1843           }
       
  1844         }
       
  1845 #endif
       
  1846         s4o.print(";\n");
       
  1847       }
  1859       }
  1848       break;
  1860       break;
  1849 
  1861 
  1850     case constructorinit_vf:
  1862     case constructorinit_vf:
  1851       if (this->current_var_init_symbol != NULL) {
  1863       if (this->current_var_init_symbol != NULL) {
  1852         for(int i = 0; i < list->n; i++) {
  1864         for(int i = 0; i < list->n; i++) {
  1853           s4o.print(nv->get());
  1865           s4o.print(nv->get());
  1854 
  1866 
  1855           s4o.print("*");
  1867           s4o.print(INIT_GLOBAL);
       
  1868           s4o.print("(");
  1856           list->elements[i]->accept(*this);
  1869           list->elements[i]->accept(*this);
  1857           s4o.print(" = ");
  1870           s4o.print(",");
  1858           this->current_var_init_symbol->accept(*this);
  1871           this->current_var_init_symbol->accept(*this);
  1859           s4o.print(";");
  1872           s4o.print(")");
  1860 #if 0
  1873 #if 0
  1861  	  /* The following code would be for globalinit_vf !!
  1874  	  /* The following code would be for globalinit_vf !!
  1862 	   * But it is not currently required...
  1875 	   * But it is not currently required...
  1863 	   */
  1876 	   */
  1864 	  s4o.print(s4o.indent_spaces + "__ext_element_c<");
  1877 	  s4o.print(s4o.indent_spaces + "__ext_element_c<");