stage4/generate_c/generate_c.cc
changeset 958 7474d2cd1d6e
parent 945 477393b00f95
child 965 c9eeb67ba939
equal deleted inserted replaced
957:4489afa5b1c5 958:7474d2cd1d6e
  1612     /* B.1 - Common elements */
  1612     /* B.1 - Common elements */
  1613     /*************************/
  1613     /*************************/
  1614     /*******************************************/
  1614     /*******************************************/
  1615     /* B 1.1 - Letters, digits and identifiers */
  1615     /* B 1.1 - Letters, digits and identifiers */
  1616     /*******************************************/
  1616     /*******************************************/
  1617     
       
  1618     void *visit(identifier_c *symbol) {
  1617     void *visit(identifier_c *symbol) {
  1619         if (configuration_name)
  1618       if (configuration_name)  s4o.print(symbol->value);
  1620           s4o.print(symbol->value);
  1619       else                     generate_c_base_c::visit(symbol);
  1621         else
  1620       return NULL;
  1622           generate_c_base_c::visit(symbol);
       
  1623         return NULL;
       
  1624     }
  1621     }
  1625 
  1622 
  1626     /********************/
  1623     /********************/
  1627     /* 2.1.6 - Pragmas  */
  1624     /* 2.1.6 - Pragmas  */
  1628     /********************/
  1625     /********************/
  1819           s4o.print("(&");
  1816           s4o.print("(&");
  1820           symbol->program_name->accept(*this);
  1817           symbol->program_name->accept(*this);
  1821           print_retain();
  1818           print_retain();
  1822           s4o.print(");\n");
  1819           s4o.print(");\n");
  1823           break;
  1820           break;
  1824         case run_dt:
  1821         case run_dt: 
  1825           current_program_name = ((identifier_c*)(symbol->program_name))->value;
  1822           { identifier_c *tmp_id = dynamic_cast<identifier_c*>(symbol->program_name);
       
  1823             if (NULL == tmp_id) ERROR;
       
  1824             current_program_name = tmp_id->value;
       
  1825 	  }
  1826           if (symbol->task_name != NULL) {
  1826           if (symbol->task_name != NULL) {
  1827             s4o.print(s4o.indent_spaces);
  1827             s4o.print(s4o.indent_spaces);
  1828             s4o.print("if (");
  1828             s4o.print("if (");
  1829             symbol->task_name->accept(*this);
  1829             symbol->task_name->accept(*this);
  1830             s4o.print(") {\n");
  1830             s4o.print(") {\n");
  2142 /* B.1 - Common elements */
  2142 /* B.1 - Common elements */
  2143 /*************************/
  2143 /*************************/
  2144 /*******************************************/
  2144 /*******************************************/
  2145 /* B 1.1 - Letters, digits and identifiers */
  2145 /* B 1.1 - Letters, digits and identifiers */
  2146 /*******************************************/
  2146 /*******************************************/
  2147     void *visit(identifier_c *symbol) {
  2147     void *visit(identifier_c *symbol) {current_name = symbol->value; return NULL;}
  2148         current_name = symbol->value;
  2148     /* In the derived datatype and POUs declarations, the names are stored as identfier_c, so the following visitors are not required! */
  2149         return NULL;
  2149     void *visit(derived_datatype_identifier_c *symbol) {ERROR; return NULL;}
  2150     }
  2150     void *visit(         poutype_identifier_c *symbol) {ERROR; return NULL;}
       
  2151     
  2151 
  2152 
  2152 /********************************/
  2153 /********************************/
  2153 /* B 1.3.3 - Derived data types */
  2154 /* B 1.3.3 - Derived data types */
  2154 /********************************/
  2155 /********************************/
  2155     /*  TYPE type_declaration_list END_TYPE */
  2156     /*  TYPE type_declaration_list END_TYPE */
  2165     }
  2166     }
  2166 
  2167 
  2167 /**************************************/
  2168 /**************************************/
  2168 /* B.1.5 - Program organization units */
  2169 /* B.1.5 - Program organization units */
  2169 /**************************************/
  2170 /**************************************/
       
  2171 /* WARNING: The following code is buggy when generating an independent pair of files for each POU, as the
       
  2172  *          specially created stage4out_c (s4o_c and s4o_h) will not comply with the enable/disable_code_generation_pragma_c
       
  2173  */
  2170 #define handle_pou(fname,pname) \
  2174 #define handle_pou(fname,pname) \
  2171       if (!allow_output) return NULL;\
  2175       if (!allow_output) return NULL;\
  2172       if (generate_pou_filepairs__) {\
  2176       if (generate_pou_filepairs__) {\
  2173         const char *pou_name = get_datatype_info_c::get_id_str(pname);\
  2177         const char *pou_name = get_datatype_info_c::get_id_str(pname);\
  2174         stage4out_c s4o_c(current_builddir, pou_name, "c");\
  2178         stage4out_c s4o_c(current_builddir, pou_name, "c");\