fe_interface_header.cpp

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

CPP
970
字号
{
  return this->pd_interface_name;
}

AST_Interface **
FE_InterfaceHeader::inherits (void) const
{
  return this->pd_inherits;
}

long
FE_InterfaceHeader::n_inherits (void) const
{
  return this->pd_n_inherits;
}

AST_Interface **
FE_InterfaceHeader::inherits_flat (void) const
{
  return this->pd_inherits_flat;
}

long
FE_InterfaceHeader::n_inherits_flat (void) const
{
  return this->pd_n_inherits_flat;
}

//************************************************************************

FE_OBVHeader::FE_OBVHeader (UTL_ScopedName *n,
                            UTL_NameList *inherits,
                            UTL_NameList *supports,
                            idl_bool truncatable,
                            idl_bool is_eventtype)
  : FE_InterfaceHeader (n,
                        inherits,
                        I_FALSE,
                        I_FALSE,
                        I_FALSE),
    pd_supports (0),
    pd_inherits_concrete (0),
    pd_supports_concrete (0),
    pd_truncatable (truncatable)
{
  this->compile_inheritance (inherits,
                             I_TRUE);

  if (this->pd_n_inherits > 0)
    {
      AST_Interface *iface = this->pd_inherits[0];
      AST_ValueType *vt = AST_ValueType::narrow_from_decl (iface);

      if (vt != 0
          && vt->is_abstract () == I_FALSE)
        {
          this->pd_inherits_concrete = vt;
        }

      if (! is_eventtype
          && this->pd_inherits[0]->node_type () == AST_Decl::NT_eventtype)
        {
          idl_global->err ()->valuetype_expected (this->pd_inherits[0]);
        }

      for (long i = 1; i < this->pd_n_inherits; ++i)
        {
          iface = this->pd_inherits[i];

          if (!iface->is_abstract ())
            {
              idl_global->err ()->abstract_expected (iface);
            }

          if (! is_eventtype
              && iface->node_type () == AST_Decl::NT_eventtype)
            {
              idl_global->err ()->valuetype_expected (iface);
            }
        }
    }

  if (idl_global->err_count () == 0)
    {
      this->compile_supports (supports);
    }
}

FE_OBVHeader::~FE_OBVHeader (void)
{
}

AST_Interface **
FE_OBVHeader::supports (void) const
{
  return this->pd_supports;
}

long
FE_OBVHeader::n_supports (void) const
{
  return this->pd_n_supports;
}

AST_ValueType *
FE_OBVHeader::inherits_concrete (void) const
{
  return this->pd_inherits_concrete;
}

AST_Interface *
FE_OBVHeader::supports_concrete (void) const
{
  return this->pd_supports_concrete;
}

idl_bool
FE_OBVHeader::truncatable (void) const
{
  return this->pd_truncatable;
}

void
FE_OBVHeader::compile_supports (UTL_NameList *supports)
{
  if (supports == 0)
    {
      this->pd_supports = 0;
      this->pd_n_supports = 0;
      return;
    }

  long length = supports->length ();
  this->pd_n_supports = length;
  ACE_NEW (this->pd_supports,
           AST_Interface *[length]);

  AST_Decl *d = 0;
  UTL_ScopedName *item = 0;;
  AST_Interface *iface = 0;
  int i = 0;

  for (UTL_NamelistActiveIterator l (supports); !l.is_done (); l.next ())
    {
      item = l.item ();

      // Check that scope stack is valid.
      if (idl_global->scopes ().top () == 0)
        {
          idl_global->err ()->lookup_error (item);
          return;
        }

      // Look it up.
      UTL_Scope *s = idl_global->scopes ().top ();

      d = s->lookup_by_name  (item,
                              I_TRUE);

      if (d == 0)
        {
          AST_Decl *sad = ScopeAsDecl (s);

          if (sad->node_type () == AST_Decl::NT_module)
            {
              AST_Module *m = AST_Module::narrow_from_decl (sad);

              d = m->look_in_previous (item->last_component ());
            }
        }

      // Not found?
      if (d == 0)
        {
          idl_global->err ()->lookup_error (item);
          return;
        }

      // Remove typedefs, if any.
      if (d->node_type () == AST_Decl::NT_typedef)
        {
          d = AST_Typedef::narrow_from_decl (d)->primitive_base_type ();
        }

      if (d->node_type () == AST_Decl::NT_interface)
        {
          iface = AST_Interface::narrow_from_decl (d);
        }
      else
        {
          idl_global->err ()->supports_error (pd_interface_name,
                                              d);
          continue;
        }

      // Forward declared interface?
      if (!iface->is_defined ())
        {
          idl_global->err ()->supports_fwd_error (pd_interface_name,
                                                  iface);
          continue;
        }

      if (!iface->is_abstract ())
        {
          if (i == 0)
            {
              this->pd_supports_concrete = iface;

              if (this->check_concrete_supported_inheritance (iface) != 0)
                {
                  idl_global->err ()->concrete_supported_inheritance_error (
                                          this->name (),
                                          iface->name ()
                                        );
                }
            }
          else
            {
              idl_global->err ()->abstract_expected (iface);
              continue;
            }
        }

      this->pd_supports[i++] = iface;
    }
}

