Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / TAO_IDL / be / be_codegen.cpp
blobe8218aed417edfa3058a23476a595120b5736cf3
1 //=============================================================================
2 /**
3 * @file be_codegen.cpp
5 * Code generation
7 * @author Aniruddha Gokhale
8 */
9 //=============================================================================
11 #include "be_codegen.h"
12 #include "be_uses.h"
13 #include "be_interface.h"
14 #include "be_helper.h"
15 #include "be_extern.h"
16 #include "be_util.h"
18 #include "global_extern.h"
19 #include "utl_string.h"
20 #include "idl_defines.h"
22 // This one TAO include is needed to generate the
23 // version check code.
24 #include "../../tao/Version.h"
26 #include "ace/OS_NS_ctype.h"
27 #include "ace/OS_NS_sys_time.h"
28 #include "ace/OS_NS_unistd.h"
29 #include "ace/Numeric_Limits.h"
31 TAO_CodeGen * tao_cg = nullptr;
33 TAO_CodeGen::TAO_CodeGen ()
34 : client_header_ (nullptr),
35 client_stubs_ (nullptr),
36 client_inline_ (nullptr),
37 server_header_ (nullptr),
38 implementation_header_(nullptr),
39 implementation_skeleton_(nullptr),
40 server_template_header_ (nullptr),
41 server_skeletons_ (nullptr),
42 server_template_skeletons_ (nullptr),
43 anyop_header_ (nullptr),
44 anyop_source_ (nullptr),
45 gperf_input_stream_ (nullptr),
46 ciao_svnt_header_ (nullptr),
47 ciao_svnt_source_ (nullptr),
48 ciao_svnt_template_header_ (nullptr),
49 ciao_svnt_template_source_ (nullptr),
50 ciao_exec_header_ (nullptr),
51 ciao_exec_source_ (nullptr),
52 ciao_exec_idl_ (nullptr),
53 ciao_conn_header_ (nullptr),
54 ciao_conn_source_ (nullptr),
55 ciao_ami_conn_idl_ (nullptr),
56 gperf_input_filename_ (nullptr),
57 strategy_ (TAO_PERFECT_HASH)
61 // destructor
62 TAO_CodeGen::~TAO_CodeGen ()
66 // Change the string to all upper case.
67 const char *
68 TAO_CodeGen::upcase (const char *str)
70 static char upcase_str [NAMEBUFSIZE];
72 ACE_OS::memset (upcase_str,
73 '\0',
74 NAMEBUFSIZE);
76 // Convert letters in str to upper case.
77 for (unsigned int i = 0; i < ACE_OS::strlen (str); ++i)
79 if (ACE_OS::ace_isalpha (str[i]))
81 upcase_str[i] =
82 static_cast<char> (ACE_OS::ace_toupper (str[i]));
84 else
86 // Copy it as it is.
87 upcase_str[i] = str[i];
91 return upcase_str;
94 // Change the string to all lower case.
95 const char *
96 TAO_CodeGen::downcase (const char *str)
98 static char downcase_str [NAMEBUFSIZE];
100 ACE_OS::memset (downcase_str,
101 '\0',
102 NAMEBUFSIZE);
104 // Convert letters in str to upper case.
105 for (unsigned int i = 0; i < ACE_OS::strlen (str); ++i)
107 if (ACE_OS::ace_isalpha (str[i]))
109 downcase_str[i] =
110 static_cast<char> (ACE_OS::ace_tolower (str[i]));
112 else
114 // Copy it as it is.
115 downcase_str[i] = str[i];
119 return downcase_str;
122 // Set the client header stream.
124 TAO_CodeGen::start_client_header (const char *fname)
126 if (nullptr == fname)
128 // Bad file name.
129 return -1;
132 // @@ We are making use of "included_idl_files" that is in the
133 // idl_global. We need to make sure the validity of those files.
134 FE_Utils::validate_included_idl_files ();
136 // Clean up between multiple files.
137 delete this->client_header_;
139 ACE_NEW_RETURN (this->client_header_,
140 TAO_OutStream,
141 -1);
143 if (this->client_header_->open (fname, TAO_OutStream::TAO_CLI_HDR) == -1)
145 return -1;
148 TAO_INSERT_COMMENT (this->client_header_);
150 // Generate the #ident string, if any.
151 this->gen_ident_string (this->client_header_);
153 ACE_CString pidl_checker (idl_global->filename ()->get_string ());
154 bool const got_pidl =
155 (pidl_checker.substr (pidl_checker.length () - 5) == ".pidl");
157 if (!got_pidl)
159 // Generate the #ifndef clause.
160 this->gen_ifndef_string (fname,
161 this->client_header_,
162 "_TAO_IDL_",
163 "_H_");
165 else
167 // Generate the #ifndef clause.
168 this->gen_ifndef_string (fname,
169 this->client_header_,
170 "_TAO_PIDL_",
171 "_H_");
174 if (be_global->pre_include () != nullptr)
176 *this->client_header_ << "#include /**/ \""
177 << be_global->pre_include ()
178 << "\"\n\n";
181 if (be_global->include_guard () != nullptr)
183 *this->client_header_ << "#ifndef "
184 << be_global->include_guard ()
185 << "\n";
187 *this->client_header_ << "#error "
188 << "You should not include " << fname;
190 if (be_global->safe_include () != nullptr)
192 *this->client_header_ << ", use " << be_global->safe_include ();
195 *this->client_header_ << "\n";
197 *this->client_header_ << "#endif /* "
198 << be_global->include_guard ()
199 << " */\n";
202 // To get ACE_UNUSED_ARGS
203 this->gen_standard_include (this->client_header_,
204 "ace/config-all.h",
205 true);
207 // Some compilers don't optimize the #ifndef header include
208 // protection, but do optimize based on #pragma once.
209 *this->client_header_ << "\n\n#if !defined (ACE_LACKS_PRAGMA_ONCE)\n"
210 << "# pragma once\n"
211 << "#endif /* ACE_LACKS_PRAGMA_ONCE */";
213 *this->client_header_ << be_nl;
215 // So the ostream operator header will be visible in included ORB files.
216 if (be_global->gen_ostream_operators ())
218 *this->client_header_ << "\n#if !defined (GEN_OSTREAM_OPS)\n"
219 << "#define GEN_OSTREAM_OPS\n"
220 << "#endif /* GEN_OSTREAM_OPS */";
223 *this->client_header_ << be_nl;
225 // Other include files.
227 if (be_global->stub_export_include () != nullptr)
229 *this->client_header_ << "\n#include /**/ \""
230 << be_global->stub_export_include ()
231 << "\"";
234 if (be_global->unique_include () != nullptr)
236 *this->client_header_ << "\n#include \""
237 << be_global->unique_include ()
238 << "\"";
240 else
242 if (be_global->alt_mapping ())
244 *this->client_header_ << "\n#include <string>"
245 << "\n#include <vector>\n";
248 this->gen_stub_hdr_includes ();
250 size_t const nfiles = idl_global->n_included_idl_files ();
252 if (nfiles > 0)
254 *this->client_header_ << "\n";
257 // We must include all the client headers corresponding to
258 // IDL files included by the current IDL file.
259 // We will use the included IDL file names as they appeared
260 // in the original main IDL file, not the one which went
261 // thru CC preprocessor.
262 for (size_t j = 0; j < nfiles; ++j)
264 char* idl_name = idl_global->included_idl_files ()[j];
266 // Make a String out of it.
267 UTL_String idl_name_str = idl_name;
269 // Get the clnt header from the IDL file name.
270 const char* client_hdr =
271 BE_GlobalData::be_get_client_hdr (&idl_name_str,
272 true);
274 idl_name_str.destroy ();
276 // Sanity check and then print.
277 if (client_hdr != nullptr)
279 this->client_header_->print ("\n#include \"%s\"",
280 client_hdr);
282 else
284 ACE_ERROR_RETURN ((LM_ERROR,
285 ACE_TEXT ("\nERROR, invalid file '%C' included"),
286 idl_name),
287 -1);
292 for (ACE_Unbounded_Queue<char *>::CONST_ITERATOR i (
293 idl_global->ciao_ami_idl_fnames ());
294 !i.done ();
295 i.advance ())
297 char **tmp = nullptr;
298 i.next (tmp);
300 // Make a String out of it.
301 UTL_String idl_name_str (*tmp);
303 // Get the clnt header from the IDL file name.
304 const char* client_hdr =
305 BE_GlobalData::be_get_client_hdr (&idl_name_str,
306 true);
308 idl_name_str.destroy ();
310 // Sanity check and then print.
311 if (client_hdr != nullptr)
313 this->client_header_->print ("\n#include \"%s\"",
314 client_hdr);
316 else
318 ACE_ERROR_RETURN ((LM_ERROR,
319 ACE_TEXT ("\nERROR, invalid file '%C' included"),
320 *tmp),
321 -1);
325 // Generate the regeneration check.
326 *this->client_header_ << "\n\n#if TAO_MAJOR_VERSION != " << TAO_MAJOR_VERSION
327 << " || TAO_MINOR_VERSION != " << TAO_MINOR_VERSION
328 << " || TAO_MICRO_VERSION != " << TAO_MICRO_VERSION
329 << "\n#error This file should be regenerated with TAO_IDL"
330 << "\n#endif";
332 // Begin versioned namespace support after initial headers have been
333 // included, but before the inline file and post include
334 // directives.
336 // Just for the client header, which is included first,
337 // the versioned namespace is opened, closed, and opened again.
338 // This is needed because tao_idl will generate code as if there is no
339 // versioned namespace wrapping the mapped types. The 'using namespace'
340 // that appears in the END macro allows these types to be referenced from
341 // the global namespace.
342 *this->client_header_ << be_global->versioning_begin ()
343 << be_global->versioning_end ()
344 << be_global->versioning_begin ();
346 return 0;
349 // Get the client header stream.
350 TAO_OutStream *
351 TAO_CodeGen::client_header ()
353 return this->client_header_;
356 // Set the client stub stream.
358 TAO_CodeGen::start_client_stubs (const char *fname)
360 // Clean up between multiple files.
361 delete this->client_stubs_;
363 ACE_NEW_RETURN (this->client_stubs_,
364 TAO_OutStream,
365 -1);
367 if (this->client_stubs_->open (fname, TAO_OutStream::TAO_CLI_IMPL) == -1)
369 return -1;
372 TAO_INSERT_COMMENT (this->client_stubs_);
374 this->gen_stub_src_includes ();
376 // Generate the ident string, if any.
377 this->gen_ident_string (this->client_stubs_);
379 // Only when we generate a client inline file generate the include
380 if (be_global->gen_client_inline ())
382 // Generate the code that includes the inline file if not included in the
383 // header file.
384 *this->client_stubs_ << "\n\n#if !defined (__ACE_INLINE__)";
385 *this->client_stubs_ << "\n#include \""
386 << be_global->be_get_client_inline_fname (true)
387 << "\"";
388 *this->client_stubs_ << "\n#endif /* !defined INLINE */";
391 // Begin versioned namespace support after all headers have been
392 // included, but before any code is generated.
393 *this->client_stubs_ << be_global->versioning_begin ();
395 return 0;
398 // Get the client stubs stream.
399 TAO_OutStream *
400 TAO_CodeGen::client_stubs ()
402 return this->client_stubs_;
405 // Set the client inline stream.
407 TAO_CodeGen::start_client_inline (const char *fname)
409 // Clean up between multiple files.
410 delete this->client_inline_;
412 ACE_NEW_RETURN (this->client_inline_,
413 TAO_OutStream,
414 -1);
416 if (this->client_inline_->open (fname, TAO_OutStream::TAO_CLI_INL) == -1)
418 return -1;
421 // Generate the ident string, if any.
422 this->gen_ident_string (this->client_inline_);
424 // Begin versioned namespace support after initial headers, if any,
425 // have been included.
426 *this->client_inline_ << be_global->versioning_begin ();
428 return 0;
431 // Get the client inline stream.
432 TAO_OutStream *
433 TAO_CodeGen::client_inline ()
435 return this->client_inline_;
438 // Set the server header stream.
440 TAO_CodeGen::start_server_header (const char *fname)
442 // Clean up between multiple files.
443 delete this->server_header_;
445 ACE_NEW_RETURN (this->server_header_,
446 TAO_OutStream,
447 -1);
449 if (this->server_header_->open (fname, TAO_OutStream::TAO_SVR_HDR) == -1)
451 return -1;
454 TAO_INSERT_COMMENT (this->server_header_);
456 // Generate the ident string, if any.
457 this->gen_ident_string (this->server_header_);
459 // Generate the #ifndef clause.
460 this->gen_ifndef_string (fname,
461 this->server_header_,
462 "_TAO_IDL_",
463 "_H_");
465 if (be_global->pre_include () != nullptr)
467 *this->server_header_ << "#include /**/ \""
468 << be_global->pre_include ()
469 << "\"\n";
472 // The server header should include the client header.
473 if (be_global->safe_include ())
475 // Generate the safe include if it is defined instead of the client header
476 // need to put only the base names. Path info is not required.
477 *this->server_header_ << "\n#include \""
478 << be_global->safe_include ()
479 << "\"";
481 else
483 *this->server_header_ << "\n#include \""
484 << be_global->be_get_client_hdr_fname (true)
485 << "\"";
488 // We must include all the skeleton headers corresponding to
489 // IDL files included by the current IDL file.
490 // We will use the included IDL file names as they appeared
491 // in the original main IDL file, not the one which went
492 // thru CC preprocessor.
493 for (size_t j = 0;
494 j < idl_global->n_included_idl_files ();
495 ++j)
497 char* idl_name = idl_global->included_idl_files ()[j];
499 // String'ifying the name.
500 UTL_String idl_name_str (idl_name);
502 char const * const server_hdr =
503 BE_GlobalData::be_get_server_hdr (&idl_name_str, true);
505 idl_name_str.destroy ();
507 this->server_header_->print ("\n#include \"%s\"",
508 server_hdr);
511 /// These are generated regardless, so we put it before the
512 /// check below.
513 if (be_global->gen_arg_traits ())
515 this->gen_skel_arg_file_includes (this->server_header_);
518 if (be_global->gen_skel_files ())
520 // Some compilers don't optimize the #ifndef header include
521 // protection, but do optimize based on #pragma once.
522 *this->server_header_ << "\n\n#if !defined (ACE_LACKS_PRAGMA_ONCE)\n"
523 << "# pragma once\n"
524 << "#endif /* ACE_LACKS_PRAGMA_ONCE */\n";
526 this->gen_skel_hdr_includes ();
528 if (be_global->skel_export_include () != nullptr)
530 *this->server_header_ << "\n\n#include /**/ \""
531 << be_global->skel_export_include ()
532 << "\"";
535 else
537 // If we are suppressing skel file generation, bail after generating the
538 // copyright text and an informative message.
539 *this->server_header_ << be_nl_2
540 << "// Skeleton file generation suppressed with "
541 << "command line option -SS";
544 // Begin versioned namespace support after initial headers have been
545 // included, but before the inline file and post include
546 // directives.
547 *this->server_header_ << be_global->versioning_begin ();
549 return 0;
552 // Get the server header stream.
553 TAO_OutStream *
554 TAO_CodeGen::server_header ()
556 return this->server_header_;
559 // Set the server header stream.
561 TAO_CodeGen::start_server_template_header (const char *fname)
563 // Clean up between multiple files.
564 delete this->server_template_header_;
566 ACE_NEW_RETURN (this->server_template_header_,
567 TAO_OutStream,
568 -1);
570 int status =
571 this->server_template_header_->open (
572 fname,
573 TAO_OutStream::TAO_SVR_TMPL_HDR);
575 if (status == -1)
577 return -1;
580 TAO_INSERT_COMMENT (this->server_template_header_);
582 // Generate the ident string, if any.
583 this->gen_ident_string (this->server_template_header_);
585 // Generate the #ifndef clause.
586 this->gen_ifndef_string (fname,
587 this->server_template_header_,
588 "_TAO_IDL_",
589 "_H_");
591 if (be_global->pre_include () != nullptr)
593 *this->server_template_header_ << "#include /**/ \""
594 << be_global->pre_include ()
595 << "\"";
598 // Begin versioned namespace support after initial headers have been
599 // included, but before the inline file and post include
600 // directives.
601 *this->server_template_header_ << be_global->versioning_begin ();
603 return 0;
606 // Get the server header stream.
607 TAO_OutStream *
608 TAO_CodeGen::server_template_header ()
610 return this->server_template_header_;
613 // Set the server skeletons stream.
615 TAO_CodeGen::start_server_skeletons (const char *fname)
617 // Clean up between multiple files.
618 delete this->server_skeletons_;
620 ACE_NEW_RETURN (this->server_skeletons_,
621 TAO_OutStream,
622 -1);
624 if (this->server_skeletons_->open (fname,
625 TAO_OutStream::TAO_SVR_IMPL)
626 == -1)
628 return -1;
631 TAO_INSERT_COMMENT (this->server_skeletons_);
633 // Generate the ident string, if any.
634 this->gen_ident_string (this->server_skeletons_);
636 // Generate the include statement for the precompiled header file.
637 if (be_global->pch_include ())
639 *this->server_skeletons_ << "#include \""
640 << be_global->pch_include ()
641 << "\"\n";
644 // Generate the #ifndef clause.
645 this->gen_ifndef_string (fname,
646 this->server_skeletons_,
647 "_TAO_IDL_",
648 "_CPP_");
650 // Generate the include statement for the server header.
651 *this->server_skeletons_
652 << "\n#include \""
653 << be_global->be_get_server_hdr_fname (true)
654 << "\"";
656 this->gen_skel_src_includes ();
658 // Begin versioned namespace support after initial headers have been
659 // included, but before the inline file and post include
660 // directives.
661 *this->server_skeletons_ << be_global->versioning_begin ();
663 return 0;
666 // Get the server skeletons stream.
667 TAO_OutStream *
668 TAO_CodeGen::server_skeletons ()
670 return this->server_skeletons_;
673 // Start the server template skeleton stream.
675 TAO_CodeGen::start_server_template_skeletons (const char *fname)
677 // Clean up between multiple files.
678 delete this->server_template_skeletons_;
680 ACE_NEW_RETURN (this->server_template_skeletons_,
681 TAO_OutStream,
682 -1);
684 if (this->server_template_skeletons_->open (fname,
685 TAO_OutStream::TAO_SVR_TMPL_IMPL)
686 == -1)
688 return -1;
691 TAO_INSERT_COMMENT (this->server_template_skeletons_);
693 // Generate the ident string, if any.
694 this->gen_ident_string (this->server_template_skeletons_);
696 // Generate the #ifndef clause.
697 this->gen_ifndef_string (fname,
698 this->server_template_skeletons_,
699 "_TAO_IDL_",
700 "_CPP_");
702 // Generate the include statement for the server header.
703 *this->server_template_skeletons_
704 << "#include \""
705 << be_global->be_get_server_template_hdr_fname (true)
706 << "\"";
708 // Begin versioned namespace support after initial headers have been
709 // included, but before the inline file and post include
710 // directives.
711 *this->server_template_skeletons_ << be_global->versioning_begin ();
713 return 0;
716 // Get the server template skeletons stream.
717 TAO_OutStream *
718 TAO_CodeGen::server_template_skeletons ()
720 return this->server_template_skeletons_;
724 TAO_CodeGen::start_anyop_header (const char *fname)
726 // We may want to generate the full file or generate an empty
727 // one, but this is the only condition under which we want to
728 // skip it completely.
729 if (!be_global->gen_anyop_files () && !be_global->gen_empty_anyop_header ())
731 return 0;
734 // Clean up between multiple files.
735 delete this->anyop_header_;
737 ACE_NEW_RETURN (this->anyop_header_,
738 TAO_OutStream,
739 -1);
741 if (this->anyop_header_->open (fname,
742 TAO_OutStream::TAO_CLI_HDR)
743 == -1)
745 ACE_ERROR_RETURN ((LM_ERROR,
746 "TAO_CodeGen::start_anyop_header - "
747 "Error opening file\n"),
748 -1);
751 // We want the empty file not only with -GX
752 // but also when -GA appears with -Sa or -St.
753 // (JP) Not so - what if we are just passing along an *A.h
754 // from a safe_include?
755 // bool gen_empty_file = be_global->gen_empty_anyop_header ()
756 // || be_global->gen_anyop_files ()
757 // && !be_global->tc_support ();
759 if (be_global->gen_empty_anyop_header ())
761 *this->anyop_header_ << be_nl
762 << "// Generated empty file" << be_nl
763 << be_nl;
764 return 0;
767 TAO_INSERT_COMMENT (this->anyop_header_);
769 // Generate the #ident string, if any.
770 this->gen_ident_string (this->anyop_header_);
772 // Generate the #ifndef clause.
773 this->gen_ifndef_string (fname,
774 this->anyop_header_,
775 "_TAO_IDL_",
776 "_H_");
778 if (be_global->pre_include () != nullptr)
780 *this->anyop_header_ << "#include /**/ \""
781 << be_global->pre_include ()
782 << "\"\n";
785 // If anyop macro hasn't been set, default to stub macro.
786 if (be_global->anyop_export_include () != nullptr)
788 *this->anyop_header_ << "\n#include /**/ \""
789 << be_global->anyop_export_include ()
790 << "\"";
792 else if (be_global->stub_export_include () != nullptr)
794 *this->anyop_header_ << "\n#include /**/ \""
795 << be_global->stub_export_include ()
796 << "\"";
799 // Generate the include statement for AnyTypeCode
800 *this->anyop_header_ << "\n#include \"tao/AnyTypeCode/Any.h\"\n";
802 ACE_CString tao_prefix;
803 ACE_CString pidl_checker (idl_global->filename ()->get_string ());
804 bool const got_tao_pidl =
805 (pidl_checker.substr (pidl_checker.length () - 5) == ".pidl");
807 // If we're here and we have a .pidl file, we need to generate
808 // the *C.h include from the tao library, or from the command line
809 // override path.
810 if (got_tao_pidl)
812 const char *stub_incl_dir = be_global->stub_include_dir ();
814 if (stub_incl_dir == nullptr)
816 tao_prefix = "tao/";
818 else
820 tao_prefix = stub_incl_dir;
821 tao_prefix += '/';
825 // Generate the include statement for the client header. We just
826 // need to put only the base names. Path info is not required.
827 if (be_global->safe_include ())
829 // Generate the safe include if it is defined instead of the client header
830 // need to put only the base names. Path info is not required.
831 *this->anyop_header_ << "\n#include \""
832 << be_global->safe_include ()
833 << "\"";
835 else
837 *this->anyop_header_ << "\n#include \"" << tao_prefix.c_str ()
838 << be_global->be_get_client_hdr_fname ()
839 << "\"";
842 // If we have not suppressed Any operator generation and also
843 // are not generating the operators in a separate file, we
844 // need to include the *A.h file from all .pidl files here.
845 if (be_global->gen_anyop_files ())
847 for (size_t j = 0; j < idl_global->n_included_idl_files (); ++j)
849 char* idl_name = idl_global->included_idl_files ()[j];
851 ACE_CString pidl_checker (idl_name);
852 bool const got_pidl =
853 (pidl_checker.substr (pidl_checker.length () - 5) == ".pidl");
855 // If we're here and we have a .pidl file, we need to generate
856 // the *A.h include, if it is not a .pidl file we don't generate
857 // a thing because the *C.h include is already generated in the
858 // C.h file
859 if (got_pidl)
861 // Make a String out of it.
862 UTL_String idl_name_str = idl_name;
864 const char *anyop_hdr =
865 BE_GlobalData::be_get_anyop_header (&idl_name_str, true);
867 idl_name_str.destroy ();
869 // Stripped off any scope in the name and add the
870 // AnyTypeCode prefix.
871 ACE_CString work_hdr (anyop_hdr);
872 ACE_CString final_hdr = "tao/AnyTypeCode/";
873 ACE_CString::size_type pos = work_hdr.rfind ('/');
875 if (pos != ACE_CString::npos)
877 ACE_CString scope (work_hdr.substr (0, pos - 1));
879 // If we find a '/' in the containing scope name, it
880 // means we are including a .pidl file from a
881 // subdirectory of $TAO_ROOT/tao, and so we should
882 // include the anyop_hdr string as is, and not strip
883 // off the scope name and prepend "tao/AnyTypeCode/".
884 // Only .pidl files in $TAO_ROOT/tao itself have
885 // their generated *A.* files moved to the AnyTypeCode
886 // library.
887 if (scope.find ('/') == ACE_CString::npos)
889 work_hdr = work_hdr.substr (pos + 1);
890 final_hdr += work_hdr;
892 else
894 final_hdr = work_hdr;
898 this->anyop_header_->print ("\n#include \"%s\"",
899 final_hdr.c_str ());
904 *this->anyop_header_ << "\n";
906 // Begin versioned namespace support after initial headers have been
907 // included, but before the inline file and post include
908 // directives.
909 *this->anyop_header_ << be_global->versioning_begin ();
911 return 0;
915 TAO_CodeGen::start_anyop_source (const char *fname)
917 if (!be_global->gen_anyop_files ())
919 return 0;
922 // Clean up between multiple files.
923 delete this->anyop_source_;
925 ACE_NEW_RETURN (this->anyop_source_,
926 TAO_OutStream,
927 -1);
929 if (this->anyop_source_->open (fname, TAO_OutStream::TAO_CLI_IMPL) == -1)
931 ACE_ERROR_RETURN ((LM_ERROR,
932 "TAO_CodeGen::start_anyop_source - "
933 "Error opening file\n"),
934 -1);
937 // Generate the include statement for the precompiled header file.
938 if (be_global->pch_include ())
940 *this->anyop_source_ << "#include \""
941 << be_global->pch_include ()
942 << "\"";
945 // Generate the include statement for the client header. We just
946 // need to put only the base names. Path info is not required.
947 *this->anyop_source_ << "\n#include \""
948 << be_global->be_get_anyop_header_fname (true)
949 << "\"";
951 this->gen_typecode_includes (this->anyop_source_);
953 this->gen_any_file_includes (this->anyop_source_);
955 // Begin versioned namespace support after initial headers have been
956 // included, but before the inline file and post include
957 // directives.
958 *this->anyop_source_ << be_global->versioning_begin ();
960 return 0;
963 TAO_OutStream *
964 TAO_CodeGen::anyop_header ()
966 return this->anyop_header_;
969 TAO_OutStream *
970 TAO_CodeGen::anyop_source ()
972 return this->anyop_source_;
976 TAO_CodeGen::start_ciao_svnt_header (const char *fname)
978 // Clean up between multiple files.
979 delete this->ciao_svnt_header_;
981 ACE_NEW_RETURN (this->ciao_svnt_header_,
982 TAO_OutStream,
983 -1);
985 int status =
986 this->ciao_svnt_header_->open (fname,
987 TAO_OutStream::CIAO_SVNT_HDR);
989 if (status == -1)
991 ACE_ERROR_RETURN ((LM_ERROR,
992 ACE_TEXT ("TAO_CodeGen::start_ciao_svnt_header - ")
993 ACE_TEXT ("Error opening file\n")),
994 -1);
997 TAO_OutStream &os = *this->ciao_svnt_header_;
999 TAO_INSERT_COMMENT (&os);
1001 // Generate the #ident string, if any.
1002 this->gen_ident_string (this->ciao_svnt_header_);
1004 // Generate the #ifndef clause.
1005 this->gen_ifndef_string (fname,
1006 this->ciao_svnt_header_,
1007 "CIAO_SESSION_",
1008 "_H_");
1010 if (be_global->pre_include () != nullptr)
1012 os << "#include /**/ \""
1013 << be_global->pre_include ()
1014 << "\"\n";
1017 // All CIAO examples so far have component skeleton and servant
1018 // generated code in the same library, using the skel export macro,
1019 // so the values for the servant export default to the skel values.
1020 // Eventually, there should be a way to completely decouple them.
1021 if (be_global->svnt_export_include () != nullptr)
1023 os << "\n#include /**/ \""
1024 << be_global->svnt_export_include ()
1025 << "\"\n";
1027 else if (be_global->skel_export_include () != nullptr)
1029 os << "\n#include /**/ \""
1030 << be_global->skel_export_include ()
1031 << "\"\n";
1034 // Some compilers don't optimize the #ifndef header include
1035 // protection, but do optimize based on #pragma once.
1036 os << "\n#if !defined (ACE_LACKS_PRAGMA_ONCE)\n"
1037 << "# pragma once\n"
1038 << "#endif /* ACE_LACKS_PRAGMA_ONCE */\n"
1039 << be_nl;
1042 char **path_tmp = nullptr;
1044 for (ACE_Unbounded_Queue_Iterator<char *>riter (
1045 idl_global->ciao_lem_file_names ());
1046 riter.done () == 0;
1047 riter.advance ())
1049 riter.next (path_tmp);
1051 ACE_CString filename (*path_tmp);
1052 // sanity
1053 if (filename.substr (filename.length() - 5) == "E.idl")
1055 os << "#include \""
1056 << filename.substr(0, filename.length() - 5) << "_svnt.h\""
1057 << be_nl;
1061 // Generate the include statement for the template server header.
1062 if (be_global->gen_svnt_t_files ())
1064 os << "#include \""
1065 << be_global->be_get_ciao_tmpl_svnt_hdr_fname (true)
1066 << "\"" << be_nl;
1069 this->gen_svnt_hdr_includes (this->ciao_svnt_header_);
1071 return 0;
1075 TAO_CodeGen::start_ciao_svnt_source (const char *fname)
1077 // Clean up between multiple files.
1078 delete this->ciao_svnt_source_;
1080 ACE_NEW_RETURN (this->ciao_svnt_source_,
1081 TAO_OutStream,
1082 -1);
1084 int status =
1085 this->ciao_svnt_source_->open (fname,
1086 TAO_OutStream::CIAO_SVNT_IMPL);
1088 if (status == -1)
1090 ACE_ERROR_RETURN ((LM_ERROR,
1091 ACE_TEXT ("TAO_CodeGen::")
1092 ACE_TEXT ("start_ciao_svnt_source - ")
1093 ACE_TEXT ("Error opening file\n")),
1094 -1);
1097 TAO_OutStream &os = *this->ciao_svnt_source_;
1099 TAO_INSERT_COMMENT (&os);
1101 // Generate the #ident string, if any.
1102 this->gen_ident_string (this->ciao_svnt_source_);
1104 // Generate the include statement for the server header.
1105 *this->ciao_svnt_source_
1106 << "#include \""
1107 << be_global->be_get_ciao_svnt_hdr_fname (true)
1108 << "\"" << be_nl;
1110 this->gen_svnt_src_includes (this->ciao_svnt_source_);
1112 return 0;
1116 TAO_CodeGen::start_ciao_svnt_template_header (const char *fname)
1118 // Clean up between multiple files.
1119 delete this->ciao_svnt_template_header_;
1121 ACE_NEW_RETURN (this->ciao_svnt_template_header_,
1122 TAO_OutStream,
1123 -1);
1125 int status =
1126 this->ciao_svnt_template_header_->open (fname,
1127 TAO_OutStream::CIAO_SVNT_T_HDR);
1129 if (status == -1)
1131 ACE_ERROR_RETURN ((LM_ERROR,
1132 ACE_TEXT ("TAO_CodeGen::start_ciao_svnt_template_header - ")
1133 ACE_TEXT ("Error opening file\n")),
1134 -1);
1137 TAO_OutStream &os = *this->ciao_svnt_template_header_;
1139 TAO_INSERT_COMMENT (&os);
1141 // Generate the #ident string, if any.
1142 this->gen_ident_string (this->ciao_svnt_template_header_);
1144 // Generate the #ifndef clause.
1145 this->gen_ifndef_string (fname,
1146 this->ciao_svnt_template_header_,
1147 "CIAO_SERVANT_",
1148 "_H_");
1150 if (be_global->pre_include () != nullptr)
1152 os << "#include /**/ \""
1153 << be_global->pre_include ()
1154 << "\"\n";
1157 // All CIAO examples so far have component skeleton and servant
1158 // generated code in the same library, using the skel export macro,
1159 // so the values for the servant export default to the skel values.
1160 // Eventually, there should be a way to completely decouple them.
1161 if (be_global->svnt_export_include () != nullptr)
1163 os << "\n#include /**/ \""
1164 << be_global->svnt_export_include ()
1165 << "\"\n";
1167 else if (be_global->skel_export_include () != nullptr)
1169 os << "\n#include /**/ \""
1170 << be_global->skel_export_include ()
1171 << "\"\n";
1174 // Some compilers don't optimize the #ifndef header include
1175 // protection, but do optimize based on #pragma once.
1176 os << "\n#if !defined (ACE_LACKS_PRAGMA_ONCE)\n"
1177 << "# pragma once\n"
1178 << "#endif /* ACE_LACKS_PRAGMA_ONCE */\n\n";
1180 this->gen_svnt_tmpl_hdr_includes (this->ciao_svnt_template_header_);
1182 if (idl_global->ami_connector_seen_)
1184 *this->ciao_svnt_template_header_ << be_nl
1185 << "#include \""
1186 << "connectors/ami4ccm/ami4ccm/ami4ccm_svnt.h\""
1187 << be_nl;
1190 return 0;
1194 TAO_CodeGen::start_ciao_svnt_template_source (const char *fname)
1196 // Clean up between multiple files.
1197 delete this->ciao_svnt_template_source_;
1199 ACE_NEW_RETURN (this->ciao_svnt_template_source_,
1200 TAO_OutStream,
1201 -1);
1203 int status =
1204 this->ciao_svnt_template_source_->open (fname,
1205 TAO_OutStream::CIAO_SVNT_T_IMPL);
1207 if (status == -1)
1209 ACE_ERROR_RETURN ((LM_ERROR,
1210 ACE_TEXT ("TAO_CodeGen::")
1211 ACE_TEXT ("start_ciao_svnt_template_source - ")
1212 ACE_TEXT ("Error opening file\n")),
1213 -1);
1216 TAO_OutStream &os = *this->ciao_svnt_template_source_;
1218 TAO_INSERT_COMMENT (&os);
1220 // Generate the #ident string, if any.
1221 this->gen_ident_string (this->ciao_svnt_template_source_);
1223 // Generate the #ifndef clause.
1224 this->gen_ifndef_string (fname,
1225 this->ciao_svnt_template_source_,
1226 "CIAO_SERVANT_",
1227 "_CPP_");
1229 this->gen_svnt_src_includes (this->ciao_svnt_template_source_);
1231 return 0;
1234 TAO_OutStream *
1235 TAO_CodeGen::ciao_svnt_header ()
1237 return this->ciao_svnt_header_;
1240 TAO_OutStream *
1241 TAO_CodeGen::ciao_svnt_source ()
1243 return this->ciao_svnt_source_;
1246 TAO_OutStream *
1247 TAO_CodeGen::ciao_svnt_template_header ()
1249 return this->ciao_svnt_template_header_;
1252 TAO_OutStream *
1253 TAO_CodeGen::ciao_svnt_template_source ()
1255 return this->ciao_svnt_template_source_;
1259 TAO_CodeGen::start_ciao_exec_header (const char *fname)
1261 // Clean up between multiple files.
1262 delete this->ciao_exec_header_;
1264 ACE_NEW_RETURN (this->ciao_exec_header_,
1265 TAO_OutStream,
1266 -1);
1268 int status =
1269 this->ciao_exec_header_->open (fname,
1270 TAO_OutStream::CIAO_EXEC_HDR);
1272 if (status == -1)
1274 ACE_ERROR_RETURN ((LM_ERROR,
1275 ACE_TEXT ("TAO_CodeGen::start_ciao_exec_header - ")
1276 ACE_TEXT ("Error opening file\n")),
1277 -1);
1280 TAO_OutStream &os = *this->ciao_exec_header_;
1282 // Generate the #ident string, if any.
1283 this->gen_ident_string (this->ciao_exec_header_);
1285 // Generate the #ifndef clause.
1286 this->gen_ifndef_string (fname,
1287 this->ciao_exec_header_,
1288 "CIAO_",
1289 "_H_");
1291 if (be_global->pre_include () != nullptr)
1293 os << "#include /**/ \""
1294 << be_global->pre_include ()
1295 << "\"\n";
1298 this->gen_standard_include (
1299 this->ciao_exec_header_,
1300 be_global->be_get_ciao_exec_stub_hdr_fname (true));
1302 // Some compilers don't optimize the #ifndef header include
1303 // protection, but do optimize based on #pragma once.
1304 os << "\n\n#if !defined (ACE_LACKS_PRAGMA_ONCE)\n"
1305 << "# pragma once\n"
1306 << "#endif /* ACE_LACKS_PRAGMA_ONCE */\n";
1308 this->gen_exec_hdr_includes ();
1310 return 0;
1314 TAO_CodeGen::start_ciao_exec_source (const char *fname)
1316 // Clean up between multiple files.
1317 delete this->ciao_exec_source_;
1319 ACE_NEW_RETURN (this->ciao_exec_source_,
1320 TAO_OutStream,
1321 -1);
1323 int status =
1324 this->ciao_exec_source_->open (fname,
1325 TAO_OutStream::CIAO_EXEC_IMPL);
1326 if (status == -1)
1328 ACE_ERROR_RETURN ((LM_ERROR,
1329 ACE_TEXT ("TAO_CodeGen::")
1330 ACE_TEXT ("start_ciao_exec_source - ")
1331 ACE_TEXT ("Error opening file\n")),
1332 -1);
1335 // Generate the #ident string, if any.
1336 this->gen_ident_string (this->ciao_exec_source_);
1338 this->gen_exec_src_includes ();
1340 return 0;
1343 TAO_OutStream *
1344 TAO_CodeGen::ciao_exec_header ()
1346 return this->ciao_exec_header_;
1349 TAO_OutStream *
1350 TAO_CodeGen::ciao_exec_source ()
1352 return this->ciao_exec_source_;
1356 TAO_CodeGen::start_ciao_exec_idl (const char *fname)
1358 // Clean up between multiple files.
1359 delete this->ciao_exec_idl_;
1361 ACE_NEW_RETURN (this->ciao_exec_idl_,
1362 TAO_OutStream,
1363 -1);
1365 int status =
1366 this->ciao_exec_idl_->open (fname,
1367 TAO_OutStream::CIAO_EXEC_IDL);
1369 if (status == -1)
1371 ACE_ERROR_RETURN ((LM_ERROR,
1372 ACE_TEXT ("TAO_CodeGen::start_ciao_exec_idl - ")
1373 ACE_TEXT ("Error opening file\n")),
1374 -1);
1377 TAO_OutStream &os = *this->ciao_exec_idl_;
1379 os << be_nl;
1381 // Generate the #ifndef clause.
1382 this->gen_ifndef_string (fname,
1383 this->ciao_exec_idl_,
1384 "_CIAO_",
1385 "_IDL_");
1387 this->gen_exec_idl_includes ();
1389 return 0;
1392 TAO_OutStream *
1393 TAO_CodeGen::ciao_exec_idl ()
1395 return this->ciao_exec_idl_;
1399 TAO_CodeGen::start_ciao_conn_header (const char *fname)
1401 // Clean up between multiple files.
1402 delete this->ciao_conn_header_;
1404 ACE_NEW_RETURN (this->ciao_conn_header_,
1405 TAO_OutStream,
1406 -1);
1408 int status =
1409 this->ciao_conn_header_->open (fname,
1410 TAO_OutStream::CIAO_CONN_HDR);
1412 if (status == -1)
1414 ACE_ERROR_RETURN ((LM_ERROR,
1415 ACE_TEXT ("TAO_CodeGen::start_ciao_conn_header - ")
1416 ACE_TEXT ("Error opening file\n")),
1417 -1);
1420 TAO_OutStream &os = *this->ciao_conn_header_;
1422 TAO_INSERT_COMMENT (&os);
1424 // Generate the #ident string, if any.
1425 this->gen_ident_string (this->ciao_conn_header_);
1427 // Generate the #ifndef clause.
1428 this->gen_ifndef_string (fname,
1429 this->ciao_conn_header_,
1430 "CIAO_",
1431 "_H_");
1433 if (be_global->pre_include () != nullptr)
1435 os << "#include /**/ \""
1436 << be_global->pre_include ()
1437 << "\"\n";
1440 // This will almost certainly be true, but just in case...
1441 if (be_global->conn_export_include () != nullptr)
1443 this->gen_standard_include (
1444 this->ciao_conn_header_,
1445 be_global->conn_export_include (),
1446 true);
1449 // Some compilers don't optimize the #ifndef header include
1450 // protection, but do optimize based on #pragma once.
1451 os << "\n\n#if !defined (ACE_LACKS_PRAGMA_ONCE)\n"
1452 << "# pragma once\n"
1453 << "#endif /* ACE_LACKS_PRAGMA_ONCE */\n";
1455 this->gen_conn_hdr_includes ();
1457 return 0;
1460 TAO_OutStream *
1461 TAO_CodeGen::ciao_conn_header ()
1463 return this->ciao_conn_header_;
1467 TAO_CodeGen::start_ciao_conn_source (const char *fname)
1469 // Clean up between multiple files.
1470 delete this->ciao_conn_source_;
1472 ACE_NEW_RETURN (this->ciao_conn_source_,
1473 TAO_OutStream,
1474 -1);
1476 int status =
1477 this->ciao_conn_source_->open (fname,
1478 TAO_OutStream::CIAO_CONN_IMPL);
1480 if (status == -1)
1482 ACE_ERROR_RETURN ((LM_ERROR,
1483 ACE_TEXT ("TAO_CodeGen::")
1484 ACE_TEXT ("start_ciao_conn_source - ")
1485 ACE_TEXT ("Error opening file\n")),
1486 -1);
1489 TAO_OutStream &os = *this->ciao_conn_source_;
1491 TAO_INSERT_COMMENT (&os);
1493 // Generate the #ident string, if any.
1494 this->gen_ident_string (this->ciao_conn_source_);
1496 this->gen_conn_src_includes ();
1498 return 0;
1501 TAO_OutStream *
1502 TAO_CodeGen::ciao_conn_source ()
1504 return this->ciao_conn_source_;
1508 TAO_CodeGen::start_ciao_ami_conn_idl (const char *fname)
1510 // Clean up between multiple files.
1511 delete this->ciao_ami_conn_idl_;
1513 ACE_NEW_RETURN (this->ciao_ami_conn_idl_,
1514 TAO_OutStream,
1515 -1);
1517 int status =
1518 this->ciao_ami_conn_idl_->open (fname,
1519 TAO_OutStream::CIAO_AMI4CCM_CONN_IDL);
1521 if (status == -1)
1523 ACE_ERROR_RETURN ((LM_ERROR,
1524 ACE_TEXT ("TAO_CodeGen::start_ciao_ami_conn_idl - ")
1525 ACE_TEXT ("Error opening file\n")),
1526 -1);
1529 TAO_OutStream &os = *this->ciao_ami_conn_idl_;
1531 os << be_nl;
1533 // Generate the #ifndef clause.
1534 this->gen_ifndef_string (fname,
1535 this->ciao_ami_conn_idl_,
1536 "_CIAO_",
1537 "_IDL_");
1539 this->gen_ami_conn_idl_includes ();
1541 return 0;
1544 TAO_OutStream *
1545 TAO_CodeGen::ciao_ami_conn_idl ()
1547 return this->ciao_ami_conn_idl_;
1550 // Set the server header stream.
1552 TAO_CodeGen::start_implementation_header (const char *fname)
1554 // Clean up between multiple files.
1555 delete this->implementation_header_;
1557 ACE_NEW_RETURN (this->implementation_header_,
1558 TAO_OutStream,
1559 -1);
1561 if (this->implementation_header_->open (fname,
1562 TAO_OutStream::TAO_IMPL_HDR) == -1)
1564 return -1;
1567 TAO_INSERT_COMMENT (this->implementation_header_);
1569 // Generate the ident string, if any.
1570 this->gen_ident_string (this->implementation_header_);
1572 // Generate the #ifndef clause.
1573 this->gen_ifndef_string (fname,
1574 this->implementation_header_,
1576 "_H_");
1578 const char* server_hdr = BE_GlobalData::be_get_server_hdr_fname (true);
1580 *this->implementation_header_<< "#include \"" << server_hdr <<"\"";
1582 *this->implementation_header_
1583 << "\n\n#if !defined (ACE_LACKS_PRAGMA_ONCE)\n"
1584 << "#pragma once\n"
1585 << "#endif /* ACE_LACKS_PRAGMA_ONCE */\n\n";
1587 if (idl_global->local_iface_seen_)
1589 *this->implementation_header_ << "#include \"tao/LocalObject.h\"\n";
1591 return 0;
1595 // Get the implementation header stream.
1596 TAO_OutStream *
1597 TAO_CodeGen::implementation_header ()
1599 return this->implementation_header_;
1603 // Set the implementation skeleton stream.
1605 TAO_CodeGen::start_implementation_skeleton (const char *fname)
1607 // Clean up between multiple files.
1608 delete this->implementation_skeleton_;
1610 ACE_NEW_RETURN (this->implementation_skeleton_,
1611 TAO_OutStream,
1612 -1);
1614 if (this->implementation_skeleton_->open (fname,
1615 TAO_OutStream::TAO_IMPL_SKEL)
1616 == -1)
1618 return -1;
1621 TAO_INSERT_COMMENT (this->implementation_skeleton_);
1623 // Generate the ident string, if any.
1624 this->gen_ident_string (this->implementation_skeleton_);
1626 const char* impl_hdr =
1627 BE_GlobalData::be_get_implementation_hdr_fname ();
1629 this->implementation_skeleton_->print ("#include \"%s\"\n\n",
1630 impl_hdr);
1632 return 0;
1635 // Get the implementation header stream.
1636 TAO_OutStream *
1637 TAO_CodeGen::implementation_skeleton ()
1639 return this->implementation_skeleton_;
1642 // Put the last #endif in the client and server headers.
1644 TAO_CodeGen::end_client_header ()
1646 // Generate the <<= and >>= operators here.
1648 TAO_INSERT_COMMENT (this->client_header_);
1650 // End versioned namespace support before remaining include
1651 // directives at end of file.
1652 *this->client_header_ << be_global->versioning_end ();
1654 // Only when we generate a client inline file generate the include
1655 if (be_global->gen_client_inline ())
1657 // Insert the code to include the inline file.
1658 *this->client_header_ << "#if defined (__ACE_INLINE__)\n";
1659 *this->client_header_ << "#include \""
1660 << be_global->be_get_client_inline_fname (true)
1661 << "\"\n";
1662 *this->client_header_ << "#endif /* defined INLINE */\n\n";
1665 // Code to put the last #endif.
1667 if (be_global->post_include () != nullptr)
1669 *this->client_header_ << "#include /**/ \""
1670 << be_global->post_include ()
1671 << "\"\n\n";
1674 *this->client_header_ << "#endif /* ifndef */\n"
1675 << "\n";
1677 return 0;
1680 void
1681 TAO_CodeGen::end_client_inline ()
1683 *this->client_inline_ << "\n";
1685 // End versioned namespace support. Do not place include directives
1686 // before this.
1687 *this->client_inline_ << be_global->versioning_end ();
1689 *this->client_inline_ << "\n";
1692 void
1693 TAO_CodeGen::end_client_stubs ()
1695 *this->client_stubs_ << "\n";
1697 // End versioned namespace support. Do not place include directives
1698 // before this.
1699 *this->client_stubs_ << be_global->versioning_end ();
1701 *this->client_stubs_ << "\n";
1705 TAO_CodeGen::end_server_header ()
1707 TAO_OutStream *os = this->server_header_;
1709 // End versioned namespace support. Do not place include directives
1710 // before this.
1711 *os << be_global->versioning_end ();
1713 /// Otherwise just generate the post_include(), if any,
1714 /// and the #endif.
1715 if (be_global->gen_skel_files ())
1717 // Insert the template header.
1718 if (be_global->gen_tie_classes ())
1720 *os << "\n\n#include \""
1721 << be_global->be_get_server_template_hdr_fname (true)
1722 << "\"\n";
1726 if (be_global->post_include () != nullptr)
1728 *os << be_nl_2
1729 << "#include /**/ \""
1730 << be_global->post_include ()
1731 << "\"";
1734 *os << be_nl_2
1735 << "#endif /* ifndef */\n"
1736 << "\n";
1738 return 0;
1742 TAO_CodeGen::end_implementation_header (const char *fname)
1744 if (fname == nullptr)
1746 // Bad file name.
1747 return -1;
1750 const char *suffix = ACE_OS::strrchr (fname, '.');
1752 if (suffix == nullptr)
1754 // File seems to have no extension, so let us take the name
1755 // as it is.
1756 suffix = fname;
1759 char macro_name [NAMEBUFSIZE] = { 0 };
1761 // Convert letters in fname to upper case.
1762 for (int i = 0; i < (suffix - fname); ++i)
1764 if (ACE_OS::ace_isalpha (fname [i]))
1766 macro_name[i] = static_cast<char> (ACE_OS::ace_toupper (fname [i]));
1768 else if (ACE_OS::ace_isdigit (fname [i]))
1770 macro_name[i] = fname[i];
1772 else
1774 macro_name[i] = '_';
1778 ACE_OS::strcat (macro_name,
1779 "_H_");
1781 // Code to put the last #endif.
1782 this->implementation_header_->print ("\n#endif /* %s */\n",
1783 macro_name);
1784 return 0;
1788 TAO_CodeGen::end_server_template_header ()
1790 TAO_INSERT_COMMENT (this->server_template_header_);
1792 // End versioned namespace support. Do not place include directives
1793 // before this.
1794 *this->server_template_header_ << be_global->versioning_end ();
1796 // Insert the code to include the template source file.
1797 *this->server_template_header_
1798 << be_nl << "#include \""
1799 << be_global->be_get_server_template_skeleton_fname (true)
1800 << "\"";
1802 // Code to put the last #endif.
1803 *this->server_template_header_ << "\n\n";
1805 if (be_global->post_include () != nullptr)
1807 *this->server_template_header_ << "#include /**/ \""
1808 << be_global->post_include ()
1809 << "\"\n";
1812 *this->server_template_header_ << "#endif /* ifndef */\n"
1813 << "\n";
1814 return 0;
1818 TAO_CodeGen::end_server_template_skeletons ()
1820 // End versioned namespace support. Do not place include directives
1821 // before this.
1822 *this->server_template_skeletons_ << be_global->versioning_end ();
1824 // Code to put the last #endif.
1825 *this->server_template_skeletons_ << "\n#endif /* ifndef */\n"
1826 << "\n";
1828 return 0;
1832 TAO_CodeGen::end_server_skeletons ()
1834 // End versioned namespace support. Do not place include directives
1835 // before this.
1836 *this->server_skeletons_ << be_global->versioning_end ();
1838 // Code to put the last #endif.
1839 *this->server_skeletons_ << "\n\n#endif /* ifndef */\n"
1840 << "\n";
1842 return 0;
1846 TAO_CodeGen::end_anyop_header ()
1848 // End versioned namespace support. Do not place include directives
1849 // before this.
1850 *this->anyop_header_ << be_global->versioning_end ();
1853 if (be_global->post_include () != nullptr)
1855 *this->anyop_header_ << "\n\n#include /**/ \""
1856 << be_global->post_include ()
1857 << "\"";
1860 // Code to put the last #endif.
1861 *this->anyop_header_ << "\n\n#endif /* ifndef */\n";
1863 return 0;
1867 TAO_CodeGen::end_anyop_source ()
1869 // End versioned namespace support. Do not place include directives
1870 // before this.
1871 *this->anyop_source_ << be_global->versioning_end ();
1873 *this->anyop_source_ << "\n";
1875 return 0;
1879 TAO_CodeGen::end_ciao_svnt_header ()
1881 if (be_global->post_include () != nullptr)
1883 *this->ciao_svnt_header_ << "\n\n#include /**/ \""
1884 << be_global->post_include ()
1885 << "\"";
1888 *this->ciao_svnt_header_ << "\n\n#endif /* ifndef */\n";
1890 return 0;
1894 TAO_CodeGen::end_ciao_svnt_source ()
1896 *this->ciao_svnt_source_ << "\n";
1898 return 0;
1902 TAO_CodeGen::end_ciao_svnt_template_header ()
1904 *this->ciao_svnt_template_header_ << be_nl_2
1905 << "#include \""
1906 << be_global->be_get_ciao_tmpl_svnt_src_fname (true)
1907 << "\"" << be_nl;
1909 if (be_global->post_include () != nullptr)
1911 *this->ciao_svnt_template_header_ << "\n\n#include /**/ \""
1912 << be_global->post_include ()
1913 << "\"";
1916 *this->ciao_svnt_template_header_ << "\n\n#endif /* ifndef */\n";
1918 return 0;
1922 TAO_CodeGen::end_ciao_svnt_template_source ()
1924 *this->ciao_svnt_template_source_ << "\n\n#endif /* ifndef */\n";
1926 *this->ciao_svnt_template_source_ << "\n";
1928 return 0;
1932 TAO_CodeGen::end_ciao_exec_header ()
1934 if (be_global->post_include () != nullptr)
1936 *this->ciao_exec_header_ << "\n\n#include /**/ \""
1937 << be_global->post_include ()
1938 << "\"";
1941 *this->ciao_exec_header_ << "\n\n#endif /* ifndef */\n";
1943 return 0;
1947 TAO_CodeGen::end_ciao_exec_source ()
1949 *this->ciao_exec_source_ << "\n";
1951 return 0;
1955 TAO_CodeGen::end_ciao_exec_idl ()
1957 *this->ciao_exec_idl_ << "\n\n#endif /* ifndef */\n";
1959 return 0;
1963 TAO_CodeGen::end_ciao_conn_header ()
1965 if (be_global->post_include () != nullptr)
1967 *this->ciao_conn_header_ << "\n\n#include /**/ \""
1968 << be_global->post_include ()
1969 << "\"";
1972 *this->ciao_conn_header_ << "\n\n#endif /* ifndef */\n";
1974 return 0;
1978 TAO_CodeGen::end_ciao_conn_source ()
1980 *this->ciao_conn_source_ << "\n";
1982 return 0;
1986 TAO_CodeGen::end_ciao_ami_conn_idl ()
1988 *this->ciao_ami_conn_idl_ << "\n\n#endif /* ifndef */\n";
1990 return 0;
1993 // We use the following helper functions to pass information. This class is the
1994 // best place to pass such information rather than passing information through
1995 // global variables spread everywhere. This class is a singleton and is
1996 // effectively a global.
1998 void
1999 TAO_CodeGen::gperf_input_stream (TAO_OutStream *os)
2001 delete this->gperf_input_stream_;
2002 this->gperf_input_stream_ = os;
2005 TAO_OutStream *
2006 TAO_CodeGen::gperf_input_stream ()
2008 return this->gperf_input_stream_;
2011 void
2012 TAO_CodeGen::gperf_input_filename (char *filename)
2014 delete [] this->gperf_input_filename_;
2015 this->gperf_input_filename_ = filename;
2018 char *
2019 TAO_CodeGen::gperf_input_filename ()
2021 return this->gperf_input_filename_;
2024 void
2025 TAO_CodeGen::gen_ident_string (TAO_OutStream *stream) const
2027 const char *str = idl_global->ident_string ();
2029 if (str != nullptr)
2031 *stream << "#" << str << be_nl_2;
2035 void
2036 TAO_CodeGen::gen_export_files ()
2038 if (be_global->gen_stub_export_hdr_file ()
2039 && be_global->stub_export_macro () != nullptr
2040 && (be_global->stub_export_include () != nullptr || be_global->stub_export_file () != nullptr))
2042 this->gen_export_file (
2043 (be_global->stub_export_file () != nullptr) ? be_global->stub_export_file () : be_global->stub_export_include (),
2044 be_global->stub_export_macro (),
2045 "stub");
2048 if (be_global->gen_skel_export_hdr_file ()
2049 && be_global->skel_export_macro () != nullptr
2050 && be_global->skel_export_include () != nullptr)
2052 this->gen_export_file (
2053 (be_global->skel_export_file () != nullptr) ? be_global->skel_export_file () : be_global->skel_export_include (),
2054 be_global->skel_export_macro (),
2055 "skel",
2056 true);
2059 if (be_global->gen_svnt_export_hdr_file ()
2060 && be_global->svnt_export_macro () != nullptr
2061 && be_global->svnt_export_include () != nullptr)
2063 this->gen_export_file (
2064 be_global->svnt_export_include (),
2065 be_global->svnt_export_macro (),
2066 "svnt");
2069 if (be_global->gen_exec_export_hdr_file ()
2070 && be_global->exec_export_macro () != nullptr
2071 && be_global->exec_export_include () != nullptr)
2073 this->gen_export_file (
2074 be_global->exec_export_include (),
2075 be_global->exec_export_macro (),
2076 "exec");
2079 if (be_global->gen_conn_export_hdr_file ()
2080 && be_global->conn_export_macro () != nullptr
2081 && be_global->conn_export_include () != nullptr)
2083 this->gen_export_file (
2084 be_global->conn_export_include (),
2085 be_global->conn_export_macro (),
2086 "conn");
2090 void
2091 TAO_CodeGen::gen_export_file (const char *filename,
2092 const char *macro,
2093 const char *,
2094 bool for_skel)
2096 // Svnt export macro may correctly default to skel
2097 // export macro, so we just return silently. The
2098 // null filename check below will catch a real error.
2099 if (macro == nullptr)
2101 return;
2104 ACE_CString macro_str (macro);
2105 ACE_CString file_str;
2107 const char *output_path =
2108 be_util::get_output_path (false, for_skel, false);
2110 if (output_path != nullptr)
2112 // Turn '\' and '\\' into '/'.
2113 char* i = const_cast<char*> (output_path);
2115 for (const char* j = output_path; *j != 0; ++i, ++j)
2117 if (*j == '\\')
2119 *i = '/';
2121 if (*(j + 1) == '\\')
2123 ++j;
2126 else
2128 *i = *j;
2132 *i = 0;
2133 file_str += output_path;
2134 file_str += '/';
2137 file_str += filename;
2139 TAO_OutStream os;
2141 if (os.open (file_str.c_str ()) == -1)
2143 ACE_ERROR ((LM_ERROR,
2144 ACE_TEXT ("TAO_CodeGen::gen_export_file() - ")
2145 ACE_TEXT ("Error: file open failed on %C\n"),
2146 filename));
2147 return;
2150 ACE_CString suffix ("_Export");
2151 size_t stem_len =
2152 macro_str.length () - suffix.length ();
2154 if (macro_str.substr (stem_len) != suffix)
2156 ACE_ERROR ((LM_ERROR,
2157 ACE_TEXT ("TAO_CodeGen::gen_export_file() - ")
2158 ACE_TEXT ("Error: export macro %C does not end with ")
2159 ACE_TEXT ("\"_Export\""),
2160 macro));
2161 return;
2164 ACE_CString stem_str (macro_str.substr (0, stem_len));
2165 const char *stem = stem_str.c_str ();
2167 os << "\n#ifndef " << stem << "_EXPORT_H\n"
2168 << "#define " << stem << "_EXPORT_H\n\n"
2169 << "#include \"ace/config-all.h\"\n\n"
2170 << "#if defined (ACE_AS_STATIC_LIBS) && !defined (" << stem << "_HAS_DLL)\n"
2171 << "# define " << stem << "_HAS_DLL 0\n"
2172 << "#endif /* ACE_AS_STATIC_LIBS && " << stem << "_HAS_DLL */\n\n"
2173 << "#if !defined (" << stem << "_HAS_DLL)\n"
2174 << "# define " << stem << "_HAS_DLL 1\n"
2175 << "#endif /* ! " << stem << "_HAS_DLL */\n\n"
2176 << "#if defined (" << stem << "_HAS_DLL) && (" << stem << "_HAS_DLL == 1)\n"
2177 << "# if defined (" << stem << "_BUILD_DLL)\n"
2178 << "# define " << stem << "_Export ACE_Proper_Export_Flag\n"
2179 << "# define " << stem << "_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)\n"
2180 << "# define " << stem << "_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)\n"
2181 << "# else /* " << stem << "_BUILD_DLL */\n"
2182 << "# define " << stem << "_Export ACE_Proper_Import_Flag\n"
2183 << "# define " << stem << "_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)\n"
2184 << "# define " << stem << "_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)\n"
2185 << "# endif /* " << stem << "_BUILD_DLL */\n"
2186 << "#else /* " << stem << "_HAS_DLL == 1 */\n"
2187 << "# define " << stem << "_Export\n"
2188 << "# define " << stem << "_SINGLETON_DECLARATION(T)\n"
2189 << "# define " << stem << "_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)\n"
2190 << "#endif /* " << stem << "_HAS_DLL == 1 */\n\n"
2191 << "// Set " << stem << "_NTRACE = 0 to turn on library-specific\n"
2192 << "// tracing even if tracing is turned off for ACE.\n"
2193 << "#if !defined (" << stem << "_NTRACE)\n"
2194 << "# if (ACE_NTRACE == 1)\n"
2195 << "# define " << stem << "_NTRACE 1\n"
2196 << "# else /* (ACE_NTRACE == 1) */\n"
2197 << "# define " << stem << "_NTRACE 0\n"
2198 << "# endif /* (ACE_NTRACE == 1) */\n"
2199 << "#endif /* !" << stem << "_NTRACE */\n\n"
2200 << "#if (" << stem << "_NTRACE == 1)\n"
2201 << "# define " << stem << "_TRACE(X)\n"
2202 << "#else /* (" << stem << "_NTRACE == 1) */\n"
2203 << "# if !defined (ACE_HAS_TRACE)\n"
2204 << "# define ACE_HAS_TRACE\n"
2205 << "# endif /* ACE_HAS_TRACE */\n"
2206 << "# define " << stem << "_TRACE(X) ACE_TRACE_IMPL(X)\n"
2207 << "# include \"ace/Trace.h\"\n"
2208 << "#endif /* (" << stem << "_NTRACE == 1) */\n\n"
2209 << "#endif /* " << stem << "_EXPORT_H */\n\n";
2212 void
2213 TAO_CodeGen::gen_standard_include (TAO_OutStream *stream,
2214 const char *included_file,
2215 bool add_comment)
2217 // Switch between changing or non-changing standard include files
2218 // include files, so that #include statements can be
2219 // generated with ""s or <>s respectively, for the standard include
2220 // files (e.g. tao/corba.h).
2222 const char *start_delimiter = "\"";
2223 const char *end_delimiter = "\"";
2225 if (be_global->changing_standard_include_files () == 0)
2227 start_delimiter = "<";
2228 end_delimiter = ">";
2231 *stream << "\n#include ";
2233 if (add_comment)
2235 *stream << "/**/ ";
2238 *stream << start_delimiter
2239 << included_file
2240 << end_delimiter;
2243 void
2244 TAO_CodeGen::gen_ifndef_string (const char *fname,
2245 TAO_OutStream *stream,
2246 const char *prefix,
2247 const char *suffix)
2249 char macro_name [NAMEBUFSIZE] = { 0 };
2251 const char *extension = ACE_OS::strrchr (fname, '.');
2253 if (extension == nullptr)
2255 // File seems to have no extension, so let us take the name
2256 // as it is.
2257 extension = fname;
2260 ACE_OS::sprintf (macro_name, "%s", prefix);
2262 size_t offset = ACE_OS::strlen (prefix);
2264 // Convert letters in fname to upper case.
2265 for (int i = 0; i < (extension - fname); i++)
2267 if (ACE_OS::ace_isalpha (fname [i]))
2269 macro_name[i + offset] = static_cast<char> (ACE_OS::ace_toupper (fname [i]));
2271 else if (ACE_OS::ace_isdigit (fname [i]))
2273 macro_name[i + offset] = fname[i];
2275 else
2277 macro_name[i + offset] = '_';
2281 if (be_global->gen_unique_guards ())
2283 ACE_OS::strcat (macro_name, "_XXXXXX");
2284 char * const t = ACE_OS::strstr (macro_name, "XXXXXX");
2286 this->make_rand_extension (t);
2289 ACE_OS::strcat (macro_name, suffix);
2291 // Generate the #ifndef ... #define statements.
2292 stream->print ("#ifndef %s\n",
2293 macro_name);
2294 stream->print ("#define %s\n\n",
2295 macro_name);
2298 void
2299 TAO_CodeGen::gen_stub_hdr_includes ()
2301 // Include valuetype and Any/TypeCode headers before ORB core
2302 // headers to make sure some things are parsed before some templates
2303 // (e.g. TAO_Pseudo_{Var,Out}_T). Addresses issues with compilers
2304 // that require all necessary non-dependent names be parsed prior to
2305 // parsing templates that may use them (e.g. GNU g++ 3.4.x).
2307 this->gen_cond_file_include (be_global->tc_support ()
2308 && !be_global->gen_anyop_files (),
2309 "tao/AnyTypeCode/AnyTypeCode_methods.h",
2310 this->client_header_);
2312 this->gen_cond_file_include (be_global->tc_support ()
2313 && !be_global->gen_anyop_files (),
2314 "tao/AnyTypeCode/Any.h",
2315 this->client_header_);
2318 if (idl_global->abstract_iface_seen_ || idl_global->abstractbase_seen_)
2320 // Include the AbstractBase file from the Valuetype library.
2321 this->gen_standard_include (this->client_header_,
2322 "tao/Valuetype/AbstractBase.h");
2324 if (idl_global->abstract_iface_seen_)
2326 // Turn on generation of the rest of the Valuetype library includes.
2327 idl_global->valuetype_seen_ = true;
2331 if (idl_global->valuebase_seen_)
2333 // Include files from the Valuetype library.
2334 this->gen_standard_include (this->client_header_,
2335 "tao/Valuetype/ValueBase.h");
2337 // Valuebox needs CDR for _tao_marshal_v code in .inl file
2338 this->gen_standard_include (this->client_header_,
2339 "tao/CDR.h");
2342 if (idl_global->valuetype_seen_)
2344 // Don't want to generate this twice.
2345 if (!idl_global->valuebase_seen_)
2347 this->gen_standard_include (this->client_header_,
2348 "tao/Valuetype/ValueBase.h");
2351 this->gen_standard_include (this->client_header_,
2352 "tao/Valuetype/Valuetype_Adapter_Factory_Impl.h");
2354 // Check for setting this bit performed in y.tab.cpp, actual checking
2355 // code is in be_valuetype.cpp.
2356 this->gen_cond_file_include (
2357 idl_global->valuefactory_seen_,
2358 "tao/Valuetype/ValueFactory.h",
2359 this->client_header_
2363 // @note This header should not go first. See the discussion above
2364 // regarding non-dependent template names.
2365 this->gen_cond_file_include (
2366 be_global->gen_orb_h_include (),
2367 "tao/ORB.h",
2368 this->client_header_
2371 this->gen_cond_file_include (
2372 idl_global->operation_seen_ || idl_global->valuefactory_seen_
2373 || idl_global->valuebase_seen_,
2374 "tao/SystemException.h",
2375 this->client_header_
2378 // For IDL exception, we need full knowledge of CORBA::UserException.
2379 this->gen_cond_file_include (
2380 idl_global->exception_seen_,
2381 "tao/UserException.h",
2382 this->client_header_
2385 const bool idl4 = idl_global->idl_version_ >= IDL_VERSION_4;
2386 this->gen_standard_include (this->client_header_,
2387 idl4 ? "tao/Basic_Types_IDLv4.h" : "tao/Basic_Types.h");
2388 if (idl4)
2390 *client_header_ <<
2391 BE_GlobalData::core_versioned_ns_begin << "\n"
2392 "namespace CORBA\n"
2393 "{\n"
2394 " using namespace IDLv4;\n"
2395 "}\n" <<
2396 BE_GlobalData::core_versioned_ns_end;
2399 // May need ORB_Constants if users check SystemException minor
2400 // codes.
2401 this->gen_cond_file_include (
2402 idl_global->operation_seen_ || idl_global->valuefactory_seen_
2403 || idl_global->valuebase_seen_,
2404 "tao/ORB_Constants.h",
2405 this->client_header_
2408 // Conditionally included.
2409 if (idl_global->dds_connector_seen_)
2411 BE_GlobalData::DDS_IMPL const the_dds_impl =
2412 be_global->dds_impl ();
2414 if (the_dds_impl == BE_GlobalData::OPENDDS)
2416 ACE_Unbounded_Queue<char *> &ts_files =
2417 idl_global->ciao_oci_ts_file_names ();
2418 char **tmp = nullptr;
2420 for (ACE_Unbounded_Queue_Iterator<char *> i (ts_files);
2421 !i.done ();
2422 i.advance ())
2424 i.next (tmp);
2425 this->gen_standard_include (this->client_header_,
2426 *tmp);
2432 // DDS/DCPS zero-copy read sequence type support.
2433 if (idl_global->dcps_support_zero_copy_read ())
2435 // include needed for sample info template instantiation.
2436 this->gen_cond_file_include (
2437 true, // for Infrastructure.idl as well as Foo types
2438 "dds/DCPS/ZeroCopyInfoSeq_T.h",
2439 this->client_header_
2441 // include needed for type specific sample sequence template instantitation.
2442 this->gen_cond_file_include (
2443 idl_global->dcps_gen_zero_copy_read (),
2444 "dds/DCPS/ZeroCopySeq_T.h",
2445 this->client_header_
2449 // Non-abstract interface or keyword 'Object'.
2450 this->gen_cond_file_include (
2451 idl_global->non_local_iface_seen_
2452 | idl_global->local_iface_seen_
2453 | idl_global->base_object_seen_,
2454 "tao/Object.h",
2455 this->client_header_);
2457 // This is true if we have a typecode or TCKind in the IDL file.
2458 // If not included here, it will appear in *C.cpp, if TCs not suppressed.
2459 this->gen_cond_file_include (
2460 idl_global->typecode_seen_
2461 | idl_global->any_seen_,
2462 "tao/AnyTypeCode/TypeCode.h",
2463 this->client_header_);
2465 this->gen_cond_file_include (
2466 idl_global->any_seen_
2467 | idl_global->typecode_seen_,
2468 "tao/AnyTypeCode/TypeCode_Constants.h",
2469 this->client_header_);
2471 // This is true if we have an 'any' in the IDL file.
2472 // If not included here, it will appear in *C.cpp, if Anys not suppressed.
2473 this->gen_cond_file_include (
2474 idl_global->any_seen_,
2475 "tao/AnyTypeCode/Any.h",
2476 this->client_header_);
2478 // Generated if (w)string member of struct/union/exception/array/valuetype
2479 // has been seen.
2480 this->gen_cond_file_include (idl_global->string_member_seen_,
2481 "tao/String_Manager_T.h",
2482 this->client_header_);
2484 // Include the Messaging library entry point, if AMI is enabled.
2485 if (be_global->ami_call_back ())
2487 // Include Messaging skeleton file.
2488 this->gen_standard_include (this->client_header_,
2489 "tao/Messaging/Messaging.h");
2492 // Include the AMI4CCM library entry point, if AMI4CCM is enabled.
2493 if (be_global->ami4ccm_call_back ())
2495 // Include Messaging skeleton file.
2496 this->gen_standard_include (this->client_header_,
2497 "connectors/ami4ccm/ami4ccm/ami4ccm.h");
2500 // Include the smart proxy base class if smart proxies are enabled.
2501 if (be_global->gen_smart_proxies ())
2503 this->gen_standard_include (this->client_header_,
2504 "tao/SmartProxies/Smart_Proxies.h");
2507 // If we have not suppressed Any operator generation and also
2508 // are not generating the operators in a separate file, we
2509 // need to include the *A.h file from all .pidl files here.
2510 if (be_global->any_support () && !be_global->gen_anyop_files ())
2512 for (size_t j = 0; j < idl_global->n_included_idl_files (); ++j)
2514 char * const idl_name = idl_global->included_idl_files ()[j];
2516 ACE_CString pidl_checker (idl_name);
2517 bool const got_pidl =
2518 (pidl_checker.substr (pidl_checker.length () - 5) == ".pidl");
2520 // If we're here and we have a .pidl file, we need to generate
2521 // the *A.h include from the AnyTypeCode library.
2522 if (got_pidl)
2524 // Make a String out of it.
2525 UTL_String idl_name_str = idl_name;
2527 char const * const anyop_hdr =
2528 BE_GlobalData::be_get_anyop_header (&idl_name_str, true);
2530 idl_name_str.destroy ();
2532 // Stripped off any scope in the name and add the
2533 // AnyTypeCode prefix.
2534 ACE_CString work_hdr (anyop_hdr);
2535 ACE_CString final_hdr = "tao/AnyTypeCode/";
2536 ACE_CString::size_type const pos = work_hdr.rfind ('/');
2538 if (pos != ACE_CString::npos)
2540 ACE_CString scope (work_hdr.substr (0, pos));
2542 // If we find a '/' in the containing scope name, it
2543 // means we are including a .pidl file from a
2544 // subdirectory of $TAO_ROOT/tao, and so we should
2545 // include the anyop_hdr string as is, and not strip
2546 // off the scope name and prepend "tao/AnyTypeCode/".
2547 // Only .pidl files in $TAO_ROOT/tao itself have
2548 // their generated *A.* files moved to the AnyTypeCode
2549 // library.
2550 if (scope.find ('/') == ACE_CString::npos)
2552 work_hdr = work_hdr.substr (pos + 1);
2553 final_hdr += work_hdr;
2555 else
2557 final_hdr = work_hdr;
2561 this->client_header_->print ("\n#include \"%s\"",
2562 final_hdr.c_str ());
2568 // Must have knowledge of the base class.
2569 this->gen_seq_file_includes ();
2571 // _vars and _outs are typedefs of template class instantiations.
2572 this->gen_var_file_includes ();
2574 if (be_global->gen_arg_traits ())
2576 // Includes whatever arg helper template classes that may be needed.
2577 this->gen_stub_arg_file_includes (this->client_header_);
2580 // Version file, for code that checks needs for regeneration.
2581 this->gen_standard_include (this->client_header_,
2582 "tao/Version.h",
2583 true);
2585 // Versioned namespace support.
2586 this->gen_standard_include (this->client_header_,
2587 "tao/Versioned_Namespace.h",
2588 true);
2590 if ((be_global->versioning_include () != nullptr) && (ACE_OS::strlen (be_global->versioning_include ()) > 0))
2592 this->gen_standard_include (this->client_header_,
2593 be_global->versioning_include (),
2594 true);
2597 // On some platforms, this include isn't needed if certain command
2598 // line options are present. Rather than try to sort that all out,
2599 // and to keep cross-compiling robust, we always generate this
2600 // include if gen_ostream_operators_ is true.
2601 if (be_global->gen_ostream_operators ())
2603 this->gen_standard_include (this->client_header_,
2604 "ace/streams.h");
2608 void
2609 TAO_CodeGen::gen_stub_src_includes ()
2611 // Generate the include statement for the precompiled header file.
2612 if (be_global->pch_include ())
2614 *this->client_stubs_ << "#include \""
2615 << be_global->pch_include ()
2616 << "\"";
2619 if (be_global->safe_include ())
2621 // Generate the safe include if it is defined instead of the client header
2622 // need to put only the base names. Path info is not required.
2623 *this->client_stubs_ << "\n#include \""
2624 << be_global->safe_include ()
2625 << "\"";
2627 else
2629 // Generate the include statement for the client header. We just
2630 // need to put only the base names. Path info is not required.
2631 *this->client_stubs_ << "\n#include \""
2632 << be_global->be_get_client_hdr_fname (true)
2633 << "\"";
2636 if (be_global->tc_support ()
2637 && !be_global->gen_anyop_files ())
2639 this->gen_typecode_includes (this->client_stubs_);
2642 // Always generated.
2643 this->gen_standard_include (this->client_stubs_,
2644 "tao/CDR.h");
2646 // Conditional includes.
2648 if (idl_global->non_local_op_seen_)
2650 this->gen_standard_include (this->client_stubs_,
2651 "tao/Exception_Data.h");
2654 // Operations for local interfaces are pure virtual.
2655 if (idl_global->non_local_op_seen_)
2657 this->gen_standard_include (this->client_stubs_,
2658 "tao/Invocation_Adapter.h");
2661 // Any abstract interface present will probably have an operation.
2662 if (idl_global->abstract_iface_seen_)
2664 this->gen_standard_include (
2665 this->client_stubs_,
2666 "tao/Valuetype/AbstractBase_Invocation_Adapter.h"
2669 this->gen_standard_include (
2670 this->client_stubs_,
2671 "tao/Valuetype/AbstractBase_T.h"
2675 if (be_global->ami_call_back () == true)
2677 this->gen_standard_include (this->client_stubs_,
2678 "tao/Messaging/Asynch_Invocation_Adapter.h");
2680 this->gen_standard_include (this->client_stubs_,
2681 "tao/Messaging/ExceptionHolder_i.h");
2684 // If valuefactory_seen_ was set, this was generated in the stub header file,
2685 // otherwise it needs to go here - used in _tao_unmarshal().
2686 if (idl_global->valuetype_seen_
2687 && !idl_global->valuefactory_seen_)
2689 this->gen_standard_include (this->client_stubs_,
2690 "tao/Valuetype/ValueFactory.h");
2693 if (idl_global->non_local_iface_seen_)
2695 // Needed for _narrow(), which is now template-based.
2696 this->gen_standard_include (this->client_stubs_,
2697 "tao/Object_T.h");
2700 if (idl_global->octet_seq_seen_)
2702 // Needed for the TAO_NO_COPY_OCTET_SEQUENCES optimization. Note that
2703 // it is preferable to just refer to CORBA::OctetSeq in the IDL file.
2704 this->gen_standard_include (this->client_stubs_,
2705 "tao/ORB_Core.h");
2708 // The UserException::_tao_{en,de}code() methods can throw a
2709 // CORBA::MARSHAL exception so make sure that system exception is
2710 // fully declared/defined by including "tao/SystemException.h".
2711 if (idl_global->exception_seen_)
2713 this->gen_standard_include (this->client_stubs_,
2714 "tao/SystemException.h");
2717 // Includes whatever Any template classes that may be needed.
2718 if (!be_global->gen_anyop_files ())
2720 this->gen_any_file_includes (this->client_stubs_);
2723 if (be_global->alt_mapping () && idl_global->seq_seen_)
2725 this->gen_standard_include (this->client_stubs_,
2726 "tao/Vector_CDR_T.h");
2728 if (be_global->any_support ())
2730 this->gen_standard_include (
2731 this->client_stubs_,
2732 "tao/AnyTypeCode/Vector_AnyOp_T.h");
2736 // strcmp() is used with interfaces and exceptions.
2737 if (idl_global->interface_seen_
2738 || idl_global->exception_seen_
2739 || idl_global->union_seen_)
2741 // Needed for _narrow(), which is now template-based.
2742 this->gen_standard_include (this->client_stubs_,
2743 "cstring");
2746 if (be_global->gen_amh_classes ())
2748 this->gen_standard_include (this->client_stubs_,
2749 "memory");
2753 void
2754 TAO_CodeGen::gen_skel_hdr_includes ()
2756 // Include the definitions for the PortableServer namespace,
2757 // this forces the application to link the POA library, a good
2758 // thing, because we need the definitions there, it also
2759 // registers the POA factory with the Service_Configurator, so
2760 // the ORB can automatically find it.
2761 if (idl_global->non_local_iface_seen_)
2763 // Include the Messaging files if AMI is enabled.
2764 if (be_global->ami_call_back () == true)
2766 // Include Messaging skeleton file.
2767 this->gen_standard_include (this->server_header_,
2768 "tao/Messaging/MessagingS.h");
2771 this->gen_standard_include (this->server_header_,
2772 "tao/PortableServer/PortableServer.h");
2773 this->gen_standard_include (this->server_header_,
2774 "tao/PortableServer/Servant_Base.h");
2776 if (be_global->gen_amh_classes ())
2778 this->gen_standard_include (this->server_header_,
2779 "tao/Messaging/AMH_Response_Handler.h");
2784 void
2785 TAO_CodeGen::gen_skel_src_includes ()
2787 // Only non-local interfaces generate anything in the skeleton.
2788 if (!(idl_global->non_local_iface_seen_
2789 || idl_global->need_skeleton_includes_))
2791 return;
2794 switch (be_global->lookup_strategy ())
2796 case BE_GlobalData::TAO_DYNAMIC_HASH:
2798 this->gen_standard_include (
2799 this->server_skeletons_,
2800 "tao/PortableServer/Operation_Table_Dynamic_Hash.h");
2802 break;
2803 case BE_GlobalData::TAO_LINEAR_SEARCH:
2805 this->gen_standard_include (
2806 this->server_skeletons_,
2807 "tao/PortableServer/Operation_Table_Linear_Search.h");
2809 break;
2810 case BE_GlobalData::TAO_BINARY_SEARCH:
2812 this->gen_standard_include (
2813 this->server_skeletons_,
2814 "tao/PortableServer/Operation_Table_Binary_Search.h");
2816 break;
2817 case BE_GlobalData::TAO_PERFECT_HASH:
2819 this->gen_standard_include (
2820 this->server_skeletons_,
2821 "tao/PortableServer/Operation_Table_Perfect_Hash.h");
2823 break;
2826 if (be_global->gen_direct_collocation ())
2828 this->gen_standard_include (
2829 this->server_skeletons_,
2830 "tao/PortableServer/Direct_Collocation_Upcall_Wrapper.h"
2834 if (be_global->ami_call_back () == true)
2836 this->gen_standard_include (this->server_skeletons_,
2837 "tao/Exception_Data.h");
2838 this->gen_standard_include (this->server_skeletons_,
2839 "tao/Messaging/ExceptionHolder_i.h");
2842 this->gen_standard_include (this->server_skeletons_,
2843 "tao/PortableServer/Upcall_Command.h");
2844 this->gen_standard_include (this->server_skeletons_,
2845 "tao/PortableServer/Upcall_Wrapper.h");
2847 this->gen_standard_include (this->server_skeletons_,
2848 "tao/TAO_Server_Request.h");
2849 this->gen_standard_include (this->server_skeletons_,
2850 "tao/ORB_Core.h");
2851 this->gen_standard_include (this->server_skeletons_,
2852 "tao/Profile.h");
2853 this->gen_standard_include (this->server_skeletons_,
2854 "tao/Stub.h");
2855 this->gen_standard_include (this->server_skeletons_,
2856 "tao/IFR_Client_Adapter.h");
2857 this->gen_standard_include (this->server_skeletons_,
2858 "tao/Object_T.h");
2859 this->gen_standard_include (this->server_skeletons_,
2860 "tao/AnyTypeCode/TypeCode.h");
2861 this->gen_standard_include (this->server_skeletons_,
2862 "tao/AnyTypeCode/DynamicC.h");
2863 this->gen_standard_include (this->server_skeletons_,
2864 "tao/CDR.h");
2865 this->gen_standard_include (this->server_skeletons_,
2866 "tao/operation_details.h");
2867 this->gen_standard_include (this->server_skeletons_,
2868 "tao/PortableInterceptor.h");
2870 // The following header must always be included.
2871 if (be_global->gen_amh_classes ())
2873 this->gen_standard_include (this->server_skeletons_,
2874 "tao/Thread_Lane_Resources.h");
2875 this->gen_standard_include (this->server_skeletons_,
2876 "tao/Buffer_Allocator_T.h");
2877 this->gen_standard_include (this->server_skeletons_,
2878 "tao/Messaging/AMH_Skeletons.h");
2879 this->gen_standard_include (this->server_skeletons_,
2880 "ace/Auto_Functor.h");
2883 this->gen_standard_include (this->server_skeletons_,
2884 "ace/Dynamic_Service.h");
2886 // For Static_Allocator_Base
2887 this->gen_standard_include (this->server_skeletons_,
2888 "ace/Malloc_Allocator.h");
2890 // For std::strcmp
2891 this->gen_standard_include (this->server_skeletons_,
2892 "cstring");
2895 void
2896 TAO_CodeGen::gen_seq_file_includes ()
2898 // @@@ (JP) These can get more specialized, after the TAO seq template
2899 // files have been split up.
2901 this->gen_cond_file_include (
2902 idl_global->vt_seq_seen_,
2903 "tao/Valuetype/Sequence_T.h",
2904 this->client_header_
2907 this->gen_cond_file_include (
2908 idl_global->seq_seen_,
2909 "tao/Sequence_T.h",
2910 this->client_header_
2914 void
2915 TAO_CodeGen::gen_any_file_includes (TAO_OutStream * stream)
2917 if (be_global->any_support ())
2919 this->gen_standard_include (stream,
2920 "tao/CDR.h");
2922 // Any_Impl_T.cpp needs the full CORBA::Any type.
2923 this->gen_cond_file_include (
2924 idl_global->interface_seen_
2925 | idl_global->valuetype_seen_,
2926 "tao/AnyTypeCode/Any.h",
2927 stream
2930 this->gen_cond_file_include (
2931 idl_global->interface_seen_
2932 | idl_global->valuetype_seen_,
2933 "tao/AnyTypeCode/Any_Impl_T.h",
2934 stream
2937 this->gen_cond_file_include (
2938 idl_global->aggregate_seen_
2939 | idl_global->seq_seen_
2940 | idl_global->exception_seen_,
2941 "tao/AnyTypeCode/Any_Dual_Impl_T.h",
2942 stream
2945 this->gen_cond_file_include (
2946 idl_global->array_seen_,
2947 "tao/AnyTypeCode/Any_Array_Impl_T.h",
2948 stream
2951 this->gen_cond_file_include (
2952 idl_global->enum_seen_,
2953 "tao/AnyTypeCode/Any_Basic_Impl_T.h",
2954 stream
2959 void
2960 TAO_CodeGen::gen_var_file_includes ()
2962 this->gen_cond_file_include (
2963 idl_global->valuetype_seen_
2964 | idl_global->fwd_valuetype_seen_,
2965 "tao/Valuetype/Value_VarOut_T.h",
2966 this->client_header_
2969 this->gen_cond_file_include (
2970 idl_global->interface_seen_
2971 | idl_global->fwd_iface_seen_,
2972 "tao/Objref_VarOut_T.h",
2973 this->client_header_
2976 this->gen_cond_file_include (
2977 idl_global->seq_seen_,
2978 "tao/Seq_Var_T.h",
2979 this->client_header_
2982 this->gen_cond_file_include (
2983 idl_global->seq_seen_,
2984 "tao/Seq_Out_T.h",
2985 this->client_header_
2988 this->gen_cond_file_include (
2989 idl_global->aggregate_seen_,
2990 "tao/VarOut_T.h",
2991 this->client_header_
2994 this->gen_cond_file_include (
2995 idl_global->array_seen_,
2996 "tao/Array_VarOut_T.h",
2997 this->client_header_
3001 void
3002 TAO_CodeGen::gen_stub_arg_file_includes (TAO_OutStream * stream)
3004 this->gen_standard_include (
3005 stream,
3006 "tao/Arg_Traits_T.h");
3008 this->gen_standard_include (
3009 stream,
3010 "tao/Basic_Arguments.h");
3012 this->gen_standard_include (
3013 stream,
3014 "tao/Special_Basic_Arguments.h");
3016 this->gen_standard_include (
3017 stream,
3018 "tao/Any_Insert_Policy_T.h");
3020 this->gen_cond_file_include (
3021 idl_global->enum_seen_,
3022 "tao/Basic_Argument_T.h",
3023 stream
3026 this->gen_standard_include (
3027 stream,
3028 "tao/Fixed_Size_Argument_T.h");
3030 this->gen_standard_include (
3031 stream,
3032 "tao/Var_Size_Argument_T.h");
3034 this->gen_cond_file_include (
3035 idl_global->bd_string_seen_,
3036 "tao/BD_String_Argument_T.h",
3037 stream
3040 be_global->changing_standard_include_files (0);
3041 this->gen_cond_file_include (
3042 idl_global->map_seen_,
3043 "map",
3044 stream
3046 be_global->changing_standard_include_files (1);
3048 // If we have a bound string and we have any generation enabled we must
3049 // include Any.h to get the <<= operator for BD_String
3050 this->gen_cond_file_include (
3051 idl_global->bd_string_seen_ && be_global->any_support (),
3052 "tao/AnyTypeCode/Any.h",
3053 stream
3056 this->gen_cond_file_include (
3057 idl_global->non_local_iface_seen_
3058 || idl_global->non_local_fwd_iface_seen_
3059 || be_global->ami_call_back ()
3060 || be_global->gen_amh_classes ()
3061 || be_global->ami4ccm_call_back (),
3062 "tao/Object_Argument_T.h",
3063 stream
3066 this->gen_cond_file_include (
3067 idl_global->special_basic_decl_seen_,
3068 "tao/Special_Basic_Arguments.h",
3069 stream
3072 this->gen_cond_file_include (
3073 idl_global->ub_string_seen_,
3074 "tao/UB_String_Arguments.h",
3075 stream
3078 this->gen_cond_file_include (
3079 idl_global->array_seen_,
3080 "tao/Fixed_Array_Argument_T.h",
3081 stream
3084 this->gen_cond_file_include (
3085 idl_global->array_seen_,
3086 "tao/Var_Array_Argument_T.h",
3087 stream
3090 this->gen_cond_file_include (
3091 idl_global->seq_seen_ && be_global->alt_mapping (),
3092 "tao/Vector_Argument_T.h",
3093 stream
3096 this->gen_cond_file_include (
3097 idl_global->any_arg_seen_,
3098 "tao/AnyTypeCode/Any_Arg_Traits.h",
3099 stream
3103 void
3104 TAO_CodeGen::gen_skel_arg_file_includes (TAO_OutStream * stream)
3106 this->gen_standard_include (
3107 stream,
3108 "tao/PortableServer/Basic_SArguments.h");
3110 this->gen_standard_include (
3111 stream,
3112 "tao/PortableServer/Special_Basic_SArguments.h");
3114 this->gen_cond_file_include (
3115 idl_global->bd_string_seen_,
3116 "tao/PortableServer/BD_String_SArgument_T.h",
3117 stream
3120 this->gen_standard_include (
3121 stream,
3122 "tao/PortableServer/Fixed_Size_SArgument_T.h");
3124 this->gen_standard_include (
3125 stream,
3126 "tao/PortableServer/Var_Size_SArgument_T.h");
3128 // If we have a bound string and we have any generation enabled we must
3129 // include Any.h to get the <<= operator for BD_String
3130 this->gen_cond_file_include (
3131 idl_global->bd_string_seen_ && be_global->any_support (),
3132 "tao/AnyTypeCode/Any.h",
3133 stream
3136 // Always needed for CORBA::Object handling in _component() skeleton
3137 // code when an unconstrained (non-local) IDL interface is defined.
3138 this->gen_cond_file_include (
3139 idl_global->non_local_iface_seen_
3140 || idl_global->non_local_fwd_iface_seen_
3141 || idl_global->valuetype_seen_
3142 || be_global->ami_call_back ()
3143 || be_global->gen_amh_classes ()
3144 || be_global->ami4ccm_call_back (),
3145 "tao/PortableServer/Object_SArg_Traits.h",
3146 stream);
3148 // Always needed for CORBA::Boolean handling in _is_a() skeleton
3149 // code when an unconstrained (non-local) IDL interface is defined.
3150 this->gen_cond_file_include (
3151 idl_global->special_basic_decl_seen_,
3152 "tao/PortableServer/Special_Basic_SArguments.h",
3153 stream
3156 // Always needed for string argument handling in _is_a() skeleton
3157 // code when an unconstrained (non-local) IDL interface is defined.
3158 this->gen_cond_file_include (
3159 idl_global->ub_string_seen_
3160 || idl_global->non_local_iface_seen_,
3161 "tao/PortableServer/UB_String_SArguments.h",
3162 stream
3165 this->gen_cond_file_include (
3166 idl_global->array_seen_,
3167 "tao/PortableServer/Fixed_Array_SArgument_T.h",
3168 stream
3171 this->gen_cond_file_include (
3172 idl_global->array_seen_,
3173 "tao/PortableServer/Var_Array_SArgument_T.h",
3174 stream
3177 this->gen_cond_file_include (
3178 idl_global->seq_seen_ && be_global->alt_mapping (),
3179 "tao/PortableServer/Vector_SArgument_T.h",
3180 stream
3183 this->gen_cond_file_include (
3184 idl_global->any_arg_seen_,
3185 "tao/PortableServer/Any_SArg_Traits.h",
3186 stream
3189 // Non-abstract interface or keyword 'Object'.
3190 this->gen_cond_file_include (
3191 idl_global->object_arg_seen_,
3192 "tao/PortableServer/Object_SArg_Traits.h",
3193 stream);
3195 // This is true if we have a typecode or TCKind in the IDL file.
3196 // If not included here, it will appear in *C.cpp, if TCs not suppressed.
3197 this->gen_cond_file_include (
3198 idl_global->typecode_seen_,
3199 "tao/PortableServer/TypeCode_SArg_Traits.h",
3200 stream);
3202 if (be_global->gen_thru_poa_collocation ())
3204 // Thru-POA/skeleton argument selection function templates.
3205 this->gen_cond_file_include (
3206 idl_global->non_local_iface_seen_,
3207 "tao/PortableServer/get_arg.h",
3208 stream);
3210 // Always needed for CORBA::Boolean
3211 // handling in _is_a() skeleton
3212 // code when an unconstrained (non-local)
3213 // IDL interface is defined.
3214 this->gen_cond_file_include (
3215 idl_global->non_local_iface_seen_,
3216 "tao/Special_Basic_Arguments.h",
3217 stream);
3219 // Always needed for string argument
3220 // handling in _is_a() skeleton
3221 // code when an unconstrained (non-local)
3222 // IDL interface is defined.
3223 this->gen_cond_file_include (idl_global->non_local_iface_seen_,
3224 "tao/UB_String_Arguments.h",
3225 stream);
3229 void
3230 TAO_CodeGen::gen_cond_file_include (bool condition_green,
3231 const char *filepath,
3232 TAO_OutStream *stream)
3234 if (condition_green)
3236 this->gen_standard_include (stream,
3237 filepath);
3241 void
3242 TAO_CodeGen::gen_typecode_includes (TAO_OutStream * stream)
3244 this->gen_standard_include (
3245 stream,
3246 "tao/AnyTypeCode/Null_RefCount_Policy.h");
3248 this->gen_standard_include (
3249 stream,
3250 "tao/AnyTypeCode/TypeCode_Constants.h");
3252 // Just assume we're going to need alias TypeCodes since there is
3253 // currently no alias_seen_ or typedef_seen_ flag in idl_global.
3254 this->gen_standard_include (
3255 stream,
3256 "tao/AnyTypeCode/Alias_TypeCode_Static.h");
3258 this->gen_cond_file_include (
3259 idl_global->enum_seen_,
3260 "tao/AnyTypeCode/Enum_TypeCode_Static.h",
3261 stream);
3263 this->gen_cond_file_include (
3264 idl_global->interface_seen_,
3265 "tao/AnyTypeCode/Objref_TypeCode_Static.h",
3266 stream);
3268 this->gen_cond_file_include (
3269 idl_global->seq_seen_ | idl_global->array_seen_,
3270 "tao/AnyTypeCode/Sequence_TypeCode_Static.h",
3271 stream);
3273 this->gen_cond_file_include (
3274 idl_global->string_seen_,
3275 "tao/AnyTypeCode/String_TypeCode_Static.h",
3276 stream);
3278 this->gen_cond_file_include (
3279 idl_global->exception_seen_ | idl_global->aggregate_seen_,
3280 "tao/AnyTypeCode/Struct_TypeCode_Static.h",
3281 stream);
3283 this->gen_cond_file_include (
3284 idl_global->exception_seen_ | idl_global->aggregate_seen_,
3285 "tao/AnyTypeCode/TypeCode_Struct_Field.h",
3286 stream);
3288 this->gen_cond_file_include (
3289 idl_global->union_seen_,
3290 "tao/AnyTypeCode/TypeCode_Case_T.h",
3291 stream);
3293 this->gen_cond_file_include (
3294 idl_global->union_seen_,
3295 "tao/AnyTypeCode/Union_TypeCode_Static.h",
3296 stream);
3298 this->gen_cond_file_include (
3299 idl_global->valuetype_seen_,
3300 "tao/AnyTypeCode/Value_TypeCode_Static.h",
3301 stream);
3303 this->gen_cond_file_include (
3304 idl_global->valuetype_seen_,
3305 "tao/AnyTypeCode/TypeCode_Value_Field.h",
3306 stream);
3308 this->gen_cond_file_include (
3309 idl_global->recursive_type_seen_,
3310 "tao/AnyTypeCode/Recursive_Type_TypeCode.h",
3311 stream);
3314 void
3315 TAO_CodeGen::gen_svnt_hdr_includes (TAO_OutStream *stream)
3317 ACE_CString container_file ("ciao/Containers/");
3318 container_file += be_global->ciao_container_type ();
3319 container_file += "/";
3320 container_file += be_global->ciao_container_type ();
3321 container_file += "_ContainerC.h";
3323 this->gen_standard_include (
3324 stream,
3325 container_file.c_str ());
3327 ACE_CString context_file ("ciao/Contexts/");
3328 context_file += be_global->ciao_container_type ();
3329 context_file += "/";
3330 context_file += be_global->ciao_container_type ();
3331 context_file += "_Context_T.h";
3333 this->gen_standard_include (
3334 stream,
3335 context_file.c_str ());
3337 ACE_CString servant_file ("ciao/Servants/");
3338 servant_file += be_global->ciao_container_type ();
3339 servant_file += "/Servant_Impl_T.h";
3341 this->gen_standard_include (
3342 stream,
3343 servant_file.c_str ());
3345 this->gen_standard_include (
3346 stream,
3347 "ciao/Servants/Home_Servant_Impl_T.h");
3349 this->gen_standard_include (
3350 stream,
3351 "ciao/Servants/Facet_Servant_Base_T.h");
3353 *stream << be_nl;
3355 this->gen_standard_include (
3356 stream,
3357 be_global->be_get_server_hdr_fname (true));
3360 void
3361 TAO_CodeGen::gen_svnt_tmpl_hdr_includes (TAO_OutStream *stream)
3363 ACE_CString servant_file ("ciao/Servants/");
3364 servant_file += be_global->ciao_container_type ();
3365 servant_file += "/Servant_Impl_T.h";
3367 this->gen_standard_include (
3368 stream,
3369 servant_file.c_str ());
3371 this->gen_standard_include (
3372 stream,
3373 "ciao/Servants/Home_Servant_Impl_T.h");
3375 this->gen_standard_include (
3376 stream,
3377 "ciao/Servants/Facet_Servant_Base_T.h");
3379 *stream << be_nl;
3381 if (be_global->gen_ciao_exec_idl())
3383 this->gen_standard_include (
3384 stream,
3385 be_global->be_get_ciao_exec_stub_hdr_fname (true));
3387 *stream << be_nl;
3390 this->gen_standard_include (
3391 stream,
3392 be_global->be_get_server_hdr_fname (true));
3395 void
3396 TAO_CodeGen::gen_svnt_src_includes (TAO_OutStream *stream)
3398 this->gen_standard_include (
3399 stream,
3400 "ciao/Valuetype_Factories/Cookies.h");
3402 this->gen_standard_include (
3403 stream,
3404 "tao/SystemException.h");
3406 this->gen_standard_include (
3407 stream,
3408 "tao/Valuetype/ValueFactory.h");
3410 this->gen_standard_include (
3411 stream,
3412 "tao/ORB_Core.h");
3414 this->gen_standard_include (
3415 stream,
3416 "ace/SString.h");
3419 void
3420 TAO_CodeGen::gen_exec_hdr_includes ()
3422 // All CIAO examples so far have component skeleton and servant
3423 // generated code in the same library, using the skel export macro,
3424 // so the values for the servant export default to the skel values.
3425 // Eventually, there should be a way to completely decouple them.
3426 if (be_global->exec_export_include () != nullptr)
3428 this->gen_standard_include (
3429 this->ciao_exec_header_,
3430 be_global->exec_export_include (),
3431 true);
3434 this->gen_standard_include (
3435 this->ciao_exec_header_,
3436 "tao/LocalObject.h");
3439 void
3440 TAO_CodeGen::gen_exec_src_includes ()
3442 // Generate the include statement for the exec source.
3443 this->gen_standard_include (
3444 this->ciao_exec_source_,
3445 be_global->be_get_ciao_exec_hdr_fname (true));
3446 if (be_global->gen_ciao_exec_reactor_impl ())
3448 this->gen_standard_include (
3449 this->ciao_exec_source_, "tao/ORB_Core.h");
3450 this->gen_standard_include (
3451 this->ciao_exec_source_, "ace/Reactor.h");
3455 void
3456 TAO_CodeGen::gen_exec_idl_includes ()
3458 if (!be_global->gen_noeventccm ())
3460 this->gen_standard_include (
3461 this->ciao_exec_idl_,
3462 "ccm/CCM_Events.idl");
3465 this->gen_standard_include (
3466 this->ciao_exec_idl_,
3467 "ccm/CCM_Home.idl");
3469 this->gen_standard_include (
3470 this->ciao_exec_idl_,
3471 "ccm/CCM_Object.idl");
3473 if (!be_global->gen_lwccm ())
3475 this->gen_standard_include (
3476 this->ciao_exec_idl_,
3477 "ccm/CCM_Enumeration.idl");
3480 this->gen_standard_include (
3481 this->ciao_exec_idl_,
3482 "ccm/CCM_CCMException.idl");
3484 this->gen_standard_include (
3485 this->ciao_exec_idl_,
3486 "ccm/CCM_HomeExecutorBase.idl");
3489 ACE_CString component_file ("ccm/");
3490 component_file += be_global->ciao_container_type ();
3491 component_file += "/CCM_";
3492 component_file += be_global->ciao_container_type ();
3493 component_file += "Component.idl";
3495 this->gen_standard_include (
3496 this->ciao_exec_idl_,
3497 component_file.c_str ());
3499 if (be_global->ami4ccm_call_back ())
3501 this->gen_standard_include (
3502 this->ciao_exec_idl_,
3503 "connectors/ami4ccm/ami4ccm/ami4ccm.idl");
3506 if (be_global->stripped_filename ())
3508 this->gen_standard_include (
3509 this->ciao_exec_idl_,
3510 be_global->stripped_filename ());
3512 else
3514 this->gen_standard_include (
3515 this->ciao_exec_idl_,
3516 idl_global->stripped_filename ()->get_string ());
3519 char **path_tmp = nullptr;
3521 for (ACE_Unbounded_Queue_Iterator<char *>riter (
3522 idl_global->ciao_lem_file_names ());
3523 riter.done () == 0;
3524 riter.advance ())
3526 riter.next (path_tmp);
3528 const char *exec_idl_fname =
3529 be_global->be_get_ciao_exec_idl_fname (true);
3531 bool skip_incl = false;
3532 // special case for ami4ccm, if xxxE.idl. don't include xxxAE.idl.
3533 char *exe_idl_fname = ACE_OS::strdup(exec_idl_fname);
3534 char * base = ACE_OS::strstr(exe_idl_fname, "E.idl");
3535 if (base != nullptr)
3537 static char test[MAXPATHLEN];
3538 ACE_OS::memset (test, 0, MAXPATHLEN);
3540 ACE_OS::strncpy(test, exe_idl_fname, base - exe_idl_fname);
3541 ACE_OS::strcat (test, "AE.idl");
3543 if (ACE_OS::strstr ( *path_tmp, test) != nullptr)
3545 //skip include
3546 skip_incl = true;
3550 /// No need to have the exec IDL file include itself.
3551 if ((ACE_OS::strcmp (*path_tmp, exec_idl_fname) != 0) &&
3552 (!skip_incl))
3554 this->gen_standard_include (this->ciao_exec_idl_, *path_tmp);
3559 bool
3560 TAO_CodeGen::is_system_file (const char * idl_name) const
3562 return
3563 ACE_OS::strcmp (idl_name, "Components.idl") == 0
3564 || ACE_OS::strcmp (
3565 idl_name,
3566 "connectors/ami4ccm/ami4ccm/ami4ccm.idl") == 0;
3569 void
3570 TAO_CodeGen::gen_conn_hdr_includes ()
3572 ACE_Unbounded_Queue<char *> &lem_file_names =
3573 idl_global->ciao_lem_file_names ();
3575 char **path_tmp = nullptr;
3577 for (ACE_Unbounded_Queue_Iterator<char *> riter (
3578 lem_file_names);
3579 riter.done () == 0;
3580 riter.advance ())
3582 riter.next (path_tmp);
3583 ACE_CString lem_str (*path_tmp);
3584 lem_str = lem_str.substr (0, lem_str.find (".idl"));
3585 lem_str += be_global->client_hdr_ending ();
3587 this->gen_standard_include (
3588 this->ciao_conn_header_,
3589 lem_str.c_str ());
3592 *this->ciao_conn_header_ << be_nl;
3594 if (idl_global->dds_connector_seen_)
3596 BE_GlobalData::DDS_IMPL const the_dds_impl =
3597 be_global->dds_impl ();
3599 switch (the_dds_impl)
3601 case BE_GlobalData::NDDS:
3602 this->gen_conn_ts_includes (
3603 idl_global->ciao_rti_ts_file_names ());
3604 break;
3605 case BE_GlobalData::OPENSPLICE:
3606 this->gen_conn_ts_includes (
3607 idl_global->ciao_spl_ts_file_names ());
3608 break;
3609 case BE_GlobalData::OPENDDS:
3610 this->gen_conn_ts_includes (
3611 idl_global->ciao_oci_ts_file_names ());
3612 break;
3613 case BE_GlobalData::COREDX:
3614 this->gen_conn_ts_includes (
3615 idl_global->ciao_coredx_ts_file_names ());
3616 break;
3617 case BE_GlobalData::DDS_NONE:
3618 break;
3622 for (ACE_Unbounded_Queue<char *>::CONST_ITERATOR iiter (
3623 idl_global->dds4ccm_impl_fnames ());
3624 !iiter.done ();
3625 iiter.advance ())
3627 iiter.next (path_tmp);
3629 this->gen_standard_include (
3630 this->ciao_conn_header_,
3631 *path_tmp);
3634 if (idl_global->ami_connector_seen_)
3636 this->gen_standard_include (
3637 this->ciao_conn_header_,
3638 "tao/LocalObject.h");
3641 for (size_t j = 0; j < idl_global->n_included_idl_files (); ++j)
3643 if (j == 0)
3645 *this->ciao_conn_header_ << be_nl;
3648 char * const idl_name =
3649 idl_global->included_idl_files ()[j];
3652 if (this->is_system_file (idl_name))
3654 continue;
3657 UTL_String str (idl_name);
3659 this->gen_standard_include (
3660 this->ciao_conn_header_,
3661 BE_GlobalData::be_get_server_hdr (&str, true));
3663 str.destroy ();
3666 this->gen_standard_include (
3667 this->ciao_conn_header_,
3668 BE_GlobalData::be_get_ciao_exec_stub_header (
3669 idl_global->stripped_filename ()));
3672 void
3673 TAO_CodeGen::gen_conn_src_includes ()
3675 // Generate the include statement for the connector exec source.
3676 this->gen_standard_include (
3677 this->ciao_conn_source_,
3678 be_global->be_get_ciao_conn_hdr_fname (true));
3680 // Include the AMI4CCM library entry point, if AMI4CCM is enabled.
3681 if (idl_global->ami_connector_seen_)
3683 this->gen_standard_include (
3684 this->ciao_conn_source_,
3685 "connectors/ami4ccm/ami4ccm/ami4ccm.h");
3689 void
3690 TAO_CodeGen::gen_ami_conn_idl_includes ()
3692 // Include the AMI4CCM library entry point, if AMI4CCM is enabled.
3693 if (be_global->ami4ccm_call_back ())
3695 this->gen_standard_include (
3696 this->ciao_ami_conn_idl_,
3697 "connectors/ami4ccm/ami4ccm/ami4ccm.idl");
3700 this->gen_standard_include (
3701 this->ciao_ami_conn_idl_,
3702 idl_global->stripped_filename ()->get_string ());
3705 void
3706 TAO_CodeGen::make_rand_extension (char * const t)
3708 size_t const NUM_CHARS = ACE_OS::strlen (t);
3710 /// Use ACE_Time_Value::msec(ACE_UINT64&) as opposed to
3711 /// ACE_Time_Value::msec() to avoid truncation.
3712 ACE_UINT64 msec;
3714 /// Use a const ACE_Time_Value to resolve ambiguity between
3715 /// ACE_Time_Value::msec (long) and ACE_Time_Value::msec(ACE_UINT64&) const.
3716 ACE_Time_Value const now = ACE_OS::gettimeofday ();
3717 now.msec (msec);
3719 /// Add the process and thread ids to ensure uniqueness. Must use
3720 // C-style cast, since thr_self() returns a pointer on some platforms.
3721 msec += ACE_OS::getpid ();
3722 msec += (size_t) ACE_OS::thr_self ();
3724 // ACE_thread_t may be a char* (returned by ACE_OS::thr_self()) so
3725 // we need to use a C-style cast as a catch-all in order to use a
3726 // static_cast<> to an integral type.
3727 unsigned int seed = static_cast<unsigned int> (msec);
3729 // We only care about UTF-8 / ASCII characters in generated
3730 // filenames. A UTF-16 or UTF-32 character could potentially cause
3731 // a very large space to be searched in the below do/while() loop,
3732 // greatly slowing down this mkstemp() implementation. It is more
3733 // practical to limit the search space to UTF-8 / ASCII characters
3734 // (i.e. 127 characters).
3736 // Note that we can't make this constant static since the compiler
3737 // may not inline the return value of ACE_Numeric_Limits::max(),
3738 // meaning multiple threads could potentially initialize this value
3739 // in parallel.
3740 float const MAX_VAL =
3741 static_cast<float> (ACE_Numeric_Limits<char>::max ());
3743 // Use high-order bits rather than low-order ones (e.g. rand() %
3744 // MAX_VAL). See Numerical Recipes in C: The Art of Scientific
3745 // Computing (William H. Press, Brian P. Flannery, Saul
3746 // A. Teukolsky, William T. Vetterling; New York: Cambridge
3747 // University Press, 1992 (2nd ed., p. 277).
3749 // e.g.: MAX_VAL * rand() / (RAND_MAX + 1.0)
3751 // Factor out the constant coefficient.
3752 float const coefficient =
3753 static_cast<float> (MAX_VAL / (RAND_MAX + 1.0f));
3755 for (unsigned int n = 0; n < NUM_CHARS; ++n)
3757 ACE_TCHAR r;
3759 // This do/while() loop allows this alphanumeric character
3760 // selection to work for EBCDIC, as well.
3763 r = static_cast<ACE_TCHAR> (coefficient * ACE_OS::rand_r (&seed));
3765 while (!ACE_OS::ace_isalnum (r));
3767 t[n] = static_cast<char> (ACE_OS::ace_toupper (r));
3771 void
3772 TAO_CodeGen::gen_conn_ts_includes (
3773 ACE_Unbounded_Queue<char *> &ts_files)
3775 if (ts_files.size () > 0)
3777 *this->ciao_conn_header_ << be_nl;
3780 char **tmp = nullptr;
3782 for (ACE_Unbounded_Queue_Iterator<char *> i (ts_files);
3783 !i.done ();
3784 i.advance ())
3786 i.next (tmp);
3787 this->gen_standard_include (this->ciao_conn_header_,
3788 *tmp);
3792 void
3793 TAO_CodeGen::destroy ()
3795 delete this->client_header_;
3796 delete this->server_header_;
3797 delete this->implementation_header_;
3798 delete this->implementation_skeleton_;
3799 delete this->server_template_header_;
3800 delete this->client_stubs_;
3801 delete this->server_skeletons_;
3802 delete this->server_template_skeletons_;
3803 delete this->client_inline_;
3804 delete this->anyop_source_;
3805 delete this->anyop_header_;
3806 delete this->ciao_svnt_header_;
3807 delete this->ciao_svnt_source_;
3808 delete this->ciao_exec_header_;
3809 delete this->ciao_exec_source_;
3810 delete this->ciao_exec_idl_;
3811 delete this->ciao_conn_header_;
3812 delete this->ciao_conn_source_;
3813 delete this->ciao_ami_conn_idl_;
3814 delete this->gperf_input_stream_;
3815 delete [] this->gperf_input_filename_;