unsigned long be_sequence::isRecursive () { UTL_Scope * scope = 0; be_Type * btype = 0; AST_Decl * adecl = (AST_Decl *)this->narrow((long) & AST_Decl::type_id); assert(adecl); be_Type * base = (be_Type *)base_type()->narrow((long) & be_Type::type_id); assert(base); unsigned long offset = 1; for ( offset = 1; adecl && (scope = adecl->defined_in()) && (btype = (be_Type *)scope->narrow((long) & be_Type::type_id)); ++offset ) { adecl = (AST_Decl *)scope->narrow((long) & AST_Decl::type_id); if (btype->TypeCodeTypeName() == base->TypeCodeTypeName()) { break; } } if (scope && btype) { return offset; } return 0; }
/* * Add this AST_InterfaceFwd node (a forward declaration of an IDL * interface) to this scope */ AST_InterfaceFwd * AST_Module::fe_add_interface_fwd (AST_InterfaceFwd * i) { AST_Decl * d = lookup_for_add (i); AST_Interface * itf; /* * Already defined and cannot be redefined? Or already used? */ if (d) { if (d->node_type() == AST_Decl::NT_interface && d->defined_in() == this) { itf = AST_Interface::narrow_from_decl (d); if (itf == 0) { return 0; } i->set_full_definition (itf); return i; } if (!can_be_redefined (d)) { idl_global->err()->error3(UTL_Error::EIDL_REDEF, i, this, d); return NULL; } if (referenced (d)) { idl_global->err()->error3(UTL_Error::EIDL_DEF_USE, i, this, d); return NULL; } if (i->has_ancestor (d)) { idl_global->err()->redefinition_in_scope(i, d); return NULL; } } /* * Add it to scope */ add_to_scope (i); /* * Add it to set of locally referenced symbols */ add_to_referenced (i, false); return i; }
AST_ValueFwd *AST_Module::fe_add_valuetype_fwd(AST_ValueFwd *v) { AST_Decl *d; AST_Value *val; /* * Already defined and cannot be redefined? Or already used? */ if ((d = lookup_for_add (v)) != NULL) { if (d->node_type() == AST_Decl::NT_value && d->defined_in() == this) { val = AST_Value::narrow_from_decl(d); if (val == NULL) return NULL; v->set_full_definition(val); return v; } if (!can_be_redefined(d)) { idl_global->err()->error3(UTL_Error::EIDL_REDEF, v, this, d); return NULL; } if (referenced(d)) { idl_global->err()->error3(UTL_Error::EIDL_DEF_USE, v, this, d); return NULL; } if (v->has_ancestor(d)) { idl_global->err()->redefinition_in_scope(v, d); return NULL; } } /* * Add it to scope */ add_to_scope(v); /* * Add it to set of locally referenced symbols */ add_to_referenced(v, I_FALSE); return v; }
void be_util::gen_nesting_close (TAO_OutStream &os, AST_Decl *node) { AST_Decl *d = ScopeAsDecl (node->defined_in ()); AST_Decl::NodeType nt = d->node_type (); while (nt != AST_Decl::NT_root) { os << be_uidt_nl << "};"; d = ScopeAsDecl (d->defined_in ()); nt = d->node_type (); } }
AST_Template_Module * FE_Utils::get_tm_container (AST_Decl *contained) { AST_Decl *d = contained; while (d != 0) { AST_Template_Module *tm = AST_Template_Module::narrow_from_decl (d); if (tm != 0) { return tm; } d = ScopeAsDecl (d->defined_in ()); } return 0; }
UTL_ScopedName * ast_visitor_reifying::template_module_rel_name (AST_Decl *d) { AST_Decl *tmp = d; ACE_CString name (d->full_name ()); while (tmp != 0) { if (AST_Template_Module::narrow_from_decl (tmp) != 0) { ACE_CString head (tmp->local_name ()->get_string ()); ACE_CString::size_type start = name.find (head) + 2; ACE_CString tail (name.substr (start + head.length ())); return FE_Utils::string_to_scoped_name (tail.c_str ()); } tmp = ScopeAsDecl (tmp->defined_in ()); } return 0; }
UTL_ScopedName * be_visitor_xplicit_pre_proc::xplicit_iface_rel_name (AST_Decl *d) { AST_Decl *tmp = d; ACE_CString name (d->full_name ()); while (tmp != 0) { if (be_home::narrow_from_decl (tmp) != 0) { ACE_CString head (tmp->local_name ()->get_string ()); ACE_CString::size_type start = name.find (head) + 2; ACE_CString tail (name.substr (start + head.length ())); return FE_Utils::string_to_scoped_name (tail.c_str ()); } tmp = ScopeAsDecl (tmp->defined_in ()); } return 0; }
int be_visitor_interface_any_op_cs::visit_interface (be_interface *node) { if (node->cli_stub_any_op_gen () || node->imported () || (node->is_local () && !be_global->gen_local_iface_anyops ())) { return 0; } TAO_OutStream *os = this->ctx_->stream (); *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__; // All template specializations must be generated before the instantiations // in the operators. *os << be_global->core_versioning_begin () << be_nl; if (! node->is_abstract ()) { *os << be_nl_2 << "namespace TAO" << be_nl << "{" << be_idt_nl << "template<>" << be_nl << "::CORBA::Boolean" << be_nl << "Any_Impl_T<" << node->name () << ">::to_object (" << be_idt << be_idt_nl << "::CORBA::Object_ptr &_tao_elem) const" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "_tao_elem = ::CORBA::Object::_duplicate (this->value_);" << be_nl << "return true;" << be_uidt_nl << "}" << be_uidt_nl << "}"; } if (node->is_abstract () || node->has_mixed_parentage ()) { *os << be_nl_2 << "namespace TAO" << be_nl << "{" << be_idt_nl << "template<>" << be_nl << "::CORBA::Boolean" << be_nl << "Any_Impl_T<" << node->name () << ">::to_abstract_base (" << be_idt << be_idt_nl << "::CORBA::AbstractBase_ptr &_tao_elem) const" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "_tao_elem = ::CORBA::AbstractBase::_duplicate (this->value_);" << be_nl << "return true;" << be_uidt_nl << "}" << be_uidt_nl << "}"; } // Since we don't generate CDR stream operators for types that // explicitly contain a local interface (at some level), we // must override these Any template class methods to avoid // calling the non-existent operators. The zero return value // will eventually cause CORBA::MARSHAL to be raised if this // type is inserted into an Any and then marshaled. if (node->is_local ()) { *os << be_nl_2 << "namespace TAO" << be_nl << "{" << be_idt_nl << "template<>" << be_nl << "::CORBA::Boolean" << be_nl << "Any_Impl_T<" << node->name () << ">::marshal_value (TAO_OutputCDR &)" << be_nl << "{" << be_idt_nl << "return false;" << be_uidt_nl << "}"; *os << be_nl_2 << "template<>" << be_nl << "::CORBA::Boolean" << be_nl << "Any_Impl_T<" << node->name () << ">::demarshal_value (TAO_InputCDR &)" << be_nl << "{" << be_idt_nl << "return false;" << be_uidt_nl << "}" << be_uidt_nl << "}"; } *os << be_global->core_versioning_end () << be_nl; be_module *module = 0; if (node->is_nested ()) { AST_Decl *d = node; AST_Decl::NodeType nt = d->node_type (); while (nt != AST_Decl::NT_root) { if (nt == AST_Decl::NT_module) { module = be_module::narrow_from_decl (d); break; } else { d = ScopeAsDecl (d->defined_in ()); nt = d->node_type (); } } if (module != 0) { // Some compilers handle "any" operators in a namespace corresponding // to their module, others do not. *os << "\n\n#if defined (ACE_ANY_OPS_USE_NAMESPACE)\n"; be_util::gen_nested_namespace_begin (os, module); // emit nested variation of any operators *os << be_nl_2 << "/// Copying insertion." << be_nl << "void" << be_nl << "operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << node->local_name () << "_ptr _tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << node->local_name () << "_ptr _tao_objptr =" << be_idt_nl << node->local_name () << "::_duplicate (_tao_elem);" << be_uidt_nl << "_tao_any <<= &_tao_objptr;" << be_uidt_nl << "}" << be_nl_2; *os << "/// Non-copying insertion." << be_nl << "void" << be_nl << "operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << node->local_name () << "_ptr *_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "TAO::Any_Impl_T<" << node->local_name () << ">::insert (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->local_name () << "::_tao_any_destructor," << be_nl << node->tc_name ()->last_component () << "," << be_nl << "*_tao_elem);" << be_uidt << be_uidt << be_uidt_nl << "}" << be_nl_2; *os << "::CORBA::Boolean" << be_nl << "operator>>= (" << be_idt << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << node->local_name () << "_ptr &_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "return" << be_idt_nl << "TAO::Any_Impl_T<" << node->local_name () << ">::extract (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->local_name () << "::_tao_any_destructor," << be_nl << node->tc_name ()->last_component () << "," << be_nl << "_tao_elem);" << be_uidt << be_uidt << be_uidt << be_uidt_nl << "}"; be_util::gen_nested_namespace_end (os, module); // Emit #else. *os << be_nl_2 << "#else\n"; } } *os << be_global->core_versioning_begin () << be_nl; *os << be_nl_2 << "/// Copying insertion." << be_nl << "void" << be_nl << "operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << node->full_name () << "_ptr _tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << node->full_name () << "_ptr _tao_objptr =" << be_idt_nl << node->full_name () << "::_duplicate (_tao_elem);" << be_uidt_nl << "_tao_any <<= &_tao_objptr;" << be_uidt_nl << "}" << be_nl_2; *os << "/// Non-copying insertion." << be_nl << "void" << be_nl << "operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << node->full_name () << "_ptr *_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "TAO::Any_Impl_T<" << node->name () << ">::insert (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->name () << "::_tao_any_destructor," << be_nl << node->tc_name () << "," << be_nl << "*_tao_elem);" << be_uidt << be_uidt << be_uidt_nl << "}" << be_nl_2; *os << "::CORBA::Boolean" << be_nl << "operator>>= (" << be_idt << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << node->full_name () << "_ptr &_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "return" << be_idt_nl << "TAO::Any_Impl_T<" << node->name () << ">::extract (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->name () << "::_tao_any_destructor," << be_nl << node->tc_name () << "," << be_nl << "_tao_elem);" << be_uidt << be_uidt << be_uidt << be_uidt_nl << "}" << be_nl; *os << be_global->core_versioning_end () << be_nl; if (module != 0) { *os << "\n\n#endif"; } // All we have to do is to visit the scope and generate code. if (this->visit_scope (node) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_interface::visit_interface - " "codegen for scope failed\n"), -1); } node->cli_stub_any_op_gen (1); return 0; }
int be_visitor_union_any_op_ch::visit_union (be_union *node) { if (node->cli_hdr_any_op_gen () || node->imported ()) { return 0; } TAO_OutStream *os = this->ctx_->stream (); const char *macro = this->ctx_->export_macro (); *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl_2; be_module *module = 0; AST_Decl *decl = node; if (decl->is_nested ()) { if (node->defined_in ()->scope_node_type () == AST_Decl::NT_interface) { be_interface *intf = 0; intf = be_interface::narrow_from_scope (node->defined_in ()); decl = intf; } if (decl->defined_in ()->scope_node_type () == AST_Decl::NT_module) { module = be_module::narrow_from_scope (decl->defined_in ()); if (!module) { ACE_ERROR_RETURN ((LM_ERROR, "be_visitor_union_any_op_ch::" "visit_union - " "Error parsing nested name\n"), -1); } // Some compilers handle "any" operators in a namespace // corresponding to their module, others do not. *os << "\n\n#if defined (ACE_ANY_OPS_USE_NAMESPACE)\n"; be_util::gen_nested_namespace_begin (os, module); *os << macro << " void operator<<= (::CORBA::Any &, const ::" << node->name () << " &); // copying version" << be_nl; *os << macro << " void operator<<= (::CORBA::Any &, ::" << node->name () << "*); // noncopying version" << be_nl; *os << macro << " ::CORBA::Boolean operator>>= (const ::CORBA::Any &, ::" << node->name () << " *&); // deprecated\n"; *os << macro << " ::CORBA::Boolean operator>>= (const ::CORBA::Any &, const ::" << node->name () << " *&);"; be_util::gen_nested_namespace_end (os, module); // Emit #else. *os << be_nl_2 << "#else\n\n"; } } *os << be_global->core_versioning_begin () << be_nl; *os << macro << " void operator<<= (::CORBA::Any &, const " << node->name () << " &); // copying version" << be_nl; *os << macro << " void operator<<= (::CORBA::Any &, " << node->name () << "*); // noncopying version" << be_nl; *os << macro << " ::CORBA::Boolean operator>>= (const ::CORBA::Any &, " << node->name () << " *&); // deprecated\n"; *os << macro << " ::CORBA::Boolean operator>>= (const ::CORBA::Any &, const " << node->name () << " *&);"; *os << be_global->core_versioning_end () << be_nl; if (module != 0) { *os << "\n\n#endif"; } be_visitor_context ctx (*this->ctx_); for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_localtypes); !si.is_done (); si.next ()) { AST_Decl *d = si.item (); be_enum *e = be_enum::narrow_from_decl (d); if (e != 0) { be_visitor_enum_any_op_ch visitor (&ctx); if (e->accept (&visitor) == -1) { ACE_ERROR ((LM_ERROR, "(%N:%l) be_visitor_union_any_op_ch::visit_union" " - codegen for enum failed\n")); } // Restore the union node in the enum visitor's context. ctx.node (this->ctx_->node ()); } } if (this->visit_scope (node) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%N:%l) be_visitor_union::visit_union - " "codegen for scope failed\n"), -1); } node->cli_hdr_any_op_gen (1); return 0; }
int be_visitor_sequence_any_op_cs::visit_sequence (be_sequence *node) { if (node->cli_stub_any_op_gen () || node->imported () || (node->is_local () && !be_global->gen_local_iface_anyops ())) { return 0; } if (idl_global->dcps_sequence_type_defined (node->full_name ())) { return 0; } TAO_OutStream *os = this->ctx_->stream (); *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl_2; *os << be_global->core_versioning_begin () << be_nl; // These are no-ops for now, so we just generate them and return if (be_global->alt_mapping () && node->max_size ()->ev ()->u.ulval == 0) { be_type *bt = be_type::narrow_from_decl (node->base_type ()); if (bt->node_type () == AST_Decl::NT_typedef) { be_typedef *td = be_typedef::narrow_from_decl (bt); bt = td->primitive_base_type (); } enum type_category { ANY_VALUE, ANY_OBJREF, ANY_ARRAY }; type_category tc = ANY_VALUE; if (bt->node_type () == AST_Decl::NT_array) { tc = ANY_ARRAY; } else if (be_interface::narrow_from_decl (bt) != 0 && be_valuetype::narrow_from_decl (bt) == 0) { tc = ANY_OBJREF; } *os << be_nl << "void operator<<= (" << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << "const std::vector<" << bt->full_name () << "> &_tao_elem)" << be_uidt_nl << "{" << be_idt_nl << "TAO::"; switch (tc) { case ANY_OBJREF: *os << "insert_objref_vector<" << bt->full_name () << "_ptr> ("; break; case ANY_ARRAY: *os << "insert_array_vector<" << bt->full_name () << "_forany> ("; break; default: *os << "insert_value_vector<" << bt->full_name () << "> ("; break; } *os << be_idt_nl << "_tao_any," << be_nl << "_tao_elem);" << be_uidt << be_uidt_nl << "}"; *os << be_nl_2 << "::CORBA::Boolean operator>>= (" << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << "std::vector<" << bt->full_name () << "> &_tao_elem)" << be_uidt_nl << "{" << be_idt_nl << "return" << be_idt_nl << "TAO::"; switch (tc) { case ANY_OBJREF: *os << "extract_objref_vector<" << bt->full_name () << "_ptr> ("; break; case ANY_ARRAY: *os << "extract_array_vector<" << bt->full_name () << "_forany> ("; break; default: *os << "extract_value_vector<" << bt->full_name () << "> ("; break; } *os << be_idt_nl << "_tao_any," << be_nl << "_tao_elem);" << be_uidt << be_uidt << be_uidt_nl << "}"; *os << be_nl << be_global->core_versioning_end () << be_nl; node->cli_stub_any_op_gen (true); return 0; } // Since we don't generate CDR stream operators for types that // explicitly contain a local interface (at some level), we // must override these Any template class methods to avoid // calling the non-existent operators. The zero return value // will eventually cause CORBA::MARSHAL to be raised if this // type is inserted into an Any and then marshaled. if (node->is_local ()) { *os << "namespace TAO" << be_nl << "{" << be_idt_nl << "template<>" << be_nl << "::CORBA::Boolean" << be_nl << "Any_Dual_Impl_T<" << node->name () << ">::marshal_value (TAO_OutputCDR &)" << be_nl << "{" << be_idt_nl << "return false;" << be_uidt_nl << "}"; *os << be_nl_2 << "template<>" << be_nl << "::CORBA::Boolean" << be_nl << "Any_Dual_Impl_T<" << node->name () << ">::demarshal_value (TAO_InputCDR &)" << be_nl << "{" << be_idt_nl << "return false;" << be_uidt_nl << "}" << be_uidt_nl << "}" << be_nl; } *os << be_global->core_versioning_end () << be_nl; // If this is non-zero, we want to call its tc_name() // for the TypeCode to pass to the Any operator impls. be_typedef *td = this->ctx_->tdef (); be_module *module = 0; if (node->is_nested ()) { AST_Decl *d = node; AST_Decl::NodeType nt = d->node_type (); while (nt != AST_Decl::NT_root) { if (nt == AST_Decl::NT_module) { module = be_module::narrow_from_decl (d); break; } else { d = ScopeAsDecl (d->defined_in ()); nt = d->node_type (); } } if (module != 0) { // Some compilers handle "any" operators in a namespace // corresponding to their module, others do not. *os << "\n\n#if defined (ACE_ANY_OPS_USE_NAMESPACE)\n"; be_util::gen_nested_namespace_begin (os, module); // Copying insertion. *os << be_nl << "// Copying insertion." << be_nl << "void operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << "const ::" << node->name () << " &_tao_elem" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl << "TAO::Any_Dual_Impl_T< ::" << node->name () << ">::insert_copy (" << be_idt << be_idt_nl << "_tao_any," << be_nl << "::" << node->name () << "::_tao_any_destructor," << be_nl << "::" << (td != 0 ? td->tc_name () : node->tc_name ()) << "," << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt << be_uidt_nl << "}" << be_nl_2; // Non-copying insertion. *os << "// Non-copying insertion." << be_nl << "void operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << "::" << node->name () << " *_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "TAO::Any_Dual_Impl_T< ::" << node->name () << ">::insert (" << be_idt << be_idt_nl << "_tao_any," << be_nl << "::" << node->name () << "::_tao_any_destructor," << be_nl << "::" << (td != 0 ? td->tc_name () : node->tc_name ()) << "," << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt_nl << "}" << be_nl_2; // Extraction to non-const pointer (deprecated, just calls the other). *os << "// Extraction to non-const pointer (deprecated)." << be_nl << "::CORBA::Boolean operator>>= (" << be_idt << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << "::" << node->name () << " *&_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "return _tao_any >>= const_cast<" << be_idt << be_idt_nl << "const ::" << node->name () << " *&> (" << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt_nl << "}" << be_nl_2; // Extraction to const pointer. *os << "// Extraction to const pointer." << be_nl << "::CORBA::Boolean operator>>= (" << be_idt << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << "const ::" << node->name () << " *&_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "return" << be_idt_nl << "TAO::Any_Dual_Impl_T< ::" << node->name () << ">::extract (" << be_idt << be_idt_nl << "_tao_any," << be_nl << "::" << node->name () << "::_tao_any_destructor," << be_nl << "::" << (td != 0 ? td->tc_name () : node->tc_name ()) << "," << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt << be_uidt_nl << "}"; be_util::gen_nested_namespace_end (os, module); // Emit #else. *os << be_nl_2 << "#else\n\n"; } } *os << be_global->core_versioning_begin () << be_nl; // Copying insertion. *os << be_nl << "// Copying insertion." << be_nl << "void operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << "const " << node->name () << " &_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "TAO::Any_Dual_Impl_T<" << node->name () << ">::insert_copy (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->name () << "::_tao_any_destructor," << be_nl << (td != 0 ? td->tc_name () : node->tc_name ()) << "," << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt << be_uidt_nl << "}" << be_nl_2; // Non-copying insertion. *os << "// Non-copying insertion." << be_nl << "void operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << node->name () << " *_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "TAO::Any_Dual_Impl_T<" << node->name () << ">::insert (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->name () << "::_tao_any_destructor," << be_nl << (td != 0 ? td->tc_name () : node->tc_name ()) << "," << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt_nl << "}" << be_nl_2; // Extraction to non-const pointer (deprecated, just calls the other). *os << "// Extraction to non-const pointer (deprecated)." << be_nl << "::CORBA::Boolean operator>>= (" << be_idt << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << node->name () << " *&_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "return _tao_any >>= const_cast<" << be_idt << be_idt_nl << "const " << node->name () << " *&> (" << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt_nl << "}" << be_nl_2; // Extraction to const pointer. *os << "// Extraction to const pointer." << be_nl << "::CORBA::Boolean operator>>= (" << be_idt << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << "const " << node->name () << " *&_tao_elem)" << be_uidt << be_uidt_nl << "{" << be_idt_nl << "return" << be_idt_nl << "TAO::Any_Dual_Impl_T<" << node->name () << ">::extract (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->name () << "::_tao_any_destructor," << be_nl << (td != 0 ? td->tc_name () : node->tc_name ()) << "," << be_nl << "_tao_elem);" << be_uidt << be_uidt << be_uidt << be_uidt_nl << "}"; *os << be_global->core_versioning_end () << be_nl; if (module != 0) { *os << "\n\n#endif"; } node->cli_stub_any_op_gen (true); return 0; }
// Look up a branch in an enum which is the discriminator type for this // union, based on the label value which must be an enumerator in that // enum. AST_UnionBranch * AST_Union::lookup_enum (AST_UnionBranch *b) { AST_UnionLabel *label = b->label(); AST_Expression *lv = label->label_val (); AST_Enum *e = AST_Enum::narrow_from_decl (this->pd_disc_type); AST_Decl *d = 0; AST_UnionBranch *fb = 0; if (e == 0) { return 0; } if (lv == 0) { return b; } // Expecting a symbol label. if (lv->ec () != AST_Expression::EC_symbol) { idl_global->err ()->enum_val_expected (this, label); return b; } // See if the symbol defines a constant in the discriminator enum. UTL_ScopedName *sn = lv->n (); d = e->lookup_by_name (sn, true); if (d == 0 || d->defined_in () != e) { idl_global->err ()->enum_val_lookup_failure (this, e, sn); return b; } // OK, now see if this symbol is already used as the label of // some other branch. for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls); !i.is_done(); i.next ()) { d = i.item (); if (d->node_type () == AST_Decl::NT_union_branch) { fb = AST_UnionBranch::narrow_from_decl (d); if (fb == 0) { continue; } if (fb->label() != 0 && fb->label ()->label_kind () == AST_UnionLabel::UL_label && fb->label ()->label_val ()->compare (lv)) { idl_global->err ()->error2 (UTL_Error::EIDL_MULTIPLE_BRANCH, this, b); return b; } } } return 0; }
int be_visitor_arg_traits::visit_argument (be_argument *node) { if (this->ctx_->alias () != 0 || this->generated (node)) { return 0; } AST_Type *bt = node->field_type (); AST_Decl::NodeType nt = bt->node_type (); // We are interested here only in unaliased, bounded // (w)strings. if (nt != AST_Decl::NT_string && nt != AST_Decl::NT_wstring) { return 0; } be_string *st = be_string::narrow_from_decl (bt); ACE_CDR::ULong bound = st->max_size ()->ev ()->u.ulval; if (bound == 0) { return 0; } TAO_OutStream *os = this->ctx_->stream (); *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__; std::string guard_suffix = std::string (this->S_) + std::string ("arg_traits"); // The guard should be generated to prevent multiple declarations, // since a bounded (w)string of the same length may be used or typedef'd // more than once. os->gen_ifdef_macro (node->flat_name (), guard_suffix.c_str (), false); bool wide = (st->width () != 1); // It is legal IDL to declare a bounded (w)string as an operation // parameter type. There could be any number of identical // declarations in the same build, translation unit, or even in // the same operation, so we use the argument's flat name to // declare an empty struct, and use that struct as the template // parameter for Arg_Traits<>. *os << be_nl_2; AST_Decl *op = ScopeAsDecl (node->defined_in ()); AST_Decl *intf = ScopeAsDecl (op->defined_in ()); ACE_CString arg_flat_name (intf->flat_name ()); arg_flat_name += '_'; arg_flat_name += op->local_name ()->get_string (); arg_flat_name += '_'; arg_flat_name += node->local_name ()->get_string (); // Avoid generating a duplicate structure in the skeleton. if (ACE_OS::strlen (this->S_) == 0) { *os << "struct " << arg_flat_name.c_str () << " {};" << be_nl_2; } *os << "template<>" << be_nl << "class " << this->S_ << "Arg_Traits<" << arg_flat_name.c_str () << ">" << be_idt_nl << ": public" << be_idt << be_idt_nl << "BD_String_" << this->S_ << "Arg_Traits_T<" << be_nl << "CORBA::" << (wide ? "W" : "") << "String_var," << be_nl << bound << "," << be_nl << this->insert_policy() << be_uidt_nl << ">" << be_uidt << be_uidt << be_uidt_nl << "{" << be_nl << "};"; os->gen_endif (); this->generated (node, true); return 0; }
/* * Implements lookup by name for scoped names */ AST_Decl * UTL_Scope::lookup_by_name(UTL_ScopedName *e, idl_bool treat_as_ref, idl_bool in_parent) { AST_Decl *d; UTL_Scope *t = NULL; /* * Empty name? error */ if (e == NULL) { return NULL; } /* * If name starts with "::" or "" start search up in global scope */ if (is_global_name(e->head())) { /* * Get parent scope */ d = ScopeAsDecl(this); if (d == NULL) return NULL; t = d->defined_in(); /* * If this is the global scope.. */ if (t == NULL) { /* * Look up tail of name starting here */ d = lookup_by_name((UTL_ScopedName *) e->tail(), treat_as_ref); /* * Now return whatever we have */ return d; } /* * OK, not global scope yet, so simply iterate with parent scope */ d = t->lookup_by_name(e, treat_as_ref); /* * If treat_as_ref is true and d is not NULL, add d to * set of nodes referenced here */ if (treat_as_ref && d != NULL) add_to_referenced(d, I_FALSE); /* * Now return what we have */ return d; } /* * The name does not start with "::" * * Is name defined here? */ d = lookup_by_name_local (e->head ()); /* * Special case for scope which is an interface. We have to look * in the inherited interfaces as well.. */ if (d == NULL) { if (pd_scope_node_type == AST_Decl::NT_interface) { d = look_in_inherited(e, treat_as_ref); if (treat_as_ref && d != NULL) { add_to_referenced(d, I_FALSE); /* * OK, now return whatever we found */ return d; } } } /* Only traverse parent scope chain if not in inherited interface. */ if (d == NULL && !in_parent) { /* * OK, not found. Go down parent scope chain. */ d = ScopeAsDecl(this); if (d != NULL) { t = d->defined_in(); if (t == NULL) d = NULL; else d = t->lookup_by_name(e, treat_as_ref); } /* * If treat_as_ref is true and d is not NULL, add d to * set of nodes referenced here */ if (treat_as_ref && d != NULL) add_to_referenced(d, I_FALSE); /* * OK, now return whatever we found */ return d; } /* * OK, start of name is defined. Now loop doing local lookups * of subsequent elements of the name */ d = iter_lookup_by_name_local(d, e, treat_as_ref); /* * If treat_as_ref is true and d is not NULL, add d to set * of nodes referenced here. */ if (treat_as_ref && d != NULL) add_to_referenced(d, I_FALSE); /* * All OK, name fully resolved */ return d; }
int be_visitor_enum_any_op_cs::visit_enum (be_enum *node) { if (node->cli_stub_any_op_gen () || node->imported ()) { return 0; } TAO_OutStream *os = this->ctx_->stream (); *os << be_nl_2 << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__ << be_nl; *os << be_global->core_versioning_begin () << be_nl; // Since we don't generate CDR stream operators for types that // explicitly contain a local interface (at some level), we // must override these Any template class methods to avoid // calling the non-existent operators. The zero return value // will eventually cause CORBA::MARSHAL to be raised if this // type is inserted into an Any and then marshaled. if (node->is_local ()) { *os << "namespace TAO" << be_nl << "{" << be_idt_nl << "template<>" << be_nl << "::CORBA::Boolean" << be_nl << "Any_Basic_Impl_T<" << node->name () << ">::marshal_value (TAO_OutputCDR &)" << be_nl << "{" << be_idt_nl << "return false;" << be_uidt_nl << "}"; *os << be_nl_2 << "template<>" << be_nl << "::CORBA::Boolean" << be_nl << "Any_Basic_Impl_T<" << node->name () << ">::demarshal_value (TAO_InputCDR &)" << be_nl << "{" << be_idt_nl << "return false;" << be_uidt_nl << "}" << be_uidt_nl << "}" << be_nl_2; } *os << be_global->core_versioning_end () << be_nl; be_module *module = 0; if (node->is_nested ()) { AST_Decl *d = node; AST_Decl::NodeType nt = d->node_type (); while (nt != AST_Decl::NT_root) { if (nt == AST_Decl::NT_module) { module = be_module::narrow_from_decl (d); break; } else { d = ScopeAsDecl (d->defined_in ()); nt = d->node_type (); } } if (module != 0) { // Some compilers handle "any" operators in a namespace corresponding // to their module, others do not. *os << "\n\n#if defined (ACE_ANY_OPS_USE_NAMESPACE)\n"; be_util::gen_nested_namespace_begin (os, module); // Generate the Any <<= and >>= operator declarations // Any <<= and >>= operators. *os << "void operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << "::" << node->name () << " _tao_elem" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl << "TAO::Any_Basic_Impl_T< ::" << node->name () << ">::insert (" << be_idt << be_idt_nl << "_tao_any," << be_nl << "::" << node->tc_name () << "," << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt_nl << "}" << be_nl_2; *os << "::CORBA::Boolean operator>>= (" << be_idt << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << "::" << node->name () << " &_tao_elem" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl << "return" << be_idt_nl << "TAO::Any_Basic_Impl_T< ::" << node->name () << ">::extract (" << be_idt << be_idt_nl << "_tao_any," << be_nl << "::" << node->tc_name () << "," << be_nl << "_tao_elem " << be_uidt_nl << ");" << be_uidt << be_uidt << be_uidt_nl << "}"; be_util::gen_nested_namespace_end (os, module); // Emit #else. *os << be_nl_2 << "#else\n"; } } *os << be_global->core_versioning_begin () << be_nl; // Generate the Any <<= and >>= operator declarations // Any <<= and >>= operators. *os << "void operator<<= (" << be_idt << be_idt_nl << "::CORBA::Any &_tao_any," << be_nl << node->name () << " _tao_elem" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl << "TAO::Any_Basic_Impl_T<" << node->name () << ">::insert (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->tc_name () << "," << be_nl << "_tao_elem" << be_uidt_nl << ");" << be_uidt << be_uidt_nl << "}" << be_nl_2; *os << "::CORBA::Boolean operator>>= (" << be_idt << be_idt_nl << "const ::CORBA::Any &_tao_any," << be_nl << node->name () << " &_tao_elem" << be_uidt_nl << ")" << be_uidt_nl << "{" << be_idt_nl << "return" << be_idt_nl << "TAO::Any_Basic_Impl_T<" << node->name () << ">::extract (" << be_idt << be_idt_nl << "_tao_any," << be_nl << node->tc_name () << "," << be_nl << "_tao_elem " << be_uidt_nl << ");" << be_uidt << be_uidt << be_uidt_nl << "}"; *os << be_global->core_versioning_end () << be_nl; if (module != 0) { *os << "\n\n#endif"; } node->cli_stub_any_op_gen (1); return 0; }
int be_visitor_interface_any_op_ch::visit_interface (be_interface *node) { if (node->cli_hdr_any_op_gen () || node->imported () || (node->is_local () && !be_global->gen_local_iface_anyops ())) { return 0; } TAO_OutStream *os = this->ctx_->stream (); const char *macro = this->ctx_->export_macro (); *os << be_nl_2; *os << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__; *os << be_nl_2; be_module *module = 0; if (node->is_nested ()) { AST_Decl *d = node; AST_Decl::NodeType nt = d->node_type (); while (nt != AST_Decl::NT_root) { if (nt == AST_Decl::NT_module) { module = be_module::narrow_from_decl (d); break; } else { d = ScopeAsDecl (d->defined_in ()); nt = d->node_type (); } } if (module != 0) { // Some compilers handle "any" operators in a namespace // corresponding to their module, others do not. *os << "\n\n#if defined (ACE_ANY_OPS_USE_NAMESPACE)\n"; be_util::gen_nested_namespace_begin (os, module); // emit nested variation of any operators *os << macro << " void" << " operator<<= ( ::CORBA::Any &, " << node->local_name () << "_ptr); // copying" << be_nl; *os << macro << " void" << " operator<<= ( ::CORBA::Any &, " << node->local_name () << "_ptr *); // non-copying" << be_nl; *os << macro << " ::CORBA::Boolean" << " operator>>= (const ::CORBA::Any &, " << node->local_name () << "_ptr &);"; be_util::gen_nested_namespace_end (os, module); // Emit #else. *os << be_nl_2 << "#else\n\n"; } } *os << be_global->core_versioning_begin () << be_nl; *os << macro << " void operator<<= (::CORBA::Any &, " << node->name () << "_ptr); // copying" << be_nl; *os << macro << " void operator<<= (::CORBA::Any &, " << node->name () << "_ptr *); // non-copying" << be_nl; *os << macro << " ::CORBA::Boolean operator>>= (const ::CORBA::Any &, " << node->name () << "_ptr &);"; *os << be_global->core_versioning_end () << be_nl; if (module != 0) { *os << "\n\n#endif"; } // All we have to do is to visit the scope and generate code. if (this->visit_scope (node) == -1) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("be_visitor_interface_any_op_ch::") ACE_TEXT ("visit_interface - ") ACE_TEXT ("codegen for scope failed\n")), -1); } node->cli_hdr_any_op_gen (1); return 0; }