arg_tmplinst.cpp

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 723 行 · 第 1/2 页

CPP
723
字号
//=============================================================================
/**
*  @file   arg_tmplinst.cpp
*
*  arg_tmplinst.cpp,v 1.2 2003/10/28 18:30:38 bala Exp
*
*  This visitor generates explicit template instantiations, guarded so they
*  are seen only by compilers whose platforms require explicit template
*  instantiation, for the individual argument template helper classes.
*
*  @author Jeff Parsons <j.parsons@vanderbilt.edu>
*/
//=============================================================================

be_visitor_arg_tmplinst::be_visitor_arg_tmplinst (
    be_visitor_context *ctx,
    be_visitor_tmplinst_cs::Mode mode,
    char * prefix,
    char * suffix,
    char * linebreak,
    const char * S
  )
  : be_visitor_decl (ctx),
    mode_ (mode),
    prefix_ (prefix),
    suffix_ (suffix),
    linebreak_ (linebreak),
    S_ (S)
{
}

be_visitor_arg_tmplinst::~be_visitor_arg_tmplinst (void)
{
}

int
be_visitor_arg_tmplinst::visit_interface (be_interface *node)
{
  if (this->this_mode_and_dir_generated (node))
    {
      return 0;
    }

  TAO_OutStream *os = this->ctx_->stream ();

  *os << be_nl << be_nl
      << this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
      << "TAO::";

  this->gen_direction (os);

  *os << "_Object_" << this->S_ << "Argument_T<" << this->linebreak_
      << be_idt << be_idt_nl
      << node->name () << "_ptr";

  switch (this->dir_)
    {
      case _tao_INOUT:
        *os << "," << this->linebreak_ << be_nl
            << "TAO::Objref_Traits<"  << node->name () << ">";
        break;

      case _tao_OUT:
        *os << "," << this->linebreak_ << be_nl
            << node->name () << "_out";
        break;
      case _tao_RET:
        *os << "," << this->linebreak_ << be_nl
            << node->name () << "_var";
        break;
      default:
        break;
    }

  *os << this->linebreak_ << be_uidt_nl
      << ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;

  this->this_mode_and_dir_generated (node, I_TRUE);
  return 0;
}

int
be_visitor_arg_tmplinst::visit_interface_fwd (be_interface_fwd *node)
{
  if (this->this_mode_and_dir_generated (node))
    {
      return 0;
    }

  be_interface *fd =
    be_interface::narrow_from_decl (node->full_definition ());

  if (this->visit_interface (fd) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_arg_tmplinst::"
                         "visit_interface_fwd - code generation failed\n"),
                        -1);
    }

  this->this_mode_and_dir_generated (node, I_TRUE);
  return 0;
}

int
be_visitor_arg_tmplinst::visit_valuetype (be_valuetype *node)
{
  if (this->this_mode_and_dir_generated (node))
    {
      return 0;
    }

  TAO_OutStream *os = this->ctx_->stream ();

  *os << be_nl << be_nl
      << this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
      << "TAO::";

  this->gen_direction (os);

  *os << "_Object_" << this->S_ << "Argument_T<" << this->linebreak_
      << be_idt << be_idt_nl
      << node->name () << " *";

  switch (this->dir_)
    {
      case _tao_OUT:
        *os << "," << this->linebreak_ << be_nl
            << node->name () << "_out";
        break;
      case _tao_RET:
        *os << "," << this->linebreak_ << be_nl
            << node->name () << "_var";
        break;
      default:
        break;
    }

  *os << this->linebreak_ << be_uidt_nl
      << ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;

  this->this_mode_and_dir_generated (node, I_TRUE);
  return 0;
}

int
be_visitor_arg_tmplinst::visit_valuetype_fwd (be_valuetype_fwd *node)
{
  if (this->this_mode_and_dir_generated (node))
    {
      return 0;
    }

  be_valuetype *fd =
    be_valuetype::narrow_from_decl (node->full_definition ());

  if (this->visit_valuetype (fd) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_arg_tmplinst::"
                         "visit_valuetype_fwd - code generation failed\n"),
                        -1);
    }

  this->this_mode_and_dir_generated (node, I_TRUE);
  return 0;
}

int
be_visitor_arg_tmplinst::visit_eventtype (be_eventtype *node)
{
  return this->visit_valuetype (node);
}

int
be_visitor_arg_tmplinst::visit_eventtype_fwd (be_eventtype_fwd *node)
{
  return this->visit_valuetype_fwd (node);
}

int
be_visitor_arg_tmplinst::visit_sequence (be_sequence *node)
{
  if (this->this_mode_and_dir_generated (node))
    {
      return 0;
    }

  TAO_OutStream *os = this->ctx_->stream ();
  be_typedef *alias = this->ctx_->alias ();

  *os << be_nl << be_nl
      << this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
      << "TAO::";

  this->gen_direction (os);

  *os << "_Var_Size_" << this->S_ << "Argument_T<" << this->linebreak_
      << be_idt << be_idt_nl
      << alias->name ();

  switch (this->dir_)
    {
      case _tao_OUT:
        *os << "," << this->linebreak_ << be_nl
            << alias->name () << "_out";
        break;
      case _tao_RET:
        *os << "," << this->linebreak_ << be_nl
            << alias->name () << "_var";
        break;
      default:
        break;
    }

  *os << this->linebreak_ << be_uidt_nl
      << ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;

  this->this_mode_and_dir_generated (node, I_TRUE);
  return 0;
}

int
be_visitor_arg_tmplinst::visit_string (be_string *node)
{
  if (this->this_mode_and_dir_generated (node))
    {
      return 0;
    }

  unsigned long bound = node->max_size ()->ev ()->u.ulval;
  be_typedef *alias = this->ctx_->alias ();

  // Unbounded (w)string args are handled as a predefined type.
  // Bounded (w)strings must come in as a typedef - they can't
  // be used directly as arguments or return types.
  if (bound == 0 || alias == 0)
    {
      this->this_mode_and_dir_generated (node, I_TRUE);
      return 0;
    }

  idl_bool wide = (node->width () != 1);

  TAO_OutStream *os = this->ctx_->stream ();

  *os << be_nl << be_nl
      << this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
      << "TAO::";

  this->gen_direction (os);

  *os << "_BD_String_" << this->S_ << "Argument_T<" << this->linebreak_
      << be_idt << be_idt_nl
      << "CORBA::" << (wide ? "W" : "") << "Char";

  switch (this->dir_)
    {
      case _tao_OUT:
        *os << "," << this->linebreak_ << be_nl
            << "CORBA::" << (wide ? "W" : "") << "String_out";
        break;
      case _tao_RET:
        *os << "," << this->linebreak_ << be_nl
            << "CORBA::" << (wide ? "W" : "") << "String_var";
        break;
      default:
        break;
    }

  *os << "," << this->linebreak_ << be_nl
      << "ACE_InputCDR::to_" << (wide ? "w" : "") << "string,"
      << this->linebreak_ << be_nl
      << "ACE_OutputCDR::from_" << (wide ? "w" : "") << "string,"
      << this->linebreak_ << be_nl
      << bound << this->linebreak_ << be_uidt_nl
      << ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;

  this->this_mode_and_dir_generated (node, I_TRUE);
  return 0;
}

int
be_visitor_arg_tmplinst::visit_array (be_array *node)
{
  if (this->this_mode_and_dir_generated (node))
    {
      return 0;
    }

  TAO_OutStream *os = this->ctx_->stream ();
  idl_bool fixed = (node->size_type () == AST_Type::FIXED);

  *os << be_nl << be_nl
      << this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
      << "TAO::";

  this->gen_direction (os);

  *os << "_" << (fixed ? "Fixed" : "Var") << "_Array_"
      << this->S_ << "Argument_T<" << this->linebreak_
      << be_idt << be_idt_nl
      << node->name () << "," << this->linebreak_ << be_nl;

  switch (this->dir_)
    {
    case _tao_IN:
    case _tao_INOUT:
        *os << node->name () << "_slice," << this->linebreak_ << be_nl;
        break;
      case _tao_OUT:
        *os << node->name () << "_slice," << this->linebreak_ << be_nl;
        if (!fixed)
          {
            *os << node->name () << "_var," << this->linebreak_ << be_nl
                << node->name () << "_out," << this->linebreak_ << be_nl;
          }
        break;
      case _tao_RET:
        *os << node->name () << "_slice," << this->linebreak_ << be_nl
            << node->name () << "_var," << this->linebreak_ << be_nl;
        break;
      default:
        break;
    }

  *os << node->name () << "_forany" << this->linebreak_ << be_uidt_nl
      << ">" << this->suffix_ << be_uidt << be_uidt
      << be_uidt << be_uidt;

  this->this_mode_and_dir_generated (node, I_TRUE);

  return 0;
}

int
be_visitor_arg_tmplinst::visit_enum (be_enum *node)
{
  if (this->this_mode_and_dir_generated (node))
    {
      return 0;
    }

  TAO_OutStream *os = this->ctx_->stream ();

  *os << be_nl << be_nl
      << this->prefix_ << this->linebreak_ << be_idt << be_idt_nl
      << "TAO::";

  this->gen_direction (os);

  *os << "_Basic_" << this->S_ << "Argument_T<" << this->linebreak_
      << be_idt << be_idt_nl
      << node->name () << this->linebreak_ << be_uidt_nl
      << ">" << this->suffix_ << be_uidt << be_uidt << be_uidt;

  this->this_mode_and_dir_generated (node, I_TRUE);
  return 0;
}

int
be_visitor_arg_tmplinst::visit_structure (be_structure *node)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?