// 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; }
// 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 AST_Operation::count_arguments_with_direction (int direction_mask) { int count = 0; for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls); !si.is_done (); si.next ()) { AST_Argument *arg = AST_Argument::narrow_from_decl (si.item ()); if ((arg->direction () & direction_mask) != 0) { ++count; } } return count; }
int be_visitor_operation_tie_ss::visit_operation (be_operation *node) { /// These implied IDL operations are not to be processed on /// the skeleton side. if (node->is_sendc_ami ()) { return 0; } TAO_OutStream *os = this->ctx_->stream (); be_interface *intf = this->ctx_->interface (); if (!intf) { ACE_ERROR_RETURN ((LM_ERROR, "be_visitor_operation_tie_ss::" "visit_operation - " "bad interface scope\n"), -1); } // Retrieve the operation return type. be_type *bt = be_type::narrow_from_decl (node->return_type ()); if (!bt) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_operation_tie_ss::" "visit_operation - " "Bad return type\n"), -1); } // Although unlikely it is possible that the 'T' in 'template class<T>' will // conflict with an argument name... ACE_CString template_name ("T"); bool template_name_ok = false; while (!template_name_ok) { template_name_ok = true; for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); ! si.is_done () && template_name_ok; si.next ()) { // Check for conflicts between the arg name and the proposed template // class identifier AST_Argument *arg = AST_Argument::narrow_from_decl (si.item ()); if (! ACE_OS::strcmp (arg->local_name ()->get_string (), template_name.c_str ())) { // clash ! template_name_ok = false; } } if (! template_name_ok) { // We had a clash - postfix an underscore and try again template_name += "_"; } } *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl_2; *os << "template <class " << template_name.c_str () << ">" << be_nl; // Generate the return type mapping (same as in the header file). be_visitor_context ctx (*this->ctx_); be_visitor_operation_rettype oro_visitor (&ctx); if (bt->accept (&oro_visitor) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_operation_tie_ss::" "visit_operation - " "codegen for return type failed\n"), -1); } *os << " " << intf->full_skel_name () << "_tie<" << template_name.c_str () << ">::" << this->ctx_->port_prefix ().c_str () << node->local_name () << " "; // STEP 4: generate the argument list with the appropriate mapping (same as // in the header file) ctx = *this->ctx_; be_visitor_operation_arglist oao_visitor (&ctx); if (node->accept (&oao_visitor) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_operation_cs::" "visit_operation - " "codegen for argument list failed\n"), -1); } *os << be_nl << "{" << be_idt_nl; be_predefined_type *pdt = be_predefined_type::narrow_from_decl (bt); if (pdt == 0 || pdt->pt () != AST_PredefinedType::PT_void) { *os << "return "; } *os << "this->ptr_->" << node->local_name () << " (" << be_idt; ctx = *this->ctx_; ctx.state (TAO_CodeGen::TAO_OPERATION_COLLOCATED_ARG_UPCALL_SS); be_visitor_operation_argument ocau_visitor (&ctx); if (node->accept (&ocau_visitor) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_operation_ss::" "visit_operation - " "codegen for making upcall failed\n"), -1); } *os << be_uidt_nl; *os << ");" << be_uidt_nl; *os << "}"; return 0; }
int be_visitor_operation_direct_proxy_impl_ss::gen_invoke ( be_visitor_context & /*ctx*/, be_operation *node ) { TAO_OutStream *os = this->ctx_->stream (); *os << "->" << node->local_name () << " (" << be_idt << be_idt << be_idt; UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); if (si.is_done ()) { *os << be_uidt_nl << ");"; return 0; } AST_Argument *arg = 0; int index = 1; for (; !si.is_done (); si.next (), ++index) { arg = AST_Argument::narrow_from_decl (si.item ()); *os << (index == 1 ? "" : ",") << be_nl << "((TAO::Arg_Traits< "; this->gen_arg_template_param_name (arg, arg->field_type (), os); *os << ">::"; switch (arg->direction ()) { case AST_Argument::dir_IN: *os << "in"; break; case AST_Argument::dir_INOUT: *os << "inout"; break; case AST_Argument::dir_OUT: *os << "out"; default: break; } *os << "_arg_val *) args[" << index << "])->arg ()"; } // End the upcall *os << be_uidt_nl << ");"; return 0; }
int be_visitor_operation_ami_cs::visit_operation (be_operation *node) { // No sendc method for oneway operations. if (node->flags () == AST_Operation::OP_oneway) { return 0; } be_visitor_context ctx; TAO_OutStream *os = this->ctx_->stream (); this->ctx_->node (node); *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__; // Generate the return type mapping. Return type is simply void. *os << be_nl_2 << "void" << be_nl; // Generate the operation name. // Grab the scope name. be_decl *parent = be_scope::narrow_from_scope (node->defined_in ())->decl (); if (parent == 0) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_operation_ami_cs::" "visit_operation - " "scope name is nil\n"), -1); } // Generate the scope::operation name. *os << parent->full_name () << "::" << this->ctx_->port_prefix ().c_str () << node->local_name ()->get_string (); // Generate the argument list with the appropriate mapping (same as // in the header file) ctx = *this->ctx_; be_visitor_operation_arglist oa_visitor (&ctx); // Get the AMI version from the strategy class. be_operation *ami_op = node; if (ami_op->accept (&oa_visitor) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_operation_ami_cs::" "visit_operation - " "codegen for argument list failed\n"), -1); } // Generate the actual code for the stub. However, if any of the argument // types is "native", we flag a MARSHAL exception. // last argument *os << be_nl << "{" << be_idt; if (node->has_native ()) // native exists => no stub { be_predefined_type bpt (AST_PredefinedType::PT_void, 0); int const status = this->gen_raise_exception ("::CORBA::MARSHAL", ""); if (status == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_operation_ami_cs::" "visit_operation - " "codegen for has-native exception failed\n"), -1); } } else { *os << be_nl << "if (!this->is_evaluated ())" << be_idt_nl << "{" << be_idt_nl << "::CORBA::Object::tao_object_initialize (this);" << be_uidt_nl << "}" << be_uidt_nl << be_nl; } // Includes the reply handler, but we have to add 1 for the retval anyway. int nargs = ami_op->argument_count (); if (nargs == 1) { // No arguments other than the reply handler, and the return // type is void. No need to generate argument list. *os << be_nl_2 << "TAO::Argument ** _the_tao_operation_signature = 0;"; nargs = 0; // Don't count the reply handler. } else { *os << be_nl<< be_nl << "TAO::Arg_Traits<void>::" << (node->flags () == AST_Operation::OP_oneway && be_global->use_clonable_in_args() ? "clonable_" : "") << "ret_val _tao_retval;"; // Declare the argument helper classes. this->gen_stub_body_arglist (ami_op, os, true); // Assemble the arg helper class pointer array. *os << be_nl_2 << "TAO::Argument *_the_tao_operation_signature[] =" << be_idt_nl << "{" << be_idt_nl << "&_tao_retval"; AST_Argument *arg = 0; UTL_ScopeActiveIterator arg_list_iter (ami_op, UTL_Scope::IK_decls); // For a sendc_* operation, skip the reply handler (first argument). arg_list_iter.next (); for (; ! arg_list_iter.is_done (); arg_list_iter.next ()) { arg = AST_Argument::narrow_from_decl (arg_list_iter.item ()); *os << "," << be_nl << "&_tao_" << arg->local_name (); } *os << be_uidt_nl << "};" << be_uidt; } ACE_CString base (node->local_name ()->get_string ()); /// The sendc_* operation makes the invocation with the /// original operation name. ACE_CString lname_str (base.substr (ACE_OS::strlen ("sendc_"))); const char *lname = lname_str.c_str (); ACE_CString opname (node->is_attr_op () ? "_" : ""); opname += lname; /// Some compilers can't resolve the stream operator overload. const char *op_name = opname.c_str (); ACE_CDR::ULong len = opname.length (); *os << be_nl_2 << "TAO::Asynch_Invocation_Adapter _tao_call (" << be_idt << be_idt_nl << "this," << be_nl << "_the_tao_operation_signature," << be_nl << nargs << "," << be_nl << "\"" << op_name << "\"," << be_nl << len << "," << be_nl; *os << "TAO::TAO_CO_NONE"; if (be_global->gen_direct_collocation()) { *os << " | TAO::TAO_CO_DIRECT_STRATEGY"; } if (be_global->gen_thru_poa_collocation()) { *os << " | TAO::TAO_CO_THRU_POA_STRATEGY"; } *os << be_uidt_nl << ");" << be_uidt; *os << be_nl_2 << "_tao_call.invoke (" << be_idt << be_idt_nl << "ami_handler," << be_nl << "&"; if (parent->is_nested ()) { be_decl *gparent = be_scope::narrow_from_scope (parent->defined_in ())->decl (); *os << gparent->name () << "::"; } *os << "AMI_" << parent->local_name () << "Handler::" << lname << "_reply_stub" << be_uidt_nl << ");" << be_uidt; *os << be_uidt_nl << "}"; return 0; }
int be_visitor_valuetype::visit_attribute (be_attribute *node) { this->ctx_->node (node); this->ctx_->attribute (node); be_operation get_op (node->field_type (), AST_Operation::OP_noflags, node->name (), 0, 0); get_op.set_name ((UTL_IdList *) node->name ()->copy ()); if (this->visit_operation (&get_op) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_attribute::" "visit_attribute - " "codegen for get_attribute failed\n"), -1); } get_op.destroy (); if (node->readonly ()) { // Nothing else to do. return 0; } Identifier id ("void"); UTL_ScopedName sn (&id, 0); be_predefined_type rt (AST_PredefinedType::PT_void, &sn); // Argument type is the same as the attribute type. AST_Argument *arg = idl_global->gen ()->create_argument (AST_Argument::dir_IN, node->field_type (), node->name ()); arg->set_name ((UTL_IdList *) node->name ()->copy ()); // Create the operation. be_operation set_op (&rt, AST_Operation::OP_noflags, node->name (), 0, 0); set_op.set_name ((UTL_IdList *) node->name ()->copy ()); set_op.be_add_argument (arg); if (this->visit_operation (&set_op) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_attribute::" "visit_attribute - " "codegen for set_attribute failed\n"), -1); } set_op.destroy (); rt.destroy (); return 0; }
int be_visitor_attribute::visit_attribute (be_attribute *node) { this->ctx_->node (node); this->ctx_->attribute (node); UTL_Scope *s = node->defined_in (); AST_Decl *d = ScopeAsDecl (s); ACE_CString op_name (this->ctx_->port_prefix ()); op_name += node->local_name ()->get_string (); Identifier *op_id = 0; ACE_NEW_RETURN (op_id, Identifier (op_name.c_str ()), -1); UTL_ScopedName *op_ln = 0; ACE_NEW_RETURN (op_ln, UTL_ScopedName (op_id, 0), -1); UTL_ScopedName *op_sn = static_cast<UTL_ScopedName *> (d->name ()->copy ()); op_sn->nconc (op_ln); // first the "get" operation be_operation get_op (node->field_type (), AST_Operation::OP_noflags, 0, node->is_local (), node->is_abstract ()); get_op.set_defined_in (s); get_op.set_name (op_sn); UTL_ExceptList *get_exceptions = node->get_get_exceptions (); if (0 != get_exceptions) { get_op.be_add_exceptions (get_exceptions->copy ()); } be_visitor_context ctx (*this->ctx_); int status = 1; switch (this->ctx_->state ()) { // These two cases are the only ones that could involve a strategy. case TAO_CodeGen::TAO_ROOT_CH: case TAO_CodeGen::TAO_INTERFACE_CH: { ctx.state (TAO_CodeGen::TAO_OPERATION_CH); be_visitor_operation_ch visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_CS: { ctx.state (TAO_CodeGen::TAO_OPERATION_CS); be_visitor_operation_cs visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_SH: { be_visitor_operation_sh visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_IH: { be_visitor_operation_ih visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_SS: { be_visitor_operation_ss visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_IS: { be_visitor_operation_is visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SH: { be_visitor_operation_proxy_impl_xh visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SS: { be_visitor_operation_direct_proxy_impl_ss visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CH: { be_visitor_operation_smart_proxy_ch visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CS: { be_visitor_operation_smart_proxy_cs visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_TIE_SH: { be_visitor_operation_tie_sh visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_TIE_SS: { be_visitor_operation_tie_ss visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_SVTH: case TAO_CodeGen::TAO_ROOT_SVH: { be_visitor_operation_ch visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_SVTS: case TAO_CodeGen::TAO_ROOT_SVS: { be_visitor_operation_svs visitor (&ctx); visitor.scope (this->op_scope_); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_EXH: { be_visitor_operation_ch visitor (&ctx); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_EXS: { be_visitor_operation_exs visitor (&ctx); visitor.scope (this->op_scope_); visitor.class_extension (this->exec_class_extension_.c_str ()); status = get_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_CNH: case TAO_CodeGen::TAO_ROOT_CNS: break; default: get_op.destroy (); return 0; } if (status == -1) { get_op.destroy (); ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_attribute::" "visit_attribute - " "codegen for get_attribute failed\n"), -1); } // Do nothing for readonly attributes. if (node->readonly ()) { get_op.destroy (); return 0; } status = 1; // Create the set method. Identifier id ("void"); UTL_ScopedName sn (&id, 0); // The return type is "void". be_predefined_type rt (AST_PredefinedType::PT_void, &sn); // Argument type is the same as the attribute type. AST_Argument *arg = idl_global->gen ()->create_argument (AST_Argument::dir_IN, node->field_type (), node->name ()); arg->set_name ((UTL_IdList *) node->name ()->copy ()); // Create the operation. be_operation set_op (&rt, AST_Operation::OP_noflags, 0, node->is_local (), node->is_abstract ()); set_op.set_defined_in (node->defined_in ()); set_op.set_name (static_cast<UTL_ScopedName *> (op_sn->copy ())); set_op.be_add_argument (arg); UTL_ExceptList *set_exceptions = node->get_set_exceptions (); if (0 != set_exceptions) { set_op.be_add_exceptions (set_exceptions->copy ()); } ctx = *this->ctx_; status = 1; switch (this->ctx_->state ()) { // These two cases are the only ones that could involved a strategy. case TAO_CodeGen::TAO_ROOT_CH: case TAO_CodeGen::TAO_INTERFACE_CH: { ctx.state (TAO_CodeGen::TAO_OPERATION_CH); be_visitor_operation_ch visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_CS: { ctx.state (TAO_CodeGen::TAO_OPERATION_CS); be_visitor_operation_cs visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_SH: { be_visitor_operation_sh visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_IH: { be_visitor_operation_ih visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_SS: { be_visitor_operation_ss visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_IS: { be_visitor_operation_is visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SH: { be_visitor_operation_proxy_impl_xh visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SS: { be_visitor_operation_direct_proxy_impl_ss visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CH: { be_visitor_operation_smart_proxy_ch visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_INTERFACE_SMART_PROXY_CS: { be_visitor_operation_smart_proxy_cs visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_TIE_SH: { be_visitor_operation_tie_sh visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_TIE_SS: { be_visitor_operation_tie_ss visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_SVTH: case TAO_CodeGen::TAO_ROOT_SVH: { be_visitor_operation_ch visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_SVTS: case TAO_CodeGen::TAO_ROOT_SVS: { be_visitor_operation_svs visitor (&ctx); visitor.scope (this->op_scope_); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_EXH: { be_visitor_operation_ch visitor (&ctx); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_EXS: { be_visitor_operation_exs visitor (&ctx); visitor.scope (this->op_scope_); visitor.class_extension (this->exec_class_extension_.c_str ()); status = set_op.accept (&visitor); break; } case TAO_CodeGen::TAO_ROOT_CNH: case TAO_CodeGen::TAO_ROOT_CNS: break; default: // Error. set_op.destroy (); rt.destroy (); ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_attribute::" "visit_attribute - " "bad codegen state\n"), -1); } if (status == 0) { get_op.destroy (); set_op.destroy (); rt.destroy (); return 0; } else if (status == -1) { get_op.destroy (); set_op.destroy (); rt.destroy (); ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_attribute::" "visit_attribute - " "codegen for get_attribute failed\n"), -1); } get_op.destroy (); set_op.destroy (); rt.destroy (); return 0; }