stage4/generate_c/generate_c.cc
changeset 945 477393b00f95
parent 933 76324f461aed
child 958 7474d2cd1d6e
equal deleted inserted replaced
943:566414d7ba1f 945:477393b00f95
   248  *   for e.g.; 
   248  *   for e.g.; 
   249  *     SIN( REAL) : REAL      -> prints out ->  REAL__REAL
   249  *     SIN( REAL) : REAL      -> prints out ->  REAL__REAL
   250  *     LEN( STRING) : INT     -> prints out ->  INT__STRING
   250  *     LEN( STRING) : INT     -> prints out ->  INT__STRING
   251  *     MUL(TIME, INT) : TIME  -> prints out ->  TIME__TIME__INT
   251  *     MUL(TIME, INT) : TIME  -> prints out ->  TIME__TIME__INT
   252  */
   252  */
   253 class print_function_parameter_data_types_c: public generate_c_base_c {
   253 class print_function_parameter_data_types_c: public generate_c_base_and_typeid_c {
   254   private:
   254   private:
   255     symbol_c *current_type;
   255     symbol_c *current_type;
   256     bool_type_name_c tmp_bool;
   256     bool_type_name_c tmp_bool;
   257 
   257 
   258     void print_list(symbol_c *var_list, symbol_c *data_type) { 
   258     void print_list(symbol_c *var_list, symbol_c *data_type) { 
   267       }
   267       }
   268     }
   268     }
   269     
   269     
   270   public:
   270   public:
   271     print_function_parameter_data_types_c(stage4out_c *s4o_ptr): 
   271     print_function_parameter_data_types_c(stage4out_c *s4o_ptr): 
   272       generate_c_base_c(s4o_ptr)
   272       generate_c_base_and_typeid_c(s4o_ptr)
   273       {current_type = NULL;}
   273       {current_type = NULL;}
   274 
   274 
   275     /**************************************/
   275     /**************************************/
   276     /* B.1.5 - Program organization units */
   276     /* B.1.5 - Program organization units */
   277     /**************************************/
   277     /**************************************/
   746 void *generate_c_SFC_IL_ST_c::visit(statement_list_c *symbol) {
   746 void *generate_c_SFC_IL_ST_c::visit(statement_list_c *symbol) {
   747   generate_c_st_c generate_c_st(s4o_ptr, fbname, scope, variable_prefix);
   747   generate_c_st_c generate_c_st(s4o_ptr, fbname, scope, variable_prefix);
   748   generate_c_st.generate(symbol);
   748   generate_c_st.generate(symbol);
   749   return NULL;
   749   return NULL;
   750 }
   750 }
   751 
       
   752 
       
   753 
       
   754 
       
   755 /***********************************************************************/
       
   756 /***********************************************************************/
       
   757 /***********************************************************************/
       
   758 /***********************************************************************/
       
   759 /***********************************************************************/
       
   760 
       
   761 
       
   762 identifier_c *generate_unique_id(const char *prefix = "", symbol_c *clone = NULL) {
       
   763   static int counter = 0;
       
   764   
       
   765   counter++;
       
   766   int   len = snprintf(NULL, 0, "%s__UID_%d", prefix, counter); // UID -> Unique IDentifier
       
   767   char *str = (char *)malloc(len+1);
       
   768   if (snprintf(str, len+1,      "%s__UID_%d", prefix, counter) < 0) ERROR;
       
   769   
       
   770   identifier_c *id = new identifier_c(str);
       
   771   if (NULL == id) ERROR;
       
   772   if (NULL != clone)
       
   773     *(dynamic_cast<symbol_c *>(id)) = *(dynamic_cast<symbol_c *>(clone));
       
   774   return id;
       
   775 }
       
   776 
       
   777 
       
   778 identifier_c *generate_unique_id(symbol_c *prefix, symbol_c *clone = NULL) {
       
   779   token_c *token = dynamic_cast<token_c *>(prefix);
       
   780   //if (NULL == token) ERROR;
       
   781   if (NULL == token)
       
   782     return generate_unique_id("", clone);
       
   783   return generate_unique_id(token->value, clone);
       
   784 }
       
   785 
       
   786 
       
   787 /* This class will generate a new datatype for each implicitly declared array datatype
       
   788  * (i.e. arrays declared in a variable declaration, or a struct datatype declaration...)
       
   789  * It will do the same for implicitly declared REF_TO datatypes.
       
   790  * 
       
   791  * The class will be called once for each POU declaration, and once for each derived datatype declaration.
       
   792  * 
       
   793  * e.g.:
       
   794  *      VAR  a: ARRAY [1..3] OF INT; END_VAR   <---- ARRAY datatype is implicitly declared inside the variable declaration
       
   795  *      TYPE STRUCT
       
   796  *               a: ARRAY [1..3] OF INT;       <---- ARRAY datatype is implicitly declared inside the struct type declaration  
       
   797  *               b: INT;
       
   798  *            END_STRUCT
       
   799  *      END_TYPE
       
   800  */
       
   801 class generate_c_datatypes_c: public iterator_visitor_c {
       
   802   private:
       
   803     generate_c_typedecl_c generate_c_typedecl;
       
   804     symbol_c *prefix;
       
   805   public:
       
   806     generate_c_datatypes_c(stage4out_c *s4o_incl_ptr)
       
   807       : generate_c_typedecl(s4o_incl_ptr) {
       
   808         prefix = NULL;
       
   809     };
       
   810     virtual ~generate_c_datatypes_c(void) {
       
   811     }
       
   812 
       
   813     /*************************/
       
   814     /* B.1 - Common elements */
       
   815     /*************************/
       
   816     /**********************/
       
   817     /* B.1.3 - Data types */
       
   818     /**********************/
       
   819     /********************************/
       
   820     /* B 1.3.3 - Derived data types */
       
   821     /********************************/
       
   822     /*  identifier ':' array_spec_init */
       
   823     void *visit(array_type_declaration_c *symbol) {return NULL;} // This is not an implicitly defined array!
       
   824 
       
   825     /* ref_spec:  REF_TO (non_generic_type_name | function_block_type_name) */
       
   826     void *visit(ref_spec_c *symbol) {
       
   827       identifier_c *id = generate_unique_id(prefix, symbol);
       
   828       /* Warning: The following is dangerous... 
       
   829        * We are asking the generate_c_typedecl_c visitor to visit a newly created ref_spec_init_c object
       
   830        * that has not been through stage 3, and therefore does not have stage 3 annotations filled in.
       
   831        * This will only work if generate_c_typedecl_c does ot depend on the stage 3 annotations!
       
   832        */
       
   833       ref_spec_init_c   ref_spec(symbol, NULL);
       
   834       ref_type_decl_c   ref_decl(id, &ref_spec);
       
   835       ref_decl.accept(generate_c_typedecl); // Must be done _before_ adding the annotation, due to the way generate_c_typedecl_c works
       
   836       symbol->anotations_map["generate_c_annotaton__implicit_type_id"] = id;
       
   837       return NULL;
       
   838     }
       
   839 
       
   840     /* For the moment, we do not support initialising reference data types */
       
   841     /* ref_spec_init: ref_spec [ ASSIGN ref_initialization ] */ 
       
   842     /* NOTE: ref_initialization may be NULL!! */
       
   843     // SYM_REF2(ref_spec_init_c, ref_spec, ref_initialization)
       
   844     void *visit(ref_spec_init_c *symbol) {
       
   845       symbol->ref_spec->accept(*this);
       
   846       int implicit_id_count = symbol->ref_spec->anotations_map.count("generate_c_annotaton__implicit_type_id");
       
   847       if (implicit_id_count  > 1) ERROR;
       
   848       if (implicit_id_count == 1)
       
   849         symbol->anotations_map["generate_c_annotaton__implicit_type_id"] = symbol->ref_spec->anotations_map["generate_c_annotaton__implicit_type_id"];
       
   850       return NULL;
       
   851     }
       
   852 
       
   853     /* ref_type_decl: identifier ':' ref_spec_init */
       
   854     void *visit(ref_type_decl_c *symbol) {return NULL;} // This is not an implicitly defined REF_TO!
       
   855 
       
   856     /******************************************/
       
   857     /* B 1.4.3 - Declaration & Initialization */
       
   858     /******************************************/
       
   859     void *visit(edge_declaration_c           *symbol) {return NULL;}
       
   860     void *visit(en_param_declaration_c       *symbol) {return NULL;}
       
   861     void *visit(eno_param_declaration_c      *symbol) {return NULL;}
       
   862 
       
   863     /* array_specification [ASSIGN array_initialization] */
       
   864     /* array_initialization may be NULL ! */
       
   865     void *visit(array_spec_init_c *symbol) {
       
   866       symbol->array_specification->accept(*this);
       
   867       int implicit_id_count = symbol->array_specification->anotations_map.count("generate_c_annotaton__implicit_type_id");
       
   868       if (implicit_id_count  > 1) ERROR;
       
   869       if (implicit_id_count == 1)
       
   870         symbol->anotations_map["generate_c_annotaton__implicit_type_id"] = symbol->array_specification->anotations_map["generate_c_annotaton__implicit_type_id"];
       
   871       return NULL;
       
   872     }
       
   873 
       
   874     /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
       
   875     void *visit(array_specification_c *symbol) {
       
   876       identifier_c *id = generate_unique_id(prefix, symbol);
       
   877       /* Warning: The following is dangerous... 
       
   878        * We are asking the generate_c_typedecl_c visitor to visit a newly created array_type_declaration_c object
       
   879        * that has not been through stage 3, and therefore does not have stage 3 annotations filled in.
       
   880        * This will only work if generate_c_typedecl_c does ot depend on the stage 3 annotations!
       
   881        */
       
   882       array_spec_init_c        array_spec(symbol, NULL);
       
   883       array_type_declaration_c array_decl(id, &array_spec);
       
   884       array_decl.accept(generate_c_typedecl); // Must be done _before_ adding the annotation, due to the way generate_c_typedecl_c works
       
   885       symbol->anotations_map["generate_c_annotaton__implicit_type_id"] = id;
       
   886       return NULL;
       
   887     }
       
   888     
       
   889     /*  var1_list ':' initialized_structure */
       
   890     // SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure)
       
   891     void *visit(structured_var_init_decl_c   *symbol) {return NULL;}
       
   892 
       
   893     /* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */
       
   894     /* structure_initialization -> may be NULL ! */
       
   895     void *visit(fb_name_decl_c               *symbol) {return NULL;}
       
   896 
       
   897     /*  var1_list ':' structure_type_name */
       
   898     //SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name)
       
   899     void *visit(structured_var_declaration_c *symbol) {return NULL;}
       
   900 
       
   901 
       
   902     /***********************/
       
   903     /* B 1.5.1 - Functions */
       
   904     /***********************/      
       
   905     void *visit(function_declaration_c *symbol) {
       
   906       prefix = symbol->derived_function_name;
       
   907       symbol->var_declarations_list->accept(*this);
       
   908       prefix = NULL;
       
   909       return NULL;
       
   910     }
       
   911     /*****************************/
       
   912     /* B 1.5.2 - Function Blocks */
       
   913     /*****************************/
       
   914     void *visit(function_block_declaration_c *symbol) {
       
   915       prefix = symbol->fblock_name;
       
   916       symbol->var_declarations->accept(*this);
       
   917       prefix = NULL;
       
   918       return NULL;
       
   919     }
       
   920     /**********************/
       
   921     /* B 1.5.3 - Programs */
       
   922     /**********************/    
       
   923     void *visit(program_declaration_c *symbol) {
       
   924       prefix = symbol->program_type_name;
       
   925       symbol->var_declarations->accept(*this);
       
   926       prefix = NULL;
       
   927       return NULL;
       
   928     }
       
   929 };
       
   930 
   751 
   931 
   752 
   932 
   753 
   933 
   754 
   934 
   755 
   984      *                     Here we generate the source code!
   805      *                     Here we generate the source code!
   985      */
   806      */
   986     /*   FUNCTION derived_function_name ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
   807     /*   FUNCTION derived_function_name ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
   987     /* | FUNCTION derived_function_name ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
   808     /* | FUNCTION derived_function_name ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
   988     static void handle_function(function_declaration_c *symbol, stage4out_c &s4o, bool print_declaration) {
   809     static void handle_function(function_declaration_c *symbol, stage4out_c &s4o, bool print_declaration) {
   989       generate_c_vardecl_c *vardecl = NULL;
   810       generate_c_vardecl_c          *vardecl = NULL;
   990       generate_c_base_c     print_base(&s4o);
   811       generate_c_base_and_typeid_c   print_base(&s4o);
   991       
   812       
   992       TRACE("function_declaration_c");
   813       TRACE("function_declaration_c");
   993     
   814     
   994       /* (A) Function declaration... */
   815       /* (A) Function declaration... */
   995       /* (A.1) Function return type */
   816       /* (A.1) Function return type */
  1121      *                     Here we generate the source code!
   942      *                     Here we generate the source code!
  1122      */
   943      */
  1123     /*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
   944     /*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
  1124     //SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused)
   945     //SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused)
  1125     static void handle_function_block(function_block_declaration_c *symbol, stage4out_c &s4o, bool print_declaration) {
   946     static void handle_function_block(function_block_declaration_c *symbol, stage4out_c &s4o, bool print_declaration) {
  1126       generate_c_vardecl_c     *vardecl;
   947       generate_c_vardecl_c          *vardecl;
  1127       generate_c_sfcdecl_c     *sfcdecl;
   948       generate_c_sfcdecl_c          *sfcdecl;
  1128       generate_c_base_c         print_base(&s4o);
   949       generate_c_base_and_typeid_c   print_base(&s4o);
  1129       TRACE("function_block_declaration_c");
   950       TRACE("function_block_declaration_c");
  1130     
   951     
  1131       /* (A) Function Block data structure declaration... */
   952       /* (A) Function Block data structure declaration... */
  1132       if (print_declaration) {
   953       if (print_declaration) {
  1133         /* (A.1) Data structure declaration */
   954         /* (A.1) Data structure declaration */
  1323      *                     Here we generate the source code!
  1144      *                     Here we generate the source code!
  1324      */
  1145      */
  1325     /*  PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */
  1146     /*  PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */
  1326     //SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused)
  1147     //SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused)
  1327     static void handle_program(program_declaration_c *symbol, stage4out_c &s4o, bool print_declaration) {
  1148     static void handle_program(program_declaration_c *symbol, stage4out_c &s4o, bool print_declaration) {
  1328       generate_c_vardecl_c     *vardecl;
  1149       generate_c_vardecl_c          *vardecl;
  1329       generate_c_sfcdecl_c     *sfcdecl;
  1150       generate_c_sfcdecl_c          *sfcdecl;
  1330       generate_c_base_c         print_base(&s4o);
  1151       generate_c_base_and_typeid_c   print_base(&s4o);
  1331       TRACE("program_declaration_c");
  1152       TRACE("program_declaration_c");
  1332     
  1153     
  1333       /* (A) Program data structure declaration... */
  1154       /* (A) Program data structure declaration... */
  1334       if (print_declaration) {      
  1155       if (print_declaration) {      
  1335         /* (A.1) Data structure declaration */
  1156         /* (A.1) Data structure declaration */
  1497 /***********************************************************************/
  1318 /***********************************************************************/
  1498 /***********************************************************************/
  1319 /***********************************************************************/
  1499 /***********************************************************************/
  1320 /***********************************************************************/
  1500 /***********************************************************************/
  1321 /***********************************************************************/
  1501 
  1322 
  1502 class generate_c_config_c: public generate_c_base_c {
  1323 class generate_c_config_c: public generate_c_base_and_typeid_c {
  1503     private:
  1324     private:
  1504     stage4out_c &s4o_incl;
  1325     stage4out_c &s4o_incl;
  1505     
  1326     
  1506     public:
  1327     public:
  1507     generate_c_config_c(stage4out_c *s4o_ptr, stage4out_c *s4o_incl_ptr)
  1328     generate_c_config_c(stage4out_c *s4o_ptr, stage4out_c *s4o_incl_ptr)
  1508       : generate_c_base_c(s4o_ptr), s4o_incl(*s4o_incl_ptr) {
  1329       : generate_c_base_and_typeid_c(s4o_ptr), s4o_incl(*s4o_incl_ptr) {
  1509     };
  1330     };
  1510 
  1331 
  1511     virtual ~generate_c_config_c(void) {}
  1332     virtual ~generate_c_config_c(void) {}
  1512 
  1333 
  1513     typedef enum {
  1334     typedef enum {
  1708 /***********************************************************************/
  1529 /***********************************************************************/
  1709 /***********************************************************************/
  1530 /***********************************************************************/
  1710 /***********************************************************************/
  1531 /***********************************************************************/
  1711 
  1532 
  1712 
  1533 
  1713 class generate_c_resources_c: public generate_c_typedecl_c {
  1534 class generate_c_resources_c: public generate_c_base_and_typeid_c {
  1714 
  1535 
  1715   search_var_instance_decl_c *search_config_instance;
  1536   search_var_instance_decl_c *search_config_instance;
  1716   search_var_instance_decl_c *search_resource_instance;
  1537   search_var_instance_decl_c *search_resource_instance;
  1717 
  1538 
  1718   private:
  1539   private:
  1724     bool configuration_name;
  1545     bool configuration_name;
  1725     stage4out_c *s4o_ptr;
  1546     stage4out_c *s4o_ptr;
  1726 
  1547 
  1727   public:
  1548   public:
  1728     generate_c_resources_c(stage4out_c *s4o_ptr, symbol_c *config_scope, symbol_c *resource_scope, unsigned long time)
  1549     generate_c_resources_c(stage4out_c *s4o_ptr, symbol_c *config_scope, symbol_c *resource_scope, unsigned long time)
  1729       : generate_c_typedecl_c(s4o_ptr) {
  1550       : generate_c_base_and_typeid_c(s4o_ptr) {
  1730       current_configuration = config_scope;
  1551       current_configuration = config_scope;
  1731       search_config_instance   = new search_var_instance_decl_c(config_scope);
  1552       search_config_instance   = new search_var_instance_decl_c(config_scope);
  1732       search_resource_instance = new search_var_instance_decl_c(resource_scope);
  1553       search_resource_instance = new search_var_instance_decl_c(resource_scope);
  1733       common_ticktime = time;
  1554       common_ticktime = time;
  1734       current_resource_name = NULL;
  1555       current_resource_name = NULL;
  2235     stage4out_c                  pous_s4o;
  2056     stage4out_c                  pous_s4o;
  2236     stage4out_c             pous_incl_s4o;
  2057     stage4out_c             pous_incl_s4o;
  2237     stage4out_c     located_variables_s4o;
  2058     stage4out_c     located_variables_s4o;
  2238     stage4out_c             variables_s4o;
  2059     stage4out_c             variables_s4o;
  2239     
  2060     
  2240     generate_c_datatypes_c generate_c_datatypes;
  2061     generate_c_typedecl_c          generate_c_typedecl;
  2241     generate_c_typedecl_c  generate_c_typedecl;
  2062     generate_c_implicit_typedecl_c generate_c_implicit_typedecl;
  2242     generate_c_pous_c      generate_c_pous;
  2063     generate_c_pous_c              generate_c_pous;
  2243     
  2064     
  2244     symbol_c   *current_configuration;
  2065     symbol_c   *current_configuration;
  2245 
  2066 
  2246     const char *current_name;
  2067     const char *current_name;
  2247     const char *current_builddir;
  2068     const char *current_builddir;
  2255             s4o(*s4o_ptr),
  2076             s4o(*s4o_ptr),
  2256             pous_s4o(builddir, "POUS", "c"),
  2077             pous_s4o(builddir, "POUS", "c"),
  2257             pous_incl_s4o(builddir, "POUS", "h"),
  2078             pous_incl_s4o(builddir, "POUS", "h"),
  2258             located_variables_s4o(builddir, "LOCATED_VARIABLES","h"),
  2079             located_variables_s4o(builddir, "LOCATED_VARIABLES","h"),
  2259             variables_s4o(builddir, "VARIABLES","csv"),
  2080             variables_s4o(builddir, "VARIABLES","csv"),
  2260             generate_c_datatypes(&pous_incl_s4o),
  2081             generate_c_typedecl         (&pous_incl_s4o),
  2261             generate_c_typedecl (&pous_incl_s4o)
  2082             generate_c_implicit_typedecl(&pous_incl_s4o, &generate_c_typedecl)
  2262     {
  2083     {
  2263       current_builddir = builddir;
  2084       current_builddir = builddir;
  2264       current_configuration = NULL;
  2085       current_configuration = NULL;
  2265       allow_output = true;
  2086       allow_output = true;
  2266     }
  2087     }
  2335 //   void *visit(data_type_declaration_c *symbol)  // handled by iterator_visitor_c
  2156 //   void *visit(data_type_declaration_c *symbol)  // handled by iterator_visitor_c
  2336 
  2157 
  2337     /* helper symbol for data_type_declaration */
  2158     /* helper symbol for data_type_declaration */
  2338     void *visit(type_declaration_list_c *symbol) {
  2159     void *visit(type_declaration_list_c *symbol) {
  2339       for(int i = 0; i < symbol->n; i++) {
  2160       for(int i = 0; i < symbol->n; i++) {
  2340         symbol->elements[i]->accept(generate_c_datatypes);
  2161         symbol->elements[i]->accept(generate_c_implicit_typedecl);
  2341         symbol->elements[i]->accept(generate_c_typedecl);
  2162         symbol->elements[i]->accept(generate_c_typedecl);
  2342       }
  2163       }
  2343       return NULL;
  2164       return NULL;
  2344     }
  2165     }
  2345 
  2166 
  2347 /* B.1.5 - Program organization units */
  2168 /* B.1.5 - Program organization units */
  2348 /**************************************/
  2169 /**************************************/
  2349 #define handle_pou(fname,pname) \
  2170 #define handle_pou(fname,pname) \
  2350       if (!allow_output) return NULL;\
  2171       if (!allow_output) return NULL;\
  2351       if (generate_pou_filepairs__) {\
  2172       if (generate_pou_filepairs__) {\
  2352 	const char *pou_name = get_datatype_info_c::get_id_str(pname);\
  2173         const char *pou_name = get_datatype_info_c::get_id_str(pname);\
  2353         stage4out_c s4o_c(current_builddir, pou_name, "c");\
  2174         stage4out_c s4o_c(current_builddir, pou_name, "c");\
  2354         stage4out_c s4o_h(current_builddir, pou_name, "h");\
  2175         stage4out_c s4o_h(current_builddir, pou_name, "h");\
  2355         s4o_c.print("#include \""); s4o_c.print(pou_name); s4o_c.print(".h\"\n");\
  2176         s4o_c.print("#include \""); s4o_c.print(pou_name); s4o_c.print(".h\"\n");\
  2356         s4o_h.print("#ifndef __");  s4o_h.print(pou_name); s4o_h.print("_H\n");\
  2177         s4o_h.print("#ifndef __");  s4o_h.print(pou_name); s4o_h.print("_H\n");\
  2357         s4o_h.print("#define __");  s4o_h.print(pou_name); s4o_h.print("_H\n");\
  2178         s4o_h.print("#define __");  s4o_h.print(pou_name); s4o_h.print("_H\n");\
  2358         generate_c_datatypes_c generate_c_datatypes__(&s4o_h);\
  2179         generate_c_implicit_typedecl_c generate_c_implicit_typedecl__(&s4o_h);\
  2359         symbol->accept(generate_c_datatypes__); /* generate implicitly delcared datatypes (arrays and ref_to) */\
  2180         symbol->accept(generate_c_implicit_typedecl__); /* generate implicitly delcared datatypes (arrays and ref_to) */\
  2360         generate_c_pous_c::fname(symbol, s4o_h, true); /* generate the <pou_name>.h file */\
  2181         generate_c_pous_c::fname(symbol, s4o_h, true); /* generate the <pou_name>.h file */\
  2361         generate_c_pous_c::fname(symbol, s4o_c, false);/* generate the <pou_name>.c file */\
  2182         generate_c_pous_c::fname(symbol, s4o_c, false);/* generate the <pou_name>.c file */\
  2362         s4o_h.print("#endif /* __");  s4o_h.print(pou_name); s4o_h.print("_H */\n");\
  2183         s4o_h.print("#endif /* __");  s4o_h.print(pou_name); s4o_h.print("_H */\n");\
  2363         /* add #include directives to the POUS.h and POUS.c files... */\
  2184         /* add #include directives to the POUS.h and POUS.c files... */\
  2364         pous_incl_s4o.print("#include \"");\
  2185         pous_incl_s4o.print("#include \"");\
  2366         pous_incl_s4o.print(pou_name);\
  2187         pous_incl_s4o.print(pou_name);\
  2367         pous_s4o.     print(pou_name);\
  2188         pous_s4o.     print(pou_name);\
  2368         pous_incl_s4o.print(".h\"\n");\
  2189         pous_incl_s4o.print(".h\"\n");\
  2369         pous_s4o.     print(".c\"\n");\
  2190         pous_s4o.     print(".c\"\n");\
  2370       } else {\
  2191       } else {\
  2371         symbol->accept(generate_c_datatypes);\
  2192         symbol->accept(generate_c_implicit_typedecl);\
  2372         generate_c_pous_c::fname(symbol, pous_incl_s4o, true);\
  2193         generate_c_pous_c::fname(symbol, pous_incl_s4o, true);\
  2373         generate_c_pous_c::fname(symbol, pous_s4o,      false);\
  2194         generate_c_pous_c::fname(symbol, pous_s4o,      false);\
  2374       }
  2195       }
  2375 
  2196 
  2376 /***********************/
  2197 /***********************/
  2401 /********************************/
  2222 /********************************/
  2402 /* B 1.7 Configuration elements */
  2223 /* B 1.7 Configuration elements */
  2403 /********************************/
  2224 /********************************/
  2404     void *visit(configuration_declaration_c *symbol) {
  2225     void *visit(configuration_declaration_c *symbol) {
  2405       if (symbol->global_var_declarations != NULL)
  2226       if (symbol->global_var_declarations != NULL)
  2406         symbol->global_var_declarations->accept(generate_c_datatypes);
  2227         symbol->global_var_declarations->accept(generate_c_implicit_typedecl);
  2407       static int configuration_count = 0;
  2228       static int configuration_count = 0;
  2408 
  2229 
  2409       if (configuration_count++) {
  2230       if (configuration_count++) {
  2410         /* the first configuration is the one we will use!! */
  2231         /* the first configuration is the one we will use!! */
  2411         STAGE4_ERROR(symbol, symbol, "A previous CONFIGURATION has already been declared (C code generation currently only allows a single configuration).");
  2232         STAGE4_ERROR(symbol, symbol, "A previous CONFIGURATION has already been declared (C code generation currently only allows a single configuration).");
  2444       return NULL;
  2265       return NULL;
  2445     }
  2266     }
  2446 
  2267 
  2447     void *visit(resource_declaration_c *symbol) {
  2268     void *visit(resource_declaration_c *symbol) {
  2448       if (symbol->global_var_declarations != NULL)
  2269       if (symbol->global_var_declarations != NULL)
  2449         symbol->global_var_declarations->accept(generate_c_datatypes);
  2270         symbol->global_var_declarations->accept(generate_c_implicit_typedecl);
  2450       symbol->resource_name->accept(*this);
  2271       symbol->resource_name->accept(*this);
  2451       stage4out_c resources_s4o(current_builddir, current_name, "c");
  2272       stage4out_c resources_s4o(current_builddir, current_name, "c");
  2452       generate_c_resources_c generate_c_resources(&resources_s4o, current_configuration, symbol, common_ticktime);
  2273       generate_c_resources_c generate_c_resources(&resources_s4o, current_configuration, symbol, common_ticktime);
  2453       symbol->accept(generate_c_resources);
  2274       symbol->accept(generate_c_resources);
  2454       return NULL;
  2275       return NULL;