stage4/generate_c/generate_c.cc
changeset 918 e9bde0aa93ed
parent 917 5344b1fc826b
child 920 4369ce5e687f
equal deleted inserted replaced
917:5344b1fc826b 918:e9bde0aa93ed
  2343     }
  2343     }
  2344 
  2344 
  2345 /**************************************/
  2345 /**************************************/
  2346 /* B.1.5 - Program organization units */
  2346 /* B.1.5 - Program organization units */
  2347 /**************************************/
  2347 /**************************************/
  2348 #define handle_pou(fname,pname,var_decl_list) \
  2348 #define handle_pou(fname,pname) \
  2349       if (!allow_output) return NULL;\
  2349       if (!allow_output) return NULL;\
  2350       if (generate_pou_filepairs__) {\
  2350       if (generate_pou_filepairs__) {\
  2351         stage4out_c s4o_c(current_builddir, get_datatype_info_c::get_id_str(pname), "c");\
  2351 	const char *pou_name = get_datatype_info_c::get_id_str(pname);\
  2352         stage4out_c s4o_h(current_builddir, get_datatype_info_c::get_id_str(pname), "h");\
  2352         stage4out_c s4o_c(current_builddir, pou_name, "c");\
       
  2353         stage4out_c s4o_h(current_builddir, pou_name, "h");\
       
  2354         s4o_c.print("#include \""); s4o_c.print(pou_name); s4o_c.print(".h\"\n");\
       
  2355         s4o_h.print("#ifndef __");  s4o_h.print(pou_name); s4o_h.print("_H\n");\
       
  2356         s4o_h.print("#define __");  s4o_h.print(pou_name); s4o_h.print("_H\n");\
  2353         generate_c_datatypes_c generate_c_datatypes__(&s4o_h);\
  2357         generate_c_datatypes_c generate_c_datatypes__(&s4o_h);\
  2354         var_decl_list->accept(generate_c_datatypes__);\
  2358         symbol->accept(generate_c_datatypes__); /* generate implicitly delcared datatypes (arrays and ref_to) */\
  2355         generate_c_pous_c::fname(symbol, s4o_h, true); /* generate the <pou_name>.h file */\
  2359         generate_c_pous_c::fname(symbol, s4o_h, true); /* generate the <pou_name>.h file */\
  2356         generate_c_pous_c::fname(symbol, s4o_c, false);/* generate the <pou_name>.c file */\
  2360         generate_c_pous_c::fname(symbol, s4o_c, false);/* generate the <pou_name>.c file */\
       
  2361         s4o_h.print("#endif /* __");  s4o_h.print(pou_name); s4o_h.print("_H */\n");\
  2357         /* add #include directives to the POUS.h and POUS.c files... */\
  2362         /* add #include directives to the POUS.h and POUS.c files... */\
  2358         pous_incl_s4o.print("#include \"");\
  2363         pous_incl_s4o.print("#include \"");\
  2359         pous_s4o.     print("#include \"");\
  2364         pous_s4o.     print("#include \"");\
  2360         pous_incl_s4o.print(get_datatype_info_c::get_id_str(pname));\
  2365         pous_incl_s4o.print(pou_name);\
  2361         pous_s4o.     print(get_datatype_info_c::get_id_str(pname));\
  2366         pous_s4o.     print(pou_name);\
  2362         pous_incl_s4o.print(".h\"\n");\
  2367         pous_incl_s4o.print(".h\"\n");\
  2363         pous_s4o.     print(".c\"\n");\
  2368         pous_s4o.     print(".c\"\n");\
  2364       } else {\
  2369       } else {\
  2365         var_decl_list->accept(generate_c_datatypes);\
  2370         symbol->accept(generate_c_datatypes);\
  2366         generate_c_pous_c::fname(symbol, pous_incl_s4o, true);\
  2371         generate_c_pous_c::fname(symbol, pous_incl_s4o, true);\
  2367         generate_c_pous_c::fname(symbol, pous_s4o,      false);\
  2372         generate_c_pous_c::fname(symbol, pous_s4o,      false);\
  2368       }
  2373       }
  2369 
  2374 
  2370 /***********************/
  2375 /***********************/
  2371 /* B 1.5.1 - Functions */
  2376 /* B 1.5.1 - Functions */
  2372 /***********************/      
  2377 /***********************/      
  2373     void *visit(function_declaration_c *symbol) {
  2378     void *visit(function_declaration_c *symbol) {
  2374       handle_pou(handle_function,symbol->derived_function_name, symbol)
  2379       handle_pou(handle_function,symbol->derived_function_name)
  2375       return NULL;
  2380       return NULL;
  2376     }
  2381     }
  2377     
  2382     
  2378 /*****************************/
  2383 /*****************************/
  2379 /* B 1.5.2 - Function Blocks */
  2384 /* B 1.5.2 - Function Blocks */
  2380 /*****************************/
  2385 /*****************************/
  2381     void *visit(function_block_declaration_c *symbol) {
  2386     void *visit(function_block_declaration_c *symbol) {
  2382       handle_pou(handle_function_block,symbol->fblock_name, symbol)
  2387       handle_pou(handle_function_block,symbol->fblock_name)
  2383       return NULL;
  2388       return NULL;
  2384     }
  2389     }
  2385     
  2390     
  2386 /**********************/
  2391 /**********************/
  2387 /* B 1.5.3 - Programs */
  2392 /* B 1.5.3 - Programs */
  2388 /**********************/    
  2393 /**********************/    
  2389     void *visit(program_declaration_c *symbol) {
  2394     void *visit(program_declaration_c *symbol) {
  2390       handle_pou(handle_program,symbol->program_type_name, symbol)
  2395       handle_pou(handle_program,symbol->program_type_name)
  2391       return NULL;
  2396       return NULL;
  2392     }
  2397     }
  2393     
  2398     
  2394 
  2399 
  2395 /********************************/
  2400 /********************************/