📄 psdl_struct_visitor.cpp
字号:
// -*- C++ -*-
// PSDL_Struct_Visitor.cpp,v 1.3 2003/10/28 18:34:04 bala Exp
#include "PSDL_Struct_Visitor.h"
#include "PSDL_Stream.h"
#include "PSDL_y.h"
#include "tao/CORBA_String.h"
ACE_RCSID (PSS, PSDL_Struct_Visitor, "PSDL_Struct_Visitor.cpp,v 1.3 2003/10/28 18:34:04 bala Exp")
TAO_PSDL_Struct_Visitor::TAO_PSDL_Struct_Visitor (void)
: identifiers_count_ (0),
struct_name_ ()
{
}
TAO_PSDL_Struct_Visitor::~TAO_PSDL_Struct_Visitor (void)
{
}
int
TAO_PSDL_Struct_Visitor::visit_identifier (TAO_PSDL_Identifier *identifier)
{
// The first time it will enter this function is to get the name of
// the struct. And, then on, for the members in the structure.
// so this->identifiers_[0] will be the name of the struct.
if (this->identifiers_.size () == 0)
{
this->identifiers_.size (1);
this->count_ = 0;
}
if (this->identifiers_.size () < this->count_ + 1)
this->identifiers_.size (this->count_ + 1);
this->identifiers_ [this->count_] = identifier->value ();
++this->count_;
return 0;
}
int
TAO_PSDL_Struct_Visitor::visit_type_spec (TAO_PSDL_Type_Spec *type_spec)
{
if (type_spec->type_of_type_spec ()->accept (this) == -1)
return -1;
ACE_CString type;
// Get a pointer to PSDL_Stream of the stub header.
TAO_PSDL_Stream *ps_sh = TAO_PSDL_Scope::instance ()->get_sh ();
if (this->base_type (this->identifiers_[this->identifiers_count_], type))
{
// If this is a predefined type like long or char *
if (ACE_OS::strcmp (type.c_str (), "char *") == 0)
{
ps_sh->indent ();
*ps_sh << " TAO_String_Manager ";
}
else
{
*ps_sh << " "
<< this->version_for_stub (type) << " ";
}
}
else
{
*ps_sh << "ACE_NESTED_CLASS ("
<< TAO_PSDL_Scope::instance ()->get_name_space ()
<< ", " << this->identifiers_ [this->identifiers_count_] << ") ";
}
++this->identifiers_count_;
return 0;
}
int
TAO_PSDL_Struct_Visitor::visit_declarator (TAO_PSDL_Declarator *declarator)
{
if (declarator->type_of_declarator ()->accept (this) == -1)
return -1;
// Get a pointer to PSDL_Stream of the stub header.
TAO_PSDL_Stream *ps_sh = TAO_PSDL_Scope::instance ()->get_sh ();
*ps_sh << this->identifiers_ [this->identifiers_count_].c_str ()
<< ";\n";
++this->identifiers_count_;
return 0;
}
int
TAO_PSDL_Struct_Visitor::visit_predefined_type (TAO_PSDL_Predefined_Type *predefined_type)
{
// Get a pointer to PSDL_Stream of the stub header.
TAO_PSDL_Stream *ps_sh = TAO_PSDL_Scope::instance ()->get_sh ();
// Reset the indentation.
ps_sh->reset ();
if (predefined_type->type_of_variable_one () != 0)
{
if (predefined_type->type_of_variable_one ()->accept (this) == -1)
return -1;
this->struct_name_ = CORBA::string_dup (this->identifiers_ [0].c_str ());
*ps_sh << "struct " << this->struct_name_
<< ";\n";
*ps_sh << "class " << this->struct_name_
<< "_var;";
ps_sh->nl ();
ps_sh->nl ();
*ps_sh << "struct " << this->struct_name_;
ps_sh->nl ();
*ps_sh << "{";
ps_sh->nl ();
*ps_sh << "#if !defined(__GNUC__) || !defined (ACE_HAS_GNUG_PRE_2_8)";
ps_sh->incr_indent ();
ps_sh->nl ();
*ps_sh << "typedef " << this->struct_name_ << "_var _var_type;\n";
ps_sh->decr_indent ();
ps_sh->nl ();
*ps_sh << "#endif /* ! __GNUC__ || g++ >= 2.8 */\n";
ps_sh->nl ();
*ps_sh << "static void _tao_any_destructor (void*);";
ps_sh->nl ();
ps_sh->nl ();
}
if (predefined_type->type_of_variable_two () != 0)
{
// Resetting the counter to be used while printing out the
// type_spec and declarator informations. See the corresponding
// visit_* methods.
if (this->count_ > 0)
this->identifiers_count_ = 1;
if (predefined_type->type_of_variable_two ()->accept (this) == -1)
return -1;
*ps_sh << "\n};\n\n";
this->print_class_for_structure (this->struct_name_);
}
if (predefined_type->type_one () != 0)
{
// If the member declarations in the structure include any
// predefined types like long, save them and increment the counter.
if (this->identifiers_.size () < this->count_ + 1)
this->identifiers_.size (this->count_ + 1);
this->identifiers_ [this->count_] =
TAO_PSDL_Scope::instance ()->convert_str (predefined_type->type_one ());
++this->count_;
}
return 0;
}
void
TAO_PSDL_Struct_Visitor::gen_code_for_si (void)
{
TAO_PSDL_Stream *ps_si = TAO_PSDL_Scope::instance ()->get_si ();
ps_si->reset ();
ps_si->indent (); // start from current indentation level
// Generate the typecode information here
*ps_si << "static const CORBA::Long _oc_";
// Flat name generation.
*ps_si << this->struct_name_;
*ps_si << "[] =";
ps_si->nl ();
*ps_si << "{";
ps_si->nl ();
// Some invocation call to put in the stuff that goes between
// braces.
*ps_si << "TAO_ENCAP_BYTE_ORDER";
ps_si->nl ();
*ps_si << "// Typecode related information should go in here";
ps_si->nl ();
*ps_si << "};";
ps_si->nl ();
ps_si->nl ();
*ps_si << "static CORBA::TypeCode _tc_TAO_tc_";
*ps_si << this->struct_name_;
*ps_si << " (";
ps_si->nl ();
ps_si->incr_indent (0);
*ps_si << "CORBA::tk_struct,";
ps_si->nl ();
*ps_si << "sizeof (_oc_" << this->struct_name_ << "),";
ps_si->nl ();
*ps_si << "(char *) &_oc_";
*ps_si << this->struct_name_ << ",";
ps_si->nl ();
*ps_si << "0,";
ps_si->nl ();
*ps_si << "sizeof (" << this->struct_name_ << ")";
ps_si->nl ();
*ps_si << ");";
ps_si->decr_indent ();
ps_si->nl ();
ps_si->nl ();
*ps_si << "::CORBA::TypeCode_ptr _tc_" << this->struct_name_ << " =";
ps_si->nl ();
ps_si->incr_indent (0);
*ps_si << "&_tc_TAO_tc_" << this->struct_name_ << ";";
ps_si->decr_indent ();
ps_si->nl ();
ps_si->nl ();
*ps_si << "void ";
*ps_si << this->struct_name_
<< "::_tao_any_destructor (void *_tao_void_pointer)";
ps_si->nl ();
*ps_si << "{";
ps_si->nl ();
ps_si->incr_indent (0);
*ps_si << this->struct_name_ << " *tmp = "
<< "ACE_static_cast ("
<< this->struct_name_
<< "*, _tao_void_pointer);";
ps_si->nl ();
*ps_si << "delete tmp;";
ps_si->decr_indent ();
ps_si->nl ();
ps_si->decr_indent ();
*ps_si <<"}";
ps_si->nl ();
ps_si->nl ();
// Copying Insertion
*ps_si << "// Copying insertion.";
ps_si->nl ();
*ps_si << "void operator<<= (";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "CORBA::Any &_tao_any,"; ps_si->nl ();
*ps_si << "const " << this->struct_name_ << " &_tao_elem"; ps_si->nl ();
ps_si->decr_indent ();
*ps_si << ")"; ps_si->nl ();
*ps_si << "{";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "TAO_OutputCDR stream;"; ps_si->nl ();
*ps_si << "if (stream << _tao_elem)"; ps_si->nl ();
*ps_si << "{";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "_tao_any._tao_replace (";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "_tc_" << this->struct_name_ << ","; ps_si->nl ();
*ps_si << "TAO_ENCAP_BYTE_ORDER,"; ps_si->nl ();
*ps_si << "stream.begin ()";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << ");";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << "}";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << "}";
ps_si->nl ();
ps_si->reset ();
ps_si->nl ();
*ps_si << "// Non-copying insertion."; ps_si->nl ();
*ps_si << "void operator<<= (";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "CORBA::Any &_tao_any,"; ps_si->nl ();
*ps_si << this->struct_name_ << " *_tao_elem";
ps_si->nl ();
*ps_si << ")";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << "{";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "TAO_OutputCDR stream;"; ps_si->nl ();
*ps_si << "if (stream << *_tao_elem)"; ps_si->nl ();
*ps_si << "{";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "_tao_any._tao_replace (";
ps_si->incr_indent (0);ps_si->nl ();
*ps_si << "_tc_" << this->struct_name_ << ","; ps_si->nl ();
*ps_si << "TAO_ENCAP_BYTE_ORDER,"; ps_si->nl ();
*ps_si << "stream.begin (),"; ps_si->nl ();
*ps_si << "1,"; ps_si->nl ();
*ps_si << "_tao_elem,"; ps_si->nl ();
*ps_si << this->struct_name_ << "::_tao_any_destructor";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << ");";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << "}";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << "}"; ps_si->nl ();
ps_si->reset ();
ps_si->nl ();
*ps_si << "// Extraction to const pointer."; ps_si->nl ();
*ps_si << "CORBA::Boolean operator>>= (";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "const CORBA::Any &_tao_any,"; ps_si->nl ();
*ps_si << "const " << this->struct_name_ << " *&_tao_elem"; ps_si->nl ();
*ps_si << ")";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << "{";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "_tao_elem = 0;"; ps_si->nl ();
*ps_si << "ACE_TRY_NEW_ENV"; ps_si->nl ();
*ps_si << "{";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "CORBA::TypeCode_var type = _tao_any.type ();"; ps_si->nl ();
*ps_si << "CORBA::Boolean result ="; ps_si->nl ();
*ps_si << "type->equivalent (";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "_tc_" << this->struct_name_ << ""; ps_si->nl ();
*ps_si << "ACE_ENV_ARG_PARAMETER";
ps_si->decr_indent (0); ps_si->nl ();
*ps_si << ");"; ps_si->nl ();
*ps_si << "ACE_TRY_CHECK;"; ps_si->nl ();
*ps_si << "if (result == 0)"; ps_si->nl ();
*ps_si << "{";
ps_si->incr_indent (0); ps_si->nl ();
*ps_si << "return 0; // not equivalent";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -