// Compute the size type of the node in question. int AST_Structure::compute_size_type (void) { for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls); !si.is_done (); si.next ()) { // Get the next AST decl node. AST_Decl *d = si.item (); if (d->node_type () == AST_Decl::NT_enum_val) { continue; } AST_Field *f = AST_Field::narrow_from_decl (d); AST_Type *t = f->field_type (); if (t != 0) { this->size_type (t->size_type ()); // While we're iterating, we might as well do this one too. this->has_constructor (t->has_constructor ()); } else { ACE_DEBUG ((LM_DEBUG, "WARNING (%N:%l) be_structure::compute_size_type - " "narrow_from_decl returned 0\n")); } } return 0; }
int be_visitor_event_source_desc::visit_publishes ( be_publishes *node) { AST_Type *obj = node->publishes_type (); const char *port_name = node->local_name ()->get_string (); os_ << be_nl_2; os_ << "{" << be_idt_nl << "ACE_GUARD_RETURN (TAO_SYNCH_MUTEX," << be_nl << " mon," << be_nl << " this->context_->" << port_name << "_lock_," << be_nl << " 0);" << be_nl_2; os_ << "::CIAO::Servant::describe_pub_event_source<" << be_idt_nl << "::" << obj->full_name () << "Consumer_var> (" << be_idt_nl << "\"" << port_name << "\"," << be_nl << "\"" << obj->repoID () << "\"," << be_nl << "this->context_->ciao_publishes_" << port_name << "_," << be_nl << "safe_retval," << be_nl << slot_++ << "UL);" << be_uidt << be_uidt; os_ << be_uidt_nl << "}"; return 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 (); } }
be_argument::be_argument ( AST_Argument::Direction d, AST_Type *ft, UTL_ScopedName *n, const UTL_Pragmas &p ) : AST_Decl (AST_Decl::NT_argument, n, p), AST_Field (AST_Decl::NT_argument, ft, n, p), AST_Argument (d, ft, n, p), m_beType (0), m_direction (d) { AST_Type * at = field_type(); be_Type * bt; if (at && (bt = (be_Type*)at->narrow((long) & be_Type::type_id))) { const char * typeName = bt->TypeName (); if (typeName && strcmp (typeName, "DDS::Any") == 0) { BE_Globals::inc_any = pbtrue; } } }
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; }
// Compute total number of members. int AST_Operation::compute_argument_attr (void) { if (this->argument_count_ != -1) { return 0; } AST_Decl *d = 0; AST_Type *type = 0; AST_Argument *arg = 0; this->argument_count_ = 0; // If there are elements in this scope. if (this->nmembers () > 0) { // Instantiate a scope iterator. for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls); !si.is_done (); si.next ()) { // Get the next AST decl node. d = si.item (); if (d->node_type () == AST_Decl::NT_argument) { this->argument_count_++; arg = AST_Argument::narrow_from_decl (d); if (arg->direction() == AST_Argument::dir_IN || arg->direction() == AST_Argument::dir_INOUT) { this->has_in_arguments_ = true; } type = AST_Type::narrow_from_decl (arg->field_type ()); if (type->node_type () == AST_Decl::NT_native) { this->has_native_ = 1; } } } } type = AST_Type::narrow_from_decl (this->return_type ()); if (type->node_type () == AST_Decl::NT_native) { this->has_native_ = 1; } return 0; }
bool AST_Operation::void_return_type (void) { AST_Type* type = this->return_type (); return (type->node_type () == AST_Decl::NT_pre_defined && (AST_PredefinedType::narrow_from_decl (type)->pt () == AST_PredefinedType::PT_void)); }
void be_argument::Initialize () { AST_Type * at = field_type(); be_Type * bt; if (at && (bt = (be_Type*)at->narrow((long) & be_Type::type_id))) { bt->Initialize (); } }
int be_visitor_receptacle_desc::visit_uses (be_uses *node) { ACE_CString prefix (this->ctx_->port_prefix ()); prefix += node->local_name ()->get_string (); const char *port_name = prefix.c_str (); AST_Type *obj = node->uses_type (); bool const is_multiple = node->is_multiple (); os_ << be_nl_2; ACE_CString sname_str (comp_->full_name ()); const char *sname = sname_str.c_str (); const char *global = (sname_str == "" ? "" : "::"); if (!is_multiple) { os_ << obj->full_name () << "_var ciao_" << port_name << " = " << be_idt_nl << "this->context_->get_connection_" << port_name << " ();" << be_uidt_nl; } else { os_ << "::" << sname << global << port_name << "Connections_var ciao_" << port_name << " = " << be_idt_nl << "this->context_->get_connections_" << port_name << " ();" << be_uidt_nl; } os_ << "::CIAO::Servant::describe_" << (is_multiple ? "multiplex" : "simplex") << "_receptacle<" << be_idt_nl; if (!is_multiple) { os_ << "::" << obj->full_name () << "> (" << be_idt_nl; } else { os_ << "::" << sname << global << port_name << "Connections> (" << be_idt_nl; } os_ << "\"" << port_name << "\"," << be_nl << "\"" << obj->repoID () << "\"," << be_nl; os_ << "ciao_" << port_name << ".in ()," << be_nl; os_ << "safe_retval," << be_nl << slot_++ << "UL);" << be_uidt << be_uidt; return 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; }
be_typedef::be_typedef (AST_Type *bt, UTL_ScopedName *n, const UTL_Pragmas &p) : AST_Decl (AST_Decl::NT_typedef, n, p), AST_Typedef (bt, n, p), m_generateBase (FALSE), m_generated (FALSE), m_baseBeType (0) { AST_Type* astType = base_type(); be_array* ba; be_sequence* bs; localName = local_name()->get_string(); enclosingScope = be_Type::EnclosingScopeString(this); m_baseBeType = get_base_be_type(); // // make sure the base type has a name (if anonymous) // bs = (be_sequence*)astType->narrow((long) & be_sequence::type_id); if (bs) { m_generateBase = bs->SetName(enclosingScope, localName); } else if ((ba = (be_array*)astType->narrow((long) & be_array::type_id))) { m_generateBase = ba->SetName(enclosingScope, localName); } // // now initialize the base's type and typemap // m_baseBeType->Initialize(); m_baseBeType->HasTypeDef (pbtrue); InitializeTypeMap (this); m_typecode = m_baseBeType->m_typecode; m_typecode->id = get_decl_pragmas().get_repositoryID()->get_string(); m_typecode->name_of_type = localName; DDS_StdString scopedname = NoColons(enclosingScope + "_" + localName); TypeCodeTypeName(BE_Globals::TCPrefix + localName); MetaTypeTypeName(BE_Globals::MTPrefix + scopedname); TypeCodeRepName(BE_Globals::TCRepPrefix + scopedname); TypeCodeBaseName(BE_Globals::TCBasePrefix + scopedname); }
be_Type* be_argument::BeType() const { be_Type * ret = 0; AST_Type* atype = ((be_argument*)this)->field_type(); if (atype) { ret = (be_Type*)atype->narrow((long) & be_Type::type_id); assert(ret); } return ret; }
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; }
int be_visitor_array::visit_typedef (be_typedef *node) { TAO_OutStream *os = this->ctx_->stream (); AST_Type *pbt = node->primitive_base_type (); AST_Decl::NodeType nt = pbt->node_type (); AST_PredefinedType::PredefinedType pt = AST_PredefinedType:: PT_void; int result = 0; // We check for these first, because in these cases, we replace the // entire slice type with one of the strings below, instead of using // the node's type name, possibly suffixed with '_var'. if (nt == AST_Decl::NT_string) { *os << "::TAO::String_Manager"; return 0; } else if (nt == AST_Decl::NT_wstring) { *os << "::TAO::WString_Manager"; return 0; } result = this->visit_node (node); if (nt == AST_Decl::NT_pre_defined) { AST_PredefinedType *pdt = AST_PredefinedType::narrow_from_decl (pbt); pt = pdt->pt (); } // We must append a "_var" for typedefs of interfaces, CORBA::Objects or // typecodes. if (nt == AST_Decl::NT_interface || nt == AST_Decl::NT_interface_fwd || pt == AST_PredefinedType::PT_pseudo || pt == AST_PredefinedType::PT_object) { *os << "_var"; } return result; }
// Compute total number of members. int AST_Factory::compute_argument_attr (void) { if (this->argument_count_ != -1) { return 0; } AST_Decl *d = 0; AST_Type *type = 0; AST_Argument *arg = 0; this->argument_count_ = 0; // If there are elements in this scope. if (this->nmembers () > 0) { for (UTL_ScopeActiveIterator i (this, IK_decls); !i.is_done (); i.next ()) { // Get the next AST decl node. d = i.item (); if (d->node_type () == AST_Decl::NT_argument) { this->argument_count_++; arg = AST_Argument::narrow_from_decl (d); type = AST_Type::narrow_from_decl (arg->field_type ()); if (type->node_type () == AST_Decl::NT_native) { this->has_native_ = 1; } } } } return 0; }
int be_visitor_emitter_desc::visit_emits (be_emits *node) { AST_Type *obj = node->emits_type (); const char *port_name = node->local_name ()->get_string (); os_ << be_nl_2 << "::CIAO::Servant::describe_emit_event_source<" << be_idt_nl << "::" << obj->full_name () << "Consumer_var> (" << be_idt_nl << "\"" << port_name << "\"," << be_nl << "\"" << obj->repoID () << "\"," << be_nl << "this->context_->ciao_emits_" << port_name << "_consumer_," << be_nl << "safe_retval," << be_nl << slot_++ << "UL);" << be_uidt << be_uidt; return 0; }
DDS_StdString be_typedef::Initializer(const DDS_StdString& var, VarType vt) const { AST_Type * basetype = ((be_typedef*)this)->base_type(); be_enum * basetype_enum = 0; be_Type * type; DDS_StdString ret; assert(basetype && basetype->narrow((long)&be_Type::type_id)); // This conditional statement here is kludgy. See comment basetype_enum = (be_enum*)basetype->narrow((long) & be_enum::type_id); if (basetype_enum) { ret = var + " = (" + typeName + ")0;"; } else if ((basetype && (type = (be_Type*)basetype->narrow((long) & be_Type::type_id)))) { ret = type->Initializer(var, vt); } return ret; }
// Compute the size type of the node in question. int AST_Union::compute_size_type (void) { for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls); !si.is_done (); si.next ()) { // Get the next AST decl node. AST_Decl *d = si.item (); if (d->node_type () == AST_Decl::NT_enum_val) { continue; } AST_Field *f = AST_Field::narrow_from_decl (d); if (f != 0) { AST_Type *t = f->field_type (); // Our sizetype depends on the sizetype of our members. Although // previous value of sizetype may get overwritten, we are // guaranteed by the "size_type" call that once the value reached // be_decl::VARIABLE, nothing else can overwrite it. this->size_type (t->size_type ()); } else { ACE_DEBUG ((LM_DEBUG, "WARNING (%N:%l) be_union::compute_size_type - " "narrow_from_decl returned 0\n")); } } return 0; }
// 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_; }
// 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; }
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; }
bool be_CodeGenerator::is_local_type (AST_Decl * d) { AST_Type* ast = (AST_Type*)d->narrow((long) & AST_Type::type_id); return ast && ast->local(); }
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; }
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; }
// Dump this AST_Operation node (an operation) to the ostream o. void AST_Operation::dump (ACE_OSTREAM_TYPE &o) { AST_Decl *d = 0; AST_Type *e = 0; UTL_String *s = 0; if (this->pd_flags == OP_oneway) { this->dump_i (o, "oneway "); } else if (this->pd_flags == OP_idempotent) { this->dump_i (o, "idempotent "); } this->pd_return_type->name ()->dump (o); this->dump_i (o, " "); this->local_name ()->dump (o); this->dump_i (o, "("); // Must advance the iterator explicity inside the loop. for (UTL_ScopeActiveIterator i (this, IK_decls); !i.is_done ();) { d = i.item (); d->dump (o); i.next (); if (!i.is_done()) { this->dump_i (o, ", "); } } this->dump_i (o, ")"); if (this->pd_exceptions != 0) { this->dump_i (o, " raises("); // Must advance the iterator explicity inside the loop. for (UTL_ExceptlistActiveIterator ei (this->pd_exceptions); !ei.is_done ();) { e = ei.item (); ei.next (); e->local_name ()->dump (o); if (!ei.is_done()) { this->dump_i (o, ", "); } } this->dump_i (o, ")"); } if (this->pd_context != 0) { this->dump_i (o, " context("); // Must advance the iterator explicity inside the loop. for (UTL_StrlistActiveIterator si (this->pd_context); !si.is_done();) { s = si.item (); si.next (); this->dump_i (o, s->get_string ()); if (!si.is_done()) { this->dump_i (o, ", "); } } this->dump_i (o, ")"); } }
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; }
int be_visitor_servant_svs::visit_provides (be_provides *node) { if (node->provides_type ()->is_local ()) // @TODO || be_global->gen_lwccm ()) { return 0; } ACE_CString prefix (this->ctx_->port_prefix ()); prefix += node->local_name ()->get_string (); const char *port_name = prefix.c_str (); AST_Type *obj = node->provides_type (); const char *obj_name = obj->full_name (); AST_Decl *scope = ScopeAsDecl (obj->defined_in ()); ACE_CString sname_str (scope->full_name ()); const char *sname = sname_str.c_str (); // Avoid '_cxx_' prefix. const char *lname = obj->original_local_name ()->get_string (); const char *global = (sname_str == "" ? "" : "::"); const char *prefix_connector = (sname_str == "" ? "" : "_"); if (!be_global->gen_lwccm ()) { os_ << be_nl_2 << "::" << obj_name << "_ptr" << be_nl << node_->local_name () << "_Servant::provide_" << port_name << " (void)" << be_nl << "{" << be_idt_nl; os_ << "return" << be_idt_nl << "::" << obj_name << "::_duplicate (this->provide_" << port_name << "_.in ());" << be_uidt << be_uidt_nl << "}"; } os_ << be_nl_2 << "void" << be_nl << node_->local_name () << "_Servant::setup_" << port_name << "_i (void)" << be_nl << "{" << be_idt_nl << "ACE_CString obj_id (this->ins_name_);" << be_nl << "obj_id += \"_" << port_name << "\";" << be_nl_2 << "::CIAO::Container_var cnt_safe =" << be_idt_nl << "::CIAO::Container::_duplicate (" << "this->container_.in ());" << be_uidt_nl << be_nl << "if (::CORBA::is_nil (cnt_safe.in ()))" << be_idt_nl << "{" << be_idt_nl << "throw ::CORBA::INV_OBJREF ();" << be_uidt_nl << "}" << be_uidt_nl << be_nl << "PortableServer::POA_var POA = cnt_safe->the_port_POA ();" << be_nl << "::CORBA::Object_var tmp =" << be_idt_nl << "this->get_facet_executor (\"" << port_name << "\");"<< be_uidt_nl << be_nl << global << sname << "::CCM_" << lname << "_var tmp_var = " << be_idt_nl << global << sname <<"::CCM_" << lname << "::_narrow (tmp.in());" << be_uidt_nl << be_nl << "typedef " << global << "CIAO_FACET" << prefix_connector << scope->flat_name () << "::" << obj->local_name () << "_Servant_T <" << be_idt_nl << "POA_" << sname << global << obj->local_name () << "," << be_nl << global << sname <<"::CCM_" << lname << "," << be_nl << global << "Components::" << be_global->ciao_container_type () << "Context>" << be_idt_nl << lname << "_type;" << be_uidt_nl << be_uidt_nl << lname << "_type *" << port_name << "_servant_impl = 0;" << be_nl << "ACE_NEW_THROW_EX (" << be_idt_nl << port_name << "_servant_impl," << be_nl << lname << "_type (" << be_idt_nl << "tmp_var.in(), " << be_nl << "this->context_)," << be_uidt_nl << "CORBA::NO_MEMORY ());" << be_uidt_nl << be_nl << "PortableServer::ServantBase_var safe_base_servant (" << port_name << "_servant_impl);" << be_nl << be_nl << "PortableServer::ObjectId_var " << port_name << "_servant_oid =" << be_idt_nl << "PortableServer::string_to_ObjectId (obj_id.c_str());" << be_uidt_nl << be_nl << "POA->activate_object_with_id(" << port_name << "_servant_oid.in()," << port_name << "_servant_impl);" << be_nl << "::CORBA::Object_var " << port_name << "_servant_impl_obj = " << be_idt_nl << "cnt_safe->generate_reference ( " << be_idt_nl << "obj_id.c_str ()," << be_nl << "\"" << obj->repoID () << "\"," << be_nl << "::CIAO::Container_Types::FACET_CONSUMER_t);" << be_uidt_nl << be_uidt_nl << "this->add_facet (\"" << port_name << "\", " << port_name << "_servant_impl_obj.in ());" << be_uidt_nl << "}"; return 0; }
int be_visitor_servant_svs::visit_consumes (be_consumes *node) { AST_Type *obj = node->consumes_type (); const char *port_name = node->local_name ()->get_string (); const char *comp_lname = node_->local_name (); ACE_CString comp_sname_str ( ScopeAsDecl (node_->defined_in ())->full_name ()); const char *comp_sname = comp_sname_str.c_str (); const char *global = (comp_sname_str == "" ? "" : "::"); const char *lname = obj->local_name ()->get_string (); const char *fname = obj->full_name (); os_ << be_nl_2 << comp_lname << "_Servant::" << lname << "Consumer_" << port_name << "_Servant::" << lname << "Consumer_" << port_name << "_Servant (" << be_idt << be_idt_nl << global << comp_sname << "::CCM_" << comp_lname << "_ptr executor," << be_nl << global << comp_sname << "::CCM_" << comp_lname << "_Context_ptr c)" << be_uidt_nl << ": executor_ ( " << global << comp_sname << "::CCM_" << comp_lname << "::_duplicate (executor))," << be_idt_nl << "ctx_ ( " << global << comp_sname << "::CCM_" << comp_lname << "_Context::_duplicate (c))" << be_uidt << be_uidt_nl << "{" << be_nl << "}"; os_ << be_nl_2 << comp_lname << "_Servant::" << lname << "Consumer_" << port_name << "_Servant::~" << lname << "Consumer_" << port_name << "_Servant (void)" << be_nl << "{" << be_nl << "}"; os_ << be_nl_2 << "::CORBA::Object_ptr" << be_nl << comp_lname << "_Servant::" << lname << "Consumer_" << port_name << "_Servant::_get_component (void)" << be_nl << "{" << be_idt_nl; if (ACE_OS::strcmp (be_global->ciao_container_type (), "Session") == 0) { os_ << "return this->ctx_->get_CCM_object ();"; } else { os_ << "return ::CORBA::Object::_nil ();"; } os_ << be_uidt_nl << "}"; os_ << be_nl_2 << "void" << be_nl << comp_lname << "_Servant::" << lname << "Consumer_" << port_name << "_Servant::push_" << lname << " (" << be_idt_nl << "::" << fname << " * evt)" << be_uidt_nl << "{" << be_idt_nl << "this->executor_->push_" << port_name << " (evt);" << be_uidt_nl << "}"; os_ << be_nl_2 << "/// Inherited from ::Components::EventConsumerBase." << be_nl << "void" << be_nl << comp_lname << "_Servant::" << lname << "Consumer_" << port_name << "_Servant::push_event (" << be_idt_nl << "::Components::EventBase * ev)" << be_uidt_nl << "{" << be_idt_nl << "::" << fname << " * ev_type =" << be_idt_nl << "::" << fname << "::_downcast (ev);" << be_uidt_nl << be_nl << "if (ev_type != 0)" << be_idt_nl << "{" << be_idt_nl << "this->push_" << lname << " (ev_type);" << be_nl << "return;" << be_uidt_nl << "}" << be_uidt_nl << be_nl << "throw ::Components::BadEventType ();" << be_uidt_nl << "}"; if (!be_global->gen_lwccm ()) { os_ << be_nl_2 << "::" << fname << "Consumer_ptr" << be_nl << node_->local_name () << "_Servant::get_consumer_" << port_name << " (void)" << be_nl << "{" << be_idt_nl << "return" << be_idt_nl << "::" << fname << "Consumer::_duplicate (" << be_idt_nl << "this->consumes_" << port_name << "_.in ());" << be_uidt << be_uidt << be_uidt_nl << "}"; } os_ << be_nl_2 << "void" << be_nl << node_->local_name () << "_Servant::setup_consumer_" << port_name << "_i (void)" << be_nl << "{" << be_idt_nl << "ACE_CString obj_id (this->ins_name_);" << be_nl << "obj_id += \"_" << port_name << "\";" << be_nl_2 << "::CIAO::Container_var cnt_safe =" << be_idt_nl << "::CIAO::Container::_duplicate (" << "this->container_.in ());" << be_uidt_nl << be_nl << "if (::CORBA::is_nil (cnt_safe.in ()))" << be_idt_nl << "{" << be_idt_nl << "throw ::CORBA::INV_OBJREF ();" << be_uidt_nl << "}" << be_uidt_nl << be_nl << "PortableServer::POA_var POA = cnt_safe->the_port_POA ();" << be_nl << node_->local_name () << "_Servant::" << lname << "Consumer_" << port_name << "_Servant *" << port_name << "_servant_impl = " << be_idt_nl << "new " << node_->local_name () << "_Servant::" << lname << "Consumer_" << port_name << "_Servant (" << be_idt_nl << " this->executor_, this->context_);" << be_uidt_nl << be_uidt_nl << be_nl << "PortableServer::ServantBase_var safe_base_servant (" << port_name << "_servant_impl);" << be_nl << "PortableServer::ObjectId_var " << port_name << "_servant_oid =" << be_idt_nl << "PortableServer::string_to_ObjectId (obj_id.c_str());" << be_uidt_nl << be_nl << "POA->activate_object_with_id(" << be_idt_nl << port_name << "_servant_oid.in()," << be_nl << port_name << "_servant_impl);" << be_uidt_nl << be_nl << "::CORBA::Object_var " << port_name << "_servant_impl_obj = " << be_idt_nl << "cnt_safe->generate_reference ( " << be_idt_nl << "obj_id.c_str ()," << be_nl << "\""; ACE_CString work (obj->repoID ()); ACE_CString result (work.substr (0, work.rfind (':'))); result += "Consumer:1.0"; os_ << result.c_str (); os_ << "\"," << be_nl << "::CIAO::Container_Types::FACET_CONSUMER_t);" << be_uidt_nl << be_uidt_nl << "::Components::EventConsumerBase_var ecb =" << be_idt_nl << "::Components::EventConsumerBase::_narrow (" << port_name << "_servant_impl_obj.in ());" << be_uidt_nl << be_nl << "this->add_consumer (\"" << port_name << "\", ecb.in ());" << be_uidt_nl << "}"; return 0; }
bool AST_illegal_recursive_type (AST_Decl *t) { if (t == 0) { return false; } AST_Decl::NodeType nt; AST_Type *ut = AST_Type::narrow_from_decl (t); if (ut != 0) { ut = ut->unaliased_type (); nt = ut->node_type (); } else { nt = t->node_type (); } if (nt == AST_Decl::NT_interface) { // Check for interface->struct/union->....->interface nesting. // return AST_illegal_interface_recursion (t); } else if (nt != AST_Decl::NT_struct && nt != AST_Decl::NT_union) { // Structs and unions fall through to the check below. return false; // NOT ILLEGAL. } bool check_for_struct = false; bool check_for_union = false; AST_Structure *st1 = 0; AST_Union *un1 = 0; // Narrow the type appropriately so comparison will work. if (t->node_type () == AST_Decl::NT_struct) { check_for_struct = true; st1 = AST_Structure::narrow_from_decl (t); if (st1 == 0) { return false; // NOT ILLEGAL. } } else if (t->node_type () == AST_Decl::NT_union) { check_for_union = true; un1 = AST_Union::narrow_from_decl (t); if (un1 == 0) { return false; // NOT ILLEGAL. } } UTL_Scope *s = 0; AST_Structure *st2 = 0; AST_Union *un2 = 0; // OK, iterate up the stack. for (UTL_ScopeStackActiveIterator i (idl_global->scopes ()); !i.is_done (); i.next ()) { s = i.item (); // If we hit a NULL we're done since it means that we're nested inside // a sequence, where recursive types may be used. if (s == 0) { return false; // NOT ILLEGAL. } // OK, must check this scope. if (s->scope_node_type () == AST_Decl::NT_struct && check_for_struct == true) { st2 = AST_Structure::narrow_from_scope (s); if (st2 != 0 && st2 == st1) { return true; // ILLEGAL RECURSIVE TYPE USE. } } else if (s->scope_node_type () == AST_Decl::NT_union && check_for_union == true) { un2 = AST_Union::narrow_from_scope (s); if (un2 != 0 && un2 == un1) { return true; // ILLEGAL RECURSIVE TYPE USE. } } } // No more scopes to check. This type was used legally. return false; // NOT ILLEGAL. }
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; }