예제 #1
0
파일: be_util.cpp 프로젝트: INMarkus/ATCD
void
be_util::set_arg_seen_bit (be_type *bt)
{
  if (bt == 0)
    {
      return;
    }

  switch (bt->node_type ())
    {
      case AST_Decl::NT_typedef:
        {
          AST_Typedef *td = AST_Typedef::narrow_from_decl (bt);
          be_util::set_arg_seen_bit (
                    be_type::narrow_from_decl (td->primitive_base_type ())
                  );
          break;
        }
      case AST_Decl::NT_interface:
      case AST_Decl::NT_interface_fwd:
      case AST_Decl::NT_valuetype:
      case AST_Decl::NT_valuetype_fwd:
      case AST_Decl::NT_component:
      case AST_Decl::NT_component_fwd:
      case AST_Decl::NT_home:
      case AST_Decl::NT_eventtype:
      case AST_Decl::NT_eventtype_fwd:
        idl_global->object_arg_seen_ = true;
        break;
      case AST_Decl::NT_union:
      case AST_Decl::NT_struct:
        if (bt->size_type () == AST_Type::FIXED)
          {
            idl_global->fixed_size_decl_seen_ = true;
          }
        else
          {
            idl_global->var_size_decl_seen_ = true;
          }

        break;
      case AST_Decl::NT_struct_fwd:
      case AST_Decl::NT_union_fwd:
        {
          AST_StructureFwd *fwd = AST_StructureFwd::narrow_from_decl (bt);
          be_type *fd = be_type::narrow_from_decl (fwd->full_definition ());
          be_util::set_arg_seen_bit (fd);
          break;
        }
      case AST_Decl::NT_enum:
      case AST_Decl::NT_enum_val:
//        idl_global->basic_arg_seen_ = true;
        break;
      case AST_Decl::NT_string:
      case AST_Decl::NT_wstring:
        {
          AST_String *str = AST_String::narrow_from_decl (bt);

          if (str->max_size ()->ev ()->u.ulval == 0)
            {
              idl_global->ub_string_seen_ = true;
            }
          else
            {
              idl_global->bd_string_seen_ = true;
            }

          break;
        }
      case AST_Decl::NT_array:
        if (bt->size_type () == AST_Type::FIXED)
          {
            idl_global->fixed_array_decl_seen_ = true;
          }
        else
          {
            idl_global->var_array_decl_seen_ = true;
          }

        break;
      case AST_Decl::NT_sequence:
        idl_global->var_size_decl_seen_ = true;
        break;
      case AST_Decl::NT_pre_defined:
        {
          AST_PredefinedType *pdt = AST_PredefinedType::narrow_from_decl (bt);

          switch (pdt->pt ())
            {
              case AST_PredefinedType::PT_object:
              case AST_PredefinedType::PT_pseudo:
              case AST_PredefinedType::PT_value:
              case AST_PredefinedType::PT_abstract:
                idl_global->object_arg_seen_ = true;
                break;
              case AST_PredefinedType::PT_any:
                idl_global->var_size_decl_seen_ = true;
                idl_global->any_arg_seen_ = true;
                break;
              case AST_PredefinedType::PT_char:
              case AST_PredefinedType::PT_wchar:
              case AST_PredefinedType::PT_octet:
              case AST_PredefinedType::PT_boolean:
                idl_global->special_basic_decl_seen_ = true;
                break;
             default:
                break;
            }
        }
      default:
        break;
    }
}
예제 #2
0
int
be_visitor_arg_traits::visit_attribute (be_attribute *node)
{
  if (this->ctx_->alias () != 0 || this->generated (node))
    {
      return 0;
    }

  AST_String *st = AST_String::narrow_from_decl (node->field_type ());

  if (st == 0)
    {
      return 0;
    }

  ACE_CDR::ULong bound = st->max_size ()->ev ()->u.ulval;

  if (bound == 0)
    {
      return 0;
    }

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

  *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
      << "// " << __FILE__ << ":" << __LINE__;

  std::string guard_suffix =
    std::string (this->S_) + std::string ("arg_traits");

  // The guard should be generated to prevent multiple declarations,
  // since a bounded (w)string of the same length may be used or typedef'd
  // more than once.

  os->gen_ifdef_macro (node->flat_name (), guard_suffix.c_str (), false);

  bool wide = (st->width () != 1);

  // It is legal IDL to declare a bounded (w)string as an operation
  // parameter type. There could be any number of identical
  // declarations in the same build, translation unit, or even in
  // the same operation, so we use the argument's flat name to
  // declare an empty struct, and use that struct as the template
  // parameter for Arg_Traits<>.

  *os << be_nl;

  // Avoid generating a duplicate structure in the skeleton.
  if (ACE_OS::strlen (this->S_) == 0)
    {
      *os << "struct " << node->flat_name () << " {};"
          << be_nl_2;
    }

  *os << "template<>" << be_nl
      << "class "
      << this->S_ << "Arg_Traits<"
      << node->flat_name ()
      << ">" << be_idt_nl
      << ": public" << be_idt << be_idt_nl
      << "BD_String_" << this->S_ << "Arg_Traits_T<" << be_nl
      << "CORBA::" << (wide ? "W" : "") << "String_var," << be_nl
      << bound << "," << be_nl
      << this->insert_policy()
      << ">"
      << be_uidt << be_uidt << be_uidt_nl
      << "{" << be_nl
      << "};";

  os->gen_endif ();

  this->generated (node, true);
  return 0;
}
예제 #3
0
void be_string::InitializeTypeMap (be_Type* t)
{
   idlType = t;

   AST_Expression* maxsize = 0;
   be_string* t_string = 0;
   be_typedef* t_typedef = 0;
   DDS_StdString corbaString;
   DDS_StdString stringInOut;
   DDS_StdString stringOut;
   DDS_StdString structStringVar;

   if (m_typecode->kind == DDS::tk_string)
   {
      corbaString = BE_Globals::CorbaScope("String");
      stringInOut = BE_Globals::CorbaScope("String&");
      stringOut = BE_Globals::CorbaScope("String_out");
      structStringVar = BE_Globals::CorbaScope ("String_mgr");
   }
   else
   {
      corbaString = BE_Globals::CorbaScope ("WString");
      stringInOut = BE_Globals::CorbaScope ("WString&");
      stringOut = BE_Globals::CorbaScope ("WString_out");
      structStringVar = BE_Globals::CorbaScope ("WString_var");
   }

   char size[10];
   os_sprintf (size, "%d", (int) ExprToULong(maxsize));

   t_typedef = (be_typedef*)t->narrow((long) & be_typedef::type_id);
   if (t_typedef) 
   {
      AST_Type * t_ast = (AST_Type*)t->narrow((long) & AST_Type::type_id);

      AST_Type * basetype;
      AST_String * realbasetype;

      (void) t_ast;
      assert (t_ast);

      basetype = be_typedef::_astBase(((AST_Typedef*)t->narrow((long) & AST_Typedef::type_id))->base_type());
      assert(basetype);

      realbasetype = (AST_String*)basetype->narrow((long) & AST_String::type_id);
      assert(realbasetype);

      maxsize = realbasetype->max_size();
      corbaString = t->Scope(t->LocalName());
      stringInOut = corbaString + "&";
      stringOut = corbaString + DDSOutExtension;
      t->TypeCodeTypeName(BE_Globals::TCPrefix + t->LocalName());
      //  t->MetaTypeTypeName(BE_Globals::MTPrefix + NameToString(t_ast->name(),"_"));
      t->MetaTypeTypeName("xps_mt_DDS::String");
   }
   else
   {
      t_string = (be_string*)t->narrow((long) & be_string::type_id);
      assert(t_string);
      maxsize = t_string->max_size();
      // YO JFG 2/14/99 modified this
      // t->TypeCodeTypeName((DDS_StdString)"DDSTypeCodeFactory::createTypeCode(DDS::tk_string," + size + ")");

      if (m_typecode->kind == DDS::tk_string)
      {
         t->TypeCodeTypeName ("DDS::_tc_string");
      }
      else
      {
         t->TypeCodeTypeName ("DDS::_tc_wstring");
      }
   }

   t->TypeName(corbaString);

   if (m_typecode->kind == DDS::tk_string)
   {
      t->InTypeName ((DDS_StdString)"const char *"); // NOTE: != const corbaString;
   }
   else
   {
      t->InTypeName ((DDS_StdString)"const WChar *"); // NOTE: != const corbaString;
   }

   t->InOutTypeName (stringInOut);
   t->OutTypeName (stringOut);
   t->ReturnTypeName (stringOut);
   t->DMFAdtMemberTypeName (corbaString);
   t->StructMemberTypeName (structStringVar);
   t->UnionMemberTypeName (corbaString);
   t->SequenceMemberTypeName (corbaString);

   if (m_typecode->kind == DDS::tk_string)
   {
      t->VarSignature(VT_InParam, "DDS::Char", VT_Const, VT_Pointer, VT_NonReference);
   }
   else
   {
      t->VarSignature(VT_InParam, "DDS::WChar", VT_Const, VT_Pointer, VT_NonReference);
   }

   t->VarSignature (VT_InOutParam, stringInOut, VT_NonConst, VT_Var, VT_NonReference);
   t->VarSignature (VT_OutParam, stringOut, VT_NonConst, VT_Var, VT_NonReference);
   t->VarSignature (VT_Return, t->TypeName(), VT_NonConst, VT_Var, VT_NonReference);
}
예제 #4
0
int
be_visitor_arg_traits::visit_operation (be_operation *node)
{
  if (this->generated (node) || node->is_local () || node->imported ())
    {
      return 0;
    }

  AST_Type *rt = node->return_type ();
  AST_Decl::NodeType nt = rt->node_type ();

  // If our return type is an unaliased bounded (w)string, we create
  // an empty struct using the operation's flat name for the type,
  // and use this type as the Arg_Traits<> template parameter. All
  // this is necessary because there could be any number of such
  // return types, all identical, in the same interface, valuetype,
  // translation unit, or build, and we need a unique type for the
  // Arg_Traits<> template parameter.
  if (nt == AST_Decl::NT_string || nt == AST_Decl::NT_wstring)
    {
      AST_String *str = AST_String::narrow_from_decl (rt);
      ACE_CDR::ULong bound = str->max_size ()->ev ()->u.ulval;

      if (bound > 0)
        {
          TAO_OutStream *os = this->ctx_->stream ();

          *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl
              << "// " << __FILE__ << ":" << __LINE__;

          std::string guard_suffix =
            std::string (this->S_) + std::string ("arg_traits");

          // The guard should be generated to prevent multiple declarations,
          // since a bounded (w)string of the same length may be used or typedef'd
          // more than once.

          os->gen_ifdef_macro (node->flat_name (), guard_suffix.c_str (), false);

          bool wide = (str->width () != 1);

          *os << be_nl_2;

          // Avoid generating a duplicate structure in the skeleton.
          if (ACE_OS::strlen (this->S_) == 0)
            {
              *os << "struct " << node->flat_name () << " {};"
                  << be_nl_2;
            }

          *os << "template<>" << be_nl
              << "class "
              << this->S_ << "Arg_Traits<"
              << node->flat_name ()
              << ">" << be_idt_nl
              << ": public" << be_idt << be_idt_nl
              << "BD_String_" << this->S_ << "Arg_Traits_T<" << be_nl
              << "CORBA::" << (wide ? "W" : "") << "String_var," << be_nl
              << bound << "," << be_nl
              << this->insert_policy()
              << ">"
              << be_uidt << be_uidt << be_uidt_nl
              << "{" << be_nl
              << "};";

          os->gen_endif ();
        }
    }

  // This will catch (in visit_argument() below) any parameters that
  // are unaliased, bounded (w)strings.
  if (this->visit_scope (node) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_arg_traits::")
                         ACE_TEXT ("visit_operation - visit scope failed\n")),
                        -1);
    }

  this->generated (node, true);
  return 0;
}