Exemplo n.º 1
0
int
ast_visitor_reifying::visit_sequence (AST_Sequence *node)
{
  AST_Type *bt = node->base_type ();

  if (bt->ast_accept (this) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("ast_visitor_reifying::")
                         ACE_TEXT ("visit_sequence - ")
                         ACE_TEXT ("visit of base type failed\n")),
                        -1);
    }

  bt = AST_Type::narrow_from_decl (this->reified_node_);

  AST_Expression *v = node->max_size ();
  AST_Param_Holder *ph = v->param_holder ();

  if (ph != 0)
    {
      if (this->visit_param_holder (ph) != 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("ast_visitor_reifying::")
                             ACE_TEXT ("visit_sequence - ")
                             ACE_TEXT ("visit_param_holder() ")
                             ACE_TEXT ("failed\n")),
                            -1);
        }

      AST_Constant *c =
        AST_Constant::narrow_from_decl (this->reified_node_);

      v = c->constant_value ();
    }

  AST_Expression *bound =
    idl_global->gen ()->create_expr (v,
                                     AST_Expression::EV_ulong);
  Identifier id ("sequence");
  UTL_ScopedName sn (&id, 0);

  this->reified_node_ =
    idl_global->gen ()->create_sequence (bound,
                                         bt,
                                         &sn,
                                         false,
                                         false);

  // No need to add this new node to any scope - it's anonymous
  // and owned by the node that references it.

  return 0;
}
// Specialized visit_scope method for stucts only.
int
ifr_adding_visitor_structure::visit_scope (UTL_Scope *node)
{
    // If the struct has members that are scopes but not structs,
    // the regular visit_scope method should be called instead.
    if (node->scope_node_type () != AST_Decl::NT_struct)
    {
        return ifr_adding_visitor::visit_scope (node);
    }

    AST_Structure *s = AST_Structure::narrow_from_scope (node);
    CORBA::ULong nfields = static_cast<CORBA::ULong> (s->nfields ());
    this->members_.length (nfields);
    AST_Field **f = 0;

    try
    {
        // Visit each field.
        for (CORBA::ULong i = 0; i < nfields; ++i)
        {
            if (s->field (f, i) != 0)
            {
                ORBSVCS_ERROR_RETURN ((
                                          LM_ERROR,
                                          ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
                                          ACE_TEXT ("visit_scope -")
                                          ACE_TEXT (" field node access failed\n")),
                                      -1);
            }

            AST_Type *ft = (*f)->field_type ();
            bool defined_here = ft->is_child (this->scope_);

            // If the struct member is defined in the struct, we have to
            // do some visiting - otherwise we can just look up the entry.
            if (defined_here)
            {
                if (ft->node_type () == AST_Decl::NT_struct)
                {
                    // Since the enclosing scope hasn't been created yet,
                    // we make a special visitor to create this member
                    // at global scope and move it into the struct later.
                    ifr_adding_visitor_structure visitor (ft);

                    if (ft->ast_accept (&visitor) == -1)
                    {
                        ORBSVCS_ERROR_RETURN ((
                                                  LM_ERROR,
                                                  ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
                                                  ACE_TEXT ("visit_scope -")
                                                  ACE_TEXT (" failed to accept visitor\n")),
                                              -1);
                    }

                    this->ir_current_ =
                        CORBA::IDLType::_duplicate (visitor.ir_current ());
                }
                else
                {
                    if (ft->ast_accept (this) == -1)
                    {
                        ORBSVCS_ERROR_RETURN ((
                                                  LM_ERROR,
                                                  ACE_TEXT ("(%N:%l) ifr_adding_visitor_structure::")
                                                  ACE_TEXT ("visit_scope -")
                                                  ACE_TEXT (" failed to accept visitor\n")),
                                              -1);
                    }
                }
            }
            else
            {
                // Updates ir_current_.
                this->get_referenced_type (ft);
            }

            this->members_[i].name =
                CORBA::string_dup ((*f)->local_name ()->get_string ());

            // IfR method create_struct does not use this - it just needs
            // to be non-zero for marshaling.
            this->members_[i].type =
                CORBA::TypeCode::_duplicate (CORBA::_tc_void);

            this->members_[i].type_def =
                CORBA::IDLType::_duplicate (this->ir_current_.in ());
        }
    }
    catch (const CORBA::Exception& ex)
    {
        ex._tao_print_exception (
            ACE_TEXT (
                "ifr_adding_visitor_structure::visit_scope"));

        return -1;
    }

    return 0;
}
Exemplo n.º 3
0
int
ast_visitor_reifying::visit_array (AST_Array *node)
{
  AST_Type *bt = node->base_type ();

  if (bt->ast_accept (this) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("ast_visitor_reifying::")
                         ACE_TEXT ("visit_array - ")
                         ACE_TEXT ("visit of base type failed\n")),
                        -1);
    }

  bt = AST_Type::narrow_from_decl (this->reified_node_);

  AST_Expression **dims = node->dims ();
  AST_Expression *v = 0;
  UTL_ExprList *v_list = 0;

  for (ACE_CDR::ULong i = 0; i < node->n_dims (); ++i)
    {
      AST_Param_Holder *ph = dims[i]->param_holder ();

      if (ph != 0)
        {
          if (this->visit_param_holder (ph) != 0)
            {
              if (v_list != 0)
                {
                  v_list->destroy ();
                  delete v_list;
                  v_list = 0;
                }

              ACE_ERROR_RETURN ((LM_ERROR,
                                 ACE_TEXT ("ast_visitor_reifying::")
                                 ACE_TEXT ("visit_array - ")
                                 ACE_TEXT ("visit_param_holder() ")
                                 ACE_TEXT ("failed\n")),
                                -1);
            }

          AST_Constant *c =
            AST_Constant::narrow_from_decl (this->reified_node_);

          ACE_NEW_RETURN (v,
                          AST_Expression (c->constant_value (),
                                          AST_Expression::EV_ulong),
                          -1);
        }
      else
        {
          ACE_NEW_RETURN (v,
                          AST_Expression (dims[i],
                                          AST_Expression::EV_ulong),
                          -1);
        }

      UTL_ExprList *el = 0;
      ACE_NEW_RETURN (el,
                      UTL_ExprList (v, 0),
                      -1);

      if (v_list == 0)
        {
          v_list = el;
        }
      else
        {
          v_list->nconc (el);
        }
    }

  UTL_ScopedName sn (node->local_name (), 0);

  AST_Array *arr =
    idl_global->gen ()->create_array (&sn,
                                      node->n_dims (),
                                      v_list,
                                      false,
                                      false);

  // No need to add this new node to any scope - it's anonymous
  // and owned by the node that references it.

  if (v_list != 0)
    {
      v_list->destroy ();
      delete v_list;
      v_list = 0;
    }

  arr->set_base_type (bt);
  this->reified_node_ = arr;

  return 0;
}
Exemplo n.º 4
0
// Specialized visit_scope method for unions only.
int
ifr_adding_visitor_union::visit_scope (UTL_Scope *node)
{
  // If the union has members that are scopes but not unions,
  // the regular visit_scope method should be called instead.
  if (node->scope_node_type () != AST_Decl::NT_union)
    {
      return ifr_adding_visitor::visit_scope (node);
    }

  AST_Union *u = AST_Union::narrow_from_scope (node);

  CORBA::ULong nfields = static_cast<CORBA::ULong> (u->nfields ());

  this->members_.length (nfields);

  AST_Field **f = 0;

  // Index into members_.
  CORBA::ULong index = 0;

  try
    {
      // Visit each field.
      for (CORBA::ULong i = 0; i < nfields; ++i)
        {
          if (u->field (f, i) != 0)
            {
              ORBSVCS_ERROR_RETURN ((
                  LM_ERROR,
                  ACE_TEXT ("(%N:%l) ifr_adding_visitor_union::")
                  ACE_TEXT ("visit_scope -")
                  ACE_TEXT (" field node access failed\n")
                ),
                -1
              );
            }

          AST_Type *ft = (*f)->field_type ();

          bool defined_here = ft->is_child (this->scope_);

          // If the union member is defined in the union, we have to
          // do some visiting - otherwise we can just look up the entry.
          if (defined_here)
            {
              if (ft->node_type () == AST_Decl::NT_union)
                {
                  // Since the enclosing scope hasn't been created yet,
                  // we make a special visitor to create this member
                  // at global scope and move it into the union later.
                  ifr_adding_visitor_union visitor (ft);

                  if (ft->ast_accept (&visitor) == -1)
                    {
                      ORBSVCS_ERROR_RETURN ((
                        LM_ERROR,
                        ACE_TEXT ("(%N:%l) ifr_adding_visitor_union::")
                        ACE_TEXT ("visit_scope -")
                        ACE_TEXT (" failed to accept visitor\n")),
                       -1);
                    }

                  this->ir_current_ =
                    CORBA::IDLType::_duplicate (visitor.ir_current ());
                }
              else
                {
                  if (ft->ast_accept (this) == -1)
                    {
                      ORBSVCS_ERROR_RETURN ((
                        LM_ERROR,
                        ACE_TEXT ("(%N:%l) ifr_adding_visitor_union::")
                        ACE_TEXT ("visit_scope -")
                        ACE_TEXT (" failed to accept visitor\n")),
                       -1);
                    }
                }
            }
          else
            {
              // Updates ir_current_.
              this->get_referenced_type (ft);
            }

          // Get the case label(s).

          AST_UnionLabel *case_label = 0;
          AST_UnionBranch *ub = AST_UnionBranch::narrow_from_decl (*f);
          unsigned long len = ub->label_list_length ();

          // If there are multiple case labels, we will have an element
          // in the UnionMemberSeq for each label, not just for each member,
          // so the list length and the loop terminator must both be
          // increased accordingly.
          if (len > 1)
            {
              this->members_.length (this->members_.length () + len - 1);
            }

          for (unsigned long j = 0; j < len; ++j)
            {
              case_label = ub->label (j);

              // Is this a regular label or default label?
              if (case_label->label_kind () == AST_UnionLabel::UL_label)
                {
                  AST_Expression::AST_ExprValue *ev =
                    case_label->label_val ()->ev ();

                  // If the discriminator is an enum, we can't just insert
                  // a ulong into the Any member of struct UnionMember.
                  if (u->disc_type ()->node_type () == AST_Decl::NT_enum)
                    {
                      TAO_OutputCDR cdr;
                      cdr.write_ulong (ev->u.ulval);
                      TAO_InputCDR in_cdr (cdr);
                      TAO::Unknown_IDL_Type *unk = 0;
                      ACE_NEW_RETURN (unk,
                                      TAO::Unknown_IDL_Type (
                                        this->disc_tc_.in (),
                                        in_cdr),
                                       -1);
                      this->members_[index].label.replace (unk);
                    }
                  else
                    {
                      this->load_any (ev,
                                      this->members_[index].label);
                    }
                }
              else      // Default case label.
                {
                  this->members_[index].label <<= CORBA::Any::from_octet (0);
                }

              this->members_[index].name =
                CORBA::string_dup ((*f)->local_name ()->get_string ());

              // IfR method create_union does not use this - it just needs
              // to be non-zero for marshaling.
              this->members_[index].type =
                CORBA::TypeCode::_duplicate (CORBA::_tc_void);

              this->members_[index++].type_def =
                CORBA::IDLType::_duplicate (this->ir_current_.in ());
            }
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        ACE_TEXT (
          "ifr_adding_visitor_union::visit_scope"));

      return -1;
    }

  return 0;
}