UTL_NameList *
ast_visitor_tmpl_module_inst::create_name_list (AST_Type **list,
                                               long length)
{
  UTL_NameList *retval = 0;

  for (long i = 0; i < length; ++i)
    {
      AST_Type *item =
        AST_Type::narrow_from_decl (this->reify_type (list[i]));

      // We copy each name added so we can call destroy() on the
      // list, which disposes of the contents as well as the
      // nested tail pointers.
      UTL_NameList *name_item = 0;
      ACE_NEW_RETURN (name_item,
                      UTL_NameList (item->name ()->copy (), 0),
                      0);

      if (retval == 0)
        {
          retval = name_item;
        }
      else
        {
          retval->nconc (name_item);
        }
    }

  return retval;
}
Beispiel #2
0
void
be_component::gen_skel_inheritance (TAO_OutStream *os)
{
  AST_Component *base = this->base_component ();

  if (base != 0)
    {
      *os << "public virtual POA_" << base->name ();
    }
  else
    {
      *os << "public virtual POA_Components::CCMObject";
    }

  long nsupports = this->n_inherits ();
  AST_Type **supports = this->supports ();
  AST_Type *supported = 0;

  for (long i = 0; i < nsupports; ++i)
    {
      supported = supports[i];

      if (supported->is_abstract ())
        {
          continue;
        }

      *os << "," << be_nl;
      *os << "public virtual POA_" << supported->name ();
    }
}
Beispiel #3
0
int
be_visitor_home_svh::gen_servant_class (void)
{
  AST_Decl *scope = ScopeAsDecl (node_->defined_in ());
  ACE_CString sname_str (scope->full_name ());
  const char *sname = sname_str.c_str ();

  // No '_cxx_' prefix.
  const char *lname =
    node_->original_local_name ()->get_string ();

  const char *clname = comp_->local_name ()->get_string ();
  const char *global = (sname_str == "" ? "" : "::");

  os_ << be_nl
      << "class " << export_macro_.c_str () << " " << lname
      << "_Servant" << be_idt_nl
      << ": public virtual" << be_idt << be_idt_nl
      << "::CIAO::"
      << "Home_Servant_Impl<" << be_idt_nl
      << "::" << node_->full_skel_name () << "," << be_nl
      << global << sname << "::CCM_" << lname << "," << be_nl
      << clname << "_Servant," << be_nl
      << "::CIAO::" << be_global->ciao_container_type () << "_Container>"
      << be_uidt << be_uidt << be_uidt << be_uidt_nl
      << "{" << be_nl
      << "public:" << be_idt_nl;

  os_ << lname << "_Servant (" << be_idt_nl
      << global << sname << "::CCM_" << lname << "_ptr exe," << be_nl
      << "const char * ins_name," << be_nl
      << "::CIAO::" << be_global->ciao_container_type ()
      << "_Container_ptr c);" << be_uidt;

  os_ << be_nl_2
      << "virtual ~" << lname << "_Servant (void);";

  if (this->node_->has_rw_attributes ())
    {
      os_ << be_nl_2
          << "virtual void" << be_nl
          << "set_attributes (const "
          << "::Components::ConfigValues & descr);";
    }

AST_Type *pk = node_->primary_key ();

  if (pk != 0)
    {
      os_ << be_nl_2
          << "// Implicit home primary key operations - not supported.";

      os_ << be_nl_2
          << "virtual ::" << comp_->name () << "_ptr" << be_nl
          << "create (" << be_idt_nl
          << "::" << pk->name () << " * key);" << be_uidt;

      if (!be_global->gen_lwccm ())
        {
          os_ << be_nl_2
              << "virtual ::" << comp_->name () << "_ptr" << be_nl
              << "find_by_primary_key (" << be_idt_nl
              << "::" << pk->name () << " * key);" << be_uidt;
        }

      os_ << be_nl_2
          << "virtual void" << be_nl
          << "remove (" << be_idt_nl
          << "::" << pk->name () << " * key);" << be_uidt;

      if (!be_global->gen_lwccm ())
        {
          os_ << be_nl_2
              << "virtual ::" << pk->name () << " *" << be_nl
              << "get_primary_key (" << be_idt_nl
              << "::" << comp_->name () << "_ptr comp);" << be_uidt;
        }
    }

  be_home *h = node_;

  while (h != 0)
    {
      if (this->visit_scope (h) != 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("be_visitor_home_svh::")
                             ACE_TEXT ("gen_servant_class - ")
                             ACE_TEXT ("visit_scope() failed\n")),
                            -1);
        }

      for (long i = 0; i < h->n_inherits (); ++i)
        {
          // A closure of all the supported interfaces is stored
          // in the base class 'pd_inherits_flat' member.
          be_interface *bi =
            be_interface::narrow_from_decl (h->inherits ()[i]);

          int status =
            bi->traverse_inheritance_graph (
              be_visitor_home_svh::op_attr_decl_helper,
              &os_);

          if (status == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 ACE_TEXT ("be_visitor_home_svh::")
                                 ACE_TEXT ("gen_servant_class - ")
                                 ACE_TEXT ("traverse_inheritance_graph() ")
                                 ACE_TEXT ("failed for %s\n"),
                                 bi->full_name ()),
                                -1);
            }
        }

      h = be_home::narrow_from_decl (h->base_home ());
    }

  os_ << be_uidt_nl
      << "};";

  return 0;
}
bool
metaclass_generator::gen_typedef(AST_Typedef*, UTL_ScopedName* name, AST_Type* type, const char*)
{
  AST_Array* arr = AST_Array::narrow_from_decl(type);
  AST_Sequence* seq = 0;
  if (!arr && !(seq = AST_Sequence::narrow_from_decl(type))) {
    return true;
  }

  const Classification cls = classify(type);
  const std::string clazz = scoped(name);
  ContentSubscriptionGuard csg;
  NamespaceGuard ng;
  Function f("gen_skip_over", "bool");
  f.addArg("ser", "Serializer&");
  f.addArg("", clazz + ((cls & CL_ARRAY) ? "_forany*" : "*"));
  f.endArgs();

  std::string len;
  AST_Type* elem;

  if (arr) {
    elem = arr->base_type();
    size_t n_elems = 1;
    for (size_t i = 0; i < arr->n_dims(); ++i) {
      n_elems *= arr->dims()[i]->ev()->u.ulval;
    }
    std::ostringstream strstream;
    strstream << n_elems;
    len = strstream.str();
  } else { // Sequence
    elem = seq->base_type();
    be_global->impl_ <<
      "  ACE_CDR::ULong length;\n"
      "  if (!(ser >> length)) return false;\n";
    len = "length";
  }

  const std::string cxx_elem = scoped(elem->name());
  elem = resolveActualType(elem);
  const Classification elem_cls = classify(elem);

  if ((elem_cls & (CL_PRIMITIVE | CL_ENUM)) && !(elem_cls & CL_WIDE)) {
    // fixed-length sequence/array element -> skip all elements at once
    int sz = 1;
    to_cxx_type(elem, sz);
    be_global->impl_ <<
      "  return ser.skip(" << len << ", " << sz << ");\n";
  } else {
    be_global->impl_ <<
      "  for (ACE_CDR::ULong i = 0; i < " << len << "; ++i) {\n";
    if ((elem_cls & CL_PRIMITIVE) && (elem_cls & CL_WIDE)) {
      be_global->impl_ <<
        "    ACE_CDR::Octet o;\n"
        "    if (!(ser >> ACE_InputCDR::to_octet(o))) return false;\n"
        "    if (!ser.skip(o)) return false;\n";
    } else if (elem_cls & CL_STRING) {
      be_global->impl_ <<
        "    ACE_CDR::ULong strlength;\n"
        "    if (!(ser >> strlength)) return false;\n"
        "    if (!ser.skip(strlength)) return false;\n";
    } else if (elem_cls & (CL_ARRAY | CL_SEQUENCE | CL_STRUCTURE)) {
      be_global->impl_ <<
        "    if (!gen_skip_over(ser, static_cast<" << cxx_elem <<
        ((elem_cls & CL_ARRAY) ? "_forany" : "") << "*>(0))) return false;\n";
    }
    be_global->impl_ <<
      "  }\n";
    be_global->impl_ <<
      "  return true;\n";
  }

  return true;
}
Beispiel #5
0
int
be_visitor_home_svs::gen_servant_class (void)
{
  AST_Decl *scope = ScopeAsDecl (node_->defined_in ());
  ACE_CString sname_str (scope->full_name ());
  const char *sname = sname_str.c_str ();

  // Avoid '_cxx_' prefix.
  const char *lname =
    node_->original_local_name ()->get_string ();

  const char *clname = comp_->local_name ()->get_string ();
  const char *global = (sname_str == "" ? "" : "::");

  os_ << be_nl
      << lname << "_Servant::"
      << lname << "_Servant (" << be_idt << be_idt_nl
      << global << sname << "::CCM_" << lname << "_ptr exe," << be_nl
      << "const char * ins_name," << be_nl
      << "::CIAO::" << be_global->ciao_container_type ()
      << "_Container_ptr c)" << be_uidt_nl
      << ": ::CIAO::Home_Servant_Impl_Base ()," << be_idt_nl
      << "::CIAO::"
      << "Home_Servant_Impl<" << be_idt_nl
      << "::" << node_->full_skel_name () << "," << be_nl
      << global << sname << "::CCM_" << lname << "," << be_nl
      << clname << "_Servant," << be_nl
      << "::CIAO::" << be_global->ciao_container_type () << "_Container> (exe, c, ins_name)"
      << be_uidt << be_uidt << be_uidt_nl
      << "{" << be_nl
      << "}";

  os_ << be_nl_2
      << lname << "_Servant::~" << lname << "_Servant (void)"
      << be_nl
      << "{" << be_nl
      << "}";

  if (this->node_->has_rw_attributes ())
    {
      os_ << be_nl_2
          << "void" << be_nl
          << lname << "_Servant::set_attributes (" << be_idt_nl
          << "const ::Components::ConfigValues & descr)"
          << be_uidt_nl
          << "{" << be_idt_nl;

      os_ << "for ( ::CORBA::ULong i = 0; i < descr.length (); ++i)"
          << be_idt_nl
          << "{" << be_idt_nl
          << "const char * descr_name = descr[i]->name ();"
          << be_nl
          << "::CORBA::Any & descr_value = descr[i]->value ();";

      be_visitor_home_attr_set as_visitor (this->ctx_);

      if (as_visitor.visit_home (node_) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "home_svs::"
                             "gen_servant_class - "
                             "attr init visitor failed\n"),
                            -1);
        }

      os_ << be_uidt_nl
          << "}" << be_uidt << be_uidt_nl
          << "}";
    }

  AST_Type *pk = node_->primary_key ();

  if (pk != 0)
    {
      os_ << be_nl_2
          << "::" << comp_->name () << "_ptr" << be_nl
          << lname << "_Servant::create (" << be_idt_nl
          << "::" << pk->name () << " * /* key */)" << be_uidt_nl
          << "{" << be_idt_nl
          << "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
          << be_nl
          << "                             CORBA::COMPLETED_NO);"
          << be_uidt_nl
          << "}";

      if (!be_global->gen_lwccm ())
        {
          os_ << be_nl_2
              << "::" << comp_->name () << "_ptr" << be_nl
              << lname << "_Servant::find_by_primary_key (" << be_idt_nl
              << "::" << pk->name () << " * /* key */)" << be_uidt_nl
              << "{" << be_idt_nl
              << "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
              << be_nl
              << "                             CORBA::COMPLETED_NO);"
              << be_uidt_nl
              << "}";
        }

      os_ << be_nl_2
          << "void" << be_nl
          << lname << "_Servant::remove (" << be_idt_nl
          << "::" << pk->name () << " * /* key */)" << be_uidt_nl
          << "{" << be_idt_nl
          << "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
          << be_nl
          << "                             CORBA::COMPLETED_NO);"
          << be_uidt_nl
          << "}";

      if (!be_global->gen_lwccm ())
        {
          os_ << be_nl_2
              << "::" << pk->name () << " *" << be_nl
              << lname << "_Servant::get_primary_key (" << be_idt_nl
              << "::" << comp_->name () << "_ptr /* comp */)" << be_uidt_nl
              << "{" << be_idt_nl
              << "throw ::CORBA::NO_IMPLEMENT (CORBA::OMGVMCID | 8,"
              << be_nl
              << "                             CORBA::COMPLETED_NO);"
              << be_uidt_nl
              << "}";
        }
    }

  be_home *h = node_;

  while (h != 0)
    {
      if (this->visit_scope (h) != 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("be_visitor_home_svs::")
                             ACE_TEXT ("gen_servant_class - ")
                             ACE_TEXT ("codegen for scope failed\n")),
                            -1);
        }

      for (long i = 0; i < h->n_inherits (); ++i)
        {
          // A closure of all the supported interfaces is stored
          // in the base class 'pd_inherits_flat' member.
          be_interface *bi =
            be_interface::narrow_from_decl (h->inherits ()[i]);

          bi->get_insert_queue ().reset ();
          bi->get_del_queue ().reset ();
          bi->get_insert_queue ().enqueue_tail (bi);

          Home_Op_Attr_Generator op_attr_gen (this);

          int status =
            bi->traverse_inheritance_graph (op_attr_gen,
                                            &os_,
                                            false,
                                            false);

          if (status == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 ACE_TEXT ("be_visitor_home_svs::")
                                 ACE_TEXT ("gen_servant_class - ")
                                 ACE_TEXT ("traverse_inheritance_graph() ")
                                 ACE_TEXT ("failed for %s\n"),
                                 bi->full_name ()),
                                -1);
            }

        }

      h = be_home::narrow_from_decl (h->base_home ());
    }

  return 0;
}