diff options
author | Adam Mitz <mitza@objectcomputing.com> | 2022-06-16 15:17:03 -0500 |
---|---|---|
committer | Adam Mitz <mitza@objectcomputing.com> | 2022-06-16 15:34:56 -0500 |
commit | 5fe812b68381b582a63a8a8b761b85776e087c45 (patch) | |
tree | bcca006ccec0c8552936c0a4046e78cd31e23975 | |
parent | 553322887f7ad27e164555a74f5cc5a34d56e69f (diff) | |
download | ATCD-5fe812b68381b582a63a8a8b761b85776e087c45.tar.gz |
TAO_IDL: improve versioned namespace and valuetype support
- made versioned namespaces more general
- valuetype's traits need to be in TAO's namespace
- allow valuetypes with -Scdr
11 files changed, 269 insertions, 152 deletions
diff --git a/TAO/TAO_IDL/be/be_codegen.cpp b/TAO/TAO_IDL/be/be_codegen.cpp index 2a7d2054e48..d61acfd99b3 100644 --- a/TAO/TAO_IDL/be/be_codegen.cpp +++ b/TAO/TAO_IDL/be/be_codegen.cpp @@ -332,7 +332,16 @@ TAO_CodeGen::start_client_header (const char *fname) // Begin versioned namespace support after initial headers have been // included, but before the inline file and post include // directives. - *this->client_header_ << be_global->versioning_begin (); + // + // Just for the client header, which is included first, + // the versioned namespace is opened, closed, and opened again. + // This is needed because tao_idl will generate code as if there is no + // versioned namespace wrapping the mapped types. The 'using namespace' + // that appears in the END macro allows these types to be referenced from + // the global namespace. + *this->client_header_ << be_global->versioning_begin () + << be_global->versioning_end () + << be_global->versioning_begin (); return 0; } diff --git a/TAO/TAO_IDL/be/be_valuetype.cpp b/TAO/TAO_IDL/be/be_valuetype.cpp index 394d8af269e..6454a20f47a 100644 --- a/TAO/TAO_IDL/be/be_valuetype.cpp +++ b/TAO/TAO_IDL/be/be_valuetype.cpp @@ -507,6 +507,9 @@ be_valuetype::gen_helper_stubs (char *, char *) TAO_INSERT_COMMENT (os); + *os << be_nl + << be_global->core_versioning_begin (); + *os << "void" << be_nl << "CORBA::add_ref (" << this->full_name () << " * vt)" << be_nl << "{" << be_idt_nl @@ -525,6 +528,9 @@ be_valuetype::gen_helper_stubs (char *, char *) << "}" << be_uidt << be_uidt_nl << "}"; + *os << be_nl + << be_global->core_versioning_end () << be_nl; + return 0; } diff --git a/TAO/TAO_IDL/be/be_visitor_valuetype/marshal_cs.cpp b/TAO/TAO_IDL/be/be_visitor_valuetype/marshal_cs.cpp index 190b8307592..860b79e3c67 100644 --- a/TAO/TAO_IDL/be/be_visitor_valuetype/marshal_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_valuetype/marshal_cs.cpp @@ -24,38 +24,17 @@ be_visitor_valuetype_marshal_cs::~be_visitor_valuetype_marshal_cs () } int -be_visitor_valuetype_marshal_cs::visit_valuetype (be_valuetype *node) +be_visitor_valuetype_marshal_cs::marshal_state (be_valuetype *node) { - TAO_OutStream *os = this->ctx_->stream (); - this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_OUTPUT); - - TAO_INSERT_COMMENT (os); - - *os << "::CORBA::Boolean" << be_nl; + TAO_OutStream *const os = this->ctx_->stream (); - this->class_name (node, os); - - *os << "::_tao_marshal_state (TAO_OutputCDR &"; - - be_valuetype *inh = node->statefull_inherit (); - - // If the valuetype has no fields, and no stateful inherit, - // the stream arg is unused. - if (inh != nullptr || node->data_members_count () > 0) + if (!be_global->cdr_support ()) { - *os << "strm"; - } - - *os << ", TAO_ChunkInfo&"; - // If the valuetype has no fields, and no stateful inherit, - // the chunking helper arg is unused. - if (inh != nullptr || node->data_members_count () > 0) - { - *os << "ci"; + *os << "return false;" << be_uidt_nl << be_nl; + return 0; } - *os << ") const" << be_nl - << "{" << be_idt_nl; + be_valuetype *const inh = node->statefull_inherit (); if (inh) { @@ -104,9 +83,8 @@ be_visitor_valuetype_marshal_cs::visit_valuetype (be_valuetype *node) *os << "return false;" << be_uidt_nl << be_nl; *os << "CORBA::Boolean const ret = " << be_idt << be_idt_nl; - // All we have to do is to visit the scope and generate code. - this->gen_fields (node, - *this->ctx_); + // All we have to do is to visit the scope and generate code. + this->gen_fields (node, *this->ctx_); *os << ";" << be_uidt << be_uidt_nl; @@ -123,34 +101,21 @@ be_visitor_valuetype_marshal_cs::visit_valuetype (be_valuetype *node) } *os << "return true;" << be_uidt_nl; - *os << "}" << be_nl_2; - - // Set the substate as generating code for the input operator. - this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_INPUT); - - *os << "::CORBA::Boolean" << be_nl; - - this->class_name (node, os); - - *os << "::_tao_unmarshal_state (TAO_InputCDR &"; + return 0; +} - // If the valuetype has no fields, and no stateful inherit, - // the stream arg is unused. - if (inh != nullptr || node->data_members_count () > 0) - { - *os << "strm"; - } +int +be_visitor_valuetype_marshal_cs::unmarshal_state (be_valuetype *node) +{ + TAO_OutStream *const os = this->ctx_->stream (); - *os << ", TAO_ChunkInfo&"; - // If the valuetype has no fields, and no stateful inherit, - // the chunking helper arg is unused. - if (inh != nullptr || node->data_members_count () > 0) + if (!be_global->cdr_support ()) { - *os << "ci"; + *os << "return false;" << be_uidt_nl << be_nl; + return 0; } - *os << ")" << be_nl - << "{" << be_idt_nl; + be_valuetype *const inh = node->statefull_inherit (); if (inh) { @@ -179,6 +144,7 @@ be_visitor_valuetype_marshal_cs::visit_valuetype (be_valuetype *node) } } + be_visitor_context new_ctx = *this->ctx_; be_visitor_valuetype_field_cdr_decl field_in_cdr (&new_ctx); if (field_in_cdr.visit_scope (node) == -1) @@ -197,9 +163,8 @@ be_visitor_valuetype_marshal_cs::visit_valuetype (be_valuetype *node) *os << "return false;" << be_uidt_nl << be_nl; *os << "CORBA::Boolean const ret = " << be_idt << be_idt_nl; - // All we have to do is to visit the scope and generate code. - this->gen_fields (node, - *this->ctx_); + // All we have to do is to visit the scope and generate code. + this->gen_fields (node, *this->ctx_); *os << ";" << be_uidt << be_uidt_nl; @@ -212,8 +177,89 @@ be_visitor_valuetype_marshal_cs::visit_valuetype (be_valuetype *node) } else *os << "return true;"; + return 0; +} + +int +be_visitor_valuetype_marshal_cs::visit_valuetype (be_valuetype *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_OUTPUT); + + TAO_INSERT_COMMENT (os); + + *os << "::CORBA::Boolean" << be_nl; + + this->class_name (node, os); + + *os << "::_tao_marshal_state (TAO_OutputCDR &"; + + be_valuetype *inh = node->statefull_inherit (); + + // If the valuetype has no fields, and no stateful inherit, + // the stream arg is unused. + bool const named_args = be_global->cdr_support () && (inh != nullptr || node->data_members_count () > 0); + + if (named_args) + { + *os << "strm"; + } + + *os << ", TAO_ChunkInfo &"; + + if (named_args) + { + *os << "ci"; + } + + *os << ") const" << be_nl + << "{" << be_idt_nl; + + int const marshal_error = this->marshal_state (node); + if (marshal_error) + { + return marshal_error; + } + + *os << "}" << be_nl_2; + + // Set the substate as generating code for the input operator. + this->ctx_->sub_state (TAO_CodeGen::TAO_CDR_INPUT); + + *os << "::CORBA::Boolean" << be_nl; + + this->class_name (node, os); + + *os << "::_tao_unmarshal_state (TAO_InputCDR &"; + + if (named_args) + { + *os << "strm"; + } + + *os << ", TAO_ChunkInfo &"; + + if (named_args) + { + *os << "ci"; + } + + *os << ")" << be_nl + << "{" << be_idt_nl; + + int const unmarshal_error = this->unmarshal_state (node); + if (unmarshal_error) + { + return unmarshal_error; + } + *os << be_uidt_nl << "}" << be_nl_2; + if (!be_global->cdr_support ()) + { + return 0; + } + *os << "void" << be_nl; this->class_name (node, os); diff --git a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_ch.cpp b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_ch.cpp index dff6922a75b..12810c3aa2c 100644 --- a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_ch.cpp +++ b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_ch.cpp @@ -300,14 +300,18 @@ be_visitor_valuetype_ch::visit_valuetype (be_valuetype *node) if (node->opt_accessor ()) { *os << be_uidt_nl << "protected:" << be_idt_nl; - *os << "::CORBA::Boolean " - << "_tao_marshal_state (TAO_OutputCDR &) const;" << be_nl - << "::CORBA::Boolean " - << "_tao_unmarshal_state (TAO_InputCDR &);" << be_nl - << "virtual void " - << "truncation_hook ();" - << be_uidt_nl << be_nl; - *os << "private:" << be_idt_nl; + + if (be_global->cdr_support ()) + { + *os << "::CORBA::Boolean " + << "_tao_marshal_state (TAO_OutputCDR &) const;" << be_nl + << "::CORBA::Boolean " + << "_tao_unmarshal_state (TAO_InputCDR &);" << be_nl + << "virtual void truncation_hook ();" << be_nl; + } + + *os << be_uidt_nl << be_nl + << "private:" << be_idt_nl; this->gen_pd (node); } @@ -327,7 +331,7 @@ be_visitor_valuetype_ch::visit_valuetype (be_valuetype *node) << "_tao_unmarshal__" << node->flat_name () << " (TAO_InputCDR &, TAO_ChunkInfo &);"; } - else + else if (be_global->cdr_support ()) { *os << "virtual ::CORBA::Boolean" << be_nl << "_tao_marshal__" << node->flat_name () diff --git a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp index f655680091a..49fd7f6bf74 100644 --- a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp @@ -53,6 +53,9 @@ be_visitor_valuetype_cs::visit_valuetype (be_valuetype *node) if (node->is_defined ()) { + *os << be_nl + << be_global->core_versioning_begin (); + *os << be_nl_2 << "void" << be_nl << "TAO::Value_Traits<" << node->name () << ">::add_ref (" @@ -76,6 +79,9 @@ be_visitor_valuetype_cs::visit_valuetype (be_valuetype *node) << "{" << be_idt_nl << "::CORBA::remove_ref (p);" << be_uidt_nl << "}"; + + *os << be_nl + << be_global->core_versioning_end () << be_nl; } // The _downcast method. @@ -164,58 +170,8 @@ be_visitor_valuetype_cs::visit_valuetype (be_valuetype *node) // Nothing to marshal if abstract valuetype. if (!node->is_abstract () && !is_an_amh_exception_holder) { - // The virtual _tao_marshal_v method. - *os << "::CORBA::Boolean" << be_nl - << node->name () - << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl - << "{" << be_idt_nl - << "TAO_ChunkInfo ci (this->is_truncatable_ || this->chunking_);" - << be_nl - << "return "; - - if (node->opt_accessor ()) - { - be_decl *scope = - dynamic_cast<be_scope*> (node->defined_in ())->decl (); - - *os << scope->name () << "::" - << node->local_name () - << "::_tao_marshal_state (strm, ci);" << be_uidt_nl; - } - else - { - *os << "this->_tao_marshal__" << node->flat_name () - << " (strm, ci);" << be_uidt_nl; - } - - *os << "}" << be_nl_2; - // The virtual _tao_unmarshal_v method. - *os << "::CORBA::Boolean" << be_nl - << node->name () - << "::_tao_unmarshal_v (TAO_InputCDR & strm)" - << be_nl - << "{" << be_idt_nl - << "TAO_ChunkInfo ci (this->is_truncatable_ || this->chunking_, 1);" - << be_nl - << "return "; - - if (node->opt_accessor ()) - { - be_decl *scope = - dynamic_cast<be_scope*> (node->defined_in ())->decl (); - - *os << scope->name () << "::" - << node->local_name () - <<"::_tao_unmarshal_state (strm,ci);" << be_uidt_nl; - } - else - { - *os << "this->_tao_unmarshal__" << node->flat_name () - << " (strm,ci);" << be_uidt_nl; - } - - *os << "}" << be_nl_2; + this->marshal_unmarshal_v (node); *os << "::CORBA::Boolean" << be_nl << node->name () @@ -385,6 +341,81 @@ be_visitor_valuetype_cs::visit_valuetype (be_valuetype *node) return 0; } +void be_visitor_valuetype_cs::marshal_unmarshal_v (be_valuetype *node) +{ + TAO_OutStream *const os = this->ctx_->stream (); + + if (!be_global->cdr_support ()) + { + *os << "::CORBA::Boolean" << be_nl + << node->name () + << "::_tao_marshal_v (TAO_OutputCDR &) const" << be_nl + << "{" << be_idt_nl + << "return false;" << be_uidt_nl + << "}" << be_nl_2 + << "::CORBA::Boolean" << be_nl + << node->name () + << "::_tao_unmarshal_v (TAO_InputCDR &)" << be_nl + << "{" << be_idt_nl + << "return false;" << be_uidt_nl + << "}" << be_nl_2; + return; + } + + // The virtual _tao_marshal_v method. + *os << "::CORBA::Boolean" << be_nl + << node->name () + << "::_tao_marshal_v (TAO_OutputCDR & strm) const" << be_nl + << "{" << be_idt_nl + << "TAO_ChunkInfo ci (this->is_truncatable_ || this->chunking_);" + << be_nl + << "return "; + + if (node->opt_accessor ()) + { + be_decl *scope = + dynamic_cast<be_scope*> (node->defined_in ())->decl (); + + *os << scope->name () << "::" + << node->local_name () + << "::_tao_marshal_state (strm, ci);" << be_uidt_nl; + } + else + { + *os << "this->_tao_marshal__" << node->flat_name () + << " (strm, ci);" << be_uidt_nl; + } + + *os << "}" << be_nl_2; + + // The virtual _tao_unmarshal_v method. + *os << "::CORBA::Boolean" << be_nl + << node->name () + << "::_tao_unmarshal_v (TAO_InputCDR & strm)" + << be_nl + << "{" << be_idt_nl + << "TAO_ChunkInfo ci (this->is_truncatable_ || this->chunking_, 1);" + << be_nl + << "return "; + + if (node->opt_accessor ()) + { + be_decl *scope = + dynamic_cast<be_scope*> (node->defined_in ())->decl (); + + *os << scope->name () << "::" + << node->local_name () + <<"::_tao_unmarshal_state (strm,ci);" << be_uidt_nl; + } + else + { + *os << "this->_tao_unmarshal__" << node->flat_name () + << " (strm,ci);" << be_uidt_nl; + } + + *os << "}" << be_nl_2; +} + int be_visitor_valuetype_cs::visit_eventtype (be_eventtype *node) { diff --git a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_obv_ch.cpp b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_obv_ch.cpp index b8992bb9885..8ad3186a1e7 100644 --- a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_obv_ch.cpp +++ b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_obv_ch.cpp @@ -209,25 +209,28 @@ be_visitor_valuetype_obv_ch::visit_valuetype (be_valuetype *node) // Map fields to private data. if (!node->opt_accessor ()) { - *os << be_nl << be_uidt_nl << "protected:" << be_idt_nl; - - *os << "virtual ::CORBA::Boolean" << be_nl - << "_tao_marshal__" << node->flat_name () - << " (TAO_OutputCDR &, TAO_ChunkInfo &) const;" << be_nl_2; - - *os << "virtual ::CORBA::Boolean" << be_nl - << "_tao_unmarshal__" << node->flat_name () - << " (TAO_InputCDR &, TAO_ChunkInfo &);" << be_nl_2; - - *os << "::CORBA::Boolean " - << "_tao_marshal_state (TAO_OutputCDR &, TAO_ChunkInfo &) const;" - << be_nl - << "::CORBA::Boolean " - << "_tao_unmarshal_state (TAO_InputCDR &, TAO_ChunkInfo &);" - << be_nl - << "virtual void " - << "truncation_hook ();" - << be_uidt_nl << be_nl; + if (be_global->cdr_support ()) + { + *os << be_nl << be_uidt_nl << "protected:" << be_idt_nl; + + *os << "virtual ::CORBA::Boolean" << be_nl + << "_tao_marshal__" << node->flat_name() + << " (TAO_OutputCDR &, TAO_ChunkInfo &) const;" << be_nl_2; + + *os << "virtual ::CORBA::Boolean" << be_nl + << "_tao_unmarshal__" << node->flat_name() + << " (TAO_InputCDR &, TAO_ChunkInfo &);" << be_nl_2; + + *os << "::CORBA::Boolean " + << "_tao_marshal_state (TAO_OutputCDR &, TAO_ChunkInfo &) const;" + << be_nl + << "::CORBA::Boolean " + << "_tao_unmarshal_state (TAO_InputCDR &, TAO_ChunkInfo &);" + << be_nl + << "virtual void " + << "truncation_hook ();" + << be_uidt_nl << be_nl; + } *os << "private:" << be_idt; diff --git a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_obv_cs.cpp b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_obv_cs.cpp index 7f5eefe75cd..08b88974698 100644 --- a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_obv_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_obv_cs.cpp @@ -127,21 +127,24 @@ be_visitor_valuetype_obv_cs::visit_valuetype (be_valuetype *node) // or the valuetype is abstract. if (!node->opt_accessor ()) { - *os << be_nl_2 << "::CORBA::Boolean" << be_nl - << node->full_obv_skel_name () - << "::_tao_marshal__" << node->flat_name () - << " (TAO_OutputCDR &strm, TAO_ChunkInfo& ci) const" << be_nl - << "{" << be_idt_nl - << "return _tao_marshal_state (strm, ci);" << be_uidt_nl - << "}" << be_nl_2; + if (be_global->cdr_support ()) + { + *os << be_nl_2 << "::CORBA::Boolean" << be_nl + << node->full_obv_skel_name() + << "::_tao_marshal__" << node->flat_name() + << " (TAO_OutputCDR &strm, TAO_ChunkInfo& ci) const" << be_nl + << "{" << be_idt_nl + << "return _tao_marshal_state (strm, ci);" << be_uidt_nl + << "}" << be_nl_2; - *os << "::CORBA::Boolean" << be_nl - << node->full_obv_skel_name () - << "::_tao_unmarshal__" << node->flat_name () - << " (TAO_InputCDR &strm, TAO_ChunkInfo& ci)" << be_nl - << "{" << be_idt_nl - << "return _tao_unmarshal_state (strm, ci);" << be_uidt_nl - << "}"; + *os << "::CORBA::Boolean" << be_nl + << node->full_obv_skel_name() + << "::_tao_unmarshal__" << node->flat_name() + << " (TAO_InputCDR &strm, TAO_ChunkInfo& ci)" << be_nl + << "{" << be_idt_nl + << "return _tao_unmarshal_state (strm, ci);" << be_uidt_nl + << "}"; + } if (this->visit_scope (node) == -1) { diff --git a/TAO/TAO_IDL/be_include/be_visitor_valuetype/marshal_cs.h b/TAO/TAO_IDL/be_include/be_visitor_valuetype/marshal_cs.h index 8e23ed10fbe..0b80fbe28d2 100644 --- a/TAO/TAO_IDL/be_include/be_visitor_valuetype/marshal_cs.h +++ b/TAO/TAO_IDL/be_include/be_visitor_valuetype/marshal_cs.h @@ -25,6 +25,8 @@ */ class be_visitor_valuetype_marshal_cs : public be_visitor_scope { + int marshal_state (be_valuetype *node); + int unmarshal_state (be_valuetype *node); public: /// constructor diff --git a/TAO/TAO_IDL/be_include/be_visitor_valuetype/valuetype_cs.h b/TAO/TAO_IDL/be_include/be_visitor_valuetype/valuetype_cs.h index 44e785a5013..d61b94450e4 100644 --- a/TAO/TAO_IDL/be_include/be_visitor_valuetype/valuetype_cs.h +++ b/TAO/TAO_IDL/be_include/be_visitor_valuetype/valuetype_cs.h @@ -37,6 +37,8 @@ public: private: /// Recursive to generate for inherited members. void gen_ostream_operator_r (be_valuetype *node, unsigned long &index); + + void marshal_unmarshal_v (be_valuetype *node); }; #endif /* _BE_VALUETYPE_VALUETYPE_CS_H_ */ diff --git a/TAO/tests/IDL_Test/Versioned_Namespace/TestVersionedNamespace.idl b/TAO/tests/IDL_Test/Versioned_Namespace/TestVersionedNamespace.idl index 730895040cb..3e5fa3e9592 100644 --- a/TAO/tests/IDL_Test/Versioned_Namespace/TestVersionedNamespace.idl +++ b/TAO/tests/IDL_Test/Versioned_Namespace/TestVersionedNamespace.idl @@ -1,7 +1,17 @@ module M1 { + struct S1 { + octet o; + }; + + local interface LI { + void op(in S1 s); + }; + valuetype V { - public string s1; + public string valString; + public S1 valStruct; + public LI valLocalIface; }; }; diff --git a/TAO/tests/IDL_Test/Versioned_Namespace/Versioned_Namespace.mpc b/TAO/tests/IDL_Test/Versioned_Namespace/Versioned_Namespace.mpc index d0cc1103993..c45545aab97 100644 --- a/TAO/tests/IDL_Test/Versioned_Namespace/Versioned_Namespace.mpc +++ b/TAO/tests/IDL_Test/Versioned_Namespace/Versioned_Namespace.mpc @@ -1,6 +1,7 @@ // -*- MPC -*- -project(IDL_Test_Versioned_Namespace): taoidldefaults, taolib, anytypecode, versioned_namespace { +project(IDL_Test_Versioned_Namespace): taoidldefaults, valuetype, versioned_namespace { requires += versioned_namespace + idlflags += -Scdr -Sa idlflags += -Wb,versioning_begin=BEGIN_USER_VERSIONED_NAMESPACE \ -Wb,versioning_end=END_USER_VERSIONED_NAMESPACE \ -Wb,versioning_include=UserVersionedNamespace.h |