idl_bool 
FE_OBVHeader::check_concrete_supported_inheritance (AST_Interface *d)
{
  AST_ValueType *vt = 0;
  AST_Interface *concrete = 0;
  AST_Interface **ancestors = 0;
  AST_Interface *ancestor = 0;
  long n_ancestors = 0;

  for (long i = 0; i < this->pd_n_inherits; ++i)
    {
      vt = AST_ValueType::narrow_from_decl (this->pd_inherits[i]);
      concrete = vt->supports_concrete ();

      if (concrete != 0)
        {
          ancestors = concrete->inherits_flat ();
          n_ancestors = concrete->n_inherits_flat ();

          for (long j = 0; j < n_ancestors; ++j)
            {
              ancestor = ancestors[j];

              if (!d->is_child (ancestor))
                {
                  return 1;
                }
            }
        }
    }

  return 0;
}

//************************************************************************

FE_EventHeader::FE_EventHeader (UTL_ScopedName *n,
                                UTL_NameList *inherits,
                                UTL_NameList *supports,
                                idl_bool truncatable)
  : FE_OBVHeader (n,
                  inherits,
                  supports,
                  truncatable,
                  I_TRUE)
{
}

FE_EventHeader::~FE_EventHeader (void)
{
}

//************************************************************************

FE_ComponentHeader::FE_ComponentHeader (UTL_ScopedName *n, 
                                        UTL_ScopedName *base_component, 
                                        UTL_NameList *supports,
                                        idl_bool /* compile_now */)
  : FE_InterfaceHeader (n,
                        supports,
                        I_FALSE,
                        I_FALSE,
                        I_FALSE),
    pd_base_component (0)
{
  // If there is a base component, look up the decl and assign our member.
  // We also inherit its supported interfaces.
  if (base_component != 0)
    {
      UTL_Scope *s = idl_global->scopes ().top_non_null ();
      AST_Decl *d = s->lookup_by_name (base_component,
                                       I_TRUE);

      if (d == 0)
        {
          idl_global->err ()->lookup_error (base_component);
        }
      else
        {
          this->pd_base_component = AST_Component::narrow_from_decl (d);

          if (this->pd_base_component == 0)
            {
              idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_USE,
                                          d);
            }
          else if (!this->pd_base_component->is_defined ())
            {
              idl_global->err ()->inheritance_fwd_error (
                                      this->name (),
                                      this->pd_base_component
                                    );
            }
        }
    }

  this->compile_inheritance (supports,
                             I_FALSE);
}

FE_ComponentHeader::~FE_ComponentHeader (void)
{
}

AST_Component *
FE_ComponentHeader::base_component (void) const
{
  return this->pd_base_component;
}

AST_Interface **
FE_ComponentHeader::supports (void) const
{
  return this->pd_inherits;
}

long 
FE_ComponentHeader::n_supports (void) const
{
  return this->pd_n_inherits;
}

AST_Interface **
FE_ComponentHeader::supports_flat (void) const
{
  return this->pd_inherits_flat;
}

long
FE_ComponentHeader::n_supports_flat (void) const
{
  return this->pd_n_inherits_flat;
}

//************************************************************************

FE_HomeHeader::FE_HomeHeader (UTL_ScopedName *n,
                              UTL_ScopedName *base_home,
                              UTL_NameList *supports,
                              UTL_ScopedName *managed_component,
                              UTL_ScopedName *primary_key)
  : FE_ComponentHeader (n,
                        managed_component,
                        supports,
                        I_FALSE),
    pd_base_home (0),
    pd_primary_key (0)
{
  UTL_Scope *s = idl_global->scopes ().top_non_null ();
  AST_Decl *d = 0;

  if (base_home != 0)
    {
      d = s->lookup_by_name (base_home,
                             I_TRUE);

      if (d == 0)
        {
          idl_global->err ()->lookup_error (base_home);
        }
      else
        {
          this->pd_base_home = AST_Home::narrow_from_decl (d);

          if (this->pd_base_home == 0)
            {
              idl_global->err ()->inheritance_error (this->name (),
                                                     d);
            }
        }
    }

  if (managed_component != 0)
    {
      d = s->lookup_by_name (managed_component,
                             I_TRUE);

      if (d == 0)
        {
          idl_global->err ()->lookup_error (managed_component);
        }
      else
        {
          this->pd_base_component = AST_Component::narrow_from_decl (d);

          if (this->pd_base_component == 0)
            {
              idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_USE,
                                          d);
            }
        }
    }

  if (primary_key != 0)
    {
      d = s->lookup_by_name (primary_key,
                             I_TRUE);

      if (d == 0)
        {
          idl_global->err ()->lookup_error (primary_key);
        }
      else
        {
          this->pd_primary_key = AST_ValueType::narrow_from_decl (d);

          if (this->pd_primary_key == 0)
            {
              idl_global->err ()->valuetype_expected (d);
            }
        }
    }

  this->compile_inheritance (supports,
                             I_FALSE);
}

void
FE_HomeHeader::compile_inheritance (UTL_NameList *supports,
                                    idl_bool for_valuetype)
{
  if (this->pd_base_home != 0)
    {
      UTL_NameList *base_home_name = 0;
      ACE_NEW (base_home_name,
               UTL_NameList (this->pd_base_home->name (),
                             supports));

      supports = base_home_name;
      this->FE_InterfaceHeader::compile_inheritance (supports,
                                                     for_valuetype);
    }
}

FE_HomeHeader::~FE_HomeHeader (void)
{
}

AST_Home *
FE_HomeHeader::base_home (void) const
{
  return this->pd_base_home;
}

AST_Component *
FE_HomeHeader::managed_component (void) const
{
  return this->pd_base_component;
}

AST_ValueType *
FE_HomeHeader::primary_key (void) const
{
  return this->pd_primary_key;
}

⌨️ 快捷键说明

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