be_codegen.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,906 行 · 第 1/4 页
CPP
1,906 行
// be_codegen.cpp,v 1.132 2003/12/27 22:18:10 bala Exp
// ============================================================================
//
// = LIBRARY
// TAO IDL
//
// = FILENAME
// be_codegen.cpp
//
// = DESCRIPTION
// Code generation
//
// = AUTHOR
// Aniruddha Gokhale
//
// ============================================================================
#include "be_codegen.h"
#include "be_helper.h"
#include "be_visitor_factory.h"
#include "be_stream_factory.h"
#include "be_extern.h"
#include "global_extern.h"
#include "utl_string.h"
#include "idl_defines.h"
ACE_RCSID (be,
be_codegen,
"be_codegen.cpp,v 1.132 2003/12/27 22:18:10 bala Exp")
TAO_IDL_BE_Export TAO_CodeGen *tao_cg = 0;
TAO_CodeGen::TAO_CodeGen (void)
: client_header_ (0),
client_stubs_ (0),
client_inline_ (0),
server_header_ (0),
implementation_header_(0),
implementation_skeleton_(0),
server_template_header_ (0),
server_skeletons_ (0),
server_template_skeletons_ (0),
server_inline_ (0),
server_template_inline_ (0),
anyop_header_ (0),
anyop_source_ (0),
gperf_input_stream_ (0),
gperf_input_filename_ (0),
curr_os_ (0),
visitor_factory_ (0)
{
// Initialize the anyop streams here so we won't have to fuss
// with it in the visitors.
if (be_global->gen_anyop_files ())
{
int status = 0;
status =
this->start_anyop_header (
be_global->be_get_anyop_header_fname ()
);
if (status == -1)
{
ACE_ERROR ((LM_ERROR,
"(%N:%l) TAO_CodeGen::"
"TAO_CodeGen - "
"Error opening anyop header file\n"));
}
status =
this->start_anyop_source (
be_global->be_get_anyop_source_fname ()
);
if (status == -1)
{
ACE_ERROR ((LM_ERROR,
"(%N:%l) TAO_CodeGen::"
"TAO_CodeGen - "
"Error opening anyop source file\n"));
}
}
}
// destructor
TAO_CodeGen::~TAO_CodeGen (void)
{
delete this->client_header_;
delete this->server_header_;
delete this->implementation_header_;
delete this->implementation_skeleton_;
delete this->server_template_header_;
delete this->client_stubs_;
delete this->server_skeletons_;
delete this->server_template_skeletons_;
delete this->client_inline_;
delete this->server_inline_;
delete this->server_template_inline_;
delete this->anyop_header_;
delete this->anyop_source_;
#if !defined (linux) && !defined (__QNX__)
// This causes a seg fault on Linux RH 5.1. Let it leak . . .
delete this->gperf_input_stream_;
#endif /* ! linux */
delete [] this->gperf_input_filename_;
this->curr_os_ = 0;
// delete this->visitor_factory_;
}
// visitor factory method
be_visitor *
TAO_CodeGen::make_visitor (be_visitor_context *ctx)
{
if (this->visitor_factory_ == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("TAO_CodeGen::make_visitor - ")
ACE_TEXT ("No Visitor Factory\n\n")),
0);
}
return this->visitor_factory_->make_visitor (ctx);
}
// Change the string to all upper case.
const char *
TAO_CodeGen::upcase (const char *str)
{
static char upcase_str [NAMEBUFSIZE];
ACE_OS::memset (upcase_str,
'\0',
NAMEBUFSIZE);
// Convert letters in str to upper case.
for (unsigned int i = 0; i < ACE_OS::strlen (str); ++i)
{
if (isalpha (str [i]))
{
upcase_str[i] = (char) toupper (str[i]);
}
else
{
// Copy it as it is.
upcase_str[i] = str[i];
}
}
return upcase_str;
}
// Set the client header stream.
int
TAO_CodeGen::start_client_header (const char *fname)
{
if (fname == 0)
{
// Bad file name.
return -1;
}
// @@ We are making use of "included_idl_files" that is in the
// idl_global. We need to make sure the validity of those files.
idl_global->validate_included_idl_files ();
// Retrieve the singleton instance to the outstream factory.
TAO_OutStream_Factory *factory = TAO_OUTSTREAM_FACTORY::instance ();
// Retrieve a specialized instance.
this->client_header_ = factory->make_outstream ();
if (!this->client_header_)
{
return -1;
}
if (this->client_header_->open (fname, TAO_OutStream::TAO_CLI_HDR) == -1)
{
return -1;
}
*this->client_header_ << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__
<< be_nl << be_nl;
// Generate the #ident string, if any.
this->gen_ident_string (this->client_header_);
// Generate the #ifndef clause.
this->gen_ifndef_string (fname,
this->client_header_,
"_TAO_IDL_",
"_H_");
if (be_global->pre_include () != 0)
{
*this->client_header_ << "#include /**/ \""
<< be_global->pre_include ()
<< "\"\n\n";
}
// This one is a good candidate to go first since applications need
// full knowledge of CORBA::ORB. It's rather heavyweight though
// (includes PolicyC.h) and should probably be refactored somehow.
*this->client_header_ << "#include \"tao/ORB.h\"";
// Some compilers don't optimize the #ifndef header include
// protection, but do optimize based on #pragma once.
*this->client_header_ << "\n\n#if !defined (ACE_LACKS_PRAGMA_ONCE)\n"
<< "# pragma once\n"
<< "#endif /* ACE_LACKS_PRAGMA_ONCE */";
*this->client_header_ << be_nl;
// Other include files.
if (be_global->stub_export_include () != 0)
{
*this->client_header_ << "\n#include \""
<< be_global->stub_export_include ()
<< "\"";
}
this->gen_stub_hdr_includes ();
size_t nfiles = idl_global->n_included_idl_files ();
if (nfiles > 0)
{
*this->client_header_ << "\n";
}
// We must include all the client headers corresponding to
// IDL files included by the current IDL file.
// We will use the included IDL file names as they appeared
// in the original main IDL file, not the one which went
// thru CC preprocessor.
for (size_t j = 0; j < nfiles; ++j)
{
char* idl_name = idl_global->included_idl_files ()[j];
// Make a String out of it.
UTL_String idl_name_str = idl_name;
// Make sure this file was actually got included, not
// ignored by some #if defined compiler directive.
// Get the clnt header from the IDL file name.
const char* client_hdr =
BE_GlobalData::be_get_client_hdr (&idl_name_str,
1);
// Sanity check and then print.
if (client_hdr != 0)
{
this->client_header_->print ("\n#include \"%s\"",
client_hdr);
}
else
{
ACE_ERROR ((LM_WARNING,
ACE_TEXT ("\nWARNING, invalid file '%s' included"),
idl_name));
}
}
// Generate the TAO_EXPORT_MACRO macro.
*this->client_header_ << "\n\n#if defined (TAO_EXPORT_MACRO)\n";
*this->client_header_ << "#undef TAO_EXPORT_MACRO\n";
*this->client_header_ << "#endif\n";
*this->client_header_ << "#define TAO_EXPORT_MACRO "
<< be_global->stub_export_macro ();
// Generate export macro for nested classes.
*this->client_header_ << "\n\n#if defined (TAO_EXPORT_NESTED_CLASSES)\n"
<< "# if defined (TAO_EXPORT_NESTED_MACRO)\n"
<< "# undef TAO_EXPORT_NESTED_MACRO\n"
<< "# endif /* defined "
<< "(TAO_EXPORT_NESTED_MACRO) */\n"
<< "# define TAO_EXPORT_NESTED_MACRO "
<< be_global->stub_export_macro ()
<< be_nl
<< "#endif /* TAO_EXPORT_NESTED_CLASSES */";
*this->client_header_ << "\n\n#if defined(_MSC_VER)\n"
<< "#if (_MSC_VER >= 1200)\n"
<< "#pragma warning(push)\n"
<< "#endif /* _MSC_VER >= 1200 */\n"
<< "#pragma warning(disable:4250)";
if (be_global->use_raw_throw ())
{
*this->client_header_ << "\n#pragma warning(disable:4290)";
}
*this->client_header_ << "\n#endif /* _MSC_VER */";
*this->client_header_
<< "\n\n#if defined (__BORLANDC__)\n"
<< "#pragma option push -w-rvl -w-rch -w-ccc -w-inl\n"
<< "#endif /* __BORLANDC__ */";
return 0;
}
// Get the client header stream.
TAO_OutStream *
TAO_CodeGen::client_header (void)
{
return this->client_header_;
}
// Set the client stub stream.
int
TAO_CodeGen::start_client_stubs (const char *fname)
{
// Retrieve the singleton instance to the outstream factory.
TAO_OutStream_Factory *factory = TAO_OUTSTREAM_FACTORY::instance ();
// Retrieve a specialized instance.
this->client_stubs_ = factory->make_outstream ();
if (!this->client_stubs_)
{
return -1;
}
if (this->client_stubs_->open (fname, TAO_OutStream::TAO_CLI_IMPL) == -1)
{
return -1;
}
*this->client_stubs_ << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__
<< be_nl << be_nl;
// Generate the ident string, if any.
this->gen_ident_string (this->client_stubs_);
this->gen_stub_src_includes ();
*this->client_stubs_ << "\n\n#if defined (__BORLANDC__)\n"
<< "#pragma option -w-rvl -w-rch -w-ccc -w-aus -w-sig\n"
<< "#endif /* __BORLANDC__ */";
// Generate the code that includes the inline file if not included in the
// header file.
*this->client_stubs_ << "\n\n#if !defined (__ACE_INLINE__)";
*this->client_stubs_ << "\n#include \""
<< be_global->be_get_client_inline_fname (1)
<< "\"";
*this->client_stubs_ << "\n#endif /* !defined INLINE */";
return 0;
}
// Get the client stubs stream.
TAO_OutStream *
TAO_CodeGen::client_stubs (void)
{
return this->client_stubs_;
}
// Set the client inline stream.
int
TAO_CodeGen::start_client_inline (const char *fname)
{
// Retrieve the singleton instance to the outstream factory.
TAO_OutStream_Factory *factory = TAO_OUTSTREAM_FACTORY::instance ();
// Retrieve a specialized instance.
this->client_inline_ = factory->make_outstream ();
if (!this->client_inline_)
{
return -1;
}
if (this->client_inline_->open (fname, TAO_OutStream::TAO_CLI_INL) == -1)
{
return -1;
}
// Generate the ident string, if any.
this->gen_ident_string (this->client_inline_);
return 0;
}
// Get the client inline stream.
TAO_OutStream *
TAO_CodeGen::client_inline (void)
{
return this->client_inline_;
}
// Set the server header stream.
int
TAO_CodeGen::start_server_header (const char *fname)
{
// @@ We are making use of "included_idl_files" that is in the
// idl_global. We need to make sure the validity of those files.
idl_global->validate_included_idl_files ();
// Retrieve the singleton instance to the outstream factory.
TAO_OutStream_Factory *factory = TAO_OUTSTREAM_FACTORY::instance ();
// Retrieve a specialized instance.
this->server_header_ = factory->make_outstream ();
if (!this->server_header_)
{
return -1;
}
if (this->server_header_->open (fname, TAO_OutStream::TAO_SVR_HDR) == -1)
{
return -1;
}
*this->server_header_ << be_nl << "// TAO_IDL - Generated from" << be_nl
<< "// " << __FILE__ << ":" << __LINE__
<< be_nl << be_nl;
// Generate the ident string, if any.
this->gen_ident_string (this->server_header_);
// Generate the #ifndef clause.
this->gen_ifndef_string (fname,
this->server_header_,
"_TAO_IDL_",
"_H_");
if (be_global->pre_include () != 0)
{
*this->server_header_ << "#include /**/ \""
<< be_global->pre_include ()
<< "\"\n";
}
// We must include all the skeleton headers corresponding to
// IDL files included by the current IDL file.
// We will use the included IDL file names as they appeared
// in the original main IDL file, not the one which went
// thru CC preprocessor.
for (size_t j = 0;
j < idl_global->n_included_idl_files ();
++j)
{
char* idl_name = idl_global->included_idl_files ()[j];
// String'ifying the name.
UTL_String idl_name_str (idl_name);
const char* server_hdr =
BE_GlobalData::be_get_server_hdr (&idl_name_str, 1);
this->server_header_->print ("\n#include \"%s\"",
server_hdr);
}
// Include the Messaging files if AMI is enabled.
if (be_global->ami_call_back () == I_TRUE)
{
// Include Messaging skeleton file.
this->gen_standard_include (this->server_header_,
"tao/Messaging/MessagingS.h");
}
// The server header should include the client header.
*this->server_header_ << "\n#include \""
<< be_global->be_get_client_hdr_fname (1)
<< "\"";
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?