std::string idl_mapping_java::type(AST_Type *decl) { switch (decl->node_type()) { case AST_Decl::NT_pre_defined: { AST_PredefinedType *p = AST_PredefinedType::narrow_from_decl(decl); switch (p->pt()) { case AST_PredefinedType::PT_boolean: return "boolean"; case AST_PredefinedType::PT_char: case AST_PredefinedType::PT_wchar: return "char"; case AST_PredefinedType::PT_octet: return "byte"; case AST_PredefinedType::PT_short: case AST_PredefinedType::PT_ushort: return "short"; case AST_PredefinedType::PT_long: case AST_PredefinedType::PT_ulong: return "int"; case AST_PredefinedType::PT_longlong: case AST_PredefinedType::PT_ulonglong: return "long"; case AST_PredefinedType::PT_float: return "float"; case AST_PredefinedType::PT_double: return "double"; default: ;//fall through } } case AST_Decl::NT_string: return "String"; case AST_Decl::NT_enum: case AST_Decl::NT_interface: case AST_Decl::NT_interface_fwd: case AST_Decl::NT_native: case AST_Decl::NT_union: case AST_Decl::NT_struct: case AST_Decl::NT_struct_fwd: return scoped(decl->name()); case AST_Decl::NT_typedef: { AST_Typedef *td = AST_Typedef::narrow_from_decl(decl); return type(td->primitive_base_type()); } case AST_Decl::NT_sequence: { AST_Sequence *seq = AST_Sequence::narrow_from_decl(decl); return type(seq->base_type()) + "[]"; } case AST_Decl::NT_array: { AST_Array *arr = AST_Array::narrow_from_decl(decl); return type(arr->base_type()) + "[]"; } default: ;//fall through } cerr << "ERROR - unknown Java type " << decl->node_type() << " for IDL type: " << decl->local_name()->get_string() << endl; return "**unknown**"; }
AST_Type * be_typedef::_astBase(AST_Type * ttype) { AST_Type * ret = ttype; if (ret) { AST_Typedef * atd; while ((atd = (AST_Typedef*)ret->narrow((long) & AST_Typedef::type_id))) { ret = atd->base_type(); } } return ret; }
bool be_visitor_connector_dds_ex_base::is_dds_type ( be_connector *node, AST_Decl *d) { bool result = false; AST_Connector* base = node->base_connector (); if (base) { while (base->base_connector () != 0) { base = base->base_connector (); } const char* lname = base->local_name ()->get_string (); if (ACE_OS::strcmp (lname, "DDS_Base") == 0) { AST_Structure *s = AST_Structure::narrow_from_decl (d); if (s == 0) { AST_Typedef *td = AST_Typedef::narrow_from_decl (d); if (td != 0) { s = AST_Structure::narrow_from_decl (td->primitive_base_type ()); } } if (s) { result = true; } } } return result; }
// Are we or the parameter node involved in any recursion? bool AST_Exception::in_recursion (ACE_Unbounded_Queue<AST_Type *> &list) { bool self_test = (list.size () == 0); // We should calculate this only once. If it has already been // done, just return it. if (self_test && this->in_recursion_ != -1) { return (this->in_recursion_ == 1); } if (list.size () > 1) { if (match_names (this, list)) { // this happens when we are not recursed ourselves but instead // are part of another recursive type return false; } } list.enqueue_tail(this); // Proceed if the number of members in our scope is greater than 0. if (this->nmembers () > 0) { // Continue until each element is visited. for (UTL_ScopeActiveIterator i (this, IK_decls);!i.is_done ();i.next ()) { AST_Field *field = AST_Field::narrow_from_decl (i.item ()); if (field == 0) // This will be an enum value or other legitimate non-field // member - in any case, no recursion. { continue; } AST_Type *type = field->field_type (); if (type->node_type () == AST_Decl::NT_typedef) { AST_Typedef *td = AST_Typedef::narrow_from_decl (type); type = td->primitive_base_type (); } if (type == 0) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%N:%l) AST_Exception::") ACE_TEXT ("in_recursion - ") ACE_TEXT ("bad field type\n")), 0); } if (type->in_recursion (list)) { if (self_test) this->in_recursion_ = 1; idl_global->recursive_type_seen_ = true; return true; } } } // Not in recursion. if (self_test) this->in_recursion_ = 0; return 0; //this->in_recursion_; }
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; } }
// NOTE: No attempt is made to ensure that exceptions are mentioned // only once.. UTL_NameList * AST_Operation::fe_add_exceptions (UTL_NameList *t) { if (0 == t) { return 0; } UTL_ScopedName *nl_n = 0; AST_Type *fe = 0; AST_Decl *d = 0; this->pd_exceptions = 0; for (UTL_NamelistActiveIterator nl_i (t); !nl_i.is_done (); nl_i.next ()) { nl_n = nl_i.item (); d = this->lookup_by_name (nl_n, true); if (d == 0) { idl_global->err ()->lookup_error (nl_n); return 0; } AST_Decl::NodeType nt = d->node_type (); switch (nt) { case AST_Decl::NT_except: break; case AST_Decl::NT_param_holder: { AST_Param_Holder *ph = AST_Param_Holder::narrow_from_decl (d); nt = ph->info ()->type_; if (nt != AST_Decl::NT_except && nt != AST_Decl::NT_type) { idl_global->err ()->mismatched_template_param ( ph->info ()->name_.c_str ()); } break; } case AST_Decl::NT_typedef: { AST_Typedef *td = AST_Typedef::narrow_from_decl (d); nt = td->primitive_base_type ()->node_type (); if (nt != AST_Decl::NT_except) { idl_global->err ()->error1 ( UTL_Error::EIDL_ILLEGAL_RAISES, this); } break; } case AST_Decl::NT_native: { // This is the only use case for this node type. int compare = ACE_OS::strcmp (d->local_name ()->get_string (), "UserExceptionBase"); if (compare != 0) { idl_global->err ()->error1 ( UTL_Error::EIDL_ILLEGAL_RAISES, this); } break; } default: idl_global->err ()->error1 ( UTL_Error::EIDL_ILLEGAL_RAISES, this); break; }; bool oneway_op = (this->flags () == AST_Operation::OP_oneway); fe = AST_Type::narrow_from_decl (d); if (oneway_op && fe != 0) { idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES, this); } if (fe == 0) { idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES, this); return 0; } if (this->pd_exceptions == 0) { ACE_NEW_RETURN (this->pd_exceptions, UTL_ExceptList (fe, 0), 0); } else { UTL_ExceptList *el = 0; ACE_NEW_RETURN (el, UTL_ExceptList (fe, 0), 0); this->pd_exceptions->nconc (el); } } // This return value is never used, it's easier to // destroy it here and return 0 than to destroy it // each place it is passed in. t->destroy (); delete t; t = 0; return 0; }
int be_visitor_connector_dds_exs::visit_connector (be_connector *node) { if (node->imported ()) { return 0; } if (!this->begin (node)) { return -1; } // If we have a connector within a templated module if (! this->t_args_.is_empty ()) { os_ << be_nl << this->node_->local_name () << "_exec_i::" << this->node_->local_name () << "_exec_i (void)" << be_idt_nl << ": " << this->base_tname_ << "_Connector_T"; os_ << " <" << be_idt << be_idt_nl; os_ << "CCM_" << this->node_->flat_name () << "_Traits," << be_nl; size_t slot = 1UL; for (FE_Utils::T_ARGLIST::CONST_ITERATOR i (this->t_args_); !i.done (); i.advance (), ++slot) { AST_Decl **item = 0; i.next (item); AST_Decl *d = *item; if (this->is_dds_type (node, d)) { os_ << d->flat_name () << "_DDS_Traits"; } else { os_ << d->name (); } bool needs_bool = false; bool is_fixed = false; FE_Utils::T_Param_Info *param = 0; if (this->t_params_->get (param, slot - 1) != 0) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("be_visitor_connector_dds_exh::") ACE_TEXT ("visit_connector - ") ACE_TEXT ("template param fetch failed\n ")), -1); } if (d->node_type () == AST_Decl::NT_typedef) { /// Strip away all layers of typedef before narrowing. AST_Typedef *td = AST_Typedef::narrow_from_decl (d); d = td->primitive_base_type (); } /// No need to check if this is 0, but must narrow /// to call virtual function size_type() below. AST_Type *t = AST_Type::narrow_from_decl (d); switch (param->type_) { case AST_Decl::NT_type: case AST_Decl::NT_struct: case AST_Decl::NT_union: needs_bool = true; is_fixed = (t->size_type () == AST_Type::FIXED); break; default: break; } if (needs_bool) { os_ << "," << be_nl << (is_fixed ? "true" : "false"); } if (slot < this->t_args_.size ()) { os_ << "," << be_nl; } } os_ << "> ()" << be_uidt << be_uidt << be_uidt_nl << "{" << be_nl << "}"; os_ << be_nl_2 << this->node_->local_name () << "_exec_i::~" << this->node_->local_name () << "_exec_i (void)" << be_nl << "{" << be_nl << "}"; this->gen_exec_entrypoint_defn (); } os_ << be_uidt_nl << "}"; return 0; }
/* * Helper function for lookup_by_name. Iterates doing local lookups of * subsequent components of a scoped name */ static AST_Decl * iter_lookup_by_name_local(AST_Decl *d, UTL_ScopedName *e, idl_bool treat_as_ref) { Identifier *s; AST_Typedef *td; UTL_IdListActiveIterator *i; UTL_Scope *sc; i = new UTL_IdListActiveIterator(e); for (i->next(); !(i->is_done()); ) { s = i->item(); /* * Update iterator before loop. This is needed for the check for * typedef, since we only want to look at the base type if there * actually are more components of the name to resolve. */ i->next(); /* * Next component in name was not found */ if (d == NULL) { return NULL; } /* * If this is a typedef and we're not done, we should get the * base type to get the scope it defines (if any) */ if (!(i->is_done())) { while (d != NULL && d->node_type() == AST_Decl::NT_typedef) { td = AST_Typedef::narrow_from_decl(d); if (td == NULL) return NULL; d = td->base_type(); } if (d == NULL) return NULL; } /* * Try to convert the AST_Decl to a UTL_Scope */ sc = DeclAsScope(d); if (sc == NULL) return NULL; /* * Look up the next element */ d = sc->lookup_by_name_local (s); } /* * OK, done with the loop */ return d; }
int be_visitor_connector_dds_exh::visit_connector (be_connector *node) { if (node->imported ()) { return 0; } if (!this->begin (node)) { return -1; } // If we have a connector within a templated module if (! this->t_args_.is_empty ()) { // Generate all needed dds_traits for (FE_Utils::T_ARGLIST::CONST_ITERATOR i (this->t_args_); !i.done (); i.advance ()) { AST_Decl **item = 0; i.next (item); AST_Decl *d = *item; if (this->is_dds_type (node, d)) { this->gen_dds_traits (d); } } // Generate connector traits this->gen_connector_traits (); os_ << be_nl_2 << "class " << this->export_macro_.c_str () << " " << this->node_->local_name () << "_exec_i" << be_idt_nl << ": public " << this->base_tname_ << "_Connector_T"; os_ << " <" << be_idt << be_idt_nl; os_ << "CCM_" << this->node_->flat_name () << "_Traits," << be_nl; size_t slot = 1UL; for (FE_Utils::T_ARGLIST::CONST_ITERATOR i (this->t_args_); !i.done (); i.advance (), ++slot) { AST_Decl **item = 0; i.next (item); AST_Decl *d = *item; if (this->is_dds_type (node, d)) { os_ << d->flat_name () << "_DDS_Traits"; } else { os_ << d->name (); } bool needs_bool = false; bool is_fixed = false; FE_Utils::T_Param_Info *param = 0; if (this->t_params_->get (param, slot - 1) != 0) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("be_visitor_connector_dds_exh::") ACE_TEXT ("visit_connector - ") ACE_TEXT ("template param fetch failed\n ")), -1); } if (d->node_type () == AST_Decl::NT_typedef) { /// Strip away all layers of typedef before narrowing. AST_Typedef *td = AST_Typedef::narrow_from_decl (d); d = td->primitive_base_type (); } /// No need to check if this is 0, but must narrow /// to call virtual function size_type() below. AST_Type *t = AST_Type::narrow_from_decl (d); switch (param->type_) { case AST_Decl::NT_type: case AST_Decl::NT_struct: case AST_Decl::NT_union: needs_bool = true; is_fixed = (t->size_type () == AST_Type::FIXED); break; default: break; } if (needs_bool) { os_ << "," << be_nl << (is_fixed ? "true" : "false"); } if (slot < this->t_args_.size ()) { os_ << "," << be_nl; } } os_ << ">"; os_ << be_uidt << be_uidt << be_uidt_nl << "{" << be_nl << "public:" << be_idt_nl << this->node_->local_name () << "_exec_i (void);" << be_nl << "virtual ~" << this->node_->local_name () << "_exec_i (void);" << be_uidt_nl << "};"; this->gen_exec_entrypoint_decl (); } os_ << be_uidt_nl << "}"; /// Unset the flags in the port interfaces list. This is /// also done in visit_mirror_port(), but we must also do /// it here to catch a port interface that didn't come to /// us from an extended port or mirror port. for (ACE_Unbounded_Queue<be_interface *>::ITERATOR iter ( this->port_ifaces_); !iter.done (); iter.advance ()) { be_interface **item = 0; iter.next (item); (*item)->dds_connector_traits_done (false); } return 0; }